2014-04-28 22:54:00 +02:00
|
|
|
#ifndef insert_completer_hh_INCLUDED
|
|
|
|
#define insert_completer_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "option_manager.hh"
|
2017-03-16 10:57:39 +01:00
|
|
|
#include "option.hh"
|
2015-10-05 02:48:00 +02:00
|
|
|
#include "display_buffer.hh"
|
2015-12-28 01:18:38 +01:00
|
|
|
#include "vector.hh"
|
2014-04-28 22:54:00 +02:00
|
|
|
|
2014-08-19 19:56:11 +02:00
|
|
|
#include "optional.hh"
|
|
|
|
|
2014-04-28 22:54:00 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2016-06-26 07:45:42 +02:00
|
|
|
struct SelectionList;
|
2015-12-28 01:18:38 +01:00
|
|
|
struct Key;
|
2018-04-07 07:36:39 +02:00
|
|
|
class FaceRegistry;
|
2015-12-28 01:18:38 +01:00
|
|
|
|
2014-08-19 19:56:11 +02:00
|
|
|
struct InsertCompleterDesc
|
|
|
|
{
|
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
Word,
|
|
|
|
Option,
|
2017-10-02 18:45:11 +02:00
|
|
|
Filename,
|
|
|
|
Line
|
2014-08-19 19:56:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const InsertCompleterDesc& other) const
|
2014-10-28 21:01:55 +01:00
|
|
|
{ return mode == other.mode and param == other.param; }
|
2014-08-19 19:56:11 +02:00
|
|
|
|
|
|
|
bool operator!=(const InsertCompleterDesc& other) const
|
2015-12-28 00:28:34 +01:00
|
|
|
{ return not (*this == other); }
|
2014-08-19 19:56:11 +02:00
|
|
|
|
|
|
|
Mode mode;
|
|
|
|
Optional<String> param;
|
|
|
|
};
|
|
|
|
|
2015-01-12 14:24:30 +01:00
|
|
|
using InsertCompleterDescList = Vector<InsertCompleterDesc, MemoryDomain::Options>;
|
2014-08-19 19:56:11 +02:00
|
|
|
|
|
|
|
String option_to_string(const InsertCompleterDesc& opt);
|
2018-05-27 05:00:04 +02:00
|
|
|
InsertCompleterDesc option_from_string(Meta::Type<InsertCompleterDesc>, StringView str);
|
2014-08-19 19:56:11 +02:00
|
|
|
|
2017-03-15 18:42:02 +01:00
|
|
|
inline StringView option_type_name(Meta::Type<InsertCompleterDesc>)
|
2016-08-06 10:05:50 +02:00
|
|
|
{
|
2017-03-15 18:42:02 +01:00
|
|
|
return "completer";
|
|
|
|
}
|
2016-08-06 10:05:50 +02:00
|
|
|
|
2016-04-01 02:27:23 +02:00
|
|
|
using CompletionCandidate = std::tuple<String, String, String>;
|
|
|
|
using CompletionList = PrefixedList<String, CompletionCandidate>;
|
|
|
|
|
2017-03-15 18:42:02 +01:00
|
|
|
inline StringView option_type_name(Meta::Type<CompletionList>)
|
2016-08-06 10:05:50 +02:00
|
|
|
{
|
2017-03-15 18:42:02 +01:00
|
|
|
return "completions";
|
|
|
|
}
|
2016-08-06 10:05:50 +02:00
|
|
|
|
2014-04-28 22:54:00 +02:00
|
|
|
struct InsertCompletion
|
|
|
|
{
|
2015-08-30 12:05:48 +02:00
|
|
|
struct Candidate
|
|
|
|
{
|
|
|
|
String completion;
|
|
|
|
String docstring;
|
2015-10-05 02:48:00 +02:00
|
|
|
DisplayLine menu_entry;
|
2015-08-30 12:05:48 +02:00
|
|
|
|
|
|
|
bool operator==(const Candidate& other) const { return completion == other.completion; }
|
|
|
|
bool operator<(const Candidate& other) const { return completion < other.completion; }
|
|
|
|
};
|
2016-11-28 14:59:55 +01:00
|
|
|
using CandidateList = Vector<Candidate, MemoryDomain::Completion>;
|
2015-08-30 12:05:48 +02:00
|
|
|
|
2017-02-27 21:29:53 +01:00
|
|
|
CandidateList candidates;
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoord begin;
|
|
|
|
BufferCoord end;
|
2017-09-01 12:03:34 +02:00
|
|
|
size_t timestamp = 0;
|
2017-02-27 21:29:53 +01:00
|
|
|
|
2014-04-28 22:54:00 +02:00
|
|
|
bool is_valid() const { return not candidates.empty(); }
|
|
|
|
};
|
|
|
|
|
2014-11-02 17:04:24 +01:00
|
|
|
class InsertCompleter : public OptionManagerWatcher
|
2014-04-28 22:54:00 +02:00
|
|
|
{
|
|
|
|
public:
|
2016-09-21 14:38:34 +02:00
|
|
|
InsertCompleter(Context& context);
|
2014-04-28 22:54:00 +02:00
|
|
|
InsertCompleter(const InsertCompleter&) = delete;
|
|
|
|
InsertCompleter& operator=(const InsertCompleter&) = delete;
|
2017-05-22 11:31:56 +02:00
|
|
|
~InsertCompleter();
|
2014-04-28 22:54:00 +02:00
|
|
|
|
2018-05-03 14:22:12 +02:00
|
|
|
void select(int index, bool relative, Vector<Key>& keystrokes);
|
2018-07-15 03:46:02 +02:00
|
|
|
void update(bool allow_implicit);
|
2014-04-28 22:54:00 +02:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
void explicit_file_complete();
|
2017-10-24 22:41:13 +02:00
|
|
|
void explicit_word_buffer_complete();
|
|
|
|
void explicit_word_all_complete();
|
2017-10-26 13:04:28 +02:00
|
|
|
void explicit_line_buffer_complete();
|
|
|
|
void explicit_line_all_complete();
|
2014-04-28 22:54:00 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool setup_ifn();
|
|
|
|
|
2015-12-27 09:49:15 +01:00
|
|
|
template<typename Func>
|
|
|
|
bool try_complete(Func complete_func);
|
2014-04-28 22:54:00 +02:00
|
|
|
void on_option_changed(const Option& opt) override;
|
|
|
|
|
|
|
|
void menu_show();
|
|
|
|
|
2018-04-07 07:36:39 +02:00
|
|
|
Context& m_context;
|
|
|
|
OptionManager& m_options;
|
|
|
|
const FaceRegistry& m_faces;
|
|
|
|
InsertCompletion m_completions;
|
|
|
|
int m_current_candidate = -1;
|
2015-10-19 14:43:23 +02:00
|
|
|
|
2018-04-07 07:36:39 +02:00
|
|
|
using CompleteFunc = InsertCompletion (const SelectionList& sels,
|
|
|
|
const OptionManager& options,
|
|
|
|
const FaceRegistry& faces);
|
2015-12-28 01:18:38 +01:00
|
|
|
CompleteFunc* m_explicit_completer = nullptr;
|
2014-04-28 22:54:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // insert_completer_hh_INCLUDED
|