diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-06-25 00:00:47 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2025-06-25 00:00:47 +0200 |
| commit | 27d80646e4861b2cd6e7d8c392b1de8991f992b4 (patch) | |
| tree | d71c75f66545b0250a24506abcc56600b8aca654 /src/server | |
| parent | 8ada3b6b2975e7b471848e6024837fe2b7edc157 (diff) | |
Fix issues with non-mutable decls in nested blocks.
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e779547..53546cc 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -27,6 +27,7 @@ DocumentPositionContextHint :: enum { DocumentPositionContext :: struct { file: ast.File, position: common.AbsolutePosition, + nested_position: common.AbsolutePosition, //When doing the non-mutable local gathering we still need to know where in the nested block the position is. line: int, function: ^ast.Proc_Lit, //used to help with type resolving in function scope functions: [dynamic]^ast.Proc_Lit, //stores all the functions that have been iterated through to find the position @@ -3155,10 +3156,38 @@ get_locals_block_stmt :: proc( ast_context: ^AstContext, document_position: ^DocumentPositionContext, ) { - if !(block.pos.offset <= document_position.position && document_position.position <= block.end.offset) { - return + /* + We need to handle blocks for non mutable and mutable: non mutable has no order for their value declarations, except for nested blocks where they are hidden by scope + For non_mutable_only we set the document_position.position to be the end of the function to get all the non-mutable locals, but that shouldn't apply to the nested block itself, + but will for it's content. + + Therefore we use nested_position that is the exact token we are interested in. + + Example: + my_proc :: proc() { + { + my_variable = get_value() <-- document_position.nested_position + get_value :: proc() --- This should not be hidden + + { + get_value_2 :: proc() --- This will be hidden + } + } + } <-- document_position.position + */ + + if ast_context.non_mutable_only { + if !(block.pos.offset <= document_position.nested_position && + document_position.nested_position <= block.end.offset) { + return + } + } else { + if !(block.pos.offset <= document_position.position && document_position.position <= block.end.offset) { + return + } } + for stmt in block.stmts { get_locals_stmt(file, stmt, ast_context, document_position) } @@ -3755,7 +3784,7 @@ get_locals :: proc( return } - old_position := document_position.position + document_position.nested_position = document_position.position for function in document_position.functions { ast_context.non_mutable_only = true @@ -3763,7 +3792,7 @@ get_locals :: proc( get_locals_stmt(file, function.body, ast_context, document_position) } - document_position.position = old_position + document_position.position = document_position.nested_position ast_context.non_mutable_only = false for stmt in block.stmts { |