forked from foxora/nix
init
This commit is contained in:
commit
a07bd5fd9b
66 changed files with 6115 additions and 0 deletions
59
homes/modules/programs/neovim/lua/lsp/capabilities.lua
Normal file
59
homes/modules/programs/neovim/lua/lsp/capabilities.lua
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
local M = {}
|
||||
|
||||
function M.on_attach(_, 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')
|
||||
nmap('<leader>dd', "<cmd>Telescope diagnostics bufnr=0<CR>", '[D]ocument [D]iagnostics')
|
||||
nmap('<leader>wd', "<cmd>Telescope diagnostics<CR>", '[W]orkspace [D]iagnostics')
|
||||
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')
|
||||
nmap('<leader>e', vim.diagnostic.open_float, 'Show [E]rror')
|
||||
|
||||
-- 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
|
||||
|
||||
function M.get(server_name)
|
||||
local capabilities = require('blink.cmp').get_lsp_capabilities()
|
||||
|
||||
return capabilities
|
||||
end
|
||||
return M
|
||||
88
homes/modules/programs/neovim/lua/lsp/completion.lua
Normal file
88
homes/modules/programs/neovim/lua/lsp/completion.lua
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
return {
|
||||
{
|
||||
"friendly-snippets",
|
||||
dep_of = { "blink.cmp" },
|
||||
},
|
||||
{
|
||||
"blink.cmp",
|
||||
event = { "InsertEnter", "CmdlineEnter" },
|
||||
on_require = "blink",
|
||||
load = function (name)
|
||||
vim.cmd.packadd(name)
|
||||
end,
|
||||
after = function(plugin)
|
||||
local blink = require('blink.cmp')
|
||||
|
||||
blink.setup({
|
||||
keymap = {
|
||||
preset = 'default',
|
||||
},
|
||||
|
||||
appearance = {
|
||||
nerd_font_variant = 'mono',
|
||||
},
|
||||
|
||||
sources = {
|
||||
default = { 'lsp', 'path', 'snippets', 'buffer' },
|
||||
providers = {
|
||||
lsp = {
|
||||
name = 'LSP',
|
||||
module = 'blink.cmp.sources.lsp',
|
||||
enabled = true,
|
||||
},
|
||||
path = {
|
||||
name = 'Path',
|
||||
module = 'blink.cmp.sources.path',
|
||||
enabled = true,
|
||||
},
|
||||
snippets = {
|
||||
name = 'Snippets',
|
||||
module = 'blink.cmp.sources.snippets',
|
||||
enabled = true,
|
||||
},
|
||||
buffer = {
|
||||
name = 'Buffer',
|
||||
module = 'blink.cmp.sources.buffer',
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
completion = {
|
||||
accept = {
|
||||
auto_brackets = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
|
||||
menu = {
|
||||
border = 'rounded',
|
||||
max_height = 12,
|
||||
scrolloff = 2,
|
||||
|
||||
draw = {
|
||||
columns = {
|
||||
{ "kind_icon", gap = 1, },
|
||||
{ "label", "label_description", gap = 1, },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
documentation = {
|
||||
auto_show = false,
|
||||
window = {
|
||||
border = 'rounded',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
signature = {
|
||||
enabled = true,
|
||||
window = {
|
||||
border = 'rounded',
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
},
|
||||
}
|
||||
203
homes/modules/programs/neovim/lua/lsp/completion.lua.old
Normal file
203
homes/modules/programs/neovim/lua/lsp/completion.lua.old
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
---packadd + after/plugin
|
||||
---@type fun(names: string[]|string)
|
||||
local load_w_after_plugin = require('nixCatsUtils.lzUtils').make_load_with_after({ "plugin" })
|
||||
|
||||
-- NOTE: packadd doesnt load after directories.
|
||||
-- hence, the above function that you can get from luaUtils that exists to make that easy.
|
||||
|
||||
return {
|
||||
{
|
||||
"cmp-buffer",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp-cmdline",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp-cmdline-history",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp-nvim-lsp",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
dep_of = { "nvim-lspconfig" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp-nvim-lsp-signature-help",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp-nvim-lua",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp-path",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"cmp_luasnip",
|
||||
on_plugin = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"friendly-snippets",
|
||||
dep_of = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"lspkind.nvim",
|
||||
dep_of = { "nvim-cmp" },
|
||||
load = load_w_after_plugin,
|
||||
},
|
||||
{
|
||||
"luasnip",
|
||||
dep_of = { "nvim-cmp" },
|
||||
after = function (plugin)
|
||||
local luasnip = require 'luasnip'
|
||||
require('luasnip.loaders.from_vscode').lazy_load()
|
||||
luasnip.config.setup {}
|
||||
|
||||
local ls = require('luasnip')
|
||||
|
||||
vim.keymap.set({ "i", "s" }, "<M-n>", function()
|
||||
if ls.choice_active() then
|
||||
ls.change_choice(1)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-cmp",
|
||||
-- cmd = { "" },
|
||||
event = { "DeferredUIEnter" },
|
||||
on_require = { "cmp" },
|
||||
-- ft = "",
|
||||
-- keys = "",
|
||||
-- colorscheme = "",
|
||||
after = function (plugin)
|
||||
-- [[ Configure nvim-cmp ]]
|
||||
-- See `:help cmp`
|
||||
local cmp = require 'cmp'
|
||||
local luasnip = require 'luasnip'
|
||||
local lspkind = require 'lspkind'
|
||||
|
||||
cmp.setup {
|
||||
formatting = {
|
||||
format = lspkind.cmp_format {
|
||||
mode = 'text',
|
||||
with_text = true,
|
||||
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
|
||||
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
|
||||
|
||||
menu = {
|
||||
buffer = '[BUF]',
|
||||
nvim_lsp = '[LSP]',
|
||||
nvim_lsp_signature_help = '[LSP]',
|
||||
nvim_lsp_document_symbol = '[LSP]',
|
||||
nvim_lua = '[API]',
|
||||
path = '[PATH]',
|
||||
luasnip = '[SNIP]',
|
||||
},
|
||||
},
|
||||
},
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert {
|
||||
['<C-p>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-n>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete {},
|
||||
['<CR>'] = cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
},
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
},
|
||||
|
||||
sources = cmp.config.sources {
|
||||
-- The insertion order influences the priority of the sources
|
||||
{ name = 'nvim_lsp'--[[ , keyword_length = 3 ]] },
|
||||
{ name = 'nvim_lsp_signature_help'--[[ , keyword_length = 3 ]]},
|
||||
{ name = 'path' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'buffer' },
|
||||
},
|
||||
enabled = function()
|
||||
return vim.bo[0].buftype ~= 'prompt'
|
||||
end,
|
||||
experimental = {
|
||||
native_menu = false,
|
||||
ghost_text = false,
|
||||
},
|
||||
}
|
||||
|
||||
cmp.setup.filetype('lua', {
|
||||
sources = cmp.config.sources {
|
||||
{ name = 'nvim_lua' },
|
||||
{ name = 'nvim_lsp'--[[ , keyword_length = 3 ]]},
|
||||
{ name = 'nvim_lsp_signature_help'--[[ , keyword_length = 3 ]]},
|
||||
{ name = 'path' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'buffer' },
|
||||
},{
|
||||
{
|
||||
name = 'cmdline',
|
||||
option = {
|
||||
ignore_cmds = { 'Man', '!' },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline({ '/', '?' }, {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'nvim_lsp_document_symbol'--[[ , keyword_length = 3 ]]},
|
||||
{ name = 'buffer' },
|
||||
{ name = 'cmdline_history' },
|
||||
},
|
||||
view = {
|
||||
entries = { name = 'wildmenu', separator = '|' },
|
||||
},
|
||||
})
|
||||
|
||||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline(':', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources {
|
||||
{ name = 'cmdline' },
|
||||
-- { name = 'cmdline_history' },
|
||||
{ name = 'path' },
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
5
homes/modules/programs/neovim/lua/lsp/init.lua
Normal file
5
homes/modules/programs/neovim/lua/lsp/init.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
require("lze").load {
|
||||
{ import = "lsp.completion", },
|
||||
}
|
||||
|
||||
require("lsp.lsp")
|
||||
123
homes/modules/programs/neovim/lua/lsp/lsp.lua
Normal file
123
homes/modules/programs/neovim/lua/lsp/lsp.lua
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
local servers = {}
|
||||
|
||||
servers.lua_ls = {
|
||||
settings = {
|
||||
Lua = {
|
||||
formatters = {
|
||||
ignoreComments = false,
|
||||
},
|
||||
signatureHelp = { enable = true },
|
||||
diagnostics = {
|
||||
globals = { 'nixCats', 'vim' },
|
||||
-- disable = { 'missing-fields' },
|
||||
},
|
||||
workspace = {
|
||||
-- make the server aware of the neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
checkThirdParty = false,
|
||||
},
|
||||
},
|
||||
telemetry = { enabled = false },
|
||||
},
|
||||
}
|
||||
|
||||
local rust_analyzer_cmd = os.getenv("RUST_ANALYZER_CMD")
|
||||
servers.rust_analyzer = {
|
||||
cmd = { rust_analyzer_cmd },
|
||||
settings = {
|
||||
server = {
|
||||
-- For debugging rust-analyzer, to see log location do :LspInfo in neovim
|
||||
-- extraEnv = { {["RA_LOG"]="project_model=debug"} },
|
||||
},
|
||||
cargo = {
|
||||
allFeatures = false,
|
||||
allTargets = false,
|
||||
buildScripts = { enable = true },
|
||||
target = "x86_64-unknown-linux-gnu",
|
||||
},
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
servers.zls = {
|
||||
settings = {},
|
||||
}
|
||||
|
||||
local elixir_ls_cmd = os.getenv("ELIXIR_LS_CMD")
|
||||
servers.elixirls = {
|
||||
cmd = { elixir_ls_cmd },
|
||||
settings = {},
|
||||
}
|
||||
|
||||
servers.gleam = {
|
||||
settings = {},
|
||||
}
|
||||
|
||||
local java_home = os.getenv("JAVA_HOME")
|
||||
servers.jdtls = {
|
||||
settings = {
|
||||
java = {
|
||||
contentProvider = { preferred = 'fernflower' },
|
||||
configuration = {
|
||||
runtimes = {
|
||||
{
|
||||
name = "OpenJDK 17",
|
||||
path = os.getenv("OPENJDK_17"),
|
||||
},
|
||||
{
|
||||
name = "OpenJDK 21",
|
||||
path = os.getenv("OPENJDK_21"),
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
-- Taken from nixCats example:
|
||||
-- If you were to comment out this autocommand
|
||||
-- and instead pass the on attach function directly to
|
||||
-- nvim-lspconfig, it would do the same thing.
|
||||
-- come to think of it, it might be better because then lspconfig doesnt have to be called before lsp attach?
|
||||
-- but you would still end up triggering on a FileType event anyway, so, it makes little difference.
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('nixCats-lsp-attach', { clear = true }),
|
||||
callback = function(event)
|
||||
require('lsp.capabilities').on_attach(vim.lsp.get_client_by_id(event.data.client_id), event.buf)
|
||||
end
|
||||
})
|
||||
|
||||
require("lze").load {
|
||||
{
|
||||
"nvim-lspconfig",
|
||||
event = "FileType",
|
||||
after = function(plugin)
|
||||
-- Just register configs, don't enable yet
|
||||
for server_name, cfg in pairs(servers) do
|
||||
vim.lsp.config(server_name, {
|
||||
capabilities = require('lsp.capabilities').get(server_name),
|
||||
settings = (cfg or {}).settings,
|
||||
filetypes = (cfg or {}).filetypes,
|
||||
cmd = (cfg or {}).cmd,
|
||||
root_pattern = (cfg or {}).root_pattern,
|
||||
})
|
||||
end
|
||||
|
||||
-- Enable on-demand per filetype
|
||||
for server_name, cfg in pairs(servers) do
|
||||
local filetypes = cfg.filetypes or vim.lsp.config[server_name].filetypes
|
||||
if filetypes then
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = filetypes,
|
||||
callback = function()
|
||||
vim.lsp.enable(server_name)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue