apply fittings starter tree-sitter

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-05 18:08:21 +03:00
parent c266746eaa
commit 4790b9e302
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
38 changed files with 206 additions and 19 deletions

1
.envrc
View File

@ -1 +0,0 @@
eval "$(lorri direnv)"

4
.gitignore vendored
View File

@ -1 +1,3 @@
node_modules
#direnv
/.envrc
/.direnv/

View File

@ -1,12 +1,33 @@
.DEFAULT_GOAL := g
.PHONY: g t b
TS_CONF := $$HOME/.config/tree-sitter/config.json
g:
tree-sitter generate
t:
# @$(MAKE) --no-print-directory build
test: build
tree-sitter test
b:
tree-sitter test --update
highlight: build
tree-sitter highlight -t test/highlight/*
playground: build-wasm
tree-sitter playground --quiet
build-wasm: build
tree-sitter build-wasm
build:
tree-sitter generate
init: init-tree-sitter init-git-hooks
init-tree-sitter:
if [ ! -f "$(TS_CONF)" ]; then \
tree-sitter init-config; \
fi
if [ -z $$(jq '."parser-directories"' $(TS_CONF) | grep $$(dirname $$PWD) ) ]; then \
cat <<< $$(jq ".\"parser-directories\" |= . + [\"$$(dirname $(PWD))\"]" $(TS_CONF)) > $(TS_CONF); \
fi
init-git-hooks:
ln -s $(PWD)/scripts/pre-commit $(PWD)/.git/hooks/pre-commit
help:
cat Makefile

65
dev/nvim-ts.nix Normal file
View File

@ -0,0 +1,65 @@
{ pkgs ? import <nixpkgs> { } }:
let
extraGrammars = {
tree-sitter-plpgsql = {
language = "psql";
src = ../.;
version = "0.0.0";
};
};
tree-sitter = (pkgs.tree-sitter.override { inherit extraGrammars; });
grammars = tree-sitter.withPlugins (g: tree-sitter.allGrammars);
nvim-treesitter = pkgs.vimPlugins.nvim-treesitter.overrideAttrs (oldAttrs: {
postPatch = ''
rm -r parser
ln -s ${grammars} parser
ln -s ${../.}/queries queries/psql
'';
});
luaRc = ''
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.psql = {}
require("nvim-treesitter.configs").setup({
ensure_installed = { },
sync_install = false,
highlight = {
enable = true,
},
indent = {
enable = true,
},
})
vim.g.catppuccin_flavour = "frappe"
require("catppuccin").setup()
vim.cmd([[colorscheme catppuccin]])
'';
neovim = pkgs.neovim.override {
configure = {
customRC = ''
source ${./vimrc.vim}
lua <<EOF
${luaRc}
EOF
'';
packages.myPlugins.start = with pkgs.vimPlugins; [
nvim-treesitter
catppuccin-nvim
];
};
};
in
pkgs.runCommand "nvim-ts" { } ''
mkdir -p $out/bin
ln -s ${neovim}/bin/nvim $out/bin/nvim-ts
''

18
dev/vimrc.vim Normal file
View File

@ -0,0 +1,18 @@
" Basic settings for tests
set mouse=a
set number
set cursorline
set expandtab
set shiftwidth=2
set softtabstop=-1
set signcolumn=yes
set completeopt=menuone,noselect
set ttimeoutlen=1
set autoindent
" Always show statusline.
set laststatus=2
set statusline=%<%f\ %m%r%y\ %LL\ %=\ 0x%-4.B\ %-16.(%lL,%cC%V,%oB%)\ %P
" Detect d2 without d2-vim
au BufNewFile,BufRead *.d2 setfiletype d2

43
flake.lock Normal file
View File

@ -0,0 +1,43 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1672756850,
"narHash": "sha256-Smbq3+fitwA13qsTMeaaurv09/KVbZfW7m7lINwzDGA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "298add347c2bbce14020fcb54051f517c391196b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

25
flake.nix Normal file
View File

@ -0,0 +1,25 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
jq
nodejs-18_x
tree-sitter
nodePackages.eslint
nodePackages.prettier
nodePackages.vscode-langservers-extracted # html, css, json, eslint
(import ./dev/nvim-ts.nix { inherit pkgs; })
];
};
});
}

View File

@ -2,14 +2,14 @@
"name": "tree-sitter-plpgsql",
"version": "1.0.0",
"description": "",
"main": "bindings/node",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"main": "grammar.js",
"author": "",
"license": "ISC",
"dependencies": {
"nan": "^2.15.0",
"tree-sitter-cli": "^0.20.0"
}
"tree-sitter": [
{
"scope": "source.psql",
"file-types": ["psql"],
"injection-regex": "^psql$"
}
]
}

14
scripts/pre-commit Normal file
View File

@ -0,0 +1,14 @@
#! /usr/bin/env bash
# Can be used as a pre-commit hook
# Just symlink this file to .git/hooks/pre-commit
set -xe
if [ ! -z $(git diff --cached --name-only | grep -e "^grammar.js$") ]
then
make build
make build-wasm
git add src bindings *.wasm
fi