diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-06-11 11:46:14 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-06-11 11:46:14 +0200 |
| commit | 70d5bcf8eca474440020c31239cd827cf3bb3415 (patch) | |
| tree | 3fec51ed6f3257ad73b971e98dcb7c6b5e1f68fc /src/server/collector.odin | |
| parent | eda3110541a5a9f6f5e3b9428139f5d060e6a3ae (diff) | |
More reference work
Diffstat (limited to 'src/server/collector.odin')
| -rw-r--r-- | src/server/collector.odin | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/src/server/collector.odin b/src/server/collector.odin index b044f1c..632a94c 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -43,6 +43,7 @@ make_symbol_collection :: proc(allocator := context.allocator, config: ^common.C allocator = allocator, config = config, packages = make(map[string]map[string]Symbol, 16, allocator), + references = make(map[string]map[string]Reference, 100, allocator), unique_strings = make(map[string]string, 16, allocator), } } @@ -54,10 +55,13 @@ delete_symbol_collection :: proc(collection: SymbolCollection) { } } - for k, v in collection.references { - for k2, v2 in v { - common.free_ast(v2.identifiers, collection.allocator) - common.free_ast(v2.selectors, collection.allocator) + for _, pkg in collection.references { + for _, reference in pkg { + delete(reference.identifiers) + for _, field in reference.selectors { + delete(field) + } + delete(reference.selectors) } } @@ -80,7 +84,7 @@ delete_symbol_collection :: proc(collection: SymbolCollection) { collect_procedure_fields :: proc(collection: ^SymbolCollection, proc_type: ^ast.Proc_Type, arg_list: ^ast.Field_List, return_list: ^ast.Field_List, package_map: map[string]string) -> SymbolProcedureValue { returns := make([dynamic]^ast.Field, 0, collection.allocator) - args := make([dynamic]^ast.Field, 0, collection.allocator) + args := make([dynamic]^ast.Field, 0, collection.allocator) if return_list != nil { for ret in return_list.list { @@ -107,8 +111,8 @@ collect_procedure_fields :: proc(collection: ^SymbolCollection, proc_type: ^ast. } collect_struct_fields :: proc(collection: ^SymbolCollection, struct_type: ast.Struct_Type, package_map: map[string]string) -> SymbolStructValue { - names := make([dynamic]string, 0, collection.allocator) - types := make([dynamic]^ast.Expr, 0, collection.allocator) + names := make([dynamic]string, 0, collection.allocator) + types := make([dynamic]^ast.Expr, 0, collection.allocator) usings := make(map[string]bool, 0, collection.allocator) for field in struct_type.fields.list { @@ -385,8 +389,10 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri symbol.type = token_type symbol.doc = common.get_doc(expr.docs, collection.allocator) - if expr.builtin { + if expr.builtin || strings.contains(uri, "builtin.odin") { symbol.pkg = "$builtin" + } else if strings.contains(uri, "builtin.odin") { + symbol.pkg = "$intrinsics" } else { symbol.pkg = get_index_unique_string(collection, directory) } @@ -424,8 +430,8 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri } Reference :: struct { - identifiers: [dynamic]^ast.Ident, - selectors: [dynamic]^ast.Selector_Expr, + identifiers: [dynamic]common.Location, + selectors: map[string][dynamic]common.Range, } collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error { @@ -442,13 +448,10 @@ collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: s document.uri = uri document.text = transmute([]u8)file.src document.used_text = len(file.src) - document.allocator = document_get_allocator() - - context.allocator = common.scratch_allocator(document.allocator) parse_imports(&document, &common.config) - symbols_and_nodes := resolve_entire_file(&document, common.scratch_allocator(document.allocator)) + symbols_and_nodes := resolve_entire_file(&document, true) for k, v in symbols_and_nodes { pkg: ^map[string]Reference @@ -458,22 +461,28 @@ collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: s pkg = &collection.references[v.symbol.pkg] } + assert(pkg != nil) + ref: ^Reference - if ref, ok := &pkg[v.symbol.name]; !ok { + if ref, ok = &pkg[v.symbol.name]; !ok { pkg[get_index_unique_string(collection, v.symbol.name)] = {} ref = &pkg[v.symbol.name] + ref.identifiers = make([dynamic]common.Location, 100, collection.allocator) + ref.selectors = make(map[string][dynamic]common.Range, 100, collection.allocator) } + assert(ref != nil) + if ident, ok := v.node.derived.(^ast.Ident); ok { - append(&ref.identifiers, cast(^ast.Ident)clone_type(ident, collection.allocator, nil)) + range := common.get_token_range(ident, ident.name) + append(&ref.identifiers, common.Location { range = range, uri = get_index_unique_string(collection, ident.pos.file) }) + } else if selector, ok := v.node.derived.(^ast.Selector_Expr); ok { - append(&ref.selectors, cast(^ast.Selector_Expr)clone_type(selector, collection.allocator, nil)) + //append(&ref.selectors, cast(^ast.Selector_Expr)clone_type(selector, collection.allocator, nil)) } } - document_free_allocator(document.allocator) - return .None } @@ -498,7 +507,7 @@ get_package_mapping :: proc(file: ast.File, config: ^common.Config, directory: s name: string - full := path.join(elems = {dir, p}, allocator = context.temp_allocator) + full := path.join(elems = {dir, p}, allocator = context.temp_allocator) if imp.name.text != "" { name = imp.name.text @@ -506,7 +515,7 @@ get_package_mapping :: proc(file: ast.File, config: ^common.Config, directory: s name = path.base(full, false, context.temp_allocator) } - package_map[name] = full + package_map[name] = full } else { name: string @@ -519,7 +528,7 @@ get_package_mapping :: proc(file: ast.File, config: ^common.Config, directory: s name = path.base(full, false, context.temp_allocator) } - package_map[name] = full + package_map[name] = full } } |