mirror of
https://github.com/zoriya/flake.git
synced 2026-06-07 12:25:59 +00:00
Add lsp bindings
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
"leap.nvim": { "branch": "main", "commit": "9a69febb2e5a4f5f5a55dd2d7173098fde917bc5" },
|
"leap.nvim": { "branch": "main", "commit": "9a69febb2e5a4f5f5a55dd2d7173098fde917bc5" },
|
||||||
"lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" },
|
"lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" },
|
||||||
"neo-tree.nvim": { "branch": "v2.x", "commit": "74040b34278910d9b467fd914862e2a9a1ebacaa" },
|
"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" },
|
"noice.nvim": { "branch": "main", "commit": "d8a1f3056ad713b5d471048f8d029264828e22c0" },
|
||||||
"nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" },
|
"nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" },
|
||||||
"nvim-colorizer.lua": { "branch": "master", "commit": "550332c5791c6cad6fc7a80c26104de1d00b4692" },
|
"nvim-colorizer.lua": { "branch": "master", "commit": "550332c5791c6cad6fc7a80c26104de1d00b4692" },
|
||||||
|
|||||||
@@ -1,209 +1,131 @@
|
|||||||
local old = {
|
local nullls = {
|
||||||
{
|
"jose-elias-alvarez/null-ls.nvim",
|
||||||
"neovim/nvim-lspconfig",
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
dependencies = { "mason.nvim" },
|
||||||
dependencies = {
|
opts = function()
|
||||||
{ "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } },
|
local nls = require("null-ls")
|
||||||
"mason.nvim",
|
local sources = {
|
||||||
"williamboman/mason-lspconfig.nvim",
|
nl.builtins.code_actions.eslint_d,
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
nl.builtins.diagnostics.eslint_d,
|
||||||
},
|
nl.builtins.formatting.eslint_d,
|
||||||
---@class PluginLspOpts
|
nl.builtins.formatting.prettierd,
|
||||||
opts = {
|
nl.builtins.formatting.black,
|
||||||
-- options for vim.diagnostic.config()
|
}
|
||||||
diagnostics = {
|
return {
|
||||||
underline = true,
|
sources = vim.tbl_map(function(source)
|
||||||
update_in_insert = true,
|
return source.with({
|
||||||
virtual_text = false,
|
diagnostics_postprocess = function(diagnostic)
|
||||||
severity_sort = true,
|
diagnostic.severity = vim.diagnostic.severity.HINT
|
||||||
},
|
end,
|
||||||
-- Automatically format on save
|
})
|
||||||
autoformat = false,
|
end, sources),
|
||||||
-- options for vim.lsp.buf.format
|
}
|
||||||
-- `bufnr` and `filter` is handled by the LazyVim formatter,
|
end,
|
||||||
-- 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 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 {
|
return {
|
||||||
{
|
{
|
||||||
"dundalek/lazy-lsp.nvim",
|
"dundalek/lazy-lsp.nvim",
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"neovim/nvim-lspconfig"
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
dependencies = {
|
||||||
|
{ "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
opts = {
|
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,
|
noremap = false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- TODO: Moves this to the settinsg.lua file and use the standard way
|
||||||
wk.register({
|
wk.register({
|
||||||
y = { "Yank to system clipboard" },
|
y = { "Yank to system clipboard" },
|
||||||
Y = { "Yank line to system clipboard" },
|
Y = { "Yank line to system clipboard" },
|
||||||
@@ -102,16 +103,13 @@ return {
|
|||||||
prefix = "<leader>",
|
prefix = "<leader>",
|
||||||
})
|
})
|
||||||
|
|
||||||
wk.register({
|
|
||||||
["<leader>w"] = { "<cmd>ASToggle<cr>", "Toggle autosave" },
|
|
||||||
})
|
|
||||||
|
|
||||||
wk.register({
|
wk.register({
|
||||||
mode = { "n", "v" },
|
mode = { "n", "v" },
|
||||||
["g"] = { name = "+goto" },
|
["g"] = { name = "+goto" },
|
||||||
["]"] = { name = "+next" },
|
["]"] = { name = "+next" },
|
||||||
["["] = { name = "+prev" },
|
["["] = { name = "+prev" },
|
||||||
["<leader>g"] = { name = "+git" },
|
["<leader>g"] = { name = "+git" },
|
||||||
|
["<leader>l"] = { name = "+lsp" },
|
||||||
})
|
})
|
||||||
|
|
||||||
local uwk = require("unimpaired-which-key")
|
local uwk = require("unimpaired-which-key")
|
||||||
|
|||||||
Reference in New Issue
Block a user