mirror of
https://github.com/boxpositron/absolute-vim.git
synced 2026-02-28 11:40:36 +00:00
chore(lsp-config.lua): refactor code formatting and improve readability
feat(lsp-config.lua): add support for tailwindcss lsp and attach tailwind_colors only when using tailwindcss lsp feat(lsp-config.lua): add key mappings for various LSP functionalities like go to declaration, go to definitions, show documentation, show LSP implementation, get help, show LSP type definitions, smart rename, see available code actions, show LSP references, format file, and restart LSP feat(lsp-config.lua): configure language servers for html, typescript, css, tailwindcss, svelte, emmet, python, jedi, docker, json, vue, rust, lua, css, htmx, docker file, docker compose, and eslint
This commit is contained in:
@@ -5,53 +5,56 @@ local tailwind_colors = require("tailwindcss-colors")
|
|||||||
|
|
||||||
local opts = { noremap = true, silent = true }
|
local opts = { noremap = true, silent = true }
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
opts.buffer = bufnr
|
opts.buffer = bufnr
|
||||||
|
|
||||||
tailwind_colors.buf_attach(bufnr)
|
-- Only attach when we are using the tailwindcss lsp
|
||||||
|
if client.name == "tailwindcss" then
|
||||||
|
tailwind_colors.buf_attach(bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
-- Enable completion triggered by <c-x><c-o>
|
-- Enable completion triggered by <c-x><c-o>
|
||||||
-- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
-- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
||||||
|
|
||||||
opts.desc = "Go to declaration"
|
opts.desc = "Go to declaration"
|
||||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||||
|
|
||||||
opts.desc = "Go to definitions"
|
opts.desc = "Go to definitions"
|
||||||
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Show documentation for what is under cursor"
|
opts.desc = "Show documentation for what is under cursor"
|
||||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||||
|
|
||||||
opts.desc = "Show LSP Implementation"
|
opts.desc = "Show LSP Implementation"
|
||||||
vim.keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
vim.keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Get Help"
|
opts.desc = "Get Help"
|
||||||
vim.keymap.set("n", "<C-?>", vim.lsp.buf.signature_help, opts)
|
vim.keymap.set("n", "<C-?>", vim.lsp.buf.signature_help, opts)
|
||||||
|
|
||||||
-- vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts)
|
-- vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts)
|
||||||
-- vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
-- vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
||||||
-- vim.keymap.set('n', '<leader>wl', function()
|
-- vim.keymap.set('n', '<leader>wl', function()
|
||||||
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
-- end, opts)
|
-- end, opts)
|
||||||
|
|
||||||
opts.desc = "Show LSP type definitions"
|
opts.desc = "Show LSP type definitions"
|
||||||
vim.keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
vim.keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Smart rename"
|
opts.desc = "Smart rename"
|
||||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||||
|
|
||||||
opts.desc = "See available code actions"
|
opts.desc = "See available code actions"
|
||||||
vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, opts)
|
vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, opts)
|
||||||
|
|
||||||
opts.desc = "Show LSP references"
|
opts.desc = "Show LSP references"
|
||||||
vim.keymap.set("n", "<leader>vrr", "<cmd>Telescope lsp_references<CR>", opts)
|
vim.keymap.set("n", "<leader>vrr", "<cmd>Telescope lsp_references<CR>", opts)
|
||||||
|
|
||||||
opts.desc = "Format File"
|
opts.desc = "Format File"
|
||||||
vim.keymap.set("n", "<leader>f", function()
|
vim.keymap.set("n", "<leader>f", function()
|
||||||
vim.lsp.buf.format({ async = true })
|
vim.lsp.buf.format({ async = true })
|
||||||
end, opts)
|
end, opts)
|
||||||
|
|
||||||
opts.desc = "Restart LSP"
|
opts.desc = "Restart LSP"
|
||||||
vim.keymap.set("n", "<leader>rs", "<cmd>LspRestart<CR>", opts)
|
vim.keymap.set("n", "<leader>rs", "<cmd>LspRestart<CR>", opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||||
@@ -59,153 +62,153 @@ local capabilities = cmp_nvim_lsp.default_capabilities()
|
|||||||
-- Change the Diagnostic symbols in the sign column (gutter)
|
-- Change the Diagnostic symbols in the sign column (gutter)
|
||||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
||||||
for type, icon in pairs(signs) do
|
for type, icon in pairs(signs) do
|
||||||
local hl = "DiagnosticSign" .. type
|
local hl = "DiagnosticSign" .. type
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- configure html server
|
-- configure html server
|
||||||
lspconfig["html"].setup({
|
lspconfig["html"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure typescript server with plugin
|
-- configure typescript server with plugin
|
||||||
lspconfig["tsserver"].setup({
|
lspconfig["tsserver"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure css server
|
-- configure css server
|
||||||
lspconfig["cssls"].setup({
|
lspconfig["cssls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure tailwindcss server
|
-- configure tailwindcss server
|
||||||
lspconfig["tailwindcss"].setup({
|
lspconfig["tailwindcss"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure svelte server
|
-- configure svelte server
|
||||||
lspconfig["svelte"].setup({
|
lspconfig["svelte"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
on_attach(client, bufnr)
|
on_attach(client, bufnr)
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||||
pattern = { "*.js", "*.ts" },
|
pattern = { "*.js", "*.ts" },
|
||||||
callback = function(ctx)
|
callback = function(ctx)
|
||||||
if client.name == "svelte" then
|
if client.name == "svelte" then
|
||||||
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file })
|
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure emmet language server
|
-- configure emmet language server
|
||||||
lspconfig["emmet_ls"].setup({
|
lspconfig["emmet_ls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure python lsp
|
-- configure python lsp
|
||||||
lspconfig["pylsp"].setup({
|
lspconfig["pylsp"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
pylsp = {
|
pylsp = {
|
||||||
plugins = {
|
plugins = {
|
||||||
jedi_completion = {
|
jedi_completion = {
|
||||||
include_params = true,
|
include_params = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure jedi language server
|
-- configure jedi language server
|
||||||
lspconfig["jedi_language_server"].setup({
|
lspconfig["jedi_language_server"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure docker server
|
-- configure docker server
|
||||||
lspconfig["dockerls"].setup({
|
lspconfig["dockerls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure json server
|
-- configure json server
|
||||||
lspconfig["jsonls"].setup({
|
lspconfig["jsonls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure vue server
|
-- configure vue server
|
||||||
lspconfig["volar"].setup({
|
lspconfig["volar"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
filetypes = { "vue" },
|
filetypes = { "vue" },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure rust server
|
-- configure rust server
|
||||||
lspconfig.rust_analyzer.setup({
|
lspconfig.rust_analyzer.setup({
|
||||||
-- Server-specific settings. See `:help lspconfig-setup`
|
-- Server-specific settings. See `:help lspconfig-setup`
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
settings = {
|
settings = {
|
||||||
["rust-analyzer"] = {},
|
["rust-analyzer"] = {},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure lua server (with special settings)
|
-- configure lua server (with special settings)
|
||||||
lspconfig["lua_ls"].setup({
|
lspconfig["lua_ls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
settings = { -- custom settings for lua
|
settings = { -- custom settings for lua
|
||||||
Lua = {
|
Lua = {
|
||||||
-- make the language server recognize "vim" global
|
-- make the language server recognize "vim" global
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
globals = { "vim" },
|
globals = { "vim" },
|
||||||
},
|
},
|
||||||
workspace = {
|
workspace = {
|
||||||
-- make language server aware of runtime files
|
-- make language server aware of runtime files
|
||||||
library = {
|
library = {
|
||||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||||
[vim.fn.stdpath("config") .. "/lua"] = true,
|
[vim.fn.stdpath("config") .. "/lua"] = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure css server
|
-- configure css server
|
||||||
lspconfig["cssls"].setup({
|
lspconfig["cssls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure htmx server
|
-- configure htmx server
|
||||||
lspconfig["htmx"].setup({
|
lspconfig["htmx"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
--configure docker file server
|
--configure docker file server
|
||||||
lspconfig["dockerls"].setup({
|
lspconfig["dockerls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure docker compose server
|
-- configure docker compose server
|
||||||
lspconfig["docker_compose_language_service"].setup({
|
lspconfig["docker_compose_language_service"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure eslint server
|
-- configure eslint server
|
||||||
lspconfig["eslint"].setup({
|
lspconfig["eslint"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user