feat(neovim): add hypr grammar

This commit is contained in:
matt1432 2023-11-24 20:59:07 -05:00
parent acc2d647f7
commit ced46f834d
3 changed files with 194 additions and 91 deletions

View file

@ -4,14 +4,22 @@
... ...
}: let }: let
# installs a vim plugin from git with a given tag / branch # installs a vim plugin from git with a given tag / branch
plugin = owner: repo: rev: hash: plugin = src:
pkgs.vimUtils.buildVimPlugin { pkgs.vimUtils.buildVimPlugin {
pname = "${lib.strings.sanitizeDerivationName repo}"; pname = "${lib.strings.sanitizeDerivationName src.repo}";
version = rev; version = src.rev;
src = pkgs.fetchFromGitHub { inherit src;
inherit rev owner repo hash;
};
}; };
buildGrammar = name: grammar:
pkgs.callPackage ./grammar.nix {} {
language = grammar.language or name;
version = grammar.src.rev;
src = grammar.src;
location = grammar.location or null;
generate = grammar.generate or false;
};
fileContents = lib.strings.fileContents; fileContents = lib.strings.fileContents;
in { in {
# TODO: make a gradle module and have java in device-vars.nix # TODO: make a gradle module and have java in device-vars.nix
@ -48,6 +56,7 @@ in {
nodePackages.npm nodePackages.npm
nodePackages.neovim nodePackages.neovim
gradle gradle
gcc
bat bat
@ -134,95 +143,122 @@ in {
extraConfig = fileContents ./base.vim; extraConfig = fileContents ./base.vim;
extraLuaConfig = fileContents ./base.lua; extraLuaConfig = fileContents ./base.lua;
plugins = with pkgs.vimPlugins; [ plugins = let
# Coc configured # custom packages
coc-css hypr-src = pkgs.fetchFromGitHub {
coc-eslint owner = "luckasRanarison";
coc-java repo = "tree-sitter-hypr";
coc-sh rev = "90b3ddf8a85b5ea3d9dc4920fddb16182a192e14";
coc-stylelintplus hash = "sha256-ErFs2eCC0eZEyDldrTUj4JJ0Eu+exDHNQx4g8WXh/UQ=";
{ };
plugin = coc-snippets;
type = "viml";
config = fileContents ./plugins/snippets.vim;
}
## Lua tree-sitter-hypr = plugin hypr-src;
coc-sumneko-lua
neodev-nvim
## Fzf hypr-grammar = buildGrammar "hypr" {
coc-fzf src = hypr-src;
fzfWrapper generate = true;
fzf-vim };
coc-highlight indent-blankline = plugin (pkgs.fetchFromGitHub {
coc-json owner = "lukas-reineke";
coc-pyright repo = "indent-blankline.nvim";
coc-vimlsp rev = "046e2cf04e08ece927bacbfb87c5b35c0b636546";
coc-yaml hash = "sha256-bhoep8aTYje5K/dZ/XmpwBPn4PBEMPrmw33QJdfFe6M=";
coc-toml });
coc-markdownlint in
coc-tsserver with pkgs.vimPlugins; [
fugitive # Coc configured
coc-css
coc-eslint
coc-java
coc-sh
coc-stylelintplus
{
plugin = coc-snippets;
type = "viml";
config = fileContents ./plugins/snippets.vim;
}
{ ## Lua
plugin = dracula-nvim; coc-sumneko-lua
type = "viml"; neodev-nvim
config = fileContents ./plugins/dracula.vim;
}
{
plugin = lualine-nvim;
type = "lua";
config = fileContents ./plugins/lualine.lua;
}
{
plugin = todo-comments-nvim;
type = "lua";
config = "require('todo-comments').setup()";
}
{
plugin = gitsigns-nvim;
type = "lua";
config = fileContents ./plugins/gitsigns.lua;
}
{
plugin = nvim-autopairs;
type = "lua";
config = fileContents ./plugins/autopairs.lua;
}
nvim-treesitter-context
nvim-treesitter-textobjects
{
plugin = nvim-treesitter.withAllGrammars;
type = "viml";
config = fileContents ./plugins/treesitter.vim;
}
{
plugin =
plugin "lukas-reineke" "indent-blankline.nvim"
"046e2cf04e08ece927bacbfb87c5b35c0b636546"
"sha256-bhoep8aTYje5K/dZ/XmpwBPn4PBEMPrmw33QJdfFe6M=";
type = "lua";
config = fileContents ./plugins/indent.lua;
}
{
plugin = mini-nvim;
type = "lua";
config = fileContents ./plugins/mini.lua;
}
{
plugin = neo-tree-nvim;
type = "viml";
config = ''
${fileContents ./plugins/neotree.vim}
lua << EOF ## Fzf
${fileContents ./plugins/neotree.lua} coc-fzf
EOF fzfWrapper
''; fzf-vim
}
]; coc-highlight
coc-json
coc-pyright
coc-vimlsp
coc-yaml
coc-toml
coc-markdownlint
coc-tsserver
fugitive
{
plugin = dracula-nvim;
type = "viml";
config = fileContents ./plugins/dracula.vim;
}
{
plugin = lualine-nvim;
type = "lua";
config = fileContents ./plugins/lualine.lua;
}
{
plugin = todo-comments-nvim;
type = "lua";
config = "require('todo-comments').setup()";
}
{
plugin = gitsigns-nvim;
type = "lua";
config = fileContents ./plugins/gitsigns.lua;
}
{
plugin = nvim-autopairs;
type = "lua";
config = fileContents ./plugins/autopairs.lua;
}
nvim-treesitter-context
nvim-treesitter-textobjects
{
plugin = tree-sitter-hypr;
type = "lua";
config = ''
vim.treesitter.language.require_language("hypr", "${hypr-grammar}/parser")
'';
}
{
plugin = nvim-treesitter.withAllGrammars;
type = "viml";
config = fileContents ./plugins/treesitter.vim;
}
{
plugin = indent-blankline;
type = "lua";
config = fileContents ./plugins/indent.lua;
}
{
plugin = mini-nvim;
type = "lua";
config = fileContents ./plugins/mini.lua;
}
{
plugin = neo-tree-nvim;
type = "viml";
config = ''
${fileContents ./plugins/neotree.vim}
lua << EOF
${fileContents ./plugins/neotree.lua}
EOF
'';
}
];
}; };
}; };
} }

View file

@ -0,0 +1,62 @@
{ stdenv
, nodejs
, tree-sitter
, lib
}:
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/parsing/tree-sitter/grammar.nix
# Build a parser grammar and put the resulting shared object in `$out/parser`
{
# language name
language
, version
, src
, location ? null
, generate ? false
, ...
}@args:
stdenv.mkDerivation ({
pname = "${language}-grammar";
inherit src version;
nativeBuildInputs = lib.optionals generate [ nodejs tree-sitter ];
CFLAGS = [ "-Isrc" "-O2" ];
CXXFLAGS = [ "-Isrc" "-O2" ];
stripDebugList = [ "parser" ];
configurePhase = lib.optionalString (location != null) ''
cd ${location}
'' + lib.optionalString generate ''
tree-sitter generate
'';
# When both scanner.{c,cc} exist, we should not link both since they may be the same but in
# different languages. Just randomly prefer C++ if that happens.
buildPhase = ''
runHook preBuild
if [[ -e src/scanner.cc ]]; then
$CXX -fPIC -c src/scanner.cc -o scanner.o $CXXFLAGS
elif [[ -e src/scanner.c ]]; then
$CC -fPIC -c src/scanner.c -o scanner.o $CFLAGS
fi
$CC -fPIC -c src/parser.c -o parser.o $CFLAGS
rm -rf parser
$CXX -shared -o parser *.o
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
mv parser $out/
if [[ -d queries ]]; then
cp -r queries $out
fi
runHook postInstall
'';
} // removeAttrs args [ "language" "location" "generate" ])

View file

@ -1,8 +1,12 @@
lua << EOF lua << EOF
local path = "/home/matt/.cache/nvim/"
require('nvim-treesitter.configs').setup({ require('nvim-treesitter.configs').setup({
highlight = { enable = true }, highlight = { enable = true },
indent = { enable = true } indent = { enable = true },
parser_install_dir = path,
auto_install = true,
}) })
require('treesitter-context').setup({ require('treesitter-context').setup({
@ -11,6 +15,7 @@ require('treesitter-context').setup({
min_window_height = 20, min_window_height = 20,
}) })
vim.opt.runtimepath:append(path)
EOF EOF
" Add line under context " Add line under context