-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsp.lua
181 lines (169 loc) · 4.32 KB
/
lsp.lua
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
local nnoremap = require("bighelmet7.keymap").nnoremap
require("neodev").setup({
library = {
plugins = { "nvim-dap-ui", types = true },
},
})
-- NOTE: https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion#nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
local cmp = require("cmp")
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {},
mapping = cmp.mapping.preset.insert({
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
-- {name = "vsnip"} -- For vsnip users.
{ name = "luasnip" }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = "buffer" },
}),
})
local function config(_config)
return vim.tbl_deep_extend("force", {
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
on_attach = function()
nnoremap("gd", function()
vim.lsp.buf.definition()
end)
nnoremap("K", function()
vim.lsp.buf.hover()
end)
nnoremap("<leader>ws", function()
vim.lsp.buf.workspace_symbol()
end, { desc = "[W]orkspace [S]ymbol" })
nnoremap("<leader>vd", function()
vim.diagnostic.open_float()
end)
nnoremap("[d", function()
vim.diagnostic.goto_next()
end)
nnoremap("]d", function()
vim.diagnostic.goto_prev()
end)
nnoremap("<leader>ca", function()
vim.lsp.buf.code_action()
end, { desc = "[C]ode [A]ction" })
nnoremap("<leader>rr", function()
vim.lsp.buf.references()
end, { desc = "[R]efe[r]ences" })
nnoremap("<leader>vrn", function()
vim.lsp.buf.rename()
end)
end,
}, _config or {})
end
-- additional filetypes
vim.filetype.add({
extension = {
templ = "templ",
},
})
local servers = {
terraformls = config(),
pyright = config(),
gopls = config({
cmd = { "gopls", "serve" },
settings = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
}),
jdtls = config(),
html = config(),
eslint = config(),
tsserver = config(),
astro = config(),
yamlls = config(),
rust_analyzer = config({
cmd = { "rustup", "run", "stable", "rust-analyzer" },
}),
lua_ls = config({
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
}),
templ = config({
cmd = { "templ", "lsp" },
filetypes = { "templ" },
}),
tailwindcss = config({
init_options = {
userLanguages = {
templ = "html",
},
},
filetypes = {
"astro",
"astro-markdown",
"django-html",
"htmldjango",
"html",
"markdown",
"css",
"less",
"sass",
"scss",
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"templ",
},
}),
}
-- Setup mason so it can manage external tooling
require("mason").setup()
-- Ensure the servers above are installed
local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup({
ensure_installed = vim.tbl_keys(servers),
})
mason_lspconfig.setup_handlers({
function(server_name)
require("lspconfig")[server_name].setup(servers[server_name])
end,
})
-- gleam
require("lspconfig").gleam.setup(config({
cmd = { "gleam", "lsp" },
filetypes = { "gleam" },
}))
-- Turn on lsp status information
require("fidget").setup()