Skip to content

Commit 5629288

Browse files
fixed lspconfig not configuring language servers (nvim-lua#1475)
1 parent 2442280 commit 5629288

File tree

7 files changed

+140
-63
lines changed

7 files changed

+140
-63
lines changed

doc/kickstart.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ require 'lazy-bootstrap'
1919
-- [[ Configure and install plugins ]]
2020
require 'lazy-plugins'
2121

22+
-- require 'setup-nvim-cmp'
23+
2224
-- The line beneath this is called `modeline`. See `:help modeline`
2325
-- vim: ts=2 sts=2 sw=2 et

lua/lazy-plugins.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require('lazy').setup({
2929
require 'plugins/lspconfig',
3030
require 'plugins/conform',
3131
require 'plugins/blink-cmp',
32+
-- require 'plugins/nvim-cmp',
3233
require 'plugins/todo-comments',
3334
require 'plugins/mini',
3435
require 'plugins/treesitter',

lua/plugins/file-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ return {
1111
},
1212
lazy = false,
1313
keys = {
14-
{ '<C-N>', ':Neotree reveal<CR>', desc = 'NeoTree reveal', silent = true },
14+
{ '<C-N>', ':Neotree toggle<CR>', desc = 'NeoTree reveal', silent = true },
1515
},
1616
opts = {
1717
filesystem = {

lua/plugins/lspconfig.lua

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-- LSP Plugins
2+
--
23
return {
4+
5+
-- LSP Plugins
36
{
47
-- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
58
-- used for completion, annotations and signatures of Neovim apis
@@ -23,10 +26,42 @@ return {
2326
'mason-org/mason-lspconfig.nvim',
2427
'WhoIsSethDaniel/mason-tool-installer.nvim',
2528

29+
-- Useful status updates for LSP.
30+
-- { 'j-hui/fidget.nvim', opts = {} },
31+
2632
-- Allows extra capabilities provided by blink.cmp
2733
'saghen/blink.cmp',
2834
},
2935
config = function()
36+
-- Brief aside: **What is LSP?**
37+
--
38+
-- LSP is an initialism you've probably heard, but might not understand what it is.
39+
--
40+
-- LSP stands for Language Server Protocol. It's a protocol that helps editors
41+
-- and language tooling communicate in a standardized fashion.
42+
--
43+
-- In general, you have a "server" which is some tool built to understand a particular
44+
-- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers
45+
-- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
46+
-- processes that communicate with some "client" - in this case, Neovim!
47+
--
48+
-- LSP provides Neovim with features like:
49+
-- - Go to definition
50+
-- - Find references
51+
-- - Autocompletion
52+
-- - Symbol Search
53+
-- - and more!
54+
--
55+
-- Thus, Language Servers are external tools that must be installed separately from
56+
-- Neovim. This is where `mason` and related plugins come into play.
57+
--
58+
-- If you're wondering about lsp vs treesitter, you can check out the wonderfully
59+
-- and elegantly composed help section, `:help lsp-vs-treesitter`
60+
61+
-- This function gets run when an LSP attaches to a particular buffer.
62+
-- That is to say, every time a new file is opened that is associated with
63+
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
64+
-- function will be executed to configure the current buffer
3065
vim.api.nvim_create_autocmd('LspAttach', {
3166
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
3267
callback = function(event)
@@ -160,12 +195,6 @@ return {
160195
},
161196
}
162197

163-
-- LSP servers and clients are able to communicate to each other what features they support.
164-
-- By default, Neovim doesn't support everything that is in the LSP specification.
165-
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
166-
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
167-
local capabilities = require('blink.cmp').get_lsp_capabilities()
168-
169198
-- Enable the following language servers
170199
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
171200
--
@@ -176,20 +205,8 @@ return {
176205
-- - settings (table): Override the default settings passed when initializing the server.
177206
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
178207
local servers = {
179-
-- clangd = {},
180-
-- gopls = {},
181-
-- pyright = {},
182-
-- rust_analyzer = {},
183-
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
184-
--
185-
-- Some languages (like typescript) have entire language plugins that can be useful:
186-
-- https://github.com/pmizio/typescript-tools.nvim
187-
--
188-
-- But for many setups, the LSP (`ts_ls`) will work just fine
189-
-- ts_ls = {},
190-
--
191208
clangd = {
192-
cmd = { -- This doesn't seem to do anything. Look into this later
209+
cmd = {
193210
'clangd',
194211
'--offset-encoding=utf-16',
195212
'--clang-tidy',
@@ -198,7 +215,6 @@ return {
198215
'--header-insertion=iwyu',
199216
},
200217
},
201-
-- gopls = {},
202218
asm_lsp = {},
203219
pyright = {},
204220
rust_analyzer = {
@@ -256,18 +272,27 @@ return {
256272
},
257273

258274
ltex = {
259-
Settings = {
275+
settings = {
260276
ltex = {
261-
-- language = 'en-US',
262-
language = 'DE',
277+
language = 'en-US',
263278
checkFrequency = 'save',
264279
-- languageToolHttpServerUri = "https://api.languagetoolplus.com/",
265280
-- require("creds").languageToolOrg
266281
},
267282
},
268283
},
269284

270-
svlangserver = {},
285+
svlangserver = {
286+
settings = {
287+
systemverilog = {
288+
includeIndexing = { '**/*.{sv,svh}' },
289+
excludeIndexing = { 'test/**/*.sv*' },
290+
defines = {},
291+
launchConfiguration = 'verilator -sv -Wall --lint-only',
292+
formatCommand = 'verible-verilog-format',
293+
},
294+
},
295+
},
271296
-- veridian = {
272297
-- cmd = { 'veridian' },
273298
-- filetypes = { 'systemverilog', 'verilog' },
@@ -287,6 +312,11 @@ return {
287312
},
288313
},
289314
}
315+
---@type MasonLspconfigSettings
316+
---@diagnostic disable-next-line: missing-fields
317+
require('mason-lspconfig').setup {
318+
automatic_enable = vim.tbl_keys(servers or {}),
319+
}
290320

291321
-- Ensure the servers and tools above are installed
292322
--
@@ -307,21 +337,16 @@ return {
307337
})
308338
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
309339

310-
require('mason-lspconfig').setup {
311-
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
312-
automatic_installation = false,
313-
handlers = {
314-
function(server_name)
315-
local server = servers[server_name] or {}
316-
-- This handles overriding only values explicitly passed
317-
-- by the server configuration above. Useful when disabling
318-
-- certain features of an LSP (for example, turning off formatting for ts_ls)
319-
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
320-
require('lspconfig')[server_name].setup(server)
321-
end,
322-
},
323-
}
340+
-- Installed LSPs are configured and enabled automatically with mason-lspconfig
341+
-- The loop below is for overriding the default configuration of LSPs with the ones in the servers table
342+
for server_name, config in pairs(servers) do
343+
vim.lsp.config(server_name, config)
344+
end
345+
346+
-- NOTE: Some servers may require an old setup until they are updated. For the full list refer here: https://github.com/neovim/nvim-lspconfig/issues/3705
347+
-- These servers will have to be manually set up with require("lspconfig").server_name.setup{}
324348
end,
325349
},
326350
}
351+
327352
-- vim: ts=2 sts=2 sw=2 et

lua/plugins/nvim-cmp.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
return {
2+
-- Autocompletion
3+
'hrsh7th/nvim-cmp',
4+
lazy = true,
5+
dependencies = {
6+
-- Snippet Engine & its associated nvim-cmp source
7+
'L3MON4D3/LuaSnip',
8+
'saadparwaiz1/cmp_luasnip',
9+
10+
-- Adds LSP completion capabilities
11+
'hrsh7th/cmp-nvim-lsp',
12+
'hrsh7th/cmp-path',
13+
14+
-- Adds a number of user-friendly snippets
15+
'rafamadriz/friendly-snippets',
16+
},
17+
}

lua/setup-nvim-cmp.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- [[ Configure nvim-cmp ]]
2+
-- See `:help cmp`
3+
local cmp = require 'cmp'
4+
local luasnip = require 'luasnip'
5+
require('luasnip.loaders.from_vscode').lazy_load()
6+
luasnip.config.setup {}
7+
8+
cmp.setup {
9+
window = {
10+
-- NOTE: You can set this to try to avoid showing extra documentation
11+
-- See `:help cmp-config` for more information
12+
completion = cmp.config.window.bordered(),
13+
documentation = cmp.config.window.bordered(),
14+
},
15+
preselect = cmp.PreselectMode.None, -- NOTE: Added this to stop selecting first opt
16+
snippet = {
17+
expand = function(args)
18+
luasnip.lsp_expand(args.body)
19+
end,
20+
},
21+
mapping = cmp.mapping.preset.insert {
22+
['<C-n>'] = cmp.mapping.select_next_item(),
23+
['<C-p>'] = cmp.mapping.select_prev_item(),
24+
['<C-k>'] = cmp.mapping.scroll_docs(-4),
25+
['<C-j>'] = cmp.mapping.scroll_docs(4),
26+
['<C-Space>'] = cmp.mapping.complete {},
27+
['<CR>'] = cmp.mapping.confirm {
28+
behavior = cmp.ConfirmBehavior.Replace,
29+
select = false, -- NOTE: Changed from true to stop selecting first option
30+
},
31+
['<Tab>'] = cmp.mapping(function(fallback)
32+
if cmp.visible() then
33+
cmp.select_next_item()
34+
elseif luasnip.expand_or_locally_jumpable() then
35+
luasnip.expand_or_jump()
36+
else
37+
fallback()
38+
end
39+
end, { 'i', 's' }),
40+
['<S-Tab>'] = cmp.mapping(function(fallback)
41+
if cmp.visible() then
42+
cmp.select_prev_item()
43+
elseif luasnip.locally_jumpable(-1) then
44+
luasnip.jump(-1)
45+
else
46+
fallback()
47+
end
48+
end, { 'i', 's' }),
49+
},
50+
sources = {
51+
{ name = 'nvim_lsp' },
52+
{ name = 'luasnip' },
53+
{ name = 'path' },
54+
{ name = 'copilot' },
55+
},
56+
}

0 commit comments

Comments
 (0)