aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-07-10 19:02:32 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-07-10 19:02:32 +0200
commit00c8acb03d457276ec1164142dc67c1c1c2ac97b (patch)
treef02ee6332b6f8f95c79dd075510441ee62eed41b /src
parentdd3346e3f543d9db6ac74e979a1b8c90737f1354 (diff)
improve signatures on completion
Diffstat (limited to 'src')
-rw-r--r--src/index/collector.odin20
-rw-r--r--src/index/symbol.odin34
-rw-r--r--src/server/analysis.odin75
3 files changed, 78 insertions, 51 deletions
diff --git a/src/index/collector.odin b/src/index/collector.odin
index 0bcf02a..e859732 100644
--- a/src/index/collector.odin
+++ b/src/index/collector.odin
@@ -92,7 +92,7 @@ collect_procedure_fields :: proc(collection: ^SymbolCollection, proc_type: ^ast.
return value;
}
-collect_struct_fields :: proc(collection: ^SymbolCollection, struct_type: ast.Struct_Type, package_map: map[string]string) -> SymbolStructValue {
+collect_struct_fields :: proc(collection: ^SymbolCollection, struct_type: ast.Struct_Type, package_map: map[string]string, ident: string) -> SymbolStructValue {
names := make([dynamic]string, 0, collection.allocator);
types := make([dynamic]^ast.Expr, 0, collection.allocator);
@@ -118,12 +118,13 @@ collect_struct_fields :: proc(collection: ^SymbolCollection, struct_type: ast.St
names = names[:],
types = types[:],
usings = usings,
+ struct_name = ident,
};
return value;
}
-collect_enum_fields :: proc(collection: ^SymbolCollection, fields: []^ast.Expr, package_map: map[string]string) -> SymbolEnumValue {
+collect_enum_fields :: proc(collection: ^SymbolCollection, fields: []^ast.Expr, package_map: map[string]string, ident: string) -> SymbolEnumValue {
names := make([dynamic]string, 0, collection.allocator);
@@ -142,12 +143,13 @@ collect_enum_fields :: proc(collection: ^SymbolCollection, fields: []^ast.Expr,
value := SymbolEnumValue {
names = names[:],
+ enum_name = ident,
};
return value;
}
-collect_union_fields :: proc(collection: ^SymbolCollection, union_type: ast.Union_Type, package_map: map[string]string) -> SymbolUnionValue {
+collect_union_fields :: proc(collection: ^SymbolCollection, union_type: ast.Union_Type, package_map: map[string]string, ident: string) -> SymbolUnionValue {
names := make([dynamic]string, 0, collection.allocator);
types := make([dynamic]^ast.Expr, 0, collection.allocator);
@@ -172,18 +174,20 @@ collect_union_fields :: proc(collection: ^SymbolCollection, union_type: ast.Unio
value := SymbolUnionValue {
names = names[:],
types = types[:],
+ union_name = ident,
};
return value;
}
-collect_bitset_field :: proc(collection: ^SymbolCollection, bitset_type: ast.Bit_Set_Type, package_map: map[string]string) -> SymbolBitSetValue {
+collect_bitset_field :: proc(collection: ^SymbolCollection, bitset_type: ast.Bit_Set_Type, package_map: map[string]string, ident: string) -> SymbolBitSetValue {
cloned := clone_type(bitset_type.elem, collection.allocator, &collection.unique_strings);
replace_package_alias(cloned, package_map, collection);
return SymbolBitSetValue {
expr = cloned,
+ bitset_name = ident,
};
}
@@ -307,22 +311,22 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
case ast.Struct_Type:
token = v;
token_type = .Struct;
- symbol.value = collect_struct_fields(collection, v, package_map);
+ symbol.value = collect_struct_fields(collection, v, package_map, name);
symbol.signature = "struct";
case ast.Enum_Type:
token = v;
token_type = .Enum;
- symbol.value = collect_enum_fields(collection, v.fields, package_map);
+ symbol.value = collect_enum_fields(collection, v.fields, package_map, name);
symbol.signature = "enum";
case ast.Union_Type:
token = v;
token_type = .Enum;
- symbol.value = collect_union_fields(collection, v, package_map);
+ symbol.value = collect_union_fields(collection, v, package_map, name);
symbol.signature = "union";
case ast.Bit_Set_Type:
token = v;
token_type = .Enum;
- symbol.value = collect_bitset_field(collection, v, package_map);
+ symbol.value = collect_bitset_field(collection, v, package_map, name);
symbol.signature = "bitset";
case ast.Map_Type:
token = v;
diff --git a/src/index/symbol.odin b/src/index/symbol.odin
index 7410818..4de66c7 100644
--- a/src/index/symbol.odin
+++ b/src/index/symbol.odin
@@ -11,6 +11,7 @@ import "core:slice"
import "shared:common"
SymbolStructValue :: struct {
+ struct_name: string,
names: []string,
types: []^ast.Expr,
usings: map[string]bool,
@@ -35,10 +36,12 @@ SymbolAggregateValue :: struct {
}
SymbolEnumValue :: struct {
+ enum_name: string,
names: []string,
}
SymbolUnionValue :: struct {
+ union_name: string,
names: []string,
types: []^ast.Expr,
}
@@ -61,6 +64,7 @@ SymbolBasicValue :: struct {
}
SymbolBitSetValue :: struct {
+ bitset_name: string,
expr: ^ast.Expr,
}
@@ -124,36 +128,6 @@ SymbolType :: enum {
Unresolved = 9999,
}
-symbol_type_to_string :: proc(symbol: Symbol) -> string {
- #partial switch v in symbol.value {
- case SymbolBasicValue:
- return common.node_to_string(v.ident);
- case SymbolBitSetValue:
- return common.node_to_string(v.expr);
- case SymbolEnumValue:
- return "enum";
- case SymbolMapValue:
- return strings.concatenate(a = {"map[", common.node_to_string(v.key), "]", common.node_to_string(v.value)}, allocator = context.temp_allocator);
- case SymbolProcedureValue:
- return "proc";
- case SymbolStructValue:
- return "struct";
- case SymbolUnionValue:
- return "union";
- case SymbolDynamicArrayValue:
- return strings.concatenate(a = {"[dynamic]", common.node_to_string(v.expr)}, allocator = context.temp_allocator);
- case SymbolSliceValue:
- return strings.concatenate(a = {"[]", common.node_to_string(v.expr)}, allocator = context.temp_allocator);
- case SymbolFixedArrayValue:
- return strings.concatenate(a = {"[", common.node_to_string(v.len), "]", common.node_to_string(v.expr)}, allocator = context.temp_allocator);
- case SymbolPackageValue:
- return "package";
- case SymbolUntypedValue:
- }
-
- return "";
-}
-
free_symbol :: proc(symbol: Symbol, allocator: mem.Allocator) {
if symbol.signature != "" && symbol.signature != "struct" &&
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 74479ef..587e134 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1029,16 +1029,16 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
case Ident:
return_symbol, ok = resolve_type_identifier(ast_context, v);
case Union_Type:
- return_symbol, ok = make_symbol_union_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_union_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Enum_Type:
- return_symbol, ok = make_symbol_enum_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_enum_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Struct_Type:
- return_symbol, ok = make_symbol_struct_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_struct_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Bit_Set_Type:
- return_symbol, ok = make_symbol_bitset_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_bitset_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Proc_Lit:
if !v.type.generic {
@@ -1085,16 +1085,16 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
case Ident:
return_symbol, ok = resolve_type_identifier(ast_context, v);
case Struct_Type:
- return_symbol, ok = make_symbol_struct_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_struct_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Bit_Set_Type:
- return_symbol, ok = make_symbol_bitset_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_bitset_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Union_Type:
- return_symbol, ok = make_symbol_union_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_union_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Enum_Type:
- return_symbol, ok = make_symbol_enum_from_ast(ast_context, v), true;
+ return_symbol, ok = make_symbol_enum_from_ast(ast_context, v, node.name), true;
return_symbol.name = node.name;
case Proc_Lit:
if !v.type.generic {
@@ -1565,7 +1565,7 @@ make_symbol_basic_type_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node,
return symbol;
}
-make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type) -> index.Symbol {
+make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, ident: string) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1590,12 +1590,13 @@ make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type)
symbol.value = index.SymbolUnionValue {
names = names[:],
types = v.variants,
+ union_name = ident,
};
return symbol;
}
-make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type) -> index.Symbol {
+make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, ident: string) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1619,12 +1620,13 @@ make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type) ->
symbol.value = index.SymbolEnumValue {
names = names[:],
+ enum_name = ident,
};
return symbol;
}
-make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Type) -> index.Symbol {
+make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Type, ident: string) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1634,12 +1636,13 @@ make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Typ
symbol.value = index.SymbolBitSetValue {
expr = v.elem,
+ bitset_name = ident,
};
return symbol;
}
-make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type) -> index.Symbol {
+make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type, ident: string) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1669,6 +1672,7 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type
names = names[:],
types = types[:],
usings = usings,
+ struct_name = ident,
};
if v.poly_params != nil {
@@ -2300,11 +2304,56 @@ get_definition_location :: proc(document: ^Document, position: common.Position)
get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index.Symbol, was_variable := false) -> string {
+ using index;
+
if symbol.type == .Function {
return symbol.signature;
}
- return index.symbol_type_to_string(symbol);
+ is_variable := resolve_ident_is_variable(ast_context, ident);
+
+ #partial switch v in symbol.value {
+ case SymbolBasicValue:
+ return common.node_to_string(v.ident);
+ case SymbolBitSetValue:
+ return common.node_to_string(v.expr);
+ case SymbolEnumValue:
+ if is_variable {
+ return v.enum_name;
+ }
+ else {
+ return "enum";
+ }
+ case SymbolMapValue:
+ return strings.concatenate(a = {"map[", common.node_to_string(v.key), "]", common.node_to_string(v.value)}, allocator = context.temp_allocator);
+ case SymbolProcedureValue:
+ return "proc";
+ case SymbolStructValue:
+ if is_variable {
+ return v.struct_name;
+ }
+ else {
+ return "struct";
+ }
+ case SymbolUnionValue:
+ if is_variable {
+ return v.union_name;
+ }
+ else {
+ return "union";
+ }
+ case SymbolDynamicArrayValue:
+ return strings.concatenate(a = {"[dynamic]", common.node_to_string(v.expr)}, allocator = context.temp_allocator);
+ case SymbolSliceValue:
+ return strings.concatenate(a = {"[]", common.node_to_string(v.expr)}, allocator = context.temp_allocator);
+ case SymbolFixedArrayValue:
+ return strings.concatenate(a = {"[", common.node_to_string(v.len), "]", common.node_to_string(v.expr)}, allocator = context.temp_allocator);
+ case SymbolPackageValue:
+ return "package";
+ case SymbolUntypedValue:
+ }
+
+ return "";
}
get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {