mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 20:41:49 +03:00
Use StringView for completion functions
This commit is contained in:
parent
af2d82dfc1
commit
adde2fef75
@ -95,10 +95,10 @@ void BufferManager::set_last_used_buffer(Buffer& buffer)
|
|||||||
m_buffers.emplace(m_buffers.begin(), &buffer);
|
m_buffers.emplace(m_buffers.begin(), &buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList BufferManager::complete_buffer_name(const String& prefix,
|
CandidateList BufferManager::complete_buffer_name(StringView prefix,
|
||||||
ByteCount cursor_pos)
|
ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
String real_prefix = prefix.substr(0, cursor_pos);
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
||||||
const bool include_dirs = contains(real_prefix, '/');
|
const bool include_dirs = contains(real_prefix, '/');
|
||||||
CandidateList result;
|
CandidateList result;
|
||||||
CandidateList subsequence_result;
|
CandidateList subsequence_result;
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
Buffer& get_buffer(const String& name);
|
Buffer& get_buffer(const String& name);
|
||||||
void set_last_used_buffer(Buffer& buffer);
|
void set_last_used_buffer(Buffer& buffer);
|
||||||
|
|
||||||
CandidateList complete_buffer_name(const String& prefix,
|
CandidateList complete_buffer_name(StringView prefix,
|
||||||
ByteCount cursor_pos = -1);
|
ByteCount cursor_pos = -1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -170,10 +170,10 @@ void ClientManager::redraw_clients() const
|
|||||||
client->redraw_ifn();
|
client->redraw_ifn();
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList ClientManager::complete_client_name(const String& prefix,
|
CandidateList ClientManager::complete_client_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const
|
ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
String real_prefix = prefix.substr(0, cursor_pos);
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
||||||
CandidateList result;
|
CandidateList result;
|
||||||
CandidateList subsequence_result;
|
CandidateList subsequence_result;
|
||||||
for (auto& client : m_clients)
|
for (auto& client : m_clients)
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
bool validate_client_name(const String& name) const;
|
bool validate_client_name(const String& name) const;
|
||||||
void remove_client(Client& client);
|
void remove_client(Client& client);
|
||||||
|
|
||||||
CandidateList complete_client_name(const String& name,
|
CandidateList complete_client_name(StringView name,
|
||||||
ByteCount cursor_pos = -1) const;
|
ByteCount cursor_pos = -1) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -36,11 +36,11 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
|||||||
it->second : parse_color_pair(colordesc);
|
it->second : parse_color_pair(colordesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList ColorRegistry::complete_alias_name(const String& prefix,
|
CandidateList ColorRegistry::complete_alias_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const
|
ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
CandidateList res;
|
CandidateList res;
|
||||||
String real_prefix = prefix.substr(0, cursor_pos);
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
||||||
for (auto& alias : m_aliases)
|
for (auto& alias : m_aliases)
|
||||||
{
|
{
|
||||||
if (prefix_match(alias.first, real_prefix))
|
if (prefix_match(alias.first, real_prefix))
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
void register_alias(const String& name, const String& colordesc,
|
void register_alias(const String& name, const String& colordesc,
|
||||||
bool override = false);
|
bool override = false);
|
||||||
|
|
||||||
CandidateList complete_alias_name(const String& prefix,
|
CandidateList complete_alias_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const;
|
ByteCount cursor_pos) const;
|
||||||
private:
|
private:
|
||||||
std::unordered_map<String, ColorPair> m_aliases;
|
std::unordered_map<String, ColorPair> m_aliases;
|
||||||
|
@ -495,7 +495,7 @@ HookManager& get_hook_manager(const String& scope, Context& context)
|
|||||||
throw runtime_error("error: no such hook container " + scope);
|
throw runtime_error("error: no such hook container " + scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList complete_scope(const String& prefix)
|
CandidateList complete_scope(StringView prefix)
|
||||||
{
|
{
|
||||||
CandidateList res;
|
CandidateList res;
|
||||||
for (auto scope : { "global", "buffer", "window" })
|
for (auto scope : { "global", "buffer", "window" })
|
||||||
|
@ -6,7 +6,7 @@ namespace Kakoune
|
|||||||
{
|
{
|
||||||
|
|
||||||
Completions shell_complete(const Context& context, CompletionFlags flags,
|
Completions shell_complete(const Context& context, CompletionFlags flags,
|
||||||
const String& prefix, ByteCount cursor_pos)
|
StringView prefix, ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
ByteCount word_start = 0;
|
ByteCount word_start = 0;
|
||||||
ByteCount word_end = 0;
|
ByteCount word_end = 0;
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "units.hh"
|
#include "units.hh"
|
||||||
|
#include "string.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
|
|
||||||
class String;
|
|
||||||
using CandidateList = std::vector<String>;
|
using CandidateList = std::vector<String>;
|
||||||
|
|
||||||
struct Completions
|
struct Completions
|
||||||
@ -36,16 +36,16 @@ enum class CompletionFlags
|
|||||||
Fast
|
Fast
|
||||||
};
|
};
|
||||||
using Completer = std::function<Completions (const Context&, CompletionFlags,
|
using Completer = std::function<Completions (const Context&, CompletionFlags,
|
||||||
const String&, ByteCount)>;
|
StringView, ByteCount)>;
|
||||||
|
|
||||||
inline Completions complete_nothing(const Context& context, CompletionFlags,
|
inline Completions complete_nothing(const Context& context, CompletionFlags,
|
||||||
const String&, ByteCount cursor_pos)
|
StringView, ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
return Completions(cursor_pos, cursor_pos);
|
return Completions(cursor_pos, cursor_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
Completions shell_complete(const Context& context, CompletionFlags,
|
Completions shell_complete(const Context& context, CompletionFlags,
|
||||||
const String&, ByteCount cursor_pos);
|
StringView, ByteCount cursor_pos);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // completion_hh_INCLUDED
|
#endif // completion_hh_INCLUDED
|
||||||
|
@ -311,7 +311,7 @@ std::vector<String> list_files(const String& prefix,
|
|||||||
return result.empty() ? subseq_result : result;
|
return result.empty() ? subseq_result : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> complete_filename(const String& prefix,
|
std::vector<String> complete_filename(StringView prefix,
|
||||||
const Regex& ignored_regex,
|
const Regex& ignored_regex,
|
||||||
ByteCount cursor_pos)
|
ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
@ -346,7 +346,7 @@ std::vector<String> complete_filename(const String& prefix,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> complete_command(const String& prefix, ByteCount cursor_pos)
|
std::vector<String> complete_command(StringView prefix, ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
String real_prefix = parse_filename(prefix.substr(0, cursor_pos));
|
String real_prefix = parse_filename(prefix.substr(0, cursor_pos));
|
||||||
String dirname;
|
String dirname;
|
||||||
|
@ -35,11 +35,11 @@ String find_file(const String& filename, memoryview<String> paths);
|
|||||||
|
|
||||||
time_t get_fs_timestamp(const String& filename);
|
time_t get_fs_timestamp(const String& filename);
|
||||||
|
|
||||||
std::vector<String> complete_filename(const String& prefix,
|
std::vector<String> complete_filename(StringView prefix,
|
||||||
const Regex& ignore_regex,
|
const Regex& ignore_regex,
|
||||||
ByteCount cursor_pos = -1);
|
ByteCount cursor_pos = -1);
|
||||||
|
|
||||||
std::vector<String> complete_command(const String& prefix,
|
std::vector<String> complete_command(StringView prefix,
|
||||||
ByteCount cursor_pos = -1);
|
ByteCount cursor_pos = -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +54,12 @@ public:
|
|||||||
return *group;
|
return *group;
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList complete_id(const String& prefix, ByteCount cursor_pos) const
|
CandidateList complete_id(StringView prefix, ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
return m_functions.complete_id(prefix, cursor_pos);
|
return m_functions.complete_id(prefix, cursor_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList complete_group_id(const String& prefix, ByteCount cursor_pos) const
|
CandidateList complete_group_id(StringView prefix, ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
return m_functions.complete_id_if(
|
return m_functions.complete_id_if(
|
||||||
prefix, cursor_pos, [](const FunctionAndId& func) {
|
prefix, cursor_pos, [](const FunctionAndId& func) {
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList complete_name(const String& prefix, ByteCount cursor_pos)
|
CandidateList complete_name(StringView prefix, ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
return m_functions.complete_id(prefix, cursor_pos);
|
return m_functions.complete_id(prefix, cursor_pos);
|
||||||
}
|
}
|
||||||
|
@ -67,11 +67,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Condition>
|
template<typename Condition>
|
||||||
CandidateList complete_id_if(const String& prefix,
|
CandidateList complete_id_if(StringView prefix,
|
||||||
ByteCount cursor_pos,
|
ByteCount cursor_pos,
|
||||||
Condition condition) const
|
Condition condition) const
|
||||||
{
|
{
|
||||||
String real_prefix = prefix.substr(0, cursor_pos);
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
||||||
CandidateList result;
|
CandidateList result;
|
||||||
for (auto& value : m_content)
|
for (auto& value : m_content)
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList complete_id(const String& prefix,
|
CandidateList complete_id(StringView prefix,
|
||||||
ByteCount cursor_pos) const
|
ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
return complete_id_if(
|
return complete_id_if(
|
||||||
|
@ -85,14 +85,14 @@ CandidateList OptionManager::get_matching_names(MatchingFunc func)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList OptionManager::complete_option_name(const String& prefix,
|
CandidateList OptionManager::complete_option_name(StringView prefix,
|
||||||
ByteCount cursor_pos)
|
ByteCount cursor_pos)
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
String real_prefix = prefix.substr(0, cursor_pos);
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
||||||
auto result = get_matching_names(std::bind(prefix_match, _1, std::ref(real_prefix)));
|
auto result = get_matching_names(std::bind(prefix_match, _1, real_prefix));
|
||||||
if (result.empty())
|
if (result.empty())
|
||||||
result = get_matching_names(std::bind(subsequence_match, _1, std::ref(real_prefix)));
|
result = get_matching_names(std::bind(subsequence_match, _1, real_prefix));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public:
|
|||||||
const Option& operator[] (const String& name) const;
|
const Option& operator[] (const String& name) const;
|
||||||
Option& get_local_option(const String& name);
|
Option& get_local_option(const String& name);
|
||||||
|
|
||||||
CandidateList complete_option_name(const String& prefix,
|
CandidateList complete_option_name(StringView prefix,
|
||||||
ByteCount cursor_pos);
|
ByteCount cursor_pos);
|
||||||
|
|
||||||
using OptionList = std::vector<const Option*>;
|
using OptionList = std::vector<const Option*>;
|
||||||
|
Loading…
Reference in New Issue
Block a user