Browse Source

Language server: no longer tries to rename source files outside of project path

merge-requests/365/head
eidheim 8 years ago
parent
commit
86fa995bb6
  1. 12
      src/source_language_protocol.cc

12
src/source_language_protocol.cc

@ -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,6 +616,7 @@ 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);
if(filesystem::file_in_path(path, project_path)) {
usages.emplace_back(Usages{path, nullptr, std::vector<std::pair<Offset, Offset>>()}); usages.emplace_back(Usages{path, nullptr, std::vector<std::pair<Offset, Offset>>()});
for(auto edit_it=file_it->second.begin();edit_it!=file_it->second.end();++edit_it) { for(auto edit_it=file_it->second.begin();edit_it!=file_it->second.end();++edit_it) {
auto range_it=edit_it->second.find("range"); auto range_it=edit_it->second.find("range");
@ -624,6 +631,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
} }
} }
} }
}
else { else {
auto changes_pt=result.get_child("documentChanges", boost::property_tree::ptree()); auto changes_pt=result.get_child("documentChanges", boost::property_tree::ptree());
for(auto change_it=changes_pt.begin();change_it!=changes_pt.end();++change_it) { for(auto change_it=changes_pt.begin();change_it!=changes_pt.end();++change_it) {
@ -632,6 +640,7 @@ 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);
if(filesystem::file_in_path(path, project_path)) {
usages.emplace_back(Usages{path, std::make_unique<std::string>(), std::vector<std::pair<Offset, Offset>>()}); usages.emplace_back(Usages{path, std::make_unique<std::string>(), std::vector<std::pair<Offset, Offset>>()});
auto edits_pt=change_it->second.get_child("edits", boost::property_tree::ptree()); auto edits_pt=change_it->second.get_child("edits", boost::property_tree::ptree());
for(auto edit_it=edits_pt.begin();edit_it!=edits_pt.end();++edit_it) { for(auto edit_it=edits_pt.begin();edit_it!=edits_pt.end();++edit_it) {
@ -657,6 +666,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
} }
} }
} }
}
catch(...) { catch(...) {
usages.clear(); usages.clear();
} }

Loading…
Cancel
Save