-
Notifications
You must be signed in to change notification settings - Fork 3
/
nvim-lspconfig.lua
219 lines (198 loc) · 6.43 KB
/
nvim-lspconfig.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
local lspconfig = require("lspconfig")
local null_ls = require("null-ls")
local typescript = require("typescript")
local function format_buffer()
vim.lsp.buf.format({
filter = function(client)
return client.name ~= "tsserver" and client.name ~= "pyright" and client.name ~= "eslint"
end,
})
end
-- Setup everything on lsp attach
local on_attach = function(client, bufnr)
local function buf_set_keymap(mode, key, func)
vim.keymap.set(mode, key, func, { buffer = bufnr, silent = true })
end
-- require'lsp_signature'.on_attach()
-- Mappings.
buf_set_keymap("n", "gD", vim.lsp.buf.declaration)
buf_set_keymap("n", "gd", vim.lsp.buf.definition)
buf_set_keymap("n", "gh", vim.lsp.buf.hover)
buf_set_keymap("n", "gi", vim.lsp.buf.implementation)
buf_set_keymap("n", "<C-k>", vim.lsp.buf.signature_help)
buf_set_keymap("n", "<space>rm", vim.lsp.buf.rename)
buf_set_keymap("n", "<space>rr", vim.lsp.buf.references)
buf_set_keymap("n", "<space>d", vim.diagnostic.open_float)
buf_set_keymap("n", "<space>i", vim.lsp.buf.code_action)
buf_set_keymap("n", "[d", vim.diagnostic.goto_prev)
buf_set_keymap("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<leader>=", format_buffer, { buffer = bufnr })
if client.server_capabilities.document_range_formatting then
vim.keymap.set("v", "<leader>=", format_buffer, { buffer = bufnr })
end
end
local handle_lsp = function(opts)
return opts
end
--local ts_utils_attach = require 'plugins.lsp-ts-utils'
null_ls.setup({
on_attach = on_attach,
sources = {
-- JS/TS formatting
null_ls.builtins.formatting.prettierd,
-- Spell check
--null_ls.builtins.diagnostics.cspell,
-- Python formatting
null_ls.builtins.formatting.autopep8.with({
extra_args = {
"max-line-length",
"79",
"aggressive",
"aggressive",
"aggressive",
},
}),
-- Lua formatting
null_ls.builtins.formatting.stylua,
},
root_dir = lspconfig.util.root_pattern("yarn.lock", "lerna.json", ".git"),
--debug = true,
log = { enabled = true, level = "trace" },
})
local capabilities = vim.lsp.protocol.make_client_capabilities()
local capabilitiesWithoutFomatting = vim.lsp.protocol.make_client_capabilities()
capabilitiesWithoutFomatting.textDocument.formatting = false
capabilitiesWithoutFomatting.textDocument.rangeFormatting = false
capabilitiesWithoutFomatting.textDocument.range_formatting = false
-- Tsserver setup
require("typescript").setup({
disable_commands = false, -- prevent the plugin from creating Vim commands
debug = false, -- enable debug logging for commands
go_to_source_definition = {
fallback = true, -- fall back to standard LSP definition on failure
},
server = handle_lsp({
root_dir = lspconfig.util.root_pattern("yarn.lock", "lerna.json", ".git"),
on_attach = function(client, bufnr)
client.server_capabilities.document_formatting = false
client.server_capabilities.document_range_formatting = false
--ts_utils_attach(client)
on_attach(client, bufnr)
end,
settings = {
documentFormatting = false,
typescript = {
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
},
init_options = {
hostInfo = "neovim",
maxTsServerMemory = "8192",
preferences = { quotePreference = "single", allowIncompleteCompletions = false },
--tsserver = {
--path = "/home/armeeh/.config/yarn/global/node_modules/typescript/lib/tsserver.js",
--},
},
capabilities = capabilitiesWithoutFomatting,
}),
})
--local luadev = require("lua-dev").setup({
--lspconfig = {
--cmd = {
--"/usr/bin/lua-language-server",
--"-E",
--"/usr/share/lua-language-server/main.lua",
--},
--on_attach = on_attach,
--capabilities = capabilities,
--},
--})
--lspconfig.sumneko_lua.setup(handle_lsp(luadev))
-- Vim lsp
lspconfig.vimls.setup(handle_lsp({
on_attach = on_attach,
capabilities = capabilities,
}))
-- JSON lsp
lspconfig.jsonls.setup(handle_lsp({
on_attach = on_attach,
settings = {
json = {
-- Schemas https://www.schemastore.org
schemas = {
{
fileMatch = { "package.json" },
url = "https://json.schemastore.org/package.json",
},
{
fileMatch = { "tsconfig*.json" },
url = "https://json.schemastore.org/tsconfig.json",
},
{
fileMatch = {
".prettierrc",
".prettierrc.json",
"prettier.config.json",
},
url = "https://json.schemastore.org/prettierrc.json",
},
{
fileMatch = { ".eslintrc", ".eslintrc.json" },
url = "https://json.schemastore.org/eslintrc.json",
},
{
fileMatch = {
".babelrc",
".babelrc.json",
"babel.config.json",
},
url = "https://json.schemastore.org/babelrc.json",
},
{
fileMatch = { "lerna.json" },
url = "https://json.schemastore.org/lerna.json",
},
{
fileMatch = { "now.json", "vercel.json" },
url = "https://json.schemastore.org/now.json",
},
{
fileMatch = {
".stylelintrc",
".stylelintrc.json",
"stylelint.config.json",
},
url = "http://json.schemastore.org/stylelintrc.json",
},
},
},
},
capabilities = capabilities,
}))
lspconfig.eslint.setup(handle_lsp({
root_dir = lspconfig.util.root_pattern("yarn.lock", "lerna.json", ".git"),
on_attach = on_attach,
}))
lspconfig.prismals.setup(handle_lsp({ on_attach = on_attach }))
lspconfig.cssls.setup(handle_lsp({
capabilities = capabilities,
root_dir = lspconfig.util.root_pattern("yarn.lock", "lerna.json", ".git"),
on_attach = on_attach,
}))
lspconfig.pylsp.setup(handle_lsp({
root_dir = lspconfig.util.root_pattern(".venv", ".git"),
on_attach = on_attach,
settings = { python = { venvPath = "/home/armeeh/.virtualenvs" } },
}))
lspconfig.ccls.setup(handle_lsp({
root_dir = lspconfig.util.root_pattern("yarn.lock", "lerna.json", ".git"),
on_attach = on_attach,
}))