From 9e170348dfe20b4f72eb665e3fc1bdfd019fa173 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 6 Jul 2020 15:57:43 +0200 Subject: [PATCH] Tooltip sorkaround for flow's language server: make sure type information is shown first --- src/source_language_protocol.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/source_language_protocol.cpp b/src/source_language_protocol.cpp index a81d593..a90fd3c 100644 --- a/src/source_language_protocol.cpp +++ b/src/source_language_protocol.cpp @@ -1133,7 +1133,7 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect std::string value; std::string kind; }; - std::vector contents; + std::list contents; auto contents_pt = result.get_child_optional("contents"); if(!contents_pt) return; @@ -1149,13 +1149,18 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect contents.emplace_back(Content{*value_pt, kind}); } else { + bool first_value = true; for(auto it = contents_pt->begin(); it != contents_pt->end(); ++it) { auto value = it->second.get("value", ""); if(!value.empty()) { auto kind = it->second.get("kind", ""); if(kind.empty()) kind = it->second.get("language", ""); - contents.emplace_back(Content{value, kind}); + if(first_value) // Place first value, which most likely is type information, to front (workaround for flow-bin's language server) + contents.emplace_front(Content{value, kind}); + else + contents.emplace_back(Content{value, kind}); + first_value = false; } else { value = it->second.get_value(""); @@ -1177,15 +1182,17 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect auto token_iters = get_token_iters(get_buffer()->get_iter_at_offset(offset)); type_tooltips.emplace_back(this, token_iters.first, token_iters.second, [this, offset, contents = std::move(contents)](Tooltip &tooltip) { - for(size_t i = 0; i < contents.size(); i++) { - if(i > 0) + bool first = true; + for(auto &content : contents) { + if(!first) tooltip.buffer->insert_at_cursor("\n\n"); - if(contents[i].kind == "plaintext" || contents[i].kind.empty() || (language_id == "python" && contents[i].kind == "markdown")) // Python might support markdown in the future - tooltip.insert_with_links_tagged(contents[i].value); - else if(contents[i].kind == "markdown") - tooltip.insert_markdown(contents[i].value); + first = false; + if(content.kind == "plaintext" || content.kind.empty() || (language_id == "python" && content.kind == "markdown")) // Python might support markdown in the future + tooltip.insert_with_links_tagged(content.value); + else if(content.kind == "markdown") + tooltip.insert_markdown(content.value); else - tooltip.insert_code(contents[i].value, contents[i].kind); + tooltip.insert_code(content.value, content.kind); tooltip.remove_trailing_newlines(); }