2023-02-18 16:25:09 +01:00
|
|
|
local lsp_lines = require("lsp_lines")
|
|
|
|
lsp_lines.setup()
|
|
|
|
-- Disable virtual_text since it's redundant due to lsp_lines.
|
|
|
|
vim.diagnostic.config({
|
|
|
|
virtual_text = false,
|
|
|
|
})
|
|
|
|
|
2023-09-06 09:19:32 +02:00
|
|
|
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
|
2023-03-04 13:22:48 +01:00
|
|
|
-- Tell the server the capability of foldingRange,
|
|
|
|
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
|
|
|
|
capabilities.textDocument.foldingRange = {
|
|
|
|
dynamicRegistration = false,
|
|
|
|
lineFoldingOnly = true,
|
|
|
|
}
|
2023-08-16 16:43:35 +02:00
|
|
|
-- NOTE https://github.com/neovim/neovim/pull/22405
|
|
|
|
capabilities.didChangeWatchedFiles = {
|
|
|
|
dynamicRegistration = true,
|
|
|
|
}
|
2023-03-04 13:22:48 +01:00
|
|
|
|
2023-02-18 13:35:11 +01:00
|
|
|
local lspconfig = require("lspconfig")
|
2023-08-11 19:00:43 +02:00
|
|
|
local on_attach_def = function(client, bufnr)
|
2023-03-26 18:28:49 +02:00
|
|
|
require("which-key").register({
|
2023-08-12 11:50:46 +02:00
|
|
|
K = {
|
2024-05-13 10:33:17 +02:00
|
|
|
vim.lsp.buf.hover,
|
2023-08-12 11:50:46 +02:00
|
|
|
"Hover",
|
|
|
|
},
|
2023-02-18 16:25:09 +01:00
|
|
|
["<leader>"] = {
|
2023-10-28 15:18:59 +02:00
|
|
|
c = {
|
|
|
|
name = "code",
|
2023-09-06 08:43:03 +02:00
|
|
|
c = { require("actions-preview").code_actions, "Code action", mode = { "v", "n" } },
|
2023-08-12 16:46:45 +02:00
|
|
|
r = {
|
|
|
|
function()
|
|
|
|
return ":IncRename " .. vim.fn.expand("<cword>")
|
|
|
|
end,
|
|
|
|
"Rename",
|
|
|
|
expr = true,
|
|
|
|
},
|
2023-02-18 16:25:09 +01:00
|
|
|
f = {
|
2023-02-18 13:35:11 +01:00
|
|
|
function()
|
|
|
|
vim.lsp.buf.format({ async = true })
|
|
|
|
end,
|
2023-08-11 17:38:26 +02:00
|
|
|
"Format (lsp)",
|
2023-02-18 16:25:09 +01:00
|
|
|
mode = { "n", "v" },
|
2023-02-18 13:35:11 +01:00
|
|
|
},
|
2023-02-18 16:25:09 +01:00
|
|
|
},
|
|
|
|
t = {
|
2023-09-07 09:08:18 +02:00
|
|
|
l = {
|
|
|
|
function()
|
|
|
|
lsp_lines.toggle()
|
|
|
|
if vim.diagnostic.is_disabled() then
|
|
|
|
vim.diagnostic.enable()
|
|
|
|
else
|
|
|
|
vim.diagnostic.disable()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
"LSP lines",
|
|
|
|
},
|
2023-08-11 19:00:43 +02:00
|
|
|
i = {
|
|
|
|
function()
|
2024-01-22 15:25:47 +01:00
|
|
|
vim.lsp.inlay_hint.enable(bufnr, not vim.lsp.inlay_hint.is_enabled(bufnr))
|
2023-08-11 19:00:43 +02:00
|
|
|
end,
|
|
|
|
"LSP inlay hints",
|
|
|
|
},
|
2023-02-18 16:25:09 +01:00
|
|
|
},
|
2023-02-18 13:35:11 +01:00
|
|
|
},
|
|
|
|
g = {
|
2023-08-11 17:38:26 +02:00
|
|
|
d = {
|
|
|
|
function()
|
|
|
|
require("telescope.builtin").lsp_definitions({ reuse_win = true })
|
|
|
|
end,
|
|
|
|
"Goto definition",
|
|
|
|
},
|
|
|
|
t = {
|
|
|
|
function()
|
|
|
|
require("telescope.builtin").lsp_type_definitions({ reuse_win = true })
|
|
|
|
end,
|
2023-11-30 14:46:29 +01:00
|
|
|
"Goto type definition",
|
2023-08-11 17:38:26 +02:00
|
|
|
},
|
|
|
|
r = { "<cmd>Telescope lsp_references<cr>", "Goto references" },
|
2023-04-09 19:31:14 +02:00
|
|
|
D = { vim.lsp.buf.declaration, "Goto declaration" },
|
|
|
|
I = { "<cmd>Telescope lsp_implementations<cr>", "Goto implementation" },
|
2023-08-11 17:38:26 +02:00
|
|
|
K = { vim.lsp.buf.signature_help, "Signature help" },
|
2023-04-09 19:31:14 +02:00
|
|
|
},
|
|
|
|
["["] = {
|
2023-08-11 17:38:26 +02:00
|
|
|
d = { vim.diagnostic.goto_prev, "Previous diagnostic" },
|
2023-04-09 19:31:14 +02:00
|
|
|
},
|
|
|
|
["]"] = {
|
2023-08-11 17:38:26 +02:00
|
|
|
d = { vim.diagnostic.goto_next, "Next diagnostic" },
|
2023-02-18 13:35:11 +01:00
|
|
|
},
|
2023-02-18 17:55:20 +01:00
|
|
|
}, { buffer = bufnr, silent = true })
|
2023-08-11 19:00:43 +02:00
|
|
|
|
|
|
|
if client.server_capabilities.inlayHintProvider then
|
2023-08-12 08:05:05 +02:00
|
|
|
local slow_lsp_servers = {
|
|
|
|
"rust_analyzer",
|
|
|
|
}
|
|
|
|
local timeout = vim.tbl_contains(slow_lsp_servers, client.name, {}) and 500 or 0
|
2023-08-11 19:00:43 +02:00
|
|
|
vim.defer_fn(function()
|
2024-05-13 10:33:17 +02:00
|
|
|
vim.lsp.inlay_hint.enable(true, { bufnr })
|
2023-08-12 08:05:05 +02:00
|
|
|
end, timeout)
|
2023-08-11 19:00:43 +02:00
|
|
|
end
|
2023-02-18 13:35:11 +01:00
|
|
|
end
|
|
|
|
|
2023-02-17 22:09:13 +01:00
|
|
|
local lspconfig_default_options = {
|
|
|
|
on_attach = on_attach_def,
|
|
|
|
capabilities = capabilities,
|
2023-09-06 09:19:32 +02:00
|
|
|
flags = {
|
|
|
|
debounce_text_changes = 100,
|
|
|
|
},
|
2023-02-17 22:09:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
---function to add default options to lspconfig
|
|
|
|
---@param lsp string
|
|
|
|
---@param options table
|
|
|
|
---@return nil
|
|
|
|
local function lspconfig_setup(lsp, options)
|
2023-09-06 09:19:32 +02:00
|
|
|
local final_options = vim.tbl_deep_extend("force", lspconfig_default_options, options)
|
|
|
|
lspconfig[lsp].setup(final_options)
|
2023-02-17 12:38:44 +01:00
|
|
|
end
|
|
|
|
|
2023-03-13 09:07:50 +01:00
|
|
|
local servers = {
|
|
|
|
"bashls",
|
2024-02-12 10:12:07 +01:00
|
|
|
"gleam",
|
2023-10-25 17:22:14 +02:00
|
|
|
"gopls",
|
|
|
|
"nil_ls",
|
2023-09-27 13:11:07 +02:00
|
|
|
"nixd",
|
2024-02-13 09:27:27 +01:00
|
|
|
"pylsp",
|
2023-03-13 09:07:50 +01:00
|
|
|
"ruff_lsp",
|
2024-01-16 12:46:09 +01:00
|
|
|
"templ",
|
2023-06-25 11:15:08 +02:00
|
|
|
"typst_lsp",
|
2023-03-13 09:07:50 +01:00
|
|
|
}
|
2023-02-17 12:38:44 +01:00
|
|
|
for _, lsp in ipairs(servers) do
|
2023-02-17 22:09:13 +01:00
|
|
|
lspconfig_setup(lsp, {})
|
2023-02-17 12:38:44 +01:00
|
|
|
end
|
|
|
|
|
2024-01-16 12:46:09 +01:00
|
|
|
-- Add templ filetype
|
|
|
|
vim.filetype.add({ extension = { templ = "templ" } })
|
|
|
|
|
|
|
|
lspconfig_setup("htmx", {
|
|
|
|
filetypes = { "html", "templ" },
|
|
|
|
})
|
|
|
|
|
|
|
|
lspconfig_setup("tailwindcss", {
|
|
|
|
filetypes = { "templ", "astro", "javascript", "typescript", "react" },
|
|
|
|
init_options = { userLanguages = { templ = "html" } },
|
|
|
|
})
|
|
|
|
|
2023-07-29 17:06:58 +02:00
|
|
|
lspconfig_setup("rust_analyzer", {
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
checkOnSave = {
|
|
|
|
command = "clippy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-02-17 22:09:13 +01:00
|
|
|
lspconfig_setup("lua_ls", {
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
|
|
version = "LuaJIT",
|
2023-08-12 08:07:33 +02:00
|
|
|
path = vim.split(package.path, ";"),
|
2023-02-17 22:09:13 +01:00
|
|
|
},
|
|
|
|
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),
|
|
|
|
checkThirdParty = false,
|
|
|
|
},
|
|
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
format = {
|
|
|
|
enable = false,
|
|
|
|
},
|
2023-08-12 08:05:05 +02:00
|
|
|
hint = {
|
|
|
|
enable = true,
|
|
|
|
},
|
2023-02-17 22:09:13 +01:00
|
|
|
},
|
|
|
|
},
|
2023-02-17 12:38:44 +01:00
|
|
|
})
|