parent
303122dfc8
commit
11adcacd6f
35 changed files with 524 additions and 415 deletions
|
@ -1,3 +1,4 @@
|
|||
self: {
|
||||
firefox = import ./firefox self;
|
||||
neovim = import ./neovim self;
|
||||
}
|
||||
|
|
107
homeManagerModules/neovim/.editorconfig
Normal file
107
homeManagerModules/neovim/.editorconfig
Normal file
|
@ -0,0 +1,107 @@
|
|||
# see https://github.com/CppCXY/EmmyLuaCodeStyle
|
||||
[*.lua]
|
||||
# [basic]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
quote_style = single
|
||||
|
||||
max_line_length = 120
|
||||
end_of_line = lf
|
||||
|
||||
table_separator_style = comma
|
||||
trailing_table_separator = smart
|
||||
|
||||
call_arg_parentheses = keep
|
||||
|
||||
# [space]
|
||||
space_around_table_field_list = true
|
||||
space_before_attribute = true
|
||||
space_before_function_open_parenthesis = false
|
||||
space_before_function_call_open_parenthesis = false
|
||||
space_before_closure_open_parenthesis = false
|
||||
space_before_function_call_single_arg = false
|
||||
space_before_open_square_bracket = false
|
||||
space_inside_function_call_parentheses = false
|
||||
space_inside_function_param_list_parentheses = false
|
||||
space_inside_square_brackets = false
|
||||
|
||||
# like t[#t+1] = 1
|
||||
space_around_table_append_operator = false
|
||||
ignore_spaces_inside_function_call = false
|
||||
|
||||
# detail number or 'keep'
|
||||
space_before_inline_comment = 1
|
||||
|
||||
# convert '---' to '--- ' or '--' to '-- '
|
||||
space_after_comment_dash = false
|
||||
|
||||
# [operator space]
|
||||
space_around_math_operator = true
|
||||
space_around_math_operator.exponent = false
|
||||
space_around_concat_operator = true
|
||||
space_around_logical_operator = true
|
||||
space_around_assign_operator = true
|
||||
|
||||
space_after_comma = true
|
||||
space_after_comma_in_for_statement = true
|
||||
|
||||
# [align]
|
||||
align_call_args = false
|
||||
align_function_params = true
|
||||
align_continuous_assign_statement = true
|
||||
align_continuous_rect_table_field = true
|
||||
align_continuous_line_space = 2
|
||||
align_if_branch = false
|
||||
|
||||
# option none / always / contain_curly/
|
||||
align_array_table = true
|
||||
|
||||
align_continuous_similar_call_args = false
|
||||
|
||||
align_continuous_inline_comment = true
|
||||
# option none / always / only_call_stmt
|
||||
align_chain_expr = none
|
||||
|
||||
# [indent]
|
||||
never_indent_before_if_condition = false
|
||||
never_indent_comment_on_if_branch = false
|
||||
keep_indents_on_empty_lines = false
|
||||
allow_non_indented_comments = false
|
||||
|
||||
# [line space]
|
||||
|
||||
# The following configuration supports four expressions
|
||||
# keep
|
||||
# fixed(n)
|
||||
# min(n)
|
||||
# max(n)
|
||||
# for eg. min(2)
|
||||
|
||||
line_space_after_if_statement = keep
|
||||
|
||||
line_space_after_do_statement = keep
|
||||
|
||||
line_space_after_while_statement = keep
|
||||
|
||||
line_space_after_repeat_statement = keep
|
||||
|
||||
line_space_after_for_statement = keep
|
||||
|
||||
line_space_after_local_or_assign_statement = keep
|
||||
|
||||
line_space_after_function_statement = fixed(2)
|
||||
|
||||
line_space_after_expression_statement = keep
|
||||
|
||||
line_space_after_comment = keep
|
||||
|
||||
line_space_around_block = fixed(1)
|
||||
|
||||
# [line break]
|
||||
break_all_list_when_line_exceed = false
|
||||
auto_collapse_lines = false
|
||||
break_before_braces = false
|
||||
|
||||
# [preference]
|
||||
ignore_space_after_colon = false
|
||||
end_statement_with_semicolon = always
|
128
homeManagerModules/neovim/default.nix
Normal file
128
homeManagerModules/neovim/default.nix
Normal file
|
@ -0,0 +1,128 @@
|
|||
self: {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkOption types;
|
||||
in {
|
||||
imports = [
|
||||
./git.nix
|
||||
./treesitter.nix
|
||||
(import ./langs self)
|
||||
(import ./theme.nix self)
|
||||
];
|
||||
|
||||
options.programs.neovim = {
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
enableIde = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
|
||||
config.programs.neovim = {
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
-- by default, the indent is 2 spaces.
|
||||
vim.opt.smartindent = true;
|
||||
vim.opt.expandtab = true;
|
||||
vim.opt.shiftwidth = 2;
|
||||
vim.opt.softtabstop = 2;
|
||||
vim.opt.tabstop = 2;
|
||||
|
||||
vim.opt.number = true;
|
||||
vim.opt.relativenumber = true;
|
||||
|
||||
vim.opt.undofile = true;
|
||||
vim.opt.undodir = '${config.xdg.cacheHome}/nvim/';
|
||||
|
||||
-- Always show the signcolumn, otherwise it would shift
|
||||
-- the text each time diagnostics appear/become resolved
|
||||
vim.opt.signcolumn = 'yes';
|
||||
|
||||
-- remove highlight on words
|
||||
vim.keymap.set('n', '<esc>', ':noh<cr><esc>', {
|
||||
noremap = true,
|
||||
silent = true,
|
||||
});
|
||||
|
||||
-- Get rid of deprecated messages
|
||||
vim.tbl_add_reverse_lookup = function(tbl)
|
||||
for k, v in pairs(tbl) do
|
||||
tbl[v] = k;
|
||||
end
|
||||
end;
|
||||
vim.tbl_islist = function(tbl)
|
||||
return vim.islist(tbl);
|
||||
end;
|
||||
vim.diagnostic.is_disabled = function()
|
||||
return not vim.diagnostic.is_enabled();
|
||||
end;
|
||||
vim.lsp.buf_get_clients = function()
|
||||
return vim.lsp.get_clients();
|
||||
end;
|
||||
vim.lsp.get_active_clients = function()
|
||||
return vim.lsp.get_clients();
|
||||
end;
|
||||
'';
|
||||
|
||||
plugins = [
|
||||
pkgs.vimPlugins.fzfWrapper
|
||||
pkgs.vimPlugins.fzf-vim
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.todo-comments-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('todo-comments').setup();
|
||||
'';
|
||||
}
|
||||
{
|
||||
plugin = pkgs.vimPlugins.mini-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
-- TODO: see how this works
|
||||
local ts_input = require('mini.surround').gen_spec.input.treesitter;
|
||||
|
||||
require('mini.surround').setup({
|
||||
custom_surroundings = {
|
||||
-- Use tree-sitter to search for function call
|
||||
f = {
|
||||
input = ts_input({
|
||||
outer = '@call.outer',
|
||||
inner = '@call.inner',
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.nvim-config-local;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('config-local').setup({
|
||||
config_files = { '.nvim.lua', '.nvimrc', '.exrc' },
|
||||
|
||||
-- Where the plugin keeps files data
|
||||
hashfile = '${config.xdg.cacheHome}/nvim/config-local',
|
||||
});
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# For accurate stack trace
|
||||
_file = ./default.nix;
|
||||
}
|
27
homeManagerModules/neovim/git.nix
Normal file
27
homeManagerModules/neovim/git.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{pkgs, ...}: {
|
||||
programs.neovim.plugins = [
|
||||
pkgs.vimPlugins.fugitive
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.gitsigns-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
local gitsigns = require("gitsigns");
|
||||
|
||||
local function visual_stage()
|
||||
local first_line = vim.fn.line('v');
|
||||
local last_line = vim.fn.getpos('.')[2];
|
||||
gitsigns.stage_hunk({ first_line, last_line });
|
||||
end
|
||||
|
||||
vim.keymap.set("v", "gs", function()
|
||||
visual_stage()
|
||||
end);
|
||||
|
||||
gitsigns.setup();
|
||||
'';
|
||||
}
|
||||
];
|
||||
}
|
49
homeManagerModules/neovim/langs/bash.nix
Normal file
49
homeManagerModules/neovim/langs/bash.nix
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) getExe mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in {
|
||||
programs = mkIf cfg.enable {
|
||||
# I love doing typos
|
||||
bash.shellAliases = {
|
||||
nivm = "nvim";
|
||||
nivim = "nvim";
|
||||
};
|
||||
|
||||
neovim = {
|
||||
defaultEditor = true;
|
||||
viAlias = true;
|
||||
vimAlias = true;
|
||||
|
||||
extraPackages = mkIf cfg.enableIde [
|
||||
pkgs.nodePackages.bash-language-server
|
||||
pkgs.shellcheck
|
||||
];
|
||||
|
||||
extraLuaConfig =
|
||||
mkIf cfg.enableIde
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'sh',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
require('lspconfig').bashls.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
settings = {
|
||||
bashIde = {
|
||||
shellcheckPath = '${getExe pkgs.shellcheck}',
|
||||
},
|
||||
},
|
||||
});
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
53
homeManagerModules/neovim/langs/clang.nix
Normal file
53
homeManagerModules/neovim/langs/clang.nix
Normal file
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = builtins.attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
gcc
|
||||
clang-tools
|
||||
cmake-language-server
|
||||
;
|
||||
};
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = { 'cpp' , 'c'},
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
local lsp = require('lspconfig');
|
||||
|
||||
lsp.cmake.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
});
|
||||
|
||||
lsp.clangd.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
handlers = require('lsp-status').extensions.clangd.setup(),
|
||||
on_attach = function(_, bufnr)
|
||||
require("clangd_extensions.inlay_hints").setup_autocmd()
|
||||
require("clangd_extensions.inlay_hints").set_inlay_hints()
|
||||
end,
|
||||
});
|
||||
'';
|
||||
|
||||
plugins = builtins.attrValues {
|
||||
inherit (pkgs.vimPlugins) clangd_extensions-nvim;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
67
homeManagerModules/neovim/langs/csharp.nix
Normal file
67
homeManagerModules/neovim/langs/csharp.nix
Normal file
|
@ -0,0 +1,67 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = builtins.attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
omnisharp-roslyn
|
||||
;
|
||||
};
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = { 'cs' },
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
local omnisharp_extended = require('omnisharp_extended');
|
||||
|
||||
require('lspconfig').omnisharp.setup({
|
||||
cmd = { "dotnet", "${pkgs.omnisharp-roslyn}/lib/omnisharp-roslyn/OmniSharp.dll" },
|
||||
|
||||
handlers = {
|
||||
["textDocument/definition"] = omnisharp_extended.definition_handler,
|
||||
["textDocument/typeDefinition"] = omnisharp_extended.type_definition_handler,
|
||||
["textDocument/references"] = omnisharp_extended.references_handler,
|
||||
["textDocument/implementation"] = omnisharp_extended.implementation_handler,
|
||||
},
|
||||
|
||||
settings = {
|
||||
FormattingOptions = {
|
||||
EnableEditorConfigSupport = true,
|
||||
OrganizeImports = true,
|
||||
},
|
||||
MsBuild = {
|
||||
LoadProjectsOnDemand = false,
|
||||
},
|
||||
RoslynExtensionsOptions = {
|
||||
EnableAnalyzersSupport = true,
|
||||
EnableDecompilationSupport = true,
|
||||
EnableImportCompletion = true,
|
||||
AnalyzeOpenDocumentsOnly = false,
|
||||
},
|
||||
Sdk = {
|
||||
IncludePrereleases = true,
|
||||
},
|
||||
},
|
||||
});
|
||||
'';
|
||||
|
||||
plugins = builtins.attrValues {
|
||||
inherit (pkgs.vimPlugins) omnisharp-extended-lsp-nvim;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
98
homeManagerModules/neovim/langs/default.nix
Normal file
98
homeManagerModules/neovim/langs/default.nix
Normal file
|
@ -0,0 +1,98 @@
|
|||
self: {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) fileContents mkBefore mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in {
|
||||
imports = [
|
||||
./bash.nix
|
||||
./clang.nix
|
||||
./csharp.nix
|
||||
./hyprlang.nix
|
||||
./java.nix
|
||||
./json.nix
|
||||
./lua.nix
|
||||
./python.nix
|
||||
./rust.nix
|
||||
(import ./markdown.nix self)
|
||||
(import ./nix.nix self)
|
||||
(import ./web.nix self)
|
||||
];
|
||||
|
||||
config.programs = mkIf cfg.enableIde {
|
||||
neovim = {
|
||||
extraLuaConfig =
|
||||
mkBefore
|
||||
# lua
|
||||
''
|
||||
-- Add formatting cmd
|
||||
vim.api.nvim_create_user_command(
|
||||
'Format',
|
||||
function()
|
||||
vim.lsp.buf.format({ async = true });
|
||||
end,
|
||||
{}
|
||||
);
|
||||
|
||||
-- LSP-Status setup
|
||||
local lsp_status = require('lsp-status');
|
||||
lsp_status.register_progress();
|
||||
|
||||
-- Remove LSP highlighting to use Treesitter
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
callback = function(args)
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id);
|
||||
client.server_capabilities.semanticTokensProvider = nil;
|
||||
lsp_status.on_attach(client);
|
||||
end,
|
||||
});
|
||||
|
||||
-- Disable virtual_text since it's redundant due to lsp_lines.
|
||||
vim.diagnostic.config({
|
||||
virtual_text = false,
|
||||
});
|
||||
|
||||
require('lsp_lines').setup();
|
||||
'';
|
||||
|
||||
plugins =
|
||||
(builtins.attrValues {
|
||||
inherit
|
||||
(pkgs.vimPlugins)
|
||||
nvim-lspconfig
|
||||
lsp-status-nvim
|
||||
lsp_lines-nvim
|
||||
cmp-buffer
|
||||
cmp-nvim-lsp
|
||||
cmp-path
|
||||
cmp-spell
|
||||
vim-vsnip
|
||||
;
|
||||
})
|
||||
++ [
|
||||
{
|
||||
plugin = pkgs.vimPlugins.nvim-cmp;
|
||||
type = "lua";
|
||||
config = fileContents ../plugins/cmp.lua;
|
||||
}
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.nvim-autopairs;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('nvim-autopairs').setup({});
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# For accurate stack trace
|
||||
_file = ./default.nix;
|
||||
}
|
27
homeManagerModules/neovim/langs/hyprlang.nix
Normal file
27
homeManagerModules/neovim/langs/hyprlang.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.filetype.add({
|
||||
pattern = { ['.*/hypr/.*%.conf'] = 'hyprlang' },
|
||||
});
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'hyprlang',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
84
homeManagerModules/neovim/langs/java.nix
Normal file
84
homeManagerModules/neovim/langs/java.nix
Normal file
|
@ -0,0 +1,84 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) getExe mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
|
||||
javaSdk = pkgs.temurin-bin-17;
|
||||
javaPkgs = builtins.attrValues {inherit (pkgs) gradle maven;};
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
home.packages = javaPkgs;
|
||||
|
||||
xdg.dataFile.".gradle/gradle.properties".text = ''
|
||||
org.gradle.java.home = ${javaSdk}
|
||||
'';
|
||||
|
||||
programs = {
|
||||
java = {
|
||||
enable = true;
|
||||
package = javaSdk;
|
||||
};
|
||||
|
||||
neovim = {
|
||||
extraPackages = javaPkgs;
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'java',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
'';
|
||||
|
||||
plugins = [
|
||||
{
|
||||
# TOOD: setup debugger https://github.com/mfussenegger/nvim-jdtls#debugger-via-nvim-dap
|
||||
plugin = pkgs.vimPlugins.nvim-jdtls;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
--
|
||||
local startJdtls = function()
|
||||
local config = {
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
cmd = { '${getExe pkgs.jdt-language-server}' },
|
||||
root_dir = vim.fs.dirname(vim.fs.find(
|
||||
{ 'gradlew', '.git', 'mvnw', 'pom.xml' },
|
||||
{ upward = true }
|
||||
)[1]),
|
||||
|
||||
settings = {
|
||||
java = {
|
||||
configuration = {
|
||||
runtimes = {
|
||||
{
|
||||
name = 'JavaSE-17',
|
||||
path = '${javaSdk}',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
require('jdtls').start_or_attach(config);
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'java',
|
||||
callback = startJdtls,
|
||||
});
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
56
homeManagerModules/neovim/langs/json.nix
Normal file
56
homeManagerModules/neovim/langs/json.nix
Normal file
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = builtins.attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
vscode-langservers-extracted
|
||||
yaml-language-server
|
||||
;
|
||||
};
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'yaml',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'json',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
local lsp = require('lspconfig');
|
||||
|
||||
lsp.jsonls.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
});
|
||||
|
||||
lsp.yamlls.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
settings = {
|
||||
yaml = {
|
||||
schemas = {
|
||||
[
|
||||
"https://json.schemastore.org/github-workflow.json"
|
||||
] = "/.github/workflows/*",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
50
homeManagerModules/neovim/langs/lua.nix
Normal file
50
homeManagerModules/neovim/langs/lua.nix
Normal file
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
|
||||
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = builtins.attrValues {
|
||||
inherit (pkgs) lua-language-server;
|
||||
};
|
||||
|
||||
plugins = [
|
||||
{
|
||||
plugin = pkgs.vimPlugins.neodev-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'lua',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
-- IMPORTANT: make sure to setup neodev BEFORE lspconfig
|
||||
require("neodev").setup({
|
||||
override = function(root_dir, library)
|
||||
if root_dir:find('${flakeEnv}', 1, true) == 1 then
|
||||
library.enabled = true
|
||||
library.plugins = true
|
||||
end
|
||||
end,
|
||||
});
|
||||
|
||||
require('lspconfig').lua_ls.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
});
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
133
homeManagerModules/neovim/langs/markdown.nix
Normal file
133
homeManagerModules/neovim/langs/markdown.nix
Normal file
|
@ -0,0 +1,133 @@
|
|||
self: {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
self,
|
||||
...
|
||||
}: let
|
||||
inherit (self.inputs) vimplugin-easytables-src;
|
||||
inherit (self.lib.${pkgs.system}) buildPlugin;
|
||||
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in {
|
||||
config = mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = builtins.attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
pandoc
|
||||
texlab
|
||||
texliveFull
|
||||
rubber
|
||||
;
|
||||
};
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
local lsp = require('lspconfig');
|
||||
|
||||
lsp.texlab.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
settings = {
|
||||
texlab = {
|
||||
formatterLineLength = 100,
|
||||
latexFormatter = 'latexindent',
|
||||
latexindent = {
|
||||
modifyLineBreaks = false,
|
||||
["local"] = '.indentconfig.yaml';
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
'';
|
||||
|
||||
plugins = [
|
||||
{
|
||||
plugin = buildPlugin "easytables-nvim" vimplugin-easytables-src;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('easytables').setup();
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.knap;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
--
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'tex',
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
vim.g.knap_settings = {
|
||||
-- HTML
|
||||
htmloutputext = 'html',
|
||||
htmltohtml = 'none',
|
||||
htmltohtmlviewerlaunch = "",
|
||||
htmltohtmlviewerrefresh = 'none',
|
||||
|
||||
-- Markdown
|
||||
mdoutputext = 'html',
|
||||
markdownoutputext = 'html',
|
||||
|
||||
-- Markdown to PDF
|
||||
mdtopdf = 'pandoc %docroot% -o /tmp/%outputfile%',
|
||||
markdowntopdf = 'pandoc %docroot% -o /tmp/%outputfile%',
|
||||
mdtopdfviewerlaunch = 'sioyek /tmp/%outputfile%',
|
||||
markdowntopdfviewerlaunch = 'sioyek /tmp/%outputfile%',
|
||||
mdtopdfviewerrefresh = 'none',
|
||||
markdowntopdfviewerrefresh = "none",
|
||||
|
||||
-- Markdown to HTML
|
||||
mdtohtml = 'pandoc --standalone %docroot% -o /tmp/%outputfile%',
|
||||
markdowntohtml = 'pandoc --standalone %docroot% -o /tmp/%outputfile%',
|
||||
mdtohtmlviewerlaunch = 'firefox -new-window /tmp/%outputfile%',
|
||||
markdowntohtmlviewerlaunch = 'firefox -new-window /tmp/%outputfile%',
|
||||
mdtohtmlviewerrefresh = 'none',
|
||||
markdowntohtmlviewerrefresh = 'none',
|
||||
|
||||
-- LaTeX
|
||||
-- TODO: stop from polluting workspace
|
||||
};
|
||||
|
||||
-- F4 processes the document once, and refreshes the view
|
||||
vim.keymap.set({ 'n', 'v', 'i' }, '<F4>', function()
|
||||
require('knap').process_once();
|
||||
end);
|
||||
|
||||
-- F5 closes the viewer application, and
|
||||
-- allows settings to be reset
|
||||
vim.keymap.set({ 'n', 'v', 'i' }, '<F5>', function()
|
||||
require('knap').close_viewer();
|
||||
end);
|
||||
|
||||
-- F6 toggles the auto-processing on and off
|
||||
vim.keymap.set({ 'n', 'v', 'i' }, '<F6>', function()
|
||||
require('knap').toggle_autopreviewing();
|
||||
end);
|
||||
|
||||
-- F7 invokes a SyncTeX forward search, or similar,
|
||||
-- where appropriate
|
||||
vim.keymap.set({ 'n', 'v', 'i' }, '<F7>', function()
|
||||
require('knap').forward_jump();
|
||||
end);
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# For accurate stack trace
|
||||
_file = ./markdown.nix;
|
||||
}
|
80
homeManagerModules/neovim/langs/nix.nix
Normal file
80
homeManagerModules/neovim/langs/nix.nix
Normal file
|
@ -0,0 +1,80 @@
|
|||
self: {
|
||||
config,
|
||||
lib,
|
||||
osConfig,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) getExe hasPrefix mkIf removePrefix;
|
||||
inherit (osConfig.networking) hostName;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
|
||||
defaultFormatter = self.formatter.${pkgs.system};
|
||||
|
||||
nixdPkg = self.inputs.nixd.packages.${pkgs.system}.default;
|
||||
|
||||
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
|
||||
flakeDir = "${removePrefix "/home/${cfg.user}/" flakeEnv}";
|
||||
in {
|
||||
config = mkIf cfg.enableIde {
|
||||
assertions = [
|
||||
{
|
||||
assertion =
|
||||
cfg.enableIde
|
||||
&& hasPrefix "/home/${cfg.user}/" flakeEnv
|
||||
|| !cfg.enableIde;
|
||||
message = ''
|
||||
Your $FLAKE environment variable needs to point to a directory in
|
||||
the main users' home to use the neovim module.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
home.packages = [
|
||||
defaultFormatter
|
||||
nixdPkg
|
||||
];
|
||||
|
||||
# nixd by default kinda spams LspLog
|
||||
home.sessionVariables.NIXD_FLAGS = "-log=error";
|
||||
|
||||
xdg.dataFile."${flakeDir}/.nixd.json".text = builtins.toJSON {
|
||||
nixpkgs = {
|
||||
expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}";
|
||||
};
|
||||
options.nixos = {
|
||||
expr = "(builtins.getFlake \"${flakeDir}\").nixosConfigurations.${hostName}.options";
|
||||
};
|
||||
};
|
||||
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = [
|
||||
nixdPkg
|
||||
];
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
require('lspconfig').nixd.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
filetypes = { 'nix', 'in.nix' },
|
||||
settings = {
|
||||
nixd = {
|
||||
formatting = {
|
||||
-- TODO: Try to find <flake>.formatter
|
||||
command = { '${getExe defaultFormatter}' },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# For accurate stack trace
|
||||
_file = ./nix.nix;
|
||||
}
|
29
homeManagerModules/neovim/langs/python.nix
Normal file
29
homeManagerModules/neovim/langs/python.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
withPython3 = true;
|
||||
|
||||
extraPackages = [
|
||||
pkgs.basedpyright
|
||||
];
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
require('lspconfig').basedpyright.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
});
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
38
homeManagerModules/neovim/langs/rust.nix
Normal file
38
homeManagerModules/neovim/langs/rust.nix
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) attrValues mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
extraPackages = attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
cargo
|
||||
rustc
|
||||
rust-analyzer
|
||||
rustfmt
|
||||
;
|
||||
};
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = { 'rust' },
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
require('lspconfig').rust_analyzer.setup({
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
});
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
204
homeManagerModules/neovim/langs/web.nix
Normal file
204
homeManagerModules/neovim/langs/web.nix
Normal file
|
@ -0,0 +1,204 @@
|
|||
self: {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (self.inputs) vimplugin-ts-error-translator-src;
|
||||
inherit (self.lib.${pkgs.system}) buildPlugin;
|
||||
|
||||
inherit (lib) mkIf;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in {
|
||||
config = mkIf cfg.enableIde {
|
||||
programs = {
|
||||
neovim = {
|
||||
withNodeJs = true;
|
||||
|
||||
extraPackages = builtins.attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
nodejs_latest
|
||||
vscode-langservers-extracted
|
||||
;
|
||||
|
||||
inherit
|
||||
(pkgs.nodePackages)
|
||||
npm
|
||||
neovim
|
||||
;
|
||||
|
||||
inherit
|
||||
(self.packages.${pkgs.system})
|
||||
some-sass-language-server
|
||||
;
|
||||
};
|
||||
|
||||
extraLuaConfig =
|
||||
# lua
|
||||
''
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx', 'css', 'scss' },
|
||||
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
|
||||
});
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'html',
|
||||
command = 'setlocal ts=4 sw=4 expandtab',
|
||||
});
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'scss',
|
||||
command = 'setlocal iskeyword+=@-@',
|
||||
});
|
||||
|
||||
local lsp = require('lspconfig');
|
||||
local tsserver = require('typescript-tools');
|
||||
local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
|
||||
|
||||
tsserver.setup({
|
||||
capabilities = default_capabilities,
|
||||
|
||||
handlers = {
|
||||
-- format error code with better error message
|
||||
['textDocument/publishDiagnostics'] = function(err, result, ctx, config)
|
||||
require('ts-error-translator').translate_diagnostics(err, result, ctx, config)
|
||||
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
|
||||
end,
|
||||
},
|
||||
});
|
||||
|
||||
lsp.eslint.setup({
|
||||
capabilities = default_capabilities,
|
||||
|
||||
-- auto-save
|
||||
on_attach = function(client, bufnr)
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
buffer = bufnr,
|
||||
command = 'EslintFixAll',
|
||||
});
|
||||
end,
|
||||
|
||||
settings = {
|
||||
validate = 'on',
|
||||
packageManager = 'npm',
|
||||
useESLintClass = true,
|
||||
useFlatConfig = true,
|
||||
experimental = {
|
||||
useFlatConfig = true,
|
||||
},
|
||||
codeAction = {
|
||||
disableRuleComment = {
|
||||
enable = true,
|
||||
location = 'separateLine'
|
||||
},
|
||||
showDocumentation = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
codeActionOnSave = {
|
||||
mode = 'all',
|
||||
rules = {},
|
||||
},
|
||||
format = true,
|
||||
quiet = false,
|
||||
onIgnoredFiles = 'off',
|
||||
rulesCustomizations = {},
|
||||
run = 'onType',
|
||||
problems = {
|
||||
shortenToSingleLine = false,
|
||||
},
|
||||
nodePath = "",
|
||||
workingDirectory = {
|
||||
mode = 'location',
|
||||
},
|
||||
options = {
|
||||
flags = {'unstable_ts_config'},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
lsp.cssls.setup({
|
||||
capabilities = default_capabilities,
|
||||
|
||||
settings = {
|
||||
css = {
|
||||
validate = false,
|
||||
},
|
||||
less = {
|
||||
validate = false,
|
||||
},
|
||||
scss = {
|
||||
validate = false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
lsp.somesass_ls.setup({
|
||||
capabilities = default_capabilities,
|
||||
});
|
||||
lsp.somesass_ls.manager.config.settings = {
|
||||
somesass = {
|
||||
scss = {
|
||||
completion = {
|
||||
suggestFromUseOnly = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
local html_caps = default_capabilities;
|
||||
html_caps.textDocument.completion.completionItem.snippetSupport = true;
|
||||
|
||||
lsp.html.setup({
|
||||
capabilities = html_caps,
|
||||
settings = {
|
||||
configurationSection = { "html", "css", "javascript" },
|
||||
embeddedLanguages = {
|
||||
css = true,
|
||||
javascript = true,
|
||||
},
|
||||
provideFormatter = true,
|
||||
tabSize = 4,
|
||||
insertSpaces = true,
|
||||
indentEmptyLines = false,
|
||||
wrapAttributes = 'auto',
|
||||
wrapAttributesIndentSize = 4,
|
||||
endWithNewline = true,
|
||||
},
|
||||
});
|
||||
'';
|
||||
|
||||
plugins = [
|
||||
pkgs.vimPlugins.typescript-tools-nvim
|
||||
(buildPlugin "ts-error-translator" vimplugin-ts-error-translator-src)
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.package-info-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
local packageInfo = require('package-info');
|
||||
packageInfo.setup({
|
||||
hide_up_to_date = true,
|
||||
package_manager = 'npm',
|
||||
});
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
|
||||
pattern = { 'package.json' },
|
||||
callback = function()
|
||||
packageInfo.show({ force = true });
|
||||
end,
|
||||
});
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# For accurate stack trace
|
||||
_file = ./web.nix;
|
||||
}
|
50
homeManagerModules/neovim/plugins/cmp.lua
Normal file
50
homeManagerModules/neovim/plugins/cmp.lua
Normal file
|
@ -0,0 +1,50 @@
|
|||
local cmp = require('cmp');
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp');
|
||||
|
||||
cmp.event:on(
|
||||
'confirm_done',
|
||||
cmp_autopairs.on_confirm_done()
|
||||
);
|
||||
|
||||
cmp.setup({
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'buffer' },
|
||||
{ name = 'path' },
|
||||
},
|
||||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
vim.fn['vsnip#anonymous'](args.body);
|
||||
end,
|
||||
},
|
||||
|
||||
mapping = {
|
||||
-- Confirm selection
|
||||
['<Right>'] = cmp.mapping.confirm({ select = true }),
|
||||
|
||||
-- Next selection
|
||||
['<Down>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item();
|
||||
else
|
||||
fallback();
|
||||
end;
|
||||
end, {
|
||||
'i',
|
||||
's',
|
||||
}),
|
||||
|
||||
-- Previous selection
|
||||
['<Up>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item();
|
||||
else
|
||||
fallback();
|
||||
end;
|
||||
end, {
|
||||
'i',
|
||||
's',
|
||||
}),
|
||||
},
|
||||
});
|
443
homeManagerModules/neovim/plugins/heirline.lua
Normal file
443
homeManagerModules/neovim/plugins/heirline.lua
Normal file
|
@ -0,0 +1,443 @@
|
|||
-- Modified from https://github.com/lauranaujokat/nvim/blob/4102c789d05667f636107e3dae4ac589053ee88d/lua/setups/heirline.lua#L4
|
||||
|
||||
local conditions = require('heirline.conditions');
|
||||
local utils = require('heirline.utils');
|
||||
|
||||
---@class Palette
|
||||
---@field [string] any
|
||||
local dracula = require('dracula').colors();
|
||||
|
||||
local colors = {
|
||||
bright_bg = dracula.selection,
|
||||
dark_bg = dracula.menu,
|
||||
bright_fg = dracula.fg,
|
||||
red = dracula.red,
|
||||
dark_red = utils.get_highlight('DiffDelete').bg,
|
||||
green = dracula.green,
|
||||
blue = dracula.blue,
|
||||
gray = utils.get_highlight('NonText').fg,
|
||||
orange = utils.get_highlight('Constant').fg,
|
||||
purple = utils.get_highlight('Statement').fg,
|
||||
cyan = dracula.cyan,
|
||||
diag_warn = utils.get_highlight('DiagnosticWarn').fg,
|
||||
diag_error = utils.get_highlight('DiagnosticError').fg,
|
||||
diag_hint = utils.get_highlight('DiagnosticHint').fg,
|
||||
diag_info = utils.get_highlight('DiagnosticInfo').fg,
|
||||
git_del = utils.get_highlight('GitSignsDelete').fg,
|
||||
git_add = utils.get_highlight('GitSignsAdd').fg,
|
||||
git_change = utils.get_highlight('GitSignsChange').fg,
|
||||
};
|
||||
|
||||
require('heirline').load_colors(colors);
|
||||
|
||||
local ViMode = {
|
||||
-- get vim current mode, this information will be required by the provider
|
||||
-- and the highlight functions, so we compute it only once per component
|
||||
-- evaluation and store it as a component attribute
|
||||
init = function(self)
|
||||
self.mode = vim.fn.mode(1);
|
||||
|
||||
-- execute this only once, this is required if you want the ViMode
|
||||
-- component to be updated on operator pending mode
|
||||
if not self.once then
|
||||
vim.api.nvim_create_autocmd('ModeChanged', {
|
||||
pattern = '*:*o',
|
||||
command = 'redrawstatus',
|
||||
});
|
||||
self.once = true;
|
||||
end;
|
||||
end,
|
||||
|
||||
static = {
|
||||
mode_names = {
|
||||
n = 'N',
|
||||
no = 'N?',
|
||||
nov = 'N?',
|
||||
noV = 'N?',
|
||||
['no\22'] = 'N?',
|
||||
niI = 'Ni',
|
||||
niR = 'Nr',
|
||||
niV = 'Nv',
|
||||
nt = 'Nt',
|
||||
v = 'V',
|
||||
vs = 'Vs',
|
||||
V = 'V_',
|
||||
Vs = 'Vs',
|
||||
['\22'] = '^V',
|
||||
['\22s'] = '^V',
|
||||
s = 'S',
|
||||
S = 'S_',
|
||||
['\19'] = '^S',
|
||||
i = 'I',
|
||||
ic = 'Ic',
|
||||
ix = 'Ix',
|
||||
R = 'R',
|
||||
Rc = 'Rc',
|
||||
Rx = 'Rx',
|
||||
Rv = 'Rv',
|
||||
Rvc = 'Rv',
|
||||
Rvx = 'Rv',
|
||||
c = 'C',
|
||||
cv = 'Ex',
|
||||
r = '...',
|
||||
rm = 'M',
|
||||
['r?'] = '?',
|
||||
['!'] = '!',
|
||||
t = 'T',
|
||||
},
|
||||
|
||||
mode_colors = {
|
||||
n = 'red',
|
||||
i = 'green',
|
||||
v = 'cyan',
|
||||
V = 'cyan',
|
||||
['\22'] = 'cyan',
|
||||
c = 'orange',
|
||||
s = 'purple',
|
||||
S = 'purple',
|
||||
['\19'] = 'purple',
|
||||
R = 'orange',
|
||||
r = 'orange',
|
||||
['!'] = 'red',
|
||||
t = 'red',
|
||||
},
|
||||
},
|
||||
|
||||
-- To be extra meticulous, we can also add some vim statusline syntax to
|
||||
-- control the padding and make sure our string is always at least 2
|
||||
-- characters long. Plus a nice Icon.
|
||||
provider = function(self)
|
||||
return ' ' .. self.mode_names[self.mode] .. '%)';
|
||||
end,
|
||||
|
||||
-- Same goes for the highlight. Now the foreground will change according to the current mode.
|
||||
hl = function(self)
|
||||
local mode = self.mode:sub(1, 1); -- get only the first mode character
|
||||
return { fg = self.mode_colors[mode], bold = true };
|
||||
end,
|
||||
|
||||
-- Re-evaluate the component only on ModeChanged event
|
||||
update = {
|
||||
'ModeChanged',
|
||||
},
|
||||
};
|
||||
|
||||
local FileNameBlock = {
|
||||
init = function(self)
|
||||
self.filename = vim.api.nvim_buf_get_name(0);
|
||||
end,
|
||||
};
|
||||
|
||||
-- FileNameBlock children
|
||||
local FileIcon = {
|
||||
init = function(self)
|
||||
local filename = self.filename;
|
||||
local extension = vim.fn.fnamemodify(filename, ':e');
|
||||
self.icon, self.icon_color =
|
||||
require('nvim-web-devicons').get_icon_color(filename, extension, { default = true });
|
||||
end,
|
||||
|
||||
provider = function(self)
|
||||
return self.icon and (self.icon .. ' ');
|
||||
end,
|
||||
|
||||
hl = function(self)
|
||||
return { fg = self.icon_color };
|
||||
end,
|
||||
};
|
||||
|
||||
local FileName = {
|
||||
provider = function(self)
|
||||
-- first, trim the pattern relative to the current directory. For other
|
||||
-- options, see :h filename-modifers
|
||||
local filename = vim.fn.fnamemodify(self.filename, ':.');
|
||||
if filename == '' then
|
||||
return '[No Name]';
|
||||
end;
|
||||
-- now, if the filename would occupy more than 1/4th of the available
|
||||
-- space, we trim the file path to its initials
|
||||
-- See Flexible Components section below for dynamic truncation
|
||||
if not conditions.width_percent_below(#filename, 0.25) then
|
||||
filename = vim.fn.pathshorten(filename);
|
||||
end;
|
||||
return filename;
|
||||
end,
|
||||
|
||||
hl = { fg = utils.get_highlight('Directory').fg },
|
||||
};
|
||||
|
||||
local FileFlags = {
|
||||
{
|
||||
condition = function()
|
||||
return vim.bo.modified;
|
||||
end,
|
||||
provider = '[+]',
|
||||
hl = { fg = 'green' },
|
||||
},
|
||||
{
|
||||
condition = function()
|
||||
return not vim.bo.modifiable or vim.bo.readonly;
|
||||
end,
|
||||
provider = '',
|
||||
hl = { fg = 'orange' },
|
||||
},
|
||||
};
|
||||
|
||||
local FileNameModifer = {
|
||||
hl = function()
|
||||
if vim.bo.modified then
|
||||
-- use `force` because we need to override the child's hl foreground
|
||||
return { fg = 'cyan', bold = true, force = true };
|
||||
end;
|
||||
end,
|
||||
};
|
||||
|
||||
-- let's add the children to our FileNameBlock component
|
||||
FileNameBlock = utils.insert(
|
||||
FileNameBlock,
|
||||
FileIcon,
|
||||
utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier
|
||||
unpack(FileFlags), -- A small optimisation, since their parent does nothing
|
||||
{ provider = '%<' } -- this means that the statusline is cut here when there's not enough space
|
||||
);
|
||||
|
||||
local Ruler = {
|
||||
provider = ' line: %l col: %c',
|
||||
hl = { fg = 'green', bold = false },
|
||||
};
|
||||
|
||||
local ScrollRuler = {
|
||||
-- %l = current line number
|
||||
-- %L = number of lines in the buffer
|
||||
-- %c = column number
|
||||
-- %P = percentage through file of displayed window
|
||||
provider = '%P',
|
||||
};
|
||||
|
||||
local ScrollBar = {
|
||||
static = {
|
||||
sbar = { '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█' },
|
||||
-- sbar = { '🭶', '🭷', '🭸', '🭹', '🭺', '🭻' }
|
||||
},
|
||||
|
||||
provider = function(self)
|
||||
local curr_line = vim.api.nvim_win_get_cursor(0)[1];
|
||||
local lines = vim.api.nvim_buf_line_count(0);
|
||||
local i = math.floor((curr_line - 1) / lines * #self.sbar) + 1;
|
||||
return string.rep(self.sbar[i], 2);
|
||||
end,
|
||||
|
||||
hl = { fg = 'cyan', bg = 'bright_bg' },
|
||||
};
|
||||
|
||||
local LSPActive = {
|
||||
condition = conditions.lsp_attached,
|
||||
update = { 'LspAttach', 'LspDetach' },
|
||||
|
||||
provider = function()
|
||||
local names = {};
|
||||
for _, server in pairs(vim.lsp.get_clients()) do
|
||||
table.insert(names, server.name);
|
||||
end;
|
||||
return ' [' .. table.concat(names, ' ') .. '] ';
|
||||
end,
|
||||
|
||||
hl = { fg = 'green', bold = false },
|
||||
};
|
||||
|
||||
local spinner_frames = { '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏' };
|
||||
|
||||
-- From https://github.com/mhartington/dotfiles/blob/5961460e3a492f7815259a692fca5ca2a1df924a/config/nvim/lua/mh/statusline/lsp_status.lua#L4
|
||||
local function get_lsp_progress()
|
||||
local messages = require('lsp-status/messaging').messages;
|
||||
local buf_messages = messages();
|
||||
local msgs = {};
|
||||
|
||||
for _, msg in ipairs(buf_messages) do
|
||||
local contents;
|
||||
|
||||
if msg.progress then
|
||||
contents = msg.title;
|
||||
|
||||
if msg.spinner then
|
||||
contents = spinner_frames[(msg.spinner % #spinner_frames) + 1] .. ' ' .. contents;
|
||||
end;
|
||||
elseif msg.status then
|
||||
contents = msg.content;
|
||||
|
||||
if msg.uri then
|
||||
local space = math.min(60, math.floor(0.6 * vim.fn.winwidth(0)));
|
||||
local filename = vim.uri_to_fname(msg.uri);
|
||||
|
||||
filename = vim.fn.fnamemodify(filename, ':~:.');
|
||||
|
||||
if #filename > space then
|
||||
filename = vim.fn.pathshorten(filename);
|
||||
end;
|
||||
|
||||
contents = '(' .. filename .. ') ' .. contents;
|
||||
end;
|
||||
else
|
||||
contents = msg.content;
|
||||
end;
|
||||
|
||||
table.insert(msgs, contents);
|
||||
end;
|
||||
|
||||
return table.concat(msgs, ' ');
|
||||
end;
|
||||
|
||||
local LSPMessages = {
|
||||
provider = function()
|
||||
local progress = get_lsp_progress();
|
||||
|
||||
if progress == '' then
|
||||
return '';
|
||||
else
|
||||
return ' ' .. progress;
|
||||
end;
|
||||
end,
|
||||
hl = { fg = 'purple' },
|
||||
};
|
||||
|
||||
local Diagnostics = {
|
||||
condition = conditions.has_diagnostics,
|
||||
|
||||
static = {
|
||||
error_icon = ' ',
|
||||
warn_icon = ' ',
|
||||
info_icon = ' ',
|
||||
hint_icon = ' ',
|
||||
},
|
||||
|
||||
init = function(self)
|
||||
self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR });
|
||||
self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN });
|
||||
self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT });
|
||||
self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO });
|
||||
end,
|
||||
|
||||
update = { 'DiagnosticChanged', 'BufEnter' },
|
||||
|
||||
{
|
||||
provider = function(self)
|
||||
-- 0 is just another output, we can decide to print it or not!
|
||||
return self.errors > 0 and (self.error_icon .. self.errors);
|
||||
end,
|
||||
hl = { fg = 'diag_error' },
|
||||
},
|
||||
{
|
||||
provider = function(self)
|
||||
return self.warnings > 0 and (self.warn_icon .. self.warnings);
|
||||
end,
|
||||
hl = { fg = 'diag_warn' },
|
||||
},
|
||||
{
|
||||
provider = function(self)
|
||||
return self.info > 0 and (self.info_icon .. self.info);
|
||||
end,
|
||||
hl = { fg = 'diag_info' },
|
||||
},
|
||||
{
|
||||
provider = function(self)
|
||||
return self.hints > 0 and (self.hint_icon .. self.hints);
|
||||
end,
|
||||
hl = { fg = 'diag_hint' },
|
||||
},
|
||||
};
|
||||
|
||||
local Git = {
|
||||
condition = conditions.is_git_repo,
|
||||
|
||||
init = function(self)
|
||||
self.status_dict = vim.b.gitsigns_status_dict;
|
||||
self.has_changes = self.status_dict.added ~= 0 or
|
||||
self.status_dict.removed ~= 0 or
|
||||
self.status_dict.changed ~= 0;
|
||||
end,
|
||||
|
||||
hl = { fg = 'orange' },
|
||||
|
||||
{ -- git branch name
|
||||
provider = function(self)
|
||||
return ' ' .. self.status_dict.head;
|
||||
end,
|
||||
hl = { bold = true },
|
||||
},
|
||||
-- You could handle delimiters, icons and counts similar to Diagnostics
|
||||
{
|
||||
condition = function(self)
|
||||
return self.has_changes;
|
||||
end,
|
||||
provider = '(',
|
||||
},
|
||||
{
|
||||
provider = function(self)
|
||||
local count = self.status_dict.added or 0;
|
||||
return count > 0 and ('+' .. count);
|
||||
end,
|
||||
hl = { fg = 'git_add' },
|
||||
},
|
||||
{
|
||||
provider = function(self)
|
||||
local count = self.status_dict.removed or 0;
|
||||
return count > 0 and ('-' .. count);
|
||||
end,
|
||||
hl = { fg = 'git_del' },
|
||||
},
|
||||
{
|
||||
provider = function(self)
|
||||
local count = self.status_dict.changed or 0;
|
||||
return count > 0 and ('~' .. count);
|
||||
end,
|
||||
hl = { fg = 'git_change' },
|
||||
},
|
||||
{
|
||||
condition = function(self)
|
||||
return self.has_changes;
|
||||
end,
|
||||
provider = ')',
|
||||
},
|
||||
};
|
||||
|
||||
local Align = { provider = '%=' };
|
||||
local Space = { provider = ' ' };
|
||||
|
||||
Left = utils.surround({ '', '' }, 'bright_bg', { ViMode, Diagnostics, LSPMessages });
|
||||
Middle = utils.surround({ '', '' }, 'bright_bg', { LSPActive, FileNameBlock, Ruler });
|
||||
Right = utils.surround({ '', '' }, 'bright_bg', { Git, Space, ScrollRuler, Space, ScrollBar });
|
||||
|
||||
local DefaultStatusline = {
|
||||
hl = { bg = 'dark_bg' },
|
||||
condition = function()
|
||||
return true;
|
||||
end,
|
||||
Left,
|
||||
Align,
|
||||
Middle,
|
||||
Align,
|
||||
Right,
|
||||
};
|
||||
|
||||
local StatusLines = {
|
||||
hl = function()
|
||||
if conditions.is_active() then
|
||||
return 'StatusLine';
|
||||
else
|
||||
return 'StatusLineNC';
|
||||
end;
|
||||
end,
|
||||
|
||||
-- the first statusline with no condition, or which condition returns true is used.
|
||||
-- think of it as a switch case with breaks to stop fallthrough.
|
||||
fallthrough = false,
|
||||
|
||||
DefaultStatusline,
|
||||
};
|
||||
|
||||
-- Make it global
|
||||
vim.opt.laststatus = 3;
|
||||
|
||||
require('heirline').setup({
|
||||
statusline = StatusLines,
|
||||
});
|
63
homeManagerModules/neovim/plugins/neotree.lua
Normal file
63
homeManagerModules/neovim/plugins/neotree.lua
Normal file
|
@ -0,0 +1,63 @@
|
|||
-- Override netrw
|
||||
vim.g.loaded_netrw = 0;
|
||||
vim.g.loaded_netrwPlugin = 0;
|
||||
|
||||
require('neo-tree').setup({
|
||||
close_if_last_window = true,
|
||||
enable_refresh_on_write = true,
|
||||
|
||||
window = {
|
||||
width = 22,
|
||||
},
|
||||
|
||||
filesystem = {
|
||||
use_libuv_file_watcher = true,
|
||||
group_empty_dirs = true,
|
||||
|
||||
filtered_items = {
|
||||
visible = false,
|
||||
hide_dotfiles = false,
|
||||
hide_gitignored = false,
|
||||
hide_by_name = {},
|
||||
hide_by_pattern = {},
|
||||
always_show = {},
|
||||
never_show = {},
|
||||
never_show_by_pattern = {},
|
||||
},
|
||||
},
|
||||
|
||||
source_selector = {
|
||||
winbar = true,
|
||||
statusline = false,
|
||||
},
|
||||
|
||||
follow_current_file = {
|
||||
enabled = true,
|
||||
leave_dirs_open = true,
|
||||
},
|
||||
});
|
||||
|
||||
local function is_neotree_open()
|
||||
local manager = require('neo-tree.sources.manager');
|
||||
local renderer = require('neo-tree.ui.renderer');
|
||||
local state = manager.get_state('filesystem');
|
||||
return renderer.window_exists(state);
|
||||
end;
|
||||
|
||||
-- Auto open Neo-Tree on big enough window
|
||||
vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResized' }, {
|
||||
pattern = '*',
|
||||
callback = function()
|
||||
if vim.api.nvim_eval([[&columns]]) > 100 then
|
||||
if is_neotree_open() == false then
|
||||
vim.cmd[[Neotree show]];
|
||||
vim.cmd[[Neotree close]];
|
||||
vim.cmd[[Neotree show]];
|
||||
end;
|
||||
else
|
||||
if is_neotree_open() then
|
||||
vim.cmd[[Neotree close]];
|
||||
end;
|
||||
end;
|
||||
end,
|
||||
});
|
181
homeManagerModules/neovim/theme.nix
Normal file
181
homeManagerModules/neovim/theme.nix
Normal file
|
@ -0,0 +1,181 @@
|
|||
self: {
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (self.inputs) nvim-theme-src;
|
||||
inherit (lib) attrValues fileContents optionals;
|
||||
|
||||
cfg = config.programs.neovim;
|
||||
in {
|
||||
config.programs.neovim = {
|
||||
extraPackages = attrValues {
|
||||
inherit (pkgs) bat;
|
||||
};
|
||||
|
||||
plugins =
|
||||
[
|
||||
{
|
||||
plugin = pkgs.vimPlugins.dracula-nvim.overrideAttrs {
|
||||
src = nvim-theme-src;
|
||||
};
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
-- set dot icon in place of trailing whitespaces
|
||||
vim.opt.listchars = {
|
||||
tab = '→ ',
|
||||
trail = '•',
|
||||
extends = '⟩',
|
||||
precedes = '⟨',
|
||||
nbsp = '␣',
|
||||
};
|
||||
vim.opt.list = true;
|
||||
|
||||
-- Add visual indicator for trailing whitespaces
|
||||
vim.opt.fillchars = { eob = " " };
|
||||
vim.fn.matchadd('errorMsg', [[\s\+$]]);
|
||||
|
||||
vim.cmd.colorscheme('dracula');
|
||||
'';
|
||||
}
|
||||
{
|
||||
plugin = pkgs.vimPlugins.indent-blankline-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
--
|
||||
local highlight = {
|
||||
"RainbowRed",
|
||||
"RainbowYellow",
|
||||
"RainbowBlue",
|
||||
"RainbowOrange",
|
||||
"RainbowGreen",
|
||||
"RainbowViolet",
|
||||
"RainbowCyan",
|
||||
};
|
||||
|
||||
local hooks = require('ibl.hooks');
|
||||
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
|
||||
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" });
|
||||
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" });
|
||||
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" });
|
||||
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" });
|
||||
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" });
|
||||
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" });
|
||||
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" });
|
||||
end);
|
||||
|
||||
require('ibl').setup({
|
||||
indent = {
|
||||
highlight = highlight,
|
||||
char = "▏",
|
||||
},
|
||||
});
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.nvim-highlight-colors;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
-- Ensure termguicolors is enabled if not already
|
||||
vim.opt.termguicolors = true;
|
||||
|
||||
require('nvim-highlight-colors').setup({});
|
||||
'';
|
||||
}
|
||||
|
||||
# Deps of heirline config
|
||||
pkgs.vimPlugins.nvim-web-devicons
|
||||
{
|
||||
plugin = pkgs.vimPlugins.heirline-nvim;
|
||||
type = "lua";
|
||||
config = fileContents ./plugins/heirline.lua;
|
||||
}
|
||||
]
|
||||
++ optionals cfg.enableIde [
|
||||
{
|
||||
plugin = pkgs.vimPlugins.neo-tree-nvim;
|
||||
type = "lua";
|
||||
config = fileContents ./plugins/neotree.lua;
|
||||
}
|
||||
{
|
||||
plugin = pkgs.vimPlugins.codewindow-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
--
|
||||
local codewindow = require('codewindow');
|
||||
|
||||
codewindow.setup({
|
||||
auto_enable = false,
|
||||
minimap_width = 8,
|
||||
relative = 'editor',
|
||||
window_border = 'none',
|
||||
exclude_filetypes = { 'help' },
|
||||
});
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResized' }, {
|
||||
pattern = '*',
|
||||
callback = function()
|
||||
if vim.api.nvim_win_get_width(0) < 88 then
|
||||
codewindow.close_minimap();
|
||||
else
|
||||
codewindow.open_minimap();
|
||||
end
|
||||
end,
|
||||
});
|
||||
'';
|
||||
}
|
||||
{
|
||||
plugin = pkgs.vimPlugins.transparent-nvim;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('transparent').setup({
|
||||
groups = {
|
||||
'Normal',
|
||||
'NormalNC',
|
||||
'Comment',
|
||||
'Constant',
|
||||
'Special',
|
||||
'Identifier',
|
||||
'Statement',
|
||||
'PreProc',
|
||||
'Type',
|
||||
'Underlined',
|
||||
'Todo',
|
||||
'String',
|
||||
'Function',
|
||||
'Conditional',
|
||||
'Repeat',
|
||||
'Operator',
|
||||
'Structure',
|
||||
'LineNr',
|
||||
'NonText',
|
||||
'SignColumn',
|
||||
'CursorLine',
|
||||
'CursorLineNr',
|
||||
'StatusLine',
|
||||
'StatusLineNC',
|
||||
'EndOfBuffer',
|
||||
},
|
||||
extra_groups = {},
|
||||
exclude_groups = {},
|
||||
});
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# For accurate stack trace
|
||||
_file = ./theme.nix;
|
||||
}
|
34
homeManagerModules/neovim/treesitter.nix
Normal file
34
homeManagerModules/neovim/treesitter.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{pkgs, ...}: {
|
||||
programs.neovim.plugins = [
|
||||
{
|
||||
plugin = pkgs.vimPlugins.nvim-treesitter-context;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('treesitter-context').setup({
|
||||
enable = true,
|
||||
max_lines = 3,
|
||||
min_window_height = 20,
|
||||
});
|
||||
|
||||
vim.cmd.hi('TreesitterContextBottom', 'gui=underline guisp=Grey');
|
||||
'';
|
||||
}
|
||||
|
||||
pkgs.vimPlugins.nvim-treesitter-textobjects
|
||||
|
||||
{
|
||||
plugin = pkgs.vimPlugins.nvim-treesitter.withAllGrammars;
|
||||
type = "lua";
|
||||
config =
|
||||
# lua
|
||||
''
|
||||
require('nvim-treesitter.configs').setup({
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
});
|
||||
'';
|
||||
}
|
||||
];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue