From 1cb311de02c4dc83eafb940f5d09c10994640a99 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 31 Jul 2018 15:03:42 +0200 Subject: [PATCH] Language protocol: renamed uri to file where appropriate --- src/project.cc | 8 ++--- src/source_language_protocol.cc | 52 ++++++++++++++++----------------- src/source_language_protocol.h | 4 +-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/project.cc b/src/project.cc index 61bfedf..4a5198c 100644 --- a/src/project.cc +++ b/src/project.cc @@ -719,7 +719,7 @@ void Project::LanguageProtocol::show_symbols() { for(auto it = result.begin(); it != result.end(); ++it) { try { ::LanguageProtocol::Location location(it->second.get_child("location")); - if(filesystem::file_in_path(location.uri, *project_path)) { + if(filesystem::file_in_path(location.file, *project_path)) { locations->emplace_back(std::move(location)); names.emplace_back(it->second.get("name")); } @@ -732,7 +732,7 @@ void Project::LanguageProtocol::show_symbols() { }); result_processed.get_future().get(); for(size_t c = 0; c < locations->size() && c < names.size(); ++c) - SelectionDialog::get()->add_row(filesystem::get_relative_path((*locations)[c].uri, *project_path).string() + ':' + std::to_string((*locations)[c].range.start.line + 1) + ':' + std::to_string((*locations)[c].range.start.character + 1) + ": " + names[c]); + SelectionDialog::get()->add_row(filesystem::get_relative_path((*locations)[c].file, *project_path).string() + ':' + std::to_string((*locations)[c].range.start.line + 1) + ':' + std::to_string((*locations)[c].range.start.character + 1) + ": " + names[c]); }; } else { @@ -758,9 +758,9 @@ void Project::LanguageProtocol::show_symbols() { SelectionDialog::get()->on_select = [locations](unsigned int index, const std::string &text, bool hide_window) { auto &offset = (*locations)[index]; - if(!boost::filesystem::is_regular_file(offset.uri)) + if(!boost::filesystem::is_regular_file(offset.file)) return; - Notebook::get().open(offset.uri); + Notebook::get().open(offset.file); auto view = Notebook::get().get_current_view(); view->place_cursor_at_line_offset(offset.range.start.line, offset.range.start.character); view->scroll_to_cursor_delayed(view, true, false); diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index 2704127..995caff 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -20,13 +20,13 @@ LanguageProtocol::Offset::Offset(const boost::property_tree::ptree &pt) : line(p LanguageProtocol::Range::Range(const boost::property_tree::ptree &pt) : start(pt.get_child("start")), end(pt.get_child("end")) {} -LanguageProtocol::Location::Location(const boost::property_tree::ptree &pt, std::string uri_) : range(pt.get_child("range")) { - if(uri_.empty()) { - uri = pt.get("uri"); - uri.erase(0, 7); +LanguageProtocol::Location::Location(const boost::property_tree::ptree &pt, std::string file_) : range(pt.get_child("range")) { + if(file_.empty()) { + file = pt.get("uri"); + file.erase(0, 7); } else - uri = std::move(uri_); + file = std::move(file_); } LanguageProtocol::Diagnostic::RelatedInformation::RelatedInformation(const boost::property_tree::ptree &pt) : message(pt.get("message")), location(pt.get_child("location")) {} @@ -619,11 +619,11 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { auto c = static_cast(-1); for(auto &location : locations) { ++c; - usages.emplace_back(Offset(location.range.start.line, location.range.start.character, location.uri), std::string()); + usages.emplace_back(Offset(location.range.start.line, location.range.start.character, location.file), std::string()); auto &usage = usages.back(); auto view_it = views.end(); for(auto it = views.begin(); it != views.end(); ++it) { - if(location.uri == (*it)->file_path) { + if(location.file == (*it)->file_path) { view_it = it; break; } @@ -638,9 +638,9 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { } } else { - auto it = file_lines.find(location.uri); + auto it = file_lines.find(location.file); if(it == file_lines.end()) { - std::ifstream ifs(location.uri); + std::ifstream ifs(location.file); if(ifs) { std::vector lines; std::string line; @@ -649,11 +649,11 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { line.pop_back(); lines.emplace_back(line); } - auto pair = file_lines.emplace(location.uri, lines); + auto pair = file_lines.emplace(location.file, lines); it = pair.first; } else { - auto pair = file_lines.emplace(location.uri, std::vector()); + auto pair = file_lines.emplace(location.file, std::vector()); it = pair.first; } } @@ -693,7 +693,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { rename_similar_tokens = [this](const std::string &text) { class Changes { public: - std::string uri; + std::string file; std::vector text_edits; }; @@ -717,13 +717,13 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { auto changes_it = result.find("changes"); if(changes_it != result.not_found()) { for(auto file_it = changes_it->second.begin(); file_it != changes_it->second.end(); ++file_it) { - auto uri = file_it->first; - uri.erase(0, 7); - if(filesystem::file_in_path(uri, project_path)) { + auto file = file_it->first; + file.erase(0, 7); + if(filesystem::file_in_path(file, project_path)) { std::vector edits; for(auto edit_it = file_it->second.begin(); edit_it != file_it->second.end(); ++edit_it) edits.emplace_back(edit_it->second); - changes.emplace_back(Changes{std::move(uri), std::move(edits)}); + changes.emplace_back(Changes{std::move(file), std::move(edits)}); } } } @@ -732,14 +732,14 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { for(auto change_it = changes_pt.begin(); change_it != changes_pt.end(); ++change_it) { auto document_it = change_it->second.find("textDocument"); if(document_it != change_it->second.not_found()) { - auto uri = document_it->second.get("uri", ""); - uri.erase(0, 7); - if(filesystem::file_in_path(uri, project_path)) { + auto file = document_it->second.get("uri", ""); + file.erase(0, 7); + if(filesystem::file_in_path(file, project_path)) { std::vector edits; 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) edits.emplace_back(edit_it->second); - changes.emplace_back(Changes{std::move(uri), std::move(edits)}); + changes.emplace_back(Changes{std::move(file), std::move(edits)}); } } } @@ -774,7 +774,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { for(auto &change : changes) { auto view_it = views.end(); for(auto it = views.begin(); it != views.end(); ++it) { - if((*it)->file_path == change.uri) { + if((*it)->file_path == change.file) { view_it = it; break; } @@ -807,11 +807,11 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { else { Glib::ustring buffer; { - std::ifstream stream(change.uri, std::ifstream::binary); + std::ifstream stream(change.file, std::ifstream::binary); if(stream) buffer.assign(std::istreambuf_iterator(stream), std::istreambuf_iterator()); } - std::ofstream stream(change.uri, std::ifstream::binary); + std::ofstream stream(change.file, std::ifstream::binary); if(!buffer.empty() && stream) { std::vector lines_start_pos = {0}; for(size_t c = 0; c < buffer.size(); ++c) { @@ -837,7 +837,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() { changes_renamed.emplace_back(&change); } else - Terminal::get().print("Error: could not write to file " + change.uri + '\n', true); + Terminal::get().print("Error: could not write to file " + change.file + '\n', true); } } @@ -910,7 +910,7 @@ void Source::LanguageProtocolView::update_diagnostics(std::vectorinsert_at_cursor(diagnostic.message); for(size_t i = 0; i < diagnostic.related_informations.size(); ++i) { - auto link = filesystem::get_relative_path(diagnostic.related_informations[i].location.uri, file_path.parent_path()).string(); + auto link = filesystem::get_relative_path(diagnostic.related_informations[i].location.file, file_path.parent_path()).string(); link += ':' + std::to_string(diagnostic.related_informations[i].location.range.start.line + 1); link += ':' + std::to_string(diagnostic.related_informations[i].location.range.start.character + 1); @@ -1115,7 +1115,7 @@ Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter for(auto it = result.begin(); it != result.end(); ++it) { try { LanguageProtocol::Location location(it->second); - offset->file_path = std::move(location.uri); + offset->file_path = 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? diff --git a/src/source_language_protocol.h b/src/source_language_protocol.h index b98a973..8bb8f12 100644 --- a/src/source_language_protocol.h +++ b/src/source_language_protocol.h @@ -30,8 +30,8 @@ namespace LanguageProtocol { class Location { public: - Location(const boost::property_tree::ptree &pt, std::string uri_ = {}); - std::string uri; + Location(const boost::property_tree::ptree &pt, std::string file_ = {}); + std::string file; Range range; };