refactor(nvim): split up lang configs in separate files
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-05-07 22:49:00 -04:00
parent 3348300ab7
commit ac2b846662
18 changed files with 563 additions and 315 deletions

View file

@ -1,2 +0,0 @@
-- Add `:Format` command to format current buffer
vim.api.nvim_create_user_command("Format", "call CocAction('format')", {})

View file

@ -1,34 +0,0 @@
" by default, the indent is 2 spaces.
set smartindent
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
" for html/rb files, 2 spaces
autocmd Filetype html setlocal ts=2 sw=2 expandtab
autocmd Filetype ruby setlocal ts=2 sw=2 expandtab
" for js/coffee/jade files, 4 spaces
autocmd Filetype javascript setlocal ts=4 sw=4 sts=0 expandtab
autocmd Filetype typescript setlocal ts=4 sw=4 sts=0 expandtab
autocmd Filetype java setlocal ts=4 sw=4 sts=0 expandtab
autocmd Filetype sh setlocal ts=4 sw=4 sts=0 expandtab
autocmd Filetype hyprlang setlocal ts=4 sw=4 sts=0 expandtab
" support scss @
autocmd FileType scss setl iskeyword+=@-@
set number
set relativenumber
" TODO: make this work for nix-on-droid
set undofile
set undodir=/home/matt/.cache/nvim/
" remove highlight on words
nnoremap <silent> <esc> :noh<cr><esc>
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved
set signcolumn=yes

View file

@ -0,0 +1,58 @@
{
config,
pkgs,
lib,
...
}: let
inherit (config.vars) neovimIde;
inherit (lib) fileContents;
inherit (pkgs) vimPlugins;
in
lib.mkIf neovimIde {
programs = {
neovim = {
coc = {
enable = true;
settings = {
colors.enable = true;
coc.preferences.formatOnType = true;
diagnostic.checkCurrentLine = true;
inlayHint.enable = false;
};
};
extraLuaConfig =
/*
lua
*/
''
vim.api.nvim_create_autocmd("FileType", {
pattern = 'hyprlang',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.api.nvim_create_user_command("Format", "call CocAction('format')", {});
-- Always show the signcolumn, otherwise it would shift the text each time
-- diagnostics appear/become resolved
vim.opt.signcolumn = 'yes';
'';
plugins = [
{
plugin = vimPlugins.coc-snippets;
type = "viml";
config = fileContents ./plugins/snippets.vim;
}
## Fzf
vimPlugins.coc-fzf
vimPlugins.coc-highlight
vimPlugins.coc-json
vimPlugins.coc-yaml
vimPlugins.coc-toml
];
};
};
}

View file

@ -2,216 +2,50 @@
config, config,
pkgs, pkgs,
lib, lib,
nvim-theme-src,
coc-stylelintplus,
nixd,
vimplugin-easytables-src,
... ...
}: let }: let
inherit (config.vars) hostName mainUser neovimIde; inherit (config.vars) neovimIde;
inherit (lib) fileContents hasPrefix optionalAttrs optionals removePrefix; inherit (lib) fileContents optionals;
inherit (pkgs) vimPlugins; inherit (pkgs) vimPlugins;
buildPlugin = pname: src:
pkgs.vimUtils.buildVimPlugin {
inherit pname src;
version = src.shortRev;
};
javaSdk = pkgs.temurin-bin-17;
coc-stylelintplus-flake = coc-stylelintplus.packages.${pkgs.system}.default;
nixdPkg = nixd.packages.${pkgs.system}.default;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
flakeDir = "${removePrefix "/home/${mainUser}/" flakeEnv}";
in { in {
assertions = [
{
assertion = neovimIde && hasPrefix "/home/${mainUser}/" flakeEnv || !neovimIde;
message = ''
Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the neovim module.
'';
}
];
imports = [ imports = [
./coc.nix
./langs
./theme.nix
./treesitter.nix ./treesitter.nix
]; ];
home = optionalAttrs neovimIde {
packages = with pkgs; [
gradle
maven
alejandra
# FIXME: set nixd to use alejandra
(writeShellApplication {
name = "nixpkgs-fmt";
runtimeInputs = [alejandra];
text = "alejandra \"$@\"";
})
];
};
xdg.dataFile = optionalAttrs neovimIde {
".gradle/gradle.properties".text = ''
org.gradle.java.home = ${javaSdk}
'';
"${flakeDir}/.nixd.json".text = builtins.toJSON {
nixpkgs = {
expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}";
};
options.nixos = {
expr = "(builtins.getFlake \"${flakeDir}\").nixosConfigurations.${hostName}.options";
};
};
};
programs = { programs = {
java = optionalAttrs neovimIde {
enable = true;
package = javaSdk;
};
# I love doing typos
bash.shellAliases = {
nivm = "nvim";
nivim = "nvim";
};
neovim = { neovim = {
enable = true; enable = true;
withNodeJs = true;
withPython3 = true;
withRuby = false;
defaultEditor = true; extraLuaConfig =
viAlias = true; /*
vimAlias = true; 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;
extraPackages = vim.opt.number = true;
(with pkgs; [ vim.opt.relativenumber = true;
bat
gcc
])
++ (optionals neovimIde [
nixdPkg
]
++ (with pkgs; [
clang-tools
nodejs_latest
nodePackages.npm
nodePackages.neovim
gradle
]));
extraPython3Packages = ps: vim.opt.undofile = true;
optionals neovimIde [ vim.opt.undodir = '${config.xdg.cacheHome}/nvim/';
ps.pylint
];
coc = optionalAttrs neovimIde { -- remove highlight on words
enable = true; vim.cmd[[nnoremap <silent> <esc> :noh<cr><esc>]];
settings = { '';
# General
colors.enable = true;
coc.preferences.formatOnType = true;
diagnostic.checkCurrentLine = true;
inlayHint.enable = false;
# ESLint
eslint = {
format.enable = true;
autoFixOnSave = true;
};
# Stylelint
stylelintplus = {
enable = true;
cssInJs = true;
autoFixOnSave = true;
autoFixOnFormat = true;
};
css.validate = false;
less.validate = false;
scss.validate = false;
wxss.validate = false;
# Lua
Lua = {
misc.parameters = [
"--metapath"
"~/.cache/sumneko_lua/meta"
"--logpath"
"~/.cache/sumneko_lua/log"
];
workspace.library = [
"$\{3rd\}/luv/library"
];
};
sumneko-lua = {
serverDir = "${pkgs.lua-language-server}/share/lua-language-server";
enableNvimLuaDev = true;
};
languageserver = {
# Nix
nix = {
command = "nixd";
filetypes = ["nix"];
};
};
# Java
java = {
maven.downloadSources = true;
eclipse.downloadSources = true;
format.settings.url = "eclipse-formatter.xml";
jdt.ls = {
java.home = "${javaSdk}";
statusIcons = {
"busy" = "Busy";
"ready" = "OK";
"warning" = "Warning";
"error" = "Error";
};
};
};
# Bash
bashIde.shellcheckPath = "${pkgs.shellcheck}/bin/shellcheck";
markdownlint.config = {
no-trailing-spaces = true;
no-multiple-blanks = false;
no-duplicate-heading = false;
line-length = {
tables = false;
};
};
};
};
extraConfig = fileContents ./base.vim;
extraLuaConfig = fileContents ./base.lua;
plugins = plugins =
[ [
vimPlugins.fzfWrapper vimPlugins.fzfWrapper
vimPlugins.fzf-vim vimPlugins.fzf-vim
vimPlugins.fugitive vimPlugins.fugitive
{
plugin = vimPlugins.dracula-nvim.overrideAttrs {
src = nvim-theme-src;
};
type = "viml";
config = fileContents ./plugins/dracula.vim;
}
{ {
plugin = vimPlugins.todo-comments-nvim; plugin = vimPlugins.todo-comments-nvim;
type = "lua"; type = "lua";
@ -219,18 +53,15 @@ in {
/* /*
lua lua
*/ */
''require('todo-comments').setup()''; ''
require('todo-comments').setup();
'';
} }
{ {
plugin = vimPlugins.gitsigns-nvim; plugin = vimPlugins.gitsigns-nvim;
type = "lua"; type = "lua";
config = fileContents ./plugins/gitsigns.lua; config = fileContents ./plugins/gitsigns.lua;
} }
{
plugin = vimPlugins.indent-blankline-nvim;
type = "lua";
config = fileContents ./plugins/indent.lua;
}
{ {
plugin = vimPlugins.mini-nvim; plugin = vimPlugins.mini-nvim;
type = "lua"; type = "lua";
@ -239,72 +70,26 @@ in {
{ {
plugin = vimPlugins.codewindow-nvim; plugin = vimPlugins.codewindow-nvim;
type = "lua"; type = "lua";
config = fileContents ./plugins/codewindow.lua; config =
/*
lua
*/
''
require('codewindow').setup({
auto_enable = true,
minimap_width = 8,
relative = 'editor',
window_border = 'none',
});
'';
} }
] ]
++ optionals neovimIde [ ++ optionals neovimIde [
vimPlugins.markdown-preview-nvim
# Coc configured
vimPlugins.coc-clangd
vimPlugins.coc-cmake
vimPlugins.coc-css
vimPlugins.coc-eslint
vimPlugins.coc-java
vimPlugins.coc-sh
coc-stylelintplus-flake
{
plugin = vimPlugins.coc-snippets;
type = "viml";
config = fileContents ./plugins/snippets.vim;
}
## Lua
vimPlugins.coc-sumneko-lua
vimPlugins.neodev-nvim
## Fzf
vimPlugins.coc-fzf
vimPlugins.coc-highlight
vimPlugins.coc-json
vimPlugins.coc-pyright
vimPlugins.coc-vimlsp
vimPlugins.coc-yaml
vimPlugins.coc-toml
vimPlugins.coc-markdownlint
vimPlugins.coc-tsserver
{ {
plugin = vimPlugins.nvim-autopairs; plugin = vimPlugins.nvim-autopairs;
type = "lua"; type = "lua";
config = fileContents ./plugins/autopairs.lua; config = fileContents ./plugins/autopairs.lua;
} }
{
plugin = vimPlugins.lualine-nvim;
type = "lua";
config = fileContents ./plugins/lualine.lua;
}
{
plugin = vimPlugins.neo-tree-nvim;
type = "viml";
config = ''
${fileContents ./plugins/neotree.vim}
lua << EOF
${fileContents ./plugins/neotree.lua}
EOF
'';
}
{
plugin = buildPlugin "easytables-nvim" vimplugin-easytables-src;
type = "lua";
config =
/*
lua
*/
''require('easytables').setup();'';
}
]; ];
}; };
}; };

View file

@ -0,0 +1,44 @@
{
config,
pkgs,
lib,
...
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
in
lib.mkIf neovimIde {
programs = {
# I love doing typos
bash.shellAliases = {
nivm = "nvim";
nivim = "nvim";
};
neovim = {
defaultEditor = true;
viAlias = true;
vimAlias = true;
extraLuaConfig =
/*
lua
*/
''
vim.api.nvim_create_autocmd("FileType", {
pattern = 'sh',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
'';
coc.settings = {
# Bash
bashIde.shellcheckPath = "${pkgs.shellcheck}/bin/shellcheck";
};
plugins = [
vimPlugins.coc-sh
];
};
};
}

View file

@ -0,0 +1,24 @@
{
config,
pkgs,
lib,
...
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
in
lib.mkIf neovimIde {
programs = {
neovim = {
extraPackages = with pkgs; [
gcc
clang-tools
];
plugins = [
vimPlugins.coc-clangd
vimPlugins.coc-cmake
];
};
};
}

View file

@ -0,0 +1,12 @@
{...}: {
imports = [
./bash.nix
./clang.nix
./java.nix
./lua.nix
./markdown.nix
./nix.nix
./python.nix
./web.nix
];
}

View file

@ -0,0 +1,62 @@
{
config,
lib,
pkgs,
...
}: let
inherit (pkgs) vimPlugins;
inherit (config.vars) neovimIde;
javaSdk = pkgs.temurin-bin-17;
javaPkgs = with pkgs; [gradle maven];
in
lib.mkIf neovimIde {
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',
});
'';
coc.settings.java = {
maven.downloadSources = true;
eclipse.downloadSources = true;
format.settings.url = "eclipse-formatter.xml";
jdt.ls = {
java.home = "${javaSdk}";
statusIcons = {
"busy" = "Busy";
"ready" = "OK";
"warning" = "Warning";
"error" = "Error";
};
};
};
plugins = [
vimPlugins.coc-java
];
};
};
}

View file

@ -0,0 +1,39 @@
{
config,
pkgs,
lib,
...
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
in
lib.mkIf neovimIde {
programs = {
neovim = {
coc.settings = {
Lua = {
misc.parameters = [
"--metapath"
"~/.cache/sumneko_lua/meta"
"--logpath"
"~/.cache/sumneko_lua/log"
];
workspace.library = [
"$\{3rd\}/luv/library"
];
};
sumneko-lua = {
serverDir = "${pkgs.lua-language-server}/share/lua-language-server";
enableNvimLuaDev = true;
};
};
plugins = [
vimPlugins.coc-sumneko-lua
vimPlugins.neodev-nvim
vimPlugins.coc-vimlsp
];
};
};
}

View file

@ -0,0 +1,48 @@
{
config,
pkgs,
lib,
vimplugin-easytables-src,
...
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
buildPlugin = pname: src:
pkgs.vimUtils.buildVimPlugin {
inherit pname src;
version = src.shortRev;
};
in
lib.mkIf neovimIde {
programs = {
neovim = {
coc.settings = {
markdownlint.config = {
no-trailing-spaces = true;
no-multiple-blanks = false;
no-duplicate-heading = false;
line-length = {
tables = false;
};
};
};
plugins = [
vimPlugins.markdown-preview-nvim
vimPlugins.coc-markdownlint
{
plugin = buildPlugin "easytables-nvim" vimplugin-easytables-src;
type = "lua";
config =
/*
lua
*/
''
require('easytables').setup();
'';
}
];
};
};
}

View file

@ -0,0 +1,61 @@
{
config,
pkgs,
lib,
nixd,
...
}: let
inherit (config.vars) hostName mainUser neovimIde;
inherit (lib) hasPrefix removePrefix;
nixdPkg = nixd.packages.${pkgs.system}.default;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
flakeDir = "${removePrefix "/home/${mainUser}/" flakeEnv}";
in
lib.mkIf neovimIde {
assertions = [
{
assertion = neovimIde && hasPrefix "/home/${mainUser}/" flakeEnv || !neovimIde;
message = ''
Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the neovim module.
'';
}
];
home.packages = with pkgs; [
alejandra
# FIXME: set nixd to use alejandra
(writeShellApplication {
name = "nixpkgs-fmt";
runtimeInputs = [alejandra];
text = "alejandra \"$@\"";
})
];
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
];
coc.settings.languageserver = {
nix = {
command = "nixd";
filetypes = ["nix"];
};
};
};
};
}

View file

@ -0,0 +1,24 @@
{
config,
lib,
pkgs,
...
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
in
lib.mkIf neovimIde {
programs = {
neovim = {
withPython3 = true;
extraPython3Packages = ps: [
ps.pylint
];
plugins = [
vimPlugins.coc-pyright
];
};
};
}

View file

@ -0,0 +1,73 @@
{
config,
pkgs,
lib,
coc-stylelintplus,
...
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
coc-stylelintplus-flake = coc-stylelintplus.packages.${pkgs.system}.default;
in
lib.mkIf neovimIde {
programs = {
neovim = {
withNodeJs = true;
extraPackages = with pkgs; [
nodejs_latest
nodePackages.npm
nodePackages.neovim
];
extraLuaConfig =
/*
lua
*/
''
vim.api.nvim_create_autocmd("FileType", {
pattern = { 'javascript' , 'typescript'},
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.api.nvim_create_autocmd("FileType", {
pattern = 'html',
command = 'setlocal ts=2 sw=2 expandtab',
});
vim.api.nvim_create_autocmd("FileType", {
pattern = 'scss',
command = 'setl iskeyword+=@-@',
});
'';
coc.settings = {
# ESLint
eslint = {
format.enable = true;
autoFixOnSave = true;
};
# Stylelint
stylelintplus = {
enable = true;
cssInJs = true;
autoFixOnSave = true;
autoFixOnFormat = true;
};
css.validate = false;
less.validate = false;
scss.validate = false;
wxss.validate = false;
};
plugins = [
vimPlugins.coc-css
vimPlugins.coc-eslint
coc-stylelintplus-flake
vimPlugins.coc-tsserver
];
};
};
}

View file

@ -1,6 +0,0 @@
require('codewindow').setup({
auto_enable = true,
minimap_width = 8,
relative = 'editor',
window_border = 'none',
});

View file

@ -1,10 +0,0 @@
" set dot icon in place of trailing whitespaces
set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨
lua << EOF
-- Add visual indicator for trailing whitespaces
vim.opt.fillchars = {eob = " "}
vim.cmd[[colorscheme dracula]]
EOF

View file

@ -1,9 +0,0 @@
require('lualine').setup({
options = {
theme = 'dracula',
globalstatus = true,
},
sections = {
lualine_x = {'g:coc_status', 'bo:filetype'},
}
})

View file

@ -0,0 +1,79 @@
{
config,
pkgs,
lib,
nvim-theme-src,
...
}: let
inherit (config.vars) neovimIde;
inherit (lib) fileContents optionals;
inherit (pkgs) vimPlugins;
in {
programs = {
neovim = {
extraPackages = with pkgs; [
bat
];
plugins =
[
{
plugin = vimPlugins.dracula-nvim.overrideAttrs {
src = nvim-theme-src;
};
type = "lua";
config =
/*
lua
*/
''
-- set dot icon in place of trailing whitespaces
vim.cmd[[set list listchars=tab:\ \ ,nbsp:,trail:,extends:,precedes:]]
-- Add visual indicator for trailing whitespaces
vim.opt.fillchars = {eob = " "}
vim.cmd[[colorscheme dracula]]
'';
}
{
plugin = vimPlugins.indent-blankline-nvim;
type = "lua";
config = fileContents ./plugins/indent.lua;
}
]
++ optionals neovimIde [
{
plugin = vimPlugins.lualine-nvim;
type = "lua";
config =
/*
lua
*/
''
require('lualine').setup({
options = {
theme = 'dracula',
globalstatus = true,
},
sections = {
lualine_x = { 'g:coc_status', 'bo:filetype' },
},
});
'';
}
{
plugin = vimPlugins.neo-tree-nvim;
type = "viml";
config = ''
${fileContents ./plugins/neotree.vim}
lua << EOF
${fileContents ./plugins/neotree.lua}
EOF
'';
}
];
};
};
}