aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-10-05 13:03:55 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-10-05 13:03:55 +0200
commite0dc37746a0cab0cc714212b756cce309f1c9914 (patch)
treed0f6eec5c5b6014d7081f92bfeccc9718baccb51 /src
parentbd888dd3d45ecc9994bffe4c33c44af3dc765d02 (diff)
Handle untyped variables in generics. Also don't show signatures with the overloaded types.
Diffstat (limited to 'src')
-rw-r--r--src/server/analysis.odin14
-rw-r--r--src/server/collector.odin8
-rw-r--r--src/server/generics.odin20
-rw-r--r--src/server/signature.odin26
-rw-r--r--src/server/symbol.odin9
5 files changed, 46 insertions, 31 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 6264fc4..36d6781 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1155,11 +1155,14 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide
case "nil":
return {}, false
case "true", "false":
+ token := tokenizer.Token {
+ text = ident.name,
+ }
return {
type = .Keyword,
signature = node.name,
pkg = ast_context.current_package,
- value = SymbolUntypedValue{type = .Bool},
+ value = SymbolUntypedValue{type = .Bool, tok = token},
},
true
case:
@@ -1237,7 +1240,6 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide
make_symbol_procedure_from_ast(ast_context, local.rhs, v.type^, node, {}, false), true
}
} else {
-
return_symbol, ok =
make_symbol_procedure_from_ast(ast_context, local.rhs, v.type^, node, {}, false), true
}
@@ -2303,9 +2305,11 @@ make_symbol_procedure_from_ast :: proc(
}
symbol.value = SymbolProcedureValue {
- return_types = return_types[:],
- arg_types = arg_types[:],
- generic = v.generic,
+ return_types = return_types[:],
+ orig_return_types = return_types[:],
+ arg_types = arg_types[:],
+ orig_arg_types = arg_types[:],
+ generic = v.generic,
}
if _, ok := common.get_attribute_objc_name(attributes); ok {
diff --git a/src/server/collector.odin b/src/server/collector.odin
index a9df6a6..da98f6a 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -126,9 +126,11 @@ collect_procedure_fields :: proc(
}
value := SymbolProcedureValue {
- return_types = returns[:],
- arg_types = args[:],
- generic = is_procedure_generic(proc_type),
+ return_types = returns[:],
+ orig_return_types = returns[:],
+ arg_types = args[:],
+ orig_arg_types = args[:],
+ generic = is_procedure_generic(proc_type),
}
return value
diff --git a/src/server/generics.odin b/src/server/generics.odin
index ffb3cb6..9d5abbc 100644
--- a/src/server/generics.odin
+++ b/src/server/generics.odin
@@ -47,11 +47,15 @@ resolve_poly :: proc(
if specialization == nil {
if type != nil {
if ident, ok := unwrap_ident(type); ok {
- save_poly_map(
- ident,
- make_ident_ast(ast_context, call_node.pos, call_node.end, call_symbol.name),
- poly_map,
- )
+ if untyped_value, ok := call_symbol.value.(SymbolUntypedValue); ok {
+ save_poly_map(ident, symbol_to_expr(call_symbol, call_node.pos.file), poly_map)
+ } else {
+ save_poly_map(
+ ident,
+ make_ident_ast(ast_context, call_node.pos, call_node.end, call_symbol.name),
+ poly_map,
+ )
+ }
}
}
return true
@@ -611,8 +615,10 @@ resolve_generic_function_symbol :: proc(
symbol.value = SymbolProcedureValue {
- return_types = return_types[:],
- arg_types = argument_types[:],
+ return_types = return_types[:],
+ arg_types = argument_types[:],
+ orig_arg_types = params[:],
+ orig_return_types = results[:],
}
return symbol, true
diff --git a/src/server/signature.odin b/src/server/signature.odin
index 6034b4d..f6a277c 100644
--- a/src/server/signature.odin
+++ b/src/server/signature.odin
@@ -55,29 +55,29 @@ build_procedure_symbol_signature :: proc(symbol: ^Symbol) {
strings.write_string(&builder, "proc")
strings.write_string(&builder, "(")
- for arg, i in value.arg_types {
+ for arg, i in value.orig_arg_types {
strings.write_string(&builder, common.node_to_string(arg))
- if i != len(value.arg_types) - 1 {
+ if i != len(value.orig_arg_types) - 1 {
strings.write_string(&builder, ", ")
}
}
strings.write_string(&builder, ")")
- if len(value.return_types) != 0 {
+ if len(value.orig_return_types) != 0 {
strings.write_string(&builder, " -> ")
- if len(value.return_types) > 1 {
+ if len(value.orig_return_types) > 1 {
strings.write_string(&builder, "(")
}
- for arg, i in value.return_types {
+ for arg, i in value.orig_return_types {
strings.write_string(&builder, common.node_to_string(arg))
- if i != len(value.return_types) - 1 {
+ if i != len(value.orig_return_types) - 1 {
strings.write_string(&builder, ", ")
}
}
- if len(value.return_types) > 1 {
+ if len(value.orig_return_types) > 1 {
strings.write_string(&builder, ")")
}
}
@@ -91,7 +91,7 @@ seperate_proc_field_arguments :: proc(procedure: ^Symbol) {
if value, ok := &procedure.value.(SymbolProcedureValue); ok {
types := make([dynamic]^ast.Field, context.temp_allocator)
- for arg, i in value.arg_types {
+ for arg, i in value.orig_arg_types {
if len(arg.names) == 1 {
append(&types, arg)
continue
@@ -106,7 +106,7 @@ seperate_proc_field_arguments :: proc(procedure: ^Symbol) {
}
}
- value.arg_types = types[:]
+ value.orig_arg_types = types[:]
}
}
@@ -162,9 +162,9 @@ get_signature_information :: proc(document: ^Document, position: common.Position
signature_information := make([dynamic]SignatureInformation, context.temp_allocator)
if value, ok := call.value.(SymbolProcedureValue); ok {
- parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator)
+ parameters := make([]ParameterInformation, len(value.orig_arg_types), context.temp_allocator)
- for arg, i in value.arg_types {
+ for arg, i in value.orig_arg_types {
if arg.type != nil {
if _, is_ellipsis := arg.type.derived.(^ast.Ellipsis); is_ellipsis {
signature_help.activeParameter = min(i, signature_help.activeParameter)
@@ -188,9 +188,9 @@ get_signature_information :: proc(document: ^Document, position: common.Position
symbol := symbol
if value, ok := symbol.value.(SymbolProcedureValue); ok {
- parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator)
+ parameters := make([]ParameterInformation, len(value.orig_arg_types), context.temp_allocator)
- for arg, i in value.arg_types {
+ for arg, i in value.orig_arg_types {
if arg.type != nil {
if _, is_ellipsis := arg.type.derived.(^ast.Ellipsis); is_ellipsis {
signature_help.activeParameter = min(i, signature_help.activeParameter)
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index 0e67b33..6769a65 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -36,9 +36,11 @@ SymbolBitFieldValue :: struct {
SymbolPackageValue :: struct {}
SymbolProcedureValue :: struct {
- return_types: []^ast.Field,
- arg_types: []^ast.Field,
- generic: bool,
+ return_types: []^ast.Field,
+ arg_types: []^ast.Field,
+ orig_return_types: []^ast.Field, //If there has been generics, we still store the unaltered version here
+ orig_arg_types: []^ast.Field, //If there has been generics, we still store the unaltered version here
+ generic: bool,
}
SymbolProcedureGroupValue :: struct {
@@ -342,6 +344,7 @@ symbol_to_expr :: proc(symbol: Symbol, file: string, allocator := context.temp_a
return type
case SymbolUntypedValue:
type := new_type(ast.Basic_Lit, pos, end, allocator)
+ type.tok = v.tok
return type
case SymbolMatrixValue:
type := new_type(ast.Matrix_Type, pos, end, allocator)