Skip to content

Commit

Permalink
Better handling of local globals.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Aug 11, 2024
1 parent 95f580c commit 4bbb629
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/server/analysis.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 4bbb629

Please sign in to comment.