diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-11-19 10:11:40 +0000 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-11-19 12:19:05 +0000 |
commit | 081beb3659bd6d8efc3e977a160b1e72becbd8a2 (patch) | |
tree | fd9da850f3df20c591175cc53ee236f2140967c3 | |
parent | 0183c3247455a4c2364e5e78d6b716e98ef16aeb (diff) | |
download | rneovim-081beb3659bd6d8efc3e977a160b1e72becbd8a2.tar.gz rneovim-081beb3659bd6d8efc3e977a160b1e72becbd8a2.tar.bz2 rneovim-081beb3659bd6d8efc3e977a160b1e72becbd8a2.zip |
fix(lsp): restore get_language_id behaviour
Ensure filetype is always passed.
Fixes #31262
-rw-r--r-- | runtime/doc/lsp.txt | 4 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/client.lua | 21 |
2 files changed, 15 insertions, 10 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index b7a4f0ea01..64bef849fc 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -968,7 +968,7 @@ Lua module: vim.lsp.client *lsp-client* request before sending kill -15. If set to false, nvim exits immediately after sending the "shutdown" request to the server. - • {get_language_id} (`fun(bufnr: integer, filetype?: string): string`) + • {get_language_id} (`fun(bufnr: integer, filetype: string): string`) • {capabilities} (`lsp.ClientCapabilities`) The capabilities provided by the client (editor or tool) • {dynamic_capabilities} (`lsp.DynamicCapabilities`) @@ -1089,7 +1089,7 @@ Lua module: vim.lsp.client *lsp-client* `initialize` in the LSP spec. • {name}? (`string`, default: client-id) Name in log messages. - • {get_language_id}? (`fun(bufnr: integer, filetype?: string): string`) + • {get_language_id}? (`fun(bufnr: integer, filetype: string): string`) Language ID as string. Defaults to the buffer filetype. • {offset_encoding}? (`'utf-8'|'utf-16'|'utf-32'`) The encoding that diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua index ba12447c40..11ecb87507 100644 --- a/runtime/lua/vim/lsp/client.lua +++ b/runtime/lua/vim/lsp/client.lua @@ -92,7 +92,7 @@ local validate = vim.validate --- @field name? string --- --- Language ID as string. Defaults to the buffer filetype. ---- @field get_language_id? fun(bufnr: integer, filetype?: string): string +--- @field get_language_id? fun(bufnr: integer, filetype: string): string --- --- The encoding that the LSP server expects. Client does not verify this is correct. --- @field offset_encoding? 'utf-8'|'utf-16'|'utf-32' @@ -212,7 +212,7 @@ local validate = vim.validate --- A table with flags for the client. The current (experimental) flags are: --- @field flags vim.lsp.Client.Flags --- ---- @field get_language_id fun(bufnr: integer, filetype?: string): string +--- @field get_language_id fun(bufnr: integer, filetype: string): string --- --- The capabilities provided by the client (editor or tool) --- @field capabilities lsp.ClientCapabilities @@ -340,10 +340,10 @@ end --- By default, get_language_id just returns the exact filetype it is passed. --- It is possible to pass in something that will calculate a different filetype, --- to be sent by the client. ---- @param bufnr integer ---- @param filetype? string -local function default_get_language_id(bufnr, filetype) - return filetype or vim.bo[bufnr].filetype +--- @param _bufnr integer +--- @param filetype string +local function default_get_language_id(_bufnr, filetype) + return filetype end --- Validates a client configuration as given to |vim.lsp.start_client()|. @@ -936,6 +936,11 @@ function Client:_unregister(unregistrations) end end +--- @private +function Client:_get_language_id(bufnr) + return self.get_language_id(bufnr, vim.bo[bufnr].filetype) +end + --- @param method string --- @param bufnr? integer --- @return lsp.Registration? @@ -946,7 +951,7 @@ function Client:_get_registration(method, bufnr) return reg end local documentSelector = reg.registerOptions.documentSelector - local language = self.get_language_id(bufnr) + local language = self:_get_language_id(bufnr) local uri = vim.uri_from_bufnr(bufnr) local fname = vim.uri_to_fname(uri) for _, filter in ipairs(documentSelector) do @@ -1027,7 +1032,7 @@ function Client:_text_document_did_open_handler(bufnr) textDocument = { version = lsp.util.buf_versions[bufnr], uri = vim.uri_from_bufnr(bufnr), - languageId = self.get_language_id(bufnr), + languageId = self:_get_language_id(bufnr), text = lsp._buf_get_full_text(bufnr), }, }) |