diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-11 23:21:57 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-11 23:21:57 +0100 |
| commit | 3f3eb27677088d86cd7e0331f98385d497d0966a (patch) | |
| tree | 1f3fc486ea5f8b2da3603fd9b0cca9dcf9572fa2 | |
| parent | 04e2312b458d0448bf39bd94a1770c0710c8f255 (diff) | |
simplified how variables are decided
| -rw-r--r-- | src/analysis/analysis.odin | 107 | ||||
| -rw-r--r-- | src/common/ast.odin | 19 | ||||
| -rw-r--r-- | src/index/build.odin | 4 | ||||
| -rw-r--r-- | src/index/indexer.odin | 2 | ||||
| -rw-r--r-- | src/index/symbol.odin | 5 | ||||
| -rw-r--r-- | src/server/completion.odin | 42 | ||||
| -rw-r--r-- | src/server/hover.odin | 6 | ||||
| -rw-r--r-- | src/server/requests.odin | 4 | ||||
| -rw-r--r-- | src/server/signature.odin | 46 | ||||
| -rw-r--r-- | tests/completions_test.odin | 8 | ||||
| -rw-r--r-- | tests/hover_test.odin | 2 | ||||
| -rw-r--r-- | tests/signatures_test.odin | 21 |
12 files changed, 112 insertions, 154 deletions
diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin index bf5dd57..9419801 100644 --- a/src/analysis/analysis.odin +++ b/src/analysis/analysis.odin @@ -378,13 +378,11 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast count_required_params := 0; for param in params { - if param.default_value == nil { count_required_params += 1; } for name in param.names { - if len(call_expr.args) <= i { break; } @@ -398,7 +396,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast } if type_id, ok := param.type.derived.(Typeid_Type); ok { - if !common.node_equal(call_expr.args[i], type_id.specialization) { + if type_id.specialization != nil && !common.node_equal(call_expr.args[i], type_id.specialization) { return {}, false; } } @@ -440,7 +438,9 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast continue; } - if ident, ok := result.type.derived.(Ident); ok { + ident, ok := common.unwrap_pointer(result.type); + + if ok { if m, ok := poly_map[ident.name]; ok { field := cast(^Field)index.clone_node(result, context.temp_allocator, nil); field.type = m; @@ -468,7 +468,6 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast } else { append(&argument_types, param); } - } symbol.value = index.SymbolProcedureValue { @@ -830,7 +829,7 @@ resolve_basic_directive :: proc(ast_context: ^AstContext, directive: ast.Basic_D //but it will help with multiple requests like semantic tokens. //If this doesn't provide good results, just handle caching explicitly on semantic tokens only. lookup_symbol_cache :: proc(ast_context: ^AstContext, node: ast.Node) -> (index.Symbol, bool) { - if ast_context.document_package != node.pos.file || node.pos.file == "" { + if ast_context.document_package != ast_context.current_package { return {}, false; } @@ -952,18 +951,26 @@ internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Ex case Index_Expr: indexed, ok := resolve_type_expression(ast_context, v.expr); + if !ok { + return {}, false; + } + + symbol: index.Symbol; + #partial switch v2 in indexed.value { case index.SymbolDynamicArrayValue: - return resolve_type_expression(ast_context, v2.expr); + symbol, ok = resolve_type_expression(ast_context, v2.expr); case index.SymbolSliceValue: - return resolve_type_expression(ast_context, v2.expr); + symbol, ok = resolve_type_expression(ast_context, v2.expr); case index.SymbolFixedArrayValue: - return resolve_type_expression(ast_context, v2.expr); + symbol, ok = resolve_type_expression(ast_context, v2.expr); case index.SymbolMapValue: - return resolve_type_expression(ast_context, v2.value); + symbol, ok = resolve_type_expression(ast_context, v2.value); } - return index.Symbol {}, false; + symbol.type = indexed.type; + + return symbol, ok; case Call_Expr: ast_context.call = cast(^Call_Expr)node; return resolve_type_expression(ast_context, v.expr); @@ -973,7 +980,6 @@ internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Ex return resolve_type_expression(ast_context, v.expr); case Selector_Expr: if selector, ok := resolve_type_expression(ast_context, v.expr); ok { - ast_context.use_locals = false; #partial switch s in selector.value { @@ -996,13 +1002,16 @@ internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Ex } else { ast_context.current_package = ast_context.document_package; } - return resolve_type_expression(ast_context, s.expr); + symbol, ok := resolve_type_expression(ast_context, s.expr); + symbol.type = .Variable; + return symbol, ok; } else { value := index.SymbolFixedArrayValue { expr = s.expr, len = make_int_basic_value(components_count), }; selector.value = value; + selector.type = .Variable; return selector, true; } case index.SymbolProcedureValue: @@ -1022,7 +1031,9 @@ internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Ex for name, i in s.names { if v.field != nil && name == v.field.name { ast_context.field_name = v.field.name; - return resolve_type_expression(ast_context, s.types[i]); + symbol, ok := resolve_type_expression(ast_context, s.types[i]); + symbol.type = .Variable; + return symbol, ok; } } case index.SymbolPackageValue: @@ -1065,7 +1076,6 @@ get_local :: proc(ast_context: ^AstContext, offset: int, name: string, id := 0) if ast_context.value_decl != nil { for value_decl_name in ast_context.value_decl.names { if ident, ok := value_decl_name.derived.(ast.Ident); ok { - if ident.name == name { previous = 1; break; @@ -1089,6 +1099,21 @@ get_local :: proc(ast_context: ^AstContext, offset: int, name: string, id := 0) return nil; } +get_local_offset :: proc(ast_context: ^AstContext, offset: int, name: string, id := 0) -> int { + if local_stack, ok := ast_context.locals[name]; ok { + for i := len(local_stack) - 1; i >= 0; i -= 1 { + if local_stack[i].offset <= offset && local_stack[i].id == id { + if i < 0 { + return -1; + } else { + return local_stack[i].offset; + } + } + } + } + return -1; +} + resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (index.Symbol, bool) { if symbol, ok := lookup_symbol_cache(ast_context, node); ok { return symbol, true; @@ -1182,6 +1207,10 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide return_symbol.flags |= {.Distinct}; } + if is_variable, ok := ast_context.variables[node.name]; ok && is_variable { + return_symbol.type = .Variable; + } + return return_symbol, ok; } else if global, ok := ast_context.globals[node.name]; ast_context.use_globals && ok { @@ -1239,11 +1268,15 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide return_symbol.flags |= {.Distinct}; } + if is_variable, ok := ast_context.variables[node.name]; ok && is_variable { + return_symbol.type = .Variable; + } + return_symbol.doc = common.get_doc(global.docs, context.temp_allocator); return return_symbol, ok; } else if node.name == "context" { - for built in index.indexer.built_in_packages { + for built in index.indexer.builtin_packages { if symbol, ok := index.lookup("Context", built); ok { return symbol, ok; } @@ -1310,7 +1343,7 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide //If we are resolving a symbol that is in the document package, then we'll check the builtin packages. if ast_context.current_package == ast_context.document_package { - for built in index.indexer.built_in_packages { + for built in index.indexer.builtin_packages { if symbol, ok := index.lookup(node.name, built); ok { return resolve_symbol_return(ast_context, symbol); } @@ -1348,14 +1381,10 @@ resolve_ident_is_package :: proc(ast_context: ^AstContext, node: ast.Ident) -> b } expand_struct_usings :: proc(ast_context: ^AstContext, symbol: index.Symbol, value: index.SymbolStructValue) -> index.SymbolStructValue { - - //ERROR no completion or over on names and types - generic resolve error names := slice.to_dynamic(value.names, context.temp_allocator); types := slice.to_dynamic(value.types, context.temp_allocator); - - //ERROR no hover on k and v(completion works) - for k, v in value.usings { + for k, v in value.usings { ast_context.current_package = symbol.pkg; field_expr: ^ast.Expr; @@ -1372,9 +1401,7 @@ expand_struct_usings :: proc(ast_context: ^AstContext, symbol: index.Symbol, val } if s, ok := resolve_type_expression(ast_context, field_expr); ok { - if struct_value, ok := s.value.(index.SymbolStructValue); ok { - for name in struct_value.names { append(&names, name); } @@ -1868,7 +1895,6 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type } resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^index.Symbol) { - if ast_context.call == nil { return; } @@ -1929,7 +1955,6 @@ resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_Lis } resolve_poly_struct :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^index.Symbol) { - if ast_context.call == nil { return; } @@ -2013,9 +2038,7 @@ get_generic_assignment :: proc(file: ast.File, value: ^ast.Expr, ast_context: ^A ast_context.call = cast(^ast.Call_Expr)value; if symbol, ok := resolve_type_expression(ast_context, v.expr); ok { - if procedure, ok := symbol.value.(index.SymbolProcedureValue); ok { - for ret in procedure.return_types { append(results, ret.type); } @@ -2489,26 +2512,19 @@ resolve_entire_procedure :: proc(ast_context: ^AstContext, procedure: ast.Proc_L } } - concatenate_symbol_information :: proc { concatenate_raw_symbol_information, concatenate_raw_string_information, } concatenate_raw_symbol_information :: proc(ast_context: ^AstContext, symbol: index.Symbol, is_completion: bool) -> string { - return concatenate_raw_string_information(ast_context, symbol.pkg, symbol.name, symbol.signature, symbol.returns, symbol.type, is_completion); + return concatenate_raw_string_information(ast_context, symbol.pkg, symbol.name, symbol.signature, symbol.type, is_completion); } -concatenate_raw_string_information :: proc(ast_context: ^AstContext, pkg: string, name: string, signature: string, returns: string, type: index.SymbolType, is_completion: bool) -> string { +concatenate_raw_string_information :: proc(ast_context: ^AstContext, pkg: string, name: string, signature: string, type: index.SymbolType, is_completion: bool) -> string { pkg := path.base(pkg, false, context.temp_allocator); - if type == .Function { - if returns != "" { - return fmt.tprintf("%v.%v: proc%v -> %v", pkg, name, signature, returns); - } else { - return fmt.tprintf("%v.%v: proc%v", pkg, name, signature); - } - } else if type == .Package { + if type == .Package { return name; } else if type == .Keyword && is_completion { return name; @@ -2522,7 +2538,6 @@ concatenate_raw_string_information :: proc(ast_context: ^AstContext, pkg: string } unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.SymbolEnumValue, bool) { - if node == nil { return {}, false; } @@ -2538,7 +2553,6 @@ unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.SymbolE } unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.SymbolUnionValue, bool) { - if union_symbol, ok := resolve_type_expression(ast_context, node); ok { if union_value, ok := union_symbol.value.(index.SymbolUnionValue); ok { return union_value, true; @@ -2549,7 +2563,6 @@ unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.Symbol } unwrap_bitset :: proc(ast_context: ^AstContext, bitset_symbol: index.Symbol) -> (index.SymbolEnumValue, bool) { - if bitset_value, ok := bitset_symbol.value.(index.SymbolBitSetValue); ok { if enum_symbol, ok := resolve_type_expression(ast_context, bitset_value.expr); ok { if enum_value, ok := enum_symbol.value.(index.SymbolEnumValue); ok { @@ -2562,7 +2575,6 @@ unwrap_bitset :: proc(ast_context: ^AstContext, bitset_symbol: index.Symbol) -> } get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index.Symbol, was_variable := false) -> string { - using index; if symbol.type == .Function { @@ -2626,7 +2638,6 @@ get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index. } position_in_proc_decl :: proc(position_context: ^DocumentPositionContext) -> bool { - if position_context.value_decl == nil { return false; } @@ -2650,7 +2661,6 @@ position_in_proc_decl :: proc(position_context: ^DocumentPositionContext) -> boo is_lhs_comp_lit :: proc(position_context: ^DocumentPositionContext) -> bool { - if len(position_context.comp_lit.elems) == 0 { return true; } @@ -2674,7 +2684,6 @@ is_lhs_comp_lit :: proc(position_context: ^DocumentPositionContext) -> bool { } field_exists_in_comp_lit :: proc(comp_lit: ^ast.Comp_Lit, name: string) -> bool { - for elem in comp_lit.elems { if field, ok := elem.derived.(ast.Field_Value); ok { @@ -2698,7 +2707,6 @@ field_exists_in_comp_lit :: proc(comp_lit: ^ast.Comp_Lit, name: string) -> bool Parser gives ranges of expression, but not actually where the commas are placed. */ get_call_commas :: proc(position_context: ^DocumentPositionContext, document: ^common.Document) { - if position_context.call == nil { return; } @@ -2733,7 +2741,6 @@ get_call_commas :: proc(position_context: ^DocumentPositionContext, document: ^c } type_to_string :: proc(ast_context: ^AstContext, expr: ^ast.Expr) -> string { - if symbol, ok := resolve_type_expression(ast_context, expr); ok { if .Anonymous in symbol.flags { return symbol.name; @@ -2747,7 +2754,6 @@ type_to_string :: proc(ast_context: ^AstContext, expr: ^ast.Expr) -> string { Figure out what exactly is at the given position and whether it is in a function, struct, etc. */ get_document_position_context :: proc(document: ^common.Document, position: common.Position, hint: DocumentPositionContextHint) -> (DocumentPositionContext, bool) { - position_context: DocumentPositionContext; position_context.hint = hint; @@ -2825,7 +2831,6 @@ get_document_position_context :: proc(document: ^common.Document, position: comm //terrible fallback code fallback_position_context_completion :: proc(document: ^common.Document, position: common.Position, position_context: ^DocumentPositionContext) { - paren_count: int; bracket_count: int; end: int; @@ -3020,7 +3025,6 @@ fallback_position_context_completion :: proc(document: ^common.Document, positio } fallback_position_context_signature :: proc(document: ^common.Document, position: common.Position, position_context: ^DocumentPositionContext) { - end: int; start: int; i := position_context.position - 1; @@ -3100,14 +3104,12 @@ get_document_position ::proc { }; get_document_position_array :: proc(array: $A/[]^$T, position_context: ^DocumentPositionContext) { - for elem, i in array { get_document_position(elem, position_context); } } get_document_position_dynamic_array :: proc(array: $A/[dynamic]^$T, position_context: ^DocumentPositionContext) { - for elem, i in array { get_document_position(elem, position_context); } @@ -3118,7 +3120,6 @@ position_in_node :: proc(node: ^ast.Node, position: common.AbsolutePosition) -> } get_document_position_node :: proc(node: ^ast.Node, position_context: ^DocumentPositionContext) { - using ast; if node == nil { diff --git a/src/common/ast.odin b/src/common/ast.odin index ff6f7e2..0bc789f 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -75,6 +75,25 @@ GlobalExpr :: struct { package_private: bool, } + +unwrap_pointer :: proc(expr: ^ast.Expr) -> (ast.Ident, bool) { + expr := expr; + for expr != nil { + if pointer, ok := expr.derived.(ast.Pointer_Type); ok { + expr = pointer.elem; + } else { + break; + } + } + + if expr != nil { + ident, ok := expr.derived.(ast.Ident); + return ident, ok; + } + + return {}, false; +} + collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^ast.Node, skip_private: bool) { if value_decl, ok := stmt.derived.(ast.Value_Decl); ok { diff --git a/src/index/build.odin b/src/index/build.odin index b6577cb..f04f7ce 100644 --- a/src/index/build.odin +++ b/src/index/build.odin @@ -77,10 +77,10 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi when ODIN_OS == "windows" { builtin_package := path.join(elems = {slashed, "builtin"}, allocator = context.temp_allocator); - append(&indexer.built_in_packages, strings.to_lower(builtin_package)); + append(&indexer.builtin_packages, strings.to_lower(builtin_package)); } else { builtin_package := path.join(elems = {slashed, "builtin"}, allocator = context.allocator); - append(&indexer.built_in_packages, builtin_package); + append(&indexer.builtin_packages, builtin_package); } filepath.walk(builtin_package, walk_static_index_build); diff --git a/src/index/indexer.odin b/src/index/indexer.odin index 6c74436..42b111c 100644 --- a/src/index/indexer.odin +++ b/src/index/indexer.odin @@ -36,7 +36,7 @@ import "core:sort" Indexer :: struct { - built_in_packages: [dynamic]string, + builtin_packages: [dynamic]string, static_index: MemoryIndex, dynamic_index: MemoryIndex, } diff --git a/src/index/symbol.odin b/src/index/symbol.odin index 863701c..dfdb66c 100644 --- a/src/index/symbol.odin +++ b/src/index/symbol.odin @@ -116,7 +116,6 @@ Symbol :: struct { name: string, //name of the symbol doc: string, signature: string, //type signature - returns: string, //precedure return signature type: SymbolType, value: SymbolValue, references: []common.Location, //all the places in the project that it's being referenced @@ -153,10 +152,6 @@ free_symbol :: proc(symbol: Symbol, allocator: mem.Allocator) { delete(symbol.signature, allocator); } - if symbol.returns != "" { - delete(symbol.returns, allocator); - } - if symbol.doc != "" { delete(symbol.doc, allocator); } diff --git a/src/server/completion.odin b/src/server/completion.odin index 0885e00..c458e34 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -155,7 +155,6 @@ get_directive_completion :: proc(ast_context: ^analysis.AstContext, position_con }; for elem in directive_list { - item := CompletionItem { detail = elem, label = elem, @@ -169,7 +168,6 @@ get_directive_completion :: proc(ast_context: ^analysis.AstContext, position_con } get_comp_lit_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis; items := make([dynamic]CompletionItem, context.temp_allocator); @@ -179,17 +177,13 @@ get_comp_lit_completion :: proc(ast_context: ^analysis.AstContext, position_cont } if symbol, ok := resolve_type_expression(ast_context, position_context.parent_comp_lit.type); ok { - if comp_symbol, _, ok := resolve_type_comp_literal(ast_context, position_context, symbol, position_context.parent_comp_lit); ok { - #partial switch v in comp_symbol.value { case index.SymbolStructValue: for name, i in v.names { - ast_context.current_package = comp_symbol.pkg; if resolved, ok := resolve_type_expression(ast_context, v.types[i]); ok { - if field_exists_in_comp_lit(position_context.comp_lit, name) { continue; } @@ -212,7 +206,6 @@ get_comp_lit_completion :: proc(ast_context: ^analysis.AstContext, position_cont } get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis; items := make([dynamic]CompletionItem, context.temp_allocator); @@ -220,9 +213,9 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont ast_context.current_package = ast_context.document_package; selector: index.Symbol; - ok: bool; + ok: bool; - ast_context.use_locals = true; + ast_context.use_locals = true; ast_context.use_globals = true; selector, ok = resolve_type_expression(ast_context, position_context.selector); @@ -231,16 +224,10 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont return; } - if ident, ok := position_context.selector.derived.(ast.Ident); ok { - symbol, ok := resolve_type_identifier(ast_context, ident); - - if !ok { - return; - } - - if (symbol.type != .Variable && symbol.type != .Package && selector.type != .Enum && ident.name != "") || (symbol.type == .Variable && selector.type == .Enum) { - return; - } + //if (selector.type != .Variable && selector.type != .Package && selector.type != .Enum && selector.name != "") || (selector.type == .Variable && selector.type == .Enum) { + + if selector.type != .Variable && selector.type != .Package { + return; } if selector.pkg != "" { @@ -448,7 +435,6 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont symbol := search.symbol; resolve_unresolved_symbol(ast_context, &symbol); - build_procedure_symbol_return(&symbol); build_procedure_symbol_signature(&symbol); item := CompletionItem { @@ -803,7 +789,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co doc: string, pkg: string, signature: string, - returns: string, flags: index.SymbolFlags, }; @@ -849,7 +834,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co for r in results { r := r; resolve_unresolved_symbol(ast_context, &r.symbol); - build_procedure_symbol_return(&r.symbol); build_procedure_symbol_signature(&r.symbol); if r.symbol.uri != ast_context.uri { append(&combined, CombinedResult { @@ -859,7 +843,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co doc = r.symbol.doc, flags = r.symbol.flags, signature = r.symbol.signature, - returns = r.symbol.returns, pkg = r.symbol.pkg, }); } @@ -890,7 +873,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co if symbol, ok := resolve_type_identifier(ast_context, ident^); ok { symbol.signature = get_signature(ast_context, ident^, symbol); - build_procedure_symbol_return(&symbol); build_procedure_symbol_signature(&symbol); if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 { @@ -902,7 +884,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co flags = symbol.flags, pkg = symbol.pkg, signature = symbol.signature, - returns = symbol.returns, }); } } @@ -913,17 +894,18 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co break; } + local_offset := get_local_offset(ast_context, position_context.position, k); + ast_context.use_locals = true; ast_context.use_globals = true; ast_context.current_package = ast_context.document_package; - ident := index.new_type(ast.Ident, {offset = position_context.position}, {offset = position_context.position}, context.temp_allocator); + ident := index.new_type(ast.Ident, {offset = local_offset}, {offset = local_offset}, context.temp_allocator); ident.name = k; if symbol, ok := resolve_type_identifier(ast_context, ident^); ok { symbol.signature = get_signature(ast_context, ident^, symbol); - build_procedure_symbol_return(&symbol); build_procedure_symbol_signature(&symbol); if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 { @@ -935,7 +917,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co flags = symbol.flags, pkg = symbol.pkg, signature = symbol.signature, - returns = symbol.returns, }); } } @@ -959,7 +940,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co doc = symbol.doc, flags = symbol.flags, signature = symbol.signature, - returns = symbol.returns, pkg = symbol.pkg, }); } @@ -979,7 +959,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co doc = symbol.doc, flags = symbol.flags, signature = symbol.signature, - returns = symbol.returns, pkg = symbol.pkg, }); } @@ -999,7 +978,6 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co doc = symbol.doc, flags = symbol.flags, signature = symbol.signature, - returns = symbol.returns, pkg = symbol.pkg, }); } @@ -1063,7 +1041,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co item.command.command = "editor.action.triggerParameterHints"; } - item.detail = concatenate_symbol_information(ast_context, result.pkg, result.name, result.signature, result.returns, result.type, true); + item.detail = concatenate_symbol_information(ast_context, result.pkg, result.name, result.signature, result.type, true); append(&items, item); } diff --git a/src/server/hover.odin b/src/server/hover.odin index b77c0b1..d19d990 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -18,7 +18,6 @@ import "shared:index" import "shared:analysis" write_hover_content :: proc(ast_context: ^analysis.AstContext, symbol: index.Symbol) -> MarkupContent { - using analysis; content: MarkupContent; @@ -34,7 +33,6 @@ write_hover_content :: proc(ast_context: ^analysis.AstContext, symbol: index.Sym } } - build_procedure_symbol_return(&symbol); build_procedure_symbol_signature(&symbol); cat := concatenate_symbol_information(ast_context, symbol, false); @@ -99,7 +97,7 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit resolved.signature = get_signature(&ast_context, ident, resolved); resolved.name = ident.name; - if is_variable, ok := ast_context.variables[ident.name]; ok && is_variable { + if resolved.type == .Variable { resolved.pkg = ast_context.document_package; } @@ -166,7 +164,7 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit resolved.signature = get_signature(&ast_context, ident, resolved); resolved.name = ident.name; - if is_variable, ok := ast_context.variables[ident.name]; ok && is_variable { + if resolved.type == .Variable { resolved.pkg = ast_context.document_package; } diff --git a/src/server/requests.odin b/src/server/requests.odin index 7892432..8d965c7 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -570,9 +570,9 @@ request_initialize :: proc (task: ^common.Task) { if core, ok := config.collections["core"]; ok { when ODIN_OS == "windows" { - append(&index.indexer.built_in_packages, path.join(strings.to_lower(core, context.temp_allocator), "runtime")); + append(&index.indexer.builtin_packages, path.join(strings.to_lower(core, context.temp_allocator), "runtime")); } else { - append(&index.indexer.built_in_packages, path.join(core, "runtime")); + append(&index.indexer.builtin_packages, path.join(core, "runtime")); } } diff --git a/src/server/signature.odin b/src/server/signature.odin index 91e2b47..cc04cd5 100644 --- a/src/server/signature.odin +++ b/src/server/signature.odin @@ -56,6 +56,7 @@ build_procedure_symbol_signature :: proc(symbol: ^index.Symbol) { if value, ok := symbol.value.(index.SymbolProcedureValue); ok { builder := strings.make_builder(context.temp_allocator); + strings.write_string(&builder, "proc"); strings.write_string(&builder, "("); for arg, i in value.arg_types { strings.write_string(&builder, common.node_to_string(arg)); @@ -65,34 +66,27 @@ build_procedure_symbol_signature :: proc(symbol: ^index.Symbol) { } strings.write_string(&builder, ")"); - symbol.signature = strings.to_string(builder); - } -} + if len(value.return_types) != 0 { + strings.write_string(&builder, " -> "); -build_procedure_symbol_return :: proc(symbol: ^index.Symbol) { - if value, ok := symbol.value.(index.SymbolProcedureValue); ok { - builder := strings.make_builder(context.temp_allocator); + if len(value.return_types) > 1 { + strings.write_string(&builder, "("); + } - if len(value.return_types) == 0 { - return; - } - - if len(value.return_types) > 1 { - strings.write_string(&builder, "("); - } - - for arg, i in value.return_types { - strings.write_string(&builder, common.node_to_string(arg)); - if i != len(value.return_types) - 1 { - strings.write_string(&builder, ", "); + for arg, i in value.return_types { + strings.write_string(&builder, common.node_to_string(arg)); + if i != len(value.return_types) - 1 { + strings.write_string(&builder, ", "); + } + } + + if len(value.return_types) > 1 { + strings.write_string(&builder, ")"); } } - - if len(value.return_types) > 1 { - strings.write_string(&builder, ")"); - } - - symbol.returns = strings.to_string(builder); + symbol.signature = strings.to_string(builder); + } else if value, ok := symbol.value.(index.SymbolAggregateValue); ok { + symbol.signature = "proc"; } } @@ -101,7 +95,6 @@ seperate_proc_field_arguments :: proc(procedure: ^index.Symbol) { types := make([dynamic]^ast.Field, context.temp_allocator); for arg, i in value.arg_types { - if len(arg.names) == 1 { append(&types, arg); continue; @@ -122,7 +115,6 @@ seperate_proc_field_arguments :: proc(procedure: ^index.Symbol) { get_signature_information :: proc(document: ^common.Document, position: common.Position) -> (SignatureHelp, bool) { - using analysis; signature_help: SignatureHelp; @@ -175,7 +167,6 @@ get_signature_information :: proc(document: ^common.Document, position: common.P } build_procedure_symbol_signature(&call); - build_procedure_symbol_return(&call); info := SignatureInformation { label = concatenate_symbol_information(&ast_context, call, false), @@ -206,7 +197,6 @@ get_signature_information :: proc(document: ^common.Document, position: common.P } build_procedure_symbol_signature(&symbol); - build_procedure_symbol_return(&symbol); info := SignatureInformation { label = concatenate_symbol_information(&ast_context, symbol, false), diff --git a/tests/completions_test.odin b/tests/completions_test.odin index e0961d6..238cfd3 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -1211,7 +1211,6 @@ ast_distinct_u32_completion :: proc(t: ^testing.T) { @(test) ast_new_completion :: proc(t: ^testing.T) { - source := test.Source { main = `package main new :: proc($T: typeid) -> (^T, Allocator_Error) #optional_second { @@ -1225,25 +1224,24 @@ ast_new_completion :: proc(t: ^testing.T) { `, }; - test.expect_completion_details(t, &source, "", {"test.d: Distinct_Type"}); + test.expect_completion_details(t, &source, "", {"test.adzz: int"}); } @(test) ast_rawtr_cast_completion :: proc(t: ^testing.T) { - source := test.Source { main = `package main main :: proc() { raw: rawptr - my_int := cast(^int)raw; + my_int := cast(int)raw; my_i* } `, }; - test.expect_completion_details(t, &source, "", {"test.d: Distinct_Type"}); + test.expect_completion_details(t, &source, "", {"test.my_int: int"}); } ast_overload_with_procedure_return :: proc(t: ^testing.T) { diff --git a/tests/hover_test.odin b/tests/hover_test.odin index ba4ffb5..6800820 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -79,5 +79,5 @@ ast_hover_external_package_parameter :: proc(t: ^testing.T) { packages = packages[:], }; - test.expect_hover(t, &source, "cool: my_package.My_Struct"); + test.expect_hover(t, &source, "test.cool: My_Struct"); }
\ No newline at end of file diff --git a/tests/signatures_test.odin b/tests/signatures_test.odin index 9363962..6e29db6 100644 --- a/tests/signatures_test.odin +++ b/tests/signatures_test.odin @@ -8,7 +8,6 @@ import test "shared:testing" @(test) ast_declare_proc_signature :: proc(t: ^testing.T) { - source := test.Source { main = `package test main :: proc(*) @@ -21,7 +20,6 @@ ast_declare_proc_signature :: proc(t: ^testing.T) { @(test) ast_naked_parens :: proc(t: ^testing.T) { - source := test.Source { main = `package test main :: proc() { @@ -44,7 +42,6 @@ ast_naked_parens :: proc(t: ^testing.T) { @(test) ast_simple_proc_signature :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int) { @@ -62,7 +59,6 @@ ast_simple_proc_signature :: proc(t: ^testing.T) { @(test) ast_default_assignment_proc_signature :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int, b := context.allocator) { @@ -80,7 +76,6 @@ ast_default_assignment_proc_signature :: proc(t: ^testing.T) { @(test) ast_proc_signature_argument_last_position :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int, b: int) { @@ -98,7 +93,6 @@ ast_proc_signature_argument_last_position :: proc(t: ^testing.T) { @(test) ast_proc_signature_argument_first_position :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int, b: int) { @@ -117,7 +111,6 @@ ast_proc_signature_argument_first_position :: proc(t: ^testing.T) { @(test) ast_proc_signature_argument_move_position :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int, b: int, c: int) { @@ -135,7 +128,6 @@ ast_proc_signature_argument_move_position :: proc(t: ^testing.T) { @(test) ast_proc_signature_argument_complex :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int, b: int, c: int) { @@ -153,7 +145,6 @@ ast_proc_signature_argument_complex :: proc(t: ^testing.T) { @(test) ast_proc_signature_argument_open_brace_position :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(a: int, b: int, c: int) { @@ -171,7 +162,6 @@ ast_proc_signature_argument_open_brace_position :: proc(t: ^testing.T) { @(test) ast_proc_signature_argument_any_ellipsis_position :: proc(t: ^testing.T) { - source := test.Source { main = `package test cool_function :: proc(args: ..any, b := 2) { @@ -189,7 +179,6 @@ ast_proc_signature_argument_any_ellipsis_position :: proc(t: ^testing.T) { @(test) ast_proc_group_signature_empty_call :: proc(t: ^testing.T) { - source := test.Source { main = `package test int_function :: proc(a: int) { @@ -215,7 +204,6 @@ ast_proc_group_signature_empty_call :: proc(t: ^testing.T) { @(test) ast_proc_signature_generic :: proc(t: ^testing.T) { - source := test.Source { main = `package test @@ -236,7 +224,6 @@ ast_proc_signature_generic :: proc(t: ^testing.T) { @(test) ast_proc_group_signature_basic_types :: proc(t: ^testing.T) { - source := test.Source { main = `package test int_function :: proc(a: int, b: bool, c: int) { @@ -263,7 +250,6 @@ ast_proc_group_signature_basic_types :: proc(t: ^testing.T) { @(test) ast_proc_group_signature_distinct_basic_types :: proc(t: ^testing.T) { - source := test.Source { main = `package test @@ -295,7 +281,6 @@ ast_proc_group_signature_distinct_basic_types :: proc(t: ^testing.T) { @(test) ast_proc_group_signature_struct :: proc(t: ^testing.T) { - source := test.Source { main = `package test @@ -336,7 +321,6 @@ ast_proc_group_signature_struct :: proc(t: ^testing.T) { @(test) index_simple_signature :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package); append(&packages, test.Package { @@ -365,7 +349,6 @@ index_simple_signature :: proc(t: ^testing.T) { @(test) ast_index_builtin_len_proc :: proc(t: ^testing.T) { - source := test.Source { main = `package test main :: proc() { @@ -380,7 +363,6 @@ ast_index_builtin_len_proc :: proc(t: ^testing.T) { @(test) ast_signature_on_invalid_package :: proc(t: ^testing.T) { - source := test.Source { main = `package test import "core:totallyReal" @@ -396,7 +378,6 @@ ast_signature_on_invalid_package :: proc(t: ^testing.T) { @(test) ast_signature_variable_pointer :: proc(t: ^testing.T) { - source := test.Source { main = `package test import "core:totallyReal" @@ -418,7 +399,6 @@ ast_signature_variable_pointer :: proc(t: ^testing.T) { @(test) ast_signature_global_variable_pointer :: proc(t: ^testing.T) { - source := test.Source { main = `package test import "core:totallyReal" @@ -440,7 +420,6 @@ ast_signature_global_variable_pointer :: proc(t: ^testing.T) { @(test) index_variable_pointer_signature :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package); append(&packages, test.Package { |