diff --git a/src/project.cpp b/src/project.cpp index 7165a20..ddc319f 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -15,7 +15,6 @@ #include "info.hpp" #include "snippets.hpp" #include "source_clang.hpp" -#include "source_language_protocol.hpp" #include "usages_clang.hpp" #include @@ -675,145 +674,6 @@ void Project::LLDB::debug_write(const std::string &buffer) { } #endif -void Project::LanguageProtocol::show_symbols() { - auto project_path = std::make_shared(build->project_path); - auto view = Notebook::get().get_current_view(); - auto language_protocol_view = dynamic_cast(view); - - if(project_path->empty()) { - if(language_protocol_view) - *project_path = language_protocol_view->file_path.parent_path(); - else { - Info::get().print("Could not find project folder"); - return; - } - } - - auto language_id = get_language_id(); - auto executable_name = language_id + "-language-server"; - if(filesystem::find_executable(executable_name).empty()) - return Base::show_symbols(); - - auto client = ::LanguageProtocol::Client::get(language_protocol_view ? language_protocol_view->file_path : *project_path, language_id); - auto capabilities = client->initialize(language_protocol_view); - - if(!capabilities.workspace_symbol && !(capabilities.document_symbol && language_protocol_view)) - return Base::show_symbols(); - - if(view) - SelectionDialog::create(view, true, true); - else - SelectionDialog::create(true, true); - - SelectionDialog::get()->on_hide = [] { - SelectionDialog::get()->on_search_entry_changed = nullptr; // To delete client object - }; - - auto locations = std::make_shared>>(); - if(capabilities.workspace_symbol) { - SelectionDialog::get()->on_search_entry_changed = [client, project_path, locations](const std::string &text) { - if(text.size() > 1) - return; - else { - locations->clear(); - SelectionDialog::get()->erase_rows(); - if(text.empty()) - return; - } - std::promise result_processed; - client->write_request(nullptr, "workspace/symbol", R"("query":")" + text + '"', [&result_processed, locations, project_path](const boost::property_tree::ptree &result, bool error) { - if(!error) { - for(auto it = result.begin(); it != result.end(); ++it) { - try { - ::LanguageProtocol::Location location(it->second.get_child("location")); - if(filesystem::file_in_path(location.file, *project_path)) { - auto container = it->second.get("containerName", ""); - if(container == "null") - container.clear(); - - auto row = filesystem::get_relative_path(location.file, *project_path).string() + ':' + std::to_string(location.range.start.line + 1) + ": " + (!container.empty() ? Glib::Markup::escape_text(container) + "::" : "") + "" + Glib::Markup::escape_text(it->second.get("name")) + ""; - - locations->emplace_back(std::make_pair(std::move(location), std::move(row))); - } - } - catch(...) { - } - } - } - result_processed.set_value(); - }); - result_processed.get_future().get(); - - std::sort(locations->begin(), locations->end()); - for(auto &location : *locations) { - SelectionDialog::get()->add_row(location.second); - location.second.clear(); - } - }; - } - else { - std::promise result_processed; - client->write_request(language_protocol_view, "textDocument/documentSymbol", R"("textDocument":{"uri":")" + language_protocol_view->uri + "\"}", [&result_processed, locations, language_protocol_view](const boost::property_tree::ptree &result, bool error) { - if(!error) { - std::function parse_result = [locations, &parse_result, language_protocol_view](const boost::property_tree::ptree &pt, const std::string &container) { - for(auto it = pt.begin(); it != pt.end(); ++it) { - try { - std::unique_ptr<::LanguageProtocol::Location> location; - std::string prefix; - auto location_pt = it->second.get_child_optional("location"); - if(location_pt) { - location = std::make_unique<::LanguageProtocol::Location>(*location_pt); - std::string container = it->second.get("containerName", ""); - if(container == "null") - container.clear(); - if(!container.empty()) - prefix = container + "::"; - } - else { - location = std::make_unique<::LanguageProtocol::Location>(language_protocol_view->file_path.string(), ::LanguageProtocol::Range(it->second.get_child("range"))); - if(!container.empty()) - prefix = container + "::"; - } - auto row = std::to_string(location->range.start.line + 1) + ": " + Glib::Markup::escape_text(prefix) + "" + Glib::Markup::escape_text(it->second.get("name")) + ""; - locations->emplace_back(std::make_pair(std::move(*location), std::move(row))); - auto children = it->second.get_child_optional("children"); - if(children) - parse_result(*children, (!container.empty() ? container + "::" : "") + it->second.get("name")); - } - catch(...) { - } - } - }; - parse_result(result, ""); - } - result_processed.set_value(); - }); - result_processed.get_future().get(); - - std::sort(locations->begin(), locations->end()); - for(auto &location : *locations) { - SelectionDialog::get()->add_row(location.second); - location.second.clear(); - } - } - - SelectionDialog::get()->on_select = [locations](unsigned int index, const std::string &text, bool hide_window) { - auto &location = (*locations)[index].first; - boost::system::error_code ec; - if(!boost::filesystem::is_regular_file(location.file, ec)) - return; - if(Notebook::get().open(location.file)) { - auto view = Notebook::get().get_current_view(); - view->place_cursor_at_line_offset(location.range.start.line, location.range.start.character); - view->scroll_to_cursor_delayed(true, false); - } - }; - - if(view) - view->hide_tooltips(); - SelectionDialog::get()->show(); -} - std::pair Project::Clang::get_run_arguments() { auto build_path = build->get_default_path(); if(build_path.empty()) diff --git a/src/project.hpp b/src/project.hpp index 6503d1d..942c5a7 100644 --- a/src/project.hpp +++ b/src/project.hpp @@ -59,7 +59,7 @@ namespace Project { virtual void compile_and_run(); virtual void recreate_build(); - virtual void show_symbols(); + void show_symbols(); virtual std::pair debug_get_run_arguments(); virtual Project::DebugOptions *debug_get_options() { return nullptr; } @@ -105,7 +105,6 @@ namespace Project { class LanguageProtocol : public virtual Base { public: virtual std::string get_language_id() = 0; - void show_symbols() override; }; class Clang : public LLDB {