2024-04-14 23:36:23 -04:00
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
desc = 'LSP actions',
|
|
|
|
callback = function(event)
|
|
|
|
local bufmap = function(mode, lhs, rhs)
|
|
|
|
local opts = {buffer = event.buf}
|
|
|
|
vim.keymap.set(mode, lhs, rhs, opts)
|
|
|
|
end
|
|
|
|
|
2024-09-05 13:12:55 -04:00
|
|
|
local map = function(keys, func, desc)
|
|
|
|
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
|
|
|
|
end
|
|
|
|
-- Jump to the definition of the word under your cursor.
|
|
|
|
-- This is where a variable was first declared, or where a function is defined, etc.
|
|
|
|
-- To jump back, press <C-t>.
|
|
|
|
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
|
|
|
|
|
|
|
|
-- Find references for the word under your cursor.
|
|
|
|
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
|
|
|
|
|
|
|
-- Jump to the implementation of the word under your cursor.
|
|
|
|
-- Useful when your language has ways of declaring types without an actual implementation.
|
|
|
|
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
|
|
|
|
|
|
|
|
-- Jump to the type of the word under your cursor.
|
|
|
|
-- Useful when you're not sure what type a variable is and you want to see
|
|
|
|
-- the definition of its *type*, not where it was *defined*.
|
|
|
|
map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
|
|
|
|
|
|
|
|
-- Fuzzy find all the symbols in your current document.
|
|
|
|
-- Symbols are things like variables, functions, types, etc.
|
|
|
|
map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
|
|
|
|
|
|
|
-- Fuzzy find all the symbols in your current workspace.
|
|
|
|
-- Similar to document symbols, except searches over your entire project.
|
|
|
|
map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
|
|
|
|
|
|
|
-- Rename the variable under your cursor.
|
|
|
|
-- Most Language Servers support renaming across files, etc.
|
|
|
|
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
|
|
|
|
|
|
|
-- Execute a code action, usually your cursor needs to be on top of an error
|
|
|
|
-- or a suggestion from your LSP for this to activate.
|
|
|
|
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
|
|
|
|
|
|
|
-- WARN: This is not Goto Definition, this is Goto Declaration.
|
|
|
|
-- For example, in C this would take you to the header.
|
|
|
|
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
2024-09-21 08:48:35 -04:00
|
|
|
|
|
|
|
-- Add the ability to toggle between source and header files, but only for the
|
|
|
|
-- clangd clients
|
|
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
|
|
if (client.name == "clangd") then
|
|
|
|
map('th', ":ClangdSwitchSourceHeader<CR>", '[T]oggle [H]eader' )
|
|
|
|
end
|
2024-04-14 23:36:23 -04:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
2024-02-04 20:53:56 -05:00
|
|
|
|
|
|
|
require('mason').setup({})
|
|
|
|
require('mason-lspconfig').setup({
|
2024-09-05 13:12:55 -04:00
|
|
|
ensure_installed = {'lua_ls', 'pyright', 'rust_analyzer', 'clangd', 'tsserver', },
|
2024-02-04 20:53:56 -05:00
|
|
|
handlers = {
|
2024-04-14 23:36:23 -04:00
|
|
|
require('lspconfig').clangd.setup({
|
|
|
|
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto","hpp"},
|
|
|
|
capabilities = capabilities,
|
|
|
|
}),
|
2024-09-05 13:12:55 -04:00
|
|
|
require('lspconfig').tsserver.setup({
|
|
|
|
init_options = {
|
|
|
|
plugins = {
|
|
|
|
{
|
|
|
|
name = "@vue/typescript-plugin",
|
|
|
|
location = "/usr/local/lib/node_modules/@vue/typescript-plugin",
|
|
|
|
languages = { "vue" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx", "vue"},
|
|
|
|
capabilities = capabilities,
|
2024-10-08 16:06:31 -04:00
|
|
|
on_attach = function(client)
|
|
|
|
client.server_capabilities.document_formatting = false
|
|
|
|
end,
|
|
|
|
}),
|
|
|
|
require('lspconfig').volar.setup({
|
|
|
|
on_attach = function(client)
|
|
|
|
client.server_capabilities.document_formatting = false
|
|
|
|
end,
|
2024-09-05 13:12:55 -04:00
|
|
|
}),
|
2024-04-14 23:36:23 -04:00
|
|
|
require('lspconfig').rust_analyzer.setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
cmd = {
|
|
|
|
"rustup", "run", "stable", "rust-analyzer",
|
|
|
|
}
|
|
|
|
|
|
|
|
}),
|
2024-06-21 10:40:59 -04:00
|
|
|
require('lspconfig').pyright.setup{
|
2024-04-14 23:36:23 -04:00
|
|
|
capabilities = capabilities,
|
|
|
|
},
|
2024-06-21 10:40:59 -04:00
|
|
|
-- require('lspconfig').jedi_language_server.setup{
|
|
|
|
-- capabilities = capabilities,
|
|
|
|
-- },
|
2024-04-14 23:36:23 -04:00
|
|
|
require('lspconfig').lua_ls.setup{
|
|
|
|
capabilities = capabilities,
|
2024-10-12 16:32:33 -04:00
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
workspace = {
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = {
|
|
|
|
"vim",
|
|
|
|
"require",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
telemety = {
|
|
|
|
enable = false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2024-04-14 23:36:23 -04:00
|
|
|
},
|
|
|
|
},
|
2024-02-04 20:53:56 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|