Commit Graph

6 Commits

Author SHA1 Message Date
Yi Ming
2ace4089f8 refactor(lsp): no longer rely on LspDetach for detaching capabilities 2025-08-18 19:41:55 +08:00
Yi Ming
b3fbc8d6fa refactor(lsp): move util.enable to capability.enable 2025-08-18 19:41:53 +08:00
Yi Ming
a37e101dc7 refactor(lsp): change capability name to snake case 2025-08-17 12:37:34 +08:00
Yi Ming
7c3e579a90 refactor(lsp): register all derived Capability prototypes 2025-08-17 12:37:34 +08:00
Yi Ming
81d8198bda refactor(lsp): define Capability.on_attach 2025-08-17 12:37:34 +08:00
Yi Ming
8d5452c46d refactor(lsp): stateful data abstraction, vim.lsp.Capability #34639
Problem:
Closes #31453

Solution:
Introduce `vim.lsp.Capability`, which may serve as the base class for
all LSP features that require caching data. it
- was created if there is at least one client that supports the specific method;
- was destroyed if all clients that support the method were detached.

- Apply the refactor for `folding_range.lua` and `semantic_tokens.lua`.
- Show active features in :checkhealth.

Future:
I found that these features that are expected to be refactored by
`vim.lsp.Capability` have one characteristic in common: they all send
LSP requests once the document is modified. The following code is
different, but they are all for this purpose.

- semantic tokens:
fb8dba413f/runtime/lua/vim/lsp/semantic_tokens.lua (L192-L198)
- inlay hints, folding ranges, document color
fb8dba413f/runtime/lua/vim/lsp/inlay_hint.lua (L250-L266)

I think I can sum up this characteristic as the need to keep certain
data synchronized with the latest version computed by the server.
I believe we can handle this at the `vim.lsp.Capability` level, and
I think it will be very useful.

Therefore, my next step is to implement LSP request sending and data
synchronization on `vim.lsp.Capability`, rather than limiting it to the
current create/destroy data approach.
2025-07-07 03:51:30 +00:00