diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-07-07 01:40:41 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2025-07-07 01:40:41 +0200 |
| commit | e95640e1a1895be2c510a37272b982f842d5da5e (patch) | |
| tree | 99865a4e9be304dde2342859a76ecd0170c5785e /src/server | |
| parent | ef5257da82356caadf7e561f1684c329376191d2 (diff) | |
| parent | 0a64647eafc7870a151f7a03a3b32a40b42fb819 (diff) | |
Merge branch 'feat/reference-improvements' of https://github.com/BradLewis/ols into BradLewis-feat/reference-improvements
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 90 | ||||
| -rw-r--r-- | src/server/collector.odin | 3 | ||||
| -rw-r--r-- | src/server/file_resolve.odin | 19 | ||||
| -rw-r--r-- | src/server/generics.odin | 4 | ||||
| -rw-r--r-- | src/server/references.odin | 6 |
5 files changed, 79 insertions, 43 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 4573f02..b5089b1 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -764,6 +764,7 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou type = candidates[0].type, name = candidates[0].name, pkg = candidates[0].pkg, + uri = candidates[0].uri, value = SymbolAggregateValue{symbols = candidates[:]}, }, true @@ -1356,6 +1357,7 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide name = ident.name, pkg = ast_context.current_package, value = SymbolBasicValue{ident = ident}, + uri = common.create_uri(ident.pos.file, ast_context.allocator).uri, }, true } @@ -2255,50 +2257,60 @@ resolve_location_selector :: proc(ast_context: ^AstContext, selector_expr: ^ast. set_ast_package_set_scoped(ast_context, ast_context.document_package) if selector, ok := selector_expr.derived.(^ast.Selector_Expr); ok { - symbol = resolve_type_expression(ast_context, selector.expr) or_return + return resolve_symbol_selector(ast_context, selector, symbol) + } - field: string + return {}, false +} - if selector.field != nil { - #partial switch v in selector.field.derived { - case ^ast.Ident: - field = v.name - } +resolve_symbol_selector :: proc(ast_context: ^AstContext, selector: ^ast.Selector_Expr, symbol: Symbol) ->(Symbol, bool) { + field: string + symbol := symbol + + if selector.field != nil { + #partial switch v in selector.field.derived { + case ^ast.Ident: + field = v.name } + } - #partial switch v in symbol.value { - case SymbolEnumValue: - for name, i in v.names { - if strings.compare(name, field) == 0 { - symbol.range = v.ranges[i] - } - } - case SymbolStructValue: - for name, i in v.names { - if strings.compare(name, field) == 0 { - symbol.range = v.ranges[i] - } + #partial switch v in symbol.value { + case SymbolEnumValue: + for name, i in v.names { + if strings.compare(name, field) == 0 { + symbol.range = v.ranges[i] } - case SymbolBitFieldValue: - for name, i in v.names { - if strings.compare(name, field) == 0 { - symbol.range = v.ranges[i] - } + } + case SymbolStructValue: + for name, i in v.names { + if strings.compare(name, field) == 0 { + symbol.range = v.ranges[i] } - case SymbolPackageValue: - if pkg, ok := lookup(field, symbol.pkg); ok { - symbol.range = pkg.range - symbol.uri = pkg.uri - } else { - return {}, false + } + case SymbolBitFieldValue: + for name, i in v.names { + if strings.compare(name, field) == 0 { + symbol.range = v.ranges[i] } } - - return symbol, true + case SymbolPackageValue: + if pkg, ok := lookup(field, symbol.pkg); ok { + symbol.range = pkg.range + symbol.uri = pkg.uri + } else { + return {}, false + } + case SymbolProcedureValue: + if len(v.return_types) != 1 { + return {}, false + } + if s, ok := resolve_type_expression(ast_context, v.return_types[0].type); ok { + return resolve_symbol_selector(ast_context, selector, s) + } } - return {}, false + return symbol, true } @@ -2553,6 +2565,7 @@ make_symbol_procedure_from_ast :: proc( type = .Function if !type else .Type_Function, pkg = get_package_from_node(n^), name = name.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } return_types := make([dynamic]^ast.Field, ast_context.allocator) @@ -2601,6 +2614,7 @@ make_symbol_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Array_Type, type = .Type, pkg = get_package_from_node(v.node), name = name.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } if v.len != nil { @@ -2631,6 +2645,7 @@ make_symbol_dynamic_array_from_ast :: proc( type = .Type, pkg = get_package_from_node(v.node), name = name.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } symbol.value = SymbolDynamicArrayValue { @@ -2652,6 +2667,7 @@ make_symbol_matrix_from_ast :: proc(ast_context: ^AstContext, v: ast.Matrix_Type type = .Type, pkg = get_package_from_node(v.node), name = name.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } symbol.value = SymbolMatrixValue { @@ -2674,6 +2690,7 @@ make_symbol_multi_pointer_from_ast :: proc( type = .Type, pkg = get_package_from_node(v.node), name = name.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } symbol.value = SymbolMultiPointerValue { @@ -2689,6 +2706,7 @@ make_symbol_map_from_ast :: proc(ast_context: ^AstContext, v: ast.Map_Type, name type = .Type, pkg = get_package_from_node(v.node), name = name.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } symbol.value = SymbolMapValue { @@ -2724,6 +2742,7 @@ make_symbol_union_from_ast :: proc( type = .Union, pkg = get_package_from_node(v.node), name = ident.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } if inlined { @@ -2763,6 +2782,7 @@ make_symbol_enum_from_ast :: proc( type = .Enum, name = ident.name, pkg = get_package_from_node(v.node), + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } if inlined { @@ -2817,6 +2837,7 @@ make_symbol_bitset_from_ast :: proc( type = .Enum, name = ident.name, pkg = get_package_from_node(v.node), + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } if inlined { @@ -2844,6 +2865,8 @@ make_symbol_struct_from_ast :: proc( type = .Struct, pkg = get_package_from_node(v.node), name = ident.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri + } if inlined { @@ -2869,6 +2892,7 @@ make_symbol_bit_field_from_ast :: proc( type = .Struct, pkg = get_package_from_node(v.node), name = ident.name, + uri = common.create_uri(v.pos.file, ast_context.allocator).uri } if inlined { diff --git a/src/server/collector.odin b/src/server/collector.odin index f4e4a1c..4a04631 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -458,7 +458,6 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator) directory := path.dir(forward, context.temp_allocator) package_map := get_package_mapping(file, collection.config, directory) - exprs := collect_globals(file, true) for expr in exprs { @@ -619,6 +618,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri symbol.name = get_index_unique_string(collection, name) symbol.type = token_type symbol.doc = get_doc(expr.docs, collection.allocator) + symbol.uri = get_index_unique_string(collection, uri) comment := get_file_comment(file, symbol.range.start.line + 1) symbol.comment = strings.clone(get_comment(comment), collection.allocator) symbol.flags |= {.Distinct} @@ -650,7 +650,6 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri symbol.flags |= {.PrivatePackage} } - symbol.uri = get_index_unique_string(collection, uri) pkg: ^SymbolPackage ok: bool diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin index 9b1ffa0..f6096c5 100644 --- a/src/server/file_resolve.odin +++ b/src/server/file_resolve.odin @@ -202,7 +202,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) { #partial switch v in n.expr.derived { // TODO: Should there be more here? - case ^ast.Selector_Expr, ^ast.Index_Expr, ^ast.Ident, ^ast.Paren_Expr: + case ^ast.Selector_Expr, ^ast.Index_Expr, ^ast.Ident, ^ast.Paren_Expr, ^ast.Call_Expr: resolve_node(n.expr, data) } } else { @@ -491,19 +491,30 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) { for field in n.fields { data.symbols[cast(uintptr)field] = SymbolAndNode { node = field, - symbol = Symbol{range = common.get_token_range(field, string(data.document.text))}, + symbol = Symbol{ + range = common.get_token_range(field, string(data.document.text)), + uri = strings.clone(common.create_uri(field.pos.file, data.ast_context.allocator).uri, data.ast_context.allocator), + }, } // In the case of a Field_Value, we explicitly add them so we can find the LHS correctly for things like renaming if field, ok := field.derived.(^ast.Field_Value); ok { if ident, ok := field.field.derived.(^ast.Ident); ok { data.symbols[cast(uintptr)ident] = SymbolAndNode { node = ident, - symbol = Symbol{name = ident.name, range = common.get_token_range(ident, string(data.document.text))}, + symbol = Symbol{ + name = ident.name, + range = common.get_token_range(ident, string(data.document.text)), + uri = strings.clone(common.create_uri(field.pos.file, data.ast_context.allocator).uri, data.ast_context.allocator), + }, } } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok { data.symbols[cast(uintptr)binary] = SymbolAndNode { node = binary, - symbol = Symbol{name = "binary",range = common.get_token_range(binary, string(data.document.text))}, + symbol = Symbol{ + name = "binary", + range = common.get_token_range(binary, string(data.document.text)), + uri = strings.clone(common.create_uri(field.pos.file, data.ast_context.allocator).uri, data.ast_context.allocator), + }, } } } diff --git a/src/server/generics.odin b/src/server/generics.odin index 43e2787..2cb1f5c 100644 --- a/src/server/generics.odin +++ b/src/server/generics.odin @@ -547,13 +547,16 @@ resolve_generic_function_symbol :: proc( function_name := "" function_range: common.Range + function_uri := "" if ident, ok := call_expr.expr.derived.(^ast.Ident); ok { function_name = ident.name function_range = common.get_token_range(ident, ast_context.file.src) + function_uri = common.create_uri(ident.pos.file, ast_context.allocator).uri } else if selector, ok := call_expr.expr.derived.(^ast.Selector_Expr); ok { function_name = selector.field.name function_range = common.get_token_range(selector, ast_context.file.src) + function_uri = common.create_uri(selector.field.pos.file, ast_context.allocator).uri } else { return {}, false } @@ -563,6 +566,7 @@ resolve_generic_function_symbol :: proc( type = .Function, name = function_name, pkg = ast_context.current_package, + uri = function_uri, } return_types := make([dynamic]^ast.Field, ast_context.allocator) diff --git a/src/server/references.odin b/src/server/references.odin index 5f189ef..ed3af4d 100644 --- a/src/server/references.odin +++ b/src/server/references.odin @@ -322,8 +322,7 @@ resolve_references :: proc( if in_pkg || symbol.pkg == document.package_name { symbols_and_nodes := resolve_entire_file(&document, resolve_flag, context.allocator) for k, v in symbols_and_nodes { - // NOTE: the uri is sometimes empty for symbols used in the same file as they are derived - if (v.symbol.uri == symbol.uri || v.symbol.uri == "") && v.symbol.range == symbol.range { + if v.symbol.uri == symbol.uri && v.symbol.range == symbol.range { node_uri := common.create_uri(v.node.pos.file, ast_context.allocator) range := common.get_token_range(v.node^, string(document.text)) //We don't have to have the `.` with, otherwise it renames the dot. @@ -346,8 +345,7 @@ resolve_references :: proc( symbols_and_nodes := resolve_entire_file(document, resolve_flag, context.allocator) for k, v in symbols_and_nodes { - // NOTE: the uri is sometimes empty for symbols used in the same file as they are derived - if (v.symbol.uri == symbol.uri || v.symbol.uri == "") && v.symbol.range == symbol.range { + if v.symbol.uri == symbol.uri && v.symbol.range == symbol.range { node_uri := common.create_uri(v.node.pos.file, ast_context.allocator) range := common.get_token_range(v.node^, ast_context.file.src) |