chore: remove useless code and indent files

This commit is contained in:
kiyan 2021-02-22 23:01:12 +01:00 committed by Kiyan
parent 91a89aa408
commit 9d57216c0d
10 changed files with 91 additions and 109 deletions

View file

@ -187,9 +187,9 @@ end
-- for vim.inspect (https://github.com/kikito/inspect.lua#optionsprocess)
local function config_info(process_function)
process_function = process_function or function(item, path)
if path[#path] == vim.inspect.METATABLE then return end
if path[#path] == "is_supported" then return end
return item
if path[#path] == vim.inspect.METATABLE then return end
if path[#path] == "is_supported" then return end
return item
end
print(vim.inspect(config, {process = process_function}))
end
@ -346,8 +346,8 @@ function M.attach_module(mod_name, bufnr, lang)
local resolved_mod = resolve_module(mod_name)
if resolved_mod
and not attached_buffers_by_module.has(mod_name, bufnr)
and M.is_enabled(mod_name, lang) then
and not attached_buffers_by_module.has(mod_name, bufnr)
and M.is_enabled(mod_name, lang) then
attached_buffers_by_module.set(mod_name, bufnr, true)
resolved_mod.attach(bufnr, lang)
end
@ -393,7 +393,7 @@ end
function M.is_module(mod)
return type(mod) == 'table'
and ((type(mod.attach) == 'function' and type(mod.detach) == 'function')
or type(mod.module_path) == 'string')
or type(mod.module_path) == 'string')
end
-- Initializes built-in modules and any queued modules

View file

@ -14,9 +14,9 @@ local function install_health()
health_start('Installation')
if fn.executable('git') == 0 then
health_error('`git` executable not found.', {
'Install it with your package manager.',
'Check that your `$PATH` is set correctly.'
})
'Install it with your package manager.',
'Check that your `$PATH` is set correctly.'
})
else
health_ok('`git` executable found.')
end
@ -24,7 +24,7 @@ local function install_health()
if fn.executable('cc') == 0 then
health_error('`cc` executable not found.', {
'Check that either gcc or clang is in your $PATH'
})
})
else
health_ok('`cc` executable found.')
end

View file

@ -28,7 +28,7 @@ end
local function get_job_status()
return "[nvim-treesitter] ["..finished_commands.."/"..started_commands
..(failed_commands > 0 and ", failed: "..failed_commands or "").."]"
..(failed_commands > 0 and ", failed: "..failed_commands or "").."]"
end
local function get_revision(lang)
@ -53,7 +53,7 @@ local function outdated_parsers()
return vim.tbl_filter(function(lang)
return needs_update(lang)
end,
info.installed_parsers())
info.installed_parsers())
end
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
finished_commands = finished_commands + 1
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
else
local handle
@ -123,8 +123,8 @@ local function iter_cmd_sync(cmd_list)
if vim.v.shell_error ~= 0 then
print(ret)
api.nvim_err_writeln((cmd.err and cmd.err..'\n' or '')
.."Failed to execute the following command:\n"
..vim.inspect(cmd))
.."Failed to execute the following command:\n"
..vim.inspect(cmd))
return false
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)
if not cc then
api.nvim_err_writeln('No C compiler found! "'
..table.concat(vim.tbl_filter(function(c) return type(c) == 'string' end, M.compilers), '", "')
..'" are not executable.')
..table.concat(vim.tbl_filter(function(c) return type(c) == 'string' end, M.compilers), '", "')
..'" are not executable.')
return
end
local revision = configs.get_update_strategy() == 'lockfile' and get_revision(lang)
@ -283,8 +283,8 @@ function M.update(lang)
install(false, 'force')(lang)
else
local parsers_to_update = configs.get_update_strategy() == 'lockfile'
and outdated_parsers()
or info.installed_parsers()
and outdated_parsers()
or info.installed_parsers()
if #parsers_to_update == 0 then
print('All parsers are up-to-date!')
end
@ -353,7 +353,7 @@ function M.write_lockfile(verbose, skip_langs)
print(vim.inspect(lockfile))
end
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
M.ensure_installed = install(false, false)

View file

@ -192,7 +192,7 @@ function M.get_definition_scopes(node, bufnr, scope_type)
-- and the containing scope of that scope
if scope_type == 'parent' then
scope_count = 2
-- Definition is valid in all parent scopes
-- Definition is valid in all parent scopes
elseif scope_type == 'global' then
scope_count = nil
end

View file

@ -17,16 +17,12 @@ local list = setmetatable({}, {
rawset(table, parsername, setmetatable(parserconfig, {
__newindex = function(parserconfigtable, key, value)
if key == "used_by" then
ft_to_parsername[value] = parsername
else
rawset(parserconfigtable, key, value)
end
rawset(parserconfigtable, key, value)
end
}))
update_ft_to_parsername(parsername, parserconfig)
end
end
})
list.javascript = {
@ -264,13 +260,13 @@ list.scala = {
}
list.supercollider = {
install_info = {
url = "https://github.com/madskjeldgaard/tree-sitter-supercollider",
files = {"src/parser.c", "src/scanner.c"},
branch = "main",
},
maintainers = {"@madskjeldgaard"},
filetype = "supercollider",
install_info = {
url = "https://github.com/madskjeldgaard/tree-sitter-supercollider",
files = {"src/parser.c", "src/scanner.c"},
branch = "main",
},
maintainers = {"@madskjeldgaard"},
filetype = "supercollider",
}
list.haskell = {
@ -463,20 +459,6 @@ function M.ft_to_lang(ft)
return ft_to_parsername[ft] or ft
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()
return vim.tbl_keys(M.list)
end

View file

@ -26,8 +26,8 @@ do
local function update_cached_matches(bufnr, changed_tick, query_group)
query_cache.set(query_group, bufnr, {
tick = changed_tick,
cache= M.collect_group_results(bufnr, query_group) or {}
tick = changed_tick,
cache= M.collect_group_results(bufnr, query_group) or {}
})
end
@ -152,7 +152,7 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
end
if pred[1] == "make-range!" and type(pred[2]) == "string" and #pred == 4 then
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
@ -167,53 +167,53 @@ end
-- 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
function M.get_capture_matches(bufnr, capture_string, query_group)
if not string.sub(capture_string, 1,2) == '@' then
print('capture_string must start with "@"')
return
if not string.sub(capture_string, 1,2) == '@' then
print('capture_string must start with "@"')
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
--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
return matches
end
return matches
end
function M.find_best_match(bufnr, capture_string, query_group, filter_predicate, scoring_function)
if not string.sub(capture_string, 1,2) == '@' then
api.nvim_err_writeln('capture_string must start with "@"')
return
end
if not string.sub(capture_string, 1,2) == '@' then
api.nvim_err_writeln('capture_string must start with "@"')
return
end
--remove leading "@"
capture_string = string.sub(capture_string, 2)
--remove leading "@"
capture_string = string.sub(capture_string, 2)
local best
local best_score
local best
local best_score
for maybe_match in M.iter_group_results(bufnr, query_group) do
local match = utils.get_at_path(maybe_match, capture_string)
for maybe_match in M.iter_group_results(bufnr, query_group) do
local match = utils.get_at_path(maybe_match, capture_string)
if match and filter_predicate(match) then
local current_score = scoring_function(match)
if not best then
best = match
best_score = current_score
end
if current_score > best_score then
best = match
best_score = current_score
end
if match and filter_predicate(match) then
local current_score = scoring_function(match)
if not best then
best = match
best_score = current_score
end
if current_score > best_score then
best = match
best_score = current_score
end
end
return best
end
return best
end
-- Iterates matches from a query file.

View file

@ -9,7 +9,7 @@ function M.select_mkdir_cmd(directory, cwd, info_msg)
cmd = 'cmd',
opts = {
args = { '/C', 'mkdir', directory},
cwd = cwd,
cwd = cwd,
},
info = info_msg,
err = "Could not create "..directory,
@ -19,7 +19,7 @@ function M.select_mkdir_cmd(directory, cwd, info_msg)
cmd = 'mkdir',
opts = {
args = { directory },
cwd = cwd,
cwd = cwd,
},
info = info_msg,
err = "Could not create "..directory,
@ -55,13 +55,13 @@ end
function M.select_compiler_args(repo)
local args = {
'-o',
'parser.so',
'-I./src',
repo.files,
'-shared',
'-Os',
'-lstdc++',
'-o',
'parser.so',
'-I./src',
repo.files,
'-shared',
'-Os',
'-lstdc++',
}
if fn.has('win32') == 0 then
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_mv_cmd(utils.join_path(project_name..'-tmp', repo.url:match('[^/]-$')..'-'..revision),
project_name,
cache_folder),
project_name,
cache_folder),
M.select_install_rm_cmd(cache_folder, project_name..'-tmp')
}
else

View file

@ -253,7 +253,7 @@ function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)
local char_delta = 0
local line_delta = 0
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
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
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
else
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
api.nvim_win_set_cursor(api.nvim_get_current_win(),
{range2.start.line + 1 + line_delta,
range2.start.character + char_delta})
{range2.start.line + 1 + line_delta,
range2.start.character + char_delta})
end
end

View file

@ -7,7 +7,7 @@ local parsers = require'nvim-treesitter.parsers'
local function get_byte_offset(buf, row, col)
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
function TSRange.new(buf, start_row, start_col, end_row, end_col)

View file

@ -8,11 +8,11 @@ function M.setup_commands(mod, commands)
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 parts = vim.tbl_flatten({
"command!",
def.args,
command_name,
call_fn,
})
"command!",
def.args,
command_name,
call_fn,
})
api.nvim_command(table.concat(parts, " "))
end
end