mirror of
https://gitlab.com/Zaney/zaneyos.git
synced 2024-11-22 06:33:08 +01:00
Add mason, and all the lsp things needed
This commit is contained in:
parent
87ec96032a
commit
84c0f6d9ca
@ -1,43 +1,124 @@
|
||||
local on_attach = function(_, bufnr)
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
local bufmap = function(keys, func)
|
||||
vim.keymap.set('n', keys, func, { buffer = bufnr })
|
||||
end
|
||||
-- import mason_lspconfig plugin
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
||||
bufmap('<leader>r', vim.lsp.buf.rename)
|
||||
bufmap('<leader>a', vim.lsp.buf.code_action)
|
||||
-- import cmp-nvim-lsp plugin
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
bufmap('gd', vim.lsp.buf.definition)
|
||||
bufmap('gD', vim.lsp.buf.declaration)
|
||||
bufmap('gI', vim.lsp.buf.implementation)
|
||||
bufmap('<leader>D', vim.lsp.buf.type_definition)
|
||||
local keymap = vim.keymap -- for conciseness
|
||||
|
||||
bufmap('gr', require('telescope.builtin').lsp_references)
|
||||
bufmap('<leader>s', require('telescope.builtin').lsp_document_symbols)
|
||||
bufmap('<leader>S', require('telescope.builtin').lsp_dynamic_workspace_symbols)
|
||||
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 below functions
|
||||
local opts = { buffer = ev.buf, silent = true }
|
||||
|
||||
bufmap('K', vim.lsp.buf.hover)
|
||||
-- set keybinds
|
||||
opts.desc = "Show LSP references"
|
||||
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references
|
||||
|
||||
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, {})
|
||||
opts.desc = "Go to declaration"
|
||||
keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration
|
||||
|
||||
opts.desc = "Show LSP definitions"
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions
|
||||
|
||||
opts.desc = "Show LSP implementations"
|
||||
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations
|
||||
|
||||
opts.desc = "Show LSP type definitions"
|
||||
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions
|
||||
|
||||
opts.desc = "See available code actions"
|
||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
|
||||
|
||||
opts.desc = "Smart rename"
|
||||
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
|
||||
|
||||
opts.desc = "Show buffer diagnostics"
|
||||
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
|
||||
|
||||
opts.desc = "Show line diagnostics"
|
||||
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
|
||||
|
||||
opts.desc = "Go to previous diagnostic"
|
||||
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer
|
||||
|
||||
opts.desc = "Go to next diagnostic"
|
||||
keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer
|
||||
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
|
||||
|
||||
opts.desc = "Restart LSP"
|
||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
|
||||
end,
|
||||
})
|
||||
|
||||
-- used to enable autocompletion (assign to every lsp server config)
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
|
||||
-- Change the Diagnostic symbols in the sign column (gutter)
|
||||
-- (not in youtube nvim video)
|
||||
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
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
||||
|
||||
require('neodev').setup()
|
||||
require('lspconfig').lua_ls.setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
root_dir = function()
|
||||
return vim.loop.cwd()
|
||||
end,
|
||||
cmd = { "lua-lsp" },
|
||||
settings = {
|
||||
mason_lspconfig.setup_handlers({
|
||||
-- default handler for installed servers
|
||||
function(server_name)
|
||||
lspconfig[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
["svelte"] = function()
|
||||
-- configure svelte 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,
|
||||
["graphql"] = function()
|
||||
-- configure graphql language server
|
||||
lspconfig["graphql"].setup({
|
||||
capabilities = capabilities,
|
||||
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
|
||||
})
|
||||
end,
|
||||
["emmet_ls"] = function()
|
||||
-- configure emmet language server
|
||||
lspconfig["emmet_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||
})
|
||||
end,
|
||||
["lua_ls"] = function()
|
||||
-- configure lua server (with special settings)
|
||||
lspconfig["lua_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = { checkThirdParty = false },
|
||||
telemetry = { enable = false },
|
||||
-- make the language server recognize "vim" global
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
43
config/nvim/plugins/mason.lua
Normal file
43
config/nvim/plugins/mason.lua
Normal file
@ -0,0 +1,43 @@
|
||||
local mason = require("mason")
|
||||
|
||||
-- import mason-lspconfig
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
||||
-- enable mason and configure icons
|
||||
mason.setup({
|
||||
ui = {
|
||||
icons = {
|
||||
package_installed = "✓",
|
||||
package_pending = "➜",
|
||||
package_uninstalled = "✗",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
mason_lspconfig.setup({
|
||||
-- list of servers for mason to install
|
||||
ensure_installed = {
|
||||
"bashls",
|
||||
"docker",
|
||||
"docker_compose_language_service",
|
||||
"gopls",
|
||||
"jsonls",
|
||||
"markdown_oxide",
|
||||
"taplo",
|
||||
"tailwindcss",
|
||||
"yamlls",
|
||||
"nil_ls",
|
||||
"rust_analyzer",
|
||||
"sqlls",
|
||||
"tsserver",
|
||||
"html",
|
||||
"cssls",
|
||||
"tailwindcss",
|
||||
"svelte",
|
||||
"lua_ls",
|
||||
"graphql",
|
||||
"emmet_ls",
|
||||
"prismals",
|
||||
"pyright",
|
||||
},
|
||||
})
|
@ -194,6 +194,8 @@ in
|
||||
nvim-web-devicons
|
||||
nvim-cmp
|
||||
nvim-surround
|
||||
nvim-lspconfig
|
||||
cmp-nvim-lsp
|
||||
cmp-buffer
|
||||
luasnip
|
||||
cmp_luasnip
|
||||
@ -213,6 +215,8 @@ in
|
||||
nvim-tree-lua
|
||||
telescope-fzf-native-nvim
|
||||
vim-tmux-navigator
|
||||
mason-nvim
|
||||
mason-lspconfig-nvim
|
||||
];
|
||||
extraLuaConfig = ''
|
||||
${builtins.readFile ../../config/nvim/options.lua}
|
||||
@ -222,6 +226,7 @@ in
|
||||
${builtins.readFile ../../config/nvim/plugins/auto-session.lua}
|
||||
${builtins.readFile ../../config/nvim/plugins/comment.lua}
|
||||
${builtins.readFile ../../config/nvim/plugins/cmp.lua}
|
||||
${builtins.readFile ../../config/nvim/plugins/lsp.lua}
|
||||
${builtins.readFile ../../config/nvim/plugins/nvim-tree.lua}
|
||||
${builtins.readFile ../../config/nvim/plugins/telescope.lua}
|
||||
${builtins.readFile ../../config/nvim/plugins/todo-comments.lua}
|
||||
|
Loading…
Reference in New Issue
Block a user