mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
nvim: move out lsp on_attach
This commit is contained in:
parent
3352b3b6e6
commit
65f5e1107b
2 changed files with 40 additions and 32 deletions
|
|
@ -1,5 +1,4 @@
|
|||
local map = vim.keymap.set
|
||||
local methods = vim.lsp.protocol.Methods
|
||||
|
||||
----------------------
|
||||
-- Language servers --
|
||||
|
|
@ -76,32 +75,6 @@ local servers = {
|
|||
-------------
|
||||
-- Helpers --
|
||||
-------------
|
||||
local on_attach = function(client, bufnr)
|
||||
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr })
|
||||
local telescope = require("telescope.builtin")
|
||||
|
||||
map("n", "K", vim.lsp.buf.hover, { buffer = bufnr })
|
||||
map("n", "<C-k>", vim.lsp.buf.signature_help, { buffer = bufnr })
|
||||
map("n", "gd", telescope.lsp_definitions, { buffer = bufnr })
|
||||
-- conflicts with tabs
|
||||
-- map("n", "gtd", vim.lsp.buf.type_definition, { buffer = bufnr })
|
||||
-- map("n", "gi", vim.lsp.buf.implementation, { buffer = bufnr })
|
||||
map("n", "gu", telescope.lsp_references, { buffer = bufnr })
|
||||
map("n", "<leader>ca", vim.lsp.buf.code_action, { buffer = bufnr })
|
||||
map("n", "<leader>cl", vim.lsp.codelens.run, { buffer = bufnr })
|
||||
map("n", "<leader>r", vim.lsp.buf.rename, { buffer = bufnr })
|
||||
map("n", "<leader>f", function() vim.lsp.buf.format { async = true } end, { buffer = bufnr })
|
||||
|
||||
local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
|
||||
if
|
||||
client:supports_method(methods.textDocument_inlayHint)
|
||||
-- Never start cabal with inlay hint request
|
||||
-- Related: https://github.com/mrcjkb/haskell-tools.nvim/discussions/485
|
||||
and filetype ~= "cabal"
|
||||
then
|
||||
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
|
||||
end
|
||||
end
|
||||
|
||||
-- Helix style border
|
||||
local border = {
|
||||
|
|
@ -142,6 +115,9 @@ capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
|||
----------
|
||||
require("fidget").setup()
|
||||
|
||||
|
||||
local mylsp = require('lsp')
|
||||
|
||||
for name, config in pairs(servers) do
|
||||
require("lspconfig")[name].setup {
|
||||
capabilities = capabilities,
|
||||
|
|
@ -149,7 +125,7 @@ for name, config in pairs(servers) do
|
|||
-- NOTE: https://github.com/neovim/neovim/issues/30675
|
||||
offset_encoding = config.offset_encoding or "utf-8",
|
||||
on_attach = function(client, bufno)
|
||||
on_attach(client, bufno);
|
||||
mylsp.on_attach(client, bufno);
|
||||
(config.on_attach or function(...) end)(client, bufno)
|
||||
end,
|
||||
}
|
||||
|
|
@ -160,7 +136,7 @@ end
|
|||
------------------------
|
||||
-- Java
|
||||
local config = {
|
||||
on_attach = on_attach,
|
||||
on_attach = mylsp.on_attach,
|
||||
capabilities = capabilities,
|
||||
cmd = {
|
||||
-- https://github.com/NixOS/nixpkgs/issues/232822#issuecomment-1564243667
|
||||
|
|
@ -212,7 +188,7 @@ metals_config.on_attach = function(client, bufnr)
|
|||
map("n", "<leader>dsi", require("dap").step_into)
|
||||
map("n", "<leader>dl", require("dap").run_last)
|
||||
|
||||
on_attach(client, bufnr)
|
||||
mylsp.on_attach(client, bufnr)
|
||||
end
|
||||
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
|
|
@ -240,7 +216,7 @@ vim.g.haskell_tools = {
|
|||
map("n", "<leader>hhr", ht.repl.toggle, opts)
|
||||
|
||||
vim.opt_local.shiftwidth = 2
|
||||
on_attach(client, bufnr)
|
||||
mylsp.on_attach(client, bufnr)
|
||||
end,
|
||||
default_settings = {
|
||||
haskell = {
|
||||
|
|
@ -267,7 +243,7 @@ vim.g.haskell_tools = {
|
|||
----------
|
||||
vim.g.rustaceanvim = {
|
||||
server = {
|
||||
on_attach = on_attach,
|
||||
on_attach = mylsp.on_attach,
|
||||
settings = {
|
||||
["rust-analyzer"] = { files = { excludeDirs = { ".direnv/" } } },
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue