Browse Source

Cleanup of rust-analyzer installation

pipelines/353213535
eidheim 4 years ago
parent
commit
09d569873f
  1. 75
      src/notebook.cpp

75
src/notebook.cpp

@ -191,47 +191,46 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::exists(nightly_rust_analyzer, ec)) if(boost::filesystem::exists(nightly_rust_analyzer, ec))
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(nightly_rust_analyzer.string()))); source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(nightly_rust_analyzer.string())));
else { }
auto install_rust_analyzer = [this](const std::string &command) { if(source_views_previous_size == source_views.size()) {
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install rust-analyzer (Rust language server)", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); auto install_rust_analyzer = [this](const std::string &command) {
dialog.set_default_response(Gtk::RESPONSE_YES); Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install rust-analyzer (Rust language server)", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text("Would you like to install rust-analyzer through rustup?"); dialog.set_default_response(Gtk::RESPONSE_YES);
int result = dialog.run(); dialog.set_secondary_text("Would you like to install rust-analyzer through rustup?");
if(result == Gtk::RESPONSE_YES) { int result = dialog.run();
boost::optional<int> exit_status; if(result == Gtk::RESPONSE_YES) {
Terminal::get().async_process(std::string(command), "", [&exit_status](int exit_status_) { boost::optional<int> exit_status;
exit_status = exit_status_; Terminal::get().async_process(std::string(command), "", [&exit_status](int exit_status_) {
}); exit_status = exit_status_;
while(!exit_status) { });
while(Gtk::Main::events_pending()) while(!exit_status) {
Gtk::Main::iteration(); while(Gtk::Main::events_pending())
std::this_thread::sleep_for(std::chrono::milliseconds(10)); Gtk::Main::iteration();
} std::this_thread::sleep_for(std::chrono::milliseconds(10));
if(exit_status == 0) {
Terminal::get().print("\e[32mSuccessfully\e[m installed rust-analyzer.\n");
return true;
}
} }
return false; if(exit_status == 0) {
}; Terminal::get().print("\e[32mSuccessfully\e[m installed rust-analyzer.\n");
static bool first = true; return true;
if(first && !filesystem::find_executable("rustup").empty()) { }
first = false; }
std::stringstream stdin_stream, stdout_stream; return false;
if(Terminal::get().process(stdin_stream, stdout_stream, "rustup component list") == 0) { };
std::string line; static bool first = true;
bool found = false; if(first && !filesystem::find_executable("rustup").empty()) {
while(std::getline(stdout_stream, line)) { first = false;
if(starts_with(line, "rust-analyzer")) { std::stringstream stdin_stream, stdout_stream;
if(install_rust_analyzer(std::string("rustup component add rust-src ") + (starts_with(line, "rust-analyzer-preview") ? "rust-analyzer-preview" : "rust-analyzer"))) if(Terminal::get().process(stdin_stream, stdout_stream, "rustup component list") == 0) {
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(rust_analyzer.string()))); std::string line;
found = true; while(std::getline(stdout_stream, line)) {
break; if(starts_with(line, "rust-analyzer")) {
} if(install_rust_analyzer(std::string("rustup component add rust-src ") + (starts_with(line, "rust-analyzer-preview") ? "rust-analyzer-preview" : "rust-analyzer")))
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(rust_analyzer.string())));
break;
} }
if(!found && install_rust_analyzer("rustup component add rust-src && rustup toolchain install nightly && rustup component add --toolchain nightly rust-src rust-analyzer-preview"))
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, "rustup run nightly rust-analyzer"));
} }
if(source_views_previous_size == source_views.size() &&
install_rust_analyzer("rustup component add rust-src && rustup toolchain install nightly && rustup component add --toolchain nightly rust-src rust-analyzer-preview"))
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, "rustup run nightly rust-analyzer"));
} }
} }
} }

Loading…
Cancel
Save