diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-12 15:26:11 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-12 15:26:11 +0100 |
| commit | bd3f707d8e0a717df49b7bf702a5b98d214b0381 (patch) | |
| tree | da5be249507adde933a9d76a4eaa09949da5bf57 /src | |
| parent | e8d2c76db829c59e88d5342f1c4385354cc9546f (diff) | |
Fix issues with no completion on identifier in comp literal.
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis/analysis.odin | 40 | ||||
| -rw-r--r-- | src/server/completion.odin | 1 | ||||
| -rw-r--r-- | src/server/hover.odin | 4 | ||||
| -rw-r--r-- | src/testing/testing.odin | 4 |
4 files changed, 26 insertions, 23 deletions
diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin index a34cc5f..ec9f71e 100644 --- a/src/analysis/analysis.odin +++ b/src/analysis/analysis.odin @@ -81,6 +81,7 @@ AstContext :: struct { document_package: string, use_globals: bool, use_locals: bool, + local_id: int, call: ^ast.Call_Expr, //used to determene the types for generics and the correct function for overloaded functions position: common.AbsolutePosition, value_decl: ^ast.Value_Decl, @@ -2095,7 +2096,7 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co for name, i in value_decl.names { str := common.get_ast_node_string(value_decl.names[i], file.src); ast_context.variables[str] = value_decl.is_mutable; - store_local(ast_context, value_decl.type, value_decl.end.offset, str); + store_local(ast_context, value_decl.type, value_decl.end.offset, str, ast_context.local_id); } return; } @@ -2114,7 +2115,7 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co result_i := min(len(results)-1, i); str := common.get_ast_node_string(name, file.src); ast_context.in_package[str] = get_package_from_node(results[result_i]); - store_local(ast_context, results[result_i], value_decl.end.offset, str); + store_local(ast_context, results[result_i], value_decl.end.offset, str, ast_context.local_id); ast_context.variables[str] = value_decl.is_mutable; } } @@ -2200,7 +2201,7 @@ get_locals_using_stmt :: proc(stmt: ast.Using_Stmt, ast_context: ^AstContext) { selector.expr = u; selector.field = index.new_type(ast.Ident, v.types[i].pos, v.types[i].end, context.temp_allocator); selector.field.name = name; - store_local(ast_context, selector, 0, name); + store_local(ast_context, selector, 0, name, ast_context.local_id); ast_context.variables[name] = true; } } @@ -2228,7 +2229,7 @@ get_locals_assign_stmt :: proc(file: ast.File, stmt: ast.Assign_Stmt, ast_contex for lhs, i in stmt.lhs { if ident, ok := lhs.derived.(ast.Ident); ok { - store_local(ast_context, results[i], ident.pos.offset, ident.name); + store_local(ast_context, results[i], ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; } } @@ -2264,14 +2265,14 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont case index.SymbolMapValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(Ident); ok { - store_local(ast_context, v.key, ident.pos.offset, ident.name); + store_local(ast_context, v.key, ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } } if len(stmt.vals) >= 2 { if ident, ok := stmt.vals[1].derived.(Ident); ok { - store_local(ast_context, v.value, ident.pos.offset, ident.name); + store_local(ast_context, v.value, ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } @@ -2279,14 +2280,14 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont case index.SymbolDynamicArrayValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(Ident); ok { - store_local(ast_context, v.expr, ident.pos.offset, ident.name); + store_local(ast_context, v.expr, ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } } if len(stmt.vals) >= 2 { if ident, ok := stmt.vals[1].derived.(Ident); ok { - store_local(ast_context, make_int_ast(), ident.pos.offset, ident.name); + store_local(ast_context, make_int_ast(), ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } @@ -2294,7 +2295,7 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont case index.SymbolFixedArrayValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(Ident); ok { - store_local(ast_context, v.expr, ident.pos.offset, ident.name); + store_local(ast_context, v.expr, ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } @@ -2302,7 +2303,7 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont if len(stmt.vals) >= 2 { if ident, ok := stmt.vals[1].derived.(Ident); ok { - store_local(ast_context, make_int_ast(), ident.pos.offset, ident.name); + store_local(ast_context, make_int_ast(), ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } @@ -2310,14 +2311,14 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont case index.SymbolSliceValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(Ident); ok { - store_local(ast_context, v.expr, ident.pos.offset, ident.name); + store_local(ast_context, v.expr, ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } } if len(stmt.vals) >= 2 { if ident, ok := stmt.vals[1].derived.(Ident); ok { - store_local(ast_context, make_int_ast(), ident.pos.offset, ident.name); + store_local(ast_context, make_int_ast(), ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; ast_context.in_package[ident.name] = symbol.pkg; } @@ -2373,7 +2374,7 @@ get_locals_type_switch_stmt :: proc(file: ast.File, stmt: ast.Type_Switch_Stmt, if len(tag.lhs) == 1 && len(cause.list) == 1 { ident := tag.lhs[0].derived.(Ident); - store_local(ast_context, cause.list[0], ident.pos.offset, ident.name); + store_local(ast_context, cause.list[0], ident.pos.offset, ident.name, ast_context.local_id); ast_context.variables[ident.name] = true; } } @@ -2396,7 +2397,7 @@ get_locals :: proc(file: ast.File, function: ^ast.Node, ast_context: ^AstContext for name in arg.names { if arg.type != nil { str := common.get_ast_node_string(name, file.src); - store_local(ast_context, arg.type, name.pos.offset, str); + store_local(ast_context, arg.type, name.pos.offset, str, ast_context.local_id); ast_context.variables[str] = true; ast_context.parameters[str] = true; @@ -2408,7 +2409,7 @@ get_locals :: proc(file: ast.File, function: ^ast.Node, ast_context: ^AstContext } } else { str := common.get_ast_node_string(name, file.src); - store_local(ast_context, arg.default_value, name.pos.offset, str); + store_local(ast_context, arg.default_value, name.pos.offset, str, ast_context.local_id); ast_context.variables[str] = true; ast_context.parameters[str] = true; } @@ -2423,7 +2424,7 @@ get_locals :: proc(file: ast.File, function: ^ast.Node, ast_context: ^AstContext for name in result.names { if result.type != nil { str := common.get_ast_node_string(name, file.src); - store_local(ast_context, result.type, name.pos.offset, str); + store_local(ast_context, result.type, name.pos.offset, str, ast_context.local_id); ast_context.variables[str] = true; ast_context.parameters[str] = true; } @@ -2509,7 +2510,7 @@ resolve_entire_procedure :: proc(ast_context: ^AstContext, procedure: ast.Proc_L } ast.walk(&visitor, procedure.body); - + if procedure.type != nil { ast.walk(&visitor, procedure.type.params); ast.walk(&visitor, procedure.type.results); @@ -2665,6 +2666,11 @@ position_in_proc_decl :: proc(position_context: ^DocumentPositionContext) -> boo is_lhs_comp_lit :: proc(position_context: ^DocumentPositionContext) -> bool { + + if position_context.position <= position_context.comp_lit.open.offset { + return false; + } + if len(position_context.comp_lit.elems) == 0 { return true; } diff --git a/src/server/completion.odin b/src/server/completion.odin index c458e34..6eba90f 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -35,7 +35,6 @@ Completion_Type :: enum { } get_completion_list :: proc(document: ^common.Document, position: common.Position, completion_context: CompletionContext) -> (CompletionList, bool) { - using analysis; list: CompletionList; diff --git a/src/server/hover.odin b/src/server/hover.odin index d19d990..7c2d9c4 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -49,7 +49,6 @@ write_hover_content :: proc(ast_context: ^analysis.AstContext, symbol: index.Sym get_hover_information :: proc(document: ^common.Document, position: common.Position) -> (Hover, bool) { - using analysis; hover := Hover { @@ -72,14 +71,13 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit if ident, ok := position_context.identifier.derived.(ast.Ident); ok { if _, ok := common.keyword_map[ident.name]; ok { hover.contents.kind = "plaintext"; - hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); + hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); return hover, true; } } } if position_context.selector != nil && position_context.identifier != nil { - hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); ast_context.use_locals = true; diff --git a/src/testing/testing.odin b/src/testing/testing.odin index bd4e39b..c9c515d 100644 --- a/src/testing/testing.odin +++ b/src/testing/testing.odin @@ -41,8 +41,6 @@ setup :: proc(src: ^Source) { common.scratch_allocator_init(src.document.allocator, mem.kilobytes(20), context.temp_allocator); - server.document_refresh(src.document, &src.config, nil); - //no unicode in tests currently current, last: u8; current_line, current_character: int; @@ -70,6 +68,8 @@ setup :: proc(src: ^Source) { last = current; } + server.document_refresh(src.document, &src.config, nil); + /* There is a lot code here that is used in the real code, then i'd like to see. */ |