aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2020-12-10 19:43:33 +0100
committerDanielGavin <danielgavin5@hotmail.com>2020-12-10 19:43:33 +0100
commit3efec82999f08bd32e967e07103762a4840a8e48 (patch)
tree6b9f966114a7dd91f5397ff877e688af9aaebc16 /src
parent73ecf08cf959ceea663d3e7ce67f8e3d441d6ddc (diff)
now indexing global variables
Diffstat (limited to 'src')
-rw-r--r--src/index/collector.odin50
-rw-r--r--src/server/analysis.odin17
2 files changed, 59 insertions, 8 deletions
diff --git a/src/index/collector.odin b/src/index/collector.odin
index 070b5ad..b69d5eb 100644
--- a/src/index/collector.odin
+++ b/src/index/collector.odin
@@ -155,6 +155,19 @@ collect_union_fields :: proc(collection: ^SymbolCollection, union_type: ast.Unio
return value;
}
+collect_generic :: proc(collection: ^SymbolCollection, expr: ^ast.Expr, package_map: map [string] string) -> SymbolGenericValue {
+
+ cloned := clone_type(expr, collection.allocator, &collection.unique_strings);
+ replace_package_alias(cloned, package_map, collection);
+
+ value := SymbolGenericValue {
+ expr = cloned,
+ };
+
+ return value;
+}
+
+
collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error {
forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator);
@@ -243,7 +256,6 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
//right now i'm not checking comments whether is for windows, linux, etc, and some packages do not specify that(os)
if v, ok := collection.symbols[id]; !ok {
collection.symbols[id] = symbol;
- //fmt.printf("FAILED COLLOSION! %v %v \n", id, cat);
}
else {
@@ -252,6 +264,42 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
}
+ else {
+
+ for name, i in value_decl.names {
+
+ str := common.get_ast_node_string(name, file.src);
+
+ symbol: Symbol;
+ symbol.range = common.get_token_range(name, file.src);
+ symbol.name = get_index_unique_string(collection, str);
+ symbol.pkg = get_index_unique_string(collection, directory);
+ symbol.uri = get_index_unique_string(collection, uri);
+ symbol.type = .Variable;
+
+ if value_decl.type != nil {
+ symbol.value = collect_generic(collection, value_decl.type, package_map);
+ }
+
+ else {
+ if len(value_decl.values) > i {
+ symbol.value = collect_generic(collection, value_decl.values[i], package_map);
+ }
+ }
+
+ cat := strings.concatenate({symbol.pkg, str}, context.temp_allocator);
+
+ id := get_symbol_id(cat);
+
+ if v, ok := collection.symbols[id]; !ok {
+ collection.symbols[id] = symbol;
+ }
+
+ else {
+ free_symbol(symbol, collection.allocator);
+ }
+ }
+ }
}
}
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 5990d1d..e348781 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -867,8 +867,12 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
resolve_ident_is_variable :: proc(ast_context: ^AstContext, node: ast.Ident) -> bool {
- if v, ok := ast_context.variables[node.name]; ok {
- return v;
+ if v, ok := ast_context.variables[node.name]; ok && v {
+ return true;
+ }
+
+ if symbol, ok := index.lookup(node.name, ast_context.current_package); ok {
+ return symbol.type == .Variable;
}
return false;
@@ -917,6 +921,8 @@ resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok
else {
return symbol, true;
}
+ case index.SymbolGenericValue:
+ return resolve_type_expression(ast_context, v.expr);
}
return symbol, true;
@@ -1708,6 +1714,8 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> (
if position_context.selector != nil {
+ ast_context.current_package = ast_context.document_package;
+
if ident, ok := position_context.selector.derived.(ast.Ident); ok {
if !resolve_ident_is_variable(&ast_context, ident) && !resolve_ident_is_package(&ast_context, ident) {
@@ -1722,7 +1730,6 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> (
ast_context.use_locals = true;
ast_context.use_globals = true;
- ast_context.current_package = ast_context.document_package;
selector, ok = resolve_type_expression(&ast_context, position_context.selector);
@@ -1998,7 +2005,6 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> (
}
-
sort.sort(combined_sort_interface(&combined));
//hard code for now
@@ -2036,9 +2042,6 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> (
list.items = items[:];
}
-
-
-
return list, true;
}