diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2020-12-07 00:52:15 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2020-12-07 00:52:15 +0100 |
| commit | 4abc7efc0d8089db35120a16b6fd8ae079db1104 (patch) | |
| tree | 0e7773d9f91d5894a5e685a97c25f44a8beca114 /src/index | |
| parent | a564f967118551f339cf00d107b45953e8c10505 (diff) | |
better detail on completion and signatures with documentation
Diffstat (limited to 'src/index')
| -rw-r--r-- | src/index/collector.odin | 76 | ||||
| -rw-r--r-- | src/index/indexer.odin | 10 | ||||
| -rw-r--r-- | src/index/memory_index.odin | 10 | ||||
| -rw-r--r-- | src/index/symbol.odin | 10 |
4 files changed, 80 insertions, 26 deletions
diff --git a/src/index/collector.odin b/src/index/collector.odin index f8dfb63..dc2c050 100644 --- a/src/index/collector.odin +++ b/src/index/collector.odin @@ -88,16 +88,16 @@ collect_procedure_fields :: proc(collection: ^SymbolCollection, proc_type: ^ast. return value; } -collect_struct_fields :: proc(collection: ^SymbolCollection, fields: ^ast.Field_List, package_map: map [string] string) -> SymbolStructValue { +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); - for field in fields.list { + for field in struct_type.fields.list { for n in field.names { - identifier := n.derived.(ast.Ident); - append(&names, get_index_unique_string(collection, identifier.name)); + ident := n.derived.(ast.Ident); + append(&names, get_index_unique_string(collection, ident.name)); cloned := clone_type(field.type, collection.allocator, &collection.unique_strings); replace_package_alias(cloned, package_map, collection); @@ -115,7 +115,45 @@ collect_struct_fields :: proc(collection: ^SymbolCollection, fields: ^ast.Field_ return value; } +collect_enum_fields :: proc(collection: ^SymbolCollection, fields: [] ^ast.Expr, package_map: map [string] string) -> SymbolEnumValue { + names := make([dynamic] string, 0, collection.allocator); + + for n in fields { + + if ident, ok := n.derived.(ast.Ident); ok { + append(&names, get_index_unique_string(collection, ident.name)); + } + + } + + value := SymbolEnumValue { + names = names[:], + }; + + + return value; +} + +collect_union_fields :: proc(collection: ^SymbolCollection, union_type: ast.Union_Type, package_map: map [string] string) -> SymbolUnionValue { + + names := make([dynamic] string, 0, collection.allocator); + + + for variant in union_type.variants { + + if ident, ok := variant.derived.(ast.Ident); ok { + append(&names, get_index_unique_string(collection, ident.name)); + } + + } + + value := SymbolUnionValue { + names = names[:], + }; + + return value; +} collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error { @@ -158,18 +196,42 @@ 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.fields, package_map); + symbol.value = collect_struct_fields(collection, v, package_map); + case ast.Enum_Type: + token = v; + token_type = .Enum; + symbol.value = collect_enum_fields(collection, v.fields, package_map); + case ast.Union_Type: + token = v; + token_type = .Enum; + symbol.value = collect_union_fields(collection, v, package_map); case: // default break; } symbol.range = common.get_token_range(token, file.src); symbol.name = get_index_unique_string(collection, name); - symbol.scope = get_index_unique_string(collection, directory); + symbol.pkg = get_index_unique_string(collection, directory); symbol.type = token_type; symbol.uri = get_index_unique_string(collection, uri); - cat := strings.concatenate({symbol.scope, name}, context.temp_allocator); + + if value_decl.docs != nil { + + tmp: string; + + for doc in value_decl.docs.list { + tmp = strings.concatenate({tmp, "\n", doc.text}, context.temp_allocator); + } + + if tmp != "" { + replaced, allocated := strings.replace_all(tmp, "//", "", context.temp_allocator); + symbol.doc = strings.clone(replaced, collection.allocator); + } + + } + + cat := strings.concatenate({symbol.pkg, name}, context.temp_allocator); id := get_symbol_id(cat); diff --git a/src/index/indexer.odin b/src/index/indexer.odin index e7d23e3..0cd25fe 100644 --- a/src/index/indexer.odin +++ b/src/index/indexer.odin @@ -44,14 +44,14 @@ Indexer :: struct { indexer: Indexer; -lookup :: proc(name: string, scope: string, loc := #caller_location) -> (Symbol, bool) { - symbol, ok := memory_index_lookup(&indexer.static_index, name, scope); - log.infof("lookup name: %v scope: %v, symbol %v location %v", name, scope, symbol, loc); +lookup :: proc(name: string, pkg: string, loc := #caller_location) -> (Symbol, bool) { + symbol, ok := memory_index_lookup(&indexer.static_index, name, pkg); + log.infof("lookup name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc); return symbol, ok; } -fuzzy_search :: proc(name: string, scope: [] string) -> ([] Symbol, bool) { - return memory_index_fuzzy_search(&indexer.static_index, name, scope); +fuzzy_search :: proc(name: string, pkgs: [] string) -> ([] Symbol, bool) { + return memory_index_fuzzy_search(&indexer.static_index, name, pkgs); } diff --git a/src/index/memory_index.odin b/src/index/memory_index.odin index 05de53b..c7ab26e 100644 --- a/src/index/memory_index.odin +++ b/src/index/memory_index.odin @@ -26,14 +26,12 @@ make_memory_index :: proc(collection: SymbolCollection) -> MemoryIndex { } -memory_index_lookup :: proc(index: ^MemoryIndex, name: string, scope: string) -> (Symbol, bool) { - //hashed := hash.murmur64(transmute([]u8)strings.concatenate({scope, name}, context.temp_allocator)); - - id := get_symbol_id(strings.concatenate({scope, name}, context.temp_allocator)); +memory_index_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> (Symbol, bool) { + id := get_symbol_id(strings.concatenate({pkg, name}, context.temp_allocator)); return index.collection.symbols[id]; } -memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, scope: [] string) -> ([] Symbol, bool) { +memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: [] string) -> ([] Symbol, bool) { symbols := make([dynamic] Symbol, 0, context.temp_allocator); @@ -48,7 +46,7 @@ memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, scope: [] s break; } - if !exists_in_scope(symbol.scope, scope) { + if !exists_in_scope(symbol.pkg, pkgs) { continue; } diff --git a/src/index/symbol.odin b/src/index/symbol.odin index 6630015..ab8f0da 100644 --- a/src/index/symbol.odin +++ b/src/index/symbol.odin @@ -17,12 +17,6 @@ import "shared:common" */ - -SymbolFile :: struct { - imports: [] string, -}; - - SymbolStructValue :: struct { names: [] string, types: [] ^ast.Expr, @@ -71,12 +65,12 @@ SymbolValue :: union { Symbol :: struct { range: common.Range, uri: string, - scope: string, + pkg: string, name: string, + doc: string, signature: string, type: SymbolType, value: SymbolValue, - file: ^SymbolFile, }; SymbolType :: enum { |