mirror of
https://github.com/zoriya/flake.git
synced 2026-06-02 10:45:59 +00:00
Add lsp bindings
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
"leap.nvim": { "branch": "main", "commit": "9a69febb2e5a4f5f5a55dd2d7173098fde917bc5" },
|
||||
"lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" },
|
||||
"neo-tree.nvim": { "branch": "v2.x", "commit": "74040b34278910d9b467fd914862e2a9a1ebacaa" },
|
||||
"neodev.nvim": { "branch": "main", "commit": "6d362921d772963e5a5e5ed0fcf82153defaf206" },
|
||||
"neodim": { "branch": "master", "commit": "c346344ade2ce709e6bd282f10e43778672b861e" },
|
||||
"noice.nvim": { "branch": "main", "commit": "d8a1f3056ad713b5d471048f8d029264828e22c0" },
|
||||
"nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" },
|
||||
"nvim-colorizer.lua": { "branch": "master", "commit": "550332c5791c6cad6fc7a80c26104de1d00b4692" },
|
||||
|
||||
@@ -1,209 +1,131 @@
|
||||
local old = {
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
{ "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } },
|
||||
"mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
---@class PluginLspOpts
|
||||
opts = {
|
||||
-- options for vim.diagnostic.config()
|
||||
diagnostics = {
|
||||
underline = true,
|
||||
update_in_insert = true,
|
||||
virtual_text = false,
|
||||
severity_sort = true,
|
||||
},
|
||||
-- Automatically format on save
|
||||
autoformat = false,
|
||||
-- options for vim.lsp.buf.format
|
||||
-- `bufnr` and `filter` is handled by the LazyVim formatter,
|
||||
-- but can be also overridden when specified
|
||||
format = {
|
||||
formatting_options = nil,
|
||||
timeout_ms = nil,
|
||||
},
|
||||
-- LSP Server Settings
|
||||
---@type lspconfig.options
|
||||
servers = {
|
||||
jsonls = {},
|
||||
|
||||
lua_ls = {
|
||||
-- mason = false, -- set to false if you don't want this server to be installed with mason
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- omnisharp = {
|
||||
-- handlers = {
|
||||
-- ["textDocument/definition"] = require('omnisharp_extended').handler,
|
||||
-- },
|
||||
-- cmd_env = {
|
||||
-- ["OMNISHARP_FormattingOptions:EnableEditorConfigSupport"] = true,
|
||||
-- ["OMNISHARP_RoslynExtensionsOptions:enableAnalyzersSupport"] = true,
|
||||
-- ["OMNISHARP_RoslynExtensionsOptions:enableImportCompletion"] = true,
|
||||
-- ["OMNISHARP_RoslynExtensionsOptions:enableDecompilationSupport"] = true,
|
||||
-- ["OMNISHARP_msbuild:EnablePackageAutoRestore"] = true,
|
||||
-- },
|
||||
-- },
|
||||
|
||||
robotframework_ls = {
|
||||
settings = {
|
||||
robot = {
|
||||
codeFormatter = "robotidy",
|
||||
variables = {
|
||||
RESOURCES = vim.fn.getcwd() .. "/tests/robot/",
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
-- you can do any additional lsp server setup here
|
||||
-- return true if you don't want this server to be setup with lspconfig
|
||||
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
|
||||
setup = {
|
||||
-- example to setup with typescript.nvim
|
||||
-- tsserver = function(_, opts)
|
||||
-- require("typescript").setup({ server = opts })
|
||||
-- return true
|
||||
-- end,
|
||||
-- Specify * to use this function as a fallback for any server
|
||||
-- ["*"] = function(server, opts) end,
|
||||
},
|
||||
},
|
||||
---@param opts PluginLspOpts
|
||||
config = function(plugin, opts)
|
||||
-- setup formatting and keymaps
|
||||
require("lazyvim.util").on_attach(function(client, buffer)
|
||||
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
|
||||
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
|
||||
end)
|
||||
|
||||
-- diagnostics
|
||||
for name, icon in pairs(require("lazyvim.config").icons.diagnostics) do
|
||||
name = "DiagnosticSign" .. name
|
||||
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
|
||||
end
|
||||
vim.diagnostic.config(opts.diagnostics)
|
||||
|
||||
local servers = opts.servers
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
|
||||
local function setup(server)
|
||||
local server_opts = vim.tbl_deep_extend("force", {
|
||||
capabilities = vim.deepcopy(capabilities),
|
||||
}, servers[server] or {})
|
||||
|
||||
if opts.setup[server] then
|
||||
if opts.setup[server](server, server_opts) then
|
||||
return
|
||||
end
|
||||
elseif opts.setup["*"] then
|
||||
if opts.setup["*"](server, server_opts) then
|
||||
return
|
||||
end
|
||||
end
|
||||
require("lspconfig")[server].setup(server_opts)
|
||||
end
|
||||
|
||||
-- temp fix for lspconfig rename
|
||||
-- https://github.com/neovim/nvim-lspconfig/pull/2439
|
||||
local mappings = require("mason-lspconfig.mappings.server")
|
||||
if not mappings.lspconfig_to_package.lua_ls then
|
||||
mappings.lspconfig_to_package.lua_ls = "lua-language-server"
|
||||
mappings.package_to_lspconfig["lua-language-server"] = "lua_ls"
|
||||
end
|
||||
|
||||
local mlsp = require("mason-lspconfig")
|
||||
local available = mlsp.get_available_servers()
|
||||
|
||||
local ensure_installed = {} ---@type string[]
|
||||
for server, server_opts in pairs(servers) do
|
||||
if server_opts then
|
||||
server_opts = server_opts == true and {} or server_opts
|
||||
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
||||
if server_opts.mason == false or not vim.tbl_contains(available, server) then
|
||||
setup(server)
|
||||
else
|
||||
ensure_installed[#ensure_installed + 1] = server
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require("mason-lspconfig").setup({ ensure_installed = ensure_installed })
|
||||
require("mason-lspconfig").setup_handlers({ setup })
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = { "mason.nvim" },
|
||||
opts = function()
|
||||
local nls = require("null-ls")
|
||||
local sources = {
|
||||
nl.builtins.code_actions.eslint_d,
|
||||
nl.builtins.diagnostics.eslint_d,
|
||||
nl.builtins.formatting.eslint_d,
|
||||
nl.builtins.formatting.prettierd,
|
||||
nl.builtins.formatting.black,
|
||||
}
|
||||
return {
|
||||
sources = vim.tbl_map(function(source)
|
||||
return source.with({
|
||||
diagnostics_postprocess = function(diagnostic)
|
||||
diagnostic.severity = vim.diagnostic.severity.HINT
|
||||
end,
|
||||
})
|
||||
end, sources),
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
"williamboman/mason.nvim",
|
||||
cmd = "Mason",
|
||||
keys = { { "<leader>li", "<cmd>Mason<cr>", desc = "Mason" } },
|
||||
opts = {
|
||||
ensure_installed = { },
|
||||
},
|
||||
---@param opts MasonSettings | {ensure_installed: string[]}
|
||||
config = function(plugin, opts)
|
||||
require("mason").setup(opts)
|
||||
local mr = require("mason-registry")
|
||||
for _, tool in ipairs(opts.ensure_installed) do
|
||||
local p = mr.get_package(tool)
|
||||
if not p:is_installed() then
|
||||
p:install()
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
local nullls = {
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = { "mason.nvim" },
|
||||
opts = function()
|
||||
local nls = require("null-ls")
|
||||
local sources = {
|
||||
nl.builtins.code_actions.eslint_d,
|
||||
nl.builtins.diagnostics.eslint_d,
|
||||
nl.builtins.formatting.eslint_d,
|
||||
nl.builtins.formatting.prettierd,
|
||||
nl.builtins.formatting.black,
|
||||
}
|
||||
return {
|
||||
sources = vim.tbl_map(function(source)
|
||||
return source.with({
|
||||
diagnostics_postprocess = function(diagnostic)
|
||||
diagnostic.severity = vim.diagnostic.severity.HINT
|
||||
end,
|
||||
})
|
||||
end, sources),
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
local lsp_keymaps = function(buffer)
|
||||
local function map(mode, l, r, desc)
|
||||
vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc })
|
||||
end
|
||||
|
||||
map("n", "K", '<cmd>lua vim.lsp.buf.hover()<CR>', "See informations")
|
||||
map("n", "<C-k>", '<cmd>lua vim.lsp.buf.signature_help()<CR>', "See signature help")
|
||||
|
||||
map("n", "gD", '<cmd>lua vim.lsp.buf.declaration()<CR>', "Go to declaration")
|
||||
map("n", "gd", '<cmd>lua vim.lsp.buf.definition()<CR>', "Go to definition")
|
||||
map("n", "gI", '<cmd>lua vim.lsp.buf.implementation()<CR>', "Go to implementation")
|
||||
map("n", "gr", '<cmd>lua vim.lsp.buf.references()<CR>', "Go to reference(s)")
|
||||
map("n", "gs", '<cmd>lua vim.lsp.buf.type_definition()<CR>', "Type definition")
|
||||
|
||||
map("n", "<leader>lr", '<cmd>lua vim.lsp.buf.rename()<CR>', "Rename")
|
||||
map("n", "<leader>la", '<cmd>lua vim.lsp.buf.code_action()<CR>', "Code action")
|
||||
map("n", "<leader>ll", '<cmd>lua vim.lsp.codelens.run()<CR>', "Run code lens")
|
||||
map("n", "<leader>lg", '<cmd>Telescope lsp_document_symbols<CR>', "Go to symbol")
|
||||
map("n", "<leader>lf", '<cmd>lua vim.lsp.buf.format({async=true})<CR>', "Format")
|
||||
|
||||
map("v", "<leader>lf", '<cmd>lua vim.lsp.buf.format({async=true})<CR>', "Range Format")
|
||||
end
|
||||
|
||||
|
||||
return {
|
||||
{
|
||||
"dundalek/lazy-lsp.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"neovim/nvim-lspconfig"
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
{ "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
opts = {
|
||||
excluded_servers = { "efm", "diagnosticls" },
|
||||
excluded_servers = {
|
||||
-- Disable generic purpose LSP that I don't care about.
|
||||
"efm",
|
||||
"diagnosticls"
|
||||
},
|
||||
default_config = {
|
||||
on_attach = function(client, buffer)
|
||||
lsp_keymaps(buffer)
|
||||
|
||||
local ok, navic = pcall(require, "nvim-navic")
|
||||
if ok then
|
||||
navic.attach(client, buffer)
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
init = function()
|
||||
local signs = {
|
||||
{ name = "DiagnosticSignError", text = "" },
|
||||
{ name = "DiagnosticSignWarn", text = "" },
|
||||
{ name = "DiagnosticSignHint", text = "" },
|
||||
{ name = "DiagnosticSignInfo", text = "" },
|
||||
}
|
||||
for _, sign in ipairs(signs) do
|
||||
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
|
||||
end
|
||||
|
||||
local function map(l, r, desc)
|
||||
vim.keymap.set("n", l, r, { desc = desc })
|
||||
end
|
||||
map("[d", '<cmd>lua vim.diagnostic.goto_prev()<CR>', "Prev diagnostic")
|
||||
map("]d", '<cmd>lua vim.diagnostic.goto_next()<CR>', "Next diagnostic")
|
||||
map("gl", "<cmd>lua vim.diagnostic.open_float()<CR>", "See diagnostics")
|
||||
map("<leader>li", "<cmd>LspInfo<cr>", "Info")
|
||||
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = false,
|
||||
update_in_insert = true,
|
||||
float = {
|
||||
border = "rounded",
|
||||
source = "always",
|
||||
},
|
||||
})
|
||||
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||
border = "rounded",
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"zbirenbaum/neodim",
|
||||
event = "LspAttach",
|
||||
opts = {
|
||||
alpha = 0.75,
|
||||
blend_color = "#000000",
|
||||
update_in_insert = {
|
||||
enable = true,
|
||||
delay = 100,
|
||||
},
|
||||
hide = {
|
||||
virtual_text = true,
|
||||
signs = false,
|
||||
underline = true,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ return {
|
||||
noremap = false,
|
||||
})
|
||||
|
||||
-- TODO: Moves this to the settinsg.lua file and use the standard way
|
||||
wk.register({
|
||||
y = { "Yank to system clipboard" },
|
||||
Y = { "Yank line to system clipboard" },
|
||||
@@ -102,16 +103,13 @@ return {
|
||||
prefix = "<leader>",
|
||||
})
|
||||
|
||||
wk.register({
|
||||
["<leader>w"] = { "<cmd>ASToggle<cr>", "Toggle autosave" },
|
||||
})
|
||||
|
||||
wk.register({
|
||||
mode = { "n", "v" },
|
||||
["g"] = { name = "+goto" },
|
||||
["]"] = { name = "+next" },
|
||||
["["] = { name = "+prev" },
|
||||
["<leader>g"] = { name = "+git" },
|
||||
["<leader>l"] = { name = "+lsp" },
|
||||
})
|
||||
|
||||
local uwk = require("unimpaired-which-key")
|
||||
|
||||
Reference in New Issue
Block a user