feat(frontends/lean/server): sort exact matches by size in FINDP
This commit is contained in:
parent
334977b8bd
commit
113879a7dd
4 changed files with 31 additions and 1 deletions
|
@ -648,17 +648,27 @@ void server::find_pattern(unsigned line_num, std::string const & pattern) {
|
|||
opts = join(opts, m_ios.get_options());
|
||||
m_out << std::endl;
|
||||
unsigned max_errors = get_fuzzy_match_max_errors(pattern.size());
|
||||
std::vector<pair<name, name>> exact_matches;
|
||||
std::vector<pair<std::string, name>> selected;
|
||||
bitap_fuzzy_search matcher(pattern, max_errors);
|
||||
env.for_each_declaration([&](declaration const & d) {
|
||||
if (auto it = exact_prefix_match(env, pattern, d)) {
|
||||
display_decl(*it, d.get_name(), env, opts);
|
||||
exact_matches.emplace_back(*it, d.get_name());
|
||||
} else {
|
||||
std::string text = d.get_name().to_string();
|
||||
if (matcher.match(text))
|
||||
selected.emplace_back(text, d.get_name());
|
||||
}
|
||||
});
|
||||
if (!exact_matches.empty()) {
|
||||
std::sort(exact_matches.begin(), exact_matches.end(),
|
||||
[](pair<name, name> const & p1, pair<name, name> const & p2) {
|
||||
return p1.first.size() < p2.first.size();
|
||||
});
|
||||
for (pair<name, name> const & p : exact_matches) {
|
||||
display_decl(p.first, p.second, env, opts);
|
||||
}
|
||||
}
|
||||
unsigned sz = selected.size();
|
||||
if (sz == 1) {
|
||||
display_decl(selected[0].second, env, opts);
|
||||
|
|
4
tests/lean/interactive/findp.input
Normal file
4
tests/lean/interactive/findp.input
Normal file
|
@ -0,0 +1,4 @@
|
|||
VISIT findp.lean
|
||||
WAIT
|
||||
FINDP 7
|
||||
false
|
11
tests/lean/interactive/findp.input.expected.out
Normal file
11
tests/lean/interactive/findp.input.expected.out
Normal file
|
@ -0,0 +1,11 @@
|
|||
-- BEGINWAIT
|
||||
-- ENDWAIT
|
||||
-- BEGINFINDP STALE
|
||||
false|Prop
|
||||
false.rec|∀ (C : Prop), false → C
|
||||
false_elim|false → ?c
|
||||
not_false_trivial|not false
|
||||
true_ne_false|not (eq true false)
|
||||
p_ne_false|?p → ne ?p false
|
||||
eq_false_elim|eq ?a false → not ?a
|
||||
-- ENDFINDP
|
5
tests/lean/interactive/findp.lean
Normal file
5
tests/lean/interactive/findp.lean
Normal file
|
@ -0,0 +1,5 @@
|
|||
import logic.core.eq algebra.relation
|
||||
|
||||
check proof_irrel
|
||||
|
||||
check false
|
Loading…
Reference in a new issue