@@ -28,18 +28,15 @@ return {
2828 end ,
2929 },
3030 },
31-
3231 config = function ()
3332 vim .api .nvim_create_autocmd (' LspAttach' , {
3433 group = vim .api .nvim_create_augroup (' lsp-attach' , { clear = true }),
3534 callback = function (event )
3635 local map = function (keys , func , desc )
3736 vim .keymap .set (' n' , keys , func , { buffer = event .buf , desc = ' LSP: ' .. desc })
3837 end
39-
4038 local telescope_ok , telescope = pcall (require , ' telescope.builtin' )
4139 if not telescope_ok then return end
42-
4340 map (' gd' , telescope .lsp_definitions , ' Go to Definition' )
4441 map (' gr' , telescope .lsp_references , ' Go to References' )
4542 map (' gI' , telescope .lsp_implementations , ' Go to Implementation' )
@@ -49,16 +46,12 @@ return {
4946 map (' <leader>rn' , vim .lsp .buf .rename , ' Rename' )
5047 map (' <leader>ca' , vim .lsp .buf .code_action , ' Code Action' )
5148 map (' gD' , vim .lsp .buf .declaration , ' Go to Declaration' )
52-
53- map (' <S-K>' , function ()
49+ map (' K' , function ()
5450 local lspsaga_hover_ok , lspsaga_hover = pcall (require , ' lspsaga.hover' )
5551 if lspsaga_hover_ok then
5652 lspsaga_hover :render_hover_doc ()
57- else
58- vim .lsp .buf .hover ()
5953 end
6054 end , ' Show Hover' )
61-
6255 local client = vim .lsp .get_client_by_id (event .data .client_id )
6356 if client and client .server_capabilities .documentHighlightProvider then
6457 vim .api .nvim_create_autocmd ({ ' CursorHold' , ' CursorHoldI' }, {
@@ -91,9 +84,16 @@ return {
9184 },
9285 filetypes = { ' go' , ' templ' },
9386 },
94- -- tsserver = { settings = { completions = { completeFunctionCalls = true }, }, filetypes = { 'typescript', 'typescriptreact', 'typescript.tsx', 'javascript' }, root_dir = require('lspconfig.util').root_pattern('package.json', 'tsconfig.json', '.git'), },
87+ astro = {
88+ filetypes = { " astro" },
89+ init_options = {
90+ typescript = {
91+ tsdk = vim .fn .stdpath (" data" ) .. " /mason/packages/typescript-language-server/node_modules/typescript/lib" ,
92+ },
93+ },
94+ },
9595 eslint = {},
96- html = { filetypes = { ' html' , ' twig' , ' hbs' } }, -- Removed 'templ' from here
96+ html = { filetypes = { ' html' , ' twig' , ' hbs' } },
9797 templ = {
9898 cmd = { vim .fn .stdpath (" data" ) .. " /mason/bin/templ" , " lsp" },
9999 filetypes = { " templ" },
@@ -133,37 +133,41 @@ return {
133133 cssls = {},
134134 }
135135
136- -- Enable LSP Features
137136 require (' mason' ).setup ()
138- local ensure_installed = vim .tbl_keys (servers )
139- vim .list_extend (ensure_installed , { ' templ' , ' typescript-language-server' })
140- require (' mason-tool-installer' ).setup { ensure_installed = ensure_installed }
137+
138+ local capabilities = vim .tbl_deep_extend (
139+ ' force' ,
140+ {},
141+ vim .lsp .protocol .make_client_capabilities (),
142+ require (' cmp_nvim_lsp' ).default_capabilities ()
143+ )
141144
142145 require (' mason-lspconfig' ).setup {
143- handlers = {
144- function (server_name )
145- local server = servers [server_name ] or {}
146- server .capabilities = vim .tbl_deep_extend (
147- ' force' ,
148- {},
149- vim .lsp .protocol .make_client_capabilities (),
150- require (' cmp_nvim_lsp' ).default_capabilities (),
151- server .capabilities or {}
152- )
153- require (' lspconfig' )[server_name ].setup (server )
154- end ,
155- },
146+ ensure_installed = vim .tbl_keys (servers ),
156147 }
157148
149+ -- Setup servers manually
150+ for name , config in pairs (servers ) do
151+ config .capabilities = vim .tbl_deep_extend (' force' , {}, capabilities , config .capabilities or {})
152+ require (' lspconfig' )[name ].setup (config )
153+ end
154+
155+ vim .api .nvim_create_autocmd (" BufWritePre" , {
156+ pattern = " *.astro" ,
157+ callback = function ()
158+ vim .lsp .buf .format ({ async = false })
159+ end ,
160+ })
161+
158162 -- Auto-format and organize imports on save for Go
159163 vim .api .nvim_create_autocmd (" BufWritePre" , {
160164 pattern = " *.go" ,
161165 callback = function ()
162- vim .lsp .buf .format ({ async = false }) -- Format
166+ vim .lsp .buf .format ({ async = false })
163167 vim .lsp .buf .code_action ({
164168 context = { only = { " source.organizeImports" } },
165169 apply = true ,
166- }) -- Organize imports
170+ })
167171 end ,
168172 })
169173 end ,
0 commit comments