Skip to content

Commit 19457f8

Browse files
Merge pull request #19 from venkatarenduchintala/refactor/native-lsp-api
refactor(lsp): adopt Neovim 0.12 native LSP API
2 parents 890efbf + 475fd83 commit 19457f8

10 files changed

Lines changed: 165 additions & 276 deletions

File tree

after/lsp/eslint.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
vim.lsp.config('eslint', {
2+
settings = {
3+
packageManager = "npm",
4+
},
5+
})
6+
7+
-- EslintFixAll on save, scoped to eslint-attached buffers only
8+
vim.api.nvim_create_autocmd("LspAttach", {
9+
callback = function(args)
10+
local client = vim.lsp.get_client_by_id(args.data.client_id)
11+
if client and client.name == "eslint" then
12+
vim.api.nvim_create_autocmd("BufWritePre", {
13+
buffer = args.buf,
14+
command = "EslintFixAll",
15+
})
16+
end
17+
end,
18+
})

after/lsp/gopls.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
vim.lsp.config('gopls', {
2+
settings = {
3+
gopls = {
4+
analyses = {
5+
unusedparams = true,
6+
shadow = true,
7+
},
8+
staticcheck = true,
9+
gofumpt = true,
10+
},
11+
},
12+
})

after/lsp/helm_ls.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
vim.lsp.config('helm_ls', {
2+
settings = {
3+
['helm-ls'] = {
4+
logLevel = "info",
5+
valuesFiles = {
6+
mainValuesFile = "values.yaml",
7+
lintOverlayValuesFile = "values.lint.yaml",
8+
additionalValuesFilesGlobPattern = "values*.yaml",
9+
},
10+
yamlls = {
11+
enabled = true,
12+
diagnosticsLimit = 50,
13+
showDiagnosticsDirectly = false,
14+
path = "yaml-language-server",
15+
config = {
16+
schemas = {
17+
kubernetes = "templates/**",
18+
},
19+
completion = true,
20+
hover = true,
21+
},
22+
},
23+
},
24+
},
25+
})

after/lsp/lua_ls.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
vim.lsp.config('lua_ls', {
2+
settings = {
3+
Lua = {
4+
runtime = { version = "LuaJIT" },
5+
diagnostics = { globals = { "vim" } },
6+
workspace = { library = vim.api.nvim_get_runtime_file("", true) },
7+
telemetry = { enable = false },
8+
},
9+
},
10+
})

after/lsp/rust_analyzer.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
vim.lsp.config('rust_analyzer', {
2+
settings = {
3+
["rust-analyzer"] = {
4+
diagnostics = { enable = true },
5+
imports = {
6+
granularity = { group = "module" },
7+
prefix = "self",
8+
},
9+
cargo = { buildScripts = { enable = true } },
10+
procMacro = { enable = true },
11+
},
12+
},
13+
})

after/lsp/yamlls.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
vim.lsp.config('yamlls', {
2+
settings = {
3+
yaml = {
4+
validate = true,
5+
hover = true,
6+
completion = false,
7+
schemaStore = {
8+
enable = true,
9+
url = "https://www.schemastore.org/api/json/catalog.json",
10+
},
11+
schemas = {
12+
kubernetes = {
13+
"manifests/**/*.yaml",
14+
"k8s/**/*.yaml",
15+
"kubernetes/**/*.yaml",
16+
"deploy/**/*.yaml",
17+
"templates/**/*.yaml",
18+
"chart/templates/**/*.yaml",
19+
},
20+
},
21+
},
22+
},
23+
})

lua/lsp/init.lua

Lines changed: 16 additions & 256 deletions
Original file line numberDiff line numberDiff line change
@@ -1,256 +1,16 @@
1-
local capabilities = require("lsp.handlers").capabilities
2-
3-
local lspconfig = vim.lsp.config
4-
if lspconfig then
5-
-- Python
6-
lspconfig("pyright", {
7-
capabilities = capabilities,
8-
filetypes = { "python" },
9-
})
10-
-- LUA
11-
lspconfig("lua_ls", {
12-
settings = {
13-
Lua = {
14-
runtime = {
15-
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
16-
version = "LuaJIT",
17-
},
18-
diagnostics = {
19-
-- Get the language server to recognize the `vim` global
20-
globals = { "vim" },
21-
},
22-
workspace = {
23-
-- Make the server aware of Neovim runtime files
24-
library = vim.api.nvim_get_runtime_file("", true),
25-
},
26-
-- Do not send telemetry data containing a randomized but unique identifier
27-
telemetry = {
28-
enable = false,
29-
},
30-
},
31-
},
32-
})
33-
-- Rust
34-
lspconfig("rust_analyzer", {
35-
on_attach = function(client, bufnr)
36-
require("lsp.handlers").on_attach(client, bufnr)
37-
-- vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
38-
end,
39-
-- capabilities = capabilities,
40-
settings = {
41-
["rust-analyzer"] = {
42-
diagnostics = {
43-
enable = true,
44-
},
45-
imports = {
46-
granularity = {
47-
group = "module",
48-
},
49-
prefix = "self",
50-
},
51-
cargo = {
52-
buildScripts = {
53-
enable = true,
54-
},
55-
},
56-
procMacro = {
57-
enable = true,
58-
},
59-
},
60-
},
61-
})
62-
63-
-- Clangd (C++)
64-
lspconfig("clangd", {
65-
autostart = true,
66-
capabilities = capabilities,
67-
})
68-
69-
-- Bash
70-
lspconfig("bashls", {
71-
autostart = true,
72-
})
73-
74-
-- Javascript/Typescript
75-
lspconfig("eslint", {
76-
capabilities = capabilities,
77-
settings = {
78-
packageManager = "npm",
79-
},
80-
on_attach = function(client, bufnr)
81-
vim.api.nvim_create_autocmd("BufWritePre", {
82-
buffer = bufnr,
83-
command = "EslintFixAll",
84-
})
85-
end,
86-
})
87-
88-
-- HTML
89-
lspconfig("html", {
90-
autostart = true,
91-
capabilities = capabilities,
92-
})
93-
94-
-- CSS
95-
lspconfig("cssls", {
96-
capabilities = capabilities,
97-
})
98-
99-
-- Dockerfile
100-
lspconfig("dockerls", {
101-
autostart = true,
102-
capabilities = capabilities,
103-
})
104-
105-
-- Docker compose
106-
lspconfig("docker_compose_language_service", {
107-
autostart = true,
108-
capabilities = capabilities,
109-
})
110-
111-
-- VUE
112-
lspconfig("vue", {
113-
autostart = false,
114-
capabilities = capabilities,
115-
})
116-
117-
-- YAMLs — diagnostics only, no completion
118-
lspconfig("yamlls", {
119-
autostart = true,
120-
capabilities = capabilities,
121-
settings = {
122-
yaml = {
123-
validate = true,
124-
hover = true,
125-
completion = false,
126-
schemaStore = {
127-
enable = true,
128-
url = "https://www.schemastore.org/api/json/catalog.json",
129-
},
130-
schemas = {
131-
-- Kubernetes manifests in common SRE directory layouts
132-
kubernetes = {
133-
"manifests/**/*.yaml",
134-
"k8s/**/*.yaml",
135-
"kubernetes/**/*.yaml",
136-
"deploy/**/*.yaml",
137-
"templates/**/*.yaml",
138-
"chart/templates/**/*.yaml",
139-
},
140-
},
141-
},
142-
},
143-
})
144-
145-
-- CMake Language Server
146-
lspconfig("cmake", {
147-
autostart = false,
148-
capabilities = capabilities,
149-
})
150-
151-
-- Elixir Language Server
152-
lspconfig("elixirls", {
153-
autostart = false,
154-
capabilities = capabilities,
155-
})
156-
157-
-- Erlang Language Server
158-
-- lspconfig("erlangls", {
159-
-- autostart = false,
160-
-- capabilities = capabilities,
161-
-- })
162-
163-
-- Go Language Server
164-
lspconfig("gopls", {
165-
autostart = true,
166-
capabilities = capabilities,
167-
settings = {
168-
gopls = {
169-
analyses = {
170-
unusedparams = true,
171-
shadow = true,
172-
},
173-
staticcheck = true,
174-
gofumpt = true,
175-
},
176-
},
177-
})
178-
179-
-- Gradle Language Server
180-
lspconfig("gradle_ls", {
181-
autostart = false,
182-
capabilities = capabilities,
183-
})
184-
185-
-- -- Groovy Language Server
186-
lspconfig("groovyls", {
187-
autostart = false,
188-
capabilities = capabilities,
189-
})
190-
191-
-- Helm Language Server
192-
lspconfig("helm_ls", {
193-
autostart = true,
194-
capabilities = capabilities,
195-
settings = {
196-
['helm-ls'] = {
197-
logLevel = "info",
198-
valuesFiles = {
199-
mainValuesFile = "values.yaml",
200-
lintOverlayValuesFile = "values.lint.yaml",
201-
additionalValuesFilesGlobPattern = "values*.yaml",
202-
},
203-
yamlls = {
204-
enabled = true,
205-
diagnosticsLimit = 50,
206-
showDiagnosticsDirectly = false,
207-
path = "yaml-language-server",
208-
config = {
209-
schemas = {
210-
kubernetes = "templates/**",
211-
},
212-
completion = true,
213-
hover = true,
214-
},
215-
},
216-
},
217-
},
218-
})
219-
220-
-- Json Language Server
221-
lspconfig("jsonls", {
222-
autostart = false,
223-
capabilities = capabilities,
224-
})
225-
226-
-- Kotlin LS
227-
lspconfig("kotlin_language_server", {
228-
autostart = false,
229-
capabilities = capabilities,
230-
})
231-
232-
-- Make Language Server
233-
lspconfig("autotools_ls", {
234-
autostart = false,
235-
capabilities = capabilities,
236-
})
237-
238-
-- Powershell Language Server
239-
lspconfig("powershell_es", {
240-
autostart = false,
241-
capabilities = capabilities,
242-
})
243-
244-
-- SQL Language Server
245-
lspconfig("sqlls", {
246-
autostart = false,
247-
capabilities = capabilities,
248-
})
249-
250-
-- Terraform Language Server
251-
lspconfig("terraformls", {
252-
autostart = true,
253-
capabilities = capabilities,
254-
})
255-
256-
end
1+
local handlers = require("lsp.handlers")
2+
3+
-- Capabilities applied globally to every server; per-server settings live in after/lsp/<name>.lua
4+
vim.lsp.config('*', {
5+
capabilities = handlers.capabilities,
6+
})
7+
8+
-- Global on_attach via autocmd — survives any per-server on_attach overrides
9+
vim.api.nvim_create_autocmd("LspAttach", {
10+
callback = function(args)
11+
local client = vim.lsp.get_client_by_id(args.data.client_id)
12+
if client then
13+
handlers.on_attach(client, args.buf)
14+
end
15+
end,
16+
})

0 commit comments

Comments
 (0)