Browse Source

Added cancellation dialog to rust-analyzer installation

pipelines/353213535
eidheim 4 years ago
parent
commit
a0a587b8fd
  1. 18
      src/notebook.cpp

18
src/notebook.cpp

@ -1,5 +1,6 @@
#include "notebook.hpp" #include "notebook.hpp"
#include "config.hpp" #include "config.hpp"
#include "dialog.hpp"
#include "filesystem.hpp" #include "filesystem.hpp"
#include "project.hpp" #include "project.hpp"
#include "selection_dialog.hpp" #include "selection_dialog.hpp"
@ -198,12 +199,22 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
dialog.set_default_response(Gtk::RESPONSE_YES); dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.set_secondary_text("Would you like to install rust-analyzer through rustup?"); dialog.set_secondary_text("Would you like to install rust-analyzer through rustup?");
int result = dialog.run(); int result = dialog.run();
dialog.hide();
if(result == Gtk::RESPONSE_YES) { if(result == Gtk::RESPONSE_YES) {
bool canceled = false;
Dialog::Message message("Installing rust-analyzer", [&canceled] {
canceled = true;
});
boost::optional<int> exit_status; boost::optional<int> exit_status;
Terminal::get().async_process(std::string(command), "", [&exit_status](int exit_status_) { auto process = Terminal::get().async_process(std::string(command), "", [&exit_status](int exit_status_) {
exit_status = exit_status_; exit_status = exit_status_;
}); });
bool killed = false;
while(!exit_status) { while(!exit_status) {
if(canceled && !killed) {
process->kill();
killed = true;
}
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(); Gtk::Main::iteration();
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
@ -220,16 +231,17 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
first = false; first = false;
std::stringstream stdin_stream, stdout_stream; std::stringstream stdin_stream, stdout_stream;
if(Terminal::get().process(stdin_stream, stdout_stream, "rustup component list") == 0) { if(Terminal::get().process(stdin_stream, stdout_stream, "rustup component list") == 0) {
bool rust_analyzer_in_toolchain = false;
std::string line; std::string line;
while(std::getline(stdout_stream, line)) { while(std::getline(stdout_stream, line)) {
if(starts_with(line, "rust-analyzer")) { 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"))) 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()))); source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(rust_analyzer.string())));
rust_analyzer_in_toolchain = true;
break; break;
} }
} }
if(source_views_previous_size == source_views.size() && if(!rust_analyzer_in_toolchain && install_rust_analyzer("rustup component add rust-src && rustup toolchain install nightly && rustup component add --toolchain nightly rust-src rust-analyzer-preview"))
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")); source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, "rustup run nightly rust-analyzer"));
} }
} }

Loading…
Cancel
Save