Skip to content

Commit

Permalink
feat: opiniated syntax hilighting plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoey de Souza Pessanha committed May 27, 2023
1 parent 14efe00 commit d542e41
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 53 deletions.
68 changes: 68 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
flake = false;
};

nvim-ts = {
url = "github:nvim-treesitter/nvim-treesitter";
flake = false;
};

nvim-ts-autotag = {
url = "github:windwp/nvim-ts-autotag";
flake = false;
};

nvim-ts-context = {
url = "github:nvim-treesitter/nvim-treesitter-context";
flake = false;
};

nvim-ts-rainbow = {
url = "github:HiPhish/nvim-ts-rainbow2";
flake = false;
};

nvim-surround = {
url = "github:kylechui/nvim-surround/v2.0.5";
flake = false;
Expand Down Expand Up @@ -141,6 +161,12 @@
name = "catppuccin";
flavour = "macchiato";
};
treesitter = {
enable = true;
autotag.enable = true;
context.enable = false;
rainbow.enable = true;
};
visuals = {
icons.enable = true;
cursorWordline.enable = true;
Expand Down
23 changes: 23 additions & 0 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,30 @@ in
pname = name;
version = last (splitString "/" (attrByPath [ name "url" ] "HEAD" inputs));
src = getAttr name inputs;
postPatch =
if (name == "nvim-treesitter")
then ''
rm -r parser
ln -s ${treesitterGrammars} parser
''
else "";
};
treesitterGrammars = pkgs.tree-sitter.withPlugins (p: with p; [
tree-sitter-bash
tree-sitter-c
tree-sitter-css
tree-sitter-dockerfile
tree-sitter-elixir
tree-sitter-html
tree-sitter-javascript
tree-sitter-json
tree-sitter-lua
tree-sitter-nix
tree-sitter-rust
tree-sitter-toml
tree-sitter-typescript
tree-sitter-yaml
]);
in
{
neovimPlugins = listToAttrs (map
Expand Down
106 changes: 53 additions & 53 deletions modules/completion.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,68 +26,68 @@ in
(withPlugins cfg.path.enable [ nvim-cmp-path ]) ++
(withPlugins cfg.buffer.enable [ nvim-cmp-buffer ]) ++
(withPlugins cfg.cmdline.enable [ nvim-cmp-cmdline ]) ++
(withPlugins isluasnip [ luasnip friendly-snippets ] ) ++
(withPlugins isluasnip [ luasnip friendly-snippets ]) ++
[ nvim-cmp ]
);
rawConfig = ''
-- NVIM CMP
-- NVIM CMP
${writeIf isluasnip ''
require('luasnip.loaders.from_vscode').lazy_load()
${writeIf isluasnip ''
require('luasnip.loaders.from_vscode').lazy_load()
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")
''}
local cmp = require('cmp')
local luasnip = require("luasnip")
''}
local cmp = require('cmp')
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false }),
${writeIf isluasnip ''
-- super tab editing
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false }),
${writeIf isluasnip ''
-- super tab editing
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
''}
}),
sources = cmp.config.sources({
${writeIf cfg.path.enable "{ name = 'path' },"}
${writeIf cfg.buffer.enable "{ name = 'buffer' },"}
${writeIf cfg.cmdline.enable "{ name = 'cmdline' },"}
${writeIf isluasnip "{ name = 'luasnip' },"}
}),
})
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
''}
}),
sources = cmp.config.sources({
${writeIf cfg.path.enable "{ name = 'path' },"}
${writeIf cfg.buffer.enable "{ name = 'buffer' },"}
${writeIf cfg.cmdline.enable "{ name = 'cmdline' },"}
${writeIf isluasnip "{ name = 'luasnip' },"}
}),
})
-- END NVIM CMP
-- END NVIM CMP
'';
};
}
1 change: 1 addition & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
./surround.nix
./telescope.nix
./theme.nix
./treesitter.nix
./visuals.nix
];
}
58 changes: 58 additions & 0 deletions modules/treesitter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{ pkgs, lib, config, ... }:

let
inherit (pkgs) neovimPlugins;
inherit (lib) mkEnableOption mkIf withPlugins writeIf;
cfg = config.lvim.treesitter;
in
{
options.lvim.treesitter = {
enable = mkEnableOption "Enables tree-sitter [nvim-treesitter]";
autotag.enable = mkEnableOption "Enables auto tagging";
context.enable = mkEnableOption "Enables block context";
rainbow.enable = mkEnableOption "Enables rainbow colored pairs";
};

config.lvim = mkIf cfg.enable {
startPlugins = with neovimPlugins; (
(withPlugins cfg.autotag.enable [ nvim-ts-autotag ]) ++
(withPlugins cfg.autotag.enable [ nvim-ts-context ]) ++
(withPlugins cfg.autotag.enable [ nvim-ts-rainbow ]) ++
[ nvim-ts ]
);
globals = {
"foldmethod" = "expr";
"foldexpr" = "nvim_treesitter#foldexpr()";
"nofoldenable" = 1;
};
rawConfig = ''
-- TRESSITTER
require('nvim-treesitter.configs').setup({
highlight = {
enable = true,
use_languagetree = true,
},
${writeIf cfg.rainbow.enable ''
rainbow = {
enable = true,
query = 'rainbow-parens',
strategy = require('ts-rainbow').strategy.global,
},
''}
${writeIf cfg.autotag.enable ''
autotag = {
enable = true,
},
''}
})
${writeIf cfg.context.enable ''
require'treesitter-context'.setup {
enable = true,
throttle = true,
max_lines = 0
}
''}
-- END TRESSITTER
'';
};
}

0 comments on commit d542e41

Please sign in to comment.