Skip to content

Commit 0ae1d5c

Browse files
author
Evan Lesmez
committed
Update to mason-lspconfig v2
nvim-lua#1590
1 parent aa4e979 commit 0ae1d5c

File tree

2 files changed

+103
-82
lines changed

2 files changed

+103
-82
lines changed

init.lua

Lines changed: 92 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ vim.g.maplocalleader = ' '
3434

3535
-- Set to true if you have a Nerd Font installed and selected in the terminal
3636
vim.g.have_nerd_font = true
37+
vim.g.markdown_fenced_languages = {
38+
'ts=typescript',
39+
}
3740

3841
-- [[ Setting options ]]
3942
-- See `:help vim.opt`
@@ -100,6 +103,9 @@ vim.opt.scrolloff = 10
100103
-- See `:help 'confirm'`
101104
vim.opt.confirm = true
102105

106+
-- vimrc loading in project dirs
107+
vim.opt.exrc = true
108+
103109
-- [[ Basic Keymaps ]]
104110
-- See `:help vim.keymap.set()`
105111

@@ -162,7 +168,12 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then
162168
if vim.v.shell_error ~= 0 then
163169
error('Error cloning lazy.nvim:\n' .. out)
164170
end
165-
end ---@diagnostic disable-next-line: undefined-field
171+
end
172+
173+
---
174+
---@type vim.Option
175+
local rtp = vim.opt.rtp
176+
rtp:prepend(lazypath)
166177
vim.opt.rtp:prepend(lazypath)
167178

168179
-- [[ Configure and install plugins ]]
@@ -178,7 +189,7 @@ vim.opt.rtp:prepend(lazypath)
178189
-- NOTE: Here is where you install your plugins.
179190
require('lazy').setup({
180191
-- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
181-
'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
192+
'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically
182193

183194
-- NOTE: Plugins can also be added by using a table,
184195
-- with the first argument being the link and the following
@@ -409,12 +420,13 @@ require('lazy').setup({
409420
{
410421
-- Main LSP Configuration
411422
'neovim/nvim-lspconfig',
423+
event = 'VeryLazy',
412424
dependencies = {
413425
-- Automatically install LSPs and related tools to stdpath for Neovim
414426
-- Mason must be loaded before its dependents so we need to set it up here.
415427
-- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
416-
{ 'williamboman/mason.nvim', opts = {} },
417-
'williamboman/mason-lspconfig.nvim',
428+
{ 'mason-org/mason.nvim', opts = {} },
429+
'mason-org/mason-lspconfig.nvim',
418430
'WhoIsSethDaniel/mason-tool-installer.nvim',
419431

420432
-- Useful status updates for LSP.
@@ -424,13 +436,6 @@ require('lazy').setup({
424436
'saghen/blink.cmp',
425437
},
426438
config = function()
427-
-- Brief aside: **What is LSP?**
428-
--
429-
-- LSP is an initialism you've probably heard, but might not understand what it is.
430-
--
431-
-- LSP stands for Language Server Protocol. It's a protocol that helps editors
432-
-- and language tooling communicate in a standardized fashion.
433-
--
434439
-- In general, you have a "server" which is some tool built to understand a particular
435440
-- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers
436441
-- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
@@ -509,11 +514,7 @@ require('lazy').setup({
509514
---@param bufnr? integer some lsp support methods only in specific files
510515
---@return boolean
511516
local function client_supports_method(client, method, bufnr)
512-
if vim.fn.has 'nvim-0.11' == 1 then
513-
return client:supports_method(method, bufnr)
514-
else
515-
return client.supports_method(method, { bufnr = bufnr })
516-
end
517+
return client:supports_method(method, bufnr)
517518
end
518519

519520
-- The following two autocommands are used to highlight references of the
@@ -586,62 +587,72 @@ require('lazy').setup({
586587
},
587588
}
588589

589-
-- LSP servers and clients are able to communicate to each other what features they support.
590+
-- LSPs and clients are able to communicate to each other what features they support.
590591
-- By default, Neovim doesn't support everything that is in the LSP specification.
591592
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
592593
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
593-
local capabilities = require('blink.cmp').get_lsp_capabilities()
594-
595-
-- Enable the following language servers
596-
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
597594
--
598-
-- Add any additional override configuration in the following tables. Available keys are:
599-
-- - cmd (table): Override the default command used to start the server
600-
-- - filetypes (table): Override the default list of associated filetypes for the server
601-
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
602-
-- - settings (table): Override the default settings passed when initializing the server.
603-
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
595+
-- Language servers can broadly be installed in the following ways:
596+
-- 1) via the mason package manager; or
597+
-- 2) via your system's package manager; or
598+
-- 3) via a release binary from a language server's repo that's accessible somewhere on your system.
599+
600+
-- The servers table comprises of the following sub-tables:
601+
-- 1. mason
602+
-- 2. others
603+
-- Both these tables have an identical structure of language server names as keys and
604+
-- a table of language server configuration as values.
605+
---@class LspServersConfig
606+
---@field mason table<string, vim.lsp.Config>
607+
---@field others table<string, vim.lsp.Config>
604608
local servers = {
605-
clangd = {},
606-
-- gopls = {},
607-
pyright = {},
608-
-- rust_analyzer = {},
609-
ts_ls = {},
610-
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
611-
--
612-
-- Some languages (like typescript) have entire language plugins that can be useful:
613-
-- https://github.com/pmizio/typescript-tools.nvim
614-
--
615-
-- But for many setups, the LSP (`ts_ls`) will work just fine
616-
617-
lua_ls = {
618-
-- cmd = { ... },
619-
-- filetypes = { ... },
620-
-- capabilities = {},
621-
settings = {
622-
Lua = {
623-
completion = {
624-
callSnippet = 'Replace',
625-
},
626-
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
627-
diagnostics = {
628-
globals = {
629-
'vim',
630-
'love',
631-
},
632-
},
633-
-- diagnostics = { disable = { 'missing-fields' } },
634-
workspace = {
635-
library = {
636-
[vim.fn.expand '$VIMRUNTIME/lua'] = true,
637-
[vim.fn.expand '$VIMRUNTIME/lua/vim/lsp'] = true,
638-
['${3rd}/love2d/library'] = true, -- Add Love2D library
609+
mason = {
610+
-- Add any additional override configuration in any of the following tables. Available keys are:
611+
-- - cmd (table): Override the default command used to start the server
612+
-- - filetypes (table): Override the default list of associated filetypes for the server
613+
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
614+
-- - settings (table): Override the default settings passed when initializing the server.
615+
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
616+
--
617+
-- Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
618+
clangd = {},
619+
-- gopls = {},
620+
pyright = {},
621+
rust_analyzer = {},
622+
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
623+
624+
-- Some languages (like typescript) have entire language plugins that can be useful:
625+
-- https://github.com/pmizio/typescript-tools.nvim
626+
-- But for many setups, the LSP (`ts_ls`) will work just fine
627+
ts_ls = {
628+
workspace_required = true,
629+
root_markers = { 'package.json' },
630+
},
631+
denols = {
632+
workspace_required = true,
633+
root_markers = { 'deno.json', 'deno.jsonc' },
634+
},
635+
lua_ls = {
636+
-- cmd = { ... },
637+
-- filetypes = { ... },
638+
-- capabilities = {},
639+
settings = {
640+
Lua = {
641+
completion = {
642+
callSnippet = 'Replace',
639643
},
644+
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
645+
-- diagnostics = { disable = { 'missing-fields' } },
640646
},
641647
},
642648
},
649+
intelephense = {},
650+
},
651+
-- This table contains config for all language servers that are *not* installed via Mason.
652+
-- Structure is identical to the mason table from above.
653+
others = {
654+
-- dartls
643655
},
644-
intelephense = {},
645656
}
646657

647658
-- Ensure the servers and tools above are installed
@@ -657,26 +668,28 @@ require('lazy').setup({
657668
--
658669
-- You can add other tools here that you want Mason to install
659670
-- for you, so that they are available from within Neovim.
660-
local ensure_installed = vim.tbl_keys(servers or {})
671+
local ensure_installed = vim.tbl_keys(servers.mason or {})
661672
vim.list_extend(ensure_installed, {
662673
'stylua', -- Used to format Lua code
663674
})
664675
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
676+
-- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
677+
-- to the default language server configs as provided by nvim-lspconfig or
678+
-- define a custom server config that's unavailable on nvim-lspconfig.
679+
680+
for server, config in pairs(vim.tbl_extend('keep', servers.mason, servers.others)) do
681+
if not vim.tbl_isempty(config) then
682+
vim.lsp.config(server, config)
683+
end
684+
end
665685

666686
require('mason-lspconfig').setup {
667-
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
668-
automatic_installation = false,
669-
handlers = {
670-
function(server_name)
671-
local server = servers[server_name] or {}
672-
-- This handles overriding only values explicitly passed
673-
-- by the server configuration above. Useful when disabling
674-
-- certain features of an LSP (for example, turning off formatting for ts_ls)
675-
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
676-
require('lspconfig')[server_name].setup(server)
677-
end,
678-
},
687+
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via masontool-installer)
688+
automatic_enable = true, -- automatically run vim.lsp.enable() for all servers that are installed via Mason
679689
}
690+
if not vim.tbl_isempty(servers.others) then
691+
vim.lsp.enable(vim.tbl_keys(servers.others))
692+
end
680693
end,
681694
},
682695

@@ -925,7 +938,7 @@ require('lazy').setup({
925938
-- Here are some example plugins that I've included in the Kickstart repository.
926939
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
927940
--
928-
--require 'kickstart.plugins.debug',
941+
require 'kickstart.plugins.debug',
929942
require 'kickstart.plugins.indent_line',
930943
require 'kickstart.plugins.lint',
931944
require 'kickstart.plugins.autopairs',
@@ -1021,3 +1034,6 @@ vim.api.nvim_create_autocmd('BufEnter', {
10211034
vim.bo.expandtab = true
10221035
end,
10231036
})
1037+
1038+
-- The line beneath this is called `modeline`. See `:help modeline`
1039+
-- vim: ts=2 sts=2 sw=2 et

lazy-lock.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
"LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" },
33
"blink.cmp": { "branch": "main", "commit": "bae4bae0eedd1fa55f34b685862e94a222d5c6f8" },
44
"conform.nvim": { "branch": "master", "commit": "973f3cb73887d510321653044791d7937c7ec0fa" },
5-
"fidget.nvim": { "branch": "main", "commit": "17ce5ac3b4e5ef590d4f4fd7d91e8fc233114074" },
6-
"gitsigns.nvim": { "branch": "main", "commit": "b01433169be710d6c69f7b4ee264d9670698b831" },
5+
"fidget.nvim": { "branch": "main", "commit": "4ec7bed6c86b671ddde03ca1b227343cfa3e65fa" },
6+
"gitsigns.nvim": { "branch": "main", "commit": "cc2e664c7e3cd8a31af34df040d16a75cfcadced" },
77
"go.nvim": { "branch": "master", "commit": "28d9618bfe4385d3af60fed15a4c9f9445ae1f10" },
8+
"guess-indent.nvim": { "branch": "main", "commit": "84a4987ff36798c2fc1169cbaff67960aed9776f" },
89
"guihua.lua": { "branch": "master", "commit": "87bea7b98429405caf2a0ce4d029b027bb017c70" },
910
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
1011
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
1112
"lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" },
12-
"mason-lspconfig.nvim": { "branch": "main", "commit": "bb3a17efc797c34c054463174e5522442576ebd8" },
13+
"mason-lspconfig.nvim": { "branch": "main", "commit": "844d247d998c2f9a6a3baad8bb9748edc55ce69f" },
14+
"mason-nvim-dap.nvim": { "branch": "main", "commit": "86389a3dd687cfaa647b6f44731e492970034baa" },
1315
"mason-tool-installer.nvim": { "branch": "main", "commit": "517ef5994ef9d6b738322664d5fdd948f0fdeb46" },
1416
"mason.nvim": { "branch": "main", "commit": "3671ab0d40aa5bd24b1686562bd0a23391ecf76a" },
1517
"mini.icons": { "branch": "main", "commit": "b8f6fa6f5a3fd0c56936252edcd691184e5aac0c" },
1618
"mini.nvim": { "branch": "main", "commit": "c122e852517adaf7257688e435369c050da113b1" },
1719
"neo-tree.nvim": { "branch": "main", "commit": "cea666ef965884414b1b71f6b39a537f9238bdb2" },
1820
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
1921
"nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" },
20-
"nvim-lint": { "branch": "master", "commit": "9c6207559297b24f0b7c32829f8e45f7d65b991f" },
21-
"nvim-lspconfig": { "branch": "master", "commit": "4d3b3bb8815fbe37bcaf3dbdb12a22382bc11ebe" },
22+
"nvim-dap": { "branch": "master", "commit": "5dd4d50f2e6a2eaf9e57fad023d294ef371bda35" },
23+
"nvim-dap-go": { "branch": "main", "commit": "b4421153ead5d726603b02743ea40cf26a51ed5f" },
24+
"nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" },
25+
"nvim-lint": { "branch": "master", "commit": "7ef127aaede2a4d5ad8df8321e2eb4e567f29594" },
26+
"nvim-lspconfig": { "branch": "master", "commit": "d0dbf489a8810672fa9a61f4a86e5cf89214b772" },
27+
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
2228
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
2329
"nvim-web-devicons": { "branch": "master", "commit": "4a8369f4c78ef6f6f895f0cec349e48f74330574" },
2430
"oil.nvim": { "branch": "master", "commit": "bbad9a76b2617ce1221d49619e4e4b659b3c61fc" },
@@ -28,6 +34,5 @@
2834
"telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" },
2935
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
3036
"tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" },
31-
"vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" },
3237
"which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" }
3338
}

0 commit comments

Comments
 (0)