Ported config from nixvim.
Made some changes to taste along the way, though there are some still to come.
This commit is contained in:
parent
9a78fd2d53
commit
3bd72ab98f
13 changed files with 601 additions and 740 deletions
|
|
@ -2,6 +2,47 @@ local catUtils = require('nixCatsUtils')
|
|||
if (catUtils.isNixCats and nixCats('lspDebugMode')) then
|
||||
vim.lsp.set_log_level("debug")
|
||||
end
|
||||
-- we create a function that lets us more easily define mappings specific
|
||||
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||
|
||||
local lspmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = 'LSP: ' .. desc
|
||||
end
|
||||
|
||||
-- all of our LSP keybindings will be namespaced under <leader>l
|
||||
keys = '<leader>l' .. keys
|
||||
|
||||
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
lspmap('r', vim.lsp.buf.rename, '[R]ename')
|
||||
lspmap('a', vim.lsp.buf.code_action, '[C]ode Action')
|
||||
|
||||
lspmap('d', vim.lsp.buf.definition, 'Goto [D]efinition')
|
||||
|
||||
-- NOTE: why are these functions that call the telescope builtin?
|
||||
-- because otherwise they would load telescope eagerly when this is defined.
|
||||
-- due to us using the on_require handler to make sure it is available.
|
||||
if nixCats('telescope') then
|
||||
lspmap('R', function() require('telescope.builtin').lsp_references() end, 'Goto [R]eferences')
|
||||
lspmap('I', function() require('telescope.builtin').lsp_implementations() end, 'Goto [I]mplementation')
|
||||
lspmap('s', function() require('telescope.builtin').lsp_document_symbols() end, 'Document [S]ymbols')
|
||||
lspmap('ws', function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, '[W]orkspace [S]ymbols')
|
||||
end -- TODO: Investigate whether I can replace these with snacsk.nvim.
|
||||
|
||||
lspmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
lspmap('h', vim.lsp.buf.hover, 'Hover Documentation')
|
||||
lspmap('s', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||
lspmap('f', vim.lsp.buf.format, 'Format buffer')
|
||||
|
||||
-- Lesser used LSP functionality
|
||||
lspmap('D', vim.lsp.buf.declaration, 'Goto [D]eclaration')
|
||||
lspmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||
lspmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||
lspmap('wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, '[W]orkspace [L]ist Folders')
|
||||
|
||||
-- NOTE: This file uses lzextras.lsp handler https://github.com/BirdeeHub/lzextras?tab=readme-ov-file#lsp-handler
|
||||
-- This is a slightly more performant fallback function
|
||||
|
|
@ -9,7 +50,8 @@ end
|
|||
-- nixCats gives us the paths, which is faster than searching the rtp!
|
||||
local old_ft_fallback = require('lze').h.lsp.get_ft_fallback()
|
||||
require('lze').h.lsp.set_ft_fallback(function(name)
|
||||
local lspcfg = nixCats.pawsible({ "allPlugins", "opt", "nvim-lspconfig" }) or nixCats.pawsible({ "allPlugins", "start", "nvim-lspconfig" })
|
||||
local lspcfg = nixCats.pawsible({ "allPlugins", "opt", "nvim-lspconfig" }) or
|
||||
nixCats.pawsible({ "allPlugins", "start", "nvim-lspconfig" })
|
||||
if lspcfg then
|
||||
local ok, cfg = pcall(dofile, lspcfg .. "/lsp/" .. name .. ".lua")
|
||||
if not ok then
|
||||
|
|
@ -23,7 +65,7 @@ end)
|
|||
require('lze').load {
|
||||
{
|
||||
"nvim-lspconfig",
|
||||
for_cat = "general.core",
|
||||
for_cat = "lsp",
|
||||
on_require = { "lspconfig" },
|
||||
-- NOTE: define a function for lsp,
|
||||
-- and it will run for all specs with type(plugin.lsp) == table
|
||||
|
|
@ -32,11 +74,6 @@ require('lze').load {
|
|||
vim.lsp.config(plugin.name, plugin.lsp or {})
|
||||
vim.lsp.enable(plugin.name)
|
||||
end,
|
||||
before = function(_)
|
||||
vim.lsp.config('*', {
|
||||
on_attach = require('myLuaConf.LSPs.on_attach'),
|
||||
})
|
||||
end,
|
||||
},
|
||||
{
|
||||
"mason.nvim",
|
||||
|
|
@ -54,7 +91,7 @@ require('lze').load {
|
|||
{
|
||||
-- lazydev makes your lsp way better in your config without needing extra lsp configuration.
|
||||
"lazydev.nvim",
|
||||
for_cat = "neonixdev",
|
||||
for_cat = "lua",
|
||||
cmd = { "LazyDev" },
|
||||
ft = "lua",
|
||||
after = function(_)
|
||||
|
|
@ -68,7 +105,7 @@ require('lze').load {
|
|||
{
|
||||
-- name of the lsp
|
||||
"lua_ls",
|
||||
enabled = nixCats('lua') or nixCats('neonixdev') or false,
|
||||
enabled = nixCats('lua'),
|
||||
-- provide a table containing filetypes,
|
||||
-- and then whatever your functions defined in the function type specs expect.
|
||||
-- in our case, it just expects the normal lspconfig setup options,
|
||||
|
|
@ -93,33 +130,9 @@ require('lze').load {
|
|||
},
|
||||
-- also these are regular specs and you can use before and after and all the other normal fields
|
||||
},
|
||||
{
|
||||
"gopls",
|
||||
for_cat = "go",
|
||||
-- if you don't provide the filetypes it asks lspconfig for them
|
||||
lsp = {
|
||||
filetypes = { "go", "gomod", "gowork", "gotmpl" },
|
||||
},
|
||||
},
|
||||
{
|
||||
"rnix",
|
||||
-- mason doesn't have nixd
|
||||
enabled = not catUtils.isNixCats,
|
||||
lsp = {
|
||||
filetypes = { "nix" },
|
||||
},
|
||||
},
|
||||
{
|
||||
"nil_ls",
|
||||
-- mason doesn't have nixd
|
||||
enabled = not catUtils.isNixCats,
|
||||
lsp = {
|
||||
filetypes = { "nix" },
|
||||
},
|
||||
},
|
||||
{
|
||||
"nixd",
|
||||
enabled = catUtils.isNixCats and (nixCats('nix') or nixCats('neonixdev')) or false,
|
||||
enabled = catUtils.isNixCats and nixCats('lsp.nix'),
|
||||
lsp = {
|
||||
filetypes = { "nix" },
|
||||
settings = {
|
||||
|
|
@ -132,7 +145,7 @@ require('lze').load {
|
|||
nixpkgs = {
|
||||
-- in the extras set of your package definition:
|
||||
-- nixdExtras.nixpkgs = ''import ${pkgs.path} {}''
|
||||
expr = nixCats.extra("nixdExtras.nixpkgs") or [[import <nixpkgs> {}]],
|
||||
expr = nixCats.extra("nixdExtras.nixpkgs")
|
||||
},
|
||||
options = {
|
||||
-- If you integrated with your system flake,
|
||||
|
|
@ -152,7 +165,7 @@ require('lze').load {
|
|||
}
|
||||
},
|
||||
formatting = {
|
||||
command = { "nixfmt" }
|
||||
command = { "alejandra" }
|
||||
},
|
||||
diagnostic = {
|
||||
suppress = {
|
||||
|
|
@ -163,4 +176,8 @@ require('lze').load {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"rustaceanvim",
|
||||
for_cat = "lsp.rust",
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
return function(_, bufnr)
|
||||
-- we create a function that lets us more easily define mappings specific
|
||||
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||
|
||||
local nmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = 'LSP: ' .. desc
|
||||
end
|
||||
|
||||
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||
|
||||
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||
|
||||
-- NOTE: why are these functions that call the telescope builtin?
|
||||
-- because otherwise they would load telescope eagerly when this is defined.
|
||||
-- due to us using the on_require handler to make sure it is available.
|
||||
if nixCats('general.telescope') then
|
||||
nmap('gr', function() require('telescope.builtin').lsp_references() end, '[G]oto [R]eferences')
|
||||
nmap('gI', function() require('telescope.builtin').lsp_implementations() end, '[G]oto [I]mplementation')
|
||||
nmap('<leader>ds', function() require('telescope.builtin').lsp_document_symbols() end, '[D]ocument [S]ymbols')
|
||||
nmap('<leader>ws', function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, '[W]orkspace [S]ymbols')
|
||||
end -- TODO: someone who knows the builtin versions of these to do instead help me out please.
|
||||
|
||||
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
|
||||
-- See `:help K` for why this keymap
|
||||
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
||||
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||
|
||||
-- Lesser used LSP functionality
|
||||
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||
nmap('<leader>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, '[W]orkspace [L]ist Folders')
|
||||
|
||||
-- Create a command `:Format` local to the LSP buffer
|
||||
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, { desc = 'Format current buffer with LSP' })
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue