summaryrefslogtreecommitdiff
path: root/src/insert_completer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-10-29 13:57:50 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-10-29 13:57:50 +0000
commit32b51e2cc3931c32ffb575f57803b53da75a07e6 (patch)
treeeb27de5e750edd50c2b15c25fb844f2048e6d70e /src/insert_completer.cc
parent8030897708818698dc925574a5b32183d53ffbcf (diff)
Use ranked matches for option completion as well
Diffstat (limited to 'src/insert_completer.cc')
-rw-r--r--src/insert_completer.cc35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index 02b88856..08ff5071 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -233,29 +233,46 @@ InsertCompletion complete_option(const Buffer& buffer, ByteCoord cursor_pos,
if (cursor_pos.line == coord.line and cursor_pos.column >= coord.column)
{
- StringView prefix = buffer[coord.line].substr(
+ StringView query = buffer[coord.line].substr(
coord.column, cursor_pos.column - coord.column);
-
const CharCount tabstop = options["tabstop"].get<int>();
const CharCount column = get_column(buffer, tabstop, cursor_pos);
- InsertCompletion::CandidateList candidates;
+ struct RankedMatchAndInfo : RankedMatch
+ {
+ using RankedMatch::RankedMatch;
+ using RankedMatch::operator==;
+ using RankedMatch::operator<;
+
+ StringView docstring;
+ DisplayLine menu_entry;
+ };
+
+ Vector<RankedMatchAndInfo> matches;
+
for (auto it = opt.begin() + 1; it != opt.end(); ++it)
{
auto splitted = split(*it, '@');
- if (not splitted.empty() and prefix_match(splitted[0], prefix))
+ if (splitted.empty())
+ continue;
+ if (RankedMatchAndInfo match{splitted[0], query})
{
- StringView completion = splitted[0];
- StringView docstring = splitted.size() > 1 ? splitted[1] : StringView{};
-
- DisplayLine menu_entry = splitted.size() > 2 ?
+ match.docstring = splitted.size() > 1 ? splitted[1] : StringView{};
+ match.menu_entry = splitted.size() > 2 ?
parse_display_line(expand_tabs(splitted[2], tabstop, column))
: DisplayLine{ expand_tabs(splitted[0], tabstop, column) };
- candidates.push_back({completion.str(), docstring.str(), std::move(menu_entry)});
+ matches.push_back(std::move(match));
}
}
+ std::sort(matches.begin(), matches.end());
+ InsertCompletion::CandidateList candidates;
+ candidates.reserve(matches.size());
+ for (auto& match : matches)
+ candidates.push_back({ match.candidate().str(), match.docstring.str(),
+ std::move(match.menu_entry) });
+
return { coord, end, std::move(candidates), timestamp };
}
}