fix(frontend/lean/server): auto completion doesn't use prefix, fixes #147
This commit is contained in:
parent
b4793df653
commit
11addbb594
1 changed files with 20 additions and 10 deletions
|
@ -563,6 +563,20 @@ unsigned get_fuzzy_match_max_errors(unsigned prefix_sz) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional<name> exact_prefix_match(environment const & env, std::string const & pattern, declaration const & d) {
|
||||||
|
if (auto it = is_essentially_atomic(env, d.get_name())) {
|
||||||
|
std::string it_str = it->to_string();
|
||||||
|
// if pattern "perfectly" matches beginning of declaration name, we just display d on the top of the list
|
||||||
|
if (it_str.compare(0, pattern.size(), pattern) == 0)
|
||||||
|
return it;
|
||||||
|
} else {
|
||||||
|
std::string d_str = d.get_name().to_string();
|
||||||
|
if (d_str.compare(0, pattern.size(), pattern) == 0)
|
||||||
|
return optional<name>(d.get_name());
|
||||||
|
}
|
||||||
|
return optional<name>();
|
||||||
|
}
|
||||||
|
|
||||||
void server::find_pattern(unsigned line_num, std::string const & pattern) {
|
void server::find_pattern(unsigned line_num, std::string const & pattern) {
|
||||||
check_file();
|
check_file();
|
||||||
m_out << "-- BEGINFINDP";
|
m_out << "-- BEGINFINDP";
|
||||||
|
@ -589,17 +603,13 @@ void server::find_pattern(unsigned line_num, std::string const & pattern) {
|
||||||
std::vector<pair<std::string, name>> selected;
|
std::vector<pair<std::string, name>> selected;
|
||||||
bitap_fuzzy_search matcher(pattern, max_errors);
|
bitap_fuzzy_search matcher(pattern, max_errors);
|
||||||
env.for_each_declaration([&](declaration const & d) {
|
env.for_each_declaration([&](declaration const & d) {
|
||||||
std::string text = d.get_name().to_string();
|
if (auto it = exact_prefix_match(env, pattern, d)) {
|
||||||
if (auto it = is_essentially_atomic(env, d.get_name())) {
|
display_decl(*it, d.get_name(), env, opts);
|
||||||
std::string it_str = it->to_string();
|
} else {
|
||||||
// if pattern "perfectly" matches beginning of declaration name, we just display d on the top of the list
|
std::string text = d.get_name().to_string();
|
||||||
if (it_str.compare(0, pattern.size(), pattern) == 0) {
|
if (matcher.match(text))
|
||||||
display_decl(*it, d.get_name(), env, opts);
|
selected.emplace_back(text, d.get_name());
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (matcher.match(text))
|
|
||||||
selected.emplace_back(text, d.get_name());
|
|
||||||
});
|
});
|
||||||
unsigned sz = selected.size();
|
unsigned sz = selected.size();
|
||||||
if (sz == 1) {
|
if (sz == 1) {
|
||||||
|
|
Loading…
Reference in a new issue