Browse Source

Optimised autocomplete by only receive brief comments when needed

merge-requests/365/head
eidheim 8 years ago
parent
commit
45f0603439
  1. 6
      src/autocomplete.cc
  2. 4
      src/autocomplete.h
  3. 12
      src/source_clang.cc

6
src/autocomplete.cc

@ -101,8 +101,8 @@ void Autocomplete::run() {
CompletionDialog::create(view, view->get_buffer()->create_mark(start_iter)); CompletionDialog::create(view, view->get_buffer()->create_mark(start_iter));
setup_dialog(); setup_dialog();
for(auto &row : rows) { for(auto &row : rows) {
CompletionDialog::get()->add_row(row.first); CompletionDialog::get()->add_row(row);
row.first.clear(); row.clear();
} }
state = State::IDLE; state = State::IDLE;
@ -150,7 +150,7 @@ void Autocomplete::setup_dialog() {
on_changed(index, text); on_changed(index, text);
auto tooltip = rows[index].second; auto tooltip = get_tooltip(index);
if(tooltip.empty()) if(tooltip.empty())
tooltips.hide(); tooltips.hide();
else { else {

4
src/autocomplete.h

@ -18,7 +18,7 @@ public:
std::string prefix; std::string prefix;
std::mutex prefix_mutex; std::mutex prefix_mutex;
std::vector<std::pair<std::string, std::string>> rows; std::vector<std::string> rows;
Tooltips tooltips; Tooltips tooltips;
std::atomic<State> state; std::atomic<State> state;
@ -47,6 +47,8 @@ public:
std::function<void(unsigned int, const std::string &)> on_changed = [](unsigned int index, const std::string &text) {}; std::function<void(unsigned int, const std::string &)> on_changed = [](unsigned int index, const std::string &text) {};
std::function<void(unsigned int, const std::string &, bool)> on_select = [](unsigned int index, const std::string &text, bool hide_window) {}; std::function<void(unsigned int, const std::string &, bool)> on_select = [](unsigned int index, const std::string &text, bool hide_window) {};
std::function<std::string(unsigned int)> get_tooltip = [](unsigned int index) {return std::string();};
Autocomplete(Gtk::TextView *view, bool &interactive_completion, guint &last_keyval, bool strip_word); Autocomplete(Gtk::TextView *view, bool &interactive_completion, guint &last_keyval, bool strip_word);
void run(); void run();

12
src/source_clang.cc

@ -636,14 +636,14 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
Recursive::f(result, text); Recursive::f(result, text);
if(!text.empty()) { if(!text.empty()) {
bool already_added=false; bool already_added=false;
for(auto &pair: autocomplete.rows) { for(auto &row: autocomplete.rows) {
if(pair.first==text) { if(row==text) {
already_added=true; already_added=true;
break; break;
} }
} }
if(!already_added) { if(!already_added) {
autocomplete.rows.emplace_back(std::move(text), result.get_brief_comment()); autocomplete.rows.emplace_back(std::move(text));
completion_strings.emplace_back(result.cx_completion_string); completion_strings.emplace_back(result.cx_completion_string);
} }
} }
@ -670,7 +670,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
if(match && !text.empty()) { if(match && !text.empty()) {
if(!return_text.empty()) if(!return_text.empty())
text+=return_text; text+=return_text;
autocomplete.rows.emplace_back(std::move(text), result.get_brief_comment()); autocomplete.rows.emplace_back(std::move(text));
completion_strings.emplace_back(result.cx_completion_string); completion_strings.emplace_back(result.cx_completion_string);
} }
} }
@ -779,6 +779,10 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
} }
} }
}; };
autocomplete.get_tooltip = [this](unsigned int index) {
return clangmm::to_string(clang_getCompletionBriefComment(completion_strings[index]));
};
} }
bool Source::ClangViewAutocomplete::is_possible_parameter() { bool Source::ClangViewAutocomplete::is_possible_parameter() {

Loading…
Cancel
Save