@@ -3867,7 +3867,7 @@ pub const Type = struct {
38673867 return ;
38683868 }
38693869 if (token >= 1 and tree .tokenTag (token - 1 ) == .keyword_return ) blk : {
3870- const function_scope = innermostFunctionScopeAtIndex (doc_scope , tree .tokenStart (token - 1 )).unwrap () orelse break :blk ;
3870+ const function_scope = innermostScopeAtIndexWithTag (doc_scope , tree .tokenStart (token - 1 ), . initOne ( .function )).unwrap () orelse break :blk ;
38713871 const function_node = doc_scope .getScopeAstNode (function_scope ).? ;
38723872 var buf : [1 ]Ast.Node.Index = undefined ;
38733873 const func = tree .fullFnProto (& buf , function_node ).? ;
@@ -5293,36 +5293,28 @@ pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptim
52935293 }
52945294}
52955295
5296- pub fn innermostScopeAtIndex (document_scope : DocumentScope , source_index : usize ) Scope.Index {
5297- var scope_iterator = iterateEnclosingScopes (& document_scope , source_index );
5298- var scope_index : Scope.Index = scope_iterator .next ().unwrap ().? ; // the DocumentScope's root scope must exist
5299- while (scope_iterator .next ().unwrap ()) | inner_scope | {
5300- scope_index = inner_scope ;
5301- }
5302- return scope_index ;
5296+ pub fn innermostScopeAtIndex (
5297+ document_scope : DocumentScope ,
5298+ source_index : usize ,
5299+ ) Scope.Index {
5300+ return innermostScopeAtIndexWithTag (document_scope , source_index , .initFull ()).unwrap ().? ;
53035301}
53045302
5305- pub fn innermostFunctionScopeAtIndex (document_scope : DocumentScope , source_index : usize ) Scope.OptionalIndex {
5303+ pub fn innermostScopeAtIndexWithTag (
5304+ document_scope : DocumentScope ,
5305+ source_index : usize ,
5306+ tag_filter : std .EnumSet (Scope.Tag ),
5307+ ) Scope.OptionalIndex {
53065308 var scope_iterator = iterateEnclosingScopes (& document_scope , source_index );
53075309 var scope_index : Scope.OptionalIndex = .none ;
53085310 while (scope_iterator .next ().unwrap ()) | inner_scope | {
5309- if (document_scope .getScopeTag (inner_scope ) != .function ) continue ;
5311+ const scope_tag = document_scope .getScopeTag (inner_scope );
5312+ if (! tag_filter .contains (scope_tag )) continue ;
53105313 scope_index = inner_scope .toOptional ();
53115314 }
53125315 return scope_index ;
53135316}
53145317
5315- pub fn innermostBlockScope (document_scope : DocumentScope , source_index : usize ) Ast.Node.Index {
5316- var scope_iterator = iterateEnclosingScopes (& document_scope , source_index );
5317- var ast_node : ? Ast.Node.Index = null ;
5318- while (scope_iterator .next ().unwrap ()) | inner_scope | {
5319- if (document_scope .getScopeAstNode (inner_scope )) | node | {
5320- ast_node = node ;
5321- }
5322- }
5323- return ast_node .? ; // the DocumentScope's root scope is guaranteed to have an Ast Node
5324- }
5325-
53265318pub fn innermostContainer (analyser : * Analyser , handle : * DocumentStore.Handle , source_index : usize ) error {OutOfMemory }! Type {
53275319 const tree = handle .tree ;
53285320 const document_scope = try handle .getDocumentScope ();
0 commit comments