125 lines
3.6 KiB
Lua
125 lines
3.6 KiB
Lua
return {
|
|
"neovim/nvim-lspconfig",
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
dependencies = {
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
{ "antosha417/nvim-lsp-file-operations", config = true },
|
|
{ "folke/neodev.nvim", opts = {} },
|
|
{ "j-hui/fidget.nvim", tag = "legacy" },
|
|
"RobertBrunhage/dart-tools.nvim",
|
|
},
|
|
config = function()
|
|
local lspconfig = require("lspconfig")
|
|
local mason_lspconfig = require("mason-lspconfig")
|
|
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
|
|
|
local keymap = vim.keymap -- for conciseness
|
|
|
|
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 }
|
|
|
|
-- set keybinds
|
|
opts.desc = "Go to declaration"
|
|
keymap.set("n", "gD", "<cmd>vim.lsp.buf.declaration()<cr>", opts) -- go to declaration
|
|
|
|
opts.desc = "Show LSP definitions"
|
|
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions
|
|
|
|
opts.desc = "Smart rename"
|
|
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
|
|
|
|
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)
|
|
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,
|
|
|
|
["lua_ls"] = function()
|
|
-- configure lua server (with special settings)
|
|
lspconfig["lua_ls"].setup({
|
|
capabilities = capabilities,
|
|
settings = {
|
|
Lua = {
|
|
-- make the language server recognize "vim" global
|
|
diagnostics = {
|
|
globals = { "vim" },
|
|
},
|
|
completion = {
|
|
callSnippet = "Replace",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
end,
|
|
})
|
|
|
|
-- lspconfig["dcmls"].setup({
|
|
-- capabilities = capabilities,
|
|
-- cmd = {
|
|
-- "dcm",
|
|
-- "start-server",
|
|
-- },
|
|
-- filetypes = { "dart", "yaml" },
|
|
-- })
|
|
|
|
-- lspconfig["dartls"].setup({
|
|
-- capabilities = capabilities,
|
|
-- cmd = {
|
|
-- "dart",
|
|
-- "language-server",
|
|
-- "--protocol=lsp",
|
|
-- -- "--port=8123",
|
|
-- -- "--instrumentation-log-file=/Users/robertbrunhage/Desktop/lsp-log.txt",
|
|
-- },
|
|
-- filetypes = { "dart" },
|
|
-- init_options = {
|
|
-- onlyAnalyzeProjectsWithOpenFiles = false,
|
|
-- suggestFromUnimportedLibraries = true,
|
|
-- closingLabels = true,
|
|
-- outline = false,
|
|
-- flutterOutline = false,
|
|
-- },
|
|
-- settings = {
|
|
-- dart = {
|
|
-- updateImportsOnRename = true,
|
|
-- completeFunctionCalls = true,
|
|
-- showTodos = true,
|
|
-- },
|
|
-- },
|
|
-- })
|
|
|
|
-- Tooltip for the lsp in bottom right
|
|
require("fidget").setup({})
|
|
|
|
-- Hot reload :)
|
|
require("dart-tools")
|
|
|
|
-- Globally configure all LSP floating preview popups (like hover, signature help, etc)
|
|
local open_floating_preview = vim.lsp.util.open_floating_preview
|
|
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
|
opts = opts or {}
|
|
opts.border = opts.border or "rounded"-- Set border to rounded
|
|
return open_floating_preview(contents, syntax, opts, ...)
|
|
end
|
|
end,
|
|
}
|