Browse Source

Added menu item File, New Project, Rust

merge-requests/404/merge
eidheim 5 years ago
parent
commit
9579c16193
  1. 2
      docs/language_servers.md
  2. 4
      src/menu.cpp
  3. 4
      src/notebook.cpp
  4. 5
      src/project.cpp
  5. 9
      src/project_build.cpp
  6. 2
      src/project_build.hpp
  7. 7
      src/source_base.cpp
  8. 14
      src/source_language_protocol.cpp
  9. 27
      src/window.cpp

2
docs/language_servers.md

@ -85,7 +85,7 @@ ln -s ~/.cargo/bin/rust-analyzer /usr/local/bin/rust-language-server
``` ```
- Additional setup within a Rust project: - Additional setup within a Rust project:
- Add an empty `.rust-format` file to enable style format on save - Add an empty `.rustfmt.toml` file to enable style format on save
## GLSL ## GLSL

4
src/menu.cpp

@ -135,6 +135,10 @@ const Glib::ustring menu_xml = R"RAW(<interface>
<attribute name='label' translatable='no'>C++</attribute> <attribute name='label' translatable='no'>C++</attribute>
<attribute name='action'>app.file_new_project_cpp</attribute> <attribute name='action'>app.file_new_project_cpp</attribute>
</item> </item>
<item>
<attribute name='label' translatable='no'>Rust</attribute>
<attribute name='action'>app.file_new_project_rust</attribute>
</item>
</submenu> </submenu>
</section> </section>
<section> <section>

4
src/notebook.cpp

@ -175,10 +175,10 @@ 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, language_protocol_language_id + "-language-server")); source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, language_protocol_language_id + "-language-server"));
else if(language && language_protocol_language_id == "rust" && !filesystem::get_rust_sysroot_path().empty()) { else if(language && language_protocol_language_id == "rust" && !filesystem::get_rust_sysroot_path().empty()) {
auto rust_analyzer = filesystem::get_rust_sysroot_path().string() + "/bin/rust-analyzer"; auto rust_analyzer = filesystem::get_rust_sysroot_path() / "bin" / "rust-analyzer";
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::exists(rust_analyzer, ec)) if(boost::filesystem::exists(rust_analyzer, ec))
source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, rust_analyzer)); source_views.emplace_back(new Source::LanguageProtocolView(file_path, language, language_protocol_language_id, rust_analyzer.string()));
else else
source_views.emplace_back(new Source::GenericView(file_path, language)); source_views.emplace_back(new Source::GenericView(file_path, language));
} }

5
src/project.cpp

@ -908,7 +908,7 @@ std::pair<std::string, std::string> Project::Rust::get_run_arguments() {
arguments = run_arguments_it->second; arguments = run_arguments_it->second;
if(arguments.empty()) if(arguments.empty())
arguments = filesystem::get_short_path(build->get_executable(project_path)).string(); arguments = filesystem::escape_argument(filesystem::get_short_path(build->get_executable(project_path)).string());
return {project_path, arguments}; return {project_path, arguments};
} }
@ -921,8 +921,7 @@ void Project::Rust::compile() {
Terminal::get().print("\e[2mCompiling project " + filesystem::get_short_path(build->project_path).string() + "\e[m\n"); Terminal::get().print("\e[2mCompiling project " + filesystem::get_short_path(build->project_path).string() + "\e[m\n");
auto command = build->get_compile_command(); Terminal::get().async_process(build->get_compile_command(), build->project_path, [](int exit_status) {
Terminal::get().async_process(command, build->project_path, [](int exit_status) {
compiling = false; compiling = false;
}); });
} }

9
src/project_build.cpp

@ -227,3 +227,12 @@ bool Project::CargoBuild::update_debug(bool force) {
std::string Project::CargoBuild::get_compile_command() { std::string Project::CargoBuild::get_compile_command() {
return Config::get().project.cargo_command + " build"; return Config::get().project.cargo_command + " build";
} }
boost::filesystem::path Project::CargoBuild::get_executable(const boost::filesystem::path &path) {
auto project_name = project_path.filename().string();
for(auto &chr : project_name) {
if(chr == ' ')
chr = '_';
}
return get_debug_path() / project_name;
}

2
src/project_build.hpp

@ -68,7 +68,7 @@ namespace Project {
bool update_debug(bool force = false) override; bool update_debug(bool force = false) override;
std::string get_compile_command() override; std::string get_compile_command() override;
boost::filesystem::path get_executable(const boost::filesystem::path &path) override { return get_debug_path() / project_path.filename(); } boost::filesystem::path get_executable(const boost::filesystem::path &path) override;
}; };
class NpmBuild : public Build { class NpmBuild : public Build {

7
src/source_base.cpp

@ -169,6 +169,10 @@ Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib:
#endif #endif
tab_char = Config::get().source.default_tab_char; tab_char = Config::get().source.default_tab_char;
tab_size = Config::get().source.default_tab_size; tab_size = Config::get().source.default_tab_size;
if(language && (language->get_id() == "python" || language->get_id() == "rust")) {
tab_char = ' ';
tab_size = 4;
}
if(Config::get().source.auto_tab_char_and_size) { if(Config::get().source.auto_tab_char_and_size) {
auto tab_char_and_size = find_tab_char_and_size(); auto tab_char_and_size = find_tab_char_and_size();
if(tab_char_and_size.second != 0) { if(tab_char_and_size.second != 0) {
@ -408,9 +412,6 @@ void Source::BaseView::check_last_write_time(boost::optional<std::time_t> last_w
} }
std::pair<char, unsigned> Source::BaseView::find_tab_char_and_size() { std::pair<char, unsigned> Source::BaseView::find_tab_char_and_size() {
if(language && language->get_id() == "python")
return {' ', 4};
std::map<char, size_t> tab_chars; std::map<char, size_t> tab_chars;
std::map<unsigned, size_t> tab_sizes; std::map<unsigned, size_t> tab_sizes;
auto iter = get_buffer()->begin(); auto iter = get_buffer()->begin();

14
src/source_language_protocol.cpp

@ -568,6 +568,20 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
style_file_search_path = style_file_search_path.parent_path(); style_file_search_path = style_file_search_path.parent_path();
} }
if(!has_style_file && language && language->get_id() == "rust") {
auto style_file_search_path = file_path.parent_path();
while(true) {
if(boost::filesystem::exists(style_file_search_path / "rustfmt.toml", ec) ||
boost::filesystem::exists(style_file_search_path / ".rustfmt.toml", ec)) {
has_style_file = true;
break;
}
if(style_file_search_path == style_file_search_path.root_directory())
break;
style_file_search_path = style_file_search_path.parent_path();
}
}
if(!has_style_file && !continue_without_style_file) if(!has_style_file && !continue_without_style_file)
return; return;
} }

27
src/window.cpp

@ -429,6 +429,33 @@ void Window::set_menu_actions() {
Terminal::get().print("\e[31mError\e[m: Could not create project " + filesystem::get_short_path(project_path).string() + "\n", true); Terminal::get().print("\e[31mError\e[m: Could not create project " + filesystem::get_short_path(project_path).string() + "\n", true);
} }
}); });
menu.add_action("file_new_project_rust", []() {
auto sysroot = filesystem::get_rust_sysroot_path();
if(sysroot.empty()) {
Terminal::get().print("\e[33mWarning\e[m: could not find Rust.\n");
Terminal::get().print("For installation instructions please visit: https://gitlab.com/cppit/jucipp/-/blob/master/docs/language_servers.md#rust.\n");
return;
}
boost::filesystem::path project_path = Dialog::new_folder(Project::get_preferably_directory_folder());
if(!project_path.empty()) {
auto project_name = project_path.filename().string();
for(auto &chr : project_name) {
if(chr == ' ')
chr = '_';
}
if(Terminal::get().process("cargo init " + filesystem::escape_argument(project_path.string()) + " --bin --vcs none --name " + project_name) == 0) {
filesystem::write(project_path / ".rustfmt.toml", "");
Directories::get().open(project_path);
Notebook::get().open(project_path / "src" / "main.rs");
Directories::get().update();
Terminal::get().print("Rust project ");
Terminal::get().print(project_path.filename().string(), true);
Terminal::get().print(" \e[32mcreated\e[m\n");
}
else
Terminal::get().print("\e[31mError\e[m: Could not create project " + filesystem::get_short_path(project_path).string() + "\n", true);
}
});
menu.add_action("file_open_file", []() { menu.add_action("file_open_file", []() {
auto path = Dialog::open_file(Project::get_preferably_view_folder()); auto path = Dialog::open_file(Project::get_preferably_view_folder());

Loading…
Cancel
Save