feat: refactor and separate LSP/language configurations

This commit is contained in:
NotAShelf 2023-04-17 23:27:27 +03:00
commit 6b512f132a
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
30 changed files with 1266 additions and 522 deletions

View file

@ -1,4 +1,5 @@
{
pkgs,
config,
lib,
...
@ -6,59 +7,49 @@
with lib;
with builtins; let
cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
in {
config = mkIf cfg.enable (
let
writeIf = cond: msg:
if cond
then msg
else "";
in {
vim.startPlugins = [
"nvim-treesitter"
(
if cfg.autotagHtml
then "nvim-ts-autotag"
else null
)
];
config = mkIf cfg.enable {
vim.startPlugins =
["nvim-treesitter"]
++ optional cfg.autotagHtml "nvim-ts-autotag"
++ optional usingNvimCmp "cmp-treesitter";
# For some reason treesitter highlighting does not work on start if this is set before syntax on
vim.configRC.treesitter = writeIf cfg.fold (nvim.dag.entryBefore ["basic"] ''
" Tree-sitter based folding
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set nofoldenable
'');
vim.autocomplete.sources = ["treesitter"];
vim.luaConfigRC.treesitter = nvim.dag.entryAnywhere ''
-- Treesitter config
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
disable = {},
# For some reason treesitter highlighting does not work on start if this is set before syntax on
vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore ["basic"] ''
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set nofoldenable
'');
vim.luaConfigRC.treesitter = nvim.dag.entryAnywhere ''
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
disable = {},
},
auto_install = false,
ensure_installed = {},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
auto_install = false,
ensure_installed = {},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
${writeIf cfg.autotagHtml ''
autotag = {
enable = true,
},
''}
}
'';
}
);
${optionalString cfg.autotagHtml ''
autotag = {
enable = true,
},
''}
}
'';
};
}

View file

@ -5,51 +5,23 @@
...
}:
with lib;
with builtins; {
with builtins; let
cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
in {
options.vim.treesitter = {
enable = mkOption {
default = false;
type = types.bool;
description = "Enable tree-sitter [nvim-treesitter]";
};
enable = mkEnableOption "treesitter, also enabled automatically through language options";
fold = mkOption {
default = false;
type = types.bool;
description = "Enable fold with tree-sitter";
};
fold = mkEnableOption "fold with treesitter";
autotagHtml = mkOption {
default = false;
type = types.bool;
description = "Enable autoclose and rename html tag [nvim-ts-autotag]";
};
autotagHtml = mkEnableOption "autoclose and rename html tag";
grammars = mkOption {
type = with types; listOf package;
default = with (pkgs.vimPlugins.nvim-treesitter.builtGrammars);
[
c
cpp
nix
python
rust
markdown
comment
toml
make
tsx
html
javascript
css
graphql
json
zig
]
++ (optional config.vim.notes.orgmode.enable org); # add orgmode grammar if enabled
default = [];
description = ''
List of treesitter grammars to install.
When enabling a language, its treesitter grammar is added for you.
List of treesitter grammars to install. For supported languages
use the `vim.language.<lang>.treesitter` option
'';
};
};