aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/index/build.odin2
-rw-r--r--src/index/memory_index.odin10
-rw-r--r--src/index/symbol.odin70
-rw-r--r--src/server/analysis.odin10
-rw-r--r--src/server/documents.odin2
-rw-r--r--src/server/unmarshal.odin4
6 files changed, 71 insertions, 27 deletions
diff --git a/src/index/build.odin b/src/index/build.odin
index 3d96405..acab4a5 100644
--- a/src/index/build.odin
+++ b/src/index/build.odin
@@ -34,8 +34,6 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi
return 0, false;
}
- //fmt.println(info.fullpath);
-
//bit worried about using temp allocator here since we might overwrite all our temp allocator budget
data, ok := os.read_entire_file(info.fullpath, context.allocator);
diff --git a/src/index/memory_index.odin b/src/index/memory_index.odin
index 4a9ade1..e2dd3d3 100644
--- a/src/index/memory_index.odin
+++ b/src/index/memory_index.odin
@@ -38,16 +38,24 @@ memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, scope: [] s
fuzzy_matcher := common.make_fuzzy_matcher(name);
+ top := 20;
+ i := 0;
+
for _, symbol in index.collection.symbols {
+ if i >= top {
+ break;
+ }
+
if !exists_in_scope(symbol.scope, scope) {
continue;
}
- if common.fuzzy_match(fuzzy_matcher, symbol.name) > 0.5 {
+ if name == "" || common.fuzzy_match(fuzzy_matcher, symbol.name) > 0.5 {
append(&symbols, symbol);
}
+ i += 1;
}
return symbols[:], true;
diff --git a/src/index/symbol.odin b/src/index/symbol.odin
index ecec5f8..25d0474 100644
--- a/src/index/symbol.odin
+++ b/src/index/symbol.odin
@@ -14,6 +14,34 @@ Symbol :: struct {
uri: string,
scope: string,
name: string,
+ type: SymbolType,
+};
+
+SymbolType :: enum {
+ Text = 1,
+ Method = 2,
+ Function = 3,
+ Constructor = 4,
+ Field = 5,
+ Variable = 6,
+ Interface = 8,
+ Module = 9,
+ Property = 10,
+ Unit = 11,
+ Value = 12,
+ Enum = 13,
+ Keyword = 14,
+ Snippet = 15,
+ Color = 16,
+ File = 17,
+ Reference = 18,
+ Folder = 19,
+ EnumMember = 20,
+ Constant = 21,
+ Struct = 22,
+ Event = 23,
+ Operator = 24,
+ TypeParameter = 25,
};
SymbolCollection :: struct {
@@ -34,34 +62,44 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
for decl in file.decls {
+ symbol: Symbol;
+
if value_decl, ok := decl.derived.(ast.Value_Decl); ok {
name := string(file.src[value_decl.names[0].pos.offset:value_decl.names[0].end.offset]);
if len(value_decl.values) == 1 {
- if proc_lit, ok := value_decl.values[0].derived.(ast.Proc_Lit); ok {
-
- symbol: Symbol;
-
- symbol.range = common.get_token_range(proc_lit, file.src);
- symbol.name = strings.clone(name);
- symbol.scope = strings.clone(file.pkg_name); //have this use unique strings to save space
-
- uri_id := hash.murmur64(transmute([]u8)uri);
+ token: ast.Node;
+ token_type: SymbolType;
+
+ switch v in value_decl.values[0].derived {
+ case ast.Proc_Lit:
+ token = v;
+ token_type = .Function;
+ case ast.Struct_Type:
+ token = v;
+ token_type = .Struct;
+ case: // default
+ break;
+ }
- if _, ok := collection.unique_strings[uri_id]; !ok {
- collection.unique_strings[uri_id] = strings.clone(uri);
- }
+ symbol.range = common.get_token_range(token, file.src);
+ symbol.name = strings.clone(name);
+ symbol.scope = strings.clone(file.pkg_name); //have this use unique strings to save space
+ symbol.type = token_type;
- symbol.uri = collection.unique_strings[uri_id];
+ uri_id := hash.murmur64(transmute([]u8)uri);
- id := hash.murmur64(transmute([]u8)strings.concatenate({file.pkg_name, name}, context.temp_allocator));
+ if _, ok := collection.unique_strings[uri_id]; !ok {
+ collection.unique_strings[uri_id] = strings.clone(uri);
+ }
- collection.symbols[id] = symbol;
+ symbol.uri = collection.unique_strings[uri_id];
- }
+ id := hash.murmur64(transmute([]u8)strings.concatenate({file.pkg_name, name}, context.temp_allocator));
+ collection.symbols[id] = symbol;
}
}
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 8027e6d..7c1977c 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -183,19 +183,13 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> (
position_context, ok := get_document_position_context(document, position);
symbols: [] index.Symbol;
- empty_dot := false;
#partial switch v in position_context.value {
case DocumentPositionContextVariableDotVariableValue:
symbols, ok = index.fuzzy_search(v.postfix, {v.prefix});
case DocumentPositionContextVariableDotValue:
- empty_dot = true;
- }
-
- if empty_dot {
- list.isIncomplete = true;
- return list, true;
+ symbols, ok = index.fuzzy_search("", {v.prefix});
}
if !ok {
@@ -206,7 +200,7 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> (
for symbol, i in symbols {
list.items[i].label = symbol.name;
- list.items[i].kind = .Function;
+ list.items[i].kind = cast(CompletionItemKind) symbol.type;
}
return list, true;
diff --git a/src/server/documents.odin b/src/server/documents.odin
index 59eeadd..7765190 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -232,6 +232,8 @@ document_close :: proc(uri_string: string) -> common.Error {
document.client_owned = false;
+ delete(document.text);
+
return .None;
}
diff --git a/src/server/unmarshal.odin b/src/server/unmarshal.odin
index e5ca619..c658848 100644
--- a/src/server/unmarshal.odin
+++ b/src/server/unmarshal.odin
@@ -16,6 +16,10 @@ unmarshal :: proc(json_value: json.Value, v: any, allocator := context.allocator
return .None;
}
+ if json_value.value == nil {
+ return .None;
+ }
+
type_info := type_info_base(type_info_of(v.id));
#partial