Skip to content

Commit ca9b75b

Browse files
committed
feat!: move all vim.lsp.config to a config table for more general support
1 parent 46c1039 commit ca9b75b

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,24 @@ local opts = {
8989
desc = "Format file with LSP",
9090
},
9191
},
92-
-- Configure default capabilities for all language servers (`:h vim.lsp.protocol.make_client.capabilities()`)
93-
capabilities = {
94-
textDocument = {
95-
foldingRange = { dynamicRegistration = false },
92+
-- Configure language servers with `vim.lsp.config` (`:h vim.lsp.config`)
93+
config = {
94+
-- Configure LSP defaults
95+
["*"] = {
96+
-- Configure default capabilities
97+
capabilities = {
98+
textDocument = {
99+
foldingRange = { dynamicRegistration = false },
100+
},
101+
},
102+
-- Custom flags table to be passed to all language servers
103+
flags = {
104+
exit_timeout = 5000,
105+
},
96106
},
97107
},
98108
defaults = {
99-
hover = { border = "rounded", silent = true } -- customize lsp hover window
109+
hover = { border = "rounded", silent = true }, -- customize lsp hover window
100110
signature_help = false, -- disable any default customizations
101111
},
102112
-- Configuration of LSP file operation functionality
@@ -113,10 +123,6 @@ local opts = {
113123
didDelete = true,
114124
},
115125
},
116-
-- A custom flags table to be passed to all language servers (`:h lspconfig-setup`)
117-
flags = {
118-
exit_timeout = 5000,
119-
},
120126
-- Configuration options for controlling formatting with language servers
121127
formatting = {
122128
-- control auto formatting on save
@@ -146,7 +152,7 @@ local opts = {
146152
-- default handler uses key "*"
147153
["*"] = vim.lsp.enable,
148154
-- custom function handler for pyright
149-
pyright = function() vim.lsp.enable("pyright") end,
155+
pyright = function() vim.lsp.enable "pyright" end,
150156
-- set to false to disable the setup of a language server
151157
rust_analyzer = false,
152158
},

lua/astrolsp/config.lua

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,22 @@
121121
---}
122122
---```
123123
---@field features AstroLSPFeatureOpts?
124-
---Configure default capabilities for language servers (`:h vim.lsp.protocol.make_client.capabilities()`)
124+
---Configure options for language servers passed to `vim.lsp.config(key, config)` (`:h vim.lsp.config`)
125125
---Example
126126
--
127127
---```lua
128-
---capabilities = {
129-
--- textDocument = {
130-
--- foldingRange = { dynamicRegistration = false }
131-
--- }
128+
---config = {
129+
--- ["*"] = {
130+
--- capabilities = {
131+
--- textDocument = {
132+
--- foldingRange = { dynamicRegistration = false }
133+
--- }
134+
--- },
135+
--- flags = { exit_timeout = 5000 },
136+
--- },
132137
---}
133138
---```
134-
---@field capabilities lsp.ClientCapabilities?
139+
---@field config table<string,vim.lsp.Config>?
135140
---Configure default options passed to `vim.lsp.buf` functions
136141
---Example:
137142
---
@@ -168,13 +173,6 @@
168173
--- }
169174
---```
170175
---@field file_operations AstroLSPFileOperationsOpts|false?
171-
---A custom flags table to be passed to all language servers (`:h lspconfig-setup`)
172-
---Example:
173-
--
174-
---```lua
175-
---flags = { exit_timeout = 5000 }
176-
---```
177-
---@field flags table?
178176
---Configuration options for controlling formatting with language servers
179177
---Example:
180178
--
@@ -294,10 +292,9 @@ local M = {
294292
semantic_tokens = true,
295293
signature_help = false,
296294
},
297-
capabilities = {},
295+
config = {},
298296
defaults = {},
299297
file_operations = { timeout = 10000, operations = {} },
300-
flags = {},
301298
formatting = { format_on_save = { enabled = true }, disabled = {} },
302299
handlers = {},
303300
lsp_handlers = {},

lua/astrolsp/init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,16 @@ function M.setup(opts)
229229
-- enable necessary capabilities for enabled LSP file operations
230230
local fileOperations = vim.tbl_get(M.config, "file_operations", "operations")
231231
if fileOperations and not vim.tbl_isempty(fileOperations) then
232-
M.config.capabilities = vim.tbl_deep_extend("force", M.config.capabilities or {}, {
233-
workspace = { fileOperations = fileOperations },
232+
M.config.config = vim.tbl_deep_extend("force", M.config.config or {}, {
233+
["*"] = {
234+
capabilities = { workspace = { fileOperations = fileOperations } },
235+
},
234236
})
235237
end
236238

237-
vim.lsp.config("*", { capabilities = M.config.capabilities, flags = M.config.flags })
239+
for server, config in pairs(M.config.config) do
240+
vim.lsp.config(server, config)
241+
end
238242

239243
-- Set up tracking of signature help trigger characters
240244
M.add_on_attach(M.on_attach, {

0 commit comments

Comments
 (0)