Skip to content

Commit d20b4c5

Browse files
authored
Merge pull request #7 from kartikvashistha/feat/0.11-lsp
Feat/0.11 lsp
2 parents 0ecaa81 + 9ff021f commit d20b4c5

File tree

1 file changed

+90
-47
lines changed

1 file changed

+90
-47
lines changed

init.lua

Lines changed: 90 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
--[[
2-
32
=====================================================================
43
==================== READ THIS BEFORE CONTINUING ====================
54
=====================================================================
@@ -656,45 +655,67 @@ require('lazy').setup({
656655
-- By default, Neovim doesn't support everything that is in the LSP specification.
657656
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
658657
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
659-
local capabilities = require('blink.cmp').get_lsp_capabilities()
660-
661-
-- Enable the following language servers
662-
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
658+
-- NOTE: The following line is now commented as blink.cmp extends capabilites by default from its internal code:
659+
-- https://github.com/Saghen/blink.cmp/blob/102db2f5996a46818661845cf283484870b60450/plugin/blink-cmp.lua
660+
-- It has been left here as a comment for educational purposes (as the predecessor completion plugin required this explicit step).
663661
--
664-
-- Add any additional override configuration in the following tables. Available keys are:
665-
-- - cmd (table): Override the default command used to start the server
666-
-- - filetypes (table): Override the default list of associated filetypes for the server
667-
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
668-
-- - settings (table): Override the default settings passed when initializing the server.
669-
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
662+
-- local capabilities = require("blink.cmp").get_lsp_capabilities()
663+
664+
-- Language servers can broadly be installed in the following ways:
665+
-- 1) via the mason package manager; or
666+
-- 2) via your system's package manager; or
667+
-- 3) via a release binary from a language server's repo that's accessible somewhere on your system.
668+
669+
-- The servers table comprises of the following sub-tables:
670+
-- 1. mason
671+
-- 2. others
672+
-- Both these tables have an identical structure of language server names as keys and
673+
-- a table of language server configuration as values.
674+
---@class LspServersConfig
675+
---@field mason table<string, vim.lsp.Config>
676+
---@field others table<string, vim.lsp.Config>
670677
local servers = {
671-
-- clangd = {},
672-
-- gopls = {},
673-
-- pyright = {},
674-
-- rust_analyzer = {},
675-
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
676-
--
677-
-- Some languages (like typescript) have entire language plugins that can be useful:
678-
-- https://github.com/pmizio/typescript-tools.nvim
678+
-- Add any additional override configuration in any of the following tables. Available keys are:
679+
-- - cmd (table): Override the default command used to start the server
680+
-- - filetypes (table): Override the default list of associated filetypes for the server
681+
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
682+
-- - settings (table): Override the default settings passed when initializing the server.
683+
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
679684
--
680-
-- But for many setups, the LSP (`ts_ls`) will work just fine
681-
-- ts_ls = {},
682-
--
683-
684-
lua_ls = {
685-
-- cmd = { ... },
686-
-- filetypes = { ... },
687-
-- capabilities = {},
688-
settings = {
689-
Lua = {
690-
completion = {
691-
callSnippet = 'Replace',
685+
-- Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
686+
mason = {
687+
-- clangd = {},
688+
-- gopls = {},
689+
-- pyright = {},
690+
-- rust_analyzer = {},
691+
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
692+
--
693+
-- Some languages (like typescript) have entire language plugins that can be useful:
694+
-- https://github.com/pmizio/typescript-tools.nvim
695+
--
696+
-- But for many setups, the LSP (`ts_ls`) will work just fine
697+
-- ts_ls = {},
698+
--
699+
lua_ls = {
700+
-- cmd = { ... },
701+
-- filetypes = { ... },
702+
-- capabilities = {},
703+
settings = {
704+
Lua = {
705+
completion = {
706+
callSnippet = 'Replace',
707+
},
708+
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
709+
-- diagnostics = { disable = { 'missing-fields' } },
692710
},
693-
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
694-
-- diagnostics = { disable = { 'missing-fields' } },
695711
},
696712
},
697713
},
714+
-- This table contains config for all language servers that are *not* installed via Mason.
715+
-- Structure is identical to the mason table from above.
716+
others = {
717+
-- dartls = {},
718+
},
698719
}
699720

700721
-- Ensure the servers and tools above are installed
@@ -710,26 +731,31 @@ require('lazy').setup({
710731
--
711732
-- You can add other tools here that you want Mason to install
712733
-- for you, so that they are available from within Neovim.
713-
local ensure_installed = vim.tbl_keys(servers or {})
734+
local ensure_installed = vim.tbl_keys(servers.mason or {})
714735
vim.list_extend(ensure_installed, {
715736
'stylua', -- Used to format Lua code
716737
})
717738
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
718739

740+
-- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
741+
-- to the default language server configs as provided by nvim-lspconfig or
742+
-- define a custom server config that's unavailable on nvim-lspconfig.
743+
for server, config in pairs(vim.tbl_extend('keep', servers.mason, servers.others)) do
744+
if not vim.tbl_isempty(config) then
745+
vim.lsp.config(server, config)
746+
end
747+
end
748+
749+
-- After configuring our language servers, we now enable them
719750
require('mason-lspconfig').setup {
720751
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
721-
automatic_installation = false,
722-
handlers = {
723-
function(server_name)
724-
local server = servers[server_name] or {}
725-
-- This handles overriding only values explicitly passed
726-
-- by the server configuration above. Useful when disabling
727-
-- certain features of an LSP (for example, turning off formatting for ts_ls)
728-
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
729-
require('lspconfig')[server_name].setup(server)
730-
end,
731-
},
752+
automatic_enable = true, -- automatically run vim.lsp.enable() for all servers that are installed via Mason
732753
}
754+
755+
-- Manually run vim.lsp.enable for all language servers that are *not* installed via Mason
756+
if not vim.tbl_isempty(servers.others) then
757+
vim.lsp.enable(vim.tbl_keys(servers.others))
758+
end
733759
end,
734760
},
735761

@@ -896,7 +922,12 @@ require('lazy').setup({
896922
},
897923

898924
-- Highlight todo, notes, etc in comments
899-
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
925+
{
926+
'folke/todo-comments.nvim',
927+
event = 'VimEnter',
928+
dependencies = { 'nvim-lua/plenary.nvim' },
929+
opts = { signs = false },
930+
},
900931

901932
{ -- Collection of various small independent plugins/modules
902933
'echasnovski/mini.nvim',
@@ -941,7 +972,19 @@ require('lazy').setup({
941972
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
942973
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
943974
opts = {
944-
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
975+
ensure_installed = {
976+
'bash',
977+
'c',
978+
'diff',
979+
'html',
980+
'lua',
981+
'luadoc',
982+
'markdown',
983+
'markdown_inline',
984+
'query',
985+
'vim',
986+
'vimdoc',
987+
},
945988
-- Autoinstall languages that are not installed
946989
auto_install = true,
947990
highlight = {

0 commit comments

Comments
 (0)