Refresh generated neovim config
This commit is contained in:
@ -17,12 +17,19 @@ local function getline(lnum)
|
||||
return vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, false)[1] or ""
|
||||
end
|
||||
|
||||
---@param lnum integer
|
||||
---@return integer
|
||||
local function get_indentcols_at_line(lnum)
|
||||
local _, indentcols = getline(lnum):find "^%s*"
|
||||
return indentcols or 0
|
||||
end
|
||||
|
||||
---@param root TSNode
|
||||
---@param lnum integer
|
||||
---@param col? integer
|
||||
---@return TSNode
|
||||
local function get_first_node_at_line(root, lnum, col)
|
||||
col = col or vim.fn.indent(lnum)
|
||||
col = col or get_indentcols_at_line(lnum)
|
||||
return root:descendant_for_range(lnum - 1, col, lnum - 1, col + 1)
|
||||
end
|
||||
|
||||
@ -152,20 +159,20 @@ function M.get_indent(lnum)
|
||||
local node ---@type TSNode
|
||||
if is_empty_line then
|
||||
local prevlnum = vim.fn.prevnonblank(lnum)
|
||||
local indent = vim.fn.indent(prevlnum)
|
||||
local indentcols = get_indentcols_at_line(prevlnum)
|
||||
local prevline = vim.trim(getline(prevlnum))
|
||||
-- The final position can be trailing spaces, which should not affect indentation
|
||||
node = get_last_node_at_line(root, prevlnum, indent + #prevline - 1)
|
||||
node = get_last_node_at_line(root, prevlnum, indentcols + #prevline - 1)
|
||||
if node:type():match "comment" then
|
||||
-- The final node we capture of the previous line can be a comment node, which should also be ignored
|
||||
-- Unless the last line is an entire line of comment, ignore the comment range and find the last node again
|
||||
local first_node = get_first_node_at_line(root, prevlnum, indent)
|
||||
local first_node = get_first_node_at_line(root, prevlnum, indentcols)
|
||||
local _, scol, _, _ = node:range()
|
||||
if first_node:id() ~= node:id() then
|
||||
-- In case the last captured node is a trailing comment node, re-trim the string
|
||||
prevline = vim.trim(prevline:sub(1, scol - indent))
|
||||
prevline = vim.trim(prevline:sub(1, scol - indentcols))
|
||||
-- Add back indent as indent of prevline was trimmed away
|
||||
local col = indent + #prevline - 1
|
||||
local col = indentcols + #prevline - 1
|
||||
node = get_last_node_at_line(root, prevlnum, col)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,40 +1,16 @@
|
||||
local api = vim.api
|
||||
local ts = vim.treesitter
|
||||
|
||||
local new_lang_api = ts.language.register ~= nil
|
||||
|
||||
local filetype_to_parsername = {}
|
||||
|
||||
if new_lang_api then
|
||||
filetype_to_parsername = setmetatable({}, {
|
||||
__newindex = function(_, k, v)
|
||||
require("nvim-treesitter.utils").notify(
|
||||
"filetype_to_parsername is deprecated, please use 'vim.treesitter.language.register'",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
ts.language.register(v, k)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local function register_lang(lang, ft)
|
||||
if new_lang_api then
|
||||
ts.language.register(lang, ft)
|
||||
return
|
||||
end
|
||||
filetype_to_parsername[ft] = lang
|
||||
end
|
||||
|
||||
for ft, lang in pairs {
|
||||
automake = "make",
|
||||
javascriptreact = "javascript",
|
||||
ecma = "javascript",
|
||||
jsx = "javascript",
|
||||
sh = "bash",
|
||||
gyp = "python",
|
||||
html_tags = "html",
|
||||
["typescript.tsx"] = "tsx",
|
||||
["terraform-vars"] = "terraform",
|
||||
["html.handlebars"] = "glimmer",
|
||||
systemverilog = "verilog",
|
||||
pandoc = "markdown",
|
||||
rmd = "markdown",
|
||||
quarto = "markdown",
|
||||
@ -47,8 +23,20 @@ for ft, lang in pairs {
|
||||
mysql = "sql",
|
||||
sbt = "scala",
|
||||
neomuttrc = "muttrc",
|
||||
--- short-hand list from https://github.com/helix-editor/helix/blob/master/languages.toml
|
||||
rs = "rust",
|
||||
ex = "elixir",
|
||||
js = "javascript",
|
||||
ts = "typescript",
|
||||
["c-sharp"] = "csharp",
|
||||
hs = "haskell",
|
||||
py = "python",
|
||||
erl = "erlang",
|
||||
typ = "typst",
|
||||
pl = "perl",
|
||||
uxn = "uxntal",
|
||||
} do
|
||||
register_lang(lang, ft)
|
||||
ts.language.register(lang, ft)
|
||||
end
|
||||
|
||||
---@class InstallInfo
|
||||
@ -73,7 +61,7 @@ end
|
||||
local list = setmetatable({}, {
|
||||
__newindex = function(table, parsername, parserconfig)
|
||||
rawset(table, parsername, parserconfig)
|
||||
register_lang(parsername, parserconfig.filetype or parsername)
|
||||
ts.language.register(parsername, parserconfig.filetype or parsername)
|
||||
end,
|
||||
})
|
||||
|
||||
@ -99,6 +87,7 @@ list.angular = {
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
generate_requires_npm = true,
|
||||
},
|
||||
filetype = "htmlangular",
|
||||
maintainers = { "@dlvandenberg" },
|
||||
experimental = true,
|
||||
}
|
||||
@ -469,6 +458,14 @@ list.ebnf = {
|
||||
experimental = true,
|
||||
}
|
||||
|
||||
list.editorconfig = {
|
||||
install_info = {
|
||||
url = "https://github.com/ValdezFOmar/tree-sitter-editorconfig",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@ValdezFOmar" },
|
||||
}
|
||||
|
||||
list.eds = {
|
||||
install_info = {
|
||||
url = "https://github.com/uyha/tree-sitter-eds",
|
||||
@ -529,7 +526,7 @@ list.embedded_template = {
|
||||
list.erlang = {
|
||||
install_info = {
|
||||
url = "https://github.com/WhatsApp/tree-sitter-erlang",
|
||||
files = { "src/parser.c" },
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@filmor" },
|
||||
}
|
||||
@ -749,6 +746,14 @@ list.go = {
|
||||
maintainers = { "@theHamsta", "@WinWisely268" },
|
||||
}
|
||||
|
||||
list.goctl = {
|
||||
install_info = {
|
||||
url = "https://github.com/chaozwn/tree-sitter-goctl",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@chaozwn" },
|
||||
}
|
||||
|
||||
list.godot_resource = {
|
||||
install_info = {
|
||||
url = "https://github.com/PrestonKnopp/tree-sitter-godot-resource",
|
||||
@ -962,7 +967,7 @@ list.idl = {
|
||||
url = "https://github.com/cathaysia/tree-sitter-idl",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@cathaysa" },
|
||||
maintainers = { "@cathaysia" },
|
||||
}
|
||||
|
||||
list.ini = {
|
||||
@ -1327,6 +1332,14 @@ list.nasm = {
|
||||
maintainers = { "@ObserverOfTime" },
|
||||
}
|
||||
|
||||
list.nginx = {
|
||||
install_info = {
|
||||
url = "https://github.com/opa-oz/tree-sitter-nginx",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@opa-oz" },
|
||||
}
|
||||
|
||||
list.nickel = {
|
||||
install_info = {
|
||||
url = "https://github.com/nickel-lang/tree-sitter-nickel",
|
||||
@ -1445,7 +1458,7 @@ list.org = {
|
||||
|
||||
list.pascal = {
|
||||
install_info = {
|
||||
url = "https://github.com/Isopod/tree-sitter-pascal.git",
|
||||
url = "https://github.com/Isopod/tree-sitter-pascal",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@Isopod" },
|
||||
@ -1549,6 +1562,15 @@ list.pony = {
|
||||
maintainers = { "@amaanq", "@mfelsche" },
|
||||
}
|
||||
|
||||
list.powershell = {
|
||||
install_info = {
|
||||
url = "https://github.com/airbus-cert/tree-sitter-powershell",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
filetype = "ps1",
|
||||
maintainers = { "@L2jLiga" },
|
||||
}
|
||||
|
||||
list.printf = {
|
||||
install_info = {
|
||||
url = "https://github.com/ObserverOfTime/tree-sitter-printf",
|
||||
@ -1565,6 +1587,24 @@ list.prisma = {
|
||||
maintainers = { "@elianiva" },
|
||||
}
|
||||
|
||||
list.problog = {
|
||||
install_info = {
|
||||
url = "https://github.com/foxyseta/tree-sitter-prolog",
|
||||
files = { "src/parser.c" },
|
||||
location = "grammars/problog",
|
||||
},
|
||||
maintainers = { "@foxyseta" },
|
||||
}
|
||||
|
||||
list.prolog = {
|
||||
install_info = {
|
||||
url = "https://github.com/foxyseta/tree-sitter-prolog",
|
||||
files = { "src/parser.c" },
|
||||
location = "grammars/prolog",
|
||||
},
|
||||
maintainers = { "@foxyseta" },
|
||||
}
|
||||
|
||||
list.promql = {
|
||||
install_info = {
|
||||
url = "https://github.com/MichaHoffmann/tree-sitter-promql",
|
||||
@ -1689,7 +1729,7 @@ list.r = {
|
||||
url = "https://github.com/r-lib/tree-sitter-r",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@echasnovski" },
|
||||
maintainers = { "@ribru17" },
|
||||
}
|
||||
|
||||
list.racket = {
|
||||
@ -1764,6 +1804,14 @@ list.requirements = {
|
||||
readme_name = "pip requirements",
|
||||
}
|
||||
|
||||
list.rescript = {
|
||||
install_info = {
|
||||
url = "https://github.com/rescript-lang/tree-sitter-rescript",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@ribru17" },
|
||||
}
|
||||
|
||||
list.rnoweb = {
|
||||
install_info = {
|
||||
url = "https://github.com/bamonroe/tree-sitter-rnoweb",
|
||||
@ -1780,6 +1828,14 @@ list.robot = {
|
||||
maintainers = { "@Hubro" },
|
||||
}
|
||||
|
||||
list.robots = {
|
||||
install_info = {
|
||||
url = "https://github.com/opa-oz/tree-sitter-robots-txt",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@opa-oz" },
|
||||
}
|
||||
|
||||
list.roc = {
|
||||
install_info = {
|
||||
url = "https://github.com/faldor20/tree-sitter-roc",
|
||||
@ -1830,7 +1886,7 @@ list.scala = {
|
||||
|
||||
list.scfg = {
|
||||
install_info = {
|
||||
url = "https://git.sr.ht/~rockorager/tree-sitter-scfg",
|
||||
url = "https://github.com/rockorager/tree-sitter-scfg",
|
||||
files = { "src/parser.c" },
|
||||
requires_generate_from_grammar = true,
|
||||
},
|
||||
@ -1933,10 +1989,10 @@ list.sourcepawn = {
|
||||
|
||||
list.sparql = {
|
||||
install_info = {
|
||||
url = "https://github.com/BonaBeavis/tree-sitter-sparql",
|
||||
url = "https://github.com/GordianDziwis/tree-sitter-sparql",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@BonaBeavis" },
|
||||
maintainers = { "@GordianDziwis" },
|
||||
}
|
||||
|
||||
list.sql = {
|
||||
@ -2040,6 +2096,14 @@ list.systemtap = {
|
||||
maintainers = { "@ok-ryoko" },
|
||||
}
|
||||
|
||||
list.systemverilog = {
|
||||
install_info = {
|
||||
url = "https://github.com/zhangwwpeng/tree-sitter-systemverilog",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@zhangwwpeng" },
|
||||
}
|
||||
|
||||
list.t32 = {
|
||||
install_info = {
|
||||
url = "https://gitlab.com/xasc/tree-sitter-t32.git",
|
||||
@ -2135,7 +2199,7 @@ list.tmux = {
|
||||
|
||||
list.todotxt = {
|
||||
install_info = {
|
||||
url = "https://github.com/arnarg/tree-sitter-todotxt.git",
|
||||
url = "https://github.com/arnarg/tree-sitter-todotxt",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@arnarg" },
|
||||
@ -2173,10 +2237,10 @@ list.tsx = {
|
||||
|
||||
list.turtle = {
|
||||
install_info = {
|
||||
url = "https://github.com/BonaBeavis/tree-sitter-turtle",
|
||||
url = "https://github.com/GordianDziwis/tree-sitter-turtle",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@BonaBeavis" },
|
||||
maintainers = { "@GordianDziwis" },
|
||||
}
|
||||
|
||||
list.twig = {
|
||||
@ -2300,6 +2364,14 @@ list.verilog = {
|
||||
maintainers = { "@zegervdv" },
|
||||
}
|
||||
|
||||
list.vhdl = {
|
||||
install_info = {
|
||||
url = "https://github.com/jpt13653903/tree-sitter-vhdl",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@jpt13653903" },
|
||||
}
|
||||
|
||||
list.vhs = {
|
||||
install_info = {
|
||||
url = "https://github.com/charmbracelet/tree-sitter-vhs",
|
||||
@ -2326,6 +2398,14 @@ list.vimdoc = {
|
||||
maintainers = { "@clason" },
|
||||
}
|
||||
|
||||
list.vrl = {
|
||||
install_info = {
|
||||
url = "https://github.com/belltoy/tree-sitter-vrl",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@belltoy" },
|
||||
}
|
||||
|
||||
list.vue = {
|
||||
install_info = {
|
||||
url = "https://github.com/tree-sitter-grammars/tree-sitter-vue",
|
||||
@ -2435,23 +2515,15 @@ list.templ = {
|
||||
|
||||
local M = {
|
||||
list = list,
|
||||
filetype_to_parsername = filetype_to_parsername,
|
||||
}
|
||||
|
||||
local function get_lang(ft)
|
||||
if new_lang_api then
|
||||
return ts.language.get_lang(ft)
|
||||
end
|
||||
return filetype_to_parsername[ft]
|
||||
end
|
||||
|
||||
function M.ft_to_lang(ft)
|
||||
local result = get_lang(ft)
|
||||
local result = ts.language.get_lang(ft)
|
||||
if result then
|
||||
return result
|
||||
else
|
||||
ft = vim.split(ft, ".", { plain = true })[1]
|
||||
return get_lang(ft) or ft
|
||||
return ts.language.get_lang(ft) or ft
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -252,6 +252,7 @@ function M.select_download_commands(repo, project_name, cache_folder, revision,
|
||||
opts = {
|
||||
args = {
|
||||
"--silent",
|
||||
"--show-error",
|
||||
"-L", -- follow redirects
|
||||
is_github and url .. "/archive/" .. revision .. ".tar.gz"
|
||||
or url .. "/-/archive/" .. revision .. "/" .. project_name .. "-" .. revision .. ".tar.gz",
|
||||
@ -288,6 +289,31 @@ function M.select_download_commands(repo, project_name, cache_folder, revision,
|
||||
local git_folder = utils.join_path(cache_folder, project_name)
|
||||
local clone_error = "Error during download, please verify your internet connection"
|
||||
|
||||
-- Running `git clone` or `git checkout` while running under Git (such as
|
||||
-- editing a `git commit` message) will likely fail to install parsers
|
||||
-- (such as 'gitcommit') and can also corrupt the index file of the current
|
||||
-- Git repository. Check for typical git environment variables and abort if found.
|
||||
for _, k in pairs {
|
||||
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
||||
"GIT_CEILING_DIRECTORIES",
|
||||
"GIT_DIR",
|
||||
"GIT_INDEX",
|
||||
"GIT_INDEX_FILE",
|
||||
"GIT_OBJECT_DIRECTORY",
|
||||
"GIT_PREFIX",
|
||||
"GIT_WORK_TREE",
|
||||
} do
|
||||
if vim.uv.os_getenv(k) then
|
||||
vim.api.nvim_err_writeln(
|
||||
string.format(
|
||||
"Cannot install %s with git in an active git session. Exit the session and run ':TSInstall %s' manually",
|
||||
project_name
|
||||
)
|
||||
)
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
cmd = "git",
|
||||
|
||||
@ -57,13 +57,13 @@ function M._get_line_for_node(node, type_patterns, transform_fn, bufnr)
|
||||
end
|
||||
|
||||
-- Gets the actual text content of a node
|
||||
-- @deprecated Use vim.treesitter.query.get_node_text
|
||||
-- @deprecated Use vim.treesitter.get_node_text
|
||||
-- @param node the node to get the text from
|
||||
-- @param bufnr the buffer containing the node
|
||||
-- @return list of lines of text of the node
|
||||
function M.get_node_text(node, bufnr)
|
||||
vim.notify_once(
|
||||
"nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.query.get_node_text",
|
||||
"nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.get_node_text",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return get_node_text(node, bufnr)
|
||||
|
||||
Reference in New Issue
Block a user