Commit graph

286 commits

Author SHA1 Message Date
Philipp Mildenberger
2a512f7c48 Rebase cleanup/fixes and use lsp::CompletionItem in item_to_transaction directly 2023-05-18 22:25:32 +02:00
Philipp Mildenberger
521cdec5a1 Remove TODO comment in helix_lsp::Registry::restart and add doc-comment on top of function instead 2023-05-18 21:58:17 +02:00
Philipp Mildenberger
dcb07673f8 Reorder id generation for Clients to stay close to the old behavior 2023-05-18 21:58:17 +02:00
Philipp Mildenberger
56748509bd Reduce boilerplate by 'use lsp::*' in Client::supports_feature, and remove TODO comment 2023-05-18 21:58:17 +02:00
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 2023-05-18 21:58:17 +02:00
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`
2023-05-18 21:58:17 +02:00
Philipp Mildenberger
2eeac10755 Refactor doc language servers to a HashMap, and the config to use a Vec to retain order 2023-05-18 21:48:32 +02:00
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>
2023-05-18 21:48:32 +02:00
Philipp Mildenberger
4da6d8ccc7 str instead of String 2023-05-18 21:48:32 +02:00
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.
2023-05-18 21:48:30 +02:00
dependabot[bot]
d1a4bd876b
build(deps): bump tokio from 1.27.0 to 1.28.0 (#6935)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.27.0 to 1.28.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.27.0...tokio-1.28.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-02 10:17:59 +09:00
dependabot[bot]
7ea5965bd5
build(deps): bump tokio-stream from 0.1.12 to 0.1.14 (#6934)
Bumps [tokio-stream](https://github.com/tokio-rs/tokio) from 0.1.12 to 0.1.14.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Changelog](https://github.com/tokio-rs/tokio/blob/tokio-0.1.14/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-stream-0.1.12...tokio-0.1.14)

---
updated-dependencies:
- dependency-name: tokio-stream
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-02 09:59:05 +09:00
Pascal Kuthe
75f62bc86f fix didChange notifaction offset encoding 2023-04-30 20:26:40 -04:00
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
2023-04-27 16:30:15 +02:00
Daniel Sedlak
e856906f76
Fix typos (#6643) 2023-04-07 23:10:38 +08:00
Pascal Kuthe
1073dd6329
robustly handle invalid LSP ranges (#6512) 2023-04-03 10:58:50 +09:00
Pascal Kuthe
bfe8d267fe
normalize LSP workspaces (#6517) 2023-04-03 10:56:48 +09:00
Pascal Kuthe
9fe3adcff9
add option to enable/disable lsp snippets 2023-03-31 15:19:36 +09:00
Pascal Kuthe
a48d1a4abc
Prefer utf-8 over utf-32
Utf-8 support has been around for a while as an unstable feature but
utf-32 is fairly new. A bunch of LS (like rust-analyzer) added this in
a pinch, but it's pretty broken right now. The performance overhead is
not very large (still a lot better than utf-16). We can switch back
once the ecosystem has matured.
2023-03-31 15:19:32 +09:00
Pascal Kuthe
5b3dd6a678 implement proper lsp-workspace support
fix typo

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
2023-03-29 12:57:30 +09:00
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>
2023-03-29 12:57:30 +09:00
dependabot[bot]
67b7b5b109
build(deps): bump tokio from 1.26.0 to 1.27.0 (#6461)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.26.0 to 1.27.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.26.0...tokio-1.27.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-27 19:27:35 -05:00
Pascal Kuthe
f9a25a7e09 detailed snippet tests 2023-03-22 14:33:08 +09:00
Pascal Kuthe
85c9dbf603 accept bracket snippet variables without default 2023-03-22 14:33:08 +09:00
Pascal Kuthe
47420db516 accept empty snippet regex replace elements 2023-03-22 14:33:08 +09:00
Pascal Kuthe
617f09adc4 fix single-char variable names 2023-03-22 14:33:08 +09:00
Pascal Kuthe
cabb746b7d do not fail snippet parsing when control chars are not explicitly escaped 2023-03-22 14:33:08 +09:00
Pascal Kuthe
63c23d4bb0 fix typo
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-03-16 15:46:08 +09:00
Pascal Kuthe
f87299f1b7 allow empty placeholders 2023-03-16 15:46:08 +09:00
Pascal Kuthe
90348b889f revamped snippet text element parsing
Snippet text elements can contain escape sequences
that must be treated properly. Furthermore snippets
must always escape certain characters (like `}`
or `\`). The function has been updated to account
for that. `text` is now also included with
`anything` to match the grammar and can also
match empty text. To avoid infinite loops the
`non-empty` combinator has been added which is
automatically used in the `one_or_more` and
`zero_or more` combinator where the problemn would
occur.
2023-03-16 15:46:08 +09:00
Pascal Kuthe
bbf480007d always parse the entire snippet
Previously any remaining text of the snippet that could not be parsed
was ignored. This commit adds the `parse_all` function which reports
an error if any text was not consumed by the parser
2023-03-16 15:46:08 +09:00
Pascal Kuthe
7bf168dce0 set WorkspaceEditCapabilities correctly 2023-03-16 15:45:49 +09:00
Pascal Kuthe
3c9d5d0215 discard outdated diagnostics recived by the LS 2023-03-16 15:45:49 +09:00
misiasty3
db8e9f5bb2
Check language server symbol renaming support before prompting (#6257)
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2023-03-13 10:29:23 -05:00
Michael Davis
4f066b1cc6
LSP: No-op client/registerCapability requests (#6258) 2023-03-13 09:29:58 +09:00
Pascal Kuthe
171d28d2bd
indent snippets to line indent instead of completion start (#6263) 2023-03-11 11:34:43 +09:00
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
2023-03-11 11:32:14 +09:00
Pascal Kuthe
d63e570e0a treat replace/insertmode consistently, default to insert 2023-03-10 16:54:17 +09:00
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.
2023-03-10 16:54:17 +09:00
Pascal Kuthe
cdec933523 avoid allocations during snippet rendering 2023-03-10 16:54:17 +09:00
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>
2023-03-08 11:11:43 +09:00
Andrii Grynenko
8c2e447b16 Handle snippets for LSPs not providing offsets for completion 2023-03-08 10:48:35 +09:00
Andrii Grynenko
0d924255e4 Add nested placeholder parsing for LSP snippets
And fix `text` over-parsing, inspired by
d18f8d5c2d/runtime/lua/vim/lsp/_snippet.lua
2023-03-08 10:48:35 +09:00
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.
2023-03-08 10:48:35 +09:00
Urgau
ec6e575a40 Correctly handle multiple cursors with LSP snippets 2023-03-08 10:48:35 +09:00
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.
2023-03-08 10:48:35 +09:00
Urgau
ded4381728 Implement LSP snippet tabstops sorting and merging 2023-03-08 10:48:35 +09:00
Michael Davis
d2af31b916 LSP: Advertise snippet support 2023-03-08 10:48:35 +09:00
Michael Davis
b9b1ec2208 Apply snippets as transactions 2023-03-08 10:48:35 +09:00
Urgau
e973b71c83 Optimize LSP snippet parsing 2023-03-08 10:48:35 +09:00