mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-13 08:50:11 -04:00
Make luacheck happy
This commit is contained in:
parent
77f723acd7
commit
2c4a1d36d8
10 changed files with 23 additions and 43 deletions
|
|
@ -130,7 +130,7 @@ local function disable_mod_conf_autocmd(mod, lang)
|
||||||
|
|
||||||
if not config_mod or not M.is_enabled(mod, lang) then return end
|
if not config_mod or not M.is_enabled(mod, lang) then return end
|
||||||
|
|
||||||
local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod)
|
--local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod)
|
||||||
-- TODO(kyazdani): detach the correct autocmd... doesn't work when using %s, cmd
|
-- TODO(kyazdani): detach the correct autocmd... doesn't work when using %s, cmd
|
||||||
for _, ft in pairs(parsers.lang_to_ft(lang)) do
|
for _, ft in pairs(parsers.lang_to_ft(lang)) do
|
||||||
api.nvim_command(string.format("autocmd! NvimTreesitter FileType %s", ft))
|
api.nvim_command(string.format("autocmd! NvimTreesitter FileType %s", ft))
|
||||||
|
|
@ -260,7 +260,7 @@ function M.setup_module(mod, data, mod_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif type(data) == 'table' and type(mod) == 'table' then
|
elseif type(data) == 'table' and type(mod) == 'table' then
|
||||||
for key, value in pairs(data) do
|
for key, value in pairs(data) do
|
||||||
M.setup_module(mod[key], value, key)
|
M.setup_module(mod[key], value, key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -289,7 +289,7 @@ end
|
||||||
-- A module should contain an 'is_supported' function.
|
-- A module should contain an 'is_supported' function.
|
||||||
-- @param mod the module table
|
-- @param mod the module table
|
||||||
function M.is_module(mod)
|
function M.is_module(mod)
|
||||||
return type(mod) == 'table' and type(mod.is_supported) == 'function'
|
return type(mod) == 'table' and type(mod.is_supported) == 'function'
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
local api = vim.api
|
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
local parsers = require'nvim-treesitter.parsers'
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
@ -21,7 +20,7 @@ function M.get_fold_indic(lnum)
|
||||||
|
|
||||||
local parser = parsers.get_parser()
|
local parser = parsers.get_parser()
|
||||||
|
|
||||||
local multiline_here, level = smallest_multiline_containing(parser:parse():root(), 0)
|
local _, level = smallest_multiline_containing(parser:parse():root(), 0)
|
||||||
|
|
||||||
return tostring(level)
|
return tostring(level)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,10 @@ local api = vim.api
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
local queries = require'nvim-treesitter.query'
|
local queries = require'nvim-treesitter.query'
|
||||||
local locals = require'nvim-treesitter.locals'
|
|
||||||
local highlight = require'nvim-treesitter.highlight'
|
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
local parsers = require'nvim-treesitter.parsers'
|
||||||
|
|
||||||
local health_start = vim.fn["health#report_start"]
|
local health_start = vim.fn["health#report_start"]
|
||||||
local health_ok = vim.fn['health#report_ok']
|
local health_ok = vim.fn['health#report_ok']
|
||||||
local health_info = vim.fn['health#report_info']
|
|
||||||
local health_warn = vim.fn['health#report_warn']
|
local health_warn = vim.fn['health#report_warn']
|
||||||
local health_error = vim.fn['health#report_error']
|
local health_error = vim.fn['health#report_error']
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ local function select_incremental(get_parent)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
node = get_parent(nodes[#nodes])
|
local node = get_parent(nodes[#nodes])
|
||||||
if not node then return end
|
if not node then return end
|
||||||
|
|
||||||
if node ~= nodes[#nodes] then
|
if node ~= nodes[#nodes] then
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
-- Locals are a generalization of definition and scopes
|
-- Locals are a generalization of definition and scopes
|
||||||
-- its the way nvim-treesitter uses to "understand" the code
|
-- its the way nvim-treesitter uses to "understand" the code
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local ts = vim.treesitter
|
|
||||||
|
|
||||||
local queries = require'nvim-treesitter.query'
|
local queries = require'nvim-treesitter.query'
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
local parsers = require'nvim-treesitter.parsers'
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
-- This module highlights reference usages and the corresponding
|
-- This module highlights reference usages and the corresponding
|
||||||
-- definition on cursor hold.
|
-- definition on cursor hold.
|
||||||
|
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
|
||||||
local ts_utils = require'nvim-treesitter.ts_utils'
|
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||||
local locals = require'nvim-treesitter.locals'
|
local locals = require'nvim-treesitter.locals'
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
@ -17,7 +16,7 @@ function M.highlight_usages(bufnr)
|
||||||
local node_at_point = ts_utils.get_node_at_cursor()
|
local node_at_point = ts_utils.get_node_at_cursor()
|
||||||
local references = locals.get_references(bufnr)
|
local references = locals.get_references(bufnr)
|
||||||
|
|
||||||
if not node_at_point or not vim.tbl_contains(references, node_at_point) then
|
if not node_at_point or not vim.tbl_contains(references, node_at_point) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,9 +28,9 @@ function M.highlight_usages(bufnr)
|
||||||
|
|
||||||
if usage_node ~= node_at_point then
|
if usage_node ~= node_at_point then
|
||||||
api.nvim_buf_add_highlight(
|
api.nvim_buf_add_highlight(
|
||||||
bufnr,
|
bufnr,
|
||||||
usage_namespace,
|
usage_namespace,
|
||||||
'TSDefinitionUsage',
|
'TSDefinitionUsage',
|
||||||
start_row,
|
start_row,
|
||||||
start_col,
|
start_col,
|
||||||
end_col)
|
end_col)
|
||||||
|
|
@ -42,9 +41,9 @@ function M.highlight_usages(bufnr)
|
||||||
local start_row, start_col, _, end_col = def_node:range()
|
local start_row, start_col, _, end_col = def_node:range()
|
||||||
|
|
||||||
api.nvim_buf_add_highlight(
|
api.nvim_buf_add_highlight(
|
||||||
bufnr,
|
bufnr,
|
||||||
usage_namespace,
|
usage_namespace,
|
||||||
'TSDefinition',
|
'TSDefinition',
|
||||||
start_row,
|
start_row,
|
||||||
start_col,
|
start_col,
|
||||||
end_col)
|
end_col)
|
||||||
|
|
@ -60,9 +59,11 @@ function M.attach(bufnr)
|
||||||
|
|
||||||
cmd(string.format('augroup NvimTreesitterUsages_%d', bufnr))
|
cmd(string.format('augroup NvimTreesitterUsages_%d', bufnr))
|
||||||
cmd 'au!'
|
cmd 'au!'
|
||||||
|
-- luacheck: push ignore 631
|
||||||
cmd(string.format([[autocmd CursorHold <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.highlight_usages(%d)]], bufnr, bufnr))
|
cmd(string.format([[autocmd CursorHold <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.highlight_usages(%d)]], bufnr, bufnr))
|
||||||
cmd(string.format([[autocmd CursorMoved <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.clear_usage_highlights(%d)]], bufnr, bufnr))
|
cmd(string.format([[autocmd CursorMoved <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.clear_usage_highlights(%d)]], bufnr, bufnr))
|
||||||
cmd(string.format([[autocmd InsertEnter <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.clear_usage_highlights(%d)]], bufnr, bufnr))
|
cmd(string.format([[autocmd InsertEnter <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.clear_usage_highlights(%d)]], bufnr, bufnr))
|
||||||
|
-- luacheck: pop
|
||||||
cmd 'augroup END'
|
cmd 'augroup END'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,6 @@ local api = vim.api
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function node_to_qf(node, kind)
|
|
||||||
local lnum, col, _ = def.node:start()
|
|
||||||
|
|
||||||
return {
|
|
||||||
bufnr = bufnr,
|
|
||||||
lnum = lnum + 1,
|
|
||||||
col = col + 1,
|
|
||||||
text = ts_utils.get_node_text(def.node)[1] or '',
|
|
||||||
kind = kind
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.goto_definition(bufnr)
|
function M.goto_definition(bufnr)
|
||||||
local bufnr = bufnr or api.nvim_get_current_buf()
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
local node_at_point = ts_utils.get_node_at_cursor()
|
local node_at_point = ts_utils.get_node_at_cursor()
|
||||||
|
|
@ -70,10 +58,9 @@ function M.attach(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.detach(bufnr)
|
function M.detach(bufnr)
|
||||||
local buf = bufnr or api.nvim_get_current_buf()
|
|
||||||
local config = configs.get_module('refactor.navigation')
|
local config = configs.get_module('refactor.navigation')
|
||||||
|
|
||||||
for fn_name, mapping in pairs(config.keymaps) do
|
for _, mapping in pairs(config.keymaps) do
|
||||||
api.nvim_buf_del_keymap(bufnr, 'n', mapping)
|
api.nvim_buf_del_keymap(bufnr, 'n', mapping)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ function M.smart_rename(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, node in ipairs(nodes_to_rename) do
|
for _, node in ipairs(nodes_to_rename) do
|
||||||
local start_row, start_col, end_row, end_col = node:range()
|
local start_row, start_col, _, end_col = node:range()
|
||||||
local line = api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1]
|
local line = api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1]
|
||||||
|
|
||||||
if line then
|
if line then
|
||||||
|
|
@ -56,10 +56,9 @@ function M.attach(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.detach(bufnr)
|
function M.detach(bufnr)
|
||||||
local buf = bufnr or api.nvim_get_current_buf()
|
|
||||||
local config = configs.get_module('refactor.smart_rename')
|
local config = configs.get_module('refactor.smart_rename')
|
||||||
|
|
||||||
for fn_name, mapping in pairs(config.keymaps) do
|
for _, mapping in pairs(config.keymaps) do
|
||||||
api.nvim_buf_del_keymap(bufnr, 'n', mapping)
|
api.nvim_buf_del_keymap(bufnr, 'n', mapping)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -219,10 +219,9 @@ end
|
||||||
-- @param bufnr buffer
|
-- @param bufnr buffer
|
||||||
-- @returns the definition node and the definition nodes scope node
|
-- @returns the definition node and the definition nodes scope node
|
||||||
function M.find_definition(node, bufnr)
|
function M.find_definition(node, bufnr)
|
||||||
local bufnr = bufnr or api.nvim_get_current_buf()
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
local node_text = M.get_node_text(node)[1]
|
local node_text = M.get_node_text(node)[1]
|
||||||
local current_scope = M.containing_scope(node)
|
local current_scope = M.containing_scope(node)
|
||||||
local _, _, node_start = node:start()
|
|
||||||
local matching_def_nodes = {}
|
local matching_def_nodes = {}
|
||||||
|
|
||||||
-- If a scope wasn't found then use the root node
|
-- If a scope wasn't found then use the root node
|
||||||
|
|
@ -234,7 +233,7 @@ function M.find_definition(node, bufnr)
|
||||||
for _, def in ipairs(locals.get_definitions(bufnr)) do
|
for _, def in ipairs(locals.get_definitions(bufnr)) do
|
||||||
for _, def_node in ipairs(M.get_local_nodes(def)) do
|
for _, def_node in ipairs(M.get_local_nodes(def)) do
|
||||||
if M.get_node_text(def_node)[1] == node_text then
|
if M.get_node_text(def_node)[1] == node_text then
|
||||||
table.insert(matching_def_nodes, def_node)
|
table.insert(matching_def_nodes, def_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -258,7 +257,7 @@ end
|
||||||
function M.get_local_nodes(local_def)
|
function M.get_local_nodes(local_def)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
M.recurse_local_nodes(local_def, function(_, node)
|
M.recurse_local_nodes(local_def, function(_, node)
|
||||||
table.insert(result, node)
|
table.insert(result, node)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -281,9 +280,9 @@ function M.recurse_local_nodes(local_def, accumulator, full_match, last_match)
|
||||||
else
|
else
|
||||||
for match_key, def in pairs(local_def) do
|
for match_key, def in pairs(local_def) do
|
||||||
M.recurse_local_nodes(
|
M.recurse_local_nodes(
|
||||||
def,
|
def,
|
||||||
accumulator,
|
accumulator,
|
||||||
full_match and (full_match..'.'..match_key) or match_key,
|
full_match and (full_match..'.'..match_key) or match_key,
|
||||||
match_key)
|
match_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
local luv = vim.loop
|
local luv = vim.loop
|
||||||
local ts = vim.treesitter
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue