mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 19:30:02 -04:00
chore: remove useless code and indent files
This commit is contained in:
parent
91a89aa408
commit
9d57216c0d
10 changed files with 91 additions and 109 deletions
|
|
@ -187,9 +187,9 @@ end
|
||||||
-- for vim.inspect (https://github.com/kikito/inspect.lua#optionsprocess)
|
-- for vim.inspect (https://github.com/kikito/inspect.lua#optionsprocess)
|
||||||
local function config_info(process_function)
|
local function config_info(process_function)
|
||||||
process_function = process_function or function(item, path)
|
process_function = process_function or function(item, path)
|
||||||
if path[#path] == vim.inspect.METATABLE then return end
|
if path[#path] == vim.inspect.METATABLE then return end
|
||||||
if path[#path] == "is_supported" then return end
|
if path[#path] == "is_supported" then return end
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
print(vim.inspect(config, {process = process_function}))
|
print(vim.inspect(config, {process = process_function}))
|
||||||
end
|
end
|
||||||
|
|
@ -346,8 +346,8 @@ function M.attach_module(mod_name, bufnr, lang)
|
||||||
local resolved_mod = resolve_module(mod_name)
|
local resolved_mod = resolve_module(mod_name)
|
||||||
|
|
||||||
if resolved_mod
|
if resolved_mod
|
||||||
and not attached_buffers_by_module.has(mod_name, bufnr)
|
and not attached_buffers_by_module.has(mod_name, bufnr)
|
||||||
and M.is_enabled(mod_name, lang) then
|
and M.is_enabled(mod_name, lang) then
|
||||||
attached_buffers_by_module.set(mod_name, bufnr, true)
|
attached_buffers_by_module.set(mod_name, bufnr, true)
|
||||||
resolved_mod.attach(bufnr, lang)
|
resolved_mod.attach(bufnr, lang)
|
||||||
end
|
end
|
||||||
|
|
@ -393,7 +393,7 @@ end
|
||||||
function M.is_module(mod)
|
function M.is_module(mod)
|
||||||
return type(mod) == 'table'
|
return type(mod) == 'table'
|
||||||
and ((type(mod.attach) == 'function' and type(mod.detach) == 'function')
|
and ((type(mod.attach) == 'function' and type(mod.detach) == 'function')
|
||||||
or type(mod.module_path) == 'string')
|
or type(mod.module_path) == 'string')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Initializes built-in modules and any queued modules
|
-- Initializes built-in modules and any queued modules
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@ local function install_health()
|
||||||
health_start('Installation')
|
health_start('Installation')
|
||||||
if fn.executable('git') == 0 then
|
if fn.executable('git') == 0 then
|
||||||
health_error('`git` executable not found.', {
|
health_error('`git` executable not found.', {
|
||||||
'Install it with your package manager.',
|
'Install it with your package manager.',
|
||||||
'Check that your `$PATH` is set correctly.'
|
'Check that your `$PATH` is set correctly.'
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
health_ok('`git` executable found.')
|
health_ok('`git` executable found.')
|
||||||
end
|
end
|
||||||
|
|
@ -24,7 +24,7 @@ local function install_health()
|
||||||
if fn.executable('cc') == 0 then
|
if fn.executable('cc') == 0 then
|
||||||
health_error('`cc` executable not found.', {
|
health_error('`cc` executable not found.', {
|
||||||
'Check that either gcc or clang is in your $PATH'
|
'Check that either gcc or clang is in your $PATH'
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
health_ok('`cc` executable found.')
|
health_ok('`cc` executable found.')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ end
|
||||||
|
|
||||||
local function get_job_status()
|
local function get_job_status()
|
||||||
return "[nvim-treesitter] ["..finished_commands.."/"..started_commands
|
return "[nvim-treesitter] ["..finished_commands.."/"..started_commands
|
||||||
..(failed_commands > 0 and ", failed: "..failed_commands or "").."]"
|
..(failed_commands > 0 and ", failed: "..failed_commands or "").."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_revision(lang)
|
local function get_revision(lang)
|
||||||
|
|
@ -53,7 +53,7 @@ local function outdated_parsers()
|
||||||
return vim.tbl_filter(function(lang)
|
return vim.tbl_filter(function(lang)
|
||||||
return needs_update(lang)
|
return needs_update(lang)
|
||||||
end,
|
end,
|
||||||
info.installed_parsers())
|
info.installed_parsers())
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.iter_cmd(cmd_list, i, lang, success_message)
|
function M.iter_cmd(cmd_list, i, lang, success_message)
|
||||||
|
|
@ -76,7 +76,7 @@ function M.iter_cmd(cmd_list, i, lang, success_message)
|
||||||
failed_commands = failed_commands + 1
|
failed_commands = failed_commands + 1
|
||||||
finished_commands = finished_commands + 1
|
finished_commands = finished_commands + 1
|
||||||
return api.nvim_err_writeln((attr.err or ("Failed to execute the following command:\n"..vim.inspect(attr)))
|
return api.nvim_err_writeln((attr.err or ("Failed to execute the following command:\n"..vim.inspect(attr)))
|
||||||
..'\n'..vim.inspect(err))
|
..'\n'..vim.inspect(err))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local handle
|
local handle
|
||||||
|
|
@ -123,8 +123,8 @@ local function iter_cmd_sync(cmd_list)
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
print(ret)
|
print(ret)
|
||||||
api.nvim_err_writeln((cmd.err and cmd.err..'\n' or '')
|
api.nvim_err_writeln((cmd.err and cmd.err..'\n' or '')
|
||||||
.."Failed to execute the following command:\n"
|
.."Failed to execute the following command:\n"
|
||||||
..vim.inspect(cmd))
|
..vim.inspect(cmd))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -162,8 +162,8 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync,
|
||||||
local cc = shell.select_executable(M.compilers)
|
local cc = shell.select_executable(M.compilers)
|
||||||
if not cc then
|
if not cc then
|
||||||
api.nvim_err_writeln('No C compiler found! "'
|
api.nvim_err_writeln('No C compiler found! "'
|
||||||
..table.concat(vim.tbl_filter(function(c) return type(c) == 'string' end, M.compilers), '", "')
|
..table.concat(vim.tbl_filter(function(c) return type(c) == 'string' end, M.compilers), '", "')
|
||||||
..'" are not executable.')
|
..'" are not executable.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local revision = configs.get_update_strategy() == 'lockfile' and get_revision(lang)
|
local revision = configs.get_update_strategy() == 'lockfile' and get_revision(lang)
|
||||||
|
|
@ -283,8 +283,8 @@ function M.update(lang)
|
||||||
install(false, 'force')(lang)
|
install(false, 'force')(lang)
|
||||||
else
|
else
|
||||||
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
|
||||||
and outdated_parsers()
|
and outdated_parsers()
|
||||||
or info.installed_parsers()
|
or info.installed_parsers()
|
||||||
if #parsers_to_update == 0 then
|
if #parsers_to_update == 0 then
|
||||||
print('All parsers are up-to-date!')
|
print('All parsers are up-to-date!')
|
||||||
end
|
end
|
||||||
|
|
@ -353,7 +353,7 @@ function M.write_lockfile(verbose, skip_langs)
|
||||||
print(vim.inspect(lockfile))
|
print(vim.inspect(lockfile))
|
||||||
end
|
end
|
||||||
vim.fn.writefile(vim.fn.split(vim.fn.json_encode(lockfile), '\n'),
|
vim.fn.writefile(vim.fn.split(vim.fn.json_encode(lockfile), '\n'),
|
||||||
utils.join_path(utils.get_package_path(), "lockfile.json"))
|
utils.join_path(utils.get_package_path(), "lockfile.json"))
|
||||||
end
|
end
|
||||||
|
|
||||||
M.ensure_installed = install(false, false)
|
M.ensure_installed = install(false, false)
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ function M.get_definition_scopes(node, bufnr, scope_type)
|
||||||
-- and the containing scope of that scope
|
-- and the containing scope of that scope
|
||||||
if scope_type == 'parent' then
|
if scope_type == 'parent' then
|
||||||
scope_count = 2
|
scope_count = 2
|
||||||
-- Definition is valid in all parent scopes
|
-- Definition is valid in all parent scopes
|
||||||
elseif scope_type == 'global' then
|
elseif scope_type == 'global' then
|
||||||
scope_count = nil
|
scope_count = nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,12 @@ local list = setmetatable({}, {
|
||||||
|
|
||||||
rawset(table, parsername, setmetatable(parserconfig, {
|
rawset(table, parsername, setmetatable(parserconfig, {
|
||||||
__newindex = function(parserconfigtable, key, value)
|
__newindex = function(parserconfigtable, key, value)
|
||||||
if key == "used_by" then
|
rawset(parserconfigtable, key, value)
|
||||||
ft_to_parsername[value] = parsername
|
|
||||||
else
|
|
||||||
rawset(parserconfigtable, key, value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
}))
|
}))
|
||||||
|
|
||||||
update_ft_to_parsername(parsername, parserconfig)
|
update_ft_to_parsername(parsername, parserconfig)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
list.javascript = {
|
list.javascript = {
|
||||||
|
|
@ -264,13 +260,13 @@ list.scala = {
|
||||||
}
|
}
|
||||||
|
|
||||||
list.supercollider = {
|
list.supercollider = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = "https://github.com/madskjeldgaard/tree-sitter-supercollider",
|
url = "https://github.com/madskjeldgaard/tree-sitter-supercollider",
|
||||||
files = {"src/parser.c", "src/scanner.c"},
|
files = {"src/parser.c", "src/scanner.c"},
|
||||||
branch = "main",
|
branch = "main",
|
||||||
},
|
},
|
||||||
maintainers = {"@madskjeldgaard"},
|
maintainers = {"@madskjeldgaard"},
|
||||||
filetype = "supercollider",
|
filetype = "supercollider",
|
||||||
}
|
}
|
||||||
|
|
||||||
list.haskell = {
|
list.haskell = {
|
||||||
|
|
@ -463,20 +459,6 @@ function M.ft_to_lang(ft)
|
||||||
return ft_to_parsername[ft] or ft
|
return ft_to_parsername[ft] or ft
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.lang_to_ft(lang)
|
|
||||||
local obj = M.list[lang]
|
|
||||||
return vim.tbl_flatten({{obj.filetype or lang}, obj.used_by or {}})
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.lang_match_ft(lang, ft)
|
|
||||||
for _, f in pairs(M.lang_to_ft(lang)) do
|
|
||||||
if ft == f then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.available_parsers()
|
function M.available_parsers()
|
||||||
return vim.tbl_keys(M.list)
|
return vim.tbl_keys(M.list)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ do
|
||||||
|
|
||||||
local function update_cached_matches(bufnr, changed_tick, query_group)
|
local function update_cached_matches(bufnr, changed_tick, query_group)
|
||||||
query_cache.set(query_group, bufnr, {
|
query_cache.set(query_group, bufnr, {
|
||||||
tick = changed_tick,
|
tick = changed_tick,
|
||||||
cache= M.collect_group_results(bufnr, query_group) or {}
|
cache= M.collect_group_results(bufnr, query_group) or {}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -152,7 +152,7 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
|
||||||
end
|
end
|
||||||
if pred[1] == "make-range!" and type(pred[2]) == "string" and #pred == 4 then
|
if pred[1] == "make-range!" and type(pred[2]) == "string" and #pred == 4 then
|
||||||
insert_to_path(prepared_match, split(pred[2]..'.node'),
|
insert_to_path(prepared_match, split(pred[2]..'.node'),
|
||||||
tsrange.TSRange.from_nodes(bufnr, match[pred[3]], match[pred[4]]))
|
tsrange.TSRange.from_nodes(bufnr, match[pred[3]], match[pred[4]]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -167,53 +167,53 @@ end
|
||||||
-- Works like M.get_references or M.get_scopes except you can choose the capture
|
-- Works like M.get_references or M.get_scopes except you can choose the capture
|
||||||
-- Can also be a nested capture like @definition.function to get all nodes defining a function
|
-- Can also be a nested capture like @definition.function to get all nodes defining a function
|
||||||
function M.get_capture_matches(bufnr, capture_string, query_group)
|
function M.get_capture_matches(bufnr, capture_string, query_group)
|
||||||
if not string.sub(capture_string, 1,2) == '@' then
|
if not string.sub(capture_string, 1,2) == '@' then
|
||||||
print('capture_string must start with "@"')
|
print('capture_string must start with "@"')
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
--remove leading "@"
|
||||||
|
capture_string = string.sub(capture_string, 2)
|
||||||
|
|
||||||
|
local matches = {}
|
||||||
|
for match in M.iter_group_results(bufnr, query_group) do
|
||||||
|
local insert = utils.get_at_path(match, capture_string)
|
||||||
|
|
||||||
|
if insert then
|
||||||
|
table.insert(matches, insert)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
--remove leading "@"
|
return matches
|
||||||
capture_string = string.sub(capture_string, 2)
|
|
||||||
|
|
||||||
local matches = {}
|
|
||||||
for match in M.iter_group_results(bufnr, query_group) do
|
|
||||||
local insert = utils.get_at_path(match, capture_string)
|
|
||||||
|
|
||||||
if insert then
|
|
||||||
table.insert(matches, insert)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.find_best_match(bufnr, capture_string, query_group, filter_predicate, scoring_function)
|
function M.find_best_match(bufnr, capture_string, query_group, filter_predicate, scoring_function)
|
||||||
if not string.sub(capture_string, 1,2) == '@' then
|
if not string.sub(capture_string, 1,2) == '@' then
|
||||||
api.nvim_err_writeln('capture_string must start with "@"')
|
api.nvim_err_writeln('capture_string must start with "@"')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--remove leading "@"
|
--remove leading "@"
|
||||||
capture_string = string.sub(capture_string, 2)
|
capture_string = string.sub(capture_string, 2)
|
||||||
|
|
||||||
local best
|
local best
|
||||||
local best_score
|
local best_score
|
||||||
|
|
||||||
for maybe_match in M.iter_group_results(bufnr, query_group) do
|
for maybe_match in M.iter_group_results(bufnr, query_group) do
|
||||||
local match = utils.get_at_path(maybe_match, capture_string)
|
local match = utils.get_at_path(maybe_match, capture_string)
|
||||||
|
|
||||||
if match and filter_predicate(match) then
|
if match and filter_predicate(match) then
|
||||||
local current_score = scoring_function(match)
|
local current_score = scoring_function(match)
|
||||||
if not best then
|
if not best then
|
||||||
best = match
|
best = match
|
||||||
best_score = current_score
|
best_score = current_score
|
||||||
end
|
end
|
||||||
if current_score > best_score then
|
if current_score > best_score then
|
||||||
best = match
|
best = match
|
||||||
best_score = current_score
|
best_score = current_score
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return best
|
end
|
||||||
|
return best
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterates matches from a query file.
|
-- Iterates matches from a query file.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ function M.select_mkdir_cmd(directory, cwd, info_msg)
|
||||||
cmd = 'cmd',
|
cmd = 'cmd',
|
||||||
opts = {
|
opts = {
|
||||||
args = { '/C', 'mkdir', directory},
|
args = { '/C', 'mkdir', directory},
|
||||||
cwd = cwd,
|
cwd = cwd,
|
||||||
},
|
},
|
||||||
info = info_msg,
|
info = info_msg,
|
||||||
err = "Could not create "..directory,
|
err = "Could not create "..directory,
|
||||||
|
|
@ -19,7 +19,7 @@ function M.select_mkdir_cmd(directory, cwd, info_msg)
|
||||||
cmd = 'mkdir',
|
cmd = 'mkdir',
|
||||||
opts = {
|
opts = {
|
||||||
args = { directory },
|
args = { directory },
|
||||||
cwd = cwd,
|
cwd = cwd,
|
||||||
},
|
},
|
||||||
info = info_msg,
|
info = info_msg,
|
||||||
err = "Could not create "..directory,
|
err = "Could not create "..directory,
|
||||||
|
|
@ -55,13 +55,13 @@ end
|
||||||
|
|
||||||
function M.select_compiler_args(repo)
|
function M.select_compiler_args(repo)
|
||||||
local args = {
|
local args = {
|
||||||
'-o',
|
'-o',
|
||||||
'parser.so',
|
'parser.so',
|
||||||
'-I./src',
|
'-I./src',
|
||||||
repo.files,
|
repo.files,
|
||||||
'-shared',
|
'-shared',
|
||||||
'-Os',
|
'-Os',
|
||||||
'-lstdc++',
|
'-lstdc++',
|
||||||
}
|
}
|
||||||
if fn.has('win32') == 0 then
|
if fn.has('win32') == 0 then
|
||||||
table.insert(args, '-fPIC')
|
table.insert(args, '-fPIC')
|
||||||
|
|
@ -146,8 +146,8 @@ function M.select_download_commands(repo, project_name, cache_folder, revision)
|
||||||
},
|
},
|
||||||
M.select_rm_file_cmd(cache_folder..path_sep..project_name..".tar.gz"),
|
M.select_rm_file_cmd(cache_folder..path_sep..project_name..".tar.gz"),
|
||||||
M.select_mv_cmd(utils.join_path(project_name..'-tmp', repo.url:match('[^/]-$')..'-'..revision),
|
M.select_mv_cmd(utils.join_path(project_name..'-tmp', repo.url:match('[^/]-$')..'-'..revision),
|
||||||
project_name,
|
project_name,
|
||||||
cache_folder),
|
cache_folder),
|
||||||
M.select_install_rm_cmd(cache_folder, project_name..'-tmp')
|
M.select_install_rm_cmd(cache_folder, project_name..'-tmp')
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,7 @@ function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)
|
||||||
local char_delta = 0
|
local char_delta = 0
|
||||||
local line_delta = 0
|
local line_delta = 0
|
||||||
if range1["end"].line < range2.start.line
|
if range1["end"].line < range2.start.line
|
||||||
or (range1["end"].line == range2.start.line and range1["end"].character < range2.start.character) then
|
or (range1["end"].line == range2.start.line and range1["end"].character < range2.start.character) then
|
||||||
line_delta = #text2 - #text1
|
line_delta = #text2 - #text1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -269,7 +269,7 @@ function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)
|
||||||
|
|
||||||
-- add range1.start.character if last line of range1 (now text2) does not start at 0
|
-- add range1.start.character if last line of range1 (now text2) does not start at 0
|
||||||
if range1.start.line == range2.start.line + line_delta then
|
if range1.start.line == range2.start.line + line_delta then
|
||||||
char_delta = char_delta + range1.start.character
|
char_delta = char_delta + range1.start.character
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
char_delta = #(text2[#text2]) - #(text1[#text1])
|
char_delta = #(text2[#text2]) - #(text1[#text1])
|
||||||
|
|
@ -277,8 +277,8 @@ function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)
|
||||||
end
|
end
|
||||||
|
|
||||||
api.nvim_win_set_cursor(api.nvim_get_current_win(),
|
api.nvim_win_set_cursor(api.nvim_get_current_win(),
|
||||||
{range2.start.line + 1 + line_delta,
|
{range2.start.line + 1 + line_delta,
|
||||||
range2.start.character + char_delta})
|
range2.start.character + char_delta})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ local parsers = require'nvim-treesitter.parsers'
|
||||||
|
|
||||||
local function get_byte_offset(buf, row, col)
|
local function get_byte_offset(buf, row, col)
|
||||||
return api.nvim_buf_get_offset(buf, row)
|
return api.nvim_buf_get_offset(buf, row)
|
||||||
+ vim.fn.byteidx(api.nvim_buf_get_lines(buf, row, row + 1, false), col)
|
+ vim.fn.byteidx(api.nvim_buf_get_lines(buf, row, row + 1, false), col)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TSRange.new(buf, start_row, start_col, end_row, end_col)
|
function TSRange.new(buf, start_row, start_col, end_row, end_col)
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ function M.setup_commands(mod, commands)
|
||||||
for command_name, def in pairs(commands) do
|
for command_name, def in pairs(commands) do
|
||||||
local call_fn = string.format("lua require'nvim-treesitter.%s'.commands.%s.run(<f-args>)", mod, command_name)
|
local call_fn = string.format("lua require'nvim-treesitter.%s'.commands.%s.run(<f-args>)", mod, command_name)
|
||||||
local parts = vim.tbl_flatten({
|
local parts = vim.tbl_flatten({
|
||||||
"command!",
|
"command!",
|
||||||
def.args,
|
def.args,
|
||||||
command_name,
|
command_name,
|
||||||
call_fn,
|
call_fn,
|
||||||
})
|
})
|
||||||
api.nvim_command(table.concat(parts, " "))
|
api.nvim_command(table.concat(parts, " "))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue