Commit Graph

484 Commits

Author SHA1 Message Date
Lewis Russell
00e71d3da3 refactor(lsp): simplify client tracking
- Remove:
    - uninitialized_clients
    - active_clients
    - all_buffer_active_clients
- Add:
    - all_clients

- Use `lsp.get_clients()` to get buffer clients.
2024-03-25 22:21:08 +00:00
Lewis Russell
a7bbda121d fix(test): typing 2024-03-25 21:09:57 +00:00
Lewis Russell
934f38682a Revert "refactor(lsp): simplify client tracking"
This reverts commit 3f238b39cf.
2024-03-25 20:16:42 +00:00
Lewis Russell
3f238b39cf refactor(lsp): simplify client tracking
- Remove:
    - uninitialized_clients
    - active_clients
    - all_buffer_active_clients
- Add:
    - all_clients

- Use `lsp.get_clients()` to get buffer clients.
2024-03-25 18:02:38 +00:00
bfredl
0c59771e31 refactor(tests): all screen tests should use highlights
This is the first installment of a multi-PR series significantly
refactoring how highlights are being specified.

The end goal is to have a base set of 20 ish most common highlights,
and then specific files only need to add more groups to that as needed.

As a complicating factor, we also want to migrate to the new default
color scheme eventually. But by sharing a base set, that future PR
will hopefully be a lot smaller since a lot of tests will be migrated
just simply by updating the base set in place.

As a first step, fix the anti-pattern than Screen defaults to ignoring
highlights. Highlights are integral part of the screen state, not
something "extra" which we only test "sometimes". For now, we still
allow opt-out via the intentionally ugly

  screen._default_attr_ids = nil

The end goal is to get rid of all of these eventually (which will be
easier as part of the color scheme migration)
2024-03-23 13:44:35 +01:00
zeertzjq
5de0482d1a
test(lsp): fix flaky basic_finish test (#27899)
Problem:
As mentioned in #23002 on_setup and on_init are run concurrently.
However, in basic_finish tests on_setup must attach the client before
on_init finishes.  The other basic_finish test isn't flaky because it
makes an RPC request in on_init.

Solution:
Don't use on_setup in basic_finish tests.
2024-03-18 19:49:31 +08:00
En-En
e34c23b701
fix(tutor): set a value for ":syntax iskeyword" (#27833)
Problem: "NOTE"s, inline Vim script code, and links ending in digits may not be
highlighted correctly within the :Tutor.

Solution: set an explicit value for ":syntax iskeyword" that includes digits. Do
it after ":syntax include"s, so the included syntax/sh.vim doesn't mess with the
value.

Increase screen test width so all text within the conclusion section is visible.

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
2024-03-18 11:19:20 +00:00
Takuya Tokuda
77a9f3395b
fix(lsp): create codelens request parameters for each buffer (#27699) 2024-03-17 21:04:59 +01:00
Caleb Marshall
542c910a1d fix(lsp): add missing LSP semantic token highlight links
Added the following LSP semantic token types to be linked to highlight
groups by default:

* @lsp.type.event
* @lsp.type.keyword
* @lsp.type.modifier
* @lsp.type.number
* @lsp.type.operator
* @lsp.type.regexp
* @lsp.type.string
2024-03-16 20:37:56 +08:00
zeertzjq
1da0f3494e
test: correct order of arguments to eq() (#27816) 2024-03-11 22:23:14 +08:00
zeertzjq
970b60aa7c
test(tohtml_spec): don't use hard-coded sleeping time (#27770)
Instead cause some changes to screen state and use screen:expect().
2024-03-08 10:24:46 +08:00
altermo
a8131aee9e
fix(tohtml): replace hex escape with digit escape (#27728) 2024-03-04 19:08:23 +08:00
Jaehwang Jung
dc8c086c7e
fix(lsp): directly rename the existing buffers when renaming (#27690)
Problem:
`vim.lsp.util.rename()` deletes the buffers that are affected by
renaming. This has undesireable side effects. For example, when renaming
a directory, all buffers under that directory are deleted and windows
displaying those buffers are closed. Also, buffer options may change
after renaming.

Solution:
Rename the buffers with :saveas.

An alternative approach is to record all the relevant states and restore
it after renaming, but that seems to be more complex. In fact, the older
version was attempting to restore the states but only partially and
incorrectly.
2024-03-02 15:21:53 +01:00
Lewis Russell
4ff3217bbd feat(lsp): add fswatch watchfunc backend
Problem:
  vim._watch.watchdirs has terrible performance.

Solution:
  - On linux use fswatch as a watcher backend if available.

  - Add File watcher section to health:vim.lsp. Warn if watchfunc is
    libuv-poll.
2024-03-01 23:00:20 +00:00
Lewis Russell
816b56f878 fix(lsp): cancel watchers when closing a client 2024-03-01 22:30:27 +00:00
Lewis Russell
b87505e116 refactor(watch): general tidy up
- Rename watch.poll to watch.watchdirs
- Unify how include and exclude is applied
- Improve type hints
2024-03-01 22:30:27 +00:00
Jaehwang Jung
b413f5d048
fix(lsp): rename undofile when renaming (#27684)
Problem:
After `rename()`, the undo information for the renamed file(s) are lost.

Solution:
Rename the undofile as well.
2024-03-01 18:31:54 +01:00
Jaehwang Jung
7311958e12
fix(lsp): remove unnecessary file load/write when renaming (#27621)
Previously rename would unconditionally read the to-be-renamed file from the
disk and write it to the disk. This is redundant in some cases

If the file is not already loaded, it's not attached to lsp client, so nvim
doesn't need to care about this file.
If the file is loaded but has no change, it doesn't need to be written.
2024-02-28 17:32:25 +01:00
altermo
2f85bbe615 feat!: rewrite TOhtml in lua
Co-authored-by: wookayin <wookayin@gmail.com>
Co-authored-by: clason <c.clason@uni-graz.at>
Co-authored-by: Lewis Russell <me@lewisr.dev>
2024-02-28 16:26:00 +00:00
Maria José Solano
63f9c2da9a feat(lsp): support completion itemDefaults 2024-02-27 16:50:51 +01:00
Jaehwang Jung
8addd27504
fix(lsp): when renaming directory, check path prefix of buffer names (#27603)
For example, when renaming /path/to/dir, buffers like
fern://drawer/file:///path/to/dir, /path/to/dir123 should not be
matched.
2024-02-24 16:47:34 +01:00
zeertzjq
51ea753747
fix(genvimvim): generate prefixed boolean options properly (#27487) 2024-02-16 13:27:42 +08:00
Tomasz N
d09957e0a0
fix(lsp): rename: load and list new buffer if attached to window (#27408) 2024-02-14 21:11:29 +01:00
Lewis Russell
9f8c96240d refactor(lsp): resolve the config-client entanglement
Previously the LSP-Client object contained some fields that are also
in the client config, but for a lot of other fields, the config was used
directly making the two objects vaguely entangled with either not having
a clear role.

Now the config object is treated purely as config (read-only) from the
client, and any fields the client needs from the config are now copied
in as additional fields.

This means:
- the config object is no longet normalised and is left as the user
  provided it.
- the client only reads the config on creation of the client and all
  other implementations now read the clients version of the fields.

In addition, internal support for multiple callbacks has been added to
the client so the client tracking logic (done in lua.lsp) can be done
more robustly instead of wrapping the user callbacks which may error.
2024-02-13 14:49:20 +00:00
Lewis Russell
ed1b66bd99
refactor(lsp): move more code to client.lua
The dispatchers used by the RPC client should be defined in the client,
so they have been moved there. Due to this, it also made sense to move
all code related to client configuration and the creation of the RPC
client there too.

Now vim.lsp.start_client is significantly simplified and now mostly
contains logic for tracking open clients.

- Renamed client.new -> client.start
2024-02-11 12:37:20 +00:00
Lewis Russell
451bc50d40 feat(lsp): deprecate severity_limit
Problem:
  `vim.lsp.diagnostic.on_diagnostic` accepts an undocumented severity_limit
  option which is widely used.

Solution:
  Deprecate it in favour of `{min = severity}` used in `vim.diagnostic`.
  Since this is undocumented, the schedule for removal is accelerated to
  0.11.
2024-02-08 16:58:49 +00:00
Jongwook Choi
b92b9be85d test(lsp): add test cases for vim.lsp.tagfunc
Problem: There is no test case for vim.lsp.tagfunc; so CI was unable to
catch the infinite loop bug (#27325).

Solution: Add test cases for vim.lsp.tagfunc().
2024-02-03 18:01:12 -05:00
Justin M. Keyes
95cbedaa17
docs: various #25289
Co-authored-by: Jongwook Choi <wookayin@gmail.com>
Co-authored-by: Oliver Marriott <hello@omarriott.com>
Co-authored-by: Benoit de Chezelles <bew@users.noreply.github.com>
Co-authored-by: Jongwook Choi <wookayin@gmail.com>
2024-01-18 00:14:48 -08:00
Lewis Russell
795f896a57 test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
Lewis Russell
4f81f506f9 test: normalise nvim bridge functions
- remove helpers.cur*meths
- remove helpers.nvim
2024-01-12 17:53:27 +00:00
Lewis Russell
c30f2e3182 test: typing for helpers.meths 2024-01-12 13:01:06 +00:00
Lewis Russell
284e0ad26d test: use vim.mpack and vim.uv directly 2024-01-12 12:04:20 +00:00
Lewis Russell
d33e1da9b7 test: do not inject vim module into global helpers 2024-01-12 12:04:18 +00:00
Justin M. Keyes
04f2f864e2 refactor: format test/* 2024-01-03 02:09:29 +01:00
TheLeoP
3f788e73b3
feat(lsp): support connect via named pipes/unix domain sockets (#26032)
Closes https://github.com/neovim/neovim/issues/26031

Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2024-01-02 10:08:36 +01:00
Gregory Anders
164f1ea06d refactor(health): refactor provider healthchecks
* Prefer pure Lua functions over vim.fn
* Split up provider healthchecks into separate modules to help manage
  complexity
2024-01-01 20:12:37 +01:00
zeertzjq
2877672d70
feat(health): make :checkhealth support more split modifiers (#26731) 2023-12-25 10:21:13 +08:00
Pablo Arias
2ff2785c39
feat(health): checkhealth buffer can show in a split window (#26714)
:checkhealth now respects :vertical and :horizontal.
For example:
  :vertical checkhealth foo bar
will open the healthcheck buffer in a vertical split.
2023-12-25 08:30:56 +08:00
Michal Liszcz
031088fc0a
fix(lsp): filetype matching to documentSelector in dynamic capabilities (#25425)
Use the get_language_id client option to resolve the filetype when
matching the document selector in a dynamic capability.


Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
2023-12-22 15:03:13 +01:00
Steven Arcangeli
92204b06e7
refactor(lsp): move glob parsing to util (#26519)
refactor(lsp): move glob parsing to vim.glob

Moving the logic for using vim.lpeg to create a match pattern from a
glob into `vim.glob`. There are several places in the LSP spec that
use globs, and it's very useful to have glob matching as a
generally-available utility.
2023-12-22 11:40:01 +01:00
zeertzjq
1037ce2e46 test: avoid repeated screen lines in expected states
This is the command invoked repeatedly to make the changes:

    :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g
2023-12-09 22:15:02 +08:00
Mathias Fußenegger
7ca2d64e8b
test: skip failing watch file tests on freebsd (#26110)
Quick fix as follow up to https://github.com/neovim/neovim/pull/26108

kqueue only reports events on a watched folder itself, not for files
created or deleted within. So the approach the PR took doesn't work on FreeBSD.

We'll either need to bring back polling for it, combine watching with manual
file tracking, or disable LSP file watching on FreeBSD
2023-11-19 18:37:49 +01:00
LW
448907f65d
feat(lsp)!: vim.lsp.inlay_hint.get(), enable(), is_enabled() #25512
refactor!: `vim.lsp.inlay_hint()` -> `vim.lsp.inlay_hint.enable()`

Problem:
The LSP specification allows inlay hints to include tooltips, clickable
label parts, and code actions; but Neovim provides no API to query for
these.

Solution:
Add minimal viable extension point from which plugins can query for
inlay hints in a range, in order to build functionality on top of.

Possible Next Steps
---

- Add `virt_text_idx` field to `vim.fn.getmousepos()` return value, for
  usage in mappings of `<LeftMouse>`, `<C-LeftMouse>`, etc
2023-11-12 04:54:27 -08:00
Lajos Koszti
ba6761eafe
fix(lsp): fix omnicomplete in middle of the line (#25787)
Fixes a regression from 5e5f5174e3

Until that commit we had a logic like this:
`local prefix = startbyte and line:sub(startbyte + 1) or line_to_cursor:sub(word_boundary)`

The commit changed the logic and no longer cut off the line at the cursor,  resulting in a prefix that included trailing characters
2023-10-26 22:40:36 +02:00
Mathias Fussenegger
5e5f5174e3 fix(lsp): fix off-by-one error for omnifunc word boundary
Fixes https://github.com/neovim/neovim/issues/25177

I initially wanted to split this into a refactor commit to make it more
testable, but it appears that already accidentally fixed the issue by
normalizing lnum/col to 0-indexing
2023-10-23 08:26:38 +02:00
Mathias Fussenegger
195301c609 refactor(lsp): deprecate completion util methods
Relates to https://github.com/neovim/neovim/issues/25272
2023-10-21 13:49:05 +02:00
Maria José Solano
ee156ca60e
fix(lsp): refactor escaping snippet text (#25611) 2023-10-14 09:06:40 +02:00
zeertzjq
840e1864c2
fix(lsp): handle NUL bytes in popup text (#25612)
Fix #25610
2023-10-12 15:39:39 +08:00
LW
9abced6ad9
fix(lsp): account for border height in max floating popup height (#25539) 2023-10-08 10:09:25 +02:00
Maria José Solano
eb1f0e8fcc feat(lsp)!: replace snippet parser by lpeg grammar 2023-10-02 22:21:35 +02:00
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