diff options
author | August Masquelier <31262046+levouh@users.noreply.github.com> | 2022-10-04 12:44:19 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-04 20:44:19 +0200 |
commit | b075f49d9229b3e58a4d6677ed8e01db60687fa3 (patch) | |
tree | 920e67dd55a83f7bf41830afee0aceaaa3e82c5d | |
parent | c651152a9db56d9fb4681789e38d9b52d996e960 (diff) | |
download | rneovim-b075f49d9229b3e58a4d6677ed8e01db60687fa3.tar.gz rneovim-b075f49d9229b3e58a4d6677ed8e01db60687fa3.tar.bz2 rneovim-b075f49d9229b3e58a4d6677ed8e01db60687fa3.zip |
feat(lsp): add bufnr option to lsp.start (#20473)
-rw-r--r-- | runtime/doc/lsp.txt | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp.lua | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index b3bff89224..d8dcf60c21 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -825,6 +825,8 @@ start({config}, {opts}) *vim.lsp.start()* Predicate used to decide if a client should be re-used. Used on all running clients. The default implementation re-uses a client if name and root_dir matches. + • bufnr (number) Buffer handle to attach to if starting or + re-using a client (0 for current). Return: ~ (number|nil) client_id diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index a64facf214..349c662258 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -860,6 +860,9 @@ end --- Used on all running clients. --- The default implementation re-uses a client if name --- and root_dir matches. +--- - bufnr (number) +--- Buffer handle to attach to if starting or re-using a +--- client (0 for current). ---@return number|nil client_id function lsp.start(config, opts) opts = opts or {} @@ -871,7 +874,10 @@ function lsp.start(config, opts) if not config.name and type(config.cmd) == 'table' then config.name = config.cmd[1] and vim.fs.basename(config.cmd[1]) or nil end - local bufnr = api.nvim_get_current_buf() + local bufnr = opts.bufnr + if bufnr == nil or bufnr == 0 then + bufnr = api.nvim_get_current_buf() + end for _, clients in ipairs({ uninitialized_clients, lsp.get_active_clients() }) do for _, client in pairs(clients) do if reuse_client(client, config) then |