summaryrefslogtreecommitdiff
path: root/lua/ache/plugins
diff options
context:
space:
mode:
authorache <ache@ache.one>2024-08-09 06:56:15 +0200
committerache <ache@ache.one>2024-08-09 06:57:49 +0200
commit89b644d321912ef8f7530c98deba7109a8297e0e (patch)
tree05aed9d11e3fa0e02e47f9a5e5a6804ea14a4efc /lua/ache/plugins
parentConfigure ltex (diff)
Configure LSP for lua and Python
Diffstat (limited to 'lua/ache/plugins')
-rw-r--r--lua/ache/plugins/lsp/lspconfig.lua307
1 files changed, 156 insertions, 151 deletions
diff --git a/lua/ache/plugins/lsp/lspconfig.lua b/lua/ache/plugins/lsp/lspconfig.lua
index d7ef824..59e9ceb 100644
--- a/lua/ache/plugins/lsp/lspconfig.lua
+++ b/lua/ache/plugins/lsp/lspconfig.lua
@@ -1,158 +1,163 @@
return {
- "neovim/nvim-lspconfig",
- event = { "BufReadPre", "BufNewFile" },
- dependencies = {
- "hrsh7th/cmp-nvim-lsp",
- "williamboman/mason-lspconfig.nvim",
- { "antosha417/nvim-lsp-file-operations", config = true },
- { "folke/neodev.nvim", opts = {} },
- },
- config = function()
- local lspconfig = require("lspconfig")
- local mason_lspconfig = require("mason-lspconfig")
- local cmp_nvim_lsp = require("cmp_nvim_lsp")
+ "neovim/nvim-lspconfig",
+ event = { "BufReadPre", "BufNewFile" },
+ dependencies = {
+ "hrsh7th/cmp-nvim-lsp",
+ "williamboman/mason-lspconfig.nvim",
+ { "antosha417/nvim-lsp-file-operations", config = true },
+ { "folke/neodev.nvim", opts = {} },
+ },
+ config = function()
+ local lspconfig = require("lspconfig")
+ local mason_lspconfig = require("mason-lspconfig")
+ local cmp_nvim_lsp = require("cmp_nvim_lsp")
- vim.api.nvim_create_autocmd("LspAttach", {
- group = vim.api.nvim_create_augroup("UserLspConfig", {}),
- callback = function(ev)
- -- Buffer local mappings.
- -- See `:help vim.lsp.*` for documentation on any of the functions below.
+ vim.api.nvim_create_autocmd("LspAttach", {
+ group = vim.api.nvim_create_augroup("UserLspConfig", {}),
+ callback = function(ev)
+ -- Buffer local mappings.
+ -- See `:help vim.lsp.*` for documentation on any of the functions below.
- -- Keybinds
- vim.keymap.set(
- "n",
- "gR",
- "<cmd>Telescope lsp_references<CR>",
- { buffer = ev.buf, silent = true, desc = "Show LSP references" }
- )
- vim.keymap.set(
- "n",
- "gD",
- vim.lsp.buf.declaration,
- { buffer = ev.buf, silent = true, desc = "Go to declaration" }
- )
- vim.keymap.set(
- "n",
- "gd",
- "<cmd>Telescope lsp_definitions<CR>",
- { buffer = ev.buf, silent = true, desc = "Show LSP definitions" }
- )
- vim.keymap.set(
- "n",
- "gi",
- "<cmd>Telescope lsp_implementations<CR>",
- { buffer = ev.buf, silent = true, desc = "Show LSP implementations" }
- )
- vim.keymap.set(
- "n",
- "gt",
- "<cmd>Telescope lsp_type_definitions<CR>",
- { buffer = ev.buf, silent = true, desc = "Show LSP type definitions" }
- )
- vim.keymap.set(
- { "n", "v" },
- "<leader>ca",
- vim.lsp.buf.code_action,
- { buffer = ev.buf, silent = true, desc = "See available code actions" }
- )
- vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { buffer = ev.buf, silent = true, desc = "Smart rename" })
- vim.keymap.set(
- "n",
- "<leader>D",
- "<cmd>Telescope diagnostics bufnr=0<CR>",
- { buffer = ev.buf, silent = true, desc = "Show buffer diagnostics" }
- )
- vim.keymap.set(
- "n",
- "<leader>d",
- vim.diagnostic.open_float,
- { buffer = ev.buf, silent = true, desc = "Show line diagnostics" }
- )
- vim.keymap.set(
- "n",
- "<d",
- vim.diagnostic.goto_prev,
- { buffer = ev.buf, silent = true, desc = "Go to previous diagnostic" }
- )
- vim.keymap.set(
- "n",
- ">d",
- vim.diagnostic.goto_next,
- { buffer = ev.buf, silent = true, desc = "Go to next diagnostic" }
- )
- vim.keymap.set(
- "n",
- "K",
- vim.lsp.buf.hover,
- { buffer = ev.buf, silent = true, desc = "Show documentation for what is under the cursor" }
- )
- vim.keymap.set(
- "n",
- "<leader>rs",
- "<cmd>LspRestart<CR>",
- { buffer = ev.buf, silent = true, desc = "Restart LSP" }
- )
- end,
- })
+ -- Keybinds
+ vim.keymap.set(
+ "n",
+ "gR",
+ "<cmd>Telescope lsp_references<CR>",
+ { buffer = ev.buf, silent = true, desc = "Show LSP references" }
+ )
+ vim.keymap.set(
+ "n",
+ "gD",
+ vim.lsp.buf.declaration,
+ { buffer = ev.buf, silent = true, desc = "Go to declaration" }
+ )
+ vim.keymap.set(
+ "n",
+ "gd",
+ "<cmd>Telescope lsp_definitions<CR>",
+ { buffer = ev.buf, silent = true, desc = "Show LSP definitions" }
+ )
+ vim.keymap.set(
+ "n",
+ "gi",
+ "<cmd>Telescope lsp_implementations<CR>",
+ { buffer = ev.buf, silent = true, desc = "Show LSP implementations" }
+ )
+ vim.keymap.set(
+ "n",
+ "gt",
+ "<cmd>Telescope lsp_type_definitions<CR>",
+ { buffer = ev.buf, silent = true, desc = "Show LSP type definitions" }
+ )
+ vim.keymap.set(
+ { "n", "v" },
+ "<leader>ca",
+ vim.lsp.buf.code_action,
+ { buffer = ev.buf, silent = true, desc = "See available code actions" }
+ )
+ vim.keymap.set(
+ "n",
+ "<leader>rn",
+ vim.lsp.buf.rename,
+ { buffer = ev.buf, silent = true, desc = "Smart rename" }
+ )
+ vim.keymap.set(
+ "n",
+ "<leader>D",
+ "<cmd>Telescope diagnostics bufnr=0<CR>",
+ { buffer = ev.buf, silent = true, desc = "Show buffer diagnostics" }
+ )
+ vim.keymap.set(
+ "n",
+ "<leader>d",
+ vim.diagnostic.open_float,
+ { buffer = ev.buf, silent = true, desc = "Show line diagnostics" }
+ )
+ vim.keymap.set(
+ "n",
+ "<d",
+ vim.diagnostic.goto_prev,
+ { buffer = ev.buf, silent = true, desc = "Go to previous diagnostic" }
+ )
+ vim.keymap.set(
+ "n",
+ ">d",
+ vim.diagnostic.goto_next,
+ { buffer = ev.buf, silent = true, desc = "Go to next diagnostic" }
+ )
+ vim.keymap.set(
+ "n",
+ "K",
+ vim.lsp.buf.hover,
+ { buffer = ev.buf, silent = true, desc = "Show documentation for what is under the cursor" }
+ )
+ vim.keymap.set(
+ "n",
+ "<leader>rs",
+ "<cmd>LspRestart<CR>",
+ { buffer = ev.buf, silent = true, desc = "Restart LSP" }
+ )
+ end,
+ })
- -- used to enable autocompletion (assign to every lsp server config)
- local capabilities = cmp_nvim_lsp.default_capabilities()
+ -- used to enable autocompletion (assign to every lsp server config)
+ local capabilities = cmp_nvim_lsp.default_capabilities()
- -- Change the diagnostics symbols in the sign column (gutter)
- 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
+ -- Change the diagnostics symbols in the sign column (gutter)
+ 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
- mason_lspconfig.setup_handlers({
- -- default handler for installed servers
- function(server_name)
- lspconfig[server_name].setup({
- capabilities = capabilities,
- })
- end,
- ["svelte"] = function()
- -- Configuration specific to svelte LSP server
- lspconfig["svelte"].setup({
- capabilities = capabilities,
- on_attach = function(client, bufnr)
- vim.api.nvim_create_autocmd("BufWritePost", {
- pattern = { "*.js", "*.ts" },
- callback = function(ctx)
- -- Here use ctx.match instead of ctx.file
- client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
- end,
- })
- end,
- })
- end,
- ["lua_ls"] = function()
- lspconfig["lua_ls"].setup({
- capabilities = capabilities,
- settings = {
- Lua = {
- -- make the language server recognize the "vim" global variable
- diagnostics = {
- globals = { "vim" },
- },
- completion = {
- callSnippet = "Replace",
- },
- },
- },
- })
- end,
- ["pyright"] = function()
- lspconfig["pyright"].setup({
- capabilities = capabilities,
- settings = {
- python = {
- pythonPath = "/usr/bin/python",
- },
- },
- })
- end,
- })
- end,
+ mason_lspconfig.setup_handlers({
+ -- default handler for installed servers
+ function(server_name)
+ lspconfig[server_name].setup({
+ capabilities = capabilities,
+ })
+ end,
+ ["svelte"] = function()
+ -- Configuration specific to svelte LSP server
+ lspconfig["svelte"].setup({
+ capabilities = capabilities,
+ on_attach = function(client, bufnr)
+ vim.api.nvim_create_autocmd("BufWritePost", {
+ pattern = { "*.js", "*.ts" },
+ callback = function(ctx)
+ -- Here use ctx.match instead of ctx.file
+ client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
+ end,
+ })
+ end,
+ })
+ end,
+ ["lua_ls"] = function()
+ lspconfig["lua_ls"].setup({
+ capabilities = capabilities,
+ settings = {
+ Lua = {
+ -- make the language server recognize the "vim" global variable
+ diagnostics = {
+ globals = { "vim" },
+ },
+ completion = {
+ callSnippet = "Replace",
+ },
+ },
+ },
+ })
+ end,
+ ["pyright"] = function()
+ lspconfig["pyright"].setup({
+ capabilities = capabilities,
+ settings = {
+ python = {
+ pythonPath = "/usr/bin/python",
+ },
+ },
+ })
+ end,
+ })
+ end,
}