2024-03-17 12:32:47 +00:00
|
|
|
local mason_lspconfig = require("mason-lspconfig")
|
|
|
|
local lspconfig = require("lspconfig")
|
2022-12-13 15:43:36 +00:00
|
|
|
|
|
|
|
mason_lspconfig.setup({
|
2024-03-17 12:32:47 +00:00
|
|
|
automatic_installation = false,
|
2022-12-13 15:43:36 +00:00
|
|
|
})
|
|
|
|
|
2022-11-14 03:00:43 +00:00
|
|
|
-- Use an on_attach function to only map the following keys
|
|
|
|
-- after the language server attaches to the current buffer
|
2024-03-17 12:32:47 +00:00
|
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
|
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
|
|
|
callback = function(ev)
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
|
|
|
local telescope = require("telescope.builtin")
|
|
|
|
local conform = require("conform")
|
2022-10-19 00:47:07 +01:00
|
|
|
|
2024-03-30 16:08:40 +00:00
|
|
|
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
|
|
|
client.server_capabilities.semanticTokensProvider = nil
|
|
|
|
|
2024-04-18 01:21:37 +01:00
|
|
|
--Enable inlay hints
|
|
|
|
--vim.lsp.inlay_hint.enable(ev.buf,true)
|
|
|
|
|
2024-03-17 12:32:47 +00:00
|
|
|
-- Mappings.
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
local bufopts = { noremap = true, silent = true, buffer = ev.buf }
|
|
|
|
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, bufopts)
|
|
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
|
|
|
|
vim.keymap.set("n", "gd", telescope.lsp_definitions, bufopts)
|
|
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
|
|
|
vim.keymap.set("n", "gi", telescope.lsp_implementations, bufopts)
|
|
|
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
|
|
|
|
vim.keymap.set("n", "gr", telescope.lsp_references, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>ge", function() vim.diagnostic.goto_next() end, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>gE", function() vim.diagnostic.goto_prev() end, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>fo", function() conform.format({ lsp_fallback = true }) end, bufopts)
|
2024-04-18 01:21:37 +01:00
|
|
|
vim.keymap.set("n", "<space>n", "<cmd>!toke check<cr>")
|
2024-03-17 12:32:47 +00:00
|
|
|
end,
|
|
|
|
})
|
2022-10-19 00:47:07 +01:00
|
|
|
|
2022-12-15 17:43:06 +00:00
|
|
|
-- ADD NVIM CMP AS A CAPABILITY
|
|
|
|
local lsp_defaults = lspconfig.util.default_config
|
2024-03-17 12:32:47 +00:00
|
|
|
local capabilities =
|
|
|
|
vim.tbl_deep_extend("force", lsp_defaults.capabilities, require("cmp_nvim_lsp").default_capabilities())
|
2022-12-13 15:43:36 +00:00
|
|
|
|
2024-03-17 12:32:47 +00:00
|
|
|
mason_lspconfig.setup_handlers({
|
2023-09-18 07:20:52 +01:00
|
|
|
-- This is a default handler that will be called for each installed server (also for new servers that are installed during a session)
|
|
|
|
function(server_name)
|
2024-03-17 12:32:47 +00:00
|
|
|
lspconfig[server_name].setup({
|
2023-11-01 22:56:14 +00:00
|
|
|
capabilities = capabilities,
|
2024-03-17 12:32:47 +00:00
|
|
|
})
|
2023-09-18 07:20:52 +01:00
|
|
|
end,
|
2024-04-18 01:21:37 +01:00
|
|
|
["gopls"] = function ()
|
|
|
|
lspconfig["gopls"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
gopls = {
|
|
|
|
["ui.completion.usePlaceholders"] = true,
|
|
|
|
["ui.diagnostic.staticcheck"] = true,
|
|
|
|
["ui.inlayhint.hints"] = {
|
|
|
|
assignVariablesTypes = true,
|
|
|
|
compositeLiteralFields = true,
|
|
|
|
compositeLiteralTypes = true,
|
|
|
|
constantValues = true,
|
|
|
|
functionTypeParameters = true,
|
|
|
|
parameterNames = true,
|
|
|
|
rangeVariableTypes = true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end,
|
2024-03-17 12:32:47 +00:00
|
|
|
["lua_ls"] = function()
|
|
|
|
lspconfig["lua_ls"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
library = {
|
|
|
|
unpack(vim.api.nvim_get_runtime_file('', true))
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = { 'vim' },
|
|
|
|
},
|
2024-04-18 01:21:37 +01:00
|
|
|
hint = { enable = true }
|
2024-03-17 12:32:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
["ltex"] = function()
|
|
|
|
lspconfig["ltex"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
--Local on attach
|
|
|
|
on_attach = function(_, _)
|
|
|
|
-- rest of your on_attach process.
|
|
|
|
require("ltex_extra").setup()
|
|
|
|
end,
|
|
|
|
})
|
2024-03-30 16:08:40 +00:00
|
|
|
end,
|
2024-04-08 13:47:18 +01:00
|
|
|
["basedpyright"] = function()
|
2024-03-30 16:08:40 +00:00
|
|
|
lspconfig["basedpyright"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
verboseOutput = true,
|
|
|
|
autoImportCompletion = true,
|
|
|
|
basedpyright = {
|
|
|
|
analysis = {
|
|
|
|
typeCheckingMode = "all",
|
|
|
|
autoSearchPaths = true,
|
|
|
|
useLibraryCodeForTypes = true,
|
|
|
|
diagnosticMode = "openFilesOnly",
|
|
|
|
indexing = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2024-04-08 13:47:18 +01:00
|
|
|
end,
|
2024-03-30 16:08:40 +00:00
|
|
|
})
|
2024-03-17 12:32:47 +00:00
|
|
|
|
|
|
|
|
2024-03-30 16:08:40 +00:00
|
|
|
lspconfig["hls"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
filetypes = { 'haskell', 'lhaskell', 'cabal' },
|
2024-03-17 12:32:47 +00:00
|
|
|
})
|
|
|
|
|
2023-10-21 15:18:01 +01:00
|
|
|
|
2024-03-03 16:58:37 +00:00
|
|
|
|
2024-03-30 16:08:40 +00:00
|
|
|
|
|
|
|
--vim.g.rustaceanvim = {
|
|
|
|
-- server = {
|
|
|
|
-- capabilities = capabilities,
|
|
|
|
-- },
|
|
|
|
--}
|