* neovim like scroll function
* clear line annotations outside of move_vertically/_visual
* add nvim scroll function to commands
* assign nvim-scroll to C-d and C-u (half page scrolls)
* dont remove backspace and space mapping
* move non-softwrap logic to seperate function, call this in nvim-scroll fn
* Revert "move non-softwrap logic to seperate function, call this in nvim-scroll fn"
This reverts commit e4905729c3.
* Revert "clear line annotations outside of move_vertically/_visual"
This reverts commit 1df3fefe55.
* add TODO for when inline diagnostics gets merged
* move nvim-scroll logic into scroll(), dont respect scrolloff
* run cargo fmt
* run cargo clippy
* update documenation for Ctrl-d and Ctrl-u remap
* Make sure pending key list is empty when count handling
This will allow using numbers as second key event.
* count handling; add an exception for 'g'
* Lookup the key event before considering a number as count
* Avoid the allocation of another vec for the pending keys
---------
Co-authored-by: x <x@torrent>
`syn_loader` was replaced rather than interior value being replace,
old value was still being referenced and not updated after `:config-refresh`.
By using `ArcSwap` like for `config`, each `.load()` call will return the most
updated value.
Co-authored-by: kyfan <kyfan@email>
* Replace FileType::Suffix with FileType::Glob
Suffix is rather limited and cannot be used to match files which have
semantic meaning based on location + file type (for example, Github
Action workflow files). This patch adds support for a Glob FileType to
replace Suffix, which encompasses the existing behavior & adds
additional file matching functionality.
Globs are standard Unix-style path globs, which are matched against the
absolute path of the file. If the configured glob for a language is a
relative glob (that is, it isn't an absolute path or already starts with
a glob pattern), a glob pattern will be prepended to allow matching
relative paths from any directory.
The order of file type matching is also updated to first match on globs
and then on extension. This is necessary as most cases where
glob-matching is useful will have already been matched by an extension
if glob matching is done last.
* Convert file-types suffixes to globs
* Use globs for filename matching
Trying to match the file-type raw strings against both filename and
extension leads to files with the same name as the extension having the
incorrect syntax.
* Match dockerfiles with suffixes
It's common practice to add a suffix to dockerfiles based on their
context, e.g. `Dockerfile.dev`, `Dockerfile.prod`, etc.
* Make env filetype matching more generic
Match on `.env` or any `.env.*` files.
* Update docs
* Use GlobSet to match all file type globs at once
* Update todo.txt glob patterns
* Consolidate language Configuration and Loader creation
This is a refactor that improves the error handling for creating
the `helix_core::syntax::Loader` from the default and user language
configuration.
* Fix integration tests
* Add additional starlark file-type glob
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Currently, helix implements operations which change the paths of files
incorrectly and inconsistently. This PR ensures that we do the following
whenever a buffer is renamed (`:move` and workspace edits)
* always send did_open/did_close notifications
* send will_rename/did_rename requests correctly
* send them to all LSP servers not just those that are active for a
buffer
* also send these requests for paths that are not yet open in a buffer (if
triggered from workspace edit).
* only send these if the server registered interests in the path
* autodetect language, indent, line ending, ..
This PR also centralizes the infrastructure for path setting and
therefore `:w <path>` benefits from similar fixed (but without didRename)
* injecting the icon through a resource file, no extra deps
* formatted
* scripted rc compilation
* formatted and restructured
* simplified conditional func call
We use `which::which` in many crates, so `which` was a separate
dependency across all of them. We can centralize `which` into the
stdx crate so it's easy for all crates to depend on it.
I also moved the rest of `helix-view/src/env.rs` into helix-stdx's
`env` module since it only contained a thin wrapper around `which`
and `std::env`.
helix-stdx is meant to carry extensions to the stdlib or low-level
dependencies that are useful in all other crates. This commit starts
with all of the path functions from helix-core and the CWD tracking that
lived in helix-loader.
The CWD tracking in helix-loader was previously unable to call the
canonicalization functions in helix-core. Switching to our custom
canonicalization code should make no noticeable difference though
since `std::env::current_dir` returns a canonicalized path with
symlinks resolved (at least on unix).
* feat(lsp): implement show document request
Implement [window.showDocument](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showDocument)
LSP server-sent request.
This PR builds on top of helix-editor#5820,
moves the external-URL opening functionality into shared crate-level
function that returns a callback that is now used by both the
`open_file` command as well as the window.showDocument handler if
the URL is marked as external.
* add return
* use vertical split
* refactor
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
* Keep lsp event listener thread alive when malformed json is encountered from the lsp server
* Update unexpected error flow in recv() to close outstanding requests and close the language server
* Log malformed notifications as info instead of error
* Make close_language_server a nested function inside recv, similar to what's done in send
* Update malformed notification log text
* Clean up new log text a bit
* Initialize recv_buffer closer to where it's used
* Use "exit" instead of "close"
* Remove whitespace
* Remove the need for a helper method to exit the language server
* Match on Unhandled error explicitly and keep catch-all error case around
`:tree-sitter-subtree` could previously only print subtrees of nodes
in the root injection layer. We can improve on that by finding the layer
that contains the given byte range and printing the subtree within that
layer. That gives more useful results when a selection is within an
injection layer.
Make the pluralization of files and selections consistent to emphasize
the 1-to-1 relation between files and selections. The prior wording
with plural "files" and singular "selection" can mislead users into
thinking the command can open multiple files from a single selection.
Diagnostics are currently extended if text is inserted at their end. This is
desirable when inserting text after an identifier. For example consider:
let foo = 2;
--- unused variable
Renaming the identifier should extend the diagnostic:
let foobar = 2;
------ unused variable
This is currently implemented in helix but as a consequence adding whitespaces
or a type hint also extends the diagnostic:
let foo = 2;
-------- unused variable
let foo: Bar = 2;
-------- unused variable
In these cases the diagnostic should remain unchanged:
let foo = 2;
--- unused variable
let foo: Bar = 2;
--- unused variable
As a heuristic helix will now only extend diagnostics that end on a word char
if new chars are appended to the word (so not for punctuation/ whitespace).
The idea for this mapping was inspired for the word level tracking vscode uses
for many positions. While VSCode doesn't currently update diagnostics after
receiving publishDiagnostic it does use this system for inlay hints for example.
Similarly, the new association mechanism implemented here can be used for word
level tracking of inlay hints.
A similar mapping function is implemented for word starts. Together
these can be used to make a diagnostic stick to a word. If that word
is removed that diagnostic is automatically removed too. This is the exact
same behavior VSCode inlay hints eixibit.
* fix: #8977
fixes the issue that lines with only spaces are getting
joined as well
* reverting some renamings
* improve empty line check
* adding integration test
* reverting code block
* fix conditon check for line end
* applying suggested style
* rust-toolchain.toml: bump MSRV to 1.70.0
With Firefox 120 released on 21 November 2023, the MSRV is now 1.70.0.
* Fix cargo fmt with Rust 1.70.0
* Fix cargo clippy with Rust 1.70.0
* Fix cargo doc with Rust 1.70.0
* rust-toolchain.toml: add clippy component
* .github: bump dtolnay/rust-toolchain to 1.70
* helix-term: bump rust-version to 1.70
* helix-view/gutter: use checked_ilog10 to count digits
* helix-core/syntax: use MAIN_SEPARATOR_STR constant
* helix-view/handlers/dap: use Display impl for displaying process spawn error
* WIP: helix-term/commands: use checked math to assert ranges cannot overlap
* Resolve args.files before changing directory
* Removed the open_cwd work-around now that the path is full
* If -w is specified, use that as the working directory
* Open the remaining files in the argument list, also when the first is a directory
* Use an iterator access the files argument
* Add support for showing all LSPs in --health <lang>
* Add support for showing all LSPs in --health languages
* Use available/configured in --health languages
* Apply @AlexanderBrevig suggestion in --health
* Update `--health <language>`
Better output (inspired by #8156).
Handle the case where no LSPs are configured.
* Display all LSPs in `--health languages` instead of x/x
Displays all LSPs as a list in the table generated wih `--health languages`
* Make check_binary accept Optional references to str
Avoids some calls to .clone()
* Apply @the-mikedavis suggestions
* Avoid useless collecting and cloning
* Use for loop instead of .try_for_each()
* Accept +num flag for opening at line number
* Update +N argument feature according to feedback in original PR #5603
* Only override the line number of the first file if +N is specified
---------
Co-authored-by: Nachum Barcohen <38861757+nabaco@users.noreply.github.com>
* added working path arg to cli and help menu
* improve working path cli arg handling
* enable hx to set the working path
* applied cargo formatting
* improved code from cargo clippy suggestion
* improved code from follow up review
* fix for -w <path> is set but args.files is empty
* improved formatting of --help output
* adds treesitter-highlight-name command
* commit documentation changes
* moves the get_highlight_name function into core/syntax
* rename get_highlight_name function to get_highlight_for_node_at_position
* addresses pr comments: moves fn into helper fn, simplifies a lot
* commit updated documentation changes
* changes scope method to return &str so that callers can decide whether or not to own
* only stream from background thread if necessary
If the file transversal is longer shorter 30ms it will now be performed
on the main thread. Spawning a thread can take a while (or rather it
takes a while until that thread is scheduled) so the files can actually
take a while to show up. This prevents the `(running)` indicator from
briefly showing up when opening the file picker in a small directory.
* run partial cargo update
The completion component assumes that it operates on the same View but
it's possible to break this assumption by switching windows through
left-clicking. I believe we should clear the completion menu when
switching windows to fix this.
This change fixes a panic for this scenario:
* Open a buffer with LSP completion available
* Split the window (for example '<C-w>v')
* Enter insert mode and trigger the completion menu
* Select a completion candidate (for example with '<C-n>')
* Switch to the original window by left-clicking in its area
* Enter insert mode and make edits (for example 'o<backspace>')
This will trip the 'assert_eq' in Document::restore.
* transition to nucleo for fuzzy matching
* drop flakey test case
since the picker streams in results now any test that relies
on the picker containing results is potentially flakely
* use crates.io version of nucleo
* Fix typo in commands.rs
Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
---------
Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
* fix: line numbers remain relative when helix loses focus
If `line number = relative` and a new window is opened in helix, lines inside unfocused windows will be `absolute`. This commit adds the same thing when helix becomes unfocused in a terminal emulator.
* partial rebase
* create separate timer for redraw requests
* Update helix-view/src/editor.rs
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
YAML indents queries are tweaked to fix auto indent behavior.
A new capture type `indent.always` is introduced to address use cases
where combining indent captures on a single line is desired.
Fixes#6661
* fix(picker): `alt-ret' changes cursor pos of current file, not new one
Closes#7673
* fix other pickers
* symbol pickers
* diagnostick pickers
This is done using the already patched `jump_to_location` method.
* fix global and jumplist pickers
* use `view` as old_id; make `align_view` method of `Action`
* test(picker): basic <alt-ret> functionality
* fix: picker integrational test
* fix nit
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
The clipboard special registers are able to retain multiple selections
and also join the value when copying it to the clipboard. So by default
we should yank regularly to the '*' and '+' registers. That will have
the same behavior for the clipboards but will allow pasting multiple
selections if the clipboard doesn't change between yanks.
Since the clipboard provider now lives on the Registers type, we want
to eliminate it from the Editor. We can do that and clean up the
commands that interact with the clipboard by calling regular yank,
paste and replace impls on the clipboard special registers.
Eventually the clipboard commands could be removed once macro keybinding
is supported.
This fixes a discrepancy between regular registers which are used for
yanking multiple values (for example via `"ay`) and regular registers
that store a history of values (for example `"a*`).
Previously, the preview shown in `select_register`'s infobox would show
the oldest value in history. It's intuitive and useful to see the most
recent value pushed to the history though.
We cannot simply switch the preview line from `values.first()`
to `values.last()`: that would fix the preview for registers
used for history but break the preview for registers used to yank
multiple values. We could push to the beginning of the values with
`Registers::push` but this is wasteful from a performance perspective.
Instead we can have `Registers::read` return an iterator that
returns elements in the reverse order and reverse the values in
`Register::write`. This effectively means that `push` adds elements to
the beginning of the register's values. For the sake of the preview, we
can switch to `values.last()` and that is then correct for both usage-
styles. This also needs a change to call-sites that read the latest
history value to switch from `last` to `first`.
This is an unfortunately noisy change: we need to update virtually all
callsites that access the registers. For reads this means passing in the
Editor and for writes this means handling potential failure when we
can't write to a clipboard register.
This removes a handful of allocations for functions calling into the
function, which is nice because the prompt may call this function on
every keypress.
Pascal and I discussed this and we think it's generally better to
take a 'RopeSlice' rather than a '&Rope'. The code block rendering
function in the markdown component module is a good example for how
this can be useful: we can remove an allocation of a rope and instead
directly turn a '&str' into a 'RopeSlice' which is very cheap.
A change to prefer 'RopeSlice' to '&Rope' whenever the rope isn't
modified would be nice, but it would be a very large diff (around 500+
500-). Starting off with just the syntax functions seems like a nice
middle-ground, and we can remove a Rope allocation because of it.
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Since regex is almost always injected into other languages,
`pattern_character`s will inherit the highlight for the structure that
injects them (for example `/foo/` in JavaScript or `~r/foo/` in Elixir).
This removes the string highlight when used in the prompt.
We also add `ERROR` node highlighting so that errors in regex syntax
appear in the prompt. This resolves a TODO in the `regex_prompt`
function about highlighting errors in the regex.
We can use tree-sitter-regex highlighting in prompts for entering
regexes, like `search` or `global_search`. The `highlighted_code_block`
function from the markdown component makes this a very small change.
This could be improved in the future by leaving the parsed syntax tree
on the prompt, allowing incremental updates. Prompt lines are usually so
short though and tree-sitter-regex is rather small and uncomplicated,
so that improvement probably wouldn't make a big difference.
* Add initial support for LSP DidChangeWatchedFiles
* Move file event Handler to helix-lsp
* Simplify file event handling
* Refactor file event handling
* Block on future within LSP file event handler
* Fully qualify uses of the file_event::Handler type
* Rename ops field to options
* Revert newline removal from helix-view/Cargo.toml
* Ensure file event Handler is cleaned up when lsp client is shutdown
* _apply_motion generalization where possible
API encourages users to not forget setting `editor.last_motion` when
applying a motion. But also not setting `last_motion` without applying a
motion first.
* (rename) will_find_char -> find_char
method name makes it sound like it would be returning a boolean.
* use _apply_motion in find_char
Feature that falls out from this is that repetitions of t,T,f,F are
saved with the context extention/move and count. (Not defaulting to extend
by 1 count).
* Finalize apply_motion API
last_motion is now a private field and can only be set by calling
Editor.apply_motion(). Removing need (and possibility) of writing:
`motion(editor); editor.last_motion = motion`
Now it's just: `editor.apply_motion(motion)`
* editor.last_message: rm Box wrap around Arc
* Use pre-existing `Direction` rather than custom `SearchDirection`.
* `LastMotion` type alias for `Option<Arc<dyn Fn(&mut Editor)>>`
* Take motion rather than cloning it.
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
* last_motion as Option<Motion>.
* Use `Box` over `Arc` for `last_motion`.
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>