diff --git a/Makefile b/Makefile index a7433a3..0c96af8 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,54 @@ -pandocrepo = https://github.com/kdheepak/panvimdoc -pandocdir = misc/panvimdoc -TEST_DIR = test/github-theme -PLENARY_DIR = test/plenary -PLENARY_URL = https://github.com/nvim-lua/plenary.nvim/ +pandocrepo ::= https://github.com/kdheepak/panvimdoc +pandocdir ::= misc/panvimdoc +TEST_DIR ::= test/github-theme +PLENARY_DIR ::= test/plenary +PLENARY_URL ::= https://github.com/nvim-lua/plenary.nvim/ -root_dir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +root_dir ::= $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -.PHONY : all +.PHONY: all docgen test check fmt diagnose all: docgen test check -.PHONY : docgen docgen: $(pandocdir) - @pandoc \ - --citeproc \ - --shift-heading-level-by=0 \ - --metadata=project:github-nvim-theme \ - --metadata=vimversion:8.0 \ - --metadata=toc:true \ - --metadata="description:Github's Neovim themes" \ - --metadata=dedupsubheadings:true \ - --metadata=ignorerawblocks:true \ - --metadata=docmapping:true \ - --metadata=docmappingproject:true \ - --metadata=treesitter:true \ - --metadata=incrementheadinglevelby:0 \ - --lua-filter=misc/panvimdoc/scripts/skip-blocks.lua \ - --lua-filter=misc/panvimdoc/scripts/include-files.lua \ - -t misc/panvimdoc/scripts/panvimdoc.lua \ - -o doc/github-nvim-theme.txt \ - Usage.md + @pandoc \ + --citeproc \ + --shift-heading-level-by=0 \ + --metadata=project:github-nvim-theme \ + --metadata=vimversion:8.0 \ + --metadata=toc:true \ + --metadata="description:Github's Neovim themes" \ + --metadata=dedupsubheadings:true \ + --metadata=ignorerawblocks:true \ + --metadata=docmapping:true \ + --metadata=docmappingproject:true \ + --metadata=treesitter:true \ + --metadata=incrementheadinglevelby:0 \ + --lua-filter=misc/panvimdoc/scripts/skip-blocks.lua \ + --lua-filter=misc/panvimdoc/scripts/include-files.lua \ + -t misc/panvimdoc/scripts/panvimdoc.lua \bu + -o doc/github-nvim-theme.txt \ + Usage.md $(pandocdir): git clone --depth=1 --no-single-branch $(pandocrepo) $(pandocdir) @rm -rf doc/panvimdoc/.git -.PHONY : test test: $(PLENARY_DIR) nvim \ - --headless \ - --noplugin \ - -u test/minimal_init.vim \ - -c "PlenaryBustedDirectory $(TEST_DIR) { minimal_init = './test/minimal_init.vim', sequential = true }" + --headless \ + --noplugin \ + -u test/minimal_init.vim \ + -c "PlenaryBustedDirectory $(TEST_DIR) { minimal_init = './test/minimal_init.vim', sequential = true }" $(PLENARY_DIR): git clone --depth=1 --no-single-branch $(PLENARY_URL) $(PLENARY_DIR) @rm -rf $(PLENARY_DIR)/.git -.PHONY : check -check : +check: stylua --check lua/ test -f ./stylua.toml -.PHONY : fmt -fmt : +fmt: stylua lua/ test/ -f ./stylua.toml + +diagnose: + scripts/diagnose Hint diff --git a/scripts/diagnose b/scripts/diagnose new file mode 100755 index 0000000..05199b3 --- /dev/null +++ b/scripts/diagnose @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -eu + +# One of: Error, Warning, Information, or Hint +level="$1" + +export VIMRUNTIME="${VIMRUNTIME-"$(nvim -i NONE -es <<<'lua io.write(vim.env.VIMRUNTIME)')"}" +export LUA_LS="${LUA_LS-"$(which lua-language-server)"}" + +# Add vim's stdlib to library files, and never diagnose lib files (since ALL +# files will be `Opened` by the lsp to do the check). +extcfg=' +{ + workspace: { + library: [ $ENV.VIMRUNTIME, .workspace.library[] ] + }, + diagnostics: { ignoredFiles: "Disable", libraryFiles: "Disable" } +} +' + +jq=' + to_entries[] + | (.key | ltrimstr("file://") | ltrimstr($ENV.PWD)) as $f + | .value[] + | . as {range: {start: {line: $l, character: $c}, end: {line: $eL, character: $eC}}} + | [null, "error", "warning", "notice", "notice"][.severity] as $s + | "::\($s) file=\($f),line=\($l),col=\($c),endLine=\($eL),endColumn=\($eC),title=\(.code)::\(.message)" +' + +"$LUA_LS" \ + --check="$PWD" \ + --checklevel="$level" \ + --logpath=.log \ + --metapath=.meta \ + --configpath=<(jq ". * $extcfg" .luarc.json) + +if [ "${CI-no}" = no ]; then + jq -r 'to_entries[] | "\(.key):\(.value[] | "\(.range.start.line): \(.message)")", ""' .log/check.json +else + jq -r "$jq" .log/check.json +fi + +[ "$(jq 'isempty(.[]?)' .log/check.json)" = true ] || exit 1