From 4bbb629241db3cf79d1509eb391b7e3143f34242 Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Mon, 12 Aug 2024 00:42:55 +0200 Subject: [PATCH] Better handling of local globals. --- src/server/analysis.odin | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index da4e9219..2b69bc70 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -100,7 +100,7 @@ AstContext :: struct { field_name: ast.Ident, uri: string, fullpath: string, - non_mutable_only: bool, + non_mutable_only: bool, //Only store local value declarations that are non mutable. overloading: bool, } @@ -1111,7 +1111,7 @@ get_local :: proc(ast_context: AstContext, ident: ast.Ident) -> (DocumentLocal, get_local_offset :: proc(ast_context: ^AstContext, offset: int, name: string) -> int { for _, locals in &ast_context.locals { if local_stack, ok := locals[name]; ok { - for i := len(local_stack) - 1; i >= 0; i -= 1 { + #reverse for local, i in local_stack { if local_stack[i].offset <= offset || local_stack[i].local_global { if i < 0 { return -1 @@ -3407,10 +3407,6 @@ get_locals :: proc( return } - for stmt in block.stmts { - get_locals_stmt(file, stmt, ast_context, document_position) - } - old_position := document_position.position for function in document_position.functions { @@ -3420,6 +3416,12 @@ get_locals :: proc( } document_position.position = old_position + ast_context.non_mutable_only = false + + for stmt in block.stmts { + get_locals_stmt(file, stmt, ast_context, document_position) + } + } clear_locals :: proc(ast_context: ^AstContext) {