dotfiles/nix/home/programs/nvim/nvim-lspconfig.lua
2023-06-15 13:56:39 -07:00

183 lines
5.2 KiB
Lua

local nvim_lsp = require("lspconfig")
--
-- https://vonheikemen.github.io/devlog/tools/setup-nvim-lspconfig-plus-nvim-cmp/
local lsp_defaults = nvim_lsp.util.default_config
lsp_defaults.capabilities = vim.tbl_deep_extend(
'force',
lsp_defaults.capabilities,
require("cmp_nvim_lsp").default_capabilities()
)
vim.api.nvim_create_autocmd("LspAttach", {
desc = "LSP actions",
callback = function()
local bufmap = function(mode, lhs, rhs)
local opts = { buffer = true }
vim.keymap.set(mode, lhs, rhs, opts)
end
-- Displays hover information about the symbol under the cursor
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
-- Jump to the definition
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
-- Jump to declaration
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
-- Lists all the implementations for the symbol under the cursor
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
-- Jumps to the definition of the type symbol
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
-- Lists all the references
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
-- Displays a function's signature information
bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
-- Renames all references to the symbol under the cursor
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
-- Selects a code action available at the current cursor position
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
-- Show diagnostics in a floating window
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
-- Move to the previous diagnostic
bufmap('n', '[a', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
-- Move to the next diagnostic
bufmap('n', ']a', '<cmd>lua vim.diagnostic.goto_next()<cr>')
end
})
vim.api.nvim_create_autocmd("BufWritePre", {
callback = function()
vim.lsp.buf.format()
end
})
nvim_lsp.diagnosticls.setup {
filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'css', 'scss', 'markdown', 'pandoc',
'prisma' },
init_options = {
linters = {
eslint = {
command = 'eslint',
rootPatterns = { '.git' },
debounce = 100,
args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' },
sourceName = 'eslint',
parseJson = {
errorsRoot = '[0].messages',
line = 'line',
column = 'column',
endLine = 'endLine',
endColumn = 'endColumn',
message = '[eslint] ${message} [${ruleId}]',
security = 'severity'
},
securities = {
[1] = 'error',
[2] = 'warning'
}
},
markdownlint = {
command = 'markdownlint',
rootPatterns = { '.git' },
isStderr = true,
debounce = 100,
args = { '--stdin' },
offsetLine = 0,
offsetColumn = 0,
sourceName = 'markdownlint',
securities = {
undefined = 'hint'
},
formatLines = 1,
formatPattern = {
'^.*:(\\d+)\\s+(.*)$',
{
line = 1,
column = -1,
message = 2,
}
}
}
},
filetypes = {
javascript = 'eslint',
javascriptreact = 'eslint',
typescript = 'eslint',
typescriptreact = 'eslint',
markdown = 'markdownlint',
pandoc = 'markdownlint'
},
formatters = {
prettier = {
command = 'prettier',
args = { '--stdin-filepath', '%filename' }
}
},
formatFiletypes = {
css = 'prettier',
javascript = 'prettier',
javascriptreact = 'prettier',
json = 'prettier',
scss = 'prettier',
typescript = 'prettier',
typescriptreact = 'prettier',
markdown = 'prettier',
-- This implies that you have installed a prisma-supporting plugin for
-- prettier. You could instead configure this formatter to be `npx prisma format`
-- directly, but that command doesn't seem to output in the way this
-- diagnostic server expects.
prisma = 'prettier'
}
}
}
nvim_lsp.elmls.setup {
}
local capabilitiesWithoutFomatting = vim.lsp.protocol.make_client_capabilities()
capabilitiesWithoutFomatting.textDocument.formatting = false
capabilitiesWithoutFomatting.textDocument.rangeFormatting = false
capabilitiesWithoutFomatting.textDocument.range_formatting = false
nvim_lsp.tsserver.setup {
init_options = {
hostInfo = "neovim",
maxTsServerMemory = "8192",
preferences = { quotePreference = "single", allowIncompleteCompletions = false },
capabilities = capabilitiesWithoutFomatting
}
}
nvim_lsp.elixirls.setup {
cmd = { "elixir-ls" },
}
nvim_lsp.rnix.setup {
cmd = { "@rnix_lsp@/bin/rnix-lsp" },
}
nvim_lsp.rust_analyzer.setup {}
nvim_lsp.lua_ls.setup {
cmd = { "@lua_ls@/bin/lua-language-server" },
single_file_support = true,
flags = {
debounce_text_changes = 150,
},
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
},
}
nvim_lsp.texlab.setup {}