Commit Graph

200 Commits

Author SHA1 Message Date
3b6084ddf4 fix: type fixes
Type fixes caught by emmylua
2025-06-06 15:36:48 +01:00
52a4bc4548 docs: lsp, emoji, startup #33446
Co-authored-by: Maria José Solano <majosolano99@gmail.com>
2025-04-27 13:40:46 -07:00
342974773c fix(lsp): cycling signatures with the default config.focusable 2025-04-26 16:12:25 +08:00
9e93bfdb5f fix(lsp): prioritize showing active signature 2025-04-26 15:44:30 +08:00
Au.
6926fc1615 fix(lsp): opts.reuse_win does not jump if buf is already open #33476
Problem:
`vim.lsp.buf.[implementation|definition|...]({ reuse_win = true })` does not
jump cursor to existing window if buffer is already open.

Steps to reproduce:
1. `nvim repro.lua`
2. Insert anything that lsp can read to open the library definition/implementation, e.g., `vim.keymap.set`
3. open `repro.lua` buffer and the library buffer side by side.
4. type `gd` over `set` to jump to the library definition.

The open buffer is scrolled to the target line, but cursor does not jump.

Solution:
Call nvim_set_current_win if necessary.
2025-04-17 07:46:18 -07: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
f8d5811c71 fix(lsp): correctly check for "codeAction/resolve" support 2025-03-15 15:56:47 +01:00
5d08b65ac2 fix(lsp): use unresolved code action when codeAction/resolve fails 2025-03-07 10:23:55 +01:00
41b07b128c feat(lsp): support for resolving code action command (#32704)
* fix(lsp): don't call codeAction_resolve with commands

* feat(lsp): support for resolving code action command
2025-03-06 08:21:47 +00:00
c4a0c1d3b0 docs: misc #31996 2025-03-02 14:27:52 -08:00
efe92f9dff fix(docs): update context type in vim.lsp.LocationOpts.OnList 2025-02-16 11:31:08 +01:00
24d7debdfb fix(lsp): signature_help highlights wrong parameter #32382
Problem:
With some LSP servers, `vim.lsp.buf.signature_help` (CTRL-s in insert-mode)
highlights the first parameter regardless of the current cursor position.

- On some lsps the `textDocument/signatureHelp` response only includes the
  `activeParameter` field on the `lsp.SignatureHelp` object.
  ```lua
  {
    {
      result = {
        activeParameter = 2,
        signatures = {
          {
            documentation = {
              kind = "markdown",
              value = ""
            },
            label = "getBuyers(ctx context.Context, orderDB boil.ContextExecutor, supplierID string) ([]*BuyerWithLocation, error)",
            parameters = {
              {
                label = "ctx context.Context"
              },
              {
                label = "orderDB boil.ContextExecutor"
              },
              {
                label = "supplierID string"
              }
            }
          }
        }
      }
    }
  }
  ```

Solution:
Ensure we retain this information before showing the signature information.

Closes #32381
2025-02-09 10:02:46 -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
6aa42e8f92 fix: resolve all remaining LuaLS diagnostics 2025-01-27 16:37:50 +00:00
a450fda4ed fix(lsp): prefer on_list over loclist in default handler
Problem: setting `loclist = true` makes `on_list` being ignored. This
  was not a problem before, but with `vim.lsp.buf.document_symbol` using
  `loclist = true` as default it is needed to explicitly pass `loclist =
  false` in order to use custom `on_list`.

Solution: prefer `on_list` over `loclist` and document the latter as
  taking effect only in the default handler.
2025-01-23 17:04:23 +01:00
d56ba71af1 fix(lsp): document_symbol uses loclist by default #32070
Problem: Not able to open document symbols for different buffers

Solution: Use the location list as default.

To switch back to previous behavior (qflist):

  vim.lsp.buf.document_symbol({ loclist = false })

Fixes: #31832
2025-01-19 13:08:10 -08:00
850084b519 refactor: use nvim.foo.bar format for namespaces 2025-01-14 19:55:29 -08:00
02097e43c8 fix(lsp): check if sig_help window is focusable when configuring cycle keymap 2024-12-29 16:23:23 +00:00
668d2569b4 refactor: add vim._resolve_bufnr 2024-12-07 16:58:40 +00:00
146b8300a1 docs(lsp): update example, optional parameters #31299 2024-11-28 08:08:27 -08:00
864f25d6b0 docs: more accurate typing for LSP references context
**Problem:** The `context` parameter for `references()` is just typed as
a table, which is unhelpful.

**Solution:** Properly type it as an `lsp.ReferenceContext`!
2024-11-28 09:05:17 +01:00
165b099fa3 refactor(lsp): rename offset_encoding to position_encoding #31286
Problem:
LSP spec uses the term "position encoding" where we say "offset encoding".

Solution:
- Rename it everywhere except `vim.lsp.Client.offset_encoding` (which would be breaking).
- Mention "position encoding" in the documentation for `vim.lsp.Client.offset_encoding`.
2024-11-25 08:06:05 -08: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
44229bb85b feat(lsp): highlight hover target/range #31110
**Problem:** Despite the LSP providing the option for language servers
to specify a range with a hover response (for highlighting), Neovim does
not give the option to highlight this range.

**Solution:** Add an option to `buf.hover()` which causes this range to
be highlighted.

Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
2024-11-17 12:31:32 -08:00
6e68fed374 feat(lsp): multi-client support for signature_help
Signatures can be cycled using `<C-s>` when the user enters the floating
window.
2024-11-04 11:55:39 +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
b4599acbf8 fix(lsp): correct hover result handling (#30995)
Problem: vim.lsp.buf.hover() displays "No information available" when client_id
is not 1.

Solution: use vim.tbl_isempty(tbl) instead of #tbl==0
2024-10-30 16:57:33 +01:00
8260e4860b feat(lsp)!: multiple client support for vim.lsp.buf.hover()
Deprecate `vim.lsp.handlers.hover` and `vim.lsp.handlers['textDocument/hover']`
2024-10-29 09:06:05 +00:00
54249d051c feat(lsp): deprecate vim.lsp.buf.completion
Use `vim.lsp.completion.trigger()` instead'
2024-10-24 16:36:14 +01:00
7a7747f1e4 feat(lsp): deprecate execute_command with client:exec_cmd 2024-10-24 15:37:34 +01:00
39d79efa1e fix(lsp): better multi-client support for callHierarchy
Only ever display a dialogue box once.

Switch from vim.fn.inpulist to vim.ui.select

refactor(lsp): merge call and type hierarchy functions
2024-10-24 13:15:25 +01:00
c8d7d65679 fix(lsp): use correct method for prepareTypehierarchy
Regression from #30902
2024-10-24 13:15:25 +01:00
3c51058d76 fix(lsp): set tagstack on jump via goto methods
Follow up to https://github.com/neovim/neovim/pull/30877
Fixes https://github.com/neovim/neovim/issues/30926
2024-10-24 13:43:49 +02:00
2dcbfe78fc fix(lsp.buf): use correct offset_encoding for all requests
Problem:

`lsp.buf_request` send the same params to all servers and many
calls to this pass PositionalParams which depends on the clients
offset_encoding. This can result with incorrect params being sent
to a server.

Solution:

`lsp.buf_request` `params` argument can now be passed as a function
which takes the client as the first argument. This is used in
lsp/buf.lua to construct correct params for each client request.
2024-10-24 10:53:06 +01:00
2ee39b7eb4 refactor(lsp.buf): remove buf_request wrapper 2024-10-24 09:58:22 +01:00
ad4e14c201 refactor(lsp.buf): use alias for vim.lsp 2024-10-24 09:55:23 +01:00
629a5b71b5 fix(lsp): support multiple clients in typehierarchy 2024-10-22 21:59:48 +01:00
0083e03d6f feat(lsp)!: support multiple clients in goto methods (#30877)
Relates to:

- https://github.com/neovim/neovim/issues/30034
- https://github.com/neovim/neovim/issues/17712
- https://github.com/neovim/neovim/issues/16363

Closes:

- https://github.com/neovim/neovim/issues/26936 (but only provides bufnr
  and method)
- https://github.com/neovim/neovim/issues/22318

Might fix: https://github.com/neovim/neovim/issues/30737
2024-10-20 23:40:44 +02:00
dff684fdb3 feat(lsp)!: support multiple clients in lsp.buf.references
Relates to:

- https://github.com/neovim/neovim/issues/17712
- https://github.com/neovim/neovim/issues/30034
2024-10-20 14:43:22 +02:00
3f3e4837d5 perf(validate): use lighter version
- Also fix `vim.validate()` for PUC Lua when showing errors for values
  that aren't string or number.
2024-10-17 16:53:52 +01:00
fa6ab0d909 Merge pull request #30825 from lewis6991/refactor/lsputil 2024-10-17 13:35:02 +01:00
acbc6a7f91 fix(lsp.util): inconsistent handling of offset_encoding 2024-10-17 12:52:45 +01:00
ce678043e3 feat(lsp): show server name in code actions #30830
Problem:
If there are multiple LSP clients, it's not clear which actions are provided by which servers. #30710

Solution:
Show the server name next to each action (only if there are multiple clients).
2024-10-17 01:35:19 -07:00
adbaaa5225 docs(lsp): hover window controls #30347 2024-09-19 08:00:08 -07:00
8654a97006 fix(lsp): handle empty call hierarchy items #30349
Ensure that the function `pick_call_hierarchy_item` correctly handles
the case where `call_hierarchy_items` is nil or an empty table. This
prevents potential errors when the function is called with no items.
2024-09-13 04:59:49 -07:00
d9ccd828b0 fix(lsp): return call hierarchy item, not the index (#30145) 2024-08-26 17:37:36 +02:00
7031949be0 fix(lsp): avoid reusing diagnostics from different servers in actions (#30002)
Problem: When preparing the parameters for a code actions LSP request,
the code set `context.diagnostics` when processing the first LSP client,
and then reused those `context.diagnostics` for subsequent LSP clients.

This meant that the second and next LSP clients got diagnostics that
did not originate from them, and they did not get the diagnostics that
they sent.

Solution: Avoid setting `context.diagnostics` (which is referenced by
all clients). Instead, set `params.context.diagnostics` directly, which
is specific to a single client.

Fixes #30001
Caused by #29501
2024-08-07 17:28:01 +02:00
720b309c78 fix(lsp): don't send foreign diagnostics to servers in buf.code_action (#29501)
`buf.code_action` always included diagnostics on a given line from all
clients. Servers should only receive diagnostics they published, and in
the exact same format they sent it.

Should fix https://github.com/neovim/neovim/issues/29500
2024-08-01 16:01:15 +02:00
5581a95534 feat(lsp): vim.lsp.buf.format() supports textDocument/rangesFormatting #27323
While this relies on a proposed LSP 3.18 feature, it's fully backwards
compatible, so IMO there's no harm in adding this already.

Looks like some servers already support for this e.g.
- gopls: https://go-review.googlesource.com/c/tools/+/510235
- clangd: https://github.com/llvm/llvm-project/pull/80180

Fixes #27293
2024-06-24 07:54:56 -07:00