Migrate most completion to ranked match
This commit is contained in:
parent
c0e4eca982
commit
87769c9b03
|
@ -176,7 +176,7 @@ CandidateList ClientManager::complete_client_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const
|
ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
auto c = transformed(m_clients, [](const std::unique_ptr<Client>& c){ return c->context().name(); });
|
auto c = transformed(m_clients, [](const std::unique_ptr<Client>& c){ return c->context().name(); });
|
||||||
return complete(prefix, cursor_pos, c, prefix_match, subsequence_match);
|
return complete(prefix, cursor_pos, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,18 +60,8 @@ const PerArgumentCommandCompleter filename_completer({
|
||||||
|
|
||||||
static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos)
|
static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
prefix = prefix.substr(0, cursor_pos);
|
auto c = transformed(BufferManager::instance(), [](const SafePtr<Buffer>& b){ return b->display_name(); });
|
||||||
Vector<RankedMatch> matches;
|
return complete(prefix, cursor_pos, c);
|
||||||
for (auto& buffer : BufferManager::instance())
|
|
||||||
{
|
|
||||||
if (RankedMatch match{buffer->display_name(), prefix})
|
|
||||||
matches.push_back(match);
|
|
||||||
}
|
|
||||||
std::sort(matches.begin(), matches.end());
|
|
||||||
CandidateList res;
|
|
||||||
for (auto& m : matches)
|
|
||||||
res.push_back(m.candidate().str());
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PerArgumentCommandCompleter buffer_completer({
|
const PerArgumentCommandCompleter buffer_completer({
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
#define completion_hh_INCLUDED
|
#define completion_hh_INCLUDED
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "units.hh"
|
#include "units.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "vector.hh"
|
#include "vector.hh"
|
||||||
|
#include "ranked_match.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -53,41 +55,22 @@ inline Completions offset_pos(Completions completion, ByteCount offset)
|
||||||
std::move(completion.candidates) };
|
std::move(completion.candidates) };
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename Container, typename Func>
|
|
||||||
void do_matches(Container&& container, StringView prefix,
|
|
||||||
CandidateList& res, Func match_func)
|
|
||||||
{
|
|
||||||
for (auto&& elem : container)
|
|
||||||
if (match_func(elem, prefix))
|
|
||||||
res.push_back(elem);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Container, typename Func, typename... Rest>
|
|
||||||
void do_matches(Container&& container, StringView prefix,
|
|
||||||
CandidateList& res, Func match_func, Rest... rest)
|
|
||||||
{
|
|
||||||
do_matches(container, prefix, res, match_func);
|
|
||||||
if (res.empty())
|
|
||||||
do_matches(container, prefix, res, rest...);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Container, typename... MatchFunc>
|
|
||||||
CandidateList complete(StringView prefix, ByteCount cursor_pos,
|
|
||||||
const Container& container, MatchFunc... match_func)
|
|
||||||
{
|
|
||||||
CandidateList res;
|
|
||||||
detail::do_matches(container, prefix.substr(0, cursor_pos), res, match_func...);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
CandidateList complete(StringView prefix, ByteCount cursor_pos,
|
CandidateList complete(StringView prefix, ByteCount cursor_pos,
|
||||||
const Container& container)
|
const Container& container)
|
||||||
{
|
{
|
||||||
return complete(prefix, cursor_pos, container, prefix_match);
|
prefix = prefix.substr(0, cursor_pos);
|
||||||
|
Vector<RankedMatch> matches;
|
||||||
|
for (const auto& str : container)
|
||||||
|
{
|
||||||
|
if (RankedMatch match{str, prefix})
|
||||||
|
matches.push_back(match);
|
||||||
|
}
|
||||||
|
std::sort(matches.begin(), matches.end());
|
||||||
|
CandidateList res;
|
||||||
|
for (auto& m : matches)
|
||||||
|
res.push_back(m.candidate().str());
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user