Skip to content

Commit 52e118c

Browse files
committed
feat!: move entirely to built in vim.lsp.config
1 parent 9940602 commit 52e118c

File tree

4 files changed

+43
-278
lines changed

4 files changed

+43
-278
lines changed

README.md

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ AstroLSP provides a simple API for configuring and setting up language servers i
1212

1313
## ⚡️ Requirements
1414

15-
- Neovim >= 0.10
15+
- Neovim >= 0.11
1616

1717
## 📦 Installation
1818

@@ -89,27 +89,12 @@ local opts = {
8989
desc = "Format file with LSP",
9090
},
9191
},
92-
-- Configure default capabilities for language servers (`:h vim.lsp.protocol.make_client.capabilities()`)
92+
-- Configure default capabilities for all language servers (`:h vim.lsp.protocol.make_client.capabilities()`)
9393
capabilities = {
9494
textDocument = {
9595
foldingRange = { dynamicRegistration = false },
9696
},
9797
},
98-
-- Configure language servers for `lspconfig` (`:h lspconfig-setup`)
99-
config = {
100-
lua_ls = {
101-
settings = {
102-
Lua = {
103-
hint = { enable = true, arrayIndex = "Disable" },
104-
},
105-
},
106-
},
107-
clangd = {
108-
capabilities = {
109-
offsetEncoding = "utf-8",
110-
},
111-
},
112-
},
11398
defaults = {
11499
hover = { border = "rounded", silent = true } -- customize lsp hover window
115100
signature_help = false, -- disable any default customizations
@@ -158,10 +143,10 @@ local opts = {
158143
},
159144
-- Configure how language servers get set up
160145
handlers = {
161-
-- default handler, first entry with no key
162-
function(server, opts) require("lspconfig")[server].setup(opts) end,
146+
-- default handler uses key "*"
147+
["*"] = vim.lsp.enable,
163148
-- custom function handler for pyright
164-
pyright = function(_, opts) require("lspconfig").pyright.setup(opts) end,
149+
pyright = function() vim.lsp.enable("pyright") end,
165150
-- set to false to disable the setup of a language server
166151
rust_analyzer = false,
167152
},
@@ -198,25 +183,12 @@ local opts = {
198183
},
199184
},
200185
},
201-
-- Extra configuration for the `mason-lspconfig.nvim` plugin
202-
mason_lspconfig = {
203-
-- Allow registering more Mason packages as language servers for autodetection/setup
204-
servers = {
205-
-- The key is the lspconfig server name to register a package for
206-
nextflow_ls = {
207-
-- The Mason package name to register to the language server
208-
package = "nextflow-language-server",
209-
-- The filetypes that apply to the package and language server
210-
filetypes = { "nextflow" },
211-
-- (Optional) any default configuration changes that may need to happen (can be a table or a function that returns a table)
212-
config = { cmd = { "nextflow-language-server" } }
213-
}
214-
}
215-
}
216186
-- A list like table of servers that should be setup, useful for enabling language servers not installed with Mason.
217187
servers = { "dartls" },
218188
-- A custom `on_attach` function to be run after the default `on_attach` function, takes two parameters `client` and `bufnr` (`:h lspconfig-setup`)
219-
on_attach = function(client, bufnr) client.server_capabilities.semanticTokensProvider = nil end,
189+
on_attach = function(client, bufnr)
190+
-- custom on_attach code to run on all servers
191+
end,
220192
}
221193
```
222194

@@ -228,43 +200,26 @@ local opts = {
228200

229201
```lua
230202
{
231-
"neovim/nvim-lspconfig",
232-
dependencies = {
233-
{ "AstroNvim/astrolsp", opts = {} },
234-
},
235-
config = function()
236-
-- set up servers configured with AstroLSP
237-
vim.tbl_map(require("astrolsp").lsp_setup, require("astrolsp").config.servers)
238-
end,
203+
"AstroNvim/astrolsp",
204+
dependencies = { "neovim/nvim-lspconfig" },
205+
opts = {}
239206
}
240207
```
241208

242209
### [nvim-lspconfig][lspconfig] + [mason.nvim][mason] + [mason-lspconfig.nvim][mason-lspconfig]
243210

244211
```lua
245212
{
246-
"neovim/nvim-lspconfig",
213+
"AstroNvim/astrolsp",
247214
dependencies = {
248-
{ "AstroNvim/astrolsp", opts = {} },
215+
"neovim/nvim-lspconfig",
249216
{
250-
"williamboman/mason-lspconfig.nvim", -- MUST be set up before `nvim-lspconfig`
217+
"williamboman/mason-lspconfig.nvim",
251218
dependencies = { "williamboman/mason.nvim" },
252-
opts = {
253-
-- use AstroLSP setup for mason-lspconfig
254-
handlers = { function(server) require("astrolsp").lsp_setup(server) end },
255-
},
256-
config = function(_, opts)
257-
-- Optionally tell AstroLSP to register new language servers before calling the `setup` function
258-
-- this enables the `mason-lspconfig.servers` option in the AstroLSP configuration
259-
require("astrolsp.mason-lspconfig").register_servers()
260-
require("mason-lspconfig").setup(opts)
261-
end
262-
},
219+
opts = {}
220+
}
263221
},
264-
config = function()
265-
-- set up servers configured with AstroLSP
266-
vim.tbl_map(require("astrolsp").lsp_setup, require("astrolsp").config.servers)
267-
end,
222+
opts = {}
268223
}
269224
```
270225

@@ -276,7 +231,9 @@ local opts = {
276231
dependencies = {
277232
{ "AstroNvim/astrolsp", opts = {} },
278233
},
279-
opts = function() return { on_attach = require("astrolsp").on_attach } end,
234+
opts = {
235+
on_attach = function(client, bufnr) require("astrolsp").on_attach(client, bufnr) end
236+
},
280237
}
281238
```
282239

lua/astrolsp/config.lua

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,7 @@
5959
---@field hover vim.lsp.buf.hover.Opts|false? control the default options for `vim.lsp.buf.hover()` (`:h vim.lsp.buf.hover.Opts`)
6060
---@field signature_help vim.lsp.buf.signature_help.Opts|false? control the default options for `vim.lsp.buf.signature_help()` (`:h vim.lsp.buf.signature_help.Opts`)
6161

62-
---@class AstroLSPMasonLspconfigServer
63-
---@field public package string the Mason package name
64-
---@field filetypes string|string[] the filetype(s) that the server applies to
65-
---@field config? table|(fun(): table) extensions tothe default language server configuration
66-
67-
---@alias AstroLSPMasonLspconfigServers { [string]: AstroLSPMasonLspconfigServer }
68-
69-
---@class AstroLSPMasonLspconfigOpts
70-
---@field servers AstroLSPMasonLspconfigServers? a table of servers to register with mason-lspconfig.nvim
71-
7262
---@class AstroLSPOpts
73-
---_EXPERIMENTAL_ Use the native `vim.lsp.config` for LSP configuration
74-
---@field native_lsp_config boolean?
7563
---Configuration of auto commands
7664
---The key into the table is the group name for the auto commands (`:h augroup`) and the value
7765
---is a list of autocmd tables where `event` key is the event(s) that trigger the auto command
@@ -143,22 +131,6 @@
143131
---}
144132
---```
145133
---@field capabilities lsp.ClientCapabilities?
146-
---Configure language servers for `lspconfig` (`:h lspconfig-setup`)
147-
---Example:
148-
--
149-
---```lua
150-
---config = {
151-
--- lua_ls = {
152-
--- settings = {
153-
--- Lua = {
154-
--- hint = { enable = true, arrayIndex = "Disable" }
155-
--- }
156-
--- }
157-
--- },
158-
--- clangd = { capabilities = { offsetEncoding = "utf-8" } },
159-
---}
160-
---```
161-
---@field config lspconfig.options?
162134
---Configure default options passed to `vim.lsp.buf` functions
163135
---Example:
164136
---
@@ -239,18 +211,16 @@
239211
---```lua
240212
---handlers = {
241213
--- -- default handler
242-
--- function(server, opts)
243-
--- require("lspconfig")[server].setup(opts)
244-
--- end,
214+
--- ["*"] = vim.lsp.enable,
245215
--- -- custom function handler for pyright
246-
--- pyright = function(_, opts)
247-
--- require("lspconfig").pyright.setup(opts)
216+
--- pyright = function()
217+
--- -- some custom logic
248218
--- end,
249219
--- -- set to false to disable the setup of a language server
250220
--- rust_analyzer = false,
251221
---}
252222
---```
253-
---@field handlers table<string|integer,fun(server:string,opts:_.lspconfig.options)|boolean?>?
223+
---@field handlers table<string,fun(server:string)|boolean?>?
254224
---Configure global LSP handlers, set a method to `false` to use the Neovim default (`:h vim.lsp.handlers`)
255225
---Example:
256226
--
@@ -296,21 +266,6 @@
296266
---}
297267
---```
298268
---@field mappings AstroLSPMappings?
299-
---Extra options for the `mason-lspconfig.nvim` plugin such as registering new packages as language servers.
300-
---Example:
301-
--
302-
---```lua
303-
---mason_lspconfig = {
304-
--- servers = {
305-
--- nextflow_ls = {
306-
--- package = "nextflow-language-server",
307-
--- filetypes = "nextflow",
308-
--- config = { cmd = { "nextflow-language-server" } }
309-
--- }
310-
--- }
311-
---}
312-
---```
313-
---@field mason_lspconfig AstroLSPMasonLspconfigOpts?
314269
---A list like table of servers that should be setup, useful for enabling language servers not installed with Mason.
315270
---Example:
316271
--
@@ -330,7 +285,6 @@
330285

331286
---@type AstroLSPOpts
332287
local M = {
333-
native_lsp_config = false,
334288
autocmds = {},
335289
commands = {},
336290
features = {
@@ -340,16 +294,13 @@ local M = {
340294
signature_help = false,
341295
},
342296
capabilities = {},
343-
---@diagnostic disable-next-line: missing-fields
344-
config = {},
345297
defaults = {},
346298
file_operations = { timeout = 10000, operations = {} },
347299
flags = {},
348300
formatting = { format_on_save = { enabled = true }, disabled = {} },
349301
handlers = {},
350302
lsp_handlers = {},
351303
mappings = {},
352-
mason_lspconfig = {},
353304
servers = {},
354305
on_attach = nil,
355306
}

0 commit comments

Comments
 (0)