Skip to content

Commit 9f9bc89

Browse files
committed
chore: add make diagnose
- Add `make diagnose` which prints out all LSP diagnostics to stdout. It is also CI aware, in which case it will create CI annotations (but there's no workflow for it yet). - Cleanup Makefile
1 parent 5fa5e70 commit 9f9bc89

File tree

2 files changed

+78
-35
lines changed

2 files changed

+78
-35
lines changed

Makefile

+34-35
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
pandocrepo = https://github.com/kdheepak/panvimdoc
2-
pandocdir = misc/panvimdoc
3-
TEST_DIR = test/github-theme
4-
PLENARY_DIR = test/plenary
5-
PLENARY_URL = https://github.com/nvim-lua/plenary.nvim/
1+
pandocrepo ::= https://github.com/kdheepak/panvimdoc
2+
pandocdir ::= misc/panvimdoc
3+
TEST_DIR ::= test/github-theme
4+
PLENARY_DIR ::= test/plenary
5+
PLENARY_URL ::= https://github.com/nvim-lua/plenary.nvim/
66

7-
root_dir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
7+
root_dir ::= $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
88

9-
.PHONY : all
9+
.PHONY: all docgen test check fmt diagnose
1010
all: docgen test check
1111

12-
.PHONY : docgen
1312
docgen: $(pandocdir)
14-
@pandoc \
15-
--citeproc \
16-
--shift-heading-level-by=0 \
17-
--metadata=project:github-nvim-theme \
18-
--metadata=vimversion:8.0 \
19-
--metadata=toc:true \
20-
--metadata="description:Github's Neovim themes" \
21-
--metadata=dedupsubheadings:true \
22-
--metadata=ignorerawblocks:true \
23-
--metadata=docmapping:true \
24-
--metadata=docmappingproject:true \
25-
--metadata=treesitter:true \
26-
--metadata=incrementheadinglevelby:0 \
27-
--lua-filter=misc/panvimdoc/scripts/skip-blocks.lua \
28-
--lua-filter=misc/panvimdoc/scripts/include-files.lua \
29-
-t misc/panvimdoc/scripts/panvimdoc.lua \
30-
-o doc/github-nvim-theme.txt \
31-
Usage.md
13+
@pandoc \
14+
--citeproc \
15+
--shift-heading-level-by=0 \
16+
--metadata=project:github-nvim-theme \
17+
--metadata=vimversion:8.0 \
18+
--metadata=toc:true \
19+
--metadata="description:Github's Neovim themes" \
20+
--metadata=dedupsubheadings:true \
21+
--metadata=ignorerawblocks:true \
22+
--metadata=docmapping:true \
23+
--metadata=docmappingproject:true \
24+
--metadata=treesitter:true \
25+
--metadata=incrementheadinglevelby:0 \
26+
--lua-filter=misc/panvimdoc/scripts/skip-blocks.lua \
27+
--lua-filter=misc/panvimdoc/scripts/include-files.lua \
28+
-t misc/panvimdoc/scripts/panvimdoc.lua \bu
29+
-o doc/github-nvim-theme.txt \
30+
Usage.md
3231

3332
$(pandocdir):
3433
git clone --depth=1 --no-single-branch $(pandocrepo) $(pandocdir)
3534
@rm -rf doc/panvimdoc/.git
3635

37-
.PHONY : test
3836
test: $(PLENARY_DIR)
3937
nvim \
40-
--headless \
41-
--noplugin \
42-
-u test/minimal_init.vim \
43-
-c "PlenaryBustedDirectory $(TEST_DIR) { minimal_init = './test/minimal_init.vim', sequential = true }"
38+
--headless \
39+
--noplugin \
40+
-u test/minimal_init.vim \
41+
-c "PlenaryBustedDirectory $(TEST_DIR) { minimal_init = './test/minimal_init.vim', sequential = true }"
4442

4543
$(PLENARY_DIR):
4644
git clone --depth=1 --no-single-branch $(PLENARY_URL) $(PLENARY_DIR)
4745
@rm -rf $(PLENARY_DIR)/.git
4846

49-
.PHONY : check
50-
check :
47+
check:
5148
stylua --check lua/ test -f ./stylua.toml
5249

53-
.PHONY : fmt
54-
fmt :
50+
fmt:
5551
stylua lua/ test/ -f ./stylua.toml
52+
53+
diagnose:
54+
scripts/diagnose Hint

scripts/diagnose

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
# One of: Error, Warning, Information, or Hint
6+
level="$1"
7+
8+
export VIMRUNTIME="${VIMRUNTIME-"$(nvim -i NONE -es <<<'lua io.write(vim.env.VIMRUNTIME)')"}"
9+
export LUA_LS="${LUA_LS-"$(which lua-language-server)"}"
10+
11+
# Add vim's stdlib to library files, and never diagnose lib files (since ALL
12+
# files will be `Opened` by the lsp to do the check).
13+
extcfg='
14+
{
15+
workspace: {
16+
library: [ $ENV.VIMRUNTIME, .workspace.library[] ]
17+
},
18+
diagnostics: { ignoredFiles: "Disable", libraryFiles: "Disable" }
19+
}
20+
'
21+
22+
jq='
23+
to_entries[]
24+
| (.key | ltrimstr("file://") | ltrimstr($ENV.PWD)) as $f
25+
| .value[]
26+
| . as {range: {start: {line: $l, character: $c}, end: {line: $eL, character: $eC}}}
27+
| [null, "error", "warning", "notice", "notice"][.severity] as $s
28+
| "::\($s) file=\($f),line=\($l),col=\($c),endLine=\($eL),endColumn=\($eC),title=\(.code)::\(.message)"
29+
'
30+
31+
"$LUA_LS" \
32+
--check="$PWD" \
33+
--checklevel="$level" \
34+
--logpath=.log \
35+
--metapath=.meta \
36+
--configpath=<(jq ". * $extcfg" .luarc.json)
37+
38+
if [ "${CI-no}" = no ]; then
39+
jq -r 'to_entries[] | "\(.key):\(.value[] | "\(.range.start.line): \(.message)")", ""' .log/check.json
40+
else
41+
jq -r "$jq" .log/check.json
42+
fi
43+
44+
[ "$(jq 'isempty(.[]?)' .log/check.json)" = true ] || exit 1

0 commit comments

Comments
 (0)