Commit Graph

96 Commits (e20886dd6058a0b31fb99fb71a523b2ec3dfec64)

Author SHA1 Message Date
Michael Davis 9059c65a53
lsp: Check server provider capabilities (#3554)
Language Servers may signal that they do not support a method in
the initialization result (server capabilities). We can check these
when making LSP requests and hint in the status line when a method
is not supported by the server. This can also prevent crashes in
servers which assume that clients do not send requests for methods
which are disabled in the server capabilities.

There is an existing pattern the LSP client module where a method
returns `Option<impl Future<Output = Result<_>>>` with `None` signaling
no support in the server. This change extends this pattern to the rest
of the client functions. And we log an error to the statusline for
manually triggered LSP calls which return `None`.
2 years ago
Michael Davis 89efb4f711
lsp: Resolve completion item asynchronously on idle-timeout (#4781)
d7d0d5ffb7 resolves completion items on
the idle-timeout event. The `Completion::resolve_completion_item`
function blocks on the LSP request though, which blocks the compositor
and in turn blocks the event loop. So until the language server returns
the resolved completion item, Helix is unable to respond to keypresses
or other LSP messages.

This is typically ok since the resolution request is fast but for some
language servers this can be problematic, and ideally we shouldn't be
blocking like this anyways.

When receiving a `completionItem/resolve` request, the Volar server
sends a `workspace/configuration` request to Helix and blocks itself
on the response, leading to a deadlock. Eventually the resolve request
times out within Helix but Helix is locked up and unresponsive in that
window.

This change resolves the completion item without blocking the
compositor.
2 years ago
Matthias Deiml dee5b2a983
Add LSP workspace command picker (#3140)
* Add workspace command picker

* Make command typable

* Add optional argument to lsp-workspace-command
2 years ago
Blaž Hrastnik 13126823f8
lsp: Support insertReplace
Fixes #4473
2 years ago
ath3 7c9809eeb2
Find workspace from document path (#3553) 2 years ago
Riccardo Binetti 888f4fef6f
Split helix_core::find_root and helix_loader::find_local_config_dirs (#3929)
* Split helix_core::find_root and helix_loader::find_local_config_dirs

The documentation of find_root described the following priority for
detecting a project root:
- Top-most folder containing a root marker in current git repository
- Git repository root if no marker detected
- Top-most folder containing a root marker if not git repository detected
- Current working directory as fallback

The commit contained in https://github.com/helix-editor/helix/pull/1249
extracted and changed the implementation of find_root in find_root_impl,
actually reversing its result order (since that is the order that made
sense for the local configuration merge, from innermost to outermost
ancestors).

Since the two uses of find_root_impl have different requirements (and
it's not a matter of reversing the order of results since, e.g., the top
repository dir should be used by find_root only if there's not marker in
other dirs), this PR splits the two implementations in two different
specialized functions.

In doing so, find_root_impl is removed and the implementation is moved
back in find_root, moving it closer to the documented behaviour thus
making it easier to verify it's actually correct

* helix-core: remove Option from find_root return type

It always returns some result, so Option is not needed
2 years ago
Michael Davis 672ea98b05
Advertise WorkspaceSymbolClientCapabilities support (#3361) 2 years ago
Gokul Soumya 791bf7e50a
Add lsp signature help (#1755)
* Add lsp signature help

* Do not move signature help popup on multiple triggers

* Highlight current parameter in signature help

* Auto close signature help

* Position signature help above to not block completion

* Update signature help on backspace/insert mode delete

* Add lsp.auto-signature-help config option

* Add serde default annotation for LspConfig

* Show LSP inactive message only if signature help is invoked manually

* Do not assume valid signature help response from LSP

Malformed LSP responses are common, and these should not crash the
editor.

* Check signature help capability before sending request

* Reuse Open enum for PositionBias in popup

* Close signature popup and exit insert mode on escape

* Add config to control signature help docs display

* Use new Margin api in signature help

* Invoke signature help on changing to insert mode
2 years ago
Gokul Soumya 21b66ba068
lsp: Add workspace/applyEdit to client capabilites (#3012)
The functionality already existed, but the capability wasn't being
reported correctly to the server:

230ba264bf/helix-term/src/application.rs (L716-L728)
2 years ago
lazytanuki 096abdd19b
feat: highlight / select symbol under cursor using LSP textDocument/documentHighlight (#2738)
* feat: highlight symbol under cursor using LSP textDocument/documentHighlight

* fix: please clippy

* fix: shorter description and code style
2 years ago
Blaž Hrastnik 24f03097e3 Remove some more unwraps 2 years ago
Michael Davis 45ce1ebdb6
embed jsonrpc types from jsonrpc-core crate (#2801)
We should not depend on jsonrpc-core anymore:

* The project just announced it's no longer actively maintained[^1],
  preferring their new implementation in `jsonrpsee`.
* The types are too strict: we would benefit from removing some
  `#[serde(deny_unknown_fields)]` annotations to allow language
  servers that disrespect the spec[^2].
* We don't use much of the project. Just the types out of core.
  These are easy to embed directly into the `helix-lsp` crate.

[^1]: https://github.com/paritytech/jsonrpc/pull/674
[^2]: https://github.com/helix-editor/helix/issues/2786
2 years ago
farwyler f92a25a856
Passing extra formatting options to LSPs (#2635)
* allows passing extra formatting options to LSPs

- adds optional field 'format' to [[language]] sections in 'languages.toml'

- passes specified options the LSPs via FormattingOptions

* cleaner conversion of formatting properties

* move formatting options inside lsp::Client

* cleans up formatting properties merge
2 years ago
EmmChriss 807cdc60bf
configurable lsp request timeout (#2405) 2 years ago
matt rice db47761154
register publish_diagnostics client capability (#2241) 2 years ago
ttys3 19d042dde6
chore(lsp): check rename capabilities before send rename action (#2203) 2 years ago
Robin Jadoul 33b7483db5
Send active diagnostics to LSP when requesting code actions. (#2005)
* Send active diagnostics to LSP when requesting code actions.

This allows for e.g. clangd to properly send the quickfix code actions
corresponding to those diagnostics as options.
The LSP spec v3.16.0 introduced an opaque `data` member that would allow
the server to persist arbitrary data between the diagnostic and the code
actions request, but this is not supported yet by this commit.

* Reuse existing range_to_lsp_range functionality
2 years ago
Andrey Tkachenko dc8fef5dd3
Fixes #1991 LSP Auto-import (#2088) 2 years ago
Blaž Hrastnik 8adf0c1b3a
lsp: Implement support for workspace_folders (currently just one)
Refs #1898
2 years ago
Blaž Hrastnik 84e799f0e4
fix: Some LSPs still want rootPath, so provide it
Refs #1898
2 years ago
Triton171 f044059a2a
Implement LSP `workspace/configuration` and `workspace/didChangeConfiguration` (#1684)
* Implement LSP `workspace/configuration` request

* Implement LSP `workspace/didChangeConfiguration` notification.

* Simplify retrieval of LSP configuration

* Implement suggestions from PR discussion

Co-authored-by: Triton171 <triton0171@gmail.com>
2 years ago
Blaž Hrastnik 9712bbb23b
Use which to resolve lsp/dap binaries
This resolves the following issue: https://github.com/helix-editor/helix/discussions/962#discussioncomment-1580046
2 years ago
Blaž Hrastnik f88c077f99 Replace tendril with smartstring
Slightly smaller API surface, less dependencies.
2 years ago
Alexis Mousset 8a019b423f
Detect workspace root using language markers (#1370)
* Detect workspace root using language markers

* Avoid allocating root_markers

* Update helix-core/src/lib.rs

Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>

* Update helix-core/src/lib.rs

Co-authored-by: Kirawi <67773714+kirawi@users.noreply.github.com>

Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Co-authored-by: Kirawi <67773714+kirawi@users.noreply.github.com>
2 years ago
Gabriel Berto 5d7b5db8ab
Resolve completion item (#1315)
Co-authored-by: Gabriel Berto <gabriel.berto@pottencial.com.br>
2 years ago
Matouš Dzivjak 75a8b789d2
LSP code action commands (#1304)
* feat(lsp): codeAction commands

* Don't block on command call

* Fix lifetime of command execution

* Fix lint issues
2 years ago
CossonLeo 29e6849413
Add LSP rename_symbol (space-r) (#1011)
improve apply_workspace_edit
3 years ago
Ivan Tham 49f6c2623f
Bump lsp-types to 0.91.0 (#932) 3 years ago
Blaž Hrastnik bb47a9a0b8 fix: Fix regression where formatting would fail on null response 3 years ago
Blaž Hrastnik 37606bad47 lsp: doc.language_server() is None until initialize completes 3 years ago
Blaž Hrastnik 2793ff3832 lsp: SyncKind::Full: we need to send the whole document on each change 3 years ago
Blaž Hrastnik 800d79b584 ls: Refactor textDocument/didSave in a similar vein 3 years ago
Blaž Hrastnik 184637c55a lsp: refactor format so we stop cloning the language_server 3 years ago
Blaž Hrastnik 8744f367bd wip 3 years ago
Blaž Hrastnik 5a558e0d8e lsp: Delay requests & notifications until initialization is complete 3 years ago
Blaž Hrastnik c3a58cdadd lsp: Refactor capabilities as an async OnceCell
First step in making LSP init asynchronous
3 years ago
Blaž Hrastnik fe17b99ab3 fix: lsp: Don't consume \n\n as a single newline 3 years ago
Blaž Hrastnik 57ed5180e0 lsp: Improve line ending handling when generating TextEdit 3 years ago
Grzegorz Baranski 48e344a2a8
feat: code actions - document edits (#478)
* wip: Code actions

* fix(term): use current macro instead Context::context

* feat(lsp): set code_action capabilities

* feat(term): set SPC-a to code_action

* feat(term): wip on applying code actions

* deps: `cargo update`

* feat(term): applying code actions edits

* fix(term): cleanup of apply_edit

* fix(term): applying edits as a whole thing instead one by one

* refactor(term): move apply_edits below

* fix(term): improve unimplemented messages for further investigation

* fix(term): change code action command comment

Co-authored-by: Ivan Tham <pickfire@riseup.net>

* fix(term): add matching `}`

* fix(term): cleanup, todo!() on workspace edit

* fix(term): remove unrelated workspace_symbol_picker

* fix(term): apply cargo-clippy suggestions

* fix(term): replace todo!'s with editor.set_error

Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Co-authored-by: Ivan Tham <pickfire@riseup.net>
3 years ago
Cor Peters 0aa43902ca
Added option to provide a custom config file to the lsp. (#460)
* Added option to provide a custom config file to the lsp.

* Simplified lsp loading routine with anyhow

* Moved config to language.toml

* Fixed test case

* Cargo fmt

* Revert now-useless changes

* Renamed custom_config to config

Co-authored-by: Cor <prive@corpeters.nl>
3 years ago
Nathan Vegdahl 4efd6713c5 Work on moving code over to LineEnding instead of assuming '\n'.
Also some general cleanup and some minor fixes along the way.
3 years ago
wojciechkepka c2aad859b1 Handle language server shutdown with timeout 3 years ago
wojciechkepka d095ec15d4 Reenable `work_done_progress` capability 3 years ago
wojciechkepka 38cb934d8f Add unique id to each lsp client/server pair 3 years ago
wojciechkepka 80b4a69053 Update `client::reply` to be non async 3 years ago
wojciechkepka a6d39585d8 Add `work_done_token` as parameter to lsp methods 3 years ago
Robin 9baf1ecc90
add symbol picker (#230)
* add symbol picker

use the lsp document_symbol request

* fix errors from merging in master

* add docs for symbol picker
3 years ago
Blaž Hrastnik a8a5bcd13d
Temporarily disable workDone
Blows up on gopls because we don't handle receiving window/workDoneProgress/create method calls
3 years ago
Wojciech Kępka 098806ce2a
lsp: Display LSP progress messages (#216) 3 years ago
Ivan Tham 7cc13fefe9 Derive debug without feature
Note that this also removed those `finish_non_exhaustive()`.
3 years ago