Browse Source

Language protocol: no longer show tooltips when no completion is selected

merge-requests/413/head
eidheim 4 years ago
parent
commit
228056820e
  1. 2
      src/autocomplete.cpp
  2. 1
      src/autocomplete.hpp
  3. 25
      src/source_language_protocol.cpp
  4. 3
      src/source_language_protocol.hpp

2
src/autocomplete.cpp

@ -169,7 +169,7 @@ void Autocomplete::setup_dialog() {
on_change(index, text); on_change(index, text);
if(!index) { if(!index) {
tooltips.hide(); clear_tooltips();
return; return;
} }

1
src/autocomplete.hpp

@ -56,6 +56,7 @@ public:
std::function<void(unsigned int, const std::string &, bool)> on_select; std::function<void(unsigned int, const std::string &, bool)> on_select;
std::function<std::function<void(Tooltip &tooltip)>(unsigned int)> set_tooltip_buffer = [](unsigned int index) { return nullptr; }; std::function<std::function<void(Tooltip &tooltip)>(unsigned int)> set_tooltip_buffer = [](unsigned int index) { return nullptr; };
std::function<void()> clear_tooltips = [this] { tooltips.hide(); };
Autocomplete(Source::BaseView *view, bool &interactive_completion, guint &last_keyval, bool pass_buffer_and_strip_word, bool use_thread); Autocomplete(Source::BaseView *view, bool &interactive_completion, guint &last_keyval, bool pass_buffer_and_strip_word, bool use_thread);

25
src/source_language_protocol.cpp

@ -715,6 +715,7 @@ void Source::LanguageProtocolView::initialize() {
Source::LanguageProtocolView::~LanguageProtocolView() { Source::LanguageProtocolView::~LanguageProtocolView() {
autocomplete_delayed_show_arguments_connection.disconnect(); autocomplete_delayed_show_arguments_connection.disconnect();
resolve_completion_item_connection.disconnect();
update_type_coverage_connection.disconnect(); update_type_coverage_connection.disconnect();
if(initialize_thread.joinable()) if(initialize_thread.joinable())
@ -1504,7 +1505,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
// Activate argument completions // Activate argument completions
get_buffer()->signal_changed().connect( get_buffer()->signal_changed().connect(
[this] { [this] {
autocompete_possibly_no_arguments = false; autocomplete_possibly_no_arguments = false;
if(!interactive_completion) if(!interactive_completion)
return; return;
if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) if(CompletionDialog::get() && CompletionDialog::get()->is_visible())
@ -1732,7 +1733,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if(autocomplete_rows.empty()) { if(autocomplete_rows.empty()) {
dispatcher.post([this] { dispatcher.post([this] {
// Move cursor forward if no arguments in completed function and if cursor is still inside () // Move cursor forward if no arguments in completed function and if cursor is still inside ()
if(autocompete_possibly_no_arguments) { if(autocomplete_possibly_no_arguments) {
auto iter = get_buffer()->get_insert()->get_iter(); auto iter = get_buffer()->get_insert()->get_iter();
auto prev = iter; auto prev = iter;
if(prev.backward_char() && *prev == '(' && *iter == ')' && iter.forward_char()) if(prev.backward_char() && *prev == '(' && *iter == ')' && iter.forward_char())
@ -1882,7 +1883,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if(*iter == ')' && iter.backward_char() && *iter == '(') { // If no arguments, try signatureHelp if(*iter == ')' && iter.backward_char() && *iter == '(') { // If no arguments, try signatureHelp
last_keyval = '('; last_keyval = '(';
if(is_js) // Workaround for typescript-language-server if(is_js) // Workaround for typescript-language-server
autocompete_possibly_no_arguments = true; autocomplete_possibly_no_arguments = true;
autocomplete->run(); autocomplete->run();
} }
} }
@ -1916,9 +1917,16 @@ void Source::LanguageProtocolView::setup_autocomplete() {
}; };
if(capabilities.completion_resolve && autocomplete_row.detail.empty() && autocomplete_row.documentation.value.empty() && autocomplete_row.item_object) { if(capabilities.completion_resolve && autocomplete_row.detail.empty() && autocomplete_row.documentation.value.empty() && autocomplete_row.item_object) {
// Prevent several completionItem/resolve requests when no completion item is found from written source (for instance when autocompleting in python : math.___).
// This seems to be a bug in Gtk::TreeView::signal_cursor_changed.
resolve_completion_item_connection.disconnect();
resolve_completion_item_connection = Glib::signal_timeout().connect(
[this, last_count, item_object = autocomplete_row.item_object] {
if(last_count != set_tooltip_count)
return false;
std::stringstream ss; std::stringstream ss;
bool first = true; bool first = true;
for(auto &child : autocomplete_row.item_object->children_or_empty()) { for(auto &child : item_object->children_or_empty()) {
ss << (!first ? ",\"" : "\"") << JSON::escape_string(child.first) << "\":" << child.second; ss << (!first ? ",\"" : "\"") << JSON::escape_string(child.first) << "\":" << child.second;
first = false; first = false;
} }
@ -1942,6 +1950,9 @@ void Source::LanguageProtocolView::setup_autocomplete() {
}); });
} }
}); });
return false;
},
0);
return nullptr; return nullptr;
} }
if(autocomplete_row.detail.empty() && autocomplete_row.documentation.value.empty()) if(autocomplete_row.detail.empty() && autocomplete_row.documentation.value.empty())
@ -1951,6 +1962,12 @@ void Source::LanguageProtocolView::setup_autocomplete() {
insert_documentation(this, tooltip, autocomplete_row.detail, autocomplete_row.documentation); insert_documentation(this, tooltip, autocomplete_row.detail, autocomplete_row.documentation);
}; };
}; };
autocomplete->clear_tooltips = [this] {
resolve_completion_item_connection.disconnect();
++set_tooltip_count;
autocomplete->tooltips.hide();
};
} }
void Source::LanguageProtocolView::update_diagnostics_async(std::vector<LanguageProtocol::Diagnostic> &&diagnostics) { void Source::LanguageProtocolView::update_diagnostics_async(std::vector<LanguageProtocol::Diagnostic> &&diagnostics) {

3
src/source_language_protocol.hpp

@ -288,12 +288,13 @@ namespace Source {
sigc::connection autocomplete_delayed_show_arguments_connection; sigc::connection autocomplete_delayed_show_arguments_connection;
/// Workaround for typescript-language-server. /// Workaround for typescript-language-server.
/// Used to move cursor forward if no arguments in completed function and if cursor is still inside () /// Used to move cursor forward if no arguments in completed function and if cursor is still inside ()
bool autocompete_possibly_no_arguments = false; bool autocomplete_possibly_no_arguments = false;
/// If language supports named parameters, returns the symbol separating the named parameter and value, /// If language supports named parameters, returns the symbol separating the named parameter and value,
/// for instance '=' for Python /// for instance '=' for Python
boost::optional<char> get_named_parameter_symbol(); boost::optional<char> get_named_parameter_symbol();
sigc::connection resolve_completion_item_connection;
/// Used when calling completionItem/resolve. Also increased in autocomplete->on_hide. /// Used when calling completionItem/resolve. Also increased in autocomplete->on_hide.
std::atomic<size_t> set_tooltip_count = {0}; std::atomic<size_t> set_tooltip_count = {0};

Loading…
Cancel
Save