Browse Source

Language protocol: improved hover and completion item documentation

merge-requests/365/head
eidheim 8 years ago
parent
commit
7357979ac9
  1. 31
      src/source_language_protocol.cc

31
src/source_language_protocol.cc

@ -829,18 +829,26 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect
auto offset=iter.get_offset(); auto offset=iter.get_offset();
client->write_request("textDocument/hover", "\"textDocument\": {\"uri\":\"file://"+file_path.string()+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [this, offset](const boost::property_tree::ptree &result, bool error) { client->write_request("textDocument/hover", "\"textDocument\": {\"uri\":\"file://"+file_path.string()+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [this, offset](const boost::property_tree::ptree &result, bool error) {
if(!error) { if(!error) {
auto contents=result.get_child("contents", boost::property_tree::ptree()); std::string content;
auto it=contents.begin(); {
if(it!=contents.end()) { auto contents_pt=result.get_child("contents", boost::property_tree::ptree());
auto value=it->second.get<std::string>("value", ""); auto contents_it=contents_pt.begin();
if(!value.empty()) { if(contents_it!=contents_pt.end())
dispatcher.post([this, offset, value=std::move(value)] { content=contents_it->second.get<std::string>("value", "");
}
if(content.empty()) {
auto contents_it=result.find("contents");
if(contents_it!=result.not_found())
content=contents_it->second.get_value<std::string>("");
}
if(!content.empty()) {
dispatcher.post([this, offset, content=std::move(content)] {
if(offset>=get_buffer()->get_char_count()) if(offset>=get_buffer()->get_char_count())
return; return;
type_tooltips.clear(); type_tooltips.clear();
auto create_tooltip_buffer=[this, offset, value=std::move(value)]() { auto create_tooltip_buffer=[this, offset, content=std::move(content)]() {
auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table()); auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table());
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "Type: "+value, "def:note"); tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), content, "def:note");
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
if(language_id=="rust" && capabilities.definition) { if(language_id=="rust" && capabilities.definition) {
@ -888,7 +896,6 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect
}); });
} }
} }
}
}); });
} }
@ -1072,10 +1079,16 @@ void Source::LanguageProtocolView::setup_autocomplete() {
for(auto it=begin;it!=end;++it) { for(auto it=begin;it!=end;++it) {
auto label=it->second.get<std::string>("label", ""); auto label=it->second.get<std::string>("label", "");
auto detail=it->second.get<std::string>("detail", ""); auto detail=it->second.get<std::string>("detail", "");
auto documentation=it->second.get<std::string>("documentation", "");
auto insert=it->second.get<std::string>("insertText", label); auto insert=it->second.get<std::string>("insertText", label);
if(!label.empty()) { if(!label.empty()) {
autocomplete.rows.emplace_back(std::move(label)); autocomplete.rows.emplace_back(std::move(label));
autocomplete_comment.emplace_back(std::move(detail)); autocomplete_comment.emplace_back(std::move(detail));
if(!documentation.empty()) {
if(!autocomplete_comment.back().empty())
autocomplete_comment.back()+="\n\n";
autocomplete_comment.back()+=documentation;
}
autocomplete_insert.emplace_back(std::move(insert)); autocomplete_insert.emplace_back(std::move(insert));
} }
} }

Loading…
Cancel
Save