aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-23 09:38:10 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-24 08:55:23 -0400
commit0d7f28a8ca38fbdd4baa522ec1caf9316d090d19 (patch)
treef191c7139e18154e556bb8742eb1cc0cafa1e118 /src
parente239a9a74e732d91cc3e7e1c4b2dc68da1f2cb4c (diff)
Check types before adding pointer completion
Diffstat (limited to 'src')
-rw-r--r--src/server/analysis.odin22
-rw-r--r--src/server/completion.odin9
-rw-r--r--src/server/documentation.odin4
-rw-r--r--src/server/hover.odin2
-rw-r--r--src/server/symbol.odin31
5 files changed, 41 insertions, 27 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 053273a..d65a410 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -408,7 +408,12 @@ are_symbol_basic_same_keywords :: proc(a, b: Symbol) -> bool {
return true
}
-is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.Field_Flags = {}) -> bool {
+is_symbol_same_typed :: proc(
+ ast_context: ^AstContext,
+ a, b: Symbol,
+ flags: ast.Field_Flags = {},
+ ignore_pointers := false,
+) -> bool {
// In order to correctly equate the symbols for overloaded functions, we need to check both directions
if same, ok := are_symbol_untyped_basic_same_typed(a, b); ok {
return same
@@ -423,7 +428,7 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.
return false
}
- if a.pointers != b.pointers {
+ if !ignore_pointers && a.pointers != b.pointers {
return false
}
@@ -438,11 +443,11 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.
#partial switch b_value in b.value {
case SymbolBasicValue:
if .Any_Int in flags {
- //Temporary - make a function that finds the base type of basic values
- //This code only works with non distinct ints
- switch a.name {
- case "int", "uint", "u32", "i32", "u8", "i8", "u64", "u16", "i16":
- return true
+ names := untyped_map[.Integer]
+ for name in names {
+ if a.name == name {
+ return true
+ }
}
}
}
@@ -453,7 +458,8 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.
#partial switch a_value in a.value {
case SymbolBasicValue:
- return a.name == b.name && a.pkg == b.pkg
+ b_value := b.value.(SymbolBasicValue)
+ return a_value.ident.name == b_value.ident.name && a.pkg == b.pkg
case SymbolStructValue, SymbolEnumValue, SymbolUnionValue, SymbolBitSetValue:
return a.name == b.name && a.pkg == b.pkg
case SymbolSliceValue:
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 0b00f5b..5d28c3f 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -318,7 +318,7 @@ convert_completion_results :: proc(
}
if s, ok := symbol.(Symbol); ok && (completion_type == .Selector || completion_type == .Identifier) {
- handle_pointers(position_context, result.symbol, s, &item, completion_type)
+ handle_pointers(ast_context, position_context, result.symbol, s, &item, completion_type)
}
if common.config.enable_label_details {
@@ -372,6 +372,7 @@ convert_completion_results :: proc(
@(private = "file")
handle_pointers :: proc(
+ ast_context: ^AstContext,
position_context: ^DocumentPositionContext,
result_symbol: Symbol,
arg_symbol: Symbol,
@@ -384,6 +385,10 @@ handle_pointers :: proc(
}
}
+ if !is_symbol_same_typed(ast_context, arg_symbol, result_symbol, ignore_pointers = true) {
+ return
+ }
+
diff := result_symbol.pointers - arg_symbol.pointers
suffix := ""
prefix := ""
@@ -861,7 +866,7 @@ get_selector_completion :: proc(
completion_item = CompletionItem {
label = fmt.tprintf(".%s", name),
kind = .EnumMember,
- detail = fmt.tprintf("%s.%s", receiver, name),
+ detail = fmt.tprintf("%s.%s", selector.name, name),
additionalTextEdits = remove_edit,
},
},
diff --git a/src/server/documentation.odin b/src/server/documentation.odin
index ac1227f..a32b7d5 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -814,7 +814,9 @@ write_symbol_name :: proc(sb: ^strings.Builder, symbol: Symbol) {
fmt.sbprintf(sb, "%v: package", symbol.name)
return
}
- if pkg != "" && pkg != "$builtin" {
+ if symbol.parent_name != "" {
+ fmt.sbprintf(sb, "%v.", symbol.parent_name)
+ } else if pkg != "" && pkg != "$builtin" {
fmt.sbprintf(sb, "%v.", pkg)
}
strings.write_string(sb, symbol.name)
diff --git a/src/server/hover.odin b/src/server/hover.odin
index 86fd6a8..0dc25e6 100644
--- a/src/server/hover.odin
+++ b/src/server/hover.odin
@@ -468,7 +468,7 @@ get_soa_field_hover :: proc(
}
if symbol, ok := resolve_soa_selector_field(ast_context, selector, expr, size, field); ok {
if selector.name != "" {
- symbol.pkg = selector.name
+ symbol.parent_name = selector.name
}
symbol.name = field
build_documentation(ast_context, &symbol, false)
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index 3e97fba..e87cb70 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -204,19 +204,20 @@ SymbolFlag :: enum {
SymbolFlags :: bit_set[SymbolFlag]
Symbol :: struct {
- range: common.Range, //the range of the symbol in the file
- uri: string, //uri of the file the symbol resides
- pkg: string, //absolute directory path where the symbol resides
- name: string, //name of the symbol
- doc: string,
- comment: string,
- signature: string, //type signature
- type: SymbolType,
- type_pkg: string,
- type_name: string,
- value: SymbolValue,
- pointers: int, //how many `^` are applied to the symbol
- flags: SymbolFlags,
+ range: common.Range, //the range of the symbol in the file
+ uri: string, //uri of the file the symbol resides
+ pkg: string, //absolute directory path where the symbol resides
+ name: string, //name of the symbol
+ doc: string,
+ comment: string,
+ signature: string, //type signature
+ type: SymbolType,
+ parent_name: string, // When symbol is a field, this is the name of the parent symbol it is a field of
+ type_pkg: string,
+ type_name: string,
+ value: SymbolValue,
+ pointers: int, //how many `^` are applied to the symbol
+ flags: SymbolFlags,
}
SymbolType :: enum {
@@ -846,8 +847,8 @@ construct_struct_field_symbol :: proc(symbol: ^Symbol, parent_name: string, valu
symbol.type_pkg = symbol.pkg
symbol.type_name = symbol.name
symbol.name = value.names[index]
- symbol.pkg = parent_name
symbol.type = .Field
+ symbol.parent_name = parent_name
symbol.doc = get_doc(value.types[index], value.docs[index], context.temp_allocator)
symbol.comment = get_comment(value.comments[index])
}
@@ -859,7 +860,7 @@ construct_bit_field_field_symbol :: proc(
index: int,
) {
symbol.name = value.names[index]
- symbol.pkg = parent_name
+ symbol.parent_name = parent_name
symbol.type = .Field
symbol.doc = get_doc(value.types[index], value.docs[index], context.temp_allocator)
symbol.comment = get_comment(value.comments[index])