Browse Source

Tooltip sorkaround for flow's language server: make sure type information is shown first

pipelines/235045657
eidheim 5 years ago
parent
commit
9e170348df
  1. 25
      src/source_language_protocol.cpp

25
src/source_language_protocol.cpp

@ -1133,7 +1133,7 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect
std::string value; std::string value;
std::string kind; std::string kind;
}; };
std::vector<Content> contents; std::list<Content> contents;
auto contents_pt = result.get_child_optional("contents"); auto contents_pt = result.get_child_optional("contents");
if(!contents_pt) if(!contents_pt)
return; return;
@ -1149,13 +1149,18 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect
contents.emplace_back(Content{*value_pt, kind}); contents.emplace_back(Content{*value_pt, kind});
} }
else { else {
bool first_value = true;
for(auto it = contents_pt->begin(); it != contents_pt->end(); ++it) { for(auto it = contents_pt->begin(); it != contents_pt->end(); ++it) {
auto value = it->second.get<std::string>("value", ""); auto value = it->second.get<std::string>("value", "");
if(!value.empty()) { if(!value.empty()) {
auto kind = it->second.get<std::string>("kind", ""); auto kind = it->second.get<std::string>("kind", "");
if(kind.empty()) if(kind.empty())
kind = it->second.get<std::string>("language", ""); kind = it->second.get<std::string>("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 { else {
value = it->second.get_value<std::string>(""); value = it->second.get_value<std::string>("");
@ -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)); 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) { 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++) { bool first = true;
if(i > 0) for(auto &content : contents) {
if(!first)
tooltip.buffer->insert_at_cursor("\n\n"); 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 first = false;
tooltip.insert_with_links_tagged(contents[i].value); if(content.kind == "plaintext" || content.kind.empty() || (language_id == "python" && content.kind == "markdown")) // Python might support markdown in the future
else if(contents[i].kind == "markdown") tooltip.insert_with_links_tagged(content.value);
tooltip.insert_markdown(contents[i].value); else if(content.kind == "markdown")
tooltip.insert_markdown(content.value);
else else
tooltip.insert_code(contents[i].value, contents[i].kind); tooltip.insert_code(content.value, content.kind);
tooltip.remove_trailing_newlines(); tooltip.remove_trailing_newlines();
} }

Loading…
Cancel
Save