aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2020-12-09 17:36:44 +0100
committerDanielGavin <danielgavin5@hotmail.com>2020-12-09 17:36:44 +0100
commit07c7e937aaa2fe1c4c7813f4f7257ccafd45fabd (patch)
tree39f19e6dfb4740dad4b79f409026e24cda2e14cb /src/common
parent705f77aae24e383e6adc3cb92a48b60d22699e82 (diff)
combine results from local and indexer on non selection completion + fuzzer acronym
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fuzzy.odin47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/common/fuzzy.odin b/src/common/fuzzy.odin
index 1cc1ed4..c582421 100644
--- a/src/common/fuzzy.odin
+++ b/src/common/fuzzy.odin
@@ -3,6 +3,10 @@ package common
import "core:strings"
import "core:fmt"
+/*
+ Ported from https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/FuzzyMatch.cpp
+*/
+
max_pattern :: 63;
max_word :: 127;
@@ -121,6 +125,39 @@ make_fuzzy_matcher :: proc (pattern: string, allocator := context.temp_allocator
return matcher;
}
+fuzzy_to_acronym :: proc(word: string) -> (string, bool) {
+
+ builder := strings.make_builder(context.temp_allocator);
+
+ if len(word) <= 1 {
+ return "", false;
+ }
+
+ i := 1;
+ last_char := word[0];
+
+ strings.write_byte(&builder, last_char);
+
+ for i < len(word) {
+
+ if last_char == '_' {
+ strings.write_byte(&builder, word[i]);
+ }
+
+ last_char = word[i];
+
+ i += 1;
+ }
+
+ str := strings.to_string(builder);
+
+ if len(str) <= 1 {
+ return "", false;
+ }
+
+ return str, true;
+}
+
fuzzy_match :: proc (matcher: ^FuzzyMatcher, word: string) -> (f32, bool) {
if !fuzzy_init(matcher, word) {
@@ -128,19 +165,21 @@ fuzzy_match :: proc (matcher: ^FuzzyMatcher, word: string) -> (f32, bool) {
}
if matcher.pattern_count <= 0 {
- //fmt.println("return");
return 1, true;
}
+ if acronym, ok := fuzzy_to_acronym(word); ok {
+ if acronym == matcher.pattern {
+ return 20, true;
+ }
+ }
+
fuzzy_build_graph(matcher);
best := max(cast(int)matcher.scores[matcher.pattern_count][matcher.word_count][miss].score,
cast(int)matcher.scores[matcher.pattern_count][matcher.word_count][match].score);
- //fmt.println("best ", best);
-
if fuzzy_is_awful(best) {
- //fmt.println("awful");
return 0.0, false;
}