Commit Graph

484 Commits

Author SHA1 Message Date
Mathias Fußenegger
4a09c178a1
feat(lsp): fallback to code-action command on resolve failure (#25464)
The haskell-language-server supports resolve only for a subset of code
actions. For many code actions trying to resolve the `edit` property
results in an error, but the unresolved action already contains a
command that can be executed without issue.

The protocol specification is unfortunately a bit vague about this,
and what the haskell-language-server does seems to be valid.

Example:

    newtype Dummy = Dummy Int
    instance Num Dummy where

Triggering code actions on "Num Dummy" and choosing "Add placeholders
for all missing methods" resulted in:

    -32601: No plugin enabled for SMethod_CodeActionResolve, potentially available: explicit-fields, importLens, hlint, overloaded-record-dot

With this change it will insert the missing methods:

    instance Num Dummy where
      (+) = _
      (-) = _
      (*) = _
      negate = _
      abs = _
      signum = _
      fromInteger = _
2023-10-02 22:14:19 +02:00
Justin M. Keyes
de93489789 refactor(tutor): cleanup 2023-09-26 06:41:53 -07:00
Leonardo Mello
bc6fc0123d
fix(tutor): Tutor steps don't work on Windows #25251
Problem:
Some steps in :Tutor don't work on Windows.

Solution:
Add support for `{unix:...,win:...}` format and transform the Tutor contents
depending on the platform.
Fix https://github.com/neovim/neovim/issues/24166
2023-09-26 06:31:35 -07:00
Sergey Slipchenko
345bd91db2
fix(lsp): handle absence of a trailing newline #25194
Fixes #24339

rust-analyzer sends "Invalid offset" error in such cases. Some other
servers handle it specially.

LSP spec mentions that "A range is comparable to a selection in an
editor". Most editors don't handle trailing newlines the same way
Neovim/Vim does, it's clearly visible if it's present or not. With that
in mind it's understandable why sending end position as simply the start
of the line after the last one is considered invalid in such cases.
2023-09-21 03:06:40 -07:00
Maria José Solano
b2265bb72c test(lsp): add normalize_markdown tests 2023-09-20 07:00:52 +01:00
Maria José Solano
cfd4a9dfaf feat(lsp): use treesitter for stylize markdown 2023-09-19 14:47:37 +01:00
zeertzjq
054839437e
test(plugin/man_spec): use pesc() on actual_file in pattern (#25199) 2023-09-17 06:07:53 +08:00
Sergey Slipchenko
d22172f36b
fix(api): more intuitive cursor updates in nvim_buf_set_text
Fixes #22526
2023-09-11 08:16:03 +04:00
Grace Petryk
5e3cf9fb4b
feat(lsp): improve control over placement of floating windows (#24494) 2023-09-10 10:02:23 +02:00
Tom Praschan
131a1ee82d
feat(lsp): add original LSP Location as item's user_data in locations_to_items (#23743) 2023-09-07 10:12:02 +02:00
Chris AtLee
c235959fd9
fix(lsp): only disable inlay hints / diagnostics if no other clients are connected (#24535)
This fixes the issue where the LspNotify handlers for inlay_hint /
diagnostics would end up refreshing all attached clients.

The handler would call util._refresh, which called
vim.lsp.buf_request, which calls the method on all attached clients.

Now util._refresh takes an optional client_id parameter, which is used
to specify a specific client to update.

This commit also fixes util._refresh's handling of the `only_visible`
flag. Previously if `only_visible` was false, two requests would be made
to the server: one for the visible region, and one for the entire file.

Co-authored-by: Stanislav Asunkin <1353637+stasjok@users.noreply.github.com>
Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
2023-08-31 10:00:24 +02:00
Lewis Russell
abb8c2c453 fix(editorconfig): do not set 'endofline'
Problem:
  'endofline' can be used to detect if a file ends of <EOL>, however
  editorconfig can break this.

Solution:
  Set 'endofline' during BufWritePre

Fixes: #24869
2023-08-27 19:27:25 +01:00
Gregory Anders
e72c0cd920
feat(highlight): Allow hyphens (-) in highlight group names (#24714)
Fixes: https://github.com/neovim/neovim/issues/23184
2023-08-15 09:25:51 -05:00
Sean Dewar
cc87dda31a
fix(lsp): do not assume client capability exists in watchfiles check (#24550)
PR #23689 assumes `client.config.capabilities.workspace.didChangeWatchedFiles`
exists when checking `dynamicRegistration`, but thats's true only if it was
passed to `vim.lsp.start{_client}`.

This caused #23806 (still an issue in v0.9.1; needs manual backport), but #23681
fixed it by defaulting `config.capabilities` to `make_client_capabilities` if
not passed to `vim.lsp.start{_client}`.

However, the bug resurfaces on HEAD if you provide a non-nil `capabilities` to
`vim.lsp.start{_client}` with missing fields (e.g: not made via
`make_client_capabilities`).

From what I see, the spec says such missing fields should be interpreted as an
absence of the capability (including those indicated by missing sub-fields):
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities

Also, suggest `vim.empty_dict()` for an empty dict in
`:h vim.lsp.start_client()` (`{[vim.type_idx]=vim.types.dictionary}`
no longer works anyway, probably since the cjson switch).
2023-08-04 08:10:54 +02:00
Christoph Hasse
20c331915f
fix(lsp): SignatureHelp docstring is not escaped #16702
Problem:
Nvim LSP client always treats signature.documentation as markdown, even
if the server returns a plain string.
Per https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#signatureInformation
in a SignatureInformation response, the documentation field can be
either "string" or "MarkupContent".

Solution:
If signature.documentation is a string, treat it as "plaintext".

Closes #16563
2023-07-25 05:40:13 -07:00
Chris AtLee
63b3408551
feat(lsp): implement textDocument/diagnostic (#24128) 2023-07-20 09:03:48 +02:00
Mathias Fußenegger
1b9ccd38a1
feat(lsp)!: rename vim.lsp.get_active_clients to get_clients (#24113) 2023-07-17 18:27:16 +02:00
Mike
251ca45ac9
fix(lsp): markdown code fence should allow space before info string #24364
Problem:
Bash language server returns "hover" markdown content that starts with
a code fence and info string of `man` preceded by whitespace, which Nvim
does not render properly.

See 0ee73c53ce/server/src/server.ts (L821C15-L821C15)
```typescript
function getMarkdownContent(documentation: string, language?: string): LSP.MarkupContent {
  return {
    value: language
      ? // eslint-disable-next-line prefer-template
        ['``` ' + language, documentation, '```'].join('\n')
      : documentation,
    kind: LSP.MarkupKind.Markdown,
  }
}
```

For example,
```
    ``` man
    NAME
       git - the stupid content tracker
    ```
```

If I remove the white space, then it is properly formatted. 
```    
    ```man instead of ``` man
```

Per CommonMark Spec https://spec.commonmark.org/0.30/#info-string
whitespace is allowed before and after the `info string` which
identifies the language in a codeblock.
> The line with the opening code fence may optionally contain some text
> following the code fence; this is trimmed of leading and trailing
> spaces or tabs and called the [info
> string](https://spec.commonmark.org/0.30/#info-string). If the [info
> string](https://spec.commonmark.org/0.30/#info-string) comes after
> a backtick fence, it may not contain any backtick characters. (The
> reason for this restriction is that otherwise some inline code would
> be incorrectly interpreted as the beginning of a fenced code block.)

 Solution:
 Adjust stylize_markdown() to allow whitespace before codeblock info.
2023-07-16 03:11:45 -07:00
Mathias Fußenegger
33e1a8cd70
feat(lsp): map K to hover by default #24331
Related: https://github.com/neovim/neovim/issues/24252
2023-07-14 09:47:18 -07:00
Mathias Fußenegger
37079fca58
feat(lsp): move inlay_hint() to vim.lsp (#24130)
Allows to keep more functions hidden and gives a path forward for
further inlay_hint related functions - like applying textEdits.

See https://github.com/neovim/neovim/pull/23984#pullrequestreview-1486624668
2023-06-30 11:33:28 +02:00
Mathias Fußenegger
12c2c16acf
feat(lsp): opt-in to dynamicRegistration for inlay hints (#24102)
Since https://github.com/neovim/neovim/pull/23681 there is dynamic
registration support. We should use that for new features unless there
is a good reason to turn it off.
2023-06-22 19:39:57 +02:00
Sooryakiran Ponnath
3bf887f6e0
fix(lsp): always return boolean in lsp.buf_client_attach (#24077)
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2023-06-20 21:17:13 +02:00
Chinmay Dalal
ca5de9306c
feat(lsp): inlay hints #23984
Add automatic refresh and a public interface on top of #23736

 * add on_reload, on_detach handlers in `enable()` buf_attach, and
  LspDetach autocommand in case of manual detach
* unify `__buffers` and `hint_cache_by_buf`
* use callback bufnr in `on_lines` callback, bufstate: remove __index override
* move user-facing functions into vim.lsp.buf, unify enable/disable/toggle

Closes #18086
2023-06-19 23:06:54 -07:00
Jonas Strittmatter
c07dceba33
fix(lsp): allow Lua pattern chars in code action filter (#24041)
Previously, filtering code actions with the "only" option failed
if the code action kind contained special Lua pattern chars such as "-"
(e.g. the ocaml language server supports a "type-annotate" code action).

Solution: use string comparison instead of string.find
2023-06-17 08:01:31 +02:00
Chinmay Dalal
643546b82b
feat(lsp): add handlers for inlay hints (#23736)
initial support; public API left for a follow-up PR
2023-06-11 11:53:37 +02:00
Alexandre Teoi
4382d2ed56
feat(health): fold successful healthchecks #22866
Problem:
checkhealth can be noisy, but we don't want to omit info.

Solution:
Fold OK results by default, if 'foldenable' is enabled.
Resolves #22796
2023-06-06 08:42:26 -07:00
Gregory Anders
cbbda3bcd7
fix(editorconfig): check that buffer is valid (#23922)
Fixes: https://github.com/neovim/neovim/issues/23921
2023-06-05 11:53:13 -05:00
Jon Huhn
416fe8d185
refactor(lsp): use LPeg for watchfiles matching (#23788) 2023-06-05 07:19:31 +02:00
Raphael
3c6d971e54
fix(lsp): set extra info only when it has a value (#23868) 2023-06-05 07:17:38 +02:00
Folke Lemaitre
5282d3299c
fix(lsp): restore marks after apply_text_edits() #14630
PROBLEM:
Whenever any text edits are applied to the buffer, the `marks` part of those
lines will be lost. This is mostly problematic for code formatters that format
the whole buffer like `prettier`, `luafmt`, ...

When doing atomic changes inside a vim doc, vim keeps track of those changes and
can update the positions of marks accordingly, but in this case we have a whole
doc that changed. There's no simple way to update the positions of all marks
from the previous document state to the new document state.

SOLUTION:
* save marks right before `nvim_buf_set_lines` is called inside `apply_text_edits`
* check if any marks were lost after doing `nvim_buf_set_lines`
* restore those marks to the previous positions

TEST CASE:
* have a formatter enabled
* open any file
* create a couple of marks
* indent the whole file to the right
* save the file
Before this change: all marks will be removed.
After this change: they will be preserved.

Fixes #14307
2023-06-04 16:45:01 -07:00
Lewis Russell
2db719f6c2
feat(lua): rename vim.loop -> vim.uv (#22846) 2023-06-03 12:06:00 +02:00
Gregory Anders
fb54e6980e feat(lsp): set client offset_encoding if server supports positionEncoding
If the server sends the positionEncoding capability in its
initialization response, automatically set the client's offset_encoding
to use the value provided.
2023-06-01 11:34:23 -05:00
jdrouhard
58618d208a
feat(lsp)!: promote LspRequest to a full autocmd and enrich with additional data (#23694)
BREAKING CHANGE: LspRequest is no longer a User autocmd but is now a
first class citizen.

LspRequest as a User autocmd had limited functionality. Namely, the only
thing you could do was use the notification to do a lookup on all the
clients' requests tables to figure out what changed.

Promoting the autocmd to a full autocmd lets us set the buffer the
request was initiated on (so people can set buffer-local autocmds for
listening to these events).

Additionally, when used from Lua, we can pass additional metadata about
the request along with the notification, including the client ID, the
request ID, and the actual request object stored on the client's
requests table. Users can now listen for these events and act on them
proactively instead of polling all of the requests tables and looking
for changes.
2023-05-30 20:56:29 +02:00
Folke Lemaitre
ddd92a70d2
feat(lsp): initial support for dynamic capabilities (#23681)
- `client.dynamic_capabilities` is an object that tracks client register/unregister
- `client.supports_method` will additionally check if a dynamic capability supports the method, taking document filters into account. But only if the client enabled `dynamicRegistration` for the capability
- updated the default client capabilities to include dynamicRegistration for:
    - formatting
    - rangeFormatting
    - hover
    - codeAction
    - hover
    - rename
2023-05-28 07:51:28 +02:00
Famiu Haque
576dddb461 test: don't unnecessarily specify win/buf for nvim_(get|set)_option_value
`nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter.
2023-05-22 13:02:07 +06:00
Lewis Russell
1fe1bb084d refactor(options): deprecate nvim[_buf|_win]_[gs]et_option
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: famiu <famiuhaque@protonmail.com>
2023-05-21 15:14:01 +06:00
Jon Huhn
073035a030
fix(lsp): don't register didChangeWatchedFiles when capability not set (#23689)
Some LSP servers (tailwindcss, rome) are known to request registration
for `workspace/didChangeWatchedFiles` even when the corresponding client
capability does not advertise support. This change adds an extra check
in the `client/registerCapability` handler not to start a watch unless
the client capability is set appropriately.
2023-05-20 07:45:39 +02:00
Jon Huhn
075a72d5ff
fix(lsp): fix relative patterns for workspace/didChangeWatchedFiles (#23548) 2023-05-09 18:12:54 +02:00
zeertzjq
3001d86aea test: add more tests for :Man section extraction 2023-05-08 15:46:21 +08:00
Christian Clason
c8ebb04e92
fix(health): replace healthFoo with DiagnosticFoo (#23475)
This replaces the custom `health{Error,Warning,Success}` highlight
groups with `Diagnostic{Error,Warning,Ok}`, which are defined by
default. Removes the link for `healthHelp`, which was no longer
actually used after #20879.
2023-05-05 18:15:44 +02:00
zeertzjq
d321deb4a9
test: fix dependencies between test cases (#23343)
Discovered using --shuffle argument of busted.
2023-04-27 15:51:44 +08:00
jdrouhard
540d6c595b
test(lsp): fix unstable tests for semantic tokens
Add screen:expect() calls after insert() to make sure the screen has
been drawn before we assert the state of the semantic tokens table
2023-04-23 00:08:28 +02:00
dundargoc
c08b030761
refactor: deprecate checkhealth functions
The following functions are deprecated and will be removed in
Nvim v0.11:

- health#report_start()
- health#report_info()
- health#report_ok()
- health#report_warn()
- health#report_error()
- vim.health.report_start()
- vim.health.report_info()
- vim.health.report_ok()
- vim.health.report_warn()
- vim.health.report_error()

Users should instead use these:

- vim.health.start()
- vim.health.info()
- vim.health.ok()
- vim.health.warn()
- vim.health.error()
2023-04-15 23:40:48 +02:00
Michal Liszcz
3c697f62fa
test(lsp): fix unstable tests for set_defaults (#23002)
In the `test_rpc_server` procedure, both `on_setup` and `on_init`
callbacks can run concurrently in some scenarios. This caused some CI
failures in tests for the LSP set_defaults feature.

This commit attempts to fix this by merging those two callbacks in the
impacted tests.

See: https://github.com/neovim/neovim/actions/runs/4553550710/attempts/1
2023-04-11 18:37:27 +02:00
dundargoc
743860de40
test: replace lfs with luv and vim.fs
test: replace lfs with luv

luv already pretty much does everything lfs does, so this duplication
of dependencies isn't needed.
2023-04-04 21:59:06 +02:00
dundargoc
a5c572bd44
docs: fix typos
Co-authored-by: Gregory Anders <greg@gpanders.com>
Co-authored-by: Raphael <glephunter@gmail.com>
Co-authored-by: C.D. MacEachern <craig.daniel.maceachern@gmail.com>
Co-authored-by: himanoa <matsunoappy@gmail.com>
2023-04-04 19:07:33 +02:00
Lewis Russell
226a6c3eae
feat(diagnostic): add support for tags
The LSP spec supports two tags that can be added to diagnostics:
unnecessary and deprecated. Extend vim.diagnostic to be able to handle
these.
2023-03-30 14:49:58 +01:00
Jon Huhn
6a6191174a
test: fix flaky watchfiles tests (#22637) 2023-03-26 10:41:27 +01:00
Roberto Pommella Alegro
257d894d75
feat(lsp): render markdown in docs hover #22766
Problem:
LSP docs hover (textDocument/hover) doesn't handle HTML escape seqs in markdown.

Solution:
Convert common HTML escape seqs to a nicer form, to display in the float.
closees #22757

Signed-off-by: Kasama <robertoaall@gmail.com>
2023-03-25 12:46:07 -04:00
Ivan
4f7879dff0
fix(lsp): kill buffers after renaming a directory #22618
Problem:

When LSP client renames a directory, opened buffers in the edfitor are not
renamed or closed. Then `:wall` shows errors.

https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp/util.lua#L776
works correctly if you try to rename a single file, but doesn't delete old
buffers with `old_fname` is a dir.

Solution:
Update the logic in runtime/lua/vim/lsp/util.lua:rename()

Fixes #22617
2023-03-14 05:08:37 -07:00
hrsh7th
8dde7c907c
fix(lsp): vim.lsp.util.apply_text_edits cursor validation #22636
Problem
Using wrong variable when checking the cursor position is valid or not in
vim.lsp.util.apply_text_edits.

Solution
Use the correct variable.
2023-03-14 04:59:43 -07:00
Mathias Fußenegger
d15abd1be4
fix(lsp): use line start/end for visual line selection (#22632)
Fixes https://github.com/neovim/neovim/issues/22629
2023-03-12 09:45:28 +01:00
Mathias Fußenegger
d3c8d104bc
fix(lsp): prevent lsp tests from picking up local user config (#22606)
Sets `NVIM_APPNAME` for the lsp server instances and also for the
`exec_lua` environment to ensure local user config doesn't interfere
with the test cases.

My local `ftplugin/xml.lua` broke the LSP test cases about setting
`omnifunc` defaults.
2023-03-10 17:30:40 +01:00
Michal Liszcz
9ef7297ef1
feat(lsp): overwrite omnifunc/tagfunc set by ftplugin #22267
Problem:
Some built-in ftplugins set omnifunc/tagfunc/formatexpr which causes
lsp.lua:set_defaults() to skip setup of defaults for those filetypes.
For example the C++ ftplugin has:
    omnifunc=ccomplete#Complete
          Last set from /usr/share/nvim/runtime/ftplugin/c.vim line 30
so the changes done in #95c65a6b221fe6e1cf91e8322e7d7571dc511a71
will always be skipped for C++ files.

Solution:
Overwrite omnifunc/tagfunc/formatexpr options that were set by stock
ftplugin.

Fixes #21001
2023-03-09 06:12:56 -08:00
Justin M. Keyes
304477ff35 fix(man.lua): tests, naming 2023-03-07 15:23:06 +01:00
Eriks Muhins
160a019ffa feat(man.lua): support spaces in manpage names
Problem:
:Man command errors if given more than two arguments. Thus, it is
impossible to open man pages that contain spaces in their names.

Solution:
Adjust :Man so that it tries variants with spaces and underscores, and
uses the first found.
2023-03-07 15:19:24 +01:00
swarn
1cc23e1109
feat(lsp)!: add rule-based sem token highlighting (#22022)
feat(lsp)!: change semantic token highlighting

Change the default highlights used, and add more highlights per token.

Add an LspTokenUpdate event and a highlight_token function.

:Inspect now shows any highlights applied by token highlighting rules,
default or user-defined.

BREAKING CHANGE: change the default highlight groups used by semantic
token highlighting.
2023-03-06 19:03:13 +01:00
Jon Huhn
ac69ba5fa0
feat(lsp): implement workspace/didChangeWatchedFiles (#22405) 2023-03-05 07:52:27 +01:00
bfredl
7e19cabeb1 perf(lsp): only redraw the windows containing LSP tokens
redraw! redraws the entire screen instead of just the windows with
the buffer which were actually changed.

I considered trying to calculating the range for the delta
but it looks tricky. Could a follow-up.
2023-02-28 13:11:36 +01:00
Mathias Fussenegger
f0f27e9aef Revert "feat(lsp): implement workspace/didChangeWatchedFiles (#21293)"
This reverts commit 5732aa706c.

Causes editor to freeze in projects with many watcher registrations
2023-02-25 11:17:28 +01:00
Jon Huhn
5732aa706c
feat(lsp): implement workspace/didChangeWatchedFiles (#21293) 2023-02-25 10:07:18 +01:00
Eduard Baturin
f43fa301c1
fix(lsp): check if the buffer is a directory before w! it (#22289) 2023-02-18 07:43:59 +01:00
Lewis Russell
9ce44a750c
fix(man): use italics for <bs>_ (#22086)
fix(man): use italics for <bs>_

Even though underline is strictly what this should be. <bs>_ was used by
nroff to indicate italics which wasn't possible on old typewriters so
underline was used. Modern terminals now support italics so lets use
that now.

See:
- https://unix.stackexchange.com/questions/274658/purpose-of-ascii-text-with-overstriking-file-format/274795#274795
- https://cmd.inp.nsk.su/old/cmd2/manuals/unix/UNIX_Unleashed/ch08.htm
2023-02-01 17:21:42 +00:00
bfredl
50b256d515 fix(tests): use -l mode for lsp tests
This fixes "fake server" from leaking memory, which makes ASAN very
upset, except on current ASAN CI for some reason.
2023-01-31 13:15:23 +01:00
Sean Dewar
bcdbf77537
fix(lsp): check method is supported when range formatting (#21970)
`vim.lsp.buf.format()` silently did nothing if no servers supported
`textDocument/rangeFormatting` when formatting with a range.

Issue found by `@hwrd:matrix.org` in the Matrix chat.
2023-01-24 07:15:43 +01:00
TJ DeVries
904c13e6b5
dist: transpile cfilter.vim => cfilter.lua #21662
Vim has changed cfilter.vim from vimscript to vim9script.
Nvim supports only vimscript, not vim9script.
2023-01-08 12:31:38 -08:00
Gregory Anders
6ffa434f0b refactor(editorconfig)!: change editorconfig_enable to editorconfig 2023-01-07 08:19:37 -07:00
Gregory Anders
34d1eaa792 feat(editorconfig): allow editorconfig to be toggled dynamically
Rather than only check `editorconfig_enable` when the plugin is loaded,
check it each time the autocommand fires, so that users may enable or
disable it dynamically.

Also check for a buffer local version of the variable, so that
editorconfig can be enabled or disabled per-buffer.
2023-01-07 08:19:12 -07:00
TJ DeVries
39d70fcafd
dist: generated version of ccomplete.vim (#21623)
This is the first PR featuring a conversion of an upstream vim9script file
into a Lua file.

The generated file can be found in `runtime/autoload/ccomplete.vim` in
the vim repository. Below is a limited history of the changes of that file
at the time of conversion.

```
❯ git log --format=oneline runtime/autoload/ccomplete.vim
c4573eb12dba6a062af28ee0b8938d1521934ce4 Update runtime files
a4d131d11052cafcc5baad2273ef48e0dd4d09c5 Update runtime files
4466ad6baa22485abb1147aca3340cced4778a66 Update runtime files
d1caa941d876181aae0ebebc6ea954045bf0da24 Update runtime files
20aac6c1126988339611576d425965a25a777658 Update runtime files.
30b658179962cc3c9f0a98f071b36b09a36c2b94 Updated runtime files.
b6b046b281fac168a78b3eafdea9274bef06882f Updated runtime files.
00a927d62b68a3523cb1c4f9aa3f7683345c8182 Updated runtime files.
8c8de839325eda0bed68917d18179d2003b344d1 (tag: v7.2a) updated for version 7.2a
...
```

The file runtime/lua/_vim9script.lua only needs to be updated when vim9jit is updated
(for any bug fixes or new features, like implementing class and interface, the latest in vim9script).

Further PRs will improve the DX of generated the converted lua and
tracking which files in the neovim's code base have been generated.
2023-01-05 11:00:32 -05:00
Gregory Anders
e88cdc9a0f test(editorconfig): add editorconfig tests 2023-01-03 11:36:37 -07:00
Mathias Fußenegger
6ba34e21fe
feat(lsp): add function to clear codelens (#21504)
Currently once you retrieve the lenses you're pretty much stuck with
them as saving new lenses is additive.

Adding a dedicated method to reset lenses allows users to toggle lenses
on/off which can be useful for language servers where they are noisy or
expensive and you only want to see them temporary.
2022-12-31 16:16:21 +01:00
zeertzjq
05b6dd6e5f
test(lsp): add a screen:expect() between insert() and feed_command() (#21577)
The insert() and feed_command() type a lot of text, with only one
screen:expect() call after the feed_command() it may time out.
2022-12-29 07:55:26 +08:00
tiagovla
f4d8e992bf
fix(lsp): token_edit.data might be null on deletion (#21462) 2022-12-19 09:24:27 +01:00
Christian Clason
54d6a32fbd
feat(lsp): highlight semantic token modifiers (#21390)
Apply semantic token modifiers as separate extmarks with corresponding
highlight groups (e.g., `@readonly`). This is a low-effort PR to enable
the most common use cases (applying, e.g., italics or backgrounds on top
of type highlights; language-specific fallbacks like `@global.lua` are
also available). This can be replaced by more complicated selector-style
themes later on.
2022-12-12 20:43:14 +01:00
jdrouhard
3869a2e0cf
perf(lsp): update semantic tokens algorithm for parsing modifiers (#21383)
Instead of testing for every possible modifier type, only test bits up
to the highest set in the token array. Saves many bit ops and
comparisons when there are no modifiers or when the highest set bit is a
lower bit than the highest possible in the legend on average.

Can be further simplified when non-luaJIT gets the full bit module (see #21222)
2022-12-12 18:42:37 +01:00
fsouza
6d37d8cb17
fix(lsp): ignore null responses for semanticTokens request (#21364)
The spec indicates that the response may be `null`, but it doesn't
really say what a `null` response means. Since neovim raises an error if
the response is `null`, I figured that ignoring it would be the safest
bet.

Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2022-12-10 12:16:33 +01:00
jdrouhard
5e6a288ce7
fix(lsp): followup fixes for semantic tokens support (#21357)
1. The algorithm for applying edits was slightly incorrect. It needs to
   preserve the original token list as the edits are applied instead of
   mutating it as it iterates. From the spec:

   Semantic token edits behave conceptually like text edits on
   documents: if an edit description consists of n edits all n edits are
   based on the same state Sm of the number array. They will move the
   number array from state Sm to Sm+1.

2. Schedule the semantic token engine start() call in the
   client._on_attach() function so that users who schedule_wrap() their
   config.on_attach() functions (like nvim-lspconfig does) can still
   disable semantic tokens by deleting the semanticTokensProvider from
   their server capabilities.
2022-12-09 11:54:09 +01:00
John Drouhard
9f035559de feat(lsp): initial support for semantic token highlighting
* credit to @smolck and @theHamsta for their contributions in laying the
  groundwork for this feature and for their work on some of the helper
  utility functions and tests
2022-12-08 11:31:56 -06:00
John Drouhard
5e0c74cd82 refactor(test): create an lsp-specific helpers.lua file
* move the code for creating fake rpc servers there
2022-12-08 11:31:56 -06:00
zeertzjq
e2c5b21e18
test(lsp): call clear() before willSave tests (#21336)
Otherwise these two tests cannot run alone and may fail on CI.
2022-12-08 19:22:40 +08:00
Mathias Fußenegger
54305443b9
feat(lsp): support willSave & willSaveWaitUntil capability (#21315)
`willSaveWaitUntil` allows servers to respond with text edits before
saving a document. That is used by some language servers to format a
document or apply quick fixes like removing unused imports.
2022-12-08 10:55:01 +01:00
Mathias Fussenegger
67e1390dc8 fix(lsp): call show_document with correct args
Closes https://github.com/neovim/neovim/issues/21177
2022-12-04 15:57:46 +01:00
Mathias Fussenegger
48b84d6d6e refactor(lsp): extract a _create_server method in lsp_spec 2022-12-04 15:39:22 +01:00
dundargoc
5eb5f49488
test: simplify platform detection (#21020)
Extend the capabilities of is_os to detect more platforms such as
freebsd and openbsd. Also remove `iswin()` helper function as it can be
replaced by `is_os("win")`.
2022-11-22 08:13:30 +08:00
Lewis Russell
e8cc489acc
feat(test): add Lua forms for API methods (#20152) 2022-11-14 10:01:35 +00:00
dundargoc
736c36c02f
test: introduce skip() #21010
This is essentially a convenience wrapper around the `pending()`
function, similar to `skip_fragile()` but more general-purpose.

Also remove `pending_win32` function as it can be replaced by
`skip(iswin())`.
2022-11-13 05:52:19 -08:00
Justin M. Keyes
4d2373f5f6
feat(checkhealth): use "help" syntax, avoid tabpage #20879
- If Nvim was just started, don't create a new tab.
- Name the buffer "health://".
- Use "help" syntax instead of "markdown". It fits better, and
  eliminates various workarounds.
- Simplfy formatting, avoid visual noise.
- Don't print a "INFO" status, it is noisy.
- Drop the ":" after statuses, they are already UPPERCASE and highlighted.
2022-11-11 18:33:31 -08:00
dundargoc
4716a578ae docs: fix typos 2022-11-02 21:45:26 +08:00
Justin M. Keyes
cc7c378bf3 feat(checkhealth): check runtime ($VIMRUNTIME)
Move man/health.lua into the "runtime" check.

fix #20696
2022-10-30 16:23:58 +01:00
dundargoc
5046b4b4ad
ci: add cirrus to isCI function to skip tests (#20526)
The environment variable CIRRUS_CI is manually passed to RunTests.cmake
as it doesn't get passed when using cmake script mode.
2022-10-17 17:16:31 +02:00
Mahmoud Al-Qudsi
39911d76be
fix(man): handle absolute paths as :Man targets (#20624)
* fix(man): handle absolute paths as :Man targets

Previously, attempting to provide `:Man` with an absolute path as the name would
cause neovim to return the following error:

```
Error detected while processing command line:
/usr/local/share/nvim/runtime/lua/man.lua:690: /usr/local/share/nvim/runtime/lua/man.lua:683: Vim:E426: tag not found: nil(nil)
Press ENTER or type command to continue
```

..because it would try to validate the existence of a man page for the provided
name by executing `man -w /some/path` which (on at least some Linux machines
[0]) returns `/some/path` instead of the path to the nroff files that would be
formatted to satisfy the man(1) lookup.

While man pages are not normally named after absolute paths, users shouldn't be
blamed for trying. Given such a name/path, neovim would **not** complain that
the path didn't have a corresponding man file but would error out when trying
to call the tag function for the null-propagated name-and-section `nil(nil)`.
(The same underlying error existed before this function was ported to lua, but
did not exhibit the lua-specific `nil(nil)` name; instead a tag lookup for `()`
would fail and error out.)

With this patch, we detect the case where `man -w ...` returns the same value as
the provided name to not only prevent invoking the tag function for a
non-existent/malformed name+sect but also to properly report the non-existence
of a man page for the provided lookup (the absolute path).

While man(1) can be used to directly read an nroff-formatted document via `man
/path/to/nroff.doc`, `:Man /path/to/nroff.doc` never supported this behavior so
no functionality is lost in case the provided path _was_ an nroff file.

[0]: `man -w /absolute/path` returning `/absolute/path` observed on an Ubuntu
18.04 installation.

* test: add regression test for #20624

Add a functional test to `man_spec.lua` to check for a regression for #20624 by
first obtaining an absolute path to a random file and materializing it to disk,
then attempting to query `:Man` for an entry by that same name/path.

The test passes if nvim correctly reports that there is no man page
correspending to the provided name/path and fails if any other error (or no
error) is shown.
2022-10-17 10:37:44 +01:00
Christian Clason
9701c9dc9f
vim-patch:3c053a1a5ad2 (#20679)
Update runtime files
3c053a1a5a
2022-10-17 08:19:48 +02:00
lvimuser
0773a9ee3a
feat(lsp): support window/showDocument (#19977) 2022-10-08 10:22:25 +02:00
bfredl
9d8546e0c5 test(shada): fix shada syntax definitions test
These tests contained errors due to synstack() and friends do not ensure
syntax state is fully synced. Actually expecting what the user will
see with a screen test does ensure it is fully synced.
2022-10-05 13:46:52 +02:00
shaunsingh
caf5738fa9
fix(lsp): create missing directory before creating file (#19835)
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2022-09-24 12:46:21 +02:00
ofwinterpassed
ec94014cd1
fix(lsp): out of bounds error in lsp.util.apply_text_edits (#20137)
Co-authored-by: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com>
2022-09-20 22:14:58 +02:00
Mathias Fußenegger
10196f1b46
fix(lsp): support false result in handlers (#20252)
Closes https://github.com/neovim/neovim/issues/20111
2022-09-20 09:28:23 +02:00
zeertzjq
91a150d0a9
test(lsp): call clear() before bufwipe test (#20170)
Otherwise this test cannot be run alone, and fails frequently on CI.
2022-09-13 06:01:35 +08:00
Raphael
30ca6d23a9
fix(lsp): when buffer detach remove buffer from client attached buffers (#20081)
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2022-09-08 17:09:32 +02:00
Mathias Fußenegger
11167ab6d5
feat(lsp): add range option to lsp.buf.format (#19998) 2022-09-08 11:33:04 +02:00
Lewis Russell
2afcdbd63a
feat(Man): port to Lua (#19912)
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2022-09-02 15:20:29 +01:00
Sean Dewar
813476bf72
fix(exceptions): restore did_throw (#20000)
`!did_throw` doesn't exactly imply `!current_exception`, as `did_throw = false`
is sometimes used to defer exception handling for later (without forgetting the
exception). E.g: uncaught exception handling in `do_cmdline()` may be deferred
to a different call (e.g: when `try_level > 0`).

In #7881, `current_exception = NULL` in `do_cmdline()` is used as an analogue of
`did_throw = false`, but also causes the pending exception to be lost, which
also leaks as `discard_exception()` wasn't used.

It may be possible to fix this by saving/restoring `current_exception`, but
handling all of `did_throw`'s edge cases seems messier. Maybe not worth
diverging over.

This fix also uncovers a `man_spec.lua` bug on Windows: exceptions are thrown
due to Windows missing `man`, but they're lost; skip these tests if `man` isn't
executable.
2022-08-30 23:13:52 +01:00
Mathias Fussenegger
60ec6e34d5 feat(lsp): add tcp support 2022-08-28 14:07:53 +02:00
Mathias Fußenegger
e99de3f12f
fix(lsp): send didOpen if name changes on write (#19583)
`:saveas newName` changes the name of an existing buffer.
Due to the buffer re-use it skips the lsp attach phase and immediately
sends a `didSave` notification to the server.
Servers get confused about this, because they expect a `didOpen`
notification first.

Closes https://github.com/neovim/neovim/issues/18688
2022-08-01 22:32:53 +02:00
ii14
13abe20b5f
refactor(lsp): use autocmd api (#19407)
* refactor(lsp): use autocmd api

* refactor(lsp): inline BufWritePost and VimLeavePre callbacks
2022-07-17 19:13:33 +02:00
L3MON4D3
6f6286e4f9
fix(lsp): small bugs in snippet-parser #18998
This fixes the following bugs:
`${1:else_text}` -> format with if_text: "else_text"
`${1:-else_text}` -> format with if_text: "else_text"
`${1:}` in `format` (eg. empty else_text) -> error.
`${1:}` (eg. empty placeholder) -> error.

Thanks hrsh7th :)
2022-06-29 09:53:49 -07:00
Justin M. Keyes
b6467dfc23 test(report): formatting, drop dumplog()
Don't need to dumplog() on each failed test because we now have test-ids
that associate log messages with tests.
2022-06-15 19:23:10 -07:00
Mathias Fußenegger
e4df1c9b9e
fix(lsp): fix multi client handling in code action (#18869)
Fixes https://github.com/neovim/neovim/issues/18860
2022-06-05 16:43:32 +02:00
Mathias Fußenegger
c6d747e6a5
feat(lsp): send didChangeConfiguration after init (#18847)
Most LSP servers require the notification to correctly load the
settings and for those who don't it doesn't cause any harm.

So far this is done in lspconfig, but with the addition of vim.lsp.start
it should be part of core.
2022-06-03 18:16:11 +02:00
Javier Lopez
d837b6d50c
fix(checkhealth): skip vim.health #18816
Problem:
https://github.com/neovim/neovim/pull/18720#issuecomment-1142614996

The vim.health module is detected as a healthcheck, which produces spurious errors:

    vim: require("vim.health").check()
    ========================================================================
    - ERROR: Failed to run healthcheck for "vim" plugin. Exception:
      function health#check, line 20
      Vim(eval):E5108: Error executing lua [string "luaeval()"]:1: attempt to call field 'check' (a nil value)
      stack traceback:
      [string "luaeval()"]:1: in main chunk

Solution:
Skip vim.health when discovering healthchecks.
2022-06-01 07:10:10 -07:00
bfredl
58b9b7e7c4 fix(ci): remove 2000ms blocking wait in many plugin/lsp_spec.lua tests
Cuts down typical run time for `plugin/lsp_spec.lua`
from 70 secs to 12 secs in ASAN CI build.

This happens in ASAN/EXIT_FREE builds where nvim waits 2000ms due to
unclosed handled. I wasn't able to pin-point the exact cause.
But these tests ran in nested context where two server/client pairs
were setup for no good reason. Moving these tests out so only one client
is being setup fixed the exit hang.
2022-05-22 14:14:58 +02:00
Gregory Anders
2ffafc7aa9 feat(lsp): add LspAttach and LspDetach autocommands
The current approach of using `on_attach` callbacks for configuring
buffers for LSP is suboptimal:

1. It does not use the standard Nvim interface for driving and hooking
   into events (i.e. autocommands)
2. There is no way for "third parties" (e.g. plugins) to hook into the
   event. This means that *all* buffer configuration must go into the
   user-supplied on_attach callback. This also makes it impossible for
   these configurations to be modular, since it all must happen in the
   same place.
3. There is currently no way to do something when a client detaches from
   a buffer (there is no `on_detach` callback).

The solution is to use the traditional method of event handling in Nvim:
autocommands. When a LSP client is attached to a buffer, fire a
`LspAttach`. Likewise, when a client detaches from a buffer fire a
`LspDetach` event.

This enables plugins to easily add LSP-specific configuration to buffers
as well as enabling users to make their own configurations more modular
(e.g. by creating multiple LspAttach autocommands that each do
something unique).
2022-05-18 11:21:00 -06:00
Arsham Shirvani
f6ba7d69be
fix(man.vim): q in "$MANPAGER mode" does not quit #18443
Problem:
q in "$MANPAGER mode" does not quit Nvim. This is because
ftplugin/man.vim creates its own mapping:
    nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c
which overrides the one set by the autoload file when using :Man!
("$MANPAGER mode")

Solution:
Set b:pager during "$MANPAGER mode" so that ftplugin/man.vim can set the
mapping correctly.

Fixes #18281
Ref #17791

Helped-by: Gregory Anders <8965202+gpanders@users.noreply.github.com>
2022-05-13 07:49:08 -07:00
Fredrik Ekre
a9d25e9472
fix(lsp): perform client side filtering of code actions (#18392)
Implement filtering of actions based on the kind when passing the 'only'
parameter to code_action(). Action kinds are hierachical with a '.' as
the separator, and the filter thus allows, for example, both 'quickfix'
and 'quickfix.foo' when requestiong only 'quickfix'.

Fix https://github.com/neovim/neovim/pull/18221#issuecomment-1110179121
2022-05-12 18:48:02 +02:00
Mathias Fußenegger
55187de115
fix(lsp): fix rename capability checks and multi client support (#18441)
Adds filter and id options to filter the client to use for rename.
Similar to the recently added `format` function.

rename will use all matching clients one after another and can handle a
mix of prepareRename/rename support. Also ensures the right
`offset_encoding` is used for the `make_position_params` calls
2022-05-05 23:56:00 +02:00
William Boman
94eb72cc44
fix(lsp): make sure to always reset active codelens refreshes (#18331)
This fixes issues where subsequent calls to vim.lsp.codelens.refresh()
would have no effect due to the buffer not getting cleared from the
active_refresh table.

Examples of how such scenarios would occur are:
  - A textDocument/codeLens result yielded an error.
  - The 'textDocument/codeLens' handler was overriden in such a way that
    it no longer called vim.lsp.codelens.on_codelens().
2022-05-05 18:50:12 +02:00
Mathias Fußenegger
0344736aa6
fix(lsp): handle textDocumentSync.save bool capability (#18332)
Follow up to https://github.com/neovim/neovim/pull/17814
2022-04-30 22:13:26 +02:00
Mathias Fußenegger
88411613e2
feat(lsp): add async option to vim.lsp.buf.format (#18322)
Deprecates the existing `vim.lsp.buf.formatting` function.
With this, `vim.lsp.buf.format` will replace all three:

- vim.lsp.buf.formatting
- vim.lsp.buf.formatting_sync
- vim.lsp.buf.formatting_seq_sync
2022-04-30 17:23:50 +02:00
Michael Lingelbach
5b04e46d23
feat(lsp): add vim.lsp.buf.format (#18193) 2022-04-30 15:36:40 +02:00
Michael Lingelbach
c618b314c6
chore(lsp): remove capabilities sanitization (#17814)
* feat(lsp)!: remove capabilities sanitization

Users must now access client.server_capabilities which matches the same
structure as the protocol.

https://microsoft.github.io/language-server-protocol/specification

client.resolved_capabilities is no longer used to gate capabilities, and
will be removed in a future release.

BREAKING CHANGE


Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2022-04-30 11:22:30 +02:00
Fredrik Ekre
df09e03cf7
feat(lsp): options to filter and auto-apply code actions (#18221)
Implement two new options to vim.lsp.buf.code_action():
 - filter (function): predicate taking an Action as input, and returning
   a boolean.
 - apply (boolean): when set to true, and there is just one remaining
   action (after filtering), the action is applied without user query.

These options can, for example, be used to filter out, and automatically
apply, the action indicated by the server to be preferred:

    vim.lsp.buf.code_action({
        filter = function(action)
            return action.isPreferred
        end,
        apply = true,
    })

Fix #17514.
2022-04-30 10:14:31 +02:00
ii14
55135cea61
fix(lsp): fix unnecessary buffers being added on empty diagnostics (#18275)
Some language servers send empty `textDocument/publishDiagnostics`
messages after indexing the project with URIs corresponding to unopened buffers.
This commit guards against opening buffers corresponding to empty diagnostics.
2022-04-26 10:00:28 -07:00
Fredrik Ekre
6160973f36
fix(lsp): fix lookup of boolean values in workspace/configuration (#18026) 2022-04-15 11:12:41 +02:00
dundargoc
61205c1def
chore: fix typos (#17755)
Co-authored-by: Jordan Haine <jhaine@securitycompass.com>
2022-03-25 19:57:59 +01:00
Tim Pope
af427dedf6
fix(lsp): set tabSize from 'shiftwidth', not 'softtabstop' (#17787)
The use of 'softtabstop' to set tabSize was introduced in 5d5b068,
replacing 'tabstop'.  If we look past the name tabSize and at the actual
purpose of the field, it's the indentation width used when formatting.
This corresponds to the Vim option 'shiftwidth', not 'softtabstop'.
The latter has the comparatively mundane purpose of controlling what
happens when you hit the tab key (and even this is incomplete, as it
fails to account for 'smarttab').
2022-03-20 10:41:46 -07:00
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
Gregory Anders
d8ab8cccd0 test: update tests to work with 'hidden' 2021-08-18 12:17:12 -06:00
James McCoy
bcca62a760
Merge pull request #15368 from jamessan/fragility
test(lsp): disable finicky test when TEST_SKIP_FRAGILE is set
2021-08-14 21:21:50 -04:00
James McCoy
8491077314
test(lsp): disable finicky test when TEST_SKIP_FRAGILE is set 2021-08-13 23:53:55 -04:00
Andrea Cappuccio
adebbebdd7
fix(lsp): properly handle nil lines when trimming empty lines (#15325) 2021-08-10 20:52:30 +02:00
Jan Edmund Lazo
5cead86975
fixup! vim-patch:8.2.3019: location list only has the start position. 2021-07-31 16:58:10 -04:00
Björn Linse
a3e2636afd fix(ci): disable broken test on openbsd on all CI due to resource constraints 2021-07-23 19:35:32 +02:00
Gregory Anders
1aeb945553
feat(lsp): allow diagnostics to be disabled for a buffer (#15134)
Add two new methods to allow diagnostics to be disabled (and re-enabled)
in the current buffer. When diagnostics are disabled they are simply not
displayed to the user, but they are still sent by the server and
processed by the client.

Disabling diagnostics can be helpful in a number of scenarios. For
example, if one is working on a buffer with an overwhelming amount of
diagnostic warnings it can be helpful to simply disable diagnostics
without disabling the LSP client entirely. This also allows users more
flexibility on when and how they may want diagnostic information to be
displayed. For example, some users may not want to display diagnostic
information until after the buffer is first written.
2021-07-19 11:49:55 -07:00
Alessandro Pezzoni
82a443e1f3 test(lsp): file URIs do not allow relative paths 2021-07-10 18:27:37 +01:00
Matthieu Coudron
3552916cb9
fix(doc): remove reference to vim.lsp.callbacks (#14576)
too old now, can be confusing
2021-06-28 23:02:17 +02:00
Akin Sowemimo
444f175335 fix(lsp): do not convert vim.NIL to nil in lists 2021-06-24 11:23:19 +01:00
Matthieu Coudron
9a39a11807 fixup! vim-patch:8.2.3020: unreachable code (#14866) 2021-06-22 10:35:36 +02:00
Mathias Fussenegger
2bdd553c9e feat(lsp): Add codelens support 2021-06-14 21:45:14 +02:00
Mathias Fussenegger
f03a4d616b feat(lsp): Split out a diagnostics_to_items function from set_loclist
Makes it easier to re-use the logic to populate the quickfix list
instead of the location list.
2021-06-07 18:24:32 +02:00
Michael Lingelbach
045e47ec55
Merge pull request #14563 from mjlbach/fix_intelephense_langserver
lsp: handle case where CompletionItem.insertTextFormat is nil
2021-05-19 12:39:44 -07:00
Marco Hinz
9051064672
test(lsp_spec): improve correctness
References https://github.com/neovim/neovim/issues/14571
2021-05-19 16:35:02 +02:00
Marco Hinz
34922fba6b
Revert "lsp: make tagstack smarter motion-wise (#12262)"
This reverts commit 8885ea7f24.
2021-05-19 15:33:32 +02:00
Michael Lingelbach
63df353545 lsp: handle case where CompletionItem.insertTextFormat is nil
* Update tests to use explicit insertTextFormat for snippets
2021-05-16 15:25:34 -07:00
francisco souza
9149fe48a9 lsp: add a test for the jump_to_location + jump list fix 2021-05-06 17:56:24 -04:00
Jan Edmund Lazo
278ca5f456
vim-patch:ebdf3c964a90
Update runtime files.
ebdf3c964a

Omit vim9.
2021-04-27 09:21:35 -04:00
Gabriel Sanches
8885ea7f24
lsp: make tagstack smarter motion-wise (#12262)
This commit prevents two things regarding the tagstack and jumping to
locations:

  - Pushing the same item twice in a row

  - Pushing an item where the destination is the same as the source

Both prevent having to press CTRL-T additional times just to pop items
that don't make the cursor move.
2021-04-23 14:50:35 -07:00
Mathias Fussenegger
046991e4d5 lsp: Remove vim.NIL handling from apply_text_document_edit
The rpc layer normalizes `vim.NIL` to `nil`, so the scenario tested
should never happen.
2021-04-14 21:42:03 +02:00
Mathias Fussenegger
b67f689e4c lsp: Accept text document edits with version zero
There were a couple of reports of "Buffer X newer than edits" problems.
We first assumed that it is incorrect for a server to send 0 as a
version - and stated that they should send a `null` instead, given that
in the specification the `textDocument` of a `TextDocumentEdit` is a
`OptionalVersionedTextDocumentIdentifier`.

But it turns out that this was a change in 3.16, and in 3.15 and earlier
versions of the specification it was a `VersionedTextDocumentIdentifier`
and language servers didn't have a better option than sending `0` if
they don't keep track of the version numbers.

So this changes the version check to always accept `0` values.

See

- https://github.com/neovim/neovim/issues/12970
- https://github.com/neovim/neovim/issues/14256
- https://github.com/haskell/haskell-language-server/pull/1727
2021-04-14 21:29:32 +02:00
Björn Linse
2df527e1ff test/lsp: disable tracking in LSP tests (here be dragons) 2021-04-03 16:27:58 +02:00
Mathias Fussenegger
84213b5b9a lsp: Add support for delete workspaceEdit resource operation 2021-03-18 19:53:43 +01:00
Mathias Fussenegger
191afb42be lsp: Add support for create workspaceEdit resource operation 2021-03-18 19:53:42 +01:00