-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
nvim-lsp.nix
104 lines (97 loc) · 2.87 KB
/
nvim-lsp.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# This file provides a configured neovim for debugging the LSP.
# Run `nvim-test` inside the shell to test.
# Env vars:
# - `NIL_PATH`: The path to "nil" LSP binary. Default: `target/debug/nil`
{
pkgs ? import <nixpkgs> { },
}:
let
neovim = pkgs.neovim.override {
configure = {
customRC = ''
source ${./vimrc.vim}
lua <<EOF
${luaRc}
EOF
'';
packages.myPlugins.start = with pkgs.vimPlugins; [
vim-nix # File type and syntax highlighting.
luasnip
nvim-cmp
cmp_luasnip
cmp-nvim-lsp
nvim-lspconfig
fidget-nvim
];
};
};
# lua
luaRc = ''
require('fidget').setup {}
local cmp = require('cmp')
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<tab>'] = cmp.mapping.confirm { select = true },
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}),
}
local lsp_mappings = {
{ 'gD', vim.lsp.buf.declaration },
{ 'gd', vim.lsp.buf.definition },
{ 'gi', vim.lsp.buf.implementation },
{ 'gr', vim.lsp.buf.references },
{ '[d', vim.diagnostic.goto_prev },
{ ']d', vim.diagnostic.goto_next },
{ ' ' , vim.lsp.buf.hover },
{ ' s', vim.lsp.buf.signature_help },
{ ' d', vim.diagnostic.open_float },
{ ' q', vim.diagnostic.setloclist },
{ '\\r', vim.lsp.buf.rename },
{ '\\a', vim.lsp.buf.code_action },
}
for i, map in pairs(lsp_mappings) do
vim.keymap.set('n', map[1], function() map[2]() end)
end
vim.keymap.set('x', '\\a', function() vim.lsp.buf.code_action() end)
-- https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion
-- https://github.com/hrsh7th/cmp-nvim-lsp/issues/42#issuecomment-1283825572
local caps = vim.tbl_deep_extend(
'force',
vim.lsp.protocol.make_client_capabilities(),
require('cmp_nvim_lsp').default_capabilities(),
-- File watching is disabled by default for neovim.
-- See: https://github.com/neovim/neovim/pull/22405
{ workspace = { didChangeWatchedFiles = { dynamicRegistration = true } } }
);
local lsp_path = vim.env.NIL_PATH or 'target/debug/nil'
require('lspconfig').nil_ls.setup {
autostart = true,
capabilities = caps,
cmd = { lsp_path },
settings = {
['nil'] = {
testSetting = 42,
formatting = {
command = { "nixfmt" },
},
},
},
}
'';
in
pkgs.runCommand "nvim-lsp" { } ''
mkdir -p $out/bin
ln -s ${neovim}/bin/nvim $out/bin/nvim-lsp
''