1- -- vim: set foldmethod=marker:
2- local patched_lspconfig = false
1+ -- vim: set fdm=marker:
32
43return {
54 {
@@ -8,42 +7,24 @@ return {
87 event = { ' BufReadPre' , ' BufNewFile' },
98 config = function ()
109 local lsp = require ' skip.lsp'
11- local lsc = require ' lspconfig'
1210
13- if not patched_lspconfig then
14- local original_bufname_valid = lsc .util .bufname_valid
15-
16- -- some day, this'll break ... :O]
17- --- @diagnostic disable-next-line : duplicate-set-field
18- function lsc .util .bufname_valid (bufname )
19- -- reverse engineer bufnr :(
20- -- lspconfig pls let me conditionally attach (but early)
21- local bufs = vim .api .nvim_list_bufs ()
22- for _ , bufnr in ipairs (bufs ) do
23- if
24- vim .api .nvim_buf_is_valid (bufnr )
25- and vim .api .nvim_buf_is_loaded (bufnr )
26- and vim .api .nvim_buf_get_name (bufnr ) == bufname
27- then
28- if not lsp .attach_allowed (bufnr ) then
29- return false
30- end
31- end
11+ vim .lsp .config (' *' , {
12+ root_dir = function (bufnr , on_dir )
13+ if lsp .attach_allowed (bufnr ) then
14+ on_dir (vim .fs .root (bufnr , { ' .git' , ' .jj' , ' .github' , ' package.json' }))
3215 end
16+ end ,
17+ capabilities = lsp .capabilities ,
18+ })
3319
34- return original_bufname_valid (bufname )
35- end
36-
37- patched_lspconfig = true
38- end
39-
20+ -- diagnostic config {{{
21+ -- TODO: this doesn't belong here!!!!
4022 local signs = {
4123 [vim .diagnostic .severity .ERROR ] = ' ' ,
4224 [vim .diagnostic .severity .WARN ] = ' ' ,
4325 [vim .diagnostic .severity .HINT ] = ' ' ,
4426 [vim .diagnostic .severity .INFO ] = ' ' ,
4527 }
46- -- TODO: this doesn't belong here!!!!
4728 vim .diagnostic .config {
4829 -- make warnings and errors appear over hints
4930 severity_sort = true ,
@@ -59,14 +40,10 @@ return {
5940 header = ' ' ,
6041 },
6142 }
43+ -- }}}
6244
63- lsc .util .default_config =
64- vim .tbl_deep_extend (' force' , lsc .util .default_config , {
65- capabilities = lsp .capabilities ,
66- codelens = { enabled = true },
67- })
68-
69- lsc .yamlls .setup {
45+ -- yamlls {{{
46+ vim .lsp .config (' yamlls' , {
7047 settings = {
7148 yaml = {
7249 schemas = {
@@ -76,58 +53,19 @@ return {
7653 [' http://json.schemastore.org/prettierrc' ] = ' .prettierrc.{yml,yaml}' ,
7754 [' http://json.schemastore.org/kustomization' ] = ' kustomization.{yml,yaml}' ,
7855 [' http://json.schemastore.org/chart' ] = ' Chart.{yml,yaml}' ,
79- [' https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/application_v1alpha1.json' ] = ' *.argo-application.{yml,yaml}' ,
80- [' https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/appproject_v1alpha1.json' ] = ' *.argo-appproject.{yml,yaml}' ,
81- [' https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/applicationset_v1alpha1.json' ] = ' *.argo-applicationset.{yml,yaml}' ,
56+ [' https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/application_v1alpha1.json' ] =
57+ ' *.argo-application.{yml,yaml}' ,
58+ [' https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/appproject_v1alpha1.json' ] =
59+ ' *.argo-appproject.{yml,yaml}' ,
60+ [' https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/applicationset_v1alpha1.json' ] =
61+ ' *.argo-applicationset.{yml,yaml}' ,
8262 },
83- },
84- },
85- handlers = {
86- [' textDocument/publishDiagnostics' ] = function (
87- err ,
88- result ,
89- ctx ,
90- config
91- )
92- local is_k8s_file = vim .endswith (result .uri , ' .k8s.yml' )
93- or vim .endswith (result .uri , ' .k8s.yaml' )
94- if not is_k8s_file then
95- return vim .lsp .diagnostic .on_publish_diagnostics (
96- err ,
97- result ,
98- ctx ,
99- config
100- )
101- end
102-
103- local filtered_diagnostics = vim
104- .iter (result .diagnostics )
105- :filter (function (diagnostic )
106- return not (
107- diagnostic .message
108- == ' Matches multiple schemas when only one must validate.'
109- and diagnostic .code == 0
110- )
111- end )
112- :totable ()
113-
114- return vim .lsp .diagnostic .on_publish_diagnostics (
115- err ,
116- vim .tbl_extend (
117- ' force' ,
118- result ,
119- { diagnostics = filtered_diagnostics }
120- ),
121- ctx ,
122- config
123- )
124- end ,
125- },
126- }
127-
128- lsc .vtsls .setup {
129- root_dir = lsc .util .root_pattern (' package.json' ),
130- single_file_support = false ,
63+ }
64+ }
65+ })
66+ -- }}}
67+ -- vtsls {{{
68+ vim .lsp .config (' vtsls' , {
13169 settings = {
13270 vtsls = {
13371 enableMoveToFileCodeAction = true ,
@@ -154,137 +92,34 @@ return {
15492 format = { enable = false },
15593 },
15694 },
157- --- @param client vim.lsp.Client
158- --- @param buffer number
159- on_attach = function (client , buffer )
160- -- this is stolen from LazyVim (thanks)
161- client .commands [' _typescript.moveToFileRefactoring' ] = function (
162- command ,
163- ctx
164- )
165- --- @type string , string , lsp.Range
166- local action , uri , range = unpack (command .arguments )
167-
168- local function move (newf )
169- client .request (' workspace/executeCommand' , {
170- command = command .command ,
171- arguments = { action , uri , range , newf },
172- })
173- end
174-
175- local fname = vim .uri_to_fname (uri )
176- client .request (' workspace/executeCommand' , {
177- command = ' typescript.tsserverRequest' ,
178- arguments = {
179- ' getMoveToRefactoringFileSuggestions' ,
180- {
181- file = fname ,
182- startLine = range .start .line + 1 ,
183- startOffset = range .start .character + 1 ,
184- endLine = range [' end' ].line + 1 ,
185- endOffset = range [' end' ].character + 1 ,
186- },
187- },
188- }, function (_ , result )
189- --- @type string[]
190- local files = result .body .files
191- table.insert (files , 1 , ' Manually specify path...' )
192- vim .ui .select (files , {
193- prompt = ' Move where?' ,
194- format_item = function (f )
195- return vim .fn .fnamemodify (f , ' :~:.' )
196- end ,
197- }, function (f )
198- if f and f :find (' ^Manually specify path' ) then
199- vim .ui .input ({
200- prompt = ' Specify move destination:' ,
201- default = vim .fn .fnamemodify (fname , ' :h' ) .. ' /' ,
202- completion = ' file' ,
203- }, function (newf )
204- return newf and move (newf )
205- end )
206- elseif f then
207- move (f )
208- end
209- end )
210- end )
211- end
212- end ,
213- }
214-
215- -- lsp.eslint.setup {}
216- lsc .gh_actions_ls .setup {
95+ })
96+ -- }}}
97+ -- gh_actions_ls {{{
98+ vim .lsp .config (' gh_actions_ls' , {
21799 filetypes = { ' yaml.github' },
218- }
219- lsc .clangd .setup {}
220-
221- -- this check should probably live somewhere else
222- local uname = vim .uv .os_uname ()
223- local macos = uname .sysname == ' Darwin'
224- -- https://github.com/nix-community/nixd {{{
225- if macos then
226- local hostname = vim .split (vim .uv .os_gethostname (), ' %.' )[1 ]
227- local flake_path = vim .fs .abspath (' ~/Developer/prj/nixfiles' )
228- local username = vim .env .USER
229-
230- local extra_evals = {
231- nix_darwin = {
232- -- 1) ~/Developer is a symlink to ~/src on both of my machines
233- -- 2) if this goes through a symlink, it explodes
234- expr = (' (builtins.getFlake "%s").darwinConfigurations.%s.options' ):format (
235- flake_path ,
236- hostname
237- ),
238- },
239- home_manager = {
240- expr = (' (builtins.getFlake "%s").packages.aarch64-darwin.homeConfigurations.%s.options' ):format (
241- flake_path ,
242- username
243- ),
244- },
245- }
246- lsc .nixd .setup {
247- settings = {
248- nixd = {
249- options = extra_evals ,
250- },
251- },
252- }
253- end
100+ })
254101 -- }}}
255-
256- lsc .pyright .setup {}
257- lsc .lua_ls .setup {
258- enabled = true ,
259- settings = {
260- format = { enable = false },
261- },
262- }
263- lsc .gopls .setup {}
264- lsc .bashls .setup {}
265- lsc .dhall_lsp_server .setup {}
266- lsc .tailwindcss .setup {
102+ -- tailwindcss {{{
103+ vim .lsp .config (' tailwindcss' , {
267104 settings = {
268105 tailwindCSS = {
269106 experimental = {
270107 classRegex = {
271108 { ' cva\\ (([^)]*)\\ )' , ' ["\' `]([^"\' `]*).*?["\' `]' },
272- { ' cx\\ (([^)]*)\\ )' , " (?:'|\" |`)([^']*)(?:'|\" |`)" },
109+ { ' cx\\ (([^)]*)\\ )' , " (?:'|\" |`)([^']*)(?:'|\" |`)" },
273110 },
274111 },
275112 },
276- },
277- }
278- lsc .denols .setup {
279- root_dir = lsc .util .root_pattern (' deno.json' , ' deno.jsonc' ),
280- }
281-
113+ }
114+ })
115+ -- }}}
116+ -- cssls,jsonls,html {{{
282117 for _ , server in ipairs ({
283118 ' cssls' ,
284119 ' jsonls' ,
285120 ' html' ,
286121 }) do
287- lsc [ server ]. setup {
122+ vim . lsp . config ( server , {
288123 settings = {
289124 css = {
290125 lint = {
@@ -293,26 +128,10 @@ return {
293128 },
294129 },
295130 },
296- init_options = { provideFormatter = false },
297- handlers = {
298- [' textDocument/diagnostic' ] = function (err , result , ctx , config )
299- if
300- err ~= nil
301- and err .code == - 32601
302- and err .message :find (' Unhandled method' )
303- then
304- -- html language server always returns an error in response to
305- -- neovim querying it for diagnostics (?), so just ignore this
306- -- to avoid polluting notifications
307- return {}, nil
308- end
309- return vim .lsp .diagnostic .on_diagnostic (err , result , ctx , config )
310- end ,
311- },
312- }
131+ })
313132 end
314-
315- -- xcrun -sdk macosx --find sourcekit-lsp
133+ -- }}}
134+ -- sourcekit {{{
316135 vim .system (
317136 { ' xcrun' , ' -sdk' , ' macosx' , ' --find' , ' sourcekit-lsp' },
318137 { system = true },
@@ -332,26 +151,16 @@ return {
332151 -- { textDocument = { completion = { dynamicRegistration = true } } }
333152 -- )
334153
335- lsc . sourcekit . setup {
154+ vim . lsp . config ( ' sourcekit ' , {
336155 cmd = { path },
337156 -- capabilities = capabilities,
338- }
157+ })
339158 end )
340159 end
341160 )
342-
343- lsc .hls .setup {
344- filetypes = { ' haskell' , ' lhaskell' , ' cabal' },
345- settings = {
346- haskell = {
347- plugin = {
348- rename = { config = { crossModule = true } },
349- },
350- },
351- },
352- }
353-
354- lsc .rust_analyzer .setup {
161+ -- }}}
162+ -- rust_analyzer {{{
163+ vim .lsp .config (' rust_analyzer' , {
355164 capabilities = lsp .capabilities ,
356165 settings = {
357166 [' rust-analyzer' ] = {
@@ -381,7 +190,23 @@ return {
381190 },
382191 },
383192 },
384- }
193+ })
194+ -- }}}
195+
196+ vim .lsp .enable ({
197+ ' pyright' ,
198+ ' lua_ls' ,
199+ ' vtsls' ,
200+ ' yamlls' ,
201+ ' gopls' ,
202+ ' bashls' ,
203+ ' tailwindcss' ,
204+ ' rust_analyzer' ,
205+ ' sourcekit' ,
206+ ' html' ,
207+ ' cssls' ,
208+ ' jsonls' ,
209+ })
385210 end ,
386211 },
387212
@@ -407,7 +232,7 @@ return {
407232 end ,
408233 config = function (self , metals_config )
409234 local nvim_metals_group =
410- vim .api .nvim_create_augroup (' nvim-metals' , { clear = true })
235+ vim .api .nvim_create_augroup (' nvim-metals' , { clear = true })
411236 vim .api .nvim_create_autocmd (' FileType' , {
412237 pattern = self .ft ,
413238 callback = function ()
0 commit comments