-
Notifications
You must be signed in to change notification settings - Fork 163
More options for completion filtering #786
base: master
Are you sure you want to change the base?
Changes from 2 commits
08c5e77
db1bf88
40a2f8a
4d53c1d
a4ef803
2ea4bdf
131013a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <string_view.h> | ||
|
||
class CompletionMatcher { | ||
public: | ||
// virtual ~CompletionMatcher() = default; // don't know why but it crashed if I uncomment this like, investigating | ||
virtual int Match(std::string_view text) = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some timing to see if the virtual function call is negatively impacting how long it takes to filter completion results? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check it a bit later, no problem. I'm sure that virtual function call will not spend much more time than plain function call, especially comparing to all that fuzzy-matching stuff = ) |
||
virtual int MinScore() const = 0; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,9 @@ struct Config { | |
// For example, to hide all files in a /CACHE/ folder, use ".*/CACHE/.*" | ||
std::vector<std::string> includeBlacklist; | ||
std::vector<std::string> includeWhitelist; | ||
|
||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure to document all possible options here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
std::string matcherType = "cqueryMatcher"; | ||
}; | ||
Completion completion; | ||
|
||
|
@@ -261,7 +264,8 @@ MAKE_REFLECT_STRUCT(Config::Completion, | |
includeMaxPathSize, | ||
includeSuffixWhitelist, | ||
includeBlacklist, | ||
includeWhitelist); | ||
includeWhitelist, | ||
matcherType); | ||
MAKE_REFLECT_STRUCT(Config::Formatting, enabled) | ||
MAKE_REFLECT_STRUCT(Config::Diagnostics, | ||
blacklist, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "fts_match.h" | ||
|
||
#define FTS_FUZZY_MATCH_IMPLEMENTATION 1 | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunused-function" | ||
#include <fts_fuzzy_match.h> | ||
#pragma clang diagnostic pop | ||
|
||
FtsMatcher::FtsMatcher(std::string_view pattern) { | ||
original_pattern = pattern; | ||
} | ||
|
||
int FtsMatcher::Match(std::string_view text) { | ||
int result = 0; | ||
if (fts::fuzzy_match(original_pattern.data(), text.data(), result)) { | ||
return result; | ||
} | ||
return MinScore(); | ||
} | ||
|
||
int FtsMatcher::MinScore() const { | ||
return -100000; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "completion_matcher.h" | ||
|
||
class FtsMatcher : public CompletionMatcher { | ||
public: | ||
FtsMatcher(std::string_view pattern); | ||
int Match(std::string_view text) override; | ||
int MinScore() const override; | ||
|
||
private: | ||
std::string_view original_pattern; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "prefix_match.h" | ||
|
||
#include <algorithm> | ||
#include <cctype> | ||
|
||
namespace { | ||
bool StartsWith(std::string_view text, std::string_view prefix) { | ||
return text.find(prefix) == 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There may be a function in utils.h to do this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. And also moved |
||
} | ||
|
||
bool StartsWithIgnoreCase(std::string_view text, std::string_view prefix) { | ||
auto min_length = std::min(text.size(), prefix.size()); | ||
if (min_length == 0) { | ||
return false; | ||
} | ||
return std::equal( | ||
text.begin(), text.begin() + min_length, | ||
prefix.begin(), prefix.begin() + min_length, | ||
[](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); } | ||
); | ||
} | ||
} | ||
|
||
PrefixMatcher::PrefixMatcher(std::string_view pattern, bool case_sensitive) { | ||
original_pattern = pattern; | ||
this->case_sensitive = case_sensitive; | ||
} | ||
|
||
int PrefixMatcher::Match(std::string_view text) { | ||
if (case_sensitive) { | ||
return ::StartsWith(text, original_pattern) ? 1 : MinScore(); | ||
} else { | ||
return ::StartsWithIgnoreCase(text, original_pattern) ? 1 : MinScore(); | ||
} | ||
} | ||
|
||
int PrefixMatcher::MinScore() const { | ||
return -1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include "completion_matcher.h" | ||
|
||
class PrefixMatcher : public CompletionMatcher { | ||
public: | ||
PrefixMatcher(std::string_view pattern, bool case_sensitive); | ||
int Match(std::string_view text) override; | ||
int MinScore() const override; | ||
|
||
private: | ||
std::string_view original_pattern; | ||
bool case_sensitive; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, but this should have a virtual dtor for correct behavior (also, the = default should probably go in a .cc file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
= default
part can behave differently if moved to the.cc
file.https://accu.org/index.php/journals/2379
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea whats happened but now it works fine. Probably some weird stuff on my side