@@ -32,7 +32,6 @@ return {
3232        },
3333      },
3434
35-       --  Allows extra capabilities provided by nvim-cmp
3635      ' saghen/blink.cmp'  ,
3736    },
3837    config  =  function ()
@@ -207,18 +206,20 @@ return {
207206      --  LSP servers and clients are able to communicate to each other what features they support.
208207      --   By default, Neovim doesn't support everything that is in the LSP specification.
209208      --   When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
210-       --   So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
211-       local  capabilities  =  require (' blink.cmp'  ).get_lsp_capabilities ()
212209
213-       --  Enable the following language servers
214-       --   Feel free to add/remove any LSPs that you want here. They will automatically be installed.
215-       -- 
216-       --   Add any additional override configuration in the following tables. Available keys are:
217-       --   - cmd (table): Override the default command used to start the server
218-       --   - filetypes (table): Override the default list of associated filetypes for the server
219-       --   - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
220-       --   - settings (table): Override the default settings passed when initializing the server.
221-       --         For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
210+       --  Language servers can broadly be installed in the following ways:
211+       --   1) via the mason package manager; or
212+       --   2) via your system's package manager; or
213+       --   3) via a release binary from a language server's repo that's accessible somewhere on your system.
214+ 
215+       --  The servers table comprises of the following sub-tables:
216+       --  1. mason
217+       --  2. others
218+       --  Both these tables have an identical structure of language server names as keys and
219+       --  a table of language server configuration as values.
220+       --- @class  LspServersConfig 
221+       --- @field  mason  table<string ,  vim.lsp.Config> 
222+       --- @field  others  table<string ,  vim.lsp.Config> 
222223      local  servers  =  {
223224        --  clangd = {},
224225        --  gopls = {},
@@ -249,31 +250,42 @@ return {
249250        --  },
250251        --    },
251252        --  },
252-         texlab  =  {
253-           settings  =  {
254-             texlab  =  {
255-               bibtexFormatter  =  ' latexindent'  ,
256-               chktex  =  {
257-                 onEdit  =  false ,
258-                 onOpenAndSave  =  true ,
253+ 
254+         --   Feel free to add/remove any LSPs here that you want to install via Mason.
255+         --   They will automatically be installed and setup.
256+         mason  =  {
257+           lua_ls  =  {
258+             --  cmd = {...},
259+             --  filetypes = { ...},
260+             --  capabilities = {},
261+             settings  =  {
262+               Lua  =  {
263+                 completion  =  {
264+                   callSnippet  =  ' Replace'  ,
265+                 },
266+                 --  You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
267+                 --  diagnostics = { disable = { 'missing-fields' } },
259268              },
260269            },
261270          },
262-         },
263-         lua_ls  =  {
264-           --  cmd = {...},
265-           --  filetypes = { ...},
266-           --  capabilities = {},
267-           settings  =  {
268-             Lua  =  {
269-               completion  =  {
270-                 callSnippet  =  ' Replace'  ,
271+           texlab  =  {
272+             settings  =  {
273+               texlab  =  {
274+                 bibtexFormatter  =  ' latexindent'  ,
275+                 chktex  =  {
276+                   onEdit  =  false ,
277+                   onOpenAndSave  =  true ,
278+                 },
271279              },
272-               --  You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
273-               --  diagnostics = { disable = { 'missing-fields' } },
274280            },
275281          },
276282        },
283+ 
284+         --  This table contains config for all language servers that are *not* installed via Mason.
285+         --  Structure is identical to the mason table from above.
286+         others  =  {
287+           --  dartls = {},
288+         },
277289      }
278290
279291      --  Ensure the servers and tools above are installed
@@ -284,27 +296,32 @@ return {
284296
285297      --  You can add other tools here that you want Mason to install
286298      --  for you, so that they are available from within Neovim.
287-       local  ensure_installed  =  vim .tbl_keys (servers  or  {})
299+       local  ensure_installed  =  vim .tbl_keys (servers . mason  or  {})
288300      vim .list_extend (ensure_installed , {
289301        ' stylua'  , --  Used to format Lua code
290302      })
291303      require (' mason-tool-installer'  ).setup  { ensure_installed  =  ensure_installed  }
292304
305+       --  Either merge all additional server configs from the `servers.mason` and `servers.others` tables
306+       --  to the default language server configs as provided by nvim-lspconfig or
307+       --  define a custom server config that's unavailable on nvim-lspconfig.
308+       for  server , config  in  pairs (vim .tbl_extend (' keep'  , servers .mason , servers .others )) do 
309+         if  not  vim .tbl_isempty (config ) then 
310+           vim .lsp .config (server , config )
311+         end 
312+       end 
313+ 
314+       --  After configuring our language servers, we now enable them
293315      require (' mason-lspconfig'  ).setup  {
294316        ensure_installed  =  {},
295317        automatic_installation  =  false ,
296318        automatic_enable  =  true ,
297-         handlers  =  {
298-           function (server_name )
299-             local  server  =  servers [server_name ] or  {}
300-             --  This handles overriding only values explicitly passed
301-             --  by the server configuration above. Useful when disabling
302-             --  certain features of an LSP (for example, turning off formatting for tsserver)
303-             server .capabilities  =  vim .tbl_deep_extend (' force'  , {}, capabilities , server .capabilities  or  {})
304-             require (' lspconfig'  )[server_name ].setup (server )
305-           end ,
306-         },
307319      }
320+ 
321+       --  Manually run vim.lsp.enable for all language servers that are *not* installed via Mason
322+       if  not  vim .tbl_isempty (servers .others ) then 
323+         vim .lsp .enable (vim .tbl_keys (servers .others ))
324+       end 
308325    end ,
309326  },
310327}
0 commit comments