From 4790b9e302e495cbccbb762478133992f1999c40 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 5 Jan 2023 18:08:21 +0300 Subject: [PATCH] apply fittings starter tree-sitter --- .envrc | 1 - .gitignore | 4 +- Makefile | 39 ++++++++--- dev/nvim-ts.nix | 65 +++++++++++++++++++ dev/vimrc.vim | 18 +++++ flake.lock | 43 ++++++++++++ flake.nix | 25 +++++++ package.json | 16 ++--- scripts/pre-commit | 14 ++++ .../corpus}/alter_table_statement.txt | 0 .../corpus}/create_function/general.txt | 0 .../corpus}/create_function/parameters.txt | 0 .../corpus}/create_index_statement.txt | 0 .../corpus}/create_schema_statement.txt | 0 .../corpus}/create_sequence_statement.txt | 0 .../corpus}/create_table_statement.txt | 0 .../corpus}/create_trigger_statement.txt | 0 .../corpus}/create_type_statement.txt | 0 {corpus => test/corpus}/delete_statement.txt | 0 .../corpus}/drop_function_statement.txt | 0 .../corpus}/drop_type_statement.txt | 0 {corpus => test/corpus}/execute_statement.txt | 0 {corpus => test/corpus}/grant_statement.txt | 0 .../corpus}/insert_statement/insert.txt | 0 .../corpus}/insert_statement/on_conflict.txt | 0 {corpus => test/corpus}/plpgsql/block.txt | 0 .../corpus}/plpgsql/for_statement.txt | 0 .../plpgsql/get_diagnostics_statement.txt | 0 .../corpus}/plpgsql/if_statement.txt | 0 .../corpus}/plpgsql/open_cursor_statement.txt | 0 .../corpus}/plpgsql/raise_statement.txt | 0 .../corpus}/plpgsql/return_statement.txt | 0 .../corpus}/select_statement/from.txt | 0 .../corpus}/select_statement/join.txt | 0 .../corpus}/select_statement/select.txt | 0 .../select_statement/value_expression.txt | 0 {corpus => test/corpus}/update_statement.txt | 0 {corpus => test/corpus}/with_statement.txt | 0 38 files changed, 206 insertions(+), 19 deletions(-) delete mode 100644 .envrc create mode 100644 dev/nvim-ts.nix create mode 100644 dev/vimrc.vim create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 scripts/pre-commit rename {corpus => test/corpus}/alter_table_statement.txt (100%) rename {corpus => test/corpus}/create_function/general.txt (100%) rename {corpus => test/corpus}/create_function/parameters.txt (100%) rename {corpus => test/corpus}/create_index_statement.txt (100%) rename {corpus => test/corpus}/create_schema_statement.txt (100%) rename {corpus => test/corpus}/create_sequence_statement.txt (100%) rename {corpus => test/corpus}/create_table_statement.txt (100%) rename {corpus => test/corpus}/create_trigger_statement.txt (100%) rename {corpus => test/corpus}/create_type_statement.txt (100%) rename {corpus => test/corpus}/delete_statement.txt (100%) rename {corpus => test/corpus}/drop_function_statement.txt (100%) rename {corpus => test/corpus}/drop_type_statement.txt (100%) rename {corpus => test/corpus}/execute_statement.txt (100%) rename {corpus => test/corpus}/grant_statement.txt (100%) rename {corpus => test/corpus}/insert_statement/insert.txt (100%) rename {corpus => test/corpus}/insert_statement/on_conflict.txt (100%) rename {corpus => test/corpus}/plpgsql/block.txt (100%) rename {corpus => test/corpus}/plpgsql/for_statement.txt (100%) rename {corpus => test/corpus}/plpgsql/get_diagnostics_statement.txt (100%) rename {corpus => test/corpus}/plpgsql/if_statement.txt (100%) rename {corpus => test/corpus}/plpgsql/open_cursor_statement.txt (100%) rename {corpus => test/corpus}/plpgsql/raise_statement.txt (100%) rename {corpus => test/corpus}/plpgsql/return_statement.txt (100%) rename {corpus => test/corpus}/select_statement/from.txt (100%) rename {corpus => test/corpus}/select_statement/join.txt (100%) rename {corpus => test/corpus}/select_statement/select.txt (100%) rename {corpus => test/corpus}/select_statement/value_expression.txt (100%) rename {corpus => test/corpus}/update_statement.txt (100%) rename {corpus => test/corpus}/with_statement.txt (100%) diff --git a/.envrc b/.envrc deleted file mode 100644 index 051d09d..0000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -eval "$(lorri direnv)" diff --git a/.gitignore b/.gitignore index 3c3629e..5bcf74c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules +#direnv +/.envrc +/.direnv/ \ No newline at end of file diff --git a/Makefile b/Makefile index fdb49d7..00c9b5c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/dev/nvim-ts.nix b/dev/nvim-ts.nix new file mode 100644 index 0000000..ffa7143 --- /dev/null +++ b/dev/nvim-ts.nix @@ -0,0 +1,65 @@ +{ pkgs ? import { } }: + +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 <