End of config for now

This commit is contained in:
2023-12-30 18:35:52 +01:00
parent c6fc077654
commit 9d87a5985d
21 changed files with 490 additions and 131 deletions

43
lua/config/lsp/attach.lua Normal file
View File

@@ -0,0 +1,43 @@
return function()
local km = vim.keymap.set
local opts = {}
opts.desc = "show documentation under cursor"
km("n", "<leader>lK", vim.lsp.buf.hover, opts)
opts.desc = "show LSP References"
km("n", "<leader>lR", ":Telescope lsp_references<cr>", opts)
opts.desc = "go to declaration"
km("n", "<leader>lD", "vim.lsp.buf.declaration<cr>", opts)
opts.desc = "show LSP definition"
km("n", "<leader>ld", ":Telescope lsp_definitions<cr>", opts)
opts.desc = "Show LSP implementations"
km("n", "<leader>li", ":Telescope lsp_implementations<cr>", opts)
opts.desc = "Show LSP type definitions"
km("n", "<leader>lt", ":Telescope lsp_type_definitions<cr>", opts)
opts.desc = "See available code actions"
km({ "n", "v" }, "<leader>lc", vim.lsp.buf.code_action, opts)
opts.desc = "Smart rename"
km("n", "<leader>ln", vim.lsp.buf.rename, opts)
opts.desc = "Show buffer diagnostics"
km("n", "<leader>lE", ":Telescope diagnostics bufnr=0<cr>", opts)
opts.desc = "Show line diagnostics"
km("n", "<leader>le", vim.diagnostic.open_float, opts)
opts.desc = "Go to previous diagnostic"
km("n", "<leader>lp", vim.diagnostic.goto_prev, opts)
opts.desc = "Go to next diagnostic"
km("n", "<leader>ln", vim.diagnostic.goto_next, opts)
opts.desc = "Restart LSP"
km("n", "<leader>ls", ":LspRestart<cr>", opts)
end

57
lua/config/lsp/bash.lua Normal file
View File

@@ -0,0 +1,57 @@
local ok, mason_lspconfig, mason_tool_installer, lspconfig, conform, lint = pcall(function()
return require("mason-lspconfig"),
require("mason-tool-installer"),
require("lspconfig"),
require("conform"),
require("lint")
end)
if not ok then
return
end
mason_lspconfig.setup({
ensure_installed = { "bashls" },
})
lspconfig.bashls.setup({
capabilities = require("config/lsp/capabilities"),
on_attach = require("config/lsp/attach"),
})
mason_tool_installer.setup({
ensure_installed = { "shellcheck" },
})
conform.setup({
formatters_by_ft = {
sh = { "shellcheck" },
},
format_on_save = {
async = false,
timeout_ms = 500,
lsp_fallback = true,
},
})
vim.keymap.set({ "n", "v" }, "<leader>lf", function()
conform.format({
async = false,
timeout_ms = 500,
lsp_fallback = true,
})
end, { desc = "Format" })
lint.linters_by_ft = {
lua = { "shellcheck" },
}
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
callback = function()
lint.try_lint()
end,
})
vim.keymap.set("n", "<leader>ll", function()
lint.try_lint()
end, { desc = "Lint" })

View File

@@ -0,0 +1,6 @@
local ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not ok then
return
end
return cmp_nvim_lsp.default_capabilities()

73
lua/config/lsp/lua.lua Normal file
View File

@@ -0,0 +1,73 @@
local ok, mason_lspconfig, mason_tool_installer, lspconfig, conform, lint = pcall(function()
return require("mason-lspconfig"),
require("mason-tool-installer"),
require("lspconfig"),
require("conform"),
require("lint")
end)
if not ok then
return
end
mason_lspconfig.setup({
ensure_installed = { "lua_ls" },
})
mason_tool_installer.setup({
ensure_installed = { "stylua", "luacheck" },
})
lspconfig.lua_ls.setup({
-- capabilities = cmp_nvim_lsp.default_capabilities()
capabilities = require("config/lsp/capabilities"),
on_attach = require("config/lsp/attach"),
settings = { -- custom settings for lua
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { "vim" },
},
workspace = {
-- make language server aware of runtime files
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true,
},
},
},
},
})
conform.setup({
formatters_by_ft = {
lua = { "stylua" },
},
format_on_save = {
async = false,
timeout_ms = 500,
lsp_fallback = true,
},
})
vim.keymap.set({ "n", "v" }, "<leader>lf", function()
conform.format({
async = false,
timeout_ms = 500,
lsp_fallback = true,
})
end, { desc = "Format" })
lint.linters_by_ft = {
lua = { "luacheck" },
}
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
callback = function()
lint.try_lint()
end,
})
vim.keymap.set("n", "<leader>ll", function()
lint.try_lint()
end, { desc = "Lint" })

6
lua/config/lsp/signs.lua Normal file
View File

@@ -0,0 +1,6 @@
local signs = { Error = "", Warn = "", Hint = "󰠠 ", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end

83
lua/config/lsp/web.lua Normal file
View File

@@ -0,0 +1,83 @@
local ok, mason_lspconfig, mason_tool_installer, lspconfig, conform, lint = pcall(function()
return require("mason-lspconfig"),
require("mason-tool-installer"),
require("lspconfig"),
require("conform"),
require("lint")
end)
if not ok then
return
end
mason_lspconfig.setup({
ensure_installed = {
"tsserver",
"html",
"emmet_ls",
"cssls",
},
})
lspconfig.tsserver.setup({
capabilities = require("config/lsp/capabilities"),
on_attach = require("config/lsp/attach"),
})
lspconfig.html.setup({
capabilities = require("config/lsp/capabilities"),
on_attach = require("config/lsp/attach"),
})
lspconfig.emmet_ls.setup({
capabilities = require("config/lsp/capabilities"),
on_attach = require("config/lsp/attach"),
})
lspconfig.cssls.setup({
capabilities = require("config/lsp/capabilities"),
on_attach = require("config/lsp/attach"),
})
mason_tool_installer.setup({
ensure_installed = {
"prettierd",
"prettier",
"eslint_d",
},
})
conform.setup({
formatters_by_ft = {
javascript = { { "prettierd", "prettier" } },
json = { { "prettierd", "prettier" } },
},
format_on_save = {
async = false,
timeout_ms = 500,
lsp_fallback = true,
},
})
vim.keymap.set({ "n", "v" }, "<leader>lf", function()
conform.format({
async = false,
timeout_ms = 500,
lsp_fallback = true,
})
end, { desc = "Format" })
lint.linters_by_ft = {
javascript = { "eslint_d" },
json = { "eslint_d" },
}
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
callback = function()
lint.try_lint()
end,
})
vim.keymap.set("n", "<leader>ll", function()
lint.try_lint()
end, { desc = "Lint" })