|
|
|
@ -927,11 +927,11 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(capabilities.definition) { |
|
|
|
if(capabilities.definition) { |
|
|
|
get_declaration_location = [this]() { |
|
|
|
get_declaration_locations = [this]() { |
|
|
|
auto offset = get_declaration(get_buffer()->get_insert()->get_iter()); |
|
|
|
auto offsets = get_declarations(get_buffer()->get_insert()->get_iter()); |
|
|
|
if(!offset) |
|
|
|
if(offsets.empty()) |
|
|
|
Info::get().print("No declaration found"); |
|
|
|
Info::get().print("No declaration found"); |
|
|
|
return offset; |
|
|
|
return offsets; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Assumes that capabilities.definition is available when capabilities.implementation is supported
|
|
|
|
// Assumes that capabilities.definition is available when capabilities.implementation is supported
|
|
|
|
@ -949,27 +949,25 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(offsets.empty() || is_implementation) { |
|
|
|
if(offsets.empty() || is_implementation) { |
|
|
|
if(auto offset = get_declaration_location()) |
|
|
|
auto offsets = get_declaration_locations(); |
|
|
|
return std::vector<Offset>({std::move(offset)}); |
|
|
|
if(!offsets.empty()) |
|
|
|
|
|
|
|
return offsets; |
|
|
|
} |
|
|
|
} |
|
|
|
return offsets; |
|
|
|
return offsets; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
get_declaration_or_implementation_locations = [this]() { |
|
|
|
get_declaration_or_implementation_locations = [this]() { |
|
|
|
std::vector<Offset> offsets; |
|
|
|
return get_declaration_locations(); |
|
|
|
if(auto offset = get_declaration_location()) |
|
|
|
|
|
|
|
offsets.emplace_back(std::move(offset)); |
|
|
|
|
|
|
|
return offsets; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(capabilities.type_definition) { |
|
|
|
if(capabilities.type_definition) { |
|
|
|
get_type_declaration_location = [this]() { |
|
|
|
get_type_declaration_locations = [this]() { |
|
|
|
auto offset = get_type_declaration(get_buffer()->get_insert()->get_iter()); |
|
|
|
auto offsets = get_type_declarations(get_buffer()->get_insert()->get_iter()); |
|
|
|
if(!offset) |
|
|
|
if(offsets.empty()) |
|
|
|
Info::get().print("No type declaration found"); |
|
|
|
Info::get().print("No type declaration found"); |
|
|
|
return offset; |
|
|
|
return offsets; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
if(capabilities.implementation) { |
|
|
|
if(capabilities.implementation) { |
|
|
|
@ -2249,10 +2247,12 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect |
|
|
|
Glib::ustring value_type = "Value"; |
|
|
|
Glib::ustring value_type = "Value"; |
|
|
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
auto offset = get_declaration(token_iters.first); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto variable = get_buffer()->get_text(token_iters.first, token_iters.second); |
|
|
|
auto variable = get_buffer()->get_text(token_iters.first, token_iters.second); |
|
|
|
Glib::ustring debug_value = Debug::LLDB::get().get_value(variable, offset.file_path, offset.line + 1, offset.index + 1); |
|
|
|
Glib::ustring debug_value; |
|
|
|
|
|
|
|
auto offsets = get_declarations(token_iters.first); |
|
|
|
|
|
|
|
for(size_t i = 0; i < offsets.size() && debug_value.empty(); ++i) |
|
|
|
|
|
|
|
debug_value = Debug::LLDB::get().get_value(variable, offsets[i].file_path, offsets[i].line + 1, offsets[i].index + 1); |
|
|
|
if(debug_value.empty()) { |
|
|
|
if(debug_value.empty()) { |
|
|
|
debug_value = Debug::LLDB::get().get_return_value(file_path, token_iters.first.get_line() + 1, token_iters.first.get_line_index() + 1); |
|
|
|
debug_value = Debug::LLDB::get().get_return_value(file_path, token_iters.first.get_line() + 1, token_iters.first.get_line_index() + 1); |
|
|
|
if(!debug_value.empty()) |
|
|
|
if(!debug_value.empty()) |
|
|
|
@ -2353,10 +2353,10 @@ void Source::LanguageProtocolView::apply_clickable_tag(const Gtk::TextIter &iter |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter &iter) { |
|
|
|
std::vector<Source::Offset> Source::LanguageProtocolView::get_declarations(const Gtk::TextIter &iter) { |
|
|
|
auto offset = std::make_shared<Offset>(); |
|
|
|
auto offsets = std::make_shared<std::vector<Offset>>(); |
|
|
|
std::promise<void> result_processed; |
|
|
|
std::promise<void> result_processed; |
|
|
|
write_request("textDocument/definition", to_string({make_position(iter.get_line(), get_line_pos(iter))}), [offset, &result_processed](JSON &&result, bool error) { |
|
|
|
write_request("textDocument/definition", to_string({make_position(iter.get_line(), get_line_pos(iter))}), [offsets, &result_processed](JSON &&result, bool error) { |
|
|
|
if(!error) { |
|
|
|
if(!error) { |
|
|
|
auto locations = result.array_or_empty(); |
|
|
|
auto locations = result.array_or_empty(); |
|
|
|
if(locations.empty()) { |
|
|
|
if(locations.empty()) { |
|
|
|
@ -2366,10 +2366,7 @@ Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter |
|
|
|
for(auto &location_object : locations) { |
|
|
|
for(auto &location_object : locations) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
LanguageProtocol::Location location(location_object); |
|
|
|
LanguageProtocol::Location location(location_object); |
|
|
|
offset->file_path = std::move(location.file); |
|
|
|
offsets->emplace_back(location.range.start.line, location.range.start.character, std::move(location.file)); |
|
|
|
offset->line = location.range.start.line; |
|
|
|
|
|
|
|
offset->index = location.range.start.character; |
|
|
|
|
|
|
|
break; // TODO: can a language server return several definitions?
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch(...) { |
|
|
|
catch(...) { |
|
|
|
} |
|
|
|
} |
|
|
|
@ -2378,13 +2375,13 @@ Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter |
|
|
|
result_processed.set_value(); |
|
|
|
result_processed.set_value(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
result_processed.get_future().get(); |
|
|
|
result_processed.get_future().get(); |
|
|
|
return *offset; |
|
|
|
return *offsets; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Source::Offset Source::LanguageProtocolView::get_type_declaration(const Gtk::TextIter &iter) { |
|
|
|
std::vector<Source::Offset> Source::LanguageProtocolView::get_type_declarations(const Gtk::TextIter &iter) { |
|
|
|
auto offset = std::make_shared<Offset>(); |
|
|
|
auto offsets = std::make_shared<std::vector<Offset>>(); |
|
|
|
std::promise<void> result_processed; |
|
|
|
std::promise<void> result_processed; |
|
|
|
write_request("textDocument/typeDefinition", to_string({make_position(iter.get_line(), get_line_pos(iter))}), [offset, &result_processed](JSON &&result, bool error) { |
|
|
|
write_request("textDocument/typeDefinition", to_string({make_position(iter.get_line(), get_line_pos(iter))}), [offsets, &result_processed](JSON &&result, bool error) { |
|
|
|
if(!error) { |
|
|
|
if(!error) { |
|
|
|
auto locations = result.array_or_empty(); |
|
|
|
auto locations = result.array_or_empty(); |
|
|
|
if(locations.empty()) { |
|
|
|
if(locations.empty()) { |
|
|
|
@ -2394,10 +2391,7 @@ Source::Offset Source::LanguageProtocolView::get_type_declaration(const Gtk::Tex |
|
|
|
for(auto &location_object : locations) { |
|
|
|
for(auto &location_object : locations) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
LanguageProtocol::Location location(location_object); |
|
|
|
LanguageProtocol::Location location(location_object); |
|
|
|
offset->file_path = std::move(location.file); |
|
|
|
offsets->emplace_back(location.range.start.line, location.range.start.character, std::move(location.file)); |
|
|
|
offset->line = location.range.start.line; |
|
|
|
|
|
|
|
offset->index = location.range.start.character; |
|
|
|
|
|
|
|
break; // TODO: can a language server return several type definitions?
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch(...) { |
|
|
|
catch(...) { |
|
|
|
} |
|
|
|
} |
|
|
|
@ -2406,7 +2400,7 @@ Source::Offset Source::LanguageProtocolView::get_type_declaration(const Gtk::Tex |
|
|
|
result_processed.set_value(); |
|
|
|
result_processed.set_value(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
result_processed.get_future().get(); |
|
|
|
result_processed.get_future().get(); |
|
|
|
return *offset; |
|
|
|
return *offsets; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Source::Offset> Source::LanguageProtocolView::get_implementations(const Gtk::TextIter &iter) { |
|
|
|
std::vector<Source::Offset> Source::LanguageProtocolView::get_implementations(const Gtk::TextIter &iter) { |
|
|
|
@ -2422,7 +2416,7 @@ std::vector<Source::Offset> Source::LanguageProtocolView::get_implementations(co |
|
|
|
for(auto &location_object : locations) { |
|
|
|
for(auto &location_object : locations) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
LanguageProtocol::Location location(location_object); |
|
|
|
LanguageProtocol::Location location(location_object); |
|
|
|
offsets->emplace_back(location.range.start.line, location.range.start.character, location.file); |
|
|
|
offsets->emplace_back(location.range.start.line, location.range.start.character, std::move(location.file)); |
|
|
|
} |
|
|
|
} |
|
|
|
catch(...) { |
|
|
|
catch(...) { |
|
|
|
} |
|
|
|
} |
|
|
|
|