Regenerate nvim config
This commit is contained in:
123
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/check-queries.lua
Executable file
123
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/check-queries.lua
Executable file
@ -0,0 +1,123 @@
|
||||
#!/nix/store/php4qidg2bxzmm79vpri025bqi0fa889-coreutils-9.5/bin/env -S -l
|
||||
vim.opt.rtp:prepend "./"
|
||||
|
||||
-- Equivalent to print(), but this will ensure consistent output regardless of
|
||||
-- operating system.
|
||||
local function io_print(text)
|
||||
if not text then
|
||||
text = ""
|
||||
end
|
||||
io.write(text, "\n")
|
||||
end
|
||||
|
||||
local function extract_captures()
|
||||
local lines = vim.fn.readfile "CONTRIBUTING.md"
|
||||
local captures = {}
|
||||
local current_query
|
||||
|
||||
for _, line in ipairs(lines) do
|
||||
if vim.startswith(line, "### ") then
|
||||
current_query = vim.fn.tolower(line:sub(5))
|
||||
elseif vim.startswith(line, "@") and current_query then
|
||||
if not captures[current_query] then
|
||||
captures[current_query] = {}
|
||||
end
|
||||
|
||||
table.insert(captures[current_query], vim.split(line:sub(2), " ", true)[1])
|
||||
end
|
||||
end
|
||||
|
||||
-- Complete captures for injections.
|
||||
local parsers = vim.tbl_keys(require("nvim-treesitter.parsers").list)
|
||||
for _, lang in pairs(parsers) do
|
||||
table.insert(captures["injections"], lang)
|
||||
end
|
||||
|
||||
return captures
|
||||
end
|
||||
|
||||
local function do_check()
|
||||
local timings = {}
|
||||
local queries = require "nvim-treesitter.query"
|
||||
local parsers = #_G.arg > 0 and { unpack(_G.arg) } or require("nvim-treesitter.info").installed_parsers()
|
||||
local query_types = queries.built_in_query_groups
|
||||
|
||||
local captures = extract_captures()
|
||||
local errors = {}
|
||||
|
||||
io_print "::group::Check parsers"
|
||||
|
||||
for _, lang in pairs(parsers) do
|
||||
timings[lang] = {}
|
||||
for _, query_type in pairs(query_types) do
|
||||
local before = vim.loop.hrtime()
|
||||
local ok, query = pcall(queries.get_query, lang, query_type)
|
||||
local after = vim.loop.hrtime()
|
||||
local duration = after - before
|
||||
table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
|
||||
io_print("Checking " .. lang .. " " .. query_type .. string.format(" (%.02fms)", duration * 1e-6))
|
||||
if not ok then
|
||||
local err_msg = lang .. " (" .. query_type .. "): " .. query
|
||||
errors[#errors + 1] = err_msg
|
||||
else
|
||||
if query then
|
||||
for _, capture in ipairs(query.captures) do
|
||||
local is_valid = (
|
||||
vim.startswith(capture, "_") -- Helpers.
|
||||
or vim.tbl_contains(captures[query_type], capture)
|
||||
)
|
||||
if not is_valid then
|
||||
local error = string.format("(x) Invalid capture @%s in %s for %s.", capture, query_type, lang)
|
||||
errors[#errors + 1] = error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
io_print "::endgroup::"
|
||||
|
||||
if #errors > 0 then
|
||||
io_print "\nCheck failed!\nErrors:"
|
||||
for _, err in ipairs(errors) do
|
||||
print(err)
|
||||
end
|
||||
error()
|
||||
end
|
||||
return timings
|
||||
end
|
||||
|
||||
local ok, result = pcall(do_check)
|
||||
local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or "", ",", true)
|
||||
|
||||
for k, v in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
|
||||
if not require("nvim-treesitter.parsers").has_parser(k) then
|
||||
-- On CI all parsers that can be installed from C files should be installed
|
||||
if
|
||||
vim.env.CI
|
||||
and not v.install_info.requires_generate_from_grammar
|
||||
and not vim.tbl_contains(allowed_to_fail, k)
|
||||
then
|
||||
io_print("Error: parser for " .. k .. " is not installed")
|
||||
vim.cmd "cq"
|
||||
else
|
||||
io_print("Warning: parser for " .. k .. " is not installed")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ok then
|
||||
io_print "::group::Timings"
|
||||
table.sort(result, function(a, b)
|
||||
return a.duration < b.duration
|
||||
end)
|
||||
for i, val in ipairs(result) do
|
||||
io_print(string.format("%i. %.02fms %s %s", #result - i + 1, val.duration * 1e-6, val.lang, val.query_type))
|
||||
end
|
||||
io_print "::endgroup::"
|
||||
io_print "Check successful!"
|
||||
vim.cmd "q"
|
||||
else
|
||||
vim.cmd "cq"
|
||||
end
|
||||
26
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/ci-install.sh
Executable file
26
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/ci-install.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
os=$(uname -s)
|
||||
if [[ $os == Linux ]]; then
|
||||
wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim-linux64.tar.gz
|
||||
tar -zxf nvim-linux64.tar.gz
|
||||
sudo ln -s "$PWD"/nvim-linux64/bin/nvim /usr/local/bin
|
||||
rm -rf "$PWD"/nvim-linux64/lib/nvim/parser
|
||||
mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
|
||||
ln -s "$PWD" ~/.local/share/nvim/site/pack/nvim-treesitter/start
|
||||
elif [[ $os == Darwin ]]; then
|
||||
RELEASE_NAME="nvim-macos-$(uname -m)"
|
||||
curl -L "https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/$RELEASE_NAME.tar.gz" | tar -xz
|
||||
sudo ln -s "$PWD/$RELEASE_NAME/bin/nvim" /usr/local/bin
|
||||
rm -rf "$PWD/$RELEASE_NAME/lib/nvim/parser"
|
||||
mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
|
||||
ln -s "$PWD" ~/.local/share/nvim/site/pack/nvim-treesitter/start
|
||||
else
|
||||
curl -L https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim-win64.zip -o nvim-win64.zip
|
||||
unzip nvim-win64
|
||||
mkdir -p ~/AppData/Local/nvim/pack/nvim-treesitter/start
|
||||
mkdir -p ~/AppData/Local/nvim-data
|
||||
cp -r "$PWD" ~/AppData/Local/nvim/pack/nvim-treesitter/start
|
||||
fi
|
||||
@ -0,0 +1,52 @@
|
||||
CFLAGS ?= -Os -std=c99 -fPIC
|
||||
CXX_STANDARD ?= c++14
|
||||
CXXFLAGS ?= -Os -std=$(CXX_STANDARD) -fPIC
|
||||
LDFLAGS ?=
|
||||
SRC_DIR ?= ./src
|
||||
DEST_DIR ?= ./dest
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
SHELL := powershell.exe
|
||||
.SHELLFLAGS := -NoProfile -command
|
||||
CP := Copy-Item -Recurse -ErrorAction SilentlyContinue
|
||||
MKDIR := New-Item -ItemType directory -ErrorAction SilentlyContinue
|
||||
TARGET := parser.dll
|
||||
rmf = Write-Output $(1) | foreach { if (Test-Path $$_) { Remove-Item -Force } }
|
||||
else
|
||||
CP := cp
|
||||
MKDIR := mkdir -p
|
||||
TARGET := parser.so
|
||||
rmf = rm -rf $(1)
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard $(SRC_DIR)/*.cc),)
|
||||
LDFLAGS += -lstdc++
|
||||
endif
|
||||
|
||||
OBJECTS := parser.o
|
||||
|
||||
ifneq ($(wildcard $(SRC_DIR)/scanner.*),)
|
||||
OBJECTS += scanner.o
|
||||
endif
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -o $(TARGET) -shared $(LDFLAGS)
|
||||
|
||||
%.o: $(SRC_DIR)/%.c
|
||||
$(CC) -c $(CFLAGS) -I$(SRC_DIR) -o $@ $<
|
||||
|
||||
%.o: $(SRC_DIR)/%.cc
|
||||
$(CC) -c $(CXXFLAGS) -I$(SRC_DIR) -o $@ $<
|
||||
|
||||
clean:
|
||||
$(call rmf,$(TARGET) $(OBJECTS))
|
||||
|
||||
$(DEST_DIR):
|
||||
@$(MKDIR) $(DEST_DIR)
|
||||
|
||||
install: $(TARGET) $(DEST_DIR)
|
||||
$(CP) $(TARGET) $(DEST_DIR)/
|
||||
|
||||
.PHONY: clean
|
||||
450
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/format-queries.lua
Executable file
450
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/format-queries.lua
Executable file
@ -0,0 +1,450 @@
|
||||
#!/nix/store/php4qidg2bxzmm79vpri025bqi0fa889-coreutils-9.5/bin/env -S -l
|
||||
|
||||
local ts = vim.treesitter
|
||||
local get_node_text = ts.get_node_text
|
||||
|
||||
---@type string[]
|
||||
local files
|
||||
|
||||
local arg = _G.arg[1] or "."
|
||||
if arg:match ".*%.scm$" then
|
||||
files = { arg }
|
||||
else
|
||||
files = vim.fn.split(vim.fn.glob(arg .. "/**/*.scm"))
|
||||
end
|
||||
|
||||
ts.query.add_predicate("has-type?", function(match, _, _, pred)
|
||||
local node = match[pred[2]]
|
||||
if not node then
|
||||
return true
|
||||
end
|
||||
|
||||
local types = { unpack(pred, 3) }
|
||||
return vim.tbl_contains(types, node:type())
|
||||
end, true)
|
||||
|
||||
ts.query.add_predicate("is-start-of-line?", function(match, _, _, pred)
|
||||
local node = match[pred[2]]
|
||||
if not node then
|
||||
return true
|
||||
end
|
||||
local start_row, start_col = node:start()
|
||||
return vim.fn.indent(start_row + 1) == start_col
|
||||
end)
|
||||
|
||||
--- Control the indent here. Change to \t if uses tab instead
|
||||
local indent_str = " "
|
||||
local textwidth = 100
|
||||
|
||||
-- Query to control the formatter
|
||||
local format_queries = [[
|
||||
;;query
|
||||
;; Ignore next node with `; format-ignore`
|
||||
(
|
||||
(comment) @_pattern
|
||||
.
|
||||
(_) @format.ignore
|
||||
(#lua-match? @_pattern "^;+%s*format%-ignore"))
|
||||
|
||||
;; {{{
|
||||
;; Add newlines to top level nodes
|
||||
;; {{{
|
||||
;; Preserve inline comments
|
||||
(program
|
||||
. (_)
|
||||
(comment) @format.prepend-newline
|
||||
(#is-start-of-line? @format.prepend-newline))
|
||||
(program
|
||||
. (_)
|
||||
(comment) @_comment
|
||||
.
|
||||
(comment) @format.prepend-newline
|
||||
(#not-is-start-of-line? @_comment)
|
||||
(#is-start-of-line? @format.prepend-newline))
|
||||
; Extra newline for modelines
|
||||
(program
|
||||
(comment) @_modeline
|
||||
.
|
||||
(_) @format.prepend-newline
|
||||
(#is-start-of-line? @_modeline)
|
||||
(#contains? @_modeline "^;+%s*inherits:"))
|
||||
(program
|
||||
(comment) @_modeline
|
||||
.
|
||||
(_) @format.prepend-newline
|
||||
(#is-start-of-line? @_modeline)
|
||||
(#contains? @_modeline "^;+%s*extends%s*$"))
|
||||
;; }}}
|
||||
;; Making sure all top-level patterns are separated
|
||||
(program
|
||||
(_) @format.append-newline)
|
||||
(program
|
||||
(_) @format.cancel-append .)
|
||||
(program
|
||||
. (_)
|
||||
[
|
||||
(list)
|
||||
(grouping)
|
||||
(named_node)
|
||||
(anonymous_node)
|
||||
(field_definition)
|
||||
] @format.prepend-newline)
|
||||
|
||||
(program
|
||||
(comment) @_comment
|
||||
.
|
||||
[
|
||||
(list)
|
||||
(grouping)
|
||||
(named_node)
|
||||
(anonymous_node)
|
||||
(field_definition)
|
||||
(comment)
|
||||
] @format.cancel-prepend
|
||||
(#is-start-of-line? @_comment)
|
||||
(#not-lua-match? @_comment "^;+%s*inherits:")
|
||||
(#not-lua-match? @_comment "^;+%s*extends%s*$"))
|
||||
;; }}}
|
||||
|
||||
;; delims
|
||||
[
|
||||
":"
|
||||
"."
|
||||
] @format.append-space
|
||||
(
|
||||
"." @format.prepend-space @format.cancel-append
|
||||
.
|
||||
")")
|
||||
|
||||
;; List handler
|
||||
;; Only starts indent if 2 or more elements
|
||||
(list
|
||||
"[" @format.indent.begin
|
||||
"]" @format.indent.dedent)
|
||||
;; Otherwise, remove brackets
|
||||
(list
|
||||
"[" @format.remove @format.cancel-append
|
||||
.
|
||||
(_) @format.cancel-append
|
||||
.
|
||||
"]" @format.remove)
|
||||
;; [ ... ] @capture1 @capture2
|
||||
;; Append newlines for nodes inside the list
|
||||
(list
|
||||
(_) @format.append-newline
|
||||
(#not-has-type? @format.append-newline capture quantifier))
|
||||
|
||||
;; (_), "_" and _ handler
|
||||
;; Start indents if it's one of these patterns
|
||||
(named_node
|
||||
[
|
||||
"_"
|
||||
name: (identifier)
|
||||
] @format.indent.begin
|
||||
.
|
||||
[
|
||||
(list) ; (foo [...])
|
||||
(grouping) ; (foo ((foo)))
|
||||
(negated_field) ; (foo !field)
|
||||
(field_definition) ; (foo field: (...))
|
||||
(named_node) ; (foo (bar))
|
||||
(predicate) ; (named_node (#set!))
|
||||
(anonymous_node)
|
||||
"."
|
||||
])
|
||||
;; Honoring comment's position within a node
|
||||
(named_node
|
||||
[
|
||||
"_"
|
||||
name: (identifier)
|
||||
] @format.indent.begin
|
||||
.
|
||||
(comment) @_comment
|
||||
(#is-start-of-line? @_comment))
|
||||
(named_node
|
||||
[
|
||||
"_"
|
||||
name: (identifier)
|
||||
] @format.indent.begin @format.cancel-append
|
||||
.
|
||||
"."? @format.prepend-newline
|
||||
.
|
||||
(comment) @format.prepend-space
|
||||
(#not-is-start-of-line? @format.prepend-space))
|
||||
|
||||
;; Add newlines for other nodes, in case the top node is indented
|
||||
(named_node
|
||||
[
|
||||
(list)
|
||||
(grouping)
|
||||
(negated_field)
|
||||
(field_definition)
|
||||
(named_node)
|
||||
(predicate)
|
||||
(anonymous_node)
|
||||
"."
|
||||
] @format.append-newline)
|
||||
|
||||
;; Collapse closing parentheses
|
||||
(named_node
|
||||
[
|
||||
"_"
|
||||
name: (identifier)
|
||||
(_)
|
||||
] @format.cancel-append
|
||||
.
|
||||
")"
|
||||
(#not-has-type? @format.cancel-append comment))
|
||||
|
||||
;; All captures should be separated with a space
|
||||
(capture) @format.prepend-space
|
||||
|
||||
;; Workaround to just use the string's content
|
||||
(anonymous_node (identifier) @format.keep)
|
||||
|
||||
; ( (_) ) handler
|
||||
(grouping
|
||||
"("
|
||||
.
|
||||
[
|
||||
(named_node) ; ((foo))
|
||||
(list) ; ([foo] (...))
|
||||
(anonymous_node) ; ("foo")
|
||||
(grouping . (_))
|
||||
] @format.indent.begin
|
||||
.
|
||||
(_))
|
||||
(grouping
|
||||
"("
|
||||
.
|
||||
(grouping) @format.indent.begin
|
||||
(predicate))
|
||||
(grouping
|
||||
"("
|
||||
[
|
||||
(anonymous_node)
|
||||
(named_node)
|
||||
(list)
|
||||
(predicate)
|
||||
(grouping . (_))
|
||||
"."
|
||||
] @format.append-newline
|
||||
(_) .)
|
||||
;; Collapsing closing parens
|
||||
(grouping
|
||||
(_) @format.cancel-append . ")"
|
||||
(#not-has-type? @format.cancel-append comment))
|
||||
(grouping
|
||||
(capture) @format.prepend-space)
|
||||
;; Remove unnecessary parens
|
||||
(grouping
|
||||
"(" @format.remove
|
||||
.
|
||||
(_)
|
||||
.
|
||||
")" @format.remove .)
|
||||
(grouping
|
||||
"(" @format.remove
|
||||
.
|
||||
[
|
||||
(anonymous_node
|
||||
name: (identifier) .)
|
||||
(named_node
|
||||
[
|
||||
"_"
|
||||
name: (identifier)
|
||||
] .)
|
||||
]
|
||||
.
|
||||
")" @format.remove
|
||||
.
|
||||
(capture))
|
||||
|
||||
; Separate this query to avoid capture duplication
|
||||
(predicate
|
||||
"(" @format.indent.begin @format.cancel-append)
|
||||
(predicate
|
||||
(parameters
|
||||
(comment) @format.prepend-newline
|
||||
.
|
||||
(_) @format.cancel-prepend)
|
||||
(#is-start-of-line? @format.prepend-newline))
|
||||
(predicate
|
||||
(parameters
|
||||
(_) @format.prepend-space)
|
||||
(#set! conditional-newline))
|
||||
(predicate
|
||||
(parameters
|
||||
.
|
||||
(capture)
|
||||
. (_) @format.prepend-space)
|
||||
(#set! lookahead-newline)
|
||||
(#set! conditional-newline))
|
||||
;; Workaround to keep the string's content
|
||||
(string) @format.keep
|
||||
|
||||
;; Comment related handlers
|
||||
(comment) @format.append-newline
|
||||
;; comment styling. Feel free to change in the future
|
||||
((comment) @format.replace
|
||||
(#gsub! @format.replace "^;+(%s*.-)%s*$" ";%1"))
|
||||
;; Preserve end of line comments
|
||||
(
|
||||
[
|
||||
"."
|
||||
":"
|
||||
(list)
|
||||
(grouping)
|
||||
(named_node)
|
||||
(anonymous_node)
|
||||
(negated_field)
|
||||
] @format.cancel-append
|
||||
.
|
||||
(quantifier)?
|
||||
.
|
||||
"."? @format.prepend-newline ; Make sure anchor are not eol but start of newline
|
||||
.
|
||||
(comment) @format.prepend-space
|
||||
(#not-is-start-of-line? @format.prepend-space))
|
||||
]]
|
||||
|
||||
---@param lines string[]
|
||||
---@param lines_to_append string[]
|
||||
local function append_lines(lines, lines_to_append)
|
||||
for i = 1, #lines_to_append, 1 do
|
||||
lines[#lines] = lines[#lines] .. lines_to_append[i]
|
||||
if i ~= #lines_to_append then
|
||||
lines[#lines + 1] = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param node TSNode
|
||||
---@param lines string[]
|
||||
---@param q table<string, TSMetadata>
|
||||
---@param level integer
|
||||
local function iter(bufnr, node, lines, q, level)
|
||||
--- Sometimes 2 queries apply append twice. This is to prevent the case from happening
|
||||
local apply_newline = false
|
||||
for child, _ in node:iter_children() do
|
||||
local id = child:id()
|
||||
repeat
|
||||
if apply_newline then
|
||||
apply_newline = false
|
||||
lines[#lines + 1] = string.rep(indent_str, level)
|
||||
end
|
||||
if q["format.ignore"][id] then
|
||||
local text = vim.split(get_node_text(child, bufnr):gsub("\r\n?", "\n"), "\n", { trimempty = true })
|
||||
append_lines(lines, text)
|
||||
break
|
||||
elseif q["format.remove"][id] then
|
||||
break
|
||||
end
|
||||
if not q["format.cancel-prepend"][id] then
|
||||
if q["format.prepend-newline"][id] then
|
||||
lines[#lines + 1] = string.rep(indent_str, level)
|
||||
elseif q["format.prepend-space"][id] then
|
||||
if not q["format.prepend-space"][id]["conditional-newline"] then
|
||||
lines[#lines] = lines[#lines] .. " "
|
||||
elseif child:byte_length() + 1 + #lines[#lines] > textwidth then
|
||||
lines[#lines + 1] = string.rep(indent_str, level)
|
||||
else
|
||||
-- Do a rough guess of the actual byte length. If it's larger than `columns` then add a newline first
|
||||
-- column - byte_end + byte_start
|
||||
local _, _, byte_start = child:start()
|
||||
local _, _, byte_end = node:end_()
|
||||
if
|
||||
q["format.prepend-space"][id]["lookahead-newline"]
|
||||
and textwidth - (byte_end - byte_start) - #lines[#lines] < 0
|
||||
then
|
||||
lines[#lines + 1] = string.rep(indent_str, level)
|
||||
else
|
||||
lines[#lines] = lines[#lines] .. " "
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if q["format.replace"][id] then
|
||||
append_lines(lines, vim.split(q["format.replace"][id].text, "\n", { trimempty = true }))
|
||||
elseif child:named_child_count() == 0 or q["format.keep"][id] then
|
||||
append_lines(
|
||||
lines,
|
||||
vim.split(string.gsub(get_node_text(child, bufnr), "\r\n?", "\n"), "\n+", { trimempty = true })
|
||||
)
|
||||
else
|
||||
iter(bufnr, child, lines, q, level)
|
||||
end
|
||||
if q["format.indent.begin"][id] then
|
||||
level = level + 1
|
||||
apply_newline = true
|
||||
break
|
||||
end
|
||||
if q["format.indent.dedent"][id] then
|
||||
if string.match(lines[#lines], "^%s*" .. get_node_text(child, bufnr)) then
|
||||
lines[#lines] = string.sub(lines[#lines], 1 + #string.rep(indent_str, 1))
|
||||
end
|
||||
end
|
||||
if q["format.indent.end"][id] then
|
||||
level = math.max(level - 1, 0)
|
||||
if string.match(lines[#lines], "^%s*" .. get_node_text(child, bufnr)) then
|
||||
lines[#lines] = string.sub(lines[#lines], 1 + #string.rep(indent_str, 1))
|
||||
end
|
||||
break
|
||||
end
|
||||
until true
|
||||
repeat
|
||||
if q["format.cancel-append"][id] then
|
||||
apply_newline = false
|
||||
end
|
||||
if not q["format.cancel-append"][id] then
|
||||
if q["format.append-newline"][id] then
|
||||
apply_newline = true
|
||||
elseif q["format.append-space"][id] then
|
||||
lines[#lines] = lines[#lines] .. " "
|
||||
end
|
||||
end
|
||||
until true
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param queries string
|
||||
local function format(bufnr, queries)
|
||||
local lines = { "" }
|
||||
-- stylua: ignore
|
||||
local map = {
|
||||
['format.ignore'] = {}, -- Ignore the node and its children
|
||||
['format.indent.begin'] = {}, -- +1 shiftwidth for all nodes after this
|
||||
['format.indent.end'] = {}, -- -1 shiftwidth for all nodes after this
|
||||
['format.indent.dedent'] = {}, -- -1 shiftwidth for this line only
|
||||
['format.prepend-space'] = {}, -- Prepend a space before inserting the node
|
||||
['format.prepend-newline'] = {}, -- Prepend a \n before inserting the node
|
||||
['format.append-space'] = {}, -- Append a space after inserting the node
|
||||
['format.append-newline'] = {}, -- Append a newline after inserting the node
|
||||
['format.cancel-append'] = {}, -- Cancel any `@format.append-*` applied to the node
|
||||
['format.cancel-prepend'] = {}, -- Cancel any `@format.prepend-*` applied to the node
|
||||
['format.keep'] = {}, -- String content is not exposed as a syntax node. This is a workaround for it
|
||||
['format.replace'] = {}, -- Dedicated capture used to store results of `(#gsub!)`
|
||||
['format.remove'] = {}, -- Do not add the syntax node to the result, i.e. brackets [], parens ()
|
||||
}
|
||||
local root = ts.get_parser(bufnr, "query"):parse(true)[1]:root()
|
||||
local query = ts.query.parse("query", queries)
|
||||
for id, node, metadata in query:iter_captures(root, bufnr) do
|
||||
if query.captures[id]:sub(1, 1) ~= "_" then
|
||||
map[query.captures[id]][node:id()] = metadata and (metadata[id] and metadata[id] or metadata) or {}
|
||||
end
|
||||
end
|
||||
|
||||
iter(bufnr, root, lines, map, 0)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
end
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
local buf = vim.fn.bufadd(file)
|
||||
vim.fn.bufload(file)
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
format(buf, format_queries)
|
||||
end
|
||||
|
||||
vim.cmd "silent wa!"
|
||||
@ -0,0 +1,25 @@
|
||||
vim.opt.runtimepath:append "."
|
||||
vim.cmd.runtime { "plugin/plenary.vim", bang = true }
|
||||
vim.cmd.runtime { "plugin/nvim-treesitter.lua", bang = true }
|
||||
|
||||
vim.filetype.add {
|
||||
extension = {
|
||||
conf = "hocon",
|
||||
cmm = "t32",
|
||||
hurl = "hurl",
|
||||
ncl = "nickel",
|
||||
tig = "tiger",
|
||||
usd = "usd",
|
||||
usda = "usd",
|
||||
wgsl = "wgsl",
|
||||
w = "wing",
|
||||
},
|
||||
}
|
||||
|
||||
vim.o.swapfile = false
|
||||
vim.bo.swapfile = false
|
||||
|
||||
require("nvim-treesitter.configs").setup {
|
||||
indent = { enable = true },
|
||||
highlight = { enable = true },
|
||||
}
|
||||
10
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/pre-push
Executable file
10
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/pre-push
Executable file
@ -0,0 +1,10 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
|
||||
# Can be used as a pre-push hook
|
||||
# Just symlink this file to .git/hooks/pre-push
|
||||
|
||||
echo "Running linter..."
|
||||
luacheck .
|
||||
|
||||
echo "Checking formatting..."
|
||||
stylua --check .
|
||||
16
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/run_tests.sh
Executable file
16
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/run_tests.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
|
||||
HERE="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
|
||||
cd $HERE/..
|
||||
|
||||
run() {
|
||||
nvim --headless --noplugin -u scripts/minimal_init.lua \
|
||||
-c "PlenaryBustedDirectory $1 { minimal_init = './scripts/minimal_init.lua' }"
|
||||
}
|
||||
|
||||
if [[ $2 = '--summary' ]]; then
|
||||
## really simple results summary by filtering plenary busted output
|
||||
run tests/$1 2> /dev/null | grep -E '^\S*(Testing|Success|Failed|Errors)\s*:'
|
||||
else
|
||||
run tests/$1
|
||||
fi
|
||||
18
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/update-lockfile.sh
Executable file
18
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/update-lockfile.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
|
||||
make_ignored() {
|
||||
if [[ -n $1 ]]; then
|
||||
while read -r lang; do
|
||||
if [[ $lang != "$1" ]]; then
|
||||
printf '%s,' "$lang"
|
||||
fi
|
||||
done < <(jq -r 'keys[]' lockfile.json)
|
||||
fi
|
||||
}
|
||||
|
||||
SKIP_LOCKFILE_UPDATE_FOR_LANGS="$(make_ignored "$1")" \
|
||||
nvim --headless -c 'luafile ./scripts/write-lockfile.lua' +q
|
||||
|
||||
# Pretty print
|
||||
cp lockfile.json /tmp/lockfile.json
|
||||
jq --sort-keys > lockfile.json < /tmp/lockfile.json
|
||||
59
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/update-readme.lua
Executable file
59
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/update-readme.lua
Executable file
@ -0,0 +1,59 @@
|
||||
#!/nix/store/php4qidg2bxzmm79vpri025bqi0fa889-coreutils-9.5/bin/env -S -l
|
||||
|
||||
---@class Parser
|
||||
---@field name string
|
||||
---@field parser ParserInfo
|
||||
|
||||
local parsers = require("nvim-treesitter.parsers").get_parser_configs()
|
||||
local sorted_parsers = {}
|
||||
|
||||
for k, v in pairs(parsers) do
|
||||
table.insert(sorted_parsers, { name = k, parser = v })
|
||||
end
|
||||
|
||||
---@param a Parser
|
||||
---@param b Parser
|
||||
table.sort(sorted_parsers, function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
|
||||
local generated_text = ""
|
||||
|
||||
---@param v Parser
|
||||
for _, v in ipairs(sorted_parsers) do
|
||||
local link = "[" .. (v.parser.readme_name or v.name) .. "](" .. v.parser.install_info.url .. ")"
|
||||
|
||||
if v.parser.maintainers then
|
||||
generated_text = generated_text
|
||||
.. "- [x] "
|
||||
.. link
|
||||
.. " ("
|
||||
.. (v.parser.experimental and "experimental, " or "")
|
||||
.. "maintained by "
|
||||
.. table.concat(v.parser.maintainers, ", ")
|
||||
.. ")\n"
|
||||
else
|
||||
generated_text = generated_text .. "- [ ] " .. link .. (v.parser.experimental and " (experimental)" or "") .. "\n"
|
||||
end
|
||||
end
|
||||
|
||||
print(generated_text)
|
||||
print "\n"
|
||||
|
||||
local readme_text = table.concat(vim.fn.readfile "README.md", "\n")
|
||||
|
||||
local new_readme_text = string.gsub(
|
||||
readme_text,
|
||||
"<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->",
|
||||
"<!--parserinfo-->\n" .. generated_text .. "<!--parserinfo-->"
|
||||
)
|
||||
vim.fn.writefile(vim.fn.split(new_readme_text, "\n"), "README.md")
|
||||
|
||||
if string.find(readme_text, generated_text, 1, true) then
|
||||
print "README.md is up-to-date!"
|
||||
vim.cmd "q"
|
||||
else
|
||||
print "New README.md was written. Please commit that change! Old text was: "
|
||||
print(string.sub(readme_text, string.find(readme_text, "<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->")))
|
||||
vim.cmd "cq"
|
||||
end
|
||||
14
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/write-lockfile.lua
Executable file
14
config/neovim/store/lazy-plugins/nvim-treesitter/scripts/write-lockfile.lua
Executable file
@ -0,0 +1,14 @@
|
||||
#!/nix/store/php4qidg2bxzmm79vpri025bqi0fa889-coreutils-9.5/bin/env -S -l
|
||||
|
||||
---@type string|any[]
|
||||
local skip_langs = vim.fn.getenv "SKIP_LOCKFILE_UPDATE_FOR_LANGS"
|
||||
|
||||
if skip_langs == vim.NIL then
|
||||
skip_langs = {}
|
||||
else
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
skip_langs = vim.fn.split(skip_langs, ",")
|
||||
end
|
||||
|
||||
require("nvim-treesitter.install").write_lockfile("verbose", skip_langs)
|
||||
vim.cmd "q"
|
||||
Reference in New Issue
Block a user