Improve scopes sorter
This commit is contained in:
@@ -177,14 +177,16 @@ compare.scopes = setmetatable({
|
|||||||
-- Cursor scope.
|
-- Cursor scope.
|
||||||
local cursor_scope = nil
|
local cursor_scope = nil
|
||||||
for _, scope in ipairs(locals.get_scopes(buf)) do
|
for _, scope in ipairs(locals.get_scopes(buf)) do
|
||||||
|
if scope:start() <= cursor_row and cursor_row <= scope:end_() then
|
||||||
if not cursor_scope then
|
if not cursor_scope then
|
||||||
cursor_scope = scope
|
cursor_scope = scope
|
||||||
else
|
else
|
||||||
if scope:start() <= cursor_row and cursor_row <= scope:end_() then
|
if cursor_scope:start() <= scope:start() and scope:end_() <= cursor_scope:end_() then
|
||||||
if math.abs(scope:end_() - scope:start()) < math.abs(cursor_scope:end_() - cursor_scope:start()) then
|
|
||||||
cursor_scope = scope
|
cursor_scope = scope
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif cursor_scope and cursor_scope:end_() <= scope:start() then
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -194,8 +196,11 @@ compare.scopes = setmetatable({
|
|||||||
-- Narrow definitions.
|
-- Narrow definitions.
|
||||||
local depth = 0
|
local depth = 0
|
||||||
for scope in locals.iter_scope_tree(cursor_scope, buf) do
|
for scope in locals.iter_scope_tree(cursor_scope, buf) do
|
||||||
|
local s, e = scope:start(), scope:end_()
|
||||||
|
|
||||||
-- Check scope's direct child.
|
-- Check scope's direct child.
|
||||||
for _, definition in pairs(definitions) do
|
for _, definition in pairs(definitions) do
|
||||||
|
if s <= definition.node:start() and definition.node:end_() <= e then
|
||||||
if scope:id() == locals.containing_scope(definition.node, buf):id() then
|
if scope:id() == locals.containing_scope(definition.node, buf):id() then
|
||||||
local text = ts_utils.get_node_text(definition.node)[1]
|
local text = ts_utils.get_node_text(definition.node)[1]
|
||||||
if not self.scopes_map[text] then
|
if not self.scopes_map[text] then
|
||||||
@@ -203,6 +208,7 @@ compare.scopes = setmetatable({
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
depth = depth + 1
|
depth = depth + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user