Multicursor completions may overlap and therefore overlapping
completions must be dropped to avoid crashes. Furthermore, multicursor
edits might simply be out of range if the word before/after the cursor
is shorter. This currently leads to crashes, instead these selections
are now also removed for completions.
This commit also significantly refactors snippet transaction generation
so that tabstops behave correctly with the above rules. Furthermore,
snippet tabstops need to be carefully mapped to ensure their position
is correct and consistent with our selection semantics. Finally,
we now keep a partially updated Rope while creating snippet
transactions so that we can fill information into snippets that
depends on the position in the document.
This commit adds new functions to `Transaction` that allow creating
edits that might potentially overlap. Any change that overlaps
previous changes is ignored. Furthermore, a utility method is added
that also drops selections associated with dropped changes (for
transactions that are created from a selection).
This is needed to avoid crashes when applying multicursor
autocompletions, as the edit from a previous cursor may overlap
with the next cursor/edit.
Most LSPs will complete case-insensitive matches, particularly from
lowercase to uppercase. In some cases, notably Pyright, this is given
as a simple insert text instead of TextEdit. When this happens, the
prefix text was left unedited.
* Generalised to multiple runtime directories with priorities
This is an implementation for #3346.
Previously, one of the following runtime directories were used:
1. `$HELIX_RUNTIME`
2. sibling directory to `$CARGO_MANIFEST_DIR`
3. subdirectory of user config directory
4. subdirectory of path to helix executable
The first directory provided / found to exist in this order was used as a
root for all runtime file searches (grammars, themes, queries).
This change lowers the priority of `$HELIX_RUNTIME` so that the user
config runtime has higher priority. More significantly, all of these
directories are now searched for runtime files, enabling a user to override
default or system-level runtime files. If the same file name appears
in multiple runtime directories, the following priority is now used:
1. sibling directory to `$CARGO_MANIFEST_DIR`
2. subdirectory of user config directory
3. `$HELIX_RUNTIME`
4. subdirectory of path to helix executable
One exception to this rule is that a user can have a `themes`
directory directly in the user config directory that has higher piority
to `themes` directories in runtime directories. That behaviour has been
preserved.
As part of implementing this feature `theme::Loader` was simplified
and the cycle detection logic of the theme inheritance was improved to
cover more cases and to be more explicit.
* Removed AsRef usage to avoid binary growth
* Health displaying ;-separated runtime dirs
* Changed HELIX_RUNTIME build from src instructions
* Updated doc for more detail on runtime directories
* Improved health symlink printing and theme cycle errors
The health display of runtime symlinks now prints both ends of the
link.
Separate errors are given when theme file is not found and when the
only theme file found would form an inheritence cycle.
* Satisfied clippy on passing Path
* Clarified highest priority runtime directory purpose
* Further clarified multiple runtime details in book
Also gave markdown headings to subsections.
Fixed a error with table indentation not building
table that also appears present on master.
---------
Co-authored-by: Paul Scott <paul.scott@anu.edu.au>
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
* Fix#6092
Cause were some incorrect assumptions that missed an edge case in the
`Selection.contains()` calculation. Tests were added accordingly.
* Fix Selection.contains() edge-case handling.
Removing the len check short-circuit was the only thing needed as
pointed out by @dead10ck.
Repeating completions currently crates a savepoint when a completion
popup was triggered (so after the request completed). Just like for
normal completions the savepoint must be created at the request.
The occurrence of the completion request was previously not saved in
`last_insert`. To that end a new `InsertEvent::RequestCompletion`
variant has been added. When replayed this event creates a snapshot
that is "actived" by the `TriggerCompletion` event and subsequently
used during any `InsertEvent::CompletiuonApply` events.
Completion requests are computed asynchronously to avoid common micro
freezes while editing. This means that once a completion request
completes, the state of the editor might have changed. Currently,
there is a check to ensure we are still in insert mode. However,
we also need to ensure that the view and document hasn't changed
to avoid accidentally using a savepoint with the wrong view/document.
Furthermore, the editor might request a new completion while the
previous completion request hasn't complemented yet. This can
lead to weird flickering or an outdated completion request replacing
a newer completion that has already completed (the LSP server
is not required to process completion requests in order). This change
also needed to ensure determinism/linear ordering so that completion
popup always correspond to the last completion request.
Fixing autocomplete required moving the document savepoint before the
asynchronous completion request. However, this in turn causes new bugs:
If the completion popup is open, the savepoint is restored when the
popup closes (or another entry is selected). However, at that point
a new completion request might already have been created which
would have replaced the new savepoint (therefore leading to incorrectly
applied complies).
This commit fixes that bug by allowing in arbitrary number of
savepoints to be tracked on the document. The savepoints are reference
counted and therefore remain valid as long as any reference to them
remains. Weak reference are stored on the document and any reference
that can not be upgraded anymore (hence no strong reference remain)
are automatically discarded.
Currently, the selection is not saved/restored when completion
checkpoints are applied. This is usually fine because undoing changes
usually restores maps selections back in insert mode. But this is not
always the case and especially problematic in the presence of
multi-cursor completions (since completions are applied relative to
the selection/cursor) and snippets (which can change the selection)
* LSP: Support textDocument/prepareRename
'textDocument/prepareRename' can be used by the client to ask the
server the range of the symbol under the cursor which would be changed
by a subsequent call to 'textDocument/rename' with that position.
We can use this information to fill the prompt with an accurate prefill
which can improve the UX for renaming symbols when the symbol doesn't
align with the "word" textobject. (We currently use the "word"
textobject as a default value for the prompt.)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
* clippy fixes
* rustfmt
* Update helix-term/src/commands/lsp.rs
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
* Update helix-term/src/commands/lsp.rs
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
* fix clippy from suggestions
* Update helix-term/src/commands/lsp.rs
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
* use max_line_width + 1 during softwrap to account for newline char
Helix softwrap implementation always wraps lines so that the newline
character doesn't get cut off so he line wraps one chars earlier then
in other editors. This is necessary, because newline chars are always
selecatble in helix and must never be hidden.
However That means that `max_line_width` currently wraps one char
earlier than expected. The typical definition of line width does not
include the newline character and other helix commands like `:reflow`
also don't count the newline character here.
This commit makes softwrap use `max_line_width + 1` instead of
`max_line_width` to correct the impedance missmatch.
* fix typos
Co-authored-by: Jonathan Lebon <jonathan@jlebon.com>
* Add text-width to config.toml
* text-width: update setting documentation
* rename leftover config item
* remove leftover max-line-length occurrences
* Make `text-width` optional in editor config
When it was only used for `:reflow` it made sense to have a default
value set to `80`, but now that soft-wrapping uses this setting, keeping
a default set to `80` would make soft-wrapping behave more aggressively.
* Allow softwrapping to ignore `text-width`
Softwrapping wraps by default to the viewport width or a configured
`text-width` (whichever's smaller). In some cases we only want to set
`text-width` to use for hard-wrapping and let longer lines flow if they
have enough space. This setting allows that.
* Revert "Make `text-width` optional in editor config"
This reverts commit b247d526d69adf41434b6fd9c4983369c785aa22.
* soft-wrap: allow per-language overrides
* Update book/src/configuration.md
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
* Update book/src/languages.md
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
* Update book/src/configuration.md
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
---------
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Co-authored-by: Jonathan Lebon <jonathan@jlebon.com>
Co-authored-by: Alex Boehm <alexb@ozrunways.com>
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
* Do not add intermediate lines to jumplist with :<linenum> command.
* Revert jumplist index changes.
* Reduce calculations during update cycle.
* Use jumplist for undo, set jumplist before preview.
* remove some debug logging
* Revert "remove some debug logging"
This reverts commit 5772c4327e7121c53ea0726a4d7333ae1c413ffb.
* Revert "Use jumplist for undo, set jumplist before preview."
This reverts commit f73a1b29824feaf16477b9df547fb28d9db81923.
* Add last_selection, update implementation.
* @pascalkuthe initial feedback
* Ensure ":goto 123" keybinding works as expected.
* fix clippies, prefer expect() for expect last_selection state
This fixes blank row text in a DynamicPicker which is initially given
no options. This can happen for language servers which respond to
the workspace symbol request for an empty query with an empty list
of symbols, and that behavior is somewhat common since returning all
symbols as the spec suggests is very expensive.
For empty options, `Picker::new` calculated the widths of each column
as 0. We can recalculate the column widths when the new options are
set to fix this. This refactor is also a good opportunity to formalize
setting new options on a picker: besides setting the new options and
calculating column widths we also want to reset the cursor and rescore
the options.
Previously we did not respond to malformed or unhandled LSP requests.
The JSONRPC spec says that all non-notification requests must have
responses:
> When a rpc call is made, the Server MUST reply with a Response,
> except for in the case of Notifications
(Note that Helix is the "Server" in this case. Also from the spec:
"The Server is defined as the origin of Response objects and the
handler of Request objects.")
So this change sends error replies for requests which can't be parsed
or handled. Request IDs are also now added to the log messages for
unhandled requests.
In my testing this takes around 3-4ms in terminals that support the
enhanced keyboard protocol (Kitty, WezTerm) and a few hundred
microseconds in terminals that don't (st, Alacritty).
Wether the host terminal supports keyboard enhancement can be cached
for the lifetime of a Helix session.
Caching this lookup prevents a potential lockup within crossterm's
event reading system where the query for the keyboard enhancement
support waits on the next keyboard event, which can happen if the
crossterm event stream is checked by `tokio::select!` in another
thread.
This moves the `Application::claim_term` and
`helix-term::application::restore_term` functions into the helix-tui
crate. How the terminal should be claimed and restored is a TUI concern
and is implemented differently through different TUI backends.
This cleans out a lot of crossterm and TUI code in Application and
makes it easier to modify claim/restore based on information we query
from the terminal host. The child commit will take advantage of this
to cache the check for whether the host terminal supports the keyboard
enhancement protocol. Without this change, caching that information
takes much more code which is not easily reusable for anything else.
The code to restore the terminal is somewhat duplicated by this patch:
we want to restore the terminal in cases of panics. Panic handler hooks
must live for `'static` and the Application's terminal does not.
This refactors the snippet logic to be largely unaware of the rest of
the document. The completion application logic is moved into
generate_transaction_from_snippet which is extended to support
dynamically computing replacement text.
When accepting a snippet completion we automatically delete the
placeholders for now as doing so manual is quite cumbersome. In the
future we should keep these as a mark + virtual text that is
automatically removed once the cursor moves there.
Parser-combinators are one of the simpler tools for building ad-hoc
parsers. They're a good fit because they are...
* Small: each parser / parser-combinator is around 10 LOC.
* Functional: helix_core strives to be a functional set of utilities
usable throughout the rest of the editor.
* Flexible: use them to build any sort of ad-hoc parser. In the child
commit, we'll parse LSP Snippet syntax using these new parser
combinators.
Why not use an existing parser-combinator crate? Existing popular
parser-combinator crates have histories of making breaking changes
(for example nom and combine).
> Implementation note: I tried to not introduce a new trait since the
> types can be expressed in terms of `impl Fn`s. The trait is necessary
> to build `seq` implementations without a proc macro though, and also
> allows us to use `&'static str`s very conveniently: see the trait
> implementation for `&'static str`.
Tree-sitter has some unreleased improvements that can speed up small
queries and prevent hangs due to error recovery in some parsers. This
change pins tree-sitter to the latest master.
Neovim also pins tree-sitter to a commit on master.