Compare commits

..

4 Commits

23 changed files with 180 additions and 44 deletions

View File

@ -8,7 +8,7 @@ in
./bash ./bash
./git.nix ./git.nix
./lang/bash.nix ./lang/bash.nix
./lang/c.nix ./lang/cxx.nix
./lang/elixir.nix ./lang/elixir.nix
./lang/lean.nix ./lang/lean.nix
./lang/lua.nix ./lang/lua.nix

View File

@ -7,7 +7,7 @@
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').bashls) {} require('utils.lsp').setup(require('lspconfig').bashls) {}
''; '';
}; };
} }

View File

@ -15,11 +15,11 @@ in
programs.neovim = { programs.neovim = {
nvim-dap = '' nvim-dap = ''
require('init.c').nvim_dap() require('cxx.init').nvim_dap()
''; '';
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.c').nvim_lspconfig() require('cxx.init').nvim_lspconfig()
vim.filetype.add({ vim.filetype.add({
pattern = { pattern = {
@ -30,6 +30,6 @@ in
}; };
xdg.configFile."nvim/after/ftplugin/c.lua".text = '' xdg.configFile."nvim/after/ftplugin/c.lua".text = ''
require('init.dap').buffer_map() require('utils.dap').buffer_map()
''; '';
} }

View File

@ -6,7 +6,7 @@
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').elixirls) { require('utils.lsp').setup(require('lspconfig').elixirls) {
cmd = { 'elixir-ls' }, cmd = { 'elixir-ls' },
} }
''; '';

View File

@ -8,7 +8,7 @@ let
"Julian/lean.nvim"; "Julian/lean.nvim";
config = '' config = ''
lua << EOF lua << EOF
require('init.lsp').setup(require('lean')) { require('utils.lsp').setup(require('lean')) {
abbreviations = { builtin = true }, abbreviations = { builtin = true },
mappings = true, mappings = true,
} }

View File

@ -6,7 +6,7 @@
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lua').nvim_lspconfig() require('lua.init').nvim_lspconfig()
''; '';
}; };
} }

View File

@ -6,7 +6,7 @@
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').marksman) {} require('utils.lsp').setup(require('lspconfig').marksman) {}
''; '';
}; };
} }

View File

@ -6,7 +6,7 @@
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').nil_ls) {} require('utils.lsp').setup(require('lspconfig').nil_ls) {}
''; '';
}; };
} }

View File

@ -13,15 +13,19 @@
programs.neovim = { programs.neovim = {
nvim-dap = '' nvim-dap = ''
require('init.python').nvim_dap() require('python.init').nvim_dap()
''; '';
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.python').nvim_lspconfig() require('python.init').nvim_lspconfig()
'';
nvim-snippets = ''
require('luasnip').add_snippets('python', require('python.snippets'))
''; '';
}; };
xdg.configFile."nvim/after/ftplugin/python.lua".text = '' xdg.configFile."nvim/after/ftplugin/python.lua".text = ''
require('init.dap').buffer_map() require('utils.dap').buffer_map()
''; '';
} }

View File

@ -7,9 +7,9 @@
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').tsserver) { require('utils.lsp').setup(require('lspconfig').tsserver) {
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
require('init.lsp').on_attach(client, bufnr) require('utils.lsp').on_attach(client, bufnr)
-- Override the default formatter in typescript-language-server. -- Override the default formatter in typescript-language-server.
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', "<CMD>PrettierAsync<CR>", { vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', "<CMD>PrettierAsync<CR>", {
silent = true, silent = true,

View File

@ -31,7 +31,7 @@ function M.nvim_dap()
end end
function M.nvim_lspconfig() function M.nvim_lspconfig()
require('init.lsp').setup(require('lspconfig').clangd) {} require('utils.lsp').setup(require('lspconfig').clangd) {}
end end
return M return M

View File

@ -1,7 +1,7 @@
local M = {} local M = {}
function M.nvim_lspconfig() function M.nvim_lspconfig()
require('init.lsp').setup(require('lspconfig').lua_ls) { require('utils.lsp').setup(require('lspconfig').lua_ls) {
-- Provide completions, analysis, and location handling for plugins on the -- Provide completions, analysis, and location handling for plugins on the
-- vim runtime path. -- vim runtime path.
-- https://github.com/neovim/nvim-lspconfig/blob/48347089666d5b77d054088aa72e4e0b58026e6e/doc/server_configurations.md#lua_ls -- https://github.com/neovim/nvim-lspconfig/blob/48347089666d5b77d054088aa72e4e0b58026e6e/doc/server_configurations.md#lua_ls

View File

@ -24,7 +24,7 @@ function M.nvim_dap()
end end
function M.nvim_lspconfig() function M.nvim_lspconfig()
require('init.lsp').setup(require('lspconfig').pylsp) { require('utils.lsp').setup(require('lspconfig').pylsp) {
settings = { settings = {
pylsp = { pylsp = {
-- `flake8` currently fails in some cases. Prefer the default set of -- `flake8` currently fails in some cases. Prefer the default set of

View File

@ -0,0 +1,58 @@
local c = require('luasnip').choice_node
local d = require('luasnip').dynamic_node
local i = require('luasnip').insert_node
local sn = require('luasnip').snippet_node
local t = require('luasnip').text_node
local s = require('luasnip').snippet
local fmt = require('luasnip.extras.fmt').fmt
local VISUAL = require('utils.luasnip').VISUAL
return {
s(
{ name = 'for', trig = 'for' },
fmt([[
for {} in {}:
{}]],
{
c(1, {
i(1, 'i'),
i(2, 'k'),
i(3, 'v'),
sn(4, { i(1, 'k'), t(', '), i(2, 'v') }),
}),
d(2, function(args, _, old_state)
local default = i(nil, 'val')
local snip = old_state or default
if args[1][1] == 'i' then
snip = sn(nil, c(1, {
{ t('range('), i(1, 'n'), t(')') },
default,
}))
elseif args[1][1] == 'k' then
snip = sn(nil, c(1, {
{ i(1, 'dict'), t('.keys()') },
default,
}))
elseif args[1][1] == 'v' then
snip = sn(nil, c(1, {
{ i(1, 'dict'), t('.values()') },
default,
}))
elseif args[1][1] == 'k, v' then
snip = sn(nil, c(1, {
{ i(1, 'dict'), t('.items()') },
default,
}))
end
snip.old_state = snip
return snip
end, { 1 }),
VISUAL,
}
)
),
}

View File

@ -2,7 +2,7 @@ local M = {}
local cmp = require('cmp') local cmp = require('cmp')
local cmp_buffer = require('cmp_buffer') local cmp_buffer = require('cmp_buffer')
local luasnip = require("luasnip") local luasnip = require('luasnip')
function M.setup() function M.setup()
cmp.setup { cmp.setup {
@ -12,9 +12,8 @@ function M.setup()
end, end,
}, },
sources = { sources = {
{ { name = 'luasnip' },
name = 'nvim_lsp', { name = 'nvim_lsp' },
},
{ {
name = 'buffer', name = 'buffer',
option = { option = {
@ -31,29 +30,24 @@ function M.setup()
}, },
sorting = { sorting = {
comparators = { comparators = {
function (...) function(...)
-- This also sorts completion results coming from other sources (e.g. -- This also sorts completion results coming from other sources.
-- LSPs).
return cmp_buffer:compare_locality(...) return cmp_buffer:compare_locality(...)
end, end,
}, },
}, },
mapping = { mapping = {
['<c-n>'] = cmp.mapping(function(fallback) ['<tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.select_next_item() else fallback() end if cmp.get_active_entry() then cmp.confirm() else fallback() end
end, { 'i', 's' }),
['<c-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.select_prev_item() else fallback() end
end, { 'i', 's' }), end, { 'i', 's' }),
['<c-l>'] = cmp.mapping(function(fallback) ['<c-l>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.abort() else fallback() end if cmp.visible() then cmp.abort() else fallback() end
end, { 'i', 's' }), end, { 'i', 's' }),
['<tab>'] = cmp.mapping(function(fallback) ['<c-n>'] = cmp.mapping(function(fallback)
if cmp.get_active_entry() then if cmp.visible() then
cmp.confirm() cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
else else
@ -61,8 +55,10 @@ function M.setup()
end end
end, { 'i', 's' }), end, { 'i', 's' }),
['<s-tab>'] = cmp.mapping(function(fallback) ['<c-p>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
else else
fallback() fallback()

View File

@ -0,0 +1,60 @@
local M = {}
local luasnip = require('luasnip')
local types = require('luasnip.util.types')
local f = require('luasnip').function_node
M.VISUAL = f(function(_, snip)
local res, env = {}, snip.env
for _, ele in ipairs(env.LS_SELECT_RAW) do
table.insert(res, ele)
end
return res
end, {})
function M.setup()
luasnip.config.setup {
region_check_events = 'InsertEnter',
delete_check_events = 'InsertLeave',
store_selection_keys = '<tab>',
ext_opts = {
[types.snippet] = {
active = {
virt_text = { { '', 'DiagnosticWarn' } },
},
},
[types.choiceNode] = {
active = {
virt_text = { { '', 'DiagnosticHint' } },
-- Include in case one of our choice options is an empty string.
hl_group = 'DiagnosticOk',
},
},
},
}
vim.keymap.set({ 'i', 's' }, '<c-e>', function()
if luasnip.choice_active() then
return '<Plug>luasnip-next-choice'
else
return '<c-e>'
end
end, { silent = true, expr = true, remap = true })
vim.keymap.set({ 'i', 's' }, '<c-y>', function()
if luasnip.choice_active() then
return '<Plug>luasnip-prev-choice'
else
return '<c-y>'
end
end, { silent = true, expr = true, remap = true })
-- Allow aborting the active snippet at any point in time.
vim.keymap.set(
{ 'n', 'i', 's' },
'<c-l>',
'<cmd>LuaSnipUnlinkCurrent<cr>'
)
end
return M

View File

@ -18,8 +18,8 @@ let
sections = { sections = {
lualine_x = {'encoding', 'filetype'}, lualine_x = {'encoding', 'filetype'},
lualine_y = { lualine_y = {
require('init.statusline').get_active_lsp, require('utils.statusline').get_active_lsp,
require('init.statusline').get_dap_status, require('utils.statusline').get_dap_status,
}, },
lualine_z = {'%c:%l:%%%p'}, lualine_z = {'%c:%l:%%%p'},
}, },
@ -27,10 +27,18 @@ let
''; '';
}; };
luasnip = {
plugin = pkgs.vimPlugins.luasnip;
config = ''
require('utils.luasnip').setup()
${config.programs.neovim.nvim-snippets}
'';
};
nvim-cmp = { nvim-cmp = {
plugin = pkgs.vimPlugins.nvim-cmp; plugin = pkgs.vimPlugins.nvim-cmp;
config = '' config = ''
require('init.cmp').setup() require('utils.cmp').setup()
''; '';
}; };
@ -52,7 +60,7 @@ let
nvim-telescope = { nvim-telescope = {
plugin = pkgs.vimPlugins.telescope-nvim; plugin = pkgs.vimPlugins.telescope-nvim;
config = '' config = ''
require('init.telescope').setup() require('utils.telescope').setup()
''; '';
}; };
@ -72,7 +80,7 @@ let
] ]
)); ));
config = '' config = ''
require('init.treesitter').setup() require('utils.treesitter').setup()
''; '';
}; };
in in
@ -97,6 +105,16 @@ in
Language-specific configurations for the `nvim-lspconfig` plugin. Language-specific configurations for the `nvim-lspconfig` plugin.
''; '';
}; };
nvim-snippets = lib.mkOption {
type = lib.types.lines;
example = ''
require('...').nvim_lspconfig()
'';
description = lib.mdDoc ''
Language-specific configurations for the `luasnip` plugin.
'';
};
}; };
config = { config = {
@ -113,6 +131,7 @@ in
} else p) [ } else p) [
colorscheme # Is always first. colorscheme # Is always first.
lualine lualine
luasnip
nvim-cmp nvim-cmp
nvim-dap nvim-dap
nvim-lspconfig nvim-lspconfig
@ -121,7 +140,6 @@ in
pkgs.vimPlugins.cmp-buffer pkgs.vimPlugins.cmp-buffer
pkgs.vimPlugins.cmp-nvim-lsp pkgs.vimPlugins.cmp-nvim-lsp
pkgs.vimPlugins.cmp_luasnip pkgs.vimPlugins.cmp_luasnip
pkgs.vimPlugins.luasnip
pkgs.vimPlugins.nvim-web-devicons pkgs.vimPlugins.nvim-web-devicons
pkgs.vimPlugins.vim-prettier pkgs.vimPlugins.vim-prettier
]; ];
@ -131,13 +149,13 @@ in
xdg.configFile."nvim/init.lua".text = xdg.configFile."nvim/init.lua".text =
let let
lua = import ./lua { inherit pkgs; }; config = import ./config { inherit pkgs; };
in in
lib.mkMerge [ lib.mkMerge [
# Extra Lua configuration to be prepended to `init.lua`. Extend the # Extra Lua configuration to be prepended to `init.lua`. Extend the
# Lua loader to search for our /nix/store/.../?.lua files. # Lua loader to search for our /nix/store/.../?.lua files.
(lib.mkBefore '' (lib.mkBefore ''
package.path = '${lua}/?.lua;' .. package.path package.path = '${config}/?.lua;' .. package.path
'') '')
# Extra Lua configuration to be appended to `init.lua`. # Extra Lua configuration to be appended to `init.lua`.
(lib.mkAfter '' (lib.mkAfter ''