diff options
author | Jongwook Choi <wookayin@gmail.com> | 2023-08-31 04:14:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 10:14:20 +0200 |
commit | 0e7e25af20cf98a19f4f50ee80774fce07cef12e (patch) | |
tree | ac5e3ee8ef76bfd1672b8692332a307ca32d530b /runtime/lua/vim/lsp.lua | |
parent | c235959fd909d75248c066a781475e207606c5aa (diff) | |
download | rneovim-0e7e25af20cf98a19f4f50ee80774fce07cef12e.tar.gz rneovim-0e7e25af20cf98a19f4f50ee80774fce07cef12e.tar.bz2 rneovim-0e7e25af20cf98a19f4f50ee80774fce07cef12e.zip |
refactor(lsp): add type annotation for lsp.Client.server_capabilities (#24925)
The class `lsp.Client` has a public member `server_capabilities`,
which is assumed to be non-nil once initialized, as documented in
`:help vim.lsp.client`. Due to the possibility that it may be nil
before initialization, `lsp.Client` was not having a proper lua type
annotations on the field `server_capabilities`.
Instead of having a nil `server_capabilities` until initialized in
the RPC response callback, we can have an initial value of empty table.
This CHANGES the behavior of the `server_capabilities` field in a way
that it is no longer `nil` until initialization. Note that, as
already documented, `server_capabilities` should never be nil when
it is once initialized and thus ready to be used in user configs.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 1990c09561..b0caf5af35 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -397,8 +397,7 @@ do ---@return CTGroup local function get_group(client) local allow_inc_sync = if_nil(client.config.flags.allow_incremental_sync, true) - local change_capability = - vim.tbl_get(client.server_capabilities or {}, 'textDocumentSync', 'change') + local change_capability = vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'change') local sync_kind = change_capability or protocol.TextDocumentSyncKind.None if not allow_inc_sync and change_capability == protocol.TextDocumentSyncKind.Incremental then sync_kind = protocol.TextDocumentSyncKind.Full @@ -1312,6 +1311,9 @@ function lsp.start_client(config) --- - lsp.WorkDoneProgressEnd (extended with title from Begin) progress = vim.ringbuf(50), + --- @type lsp.ServerCapabilities + server_capabilities = {}, + ---@deprecated use client.progress instead messages = { name = name, messages = {}, progress = {}, status = {} }, dynamic_capabilities = require('vim.lsp._dynamic').new(client_id), @@ -1401,7 +1403,7 @@ function lsp.start_client(config) if not required_capability then return true end - if vim.tbl_get(client.server_capabilities or {}, unpack(required_capability)) then + if vim.tbl_get(client.server_capabilities, unpack(required_capability)) then return true else if client.dynamic_capabilities:supports_registration(method) then |