aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-03-07 11:48:43 +0000
committerLewis Russell <me@lewisr.dev>2024-03-07 12:01:10 +0000
commite172dd599cff2ae5267871b5e33fb42934c4df43 (patch)
tree61dcb038265de779341cc94a1938c3685a51deb2 /lua
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.tar
nvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.tar.gz
nvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.tar.bz2
nvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.tar.lz
nvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.tar.xz
nvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.tar.zst
nvim-lspconfig-e172dd599cff2ae5267871b5e33fb42934c4df43.zip
refactor: general cleanup
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/manager.lua30
-rw-r--r--lua/lspconfig/ui/lspinfo.lua8
-rw-r--r--lua/lspconfig/util.lua19
3 files changed, 35 insertions, 22 deletions
diff --git a/lua/lspconfig/manager.lua b/lua/lspconfig/manager.lua
index ae648a11..9940d2a2 100644
--- a/lua/lspconfig/manager.lua
+++ b/lua/lspconfig/manager.lua
@@ -23,7 +23,7 @@ local function check_in_workspace(client, root_dir)
end
--- @class lspconfig.Manager
---- @field _clients table<string,table>
+--- @field _clients table<string,integer[]>
--- @field config lspconfig.Config
--- @field make_config fun(root_dir: string): lspconfig.Config
local M = {}
@@ -42,9 +42,12 @@ function M.new(config, make_config)
end
--- @private
-function M:_get_client_from_cache(root_dir, client_name)
- local clients = self._clients
- if vim.tbl_count(clients) == 0 then
+--- @param clients table<string,integer[]>
+--- @param root_dir string
+--- @param client_name string
+--- @return vim.lsp.Client?
+local function get_client(clients, root_dir, client_name)
+ if vim.tbl_isempty(clients) then
return
end
@@ -57,15 +60,12 @@ function M:_get_client_from_cache(root_dir, client_name)
end
end
- local all_client_ids = {}
- vim.tbl_map(function(val)
- vim.list_extend(all_client_ids, { unpack(val) })
- end, clients)
-
- for _, id in ipairs(all_client_ids) do
- local client = lsp.get_client_by_id(id)
- if client and client.name == client_name then
- return client
+ for _, ids in pairs(clients) do
+ for _, id in ipairs(ids) do
+ local client = lsp.get_client_by_id(id)
+ if client and client.name == client_name then
+ return client
+ end
end
end
end
@@ -181,7 +181,7 @@ end
--- @param client vim.lsp.Client
--- @param single_file boolean
function M:_attach_after_client_initialized(bufnr, new_config, root_dir, client, single_file)
- local timer = assert(vim.loop.new_timer())
+ local timer = assert(uv.new_timer())
timer:start(
0,
10,
@@ -201,7 +201,7 @@ end
function M:add(root_dir, single_file, bufnr)
root_dir = util.path.sanitize(root_dir)
local new_config = self.make_config(root_dir)
- local client = self:_get_client_from_cache(root_dir, new_config.name)
+ local client = get_client(self._clients, root_dir, new_config.name)
---If single_file_mode is false then root_dir should match client otherwise start a new client
if not client or (not single_file and client.config.root_dir and client.config.root_dir ~= root_dir) then
diff --git a/lua/lspconfig/ui/lspinfo.lua b/lua/lspconfig/ui/lspinfo.lua
index d57c1cb8..704c344c 100644
--- a/lua/lspconfig/ui/lspinfo.lua
+++ b/lua/lspconfig/ui/lspinfo.lua
@@ -120,7 +120,7 @@ local function make_config_info(config, bufnr)
return lines
end
----@param client table
+---@param client vim.lsp.Client
---@param fname string
local function make_client_info(client, fname)
local client_info = {}
@@ -200,7 +200,7 @@ return function()
local win_info = windows.percentage_range_window(0.8, 0.7)
local bufnr, win_id = win_info.bufnr, win_info.win_id
- api.nvim_buf_set_option(bufnr, 'bufhidden', 'wipe')
+ vim.bo.bufhidden = 'wipe'
local buf_lines = {}
@@ -274,8 +274,8 @@ return function()
local fmt_buf_lines = indent_lines(buf_lines, ' ')
api.nvim_buf_set_lines(bufnr, 0, -1, true, fmt_buf_lines)
- api.nvim_buf_set_option(bufnr, 'modifiable', false)
- api.nvim_buf_set_option(bufnr, 'filetype', 'lspinfo')
+ vim.bo.modifiable = false
+ vim.bo.filetype = 'lspinfo'
local augroup = api.nvim_create_augroup('lspinfo', { clear = false })
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 176365d1..073b0e12 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -100,6 +100,8 @@ M.path = (function()
return path:gsub('([%[%]%?%*])', '\\%1')
end
+ --- @param path string
+ --- @return string
local function sanitize(path)
if is_windows then
path = path:sub(1, 1):upper() .. path:sub(2)
@@ -108,19 +110,27 @@ M.path = (function()
return path
end
+ --- @param filename string
+ --- @return string|false
local function exists(filename)
local stat = uv.fs_stat(filename)
return stat and stat.type or false
end
+ --- @param filename string
+ --- @return boolean
local function is_dir(filename)
return exists(filename) == 'directory'
end
+ --- @param filename string
+ --- @return boolean
local function is_file(filename)
return exists(filename) == 'file'
end
+ --- @param path string
+ --- @return boolean
local function is_fs_root(path)
if is_windows then
return path:match '^%a:$'
@@ -129,6 +139,8 @@ M.path = (function()
end
end
+ --- @param filename string
+ --- @return boolean
local function is_absolute(filename)
if is_windows then
return filename:match '^%a:' or filename:match '^\\\\'
@@ -137,13 +149,14 @@ M.path = (function()
end
end
- --- @param path string
- --- @return string?
+ --- @generic T: string?
+ --- @param path T
+ --- @return T
local function dirname(path)
local strip_dir_pat = '/([^/]+)$'
local strip_sep_pat = '/$'
if not path or #path == 0 then
- return
+ return path
end
local result = path:gsub(strip_sep_pat, ''):gsub(strip_dir_pat, '')
if #result == 0 then