2022-01-31 21:41:13 +01:00
|
|
|
local M = {}
|
|
|
|
|
2022-02-01 00:06:48 +01:00
|
|
|
local function map(buf, mode, lhs, rhs, opts)
|
|
|
|
local options = {noremap = true, silent = true}
|
|
|
|
if opts then options = vim.tbl_extend('force', options, opts) end
|
|
|
|
vim.api.nvim_buf_set_keymap(buf, mode, lhs, rhs, options)
|
2022-01-31 21:41:13 +01:00
|
|
|
end
|
|
|
|
|
2022-03-09 19:44:21 +01:00
|
|
|
function M.on_attach(client, bufnr)
|
2022-01-31 21:41:13 +01:00
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
|
2022-03-09 19:44:21 +01:00
|
|
|
if client.resolved_capabilities.document_formatting then
|
|
|
|
vim.cmd([[
|
|
|
|
augroup LspFormatting
|
|
|
|
autocmd! * <buffer>
|
|
|
|
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
|
|
|
|
augroup END
|
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
2022-01-31 21:41:13 +01:00
|
|
|
-- Go to declaration / definition / implementation
|
|
|
|
map(bufnr, "n", 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>')
|
|
|
|
map(bufnr, "n", 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
|
|
|
|
map(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
|
|
|
|
|
|
|
|
-- Hover
|
2022-04-04 01:10:26 +02:00
|
|
|
map(bufnr, 'n', 'J',
|
|
|
|
"<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>")
|
2022-01-31 21:41:13 +01:00
|
|
|
map(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
|
2022-04-04 01:10:26 +02:00
|
|
|
map(bufnr, 'n', 'L', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
|
2022-01-31 21:41:13 +01:00
|
|
|
|
|
|
|
-- Workspace stuff
|
2022-03-13 15:16:19 +01:00
|
|
|
map(bufnr, 'n', '<space>wa',
|
|
|
|
'<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
|
|
|
|
map(bufnr, 'n', '<space>wr',
|
|
|
|
'<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>')
|
|
|
|
map(bufnr, 'n', '<space>wl',
|
|
|
|
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>')
|
2022-01-31 21:41:13 +01:00
|
|
|
|
|
|
|
-- Code actions
|
|
|
|
map(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>')
|
|
|
|
map(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
|
2022-02-23 15:44:33 +01:00
|
|
|
-- map(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')
|
2022-01-31 21:41:13 +01:00
|
|
|
map(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>')
|
|
|
|
map(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>')
|
|
|
|
end
|
|
|
|
|
2022-02-01 15:18:36 +01:00
|
|
|
local function on_attach_typescript(client, bufnr)
|
|
|
|
client.resolved_capabilities.document_formatting = false
|
|
|
|
client.resolved_capabilities.document_range_formatting = false
|
|
|
|
|
2022-03-09 19:44:21 +01:00
|
|
|
M.on_attach(client, bufnr)
|
2022-02-01 15:18:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- General server config
|
|
|
|
local servers = {
|
|
|
|
tsserver = {on_attach = on_attach_typescript},
|
|
|
|
sumneko_lua = {
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
|
|
version = 'LuaJIT',
|
|
|
|
-- Setup your lua path
|
|
|
|
path = runtime_path
|
|
|
|
},
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cmd = {"lua-language-server"}
|
|
|
|
},
|
2022-03-13 15:16:19 +01:00
|
|
|
purescriptls = {
|
|
|
|
settings = {
|
|
|
|
purescript = {
|
|
|
|
censorWarnings = {
|
|
|
|
"UnusedName", "ShadowedName", "UserDefinedWarning"
|
|
|
|
},
|
|
|
|
formatter = "purs-tidy"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-02-01 15:18:36 +01:00
|
|
|
rnix = {}
|
2022-04-04 01:10:26 +02:00
|
|
|
-- agda = {}, Haven't gotten this one to work yet
|
2022-02-01 15:18:36 +01:00
|
|
|
}
|
|
|
|
|
2022-01-31 21:41:13 +01:00
|
|
|
function M.setup()
|
2022-03-13 15:16:19 +01:00
|
|
|
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp
|
|
|
|
.protocol
|
|
|
|
.make_client_capabilities())
|
2022-02-09 21:20:34 +01:00
|
|
|
|
2022-02-01 00:06:48 +01:00
|
|
|
-- Setup basic language servers
|
|
|
|
for lsp, details in pairs(servers) do
|
2022-02-01 15:18:36 +01:00
|
|
|
if details.on_attach == nil then
|
|
|
|
-- Default setting for on_attach
|
2022-03-09 19:44:21 +01:00
|
|
|
details.on_attach = M.on_attach
|
2022-02-01 15:18:36 +01:00
|
|
|
end
|
|
|
|
|
2022-01-31 21:41:13 +01:00
|
|
|
require('lspconfig')[lsp].setup {
|
2022-02-01 15:18:36 +01:00
|
|
|
on_attach = details.on_attach,
|
2022-02-01 00:06:48 +01:00
|
|
|
settings = details.settings, -- Specific per-language settings
|
2022-01-31 21:41:13 +01:00
|
|
|
flags = {
|
2022-02-01 00:06:48 +01:00
|
|
|
debounce_text_changes = 150 -- This will be the default in neovim 0.7+
|
|
|
|
},
|
2022-02-09 21:20:34 +01:00
|
|
|
cmd = details.cmd,
|
|
|
|
capabilities = capabilities
|
2022-01-31 21:41:13 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-01 00:06:48 +01:00
|
|
|
return M
|