Commit Graph

372 Commits

Author SHA1 Message Date
3b6084ddf4 fix: type fixes
Type fixes caught by emmylua
2025-06-06 15:36:48 +01:00
e5c5b563ec fix(lsp): only auto-detach lsp.config enabled clients #34325
Problem: A custom server (initialized through `vim.lsp.start`) gets
         unexpectedly detached.

Solution: Only auto-detach the clients enabled through `vim.lsp.enable`
          to prevent unexpected behavior.
2025-06-06 06:26:50 -07:00
80753332d1 docs: news, intro, lsp, api #33687 2025-06-01 14:13:50 -07:00
40351bbbbe fix(lua): vim.validate message param #33675
Problem:
vim.validate does not handle `message` param.

Solution:
Add the missing logic.
2025-05-04 16:36:32 -07:00
0862c1036a fix(lsp): check if client is stopping before reuse #33796
Problem:
Stopping a language server and then calling vim.lsp.start() with the same name/root will return the old language server that's in the middle of shutting down. vim.lsp.start() won't return a new server until the old process has terminated.

Solution:
Introducing a client._is_stopping field that tracks the shutdown phase, preventing the client from being reused.
2025-05-04 14:38:01 -07:00
91e116f3a6 fix(lsp): only auto-detach lsp.config clients #33834
Problem:
enable() routine detaches clients even if they were manually started
and not managed by vim.lsp.config.

Solution:
Skip clients that aren't managed by vim.lsp.config.
2025-05-04 06:07:11 -07:00
b877aa34cf feat(lsp): detach LSP clients when 'filetype' changes #33707
Problem:
When the buffer 'filetype' changes, invalid or non-applicable LSP
clients are not detached.

https://github.com/neovim/neovim/issues/33443
https://github.com/neovim/nvim-lspconfig/issues/3326

Solution:
In the enable() routine, check can_start() on _existing_ clients.
2025-05-03 14:57:59 -07:00
03d378fda6 feat(lsp): vim.lsp.is_enabled() #33703
Problem:
No way to check if a LSP config is enabled without causing it to
resolve. E.g. `vim.lsp.config['…'] ~= nil` will resolve the config,
which could be an unwanted and somewhat expensive side-effect.

Solution:
Introduce `vim.lsp.is_enabled()`.
2025-05-03 10:25:58 -07:00
1fb0126a08 fix(vim.lsp.enable): don't eagerly enable LSP configs during startup #33762
closes #33761
2025-05-02 02:05:18 -07:00
4bc7bac884 feat(lsp): start/stop LSPs as necessary during vim.lsp.enable() #33702
Problem:
enable() could be more flexible, so that it works even if called "late".

Solution:
- enable(true) calls `doautoall nvim.lsp.enable FileType`.
- enable(false) calls `client:stop()` on matching clients.

This will be useful for e.g. :LspStop/:LspStart also.
2025-04-30 16:57:29 -07:00
6577d72d81 feat(lsp): root_markers can control priority #33485
Problem:
root_markers cannot specify "equal priority filenames.

Solution:
Support nesting:

    {
      ...
      root_markers = { { ".stylua.toml", ".luarc.json" }, { ".git "} }
      ...
    }


Co-authored-by: Maria José Solano <majosolano99@gmail.com>
Co-authored-by: Gregory Anders <github@gpanders.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2025-04-30 06:43:32 -07:00
644c618825 docs: lsp, lua #33682
- sort fields alphabetically.
- in the `vim.lsp.Client` docs, reference `vim.lsp.ClientConfig` instead
  of duplicating its docs.
- cleanup lots of redundant-yet-drifted field docs.
2025-04-27 15:44:11 -07:00
52a4bc4548 docs: lsp, emoji, startup #33446
Co-authored-by: Maria José Solano <majosolano99@gmail.com>
2025-04-27 13:40:46 -07:00
9ff1239634 feat(lsp): support textDocument/documentColor
test(lsp): add tests form `vim.lsp.document_color`
2025-04-24 18:48:19 +02:00
d55330bcd1 refactor(lsp): use method type annotations for parameters 2025-04-21 11:35:29 +02:00
d7e0d46ffa feat(lsp): use stricter types for methods
This change modifies gen_lsp.lua so alias types are generated for
various types of lsp methods to distinguish between notifications
and requests:
 - vim.lsp.protocol.Method.ServerToClient.Request
 - vim.lsp.protocol.Method.ServerToClient.Notification
 - vim.lsp.protocol.Method.ClientToServer.Request
 - vim.lsp.protocol.Method.ClientToServer.Notification

 These types are then used instead of `string` where appropriate.
2025-04-17 11:40:45 +01:00
74ca73d545 docs: misc #33330 2025-04-12 10:21:03 -07:00
fece489794 refactor(lsp): deprecate client_is_stopped #33342
Problem:
`client_is_stopped(…)` is an alias for `not get_client_by_id(…)`.
And it's not used anywhere in our codebase.

Solution:
Deprecate it.
2025-04-06 02:13:13 +00:00
2ee896201c fix(lsp): better handling of "*" configs
Problem:

If a config name contains "*" it causes rtp discovery of `lsp/` to
consider the `*` as a wildcard and could lead to strange and unintended
behaviour. For example, accessing the `'*'` config from a `lsp/` file
would cause an infinite loop.

Solution:

- Explicitly disallow a config name from containing wildcards, with the
  exception of `'*'`.
- When Resolving `'*'` config, skip the rtp step.
2025-03-31 16:42:25 +01:00
b41e066aa1 docs: lsp config/commands #33122
fix #33075
2025-03-30 13:29:36 -07:00
90d15227c5 feat(lsp): workspace_required #31824
Problem:
Some language servers do not work properly without a workspace folder.

Solution:
Add `workspace_required`, which skips starting the lsp client if no
workspace folder is found.

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2025-03-30 11:07:53 -07:00
de96063bda docs(lsp): vim.api.buf_request_sync can also take function as params #33170 2025-03-30 08:51:49 -07:00
1862d3210d docs(lsp): simplify example of enabling LSP folding 2025-03-16 11:21:44 +01:00
ed07167261 fix(lsp): handle non-existent configs in lsp.config/enable 2025-03-12 09:06:28 +00:00
debabaf884 fix(lsp)!: pass buffer number to root_dir function
Problem:

The root dir function is not passed any context and can only assume the
current buffer is the one being attached.

The main use case is for getting the path of the buffer using
`nvim_buf_get_name`.

Solution:

Pass the buffer number as the first argument.
2025-03-10 18:54:03 +00:00
c4a0c1d3b0 docs: misc #31996 2025-03-02 14:27:52 -08:00
e4c1f6667b feat(lsp): use the meta model to generate server capability map 2025-02-21 08:40:33 -08:00
e71d2c817d docs: misc
Co-authored-by: Dustin S. <dstackmasta27@gmail.com>
Co-authored-by: Ferenc Fejes <fejes@inf.elte.hu>
Co-authored-by: Maria José Solano <majosolano99@gmail.com>
Co-authored-by: Yochem van Rosmalen <git@yochem.nl>
Co-authored-by: brianhuster <phambinhanctb2004@gmail.com>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2025-01-30 13:46:06 +01:00
3ee63edc1b Merge #32001 from MariaSolOs/consistent-namespaces 2025-01-15 02:01:44 -08:00
0a7e4e9e5f fix(lsp): vim.lsp.enable(...,false) does not disable #32002
Problem:
Per the documentation, passing `false` as the `enable` parameter of
`vim.lsp.enable()` should disable the given LSP(s), but it does not work
due to a logic error.

Specifically, `enable == false and nil or {}` will always evaluate to
`{}` because `nil` is falsy.

Solution:
Correct the conditional statement.
2025-01-15 01:58:36 -08:00
09e01437c9 refactor: use nvim.foo.bar format for autocommand groups 2025-01-14 21:25:25 -08:00
e8a6c1b021 fix(lsp): schedule call to vim.lsp.start for async root_dir (#31998)
When `root_dir` is a function it can (and often will) call the provided
callback function in a fast API context (e.g. in the `on_exit` handler
of `vim.system`). When the callback function is executed we should
ensure that it runs vim.lsp.start on the main event loop.
2025-01-14 08:19:54 -06:00
6a425e7045 docs: misc
Co-authored-by: Axel <axelhjq@gmail.com>
Co-authored-by: Colin Kennedy <colinvfx@gmail.com>
Co-authored-by: Daiki Noda <sys9kdr@users.noreply.github.com>
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Co-authored-by: Jean-Jacq du Plessis <1030058+jj-du-plessis@users.noreply.github.com>
Co-authored-by: Juan Giordana <juangiordana@gmail.com>
Co-authored-by: Lincoln Wallace <locnnil0@gmail.com>
Co-authored-by: Matti Hellström <hellstrom@scm.com>
Co-authored-by: Steven Locorotondo <steven.locorotondo@justeattakeaway.com>
Co-authored-by: Yochem van Rosmalen <git@yochem.nl>
Co-authored-by: glepnir <glephunter@gmail.com>
Co-authored-by: ifish <fishioon@live.com>
2025-01-11 10:34:12 +01:00
e00cd1ab40 feat(lsp): return resolved config for vim.lsp.config[name]
Allows to retrieve the configuration as it will be used by `lsp.enable`
- including the parts merged from `*` and rtp.

This is useful for explicit startup control
(`vim.lsp.start(vim.lsp.config[name])`)

Closes https://github.com/neovim/neovim/issues/31640
2024-12-31 13:18:05 +01:00
35247b00a4 feat(lsp): support function for client root_dir (#31630)
If root_dir is a function it is evaluated when the client is created to
determine the root directory.

This enables dynamically determining the root directory based on e.g.
project or directory structure (example: finding a parent Cargo.toml
file that contains "[workspace]" in a Rust project).
2024-12-27 10:09:22 -06:00
130b5fd85f feat(lsp): return table from lsp/ files on runtimepath (#31663)
Problem: LSP configs on the runtimepath must have the same name as the
LSP server and must also explicitly set the name in vim.lsp.config. This
is redundant and creates a footgun where a user may accidentally use the
wrong name when assigning to the vim.lsp.config table.

Solution: Return a table from lsp/ runtimepath files instead
2024-12-21 08:27:27 -06:00
888a803755 fix(lsp): vim.lsp.start fails if existing client has no workspace_folders #31608
Problem:
regression since https://github.com/neovim/neovim/pull/31340

`nvim -l repro.lua`:
```lua
vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls' }
vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls', root_dir = 'foo' }

-- swapped case will be ok:
-- vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls', root_dir = 'foo' }
-- vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls' }
```

Failure:
```
E5113: Error while calling lua chunk: /…/lua/vim/lsp.lua:214: bad argument #1 to
'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        /…/lua/vim/lsp.lua:214: in function 'reuse_client'
        /…/lua/vim/lsp.lua:629: in function 'start'
        repro.lua:34: in main chunk
```
2024-12-18 06:37:12 -08:00
9c20342297 fix(lsp): reuse client if configs match and no root dir
Problem:
An LSP configuration that creates client with no root_dir or
workspace_folders can result in vim.lsp.enable attaching to it multiple
times.

Solution:
When checking existing clients, reuse a client if it wasn't initially
configured have any workspace_folders. This more closely matches the
behaviour we had prior to d9235ef
2024-12-13 14:36:24 +00:00
3f1d09bc94 feat(lsp): add vim.lsp.config and vim.lsp.enable
Design goals/requirements:
- Default configuration of a server can be distributed across multiple sources.
  - And via RTP discovery.
- Default configuration can be specified for all servers.
- Configuration _can_ be project specific.

Solution:

- Two new API's:
  - `vim.lsp.config(name, cfg)`:
    - Used to define default configurations for servers of name.
    - Can be used like a table or called as a function.
    - Use `vim.lsp.confg('*', cfg)` to specify default config for all
      servers.
  - `vim.lsp.enable(name)`
    - Used to enable servers of name. Uses configuration defined
    via `vim.lsp.config()`.
2024-12-10 17:16:01 +00:00
668d2569b4 refactor: add vim._resolve_bufnr 2024-12-07 16:58:40 +00:00
5c245ec3e9 fix: remove vim.lsp._with_extend
Not used anywhere.
2024-12-07 10:08:58 +00:00
c2bf09ddff fix(lsp): check for configuration workspace folders when reusing clients 2024-12-07 09:43:45 +00:00
e56437cd48 feat(lsp): deprecate vim.lsp.start_client #31341
Problem:
LSP module has multiple "start" interfaces.

Solution:
- Enhance vim.lsp.start
- Deprecate vim.lsp.start_client
2024-12-04 05:14:47 -08:00
49d6cd1da8 docs: provide example for configuring LSP foldexpr (#31411)
Using the "supports_method" function with a client capability inside of
an LspAttach autocommand is the preferred method to do this, so we
should be showing users how to do it.
2024-12-02 12:13:09 -06:00
a1e313ded6 feat(lsp): support textDocument/foldingRange (#31311)
* refactor(shared): extract `vim._list_insert` and `vim._list_remove`

* feat(lsp): add `vim.lsp.foldexpr()`

* docs(lsp): add a todo for state management

* feat(lsp): add `vim.lsp.folding_range.foldclose()`

* feat(lsp): schedule `foldclose()` if the buffer is not up-to-date

* feat(lsp): add `vim.lsp.foldtext()`

* feat(lsp): support multiple folding range providers

* refactor(lsp): expose all folding related functions under `vim.lsp.*`

* perf(lsp): add `lsp.MultiHandler` for do `foldupdate()` only once
2024-11-29 12:40:32 +00:00
9a681ad09e fix(lsp): hover keymap (#31208)
* fix: use function call in keymap

* fix: test
2024-11-22 12:51:30 +00:00
454ae672aa feat(lsp): deprecate non-method client functions
Deprecated:
- `client.request()` -> `client:request()`
- `client.request_sync()` -> `client:request_sync()`
- `client.notify()` -> `client:notify()`
- `client.cancel_request()` -> `client:cancel_request()`
- `client.stop()` -> `client:stop()`
- `client.is_stopped()` `client:is_stopped()`
- `client.supports_method()` -> `client:supports_method()`
- `client.on_attach()` -> `client:on_attach()`

Fixed docgen to link class fields to the full function doc.
2024-11-20 08:51:45 +00:00
989a37a594 refactor(lsp): fold in dynamic_registration code into the client
Problem:

Capability register logic is spread across 3 files.

Solution:

- Consolidate (and simplify) logic into the client.
- Teach client.supports_method about resolve methods
2024-11-18 17:09:53 +00:00
9b357e30fd feat(lsp)!: remove client-server handlers from vim.lsp.handlers
- Partition the handlers in vim.lsp.handlers as:
  - client to server response handlers (RCS)
  - server to client request handlers (RSC)
  - server to client notification handlers (NSC)

  Note use string indexes instead of protocol.methods for improved
  typing in LuaLS (tip: use hover on RCS, RSC or NSC).
2024-11-01 09:17:39 +00:00
2cd6abf0d7 Merge pull request #30935 from lewis6991/feat/lsp_multi_hover 2024-10-29 09:51:14 +00:00