From c2d15bfc9a79083a0f3490617717441e60d80b05 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 14 Mar 2023 00:54:31 +0100 Subject: [PATCH] only return block scopes from `innermostBlockScope` --- src/analysis.zig | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 5ad3e3f..ba31da3 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -2176,16 +2176,25 @@ pub fn iterateSymbolsGlobal( pub fn innermostBlockScopeIndex(handle: DocumentStore.Handle, source_index: usize) Scope.Index { var scope_iterator = iterateEnclosingScopes(handle.document_scope, source_index); - var current_scope: Scope.Index = .none; + var scope_index: Scope.Index = .none; while (scope_iterator.next()) |inner_scope| { - current_scope = inner_scope; + scope_index = inner_scope; } - return current_scope; + return scope_index; } pub fn innermostBlockScope(handle: DocumentStore.Handle, source_index: usize) Ast.Node.Index { - const scope_index = innermostBlockScopeIndex(handle, source_index); - return handle.document_scope.scopes.items(.data)[@enumToInt(scope_index)].toNodeIndex().?; + const scope_datas = handle.document_scope.scopes.items(.data); + const scope_parents = handle.document_scope.scopes.items(.parent); + + var scope_index = innermostBlockScopeIndex(handle, source_index); + while (true) { + defer scope_index = scope_parents[@enumToInt(scope_index)]; + switch (scope_datas[@enumToInt(scope_index)]) { + .container, .function, .block => return scope_datas[@enumToInt(scope_index)].toNodeIndex().?, + else => {}, + } + } } pub fn innermostContainer(handle: *const DocumentStore.Handle, source_index: usize) TypeWithHandle {