|
|
|
@ -601,8 +601,14 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { |
|
|
|
auto iter=get_buffer()->get_insert()->get_iter(); |
|
|
|
auto iter=get_buffer()->get_insert()->get_iter(); |
|
|
|
std::vector<Usages> usages; |
|
|
|
std::vector<Usages> usages; |
|
|
|
std::promise<void> result_processed; |
|
|
|
std::promise<void> result_processed; |
|
|
|
client->write_request("textDocument/rename", "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}, \"newName\": \""+text+"\"", [&usages, &result_processed](const boost::property_tree::ptree &result, bool error) { |
|
|
|
client->write_request("textDocument/rename", "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}, \"newName\": \""+text+"\"", [this, &usages, &result_processed](const boost::property_tree::ptree &result, bool error) { |
|
|
|
if(!error) { |
|
|
|
if(!error) { |
|
|
|
|
|
|
|
boost::filesystem::path project_path; |
|
|
|
|
|
|
|
auto build=Project::Build::create(file_path); |
|
|
|
|
|
|
|
if(!build->project_path.empty()) |
|
|
|
|
|
|
|
project_path=build->project_path; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
project_path=file_path.parent_path(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto changes_it=result.find("changes"); |
|
|
|
auto changes_it=result.find("changes"); |
|
|
|
if(changes_it!=result.not_found()) { |
|
|
|
if(changes_it!=result.not_found()) { |
|
|
|
@ -610,15 +616,17 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { |
|
|
|
auto path=file_it->first; |
|
|
|
auto path=file_it->first; |
|
|
|
if(path.size()>=7) { |
|
|
|
if(path.size()>=7) { |
|
|
|
path.erase(0, 7); |
|
|
|
path.erase(0, 7); |
|
|
|
usages.emplace_back(Usages{path, nullptr, std::vector<std::pair<Offset, Offset>>()}); |
|
|
|
if(filesystem::file_in_path(path, project_path)) { |
|
|
|
for(auto edit_it=file_it->second.begin();edit_it!=file_it->second.end();++edit_it) { |
|
|
|
usages.emplace_back(Usages{path, nullptr, std::vector<std::pair<Offset, Offset>>()}); |
|
|
|
auto range_it=edit_it->second.find("range"); |
|
|
|
for(auto edit_it=file_it->second.begin();edit_it!=file_it->second.end();++edit_it) { |
|
|
|
if(range_it!=edit_it->second.not_found()) { |
|
|
|
auto range_it=edit_it->second.find("range"); |
|
|
|
auto start_it=range_it->second.find("start"); |
|
|
|
if(range_it!=edit_it->second.not_found()) { |
|
|
|
auto end_it=range_it->second.find("end"); |
|
|
|
auto start_it=range_it->second.find("start"); |
|
|
|
if(start_it!=range_it->second.not_found() && end_it!=range_it->second.not_found()) |
|
|
|
auto end_it=range_it->second.find("end"); |
|
|
|
usages.back().offsets.emplace_back(std::make_pair(Offset(start_it->second.get<unsigned>("line"), start_it->second.get<unsigned>("character")), |
|
|
|
if(start_it!=range_it->second.not_found() && end_it!=range_it->second.not_found()) |
|
|
|
Offset(end_it->second.get<unsigned>("line"), end_it->second.get<unsigned>("character")))); |
|
|
|
usages.back().offsets.emplace_back(std::make_pair(Offset(start_it->second.get<unsigned>("line"), start_it->second.get<unsigned>("character")), |
|
|
|
|
|
|
|
Offset(end_it->second.get<unsigned>("line"), end_it->second.get<unsigned>("character")))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -632,22 +640,24 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { |
|
|
|
auto path=document_it->second.get<std::string>("uri", ""); |
|
|
|
auto path=document_it->second.get<std::string>("uri", ""); |
|
|
|
if(path.size()>=7) { |
|
|
|
if(path.size()>=7) { |
|
|
|
path.erase(0, 7); |
|
|
|
path.erase(0, 7); |
|
|
|
usages.emplace_back(Usages{path, std::make_unique<std::string>(), std::vector<std::pair<Offset, Offset>>()}); |
|
|
|
if(filesystem::file_in_path(path, project_path)) { |
|
|
|
auto edits_pt=change_it->second.get_child("edits", boost::property_tree::ptree()); |
|
|
|
usages.emplace_back(Usages{path, std::make_unique<std::string>(), std::vector<std::pair<Offset, Offset>>()}); |
|
|
|
for(auto edit_it=edits_pt.begin();edit_it!=edits_pt.end();++edit_it) { |
|
|
|
auto edits_pt=change_it->second.get_child("edits", boost::property_tree::ptree()); |
|
|
|
auto new_text_it=edit_it->second.find("newText"); |
|
|
|
for(auto edit_it=edits_pt.begin();edit_it!=edits_pt.end();++edit_it) { |
|
|
|
if(new_text_it!=edit_it->second.not_found()) { |
|
|
|
auto new_text_it=edit_it->second.find("newText"); |
|
|
|
auto range_it=edit_it->second.find("range"); |
|
|
|
if(new_text_it!=edit_it->second.not_found()) { |
|
|
|
if(range_it!=edit_it->second.not_found()) { |
|
|
|
auto range_it=edit_it->second.find("range"); |
|
|
|
auto start_it=range_it->second.find("start"); |
|
|
|
if(range_it!=edit_it->second.not_found()) { |
|
|
|
auto end_it=range_it->second.find("end"); |
|
|
|
auto start_it=range_it->second.find("start"); |
|
|
|
if(start_it!=range_it->second.not_found() && end_it!=range_it->second.not_found()) { |
|
|
|
auto end_it=range_it->second.find("end"); |
|
|
|
auto end_line=end_it->second.get<size_t>("line"); |
|
|
|
if(start_it!=range_it->second.not_found() && end_it!=range_it->second.not_found()) { |
|
|
|
if(end_line>std::numeric_limits<int>::max()) |
|
|
|
auto end_line=end_it->second.get<size_t>("line"); |
|
|
|
end_line=std::numeric_limits<int>::max(); |
|
|
|
if(end_line>std::numeric_limits<int>::max()) |
|
|
|
*usages.back().new_text=new_text_it->second.get_value<std::string>(); |
|
|
|
end_line=std::numeric_limits<int>::max(); |
|
|
|
usages.back().offsets.emplace_back(std::make_pair(Offset(start_it->second.get<unsigned>("line"), start_it->second.get<unsigned>("character")), |
|
|
|
*usages.back().new_text=new_text_it->second.get_value<std::string>(); |
|
|
|
Offset(static_cast<unsigned>(end_line), end_it->second.get<unsigned>("character")))); |
|
|
|
usages.back().offsets.emplace_back(std::make_pair(Offset(start_it->second.get<unsigned>("line"), start_it->second.get<unsigned>("character")), |
|
|
|
|
|
|
|
Offset(static_cast<unsigned>(end_line), end_it->second.get<unsigned>("character")))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|