Commit Graph

2073 Commits (main)

Author SHA1 Message Date
Matthew Toohey 207829eefe
Fix off-by-one in select symbol references (#7132) 1 year ago
Poliorcetics 8e2660b5cc
Update diagnostics correctly on LSP exit (#7111)
* chore: avoid format! call with argument when useless

* feat: also clear diagnostics for unopened documents when exiting an LSP

* feat: we already worked on `self.editor.diagnostics` no need to redo the checks
1 year ago
Szabin 70e4cdbd8e
Add command to merge non-consecutive ranges (#7053)
* Add command for merging non-consecutive ranges

* Add `merge_selections` command to book

* Simplify `merge_ranges`

Heeded the advice of @the-mikedavis to stop iterating over all ranges and simply merge the first and the last range, as the invariants of `Selection` guarantee that the list of ranges is always sorted and never empty.

* Clarify doc comment of `merge_ranges`
1 year ago
Philipp Mildenberger 2a512f7c48 Rebase cleanup/fixes and use lsp::CompletionItem in item_to_transaction directly 1 year ago
Philipp Mildenberger f45bbf165e Apply all review suggestions (doc_id -> id, error message, unnecessary if)
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
1 year ago
Philipp Mildenberger 2b746ea6fa Some minor clarity/cosmetic improvements
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
1 year ago
Philipp Mildenberger 39b9a4bba2 Add function `Editor::language_server_by_id` and refactor/simplify related code, also don't 'crash' in completion menu if language_server somehow disappeared 1 year ago
Philipp Mildenberger 3e4bac1d96 Fix lsp_restart across multiple different document scopes (language servers weren't restarted, if not of the same scope id), and fix some smaller rebase issues 1 year ago
Philipp Mildenberger 93fd79a949 Remove offset_encoding in CodeActionOrCommandItem, as it can be retrieved on demand 1 year ago
Philipp Mildenberger ff26208427 Filter language servers also by capabilities in `doc.language_servers_with_feature`
* Add `helix_lsp::client::Client::supports_feature(&self, LanguageServerFeature)`
* Extend `doc.language_servers_with_feature` to use this method as filter as well
* Add macro `language_server_with_feature!` to reduce boilerplate for non-mergeable language server requests (like goto-definition)
* Refactored most of the `find_map` code to use the either the macro or filter directly via `doc.language_servers_with_feature`
1 year ago
Philipp Mildenberger 451fe528bb Filter out already seen language servers in requests that can be sent to multiple language servers (code-action, completion, symbol pickers) 1 year ago
Philipp Mildenberger 8ab6d7be5e Use let else instead of variable and fix some error messages
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
1 year ago
Philipp Mildenberger 1d5d5dab47 Remove offset_encoding in CompletionItem 1 year ago
Philipp Mildenberger 2eeac10755 Refactor doc language servers to a HashMap, and the config to use a Vec to retain order 1 year ago
Philipp Mildenberger b1199c552b Remove symbol picker is_empty check 1 year ago
Philipp Mildenberger 58c913ce45 Simplify 'lsp_stop' command 1 year ago
Philipp Mildenberger 7d20740b5b Fix docgen and lsp-stop documentation 1 year ago
Philipp Mildenberger 60a6af1fea Remove boilerplate in the goto methods by generically composing functions 1 year ago
Philipp Mildenberger 1122928c2a Add method doc.supports_language_server for better readability 1 year ago
Philipp Mildenberger 76b5cab524 Refactored doc.language_servers and doc.language_servers_with_feature to return an iterator and refactor LanguageServerFeature handling to a HashMap (language server name maps to features)
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
1 year ago
Philipp Mildenberger 0637691eb1 Use DoubleEndedIterator instead of collect to Vec for reversing
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
1 year ago
Philipp Mildenberger dd2f74794a Fix error messages when no language server is available
Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
1 year ago
Philipp Mildenberger f9b08656f4 Fix sorting issues of the editor wide diagnostics and apply diagnostics related review suggestions
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
1 year ago
Philipp Mildenberger b6c60beb2d Remove unnecessary completion support check (likely an artifact) 1 year ago
Philipp Mildenberger 44b2b40190 Fix issue with ltex-ls, filtering params is not what we want here 1 year ago
Philipp Mildenberger 05583f8cc9 Fix hardcoded offset_encoding 1 year ago
Philipp Mildenberger 74e21e1b25 Fix some lints/docgen hints 1 year ago
Philipp Mildenberger 7d4f7eb4bd Fix 'WorkspaceConfiguration' request with empty configuration section strings 1 year ago
Philipp Mildenberger 71551d395b Adds support for multiple language servers per language.
Language Servers are now configured in a separate table in `languages.toml`:

```toml
[langauge-server.mylang-lsp]
command = "mylang-lsp"
args = ["--stdio"]
config = { provideFormatter = true }

[language-server.efm-lsp-prettier]
command = "efm-langserver"

[language-server.efm-lsp-prettier.config]
documentFormatting = true
languages = { typescript = [ { formatCommand ="prettier --stdin-filepath ${INPUT}", formatStdin = true } ] }
```

The language server for a language is configured like this (`typescript-language-server` is configured by default):

```toml
[[language]]
name = "typescript"
language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "typescript-language-server" ]
```

or equivalent:

```toml
[[language]]
name = "typescript"
language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "efm-lsp-prettier" ]
```

Each requested LSP feature is priorized in the order of the `language-servers` array.
For example the first `goto-definition` supported language server (in this case `typescript-language-server`) will be taken for the relevant LSP request (command `goto_definition`).

If no `except-features` or `only-features` is given all features for the language server are enabled, as long as the language server supports these. If it doesn't the next language server which supports the feature is tried.

The list of supported features are:

- `format`
- `goto-definition`
- `goto-declaration`
- `goto-type-definition`
- `goto-reference`
- `goto-implementation`
- `signature-help`
- `hover`
- `document-highlight`
- `completion`
- `code-action`
- `workspace-command`
- `document-symbols`
- `workspace-symbols`
- `diagnostics`
- `rename-symbol`
- `inlay-hints`

Another side-effect/difference that comes with this PR, is that only one language server instance is started if different languages use the same language server.
1 year ago
Ivan Gulakov 2cccb3f09c
Fix completion on paths containing spaces (#6779)
There was an issue with autocompletion of a path with a space in it.

Before:

:o test\ dir -> <TAB> -> test\ dirfile1

After:

:o test\ dir -> <TAB> -> test\ dir\file1
1 year ago
Pascal Kuthe b0705337be automatically disable TS when parsing takes longer than 500ms 1 year ago
Pascal Kuthe 2f2306475c async picker syntax highlighting 1 year ago
Pascal Kuthe 25d4ebe30d don't move cursor while forward deleting in append mode
Currently, when forward deleting (`delete_char_forward` bound to `del`,
`delete_word_forward`, `kill_to_line_end`) the cursor is moved to the
left in append mode (or generally when the cursor is at the end of the
selection). For example in a document `|abc|def`  (|indicates selection)
if enter append mode the cursor is moved to `c` and the selection
becomes: `|abcd|ef`. When deleting forward (`del`) `d` is deleted. The
expectation would be that the selection doesn't shrink so that `del`
again deletes `e` and then `f`. This would look as follows:

`|abcd|ef`
`|abce|f`
`|abcf|`
`|abc |`

This is inline with how other editors like kakoune work.
However, helix currently moves the selection backwards leading to the
following behavior:

`|abcd|ef`
`|abc|ef`
`|ab|ef`
`ef`

This means that `delete_char_forward` essentially acts like
`delete_char_backward` after deleting the first character in append
mode.

To fix the problem the cursor must be moved to the right while deleting
forward (first fix in this commit). Furthermore, when the EOF char is
reached a newline char must be inserted (just like when entering
appendmode) to prevent the cursor from moving to the right
1 year ago
Pascal Kuthe 2c3ccc3e8b cleanup delete_by_selection_insert_mode function 1 year ago
Pascal Kuthe f8225ed921 fix panic when deleting overlapping ranges
Some deletion operations (especially those that use indentation)
can generate overlapping deletion ranges when using multiple cursors.
To fix that problem a new `Transaction::delete` and
`Transaction:delete_by_selection` function were added. These functions
merge overlapping deletion ranges instead of generating an invalid
transaction. This merging of changes is only possible for deletions
and not for other changes and therefore require its own function.

The function has been used in all commands that currently delete
text by using `Transaction::change_by_selection`.
1 year ago
Pascal Kuthe 6842fd4c36 clarify comments about completion savepoints
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
1 year ago
Pascal Kuthe 28b730381c only resolve completion items once 1 year ago
Pascal Kuthe 9c558fc470 ensure correct trigger/start completion offset
When re requesting a completion that already has a selected item we
reuse that selections savepoint. However, the selection has likely
changed since that savepoint which requires us to use the selection
from that savepoint
1 year ago
Pascal Kuthe 30ff7f8db2 resolve completions before applying transactions 1 year ago
Pascal Kuthe 5406e9f629 correctly handle completion rerequest 1 year ago
A-Walrus d5fe08ddb8
Replace DAP vars popup, instead of adding new (#7034) 1 year ago
ZJPzjp 3b8c15618f
Fix warnings from clippy (#7013)
* Fix warnings from clippy

* revert MAIN_SEPARATOR_STR
1 year ago
Kitsu 92c328c088
Add wbc and wbc! commands (#6947) 1 year ago
Alexis-Lapierre b0b3f45b80
Conserve BOM and properly support UTF16 (#6497) 1 year ago
Evgeniy Tatarkin 6a1bb81f10
Sort the buffer picker by most recent access (#2980) 1 year ago
Timothy DeHerrera 9c6c63a2be
inject language based on file extension & shebang (#3970)
* inject language based on file extension

Nodes can now be captured with "injection.filename". If this capture
contains a valid file extension known to Helix, then the content will
be highlighted as that language.

* inject language by shebang

Nodes can now be captured with "injection.shebang". If this capture
contains a valid shebang line known to Helix, then the content will
be highlighted as the language the shebang calls for.

* add documentation for language injection

* nix: fix highlights

The `@` is now highlighted properly on either side of the function arg.

Also, extending the phases with `buildPhase = prev.buildPhase + ''''`
is now highlighted properly.

Fix highlighting of `''$` style escapes (requires tree-sitter-nix bump)

Fix `inherit` highlighting.

* simplify injection_for_match

Split out injection pair logic into its own method to make the overall
flow easier to follow.

Also transform the top-level function into a method on a
HighlightConfiguration.

* markdown: add shebang injection query
1 year ago
jorge 204d1eba4b
feat(commands): add clear-register typable command (#5695)
Co-authored-by: Jorge <chorcheus@tutanota.com>
1 year ago
Vitalii Solodilov 2836ea2ac4
feat: add a config option to exclude declaration from LSP references (#6886)
* feat: added the config option to exclude declaration from reference query

Fixes: #5344

* fix: review

* fix: review
1 year ago
Pascal Kuthe 8f1671eaaa
fix panic in inlay hint computation when view anchor is out of bounds (#6883) 1 year ago
Dimitri Sabadie 096ed0ced4
Add extend_to_first_nonwhitespace (#6837)
Closes #6836
1 year ago
Atticus Sebastiani 228a4af35f
make `:u` alias `:update` (#6835)
* Gave the command update the alias u

* Re added trailing newline

* generated docs
1 year ago
Michael Davis ee7413a3fd
tui: Allow toggling mouse capture at runtime (#6675)
This picks up changes to the `editor.mouse` option at runtime - either
through `:set-option` or `:config-reload`. When the value changes, we
tell the terminal to enable or disable mouse capture sequences.
1 year ago
Pascal Kuthe c3e2db77f7
flip symbol range in LSP goto commands (#6794) 1 year ago
shem 1b016a89d5
Fix crash on opening from suspend state (#6764)
* Fix crash on opening from suspend state (#6725)

* Fix code style

* revert using of the imperative code style. Add panic if couldn't set terminal raw mode

* remove redundant import of core::panic macros

* small refactoring
1 year ago
Aleksey Kuznetsov 7706ff77eb
make :toggle-option print the new value (#6774)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
1 year ago
shem 9f680c69f4
Fix #6669: Theme preview doesn't return theme to normal (#6694)
* Fix #6669: Theme preview doesn't return theme to normal when delete name with Alt-Backspace

* Fix #6669: Return theme preview to normal theme for all remaining keybinds that change the promt text
1 year ago
EsfoNL 2f82bc13e8
Fix crash on opening jumplist (#6672)
Co-authored-by: Esra Fokker <esra.fokker@finalist.nl>
1 year ago
Konstantin Keller f8b7e95481
LSP: Gracefully handle 'workspace/configuration' from a stopped server (#6693) 1 year ago
Daniel Sedlak e856906f76
Fix typos (#6643) 1 year ago
Dmitry Ulyanov dd6e0cce3b
Fix line number display for LSP goto pickers (#6559)
Line numbers are 0-indexed in the LSP spec but 1-indexed for display
and jumping purposes in Helix.
1 year ago
Casper Rogild Storm 9420ba7484
Let..else refactor (#6562) 1 year ago
Pascal Kuthe 1073dd6329
robustly handle invalid LSP ranges (#6512) 1 year ago
Pascal Kuthe 9fe3adcff9
add option to enable/disable lsp snippets 1 year ago
Pascal Kuthe 7a69c40524
Hide signature help if it overlays completion menu (#5523) 1 year ago
Pascal Kuthe ab819d80f1
Correctly reload theme on :config-reload
The current implementation didn't reload the theme if no no theme was
explicitly configured (so the default theme was used). This commit
brings `refresh_theme` in line with the initialization code.
1 year ago
mWalrus e72be52996
Truncate paths in the file picker (#6410) 1 year ago
Pascal Kuthe 5b3dd6a678 implement proper lsp-workspace support
fix typo

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
1 year ago
Pascal Kuthe 2d10a429eb add workspace config and manual LSP root management
fixup documentation

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>

fixup typo

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
1 year ago
Filip Dutescu d59b80514e
feat(debug): highlight current line (#5957)
Add new theme highlight keys, for setting the colour of the breakpoint
character and the current line at which execution has been paused at.
The two new keys are `ui.highlight.frameline` and `ui.debug.breakpoint`.
Highlight according to those keys, both the line at which debugging
is paused at and the breakpoint indicator.

Add an indicator for the current line at which execution is paused
at, themed by the `ui.debug.active` theme scope. Update various themes
to showcase how the new functionality works.

Better icons are dependent on #2869, and as such will be handled in the
future, once it lands.

Closes: #5952

Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
1 year ago
Philipp Mildenberger 198ff2c3f9
Fix clippy lints (#6454) 1 year ago
Pascal Kuthe 9fac574178 do not ignore mouse scrolling when on top of virtual text 1 year ago
Pascal Kuthe 15e751b9a2 make scrolloff calculation consistent
While scrolling (with the `scroll`) command scrolloff was calculated
slightly differently than in `ensure_cursor_in_view` which could cause
the cursor to get stuck while scrolling
1 year ago
Pascal Kuthe d6c8e0c946 allow scrolling past virtual text line
Virtual text lines (either caused by softwrapped inlay hints that take
multiple or line annotations) currently block scrolling downwards.

if the visual offset passed to char_idx_at_visual_offset or
visual_offset_from_block is within a virtual text line then the char
position before the virtual text and a visual offset are returned.
We previously ignored that visual offset and as a result the cursor
would be stuck at the start of the virtual text. This commit fixes
that by simply moving the cursor to the next char (so past the virtual
text) if this visual offset is non-zero
1 year ago
Pascal Kuthe 0ab96cc257 remove incorrect assert
This assert was added during early development of #5420 and makes no
sense with the current code. We simply forgot to remove it.
1 year ago
Francesc Elies 05ee673197
Show diagnostic codes for LSP diagnostics (#6378)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
1 year ago
sarah 28632c6cee
Run shell commands asynchronously (#6373) 1 year ago
exp80 770496511c
Fix highlighting in picker with multiple columns (#6333) 1 year ago
Pascal Kuthe b6a4927f00 discard outdated workspace edits recived from the LS 1 year ago
Pascal Kuthe 3c9d5d0215 discard outdated diagnostics recived by the LS 1 year ago
Thomas Schollenberger 2a27d1b505
Prevent whitespace from rendering inside inlay hints (#6312)
* fix spaces and nbsps showing in inlay hints

* remove origin

* virtual tab + fix unneeded clone

* update virtual tab determining location

* fix clippy lint
1 year ago
Blaž Hrastnik 75ebc1fcbc
fix compilation 1 year ago
Kyle Smith 27aa919f1c
Only complete appropriate arguments for typed commands. (#5966) 1 year ago
Jonatan Pettersson d479adfdc6
Add undercurl config option #6196 (#6253)
If set to 'true' this option will force terminal undercurl support.
1 year ago
Francesc Elies d15f9721a5
LSP: Separate diagnostic picker message and code (#6095) 1 year ago
misiasty3 db8e9f5bb2
Check language server symbol renaming support before prompting (#6257)
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
1 year ago
Cole Helbling 34934733b3
helix-term: send the STOP signal to all processes in the process group (#3546)
* helix-term: send the STOP signal to all processes in the process group

From kill(3p):

    If pid is 0, sig shall be sent to all processes (excluding an unspecified set
    of  system processes) whose process group ID is equal to the process group ID
    of the sender, and for which the process has permission to send a signal.

This fixes the issue of running `git commit`, attempting to suspend
helix with ^Z, and then not regaining control over the terminal and
having to press ^Z again.

* helix-term: use libc directly to send STOP signal

* helix-term: document safety of libc::kill

* helix-term: properly handle libc::kill's failure

I misread the manpage for POSIX `kill` -- it returns `-1` in
the failure case, and sets `errno`, which is retrieved via
`std::io::Error::last_os_error()`, has its string representation printed
out, and then exits with the matching status code (or 1 if, for whatever
reason, there is no matching status code).

* helix-term: expand upon why we need to SIGSTOP the entire process group

Also add a link back to one of the upstream issues.
1 year ago
Michael Davis 4f066b1cc6
LSP: No-op client/registerCapability requests (#6258) 1 year ago
Pascal Kuthe 171d28d2bd
indent snippets to line indent instead of completion start (#6263) 1 year ago
Poliorcetics bdcd4d9411
Feat: LSP Type Hints (#5934)
* misc: missing inline, outdated link

* doc: Add new theme keys and config option to book

* fix: don't panic in Tree::try_get(view_id)

Necessary for later, where we could be receiving an LSP response
for a closed window, in which case we don't want to crash while
checking for its existence

* fix: reset idle timer on all mouse events

* refacto: Introduce Overlay::new and InlineAnnotation::new

* refacto: extract make_job_callback from Context::callback

* feat: add LSP display_inlay_hint option to config

* feat: communicate inlay hints support capabilities of helix to LSP server

* feat: Add function to request range of inlay hint from LSP

* feat: Save inlay hints in document, per view

* feat: Update inlay hints on document changes

* feat: Compute inlay hints on idle timeout

* nit: Add todo's about inlay hints for later

* fix: compute text annotations for current view in view.rs, not document.rs

* doc: Improve Document::text_annotations() description

* nit: getters don't use 'get_' in front

* fix: Drop inlay hints annotations on config refresh if necessary

* fix: padding theming for LSP inlay hints

* fix: tracking of outdated inlay hints should not be dependant on document revision (because of undos and such)

* fix: follow LSP spec and don't highlight padding as virtual text

* config: add some LSP inlay hint configs
1 year ago
Dimitar Gyurov 1661e4b5e1
Add a version-control statusline element (#5682) 1 year ago
Pascal Kuthe d63e570e0a treat replace/insertmode consistently, default to insert 1 year ago
Pascal Kuthe b1f7528090 fix snippet bugs and multicursor completion edgecases
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.
1 year ago
Taylor C. Richberger 9b4326b18b allow LSP insert text to replace non-matching prefixes (#5469)
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.
1 year ago
paul-scott ce1fb9e64c
Generalised to multiple runtime directories with priorities (#5411)
* 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>
1 year ago
gibbz00 2cf4ce2356
Fix `shrink_selection` with multiple cursors. (#6093)
* 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.
1 year ago
Pascal Kuthe aabc8af95d correctly store snapshots when repeating insert-mode actions
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.
1 year ago
Pascal Kuthe 8cb7cdfd7a discard stale completion requests
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.
1 year ago
Pascal Kuthe e8898fd9a8 store multiple snapshots on the document at once
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.
1 year ago
Pascal Kuthe 2588fa3710 save selection before completion savepoint
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)
1 year ago
Pascal Kuthe 4300a3ad05 create savepoint before requesting completion 1 year ago
Kyle Smith 44ff8a1df1
LSP: Support textDocument/prepareRename (#6103)
* 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>
1 year ago
Clément Delafargue 8dd1ab4899
Softwrapping improvements (#5893)
* 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>
1 year ago
Kyle Smith f4bdbe4674
Do not add intermediate lines to jumplist with :<linenum> command. (#5751)
* 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
1 year ago
Michael Davis 0c6d25acae
DynamicPicker: Recalculate column widths for new options (#6004)
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.
1 year ago
Michael Davis 6dc017b9e2
Jump to symbol ranges in LSP goto commands (#5986)
This follows prior changes like 42ad1a9e: we select the range given
by the language server rather than the starting point.
1 year ago
Michael Davis 170593161c
LSP: Send replies for malformed and unhandled RPC requests (#6058)
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.
1 year ago
Michael Davis 3d85024717 Move terminal claim/restore code to helix-tui
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.
1 year ago
Pascal Kuthe 48b6aa9a69
Add command for resetting diff hunks (#5736) 1 year ago
Andrii Grynenko 8c2e447b16 Handle snippets for LSPs not providing offsets for completion 1 year ago
Andrii Grynenko 1866b43cd3 Render every LSP snippets for every cursor
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.
1 year ago
Pascal Kuthe ba24cfe912 Delete snippet placeholders when accepting completion
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.
1 year ago
Michael Davis b9b1ec2208 Apply snippets as transactions 1 year ago
Davide Galassi f976c004e2
Allow LSP server to be stopped (#5964) 1 year ago
Filip Dutescu 376c19e06b
feat(dap): implement Restart request (#5651)
Add a restart debug session command, which would issue a
[Restart Request][1], if the debugger supports it and a session is
running. It uses the same arguments and requests used to start the
initial session, when recreating it.

It builds upon #5532, making use of the changes to the termination
workflow of a session.

[1]: https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Restart

Closes: #5594

Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
1 year ago
Santiago Vrancovich 39d5fb0e59
Remove centering view from Unimpaired commands (#6193)
Remove `align_view` calls from `goto_*_diag` as per issue #6177
1 year ago
nuid32 def26966d2
Fix lacking space panic (#6109)
* Fix lack of space for popup crash

* Fix saturating -> wrapping

* Fix wrapping -> saturating (I am an idiot)

* Remove useless "mut" in helix-tui/src/buffer.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* Remove redundant bound-check

* Return bound-check back

* Add bound-check for set_style

* Remove set_style bound-check

* Revert bound-check

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
1 year ago
Pascal Kuthe ccdb144665 update MSRV to 1.65 1 year ago
Alexander Brevig a2e54167d8
fix: Handle signals before crossterm events (#6170)
This is a workaround for a freeze when suspending Helix with C-z on
non-Windows systems. The check for the keyboard enhancement protocol
locks up crossterm's internal event reading/polling system by trying to
set up multiple concurrent readers. `input_stream.next()` sets up one
reader looking for regular crossterm events while the
`supports_keyboard_enhancement` query sets up another looking for
internal events. The latter hangs for two seconds or until the former
yields an event. By handling signals first we don't lock up the mutex
by trying to read keyboard events.
1 year ago
nuid32 ddc5bf4e60
Fix 'attempt to divide by zero' panic (#6155) 1 year ago
NomisIV c082ef2863
Fix indentation lines (#6134) (#6136) 1 year ago
Michael Davis 27211abf06
Ignore key-release keyboard events (#6139)
Since crossterm 0.26.x, we receive press/release keyboard events on
Windows always. We can ignore the release events though to emulate
the behavior of keyboard input on Windows on crossterm 0.25.x.
1 year ago
lesleyrs 8dab8a0a03 Add shift-backspace keybind alias for backspace (#4937)
When the Kitty Keyboard Protocol is enabled, S-backspace is
distinguished from backspace with no modifiers. This is awkward when
typing because it's very easy to accidentally hold shift and press
backspace temporarily when typing capital letters.

Kakoune (which is also a Kitty Keyboard Protocol application) treats
S-backspace as backspace too:
3150e9b3cd/src/input_handler.cc (L1275)
1 year ago
Michael Davis a066815833 Enable the enhanced keyboard protocol if supported 1 year ago
Filip Dutescu 44729fbaf9
fix(dap): validate key and index exist when requesting vars (#5628)
Check if the stack frames contain the thread id and the frame before
trying to get the frame id. If case any of the two fails to be
found, provide the user with messages to inform them of the issue and
gracefully return.

Closes: #5625

Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
1 year ago
Filip Dutescu e3765ac6d2
feat(dap): send Disconnect if Terminated event received (#5532)
Send a `Disconnect` DAP request if the `Terminated` event is received.
According to the specification, if the debugging session was started by
as `launch`, the debuggee should be terminated alongside the session. If
instead the session was started as `attach`, it should not be disposed of.

This default behaviour can be overriden if the `supportTerminateDebuggee`
capability is supported by the adapter, through the `Disconnect` request
`terminateDebuggee` argument, as described in
[the specification][discon-spec].

This also implies saving the starting command for a debug sessions, in
order to decide which behaviour should be used, as well as validating the
capabilities of the adapter, in order to decide what the disconnect should
do.

An additional change made is handling of the `Exited` event, showing a
message if the exit code is different than `0`, for the user to be aware
off the termination failure.

[discon-spec]: https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect

Closes: #4674

Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
1 year ago
Guillaume 78a1e2db60
feat: show current language when no argument is provided (#5895) 1 year ago
Triton171 a1a6d5f334
Replace incorrect usages of tab_width with indent_width. (#5918) 1 year ago
Erasin b7fb52d0e4
fix: decode lsp url for workspace_diagnostics_picker (#6016) 1 year ago
Jonathan LEI 9368ac76b3
Ignore invalid file URIs from LSP (#6000) 1 year ago
Pascal Kuthe c332b16855
ignore case while filtering completions (#6008) 1 year ago
Michael Davis d8526a752c
Use Popup::ignore_escape_key helper for completion (#6006)
The completion component has a separate branch for handling the
Escape key but it can use the `ignore_escape_key` helper added for
signature-help instead.

This should not cause a behavior change - it's just cleaning up the
completion component.
1 year ago
Pascal Kuthe 715c4b24d9
Fix crash in goto_window_center at EOF (#5987) 1 year ago
Matouš Dzivjak 2bebc5042e
feat(ui): deprecated completions (#5932)
* feat(ui): deprecated completions

Mark deprecated completions using strike-through
(CROSSED_OUT modifier). The deprection information
is taken either from the `deprecated` field of the
completion item or from the completion tags.

The field seems to be the older way of passing
the deprecated information and it was already
marked as deprecated for Symbol. In completion
item the field is still valid but it seems that
the LSP is moving in the general direction of using
tags for this kind of information and as such
relying on tags as well seems reasonable and
future-proof.
1 year ago
A-Walrus 8b09b00942
Add :toggle-option command (#4085)
This command toggles the value of boolean options
1 year ago
Gokul Soumya 425315d752 Fix completion doc popup area calculation logic
Earlier the doc popup would draw over the compeltion popup
itself and sometimes over the cursor too.
1 year ago
Gokul Soumya 1562b5ce67 Create popup rect instead of using raw values 1 year ago
Gokul Soumya 0f844ef191 Refactor our Markdown construction in completion doc 1 year ago
Gokul Soumya 937825e8fc Rename completion doc popup area variables 1 year ago
Gokul Soumya 8e9c329952 Use early return in rendering completion doc 1 year ago
Pascal Kuthe 93c7afc4ed
Negotiate LSP Position Encoding (#5894)
So far LSP always required that `PositionEncoding.characters` is an
UTF-16 offset. Now that LSP 3.17 is available in `lsp-types` request
the server to send char offsets (UTF-32) or byte offsets (UTF-8)
instead. For compatability with old servers, UTF-16 remains as the
fallback as required by the standard.
1 year ago
Daniel S Poulin 6929a12f29
Make `m` textobject look for pairs enclosing selections (#3344)
* Make `m` textobject look for pairs enclosing selections

Right now, this textobject only looks for pairs that surround the
cursor. This ensures that the pair found encloses each selection, which
is likely to be intuitively what is expected of this textobject.

* Simplification of match code

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* Adjust logic for ensuring surround range encloses selection

Prior, it was missing the case where the start of the selection came
before the opening brace. We also had an off-by-one error where if the
end of the selection was on the closing brace it would not work.

* Refactor to search for the open pair specifically to avoid edge cases

* Adjust wording of autoinfo to reflect new functionality

* Implement tests for surround functionality in new integration style

* Fix handling of skip values

* Fix out of bounds error

* Add `ma` version of tests

* Fix formatting of tests

* Reduce indentation levels for readability, and update comments

* Preserve each selection's direction with enclosing pair surround

* Add test case for multiple cursors resulting in overlap

* Mark known failures as TODO

* Make tests multi-threaded or they fail

* Cargo fmt

* Fix typos in integration test comments

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
1 year ago
lesleyrs af1157f37c
Add exit code to command failed msg (#5898) 1 year ago
Colton Clemmer ea3293b4da
Split modification indicator from file statusline elements (#4731) 1 year ago
Pascal Kuthe 8a3ec443f1
Fix new clippy lints (#5892) 1 year ago
Mike Trinkala 9d73a0d112
Fix the infinite loop when copying the cursor to the top of the file (#5888)
Example:
```
test
testitem
```

Select line 2 with x, then type Alt-C; Helix will go into an infinite
loop. The saturating_sub keeps the head_row and anchor_row pinned at 0,
and a selection is never made since the first line is too short.
1 year ago
Blaž Hrastnik 8a602995fa
Address new clippy lints 1 year ago
Pascal Kuthe e474779c87
bump msrv to 1.63 (#5570)
* bump msrv to 1.63

* resolve new complex type clippy lints
1 year ago
Michael Davis 23ed8c12f1
Select change range for goto_first/last_change commands (#5206)
This matches the behavior from 42ad1a9e04
but for the first and last change. The selection rules are the same
as for goto_next/prev_change: additions and modifications select the
added and modified range while deletions are represented with a point.
1 year ago
Skyler Hawthorne b2e83f81e1
enable rendering in integration tests (#5819)
This will allow testing more of the code base, as well as enable UI-
specific testing.

Debug mode builds are prohibitively slow for the tests, mostly
because of the concurrency write tests. So there is now a profile for
integration tests that sets the optimization level to 2 for a few helix
crates, and lowers the number of rounds of concurrent writes to 1000.
1 year ago
William Etheredge f7bd7b5eaf
Add :character-info command (#4000) 1 year ago