|
|
|
@ -89,7 +89,6 @@ Notebook::Notebook() : Gtk::Paned(), notebooks(2) { |
|
|
|
env = c_env; |
|
|
|
env = c_env; |
|
|
|
Glib::setenv("PATH", !env.empty() ? env + delimiter + cargo_bin.string() : cargo_bin.string()); |
|
|
|
Glib::setenv("PATH", !env.empty() ? env + delimiter + cargo_bin.string() : cargo_bin.string()); |
|
|
|
filesystem::rust_sysroot_path = {}; |
|
|
|
filesystem::rust_sysroot_path = {}; |
|
|
|
filesystem::rust_nightly_sysroot_path = {}; |
|
|
|
|
|
|
|
filesystem::executable_search_paths = {}; |
|
|
|
filesystem::executable_search_paths = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -201,31 +200,28 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position |
|
|
|
else if(language && !language_protocol_language_id.empty() && !filesystem::find_executable(language_protocol_language_id + "-language-server").empty()) |
|
|
|
else if(language && !language_protocol_language_id.empty() && !filesystem::find_executable(language_protocol_language_id + "-language-server").empty()) |
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(language_protocol_language_id + "-language-server"))); |
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(language_protocol_language_id + "-language-server"))); |
|
|
|
else if(language && language_protocol_language_id == "rust") { |
|
|
|
else if(language && language_protocol_language_id == "rust") { |
|
|
|
if(!filesystem::find_executable("rust-analyzer").empty()) |
|
|
|
|
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, "rust-analyzer")); |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
if(filesystem::find_executable("rustup").empty()) |
|
|
|
if(filesystem::find_executable("rustup").empty()) |
|
|
|
install_rust(); |
|
|
|
install_rust(); |
|
|
|
if(!filesystem::find_executable("rustup").empty()) { |
|
|
|
if(!filesystem::find_executable("rustup").empty()) { |
|
|
|
// Try find rust-analyzer installed with rustup
|
|
|
|
static auto rust_analyzer_installed = []() -> bool { |
|
|
|
auto sysroot = filesystem::get_rust_sysroot_path(); |
|
|
|
std::stringstream stdin_stream, stdout_stream; |
|
|
|
if(!sysroot.empty()) { |
|
|
|
auto exit_status = Terminal::get().process(stdin_stream, stdout_stream, "rustup component list --installed"); |
|
|
|
auto rust_analyzer = sysroot / "bin" / "rust-analyzer"; |
|
|
|
if(exit_status != 0) |
|
|
|
if(filesystem::is_executable(rust_analyzer)) |
|
|
|
return false; |
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(rust_analyzer.string()))); |
|
|
|
std::string line; |
|
|
|
else { |
|
|
|
while(std::getline(stdout_stream, line)) { |
|
|
|
// Workaround while rust-analyzer is in nightly toolchain only
|
|
|
|
if(starts_with(line, "rust-analyzer")) |
|
|
|
auto nightly_sysroot = filesystem::get_rust_nightly_sysroot_path(); |
|
|
|
return true; |
|
|
|
if(!nightly_sysroot.empty()) { |
|
|
|
|
|
|
|
auto nightly_rust_analyzer = nightly_sysroot / "bin" / "rust-analyzer"; |
|
|
|
|
|
|
|
if(filesystem::is_executable(nightly_rust_analyzer)) |
|
|
|
|
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument(nightly_rust_analyzer.string()))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}(); |
|
|
|
|
|
|
|
if(rust_analyzer_installed) |
|
|
|
|
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument((filesystem::get_rust_sysroot_path() / "bin" / "rust-analyzer").string()))); |
|
|
|
if(source_views_previous_size == source_views.size()) { |
|
|
|
if(source_views_previous_size == source_views.size()) { |
|
|
|
|
|
|
|
static bool show_dialog = true; |
|
|
|
|
|
|
|
if(show_dialog) { |
|
|
|
|
|
|
|
show_dialog = false; |
|
|
|
// Install rust-analyzer
|
|
|
|
// Install rust-analyzer
|
|
|
|
auto install_rust_analyzer = [this](const std::string &command, bool &show_dialog) { |
|
|
|
|
|
|
|
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); |
|
|
|
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); |
|
|
|
Gtk::Image image; |
|
|
|
Gtk::Image image; |
|
|
|
image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); |
|
|
|
image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); |
|
|
|
@ -241,7 +237,7 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position |
|
|
|
canceled = true; |
|
|
|
canceled = true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
boost::optional<int> exit_status; |
|
|
|
boost::optional<int> exit_status; |
|
|
|
|
|
|
|
std::string command = "rustup component add rust-analyzer"; |
|
|
|
Terminal::get().print("\e[2mRunning: " + command + "\e[m\n"); |
|
|
|
Terminal::get().print("\e[2mRunning: " + command + "\e[m\n"); |
|
|
|
auto process = Terminal::get().async_process(command, "", [&exit_status](int exit_status_) { |
|
|
|
auto process = Terminal::get().async_process(command, "", [&exit_status](int exit_status_) { |
|
|
|
exit_status = exit_status_; |
|
|
|
exit_status = exit_status_; |
|
|
|
@ -259,32 +255,8 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position |
|
|
|
} |
|
|
|
} |
|
|
|
if(exit_status == 0) { |
|
|
|
if(exit_status == 0) { |
|
|
|
Terminal::get().print("\e[32mSuccess\e[m: installed rust-analyzer\n"); |
|
|
|
Terminal::get().print("\e[32mSuccess\e[m: installed rust-analyzer\n"); |
|
|
|
return true; |
|
|
|
rust_analyzer_installed = true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
static bool show_dialog = true; |
|
|
|
|
|
|
|
if(show_dialog) { |
|
|
|
|
|
|
|
show_dialog = false; |
|
|
|
|
|
|
|
std::stringstream stdin_stream, stdout_stream; |
|
|
|
|
|
|
|
// Workaround while rust-analyzer is called rust-analyzer-preview instead of rust-analyzer
|
|
|
|
|
|
|
|
if(Terminal::get().process(stdin_stream, stdout_stream, "rustup component list") == 0) { |
|
|
|
|
|
|
|
bool rust_analyzer_in_toolchain = false; |
|
|
|
|
|
|
|
std::string line; |
|
|
|
|
|
|
|
while(std::getline(stdout_stream, line)) { |
|
|
|
|
|
|
|
if(starts_with(line, "rust-analyzer")) { |
|
|
|
|
|
|
|
if(install_rust_analyzer(std::string("rustup component add ") + (starts_with(line, "rust-analyzer-preview") ? "rust-analyzer-preview" : "rust-analyzer"), show_dialog)) |
|
|
|
|
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument((filesystem::get_rust_sysroot_path() / "bin" / "rust-analyzer").string()))); |
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument((filesystem::get_rust_sysroot_path() / "bin" / "rust-analyzer").string()))); |
|
|
|
rust_analyzer_in_toolchain = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Workaround while rust-analyzer is in nightly toolchain only
|
|
|
|
|
|
|
|
if(!rust_analyzer_in_toolchain && install_rust_analyzer("rustup toolchain install nightly --component rust-analyzer-preview", show_dialog)) { |
|
|
|
|
|
|
|
filesystem::rust_nightly_sysroot_path = {}; |
|
|
|
|
|
|
|
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, filesystem::escape_argument((filesystem::get_rust_nightly_sysroot_path() / "bin" / "rust-analyzer").string()))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -673,7 +645,6 @@ void Notebook::install_rust() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
filesystem::rust_sysroot_path = {}; |
|
|
|
filesystem::rust_sysroot_path = {}; |
|
|
|
filesystem::rust_nightly_sysroot_path = {}; |
|
|
|
|
|
|
|
filesystem::executable_search_paths = {}; |
|
|
|
filesystem::executable_search_paths = {}; |
|
|
|
Terminal::get().print("\e[32mSuccess\e[m: installed Rust and updated PATH environment variable\n"); |
|
|
|
Terminal::get().print("\e[32mSuccess\e[m: installed Rust and updated PATH environment variable\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|