Commit Graph

209 Commits

Author SHA1 Message Date
Michael Lingelbach
3800615da9
fix(lsp): handle insertion of previous line (#17618) 2022-03-06 07:52:11 -08:00
Michael Lingelbach
a5e475fcc2
fix(lsp): start incremental sync range at previous newline character (#17610)
This change forces the start of an incremental sync range to begin always on an existing line.
2022-03-05 09:17:56 -08:00
David Shen
5d6006f9bf
feat(diagnostic): add "code" to the diagnostic structure (#17510) 2022-03-02 18:42:27 -07:00
TJ DeVries
991e472881 feat(lua): add api and lua autocmds 2022-02-27 22:04:55 +01:00
Edmund Cape
300b009f47 fix(healthcheck): handle empty reports 2022-02-09 10:18:22 +08:00
zeertzjq
a87ecf5d08 fix(health): do not run external processes in a shell 2022-02-03 18:38:37 +08:00
Michael Lingelbach
bc722c8a74
fix(lsp): strictly enforce passing offset encoding (#17049)
This removes the "fallback" to utf-16 in many of our helper functions. We
should always explicitly pass these around when possible except in two
locations:

* generating params with help utilities called by buf.lua functions
* the buf.lua functions themselves

Anything that is called by the handler should be passed the offset encoding.
2022-01-13 02:34:04 -08:00
Mathias Fußenegger
e7cd811567
fix(lsp): handle negative activeSignature in signatureHelp (#17064)
omnisharp-roslyn can send negative values:

    {
      activeParameter = 0,
      activeSignature = -1,
      signatures = { {
          documentation = "",
          label = "TestEntity.TestEntity()",
          parameters = {}
        } }
    }

In 3.16 of the specification `activeSignature` is defined as `uinteger`
and therefore negative values shouldn't be allowed, but within 3.15 it
was defined as `number` which makes me think we can be a bit lenient in
this case and handle them.

The expected behavior is quite clear:

    The active signature. If omitted or the value lies outside the
    range of `signatures` the value defaults to zero or is ignored if
    the `SignatureHelp` has no signatures.

Fixes an error:

    util.lua:1685: attempt to get length of local 'lines' (a nil value)
    util.lua:1685: in function 'trim_empty_lines'
    handlers.lua:334: in function 'textDocument/signatureHelp'
2022-01-13 01:47:36 -08:00
hrsh7th
43ef7df22d
fix(lsp): fix applying multiple out-of-range TextEdits (#17037) 2022-01-13 10:28:13 +01:00
Mathias Fußenegger
074b033e7e
refactor(lsp): debounce timer per buf and unify with non-debounce (#17016)
Part of the `pending_change` closure in the `changetracking.prepare` was
a bit confusing because it has access to `bufnr` and `uri` but it could
actually contain pending changes batched for multiple buffers.

(We accounted for that by grouping `pending_changes` by a `uri`, but
it's not obvious what's going on)

This commit changes the approach to do everything per buffer to avoid
any ambiguity.

It also brings the debounce/no-debounce a bit closer together: The
only difference is now whether a timer is used or if it is triggered
immediately
2022-01-11 18:10:29 +01:00
Michael Lingelbach
55a59e56ed
feat(lsp): enable default debounce of 150 ms (#16908) 2022-01-05 08:36:35 -08:00
Michael Lingelbach
1b04da52b3
feat(lsp): add buf_detach_client (#16250)
This allows the user to detach an active buffer from the language
client. If no clients remain attached to a buffer, the on_lines callback
is used to cancel nvim_buf_attach.
2021-12-21 10:53:34 -08:00
matveyt
734fba0d88
feat(runtime): new checkhealth filetype (#16660) 2021-12-18 09:14:42 -07:00
Rishikesh Vaishnav
36c401db24
fix(lsp): correctly align start and end range to codepoints during incremental sync (#16670)
Closes #16624

Fixes two issues with aligning the start position and end position to
codepoints when calculating the start and end range.

When aligning the start position:
* use aligned byte index to calculate character index rather than 
  the unadjusted byte

When aligning the end position:
* do not adjust the end byte if it falls on a UTF-8 codepoint
* align byte to the first byte of the next codepoint rather than the
  last byte of the current codepoint
* compute character character end range on the aligned byte index

This commit also adds additional test coverage, including multibyte operations
that previously failed before this commit.
2021-12-17 18:05:00 -08:00
Michael Lingelbach
a2749482d9
chore(lsp): clean up initialization process (#16369)
* send vim.NIL instead of not sending workspaceFolders
* read fallback rootPath and rootUri from workspaceFolders
* update documentation
2021-11-21 11:39:30 -05:00
Michael Lingelbach
f71be1f87b
fix(lsp): improve incremental sync robustness (#16358)
closes https://github.com/neovim/neovim/issues/16352

* improve handling of multi-byte deletions
2021-11-18 16:49:46 -05:00
Michael Lingelbach
87a053f126
fix(lsp): fix edge cases in incremental sync (#16308) 2021-11-15 08:51:30 -08:00
Mathias Fußenegger
ee3a58d42e
fix(lsp): ensure buffers are re-attached on rename (#16266)
If a LSP server sent a workspace edit containing a rename the buffers
file name changed without the server receiving a close notification for
the old buffer and without the client properly re-attaching on the new
file.

This affected `Move` code-actions in nvim-jdtls, but also
`vim.lsp.buf.rename` on a class level.
2021-11-14 12:55:16 +01:00
Michael Lingelbach
2ecf0a4c61
fix(lsp): rewrite incremental sync (#16252)
* use codeunits/points instead of byte ranges when applicable
* take into account different file formats when computing range and
  sending text (dos, unix, and mac supported)
* add tests of incremental sync
2021-11-09 14:37:48 -08:00
Sebastian Lyng Johansen
16d4af6d2f
feat(ui): add vim.ui.input and use in lsp rename (#15959)
* vim.ui.input is an overridable function that prompts for user input
* take an opts table and the `on_confirm` callback, see `:help vim.ui.input` for more details
* defaults to a wrapper around vim.fn.input(opts)
* switches the built-in client's rename handler to use vim.ui.input by default
2021-11-07 07:13:53 -08:00
Gregory Anders
03b805aee6
feat(lua): enable stack traces in error output (#16228) 2021-11-06 08:26:10 -06:00
Michael Lingelbach
519d8deb08
feat(lsp): add per-client commands (#16101) 2021-11-01 03:14:59 -07:00
Gregory Anders
e921e98ce3
refactor(diagnostic): make display handlers generic (#16137)
Rather than treating virtual_text, signs, and underline specially,
introduce the concept of generic "handlers", of which those three are
simply the defaults bundled with Nvim. Handlers are called in
`vim.diagnostic.show()` and `vim.diagnostic.hide()` and are used to
handle how diagnostics are displayed.
2021-10-29 18:47:34 -07:00
jdrouhard
d1c470957b
feat(lsp): track pending+cancel requests on client object #15949 2021-10-29 05:45:01 -07:00
hrsh7th
bd2f61c6c4
fix(lsp): fix cursor row after textEdits (#16038) 2021-10-18 11:49:33 -07:00
Christian Clason
fbc5b7b090 chore(test): adapt healthcheck test to new css syntax
The runtime file update
2286304cdb
added a `syn keyword` for `css`, which affects (via `html` and
`markdown` syntax files) the highlighting of `:checkhealth` output
(before, `ERROR:` was highlighted with `healthError`; now the colon is
no longer included).
2021-10-16 19:17:28 +02:00
Michael Lingelbach
d288daac2b
fix(lsp): do not invoke handlers for unsupported methods (#15926)
Closes https://github.com/neovim/neovim/issues/15174

Instead of invoking handlers with unsupported methods, pre-compute which
clients support a given method and only notify the user if no clients
support the given method.
2021-10-10 22:32:50 -07:00
Michael Lingelbach
4f4dbfe81c
fix(lsp): update tests using 0.5.0 handler calls (#15969)
Fixes test regression introduced in https://github.com/neovim/neovim/pull/15262
2021-10-08 14:01:55 -07:00
Rishikesh Vaishnav
3f09732195
fix(lsp): expose ContentModified error code to callbacks (#15262) 2021-10-08 11:19:33 -07:00
Javier Lopez
acd5e831b6
fix(checkhealth): mitigate issues with duplicate healthchecks #15919
* fix(runtime/health): mitigate issues with duplicate healthchecks
  Previously if a healthcheck was found as Lua and Vim it was executed
  both times.
  This new implementations prefers Lua, therefore if two are found It only
  runs the Lua one, this way a plugin can mantain both implementations the
  Lua one with the method `check()` and the autoload function `#check()`
  (for none HEAD nvim versions).
  **Note: This will require plugins to use `check()` as the function name,
  since the autoload function that wraps the lua implementation won't be
  called**
* docs(health): use spaces and don't overuse backtics

followup to #15259
2021-10-05 15:37:39 -07:00
Javier López
8b43b07333 feat(ex_checkhealth): provide function for command line completion
Move away from providing completion with ExpandRTDir to ExpandGeneric
providing the function get_healthcheck_name which caches the results for
the current command line prompt.

It does the almost the same thing the Vim function 'get_healthcheck'
implemented in 'runtime/autoload/health.vim' does.
2021-10-04 16:51:54 -05:00
Javier López
c65f956015 test(runtime/health): cover lua healthchecks
- Add tests for lua healthchecks (failure, success and submodules).
- Reword some of the test naming for improved logs readability.
- Modify render test to accomodate the changes of the health autoload function.
- Add test for :checkhealth completion of Lua healtchecks.
2021-10-04 14:28:54 -05:00
zeertzjq
b3e815094b
fix(float)!: always anchor to corner of window including border #15832
N, W, S, E are all inclusive, i.e., always anchor to the exact corner of the
window (including border). This line may also need change in this case (change
0 to -1):

This is most consistent and easiest to reason about, especially with GUIs whose
border do not need to have width/height of 1/1 in cell units.

Fix #15789
2021-10-02 17:36:24 -07:00
Justin M. Keyes
069d1de184 fix(lsp_spec): tests depended on previous session
- fix tests which accidentally depended on previous session
2021-10-02 08:26:57 -07:00
Mathias Fußenegger
ec4731d982
feat(lsp): add codeAction/resolve support (#15818)
Closes https://github.com/neovim/neovim/issues/15339 and https://github.com/neovim/neovim/issues/15828
2021-09-28 14:04:01 -07:00
Mathias Fußenegger
19a77cd5a7
feat(lsp): add client command support to codelens (#15820)
Also adds a check against the server capabilities to fix
https://github.com/neovim/neovim/issues/15183
2021-09-28 09:19:19 -07:00
Michael Lingelbach
248974a4c6
Merge pull request #14115 from mfussenegger/lsp-commands
lsp: Add a registry for client side code action commands
2021-09-22 11:42:56 -07:00
Gregory Anders
17b7968f02
fix(diagnostic): preserve fields from LSP diagnostics via user_data (#15735)
* preserve fields from LSP diagnostics via adding a user_data table to the diagnostic, which can hold arbitrary data in addition to the lsp diagnostic information.
2021-09-21 15:27:12 -07:00
Mathias Fussenegger
6c03601e3a feat(lsp): add a registry for client side code action commands
This builds on https://github.com/neovim/neovim/pull/14112 and closes
https://github.com/neovim/neovim/issues/12326
2021-09-20 22:26:00 +02:00
Mathias Fussenegger
187579fe19 feat(lsp): include original request params in handler ctx
This is mostly motivated by https://github.com/neovim/neovim/issues/12326

Client side commands might need to access the original request
parameters.

Currently this is already possible by using closures with
`vim.lsp.buf_request`, but the global handlers so far couldn't access
the request parameters.
2021-09-20 22:06:54 +02:00
hrsh7th
41cfba63cd
feat(lsp): improve vim.lsp.util.apply_text_edits (#15561)
- Fix the cursor position after applying TextEdits
- Support reversed range of TextEdit
- Invoke nvim_buf_set_text one by one
2021-09-18 13:19:21 -07:00
Gregory Anders
c13242cf47
fix(diagnostic): remove useless highlight links (#15683)
These links were actually defined backwards: the highlight groups
actually being used for display are the new "Diagnostic*" groups, so
linking the old "LspDiagnostics*" groups to these does absolutely
nothing, since there is nothing actually being highlighted with the
LspDiagnostics* groups.

These links were made in an attempt to preserve backward compatibility
with existing colorschemes. We could reverse the links to maintain this
preservation, but then that disallows us from actually defining default
values for the new highlight groups.

Instead, just remove the links and be done with the old LspDiagnostics*
highlight groups.

This is not technically a breaking change: the breaking change already
happened in #15585, but this PR just makes that explicit.
2021-09-17 08:17:54 +02:00
Gregory Anders
888a6ec6ce fix(lint): remove unused function from diagnostic spec 2021-09-16 14:40:13 -06:00
Gregory Anders
a5bbb932f9 refactor: move vim.lsp.diagnostic to vim.diagnostic
This generalizes diagnostic handling outside of just the scope of LSP.
LSP clients are now a specific case of a diagnostic producer, but the
diagnostic subsystem is decoupled from the LSP subsystem (or will be,
eventually).

More discussion at [1].

[1]: https://github.com/neovim/neovim/pull/15585
2021-09-15 14:09:47 -06:00
hrsh7th
516775e9d8
fix(lsp): correctly parse LSP snippets #15579
Fixes #15522
2021-09-14 04:31:41 -07:00
Zi How Poh
c1f573fbc9
feat(lsp): support textDocument/prepareRename (#15514) 2021-09-08 17:00:15 +02:00
Jose Alvarez
3f526feebf
fix(lsp): update workspace/applyEdit handler signature (#15573) 2021-09-05 12:48:54 -07:00
Michael Lingelbach
23fe6dba13
Merge pull request #15504 from mjlbach/feat/change-handler-signature
feat(lsp)!: change handler signature
2021-09-05 10:27:52 -07:00
Michael Lingelbach
df17d7844e feat(lsp)!: change handler signature
Previously, the handler signature was:

  function(err, method, params, client_id, bufnr, config)

In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.

In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.

Instead, this PR changes the signature of the handlers to:

  function(err, result, ctx, config)

where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.

BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
2021-09-05 10:04:30 -07:00
zeertzjq
f6e662bbe9
feat(lsp): get_border_size(): support repeating border char list #15474 2021-08-27 04:19:17 -07:00