diff --git a/README.md b/README.md index 04855da..7a42658 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ See [installation guide](docs/install.md). `[language identifier]-language-server` executable is found. This executable can be a symbolic link to one of your installed language server binaries. - For additional instructions, see: [setup of tested language servers](docs/language_servers.md) -- Non-C/C++ projects are also supported, such as Python, JavaScript, and Rust projects +- Non-C/C++ projects are also supported, such as JavaScript, Python, Rust, and Go projects - Git support through libgit2 - Find symbol through Ctags ([Universal Ctags](https://github.com/universal-ctags/ctags) is recommended) diff --git a/docs/language_servers.md b/docs/language_servers.md index fbbae20..8f02af0 100644 --- a/docs/language_servers.md +++ b/docs/language_servers.md @@ -1,5 +1,11 @@ # Setup of tested language servers +- [JavaScript/TypeScript](#javascripttypescript) +- [Python3](#python3) +- [Rust](#rust) +- [Go](#go) +- [GLSL](#glsl) + ## JavaScript/TypeScript ### JavaScript with Flow static type checker @@ -87,6 +93,23 @@ ln -s ~/.cargo/bin/rust-analyzer /usr/local/bin/rust-language-server - Additional setup within a Rust project: - Add an empty `.rustfmt.toml` file to enable style format on save +## Go + +- Prerequisites: + - [Go](https://golang.org/doc/install) + - [gopls](https://github.com/golang/tools/blob/master/gopls/README.md#installation) (must be + installed) + +Create symbolic link to enable language server in juCi++: + +```sh +# Usually as root: +ln -s `which gopls` /usr/local/bin/go-language-server +``` + +- Additional setup within a Go project: + - Add an empty `.go-format` file to enable style format on save + ## GLSL Install language server, and create a script to enable server in juCi++: diff --git a/src/project.cpp b/src/project.cpp index bcac224..48dfd08 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -182,6 +182,8 @@ std::shared_ptr Project::create() { return std::shared_ptr(new Project::Python(std::move(build))); if(language_id == "html") return std::shared_ptr(new Project::HTML(std::move(build))); + if(language_id == "go") + return std::shared_ptr(new Project::Go(std::move(build))); } } else @@ -195,6 +197,8 @@ std::shared_ptr Project::create() { return std::shared_ptr(new Project::JavaScript(std::move(build))); if(dynamic_cast(build.get())) return std::shared_ptr(new Project::Python(std::move(build))); + if(dynamic_cast(build.get())) + return std::shared_ptr(new Project::Go(std::move(build))); return std::shared_ptr(new Project::Base(std::move(build))); } @@ -955,3 +959,29 @@ void Project::Rust::compile_and_run() { } }); } + +void Project::Go::compile_and_run() { + std::string command; + boost::filesystem::path path; + if(dynamic_cast(build.get())) { + command = "go run ."; + path = build->project_path; + } + else { + auto view = Notebook::get().get_current_view(); + if(!view) { + Info::get().print("No executable found"); + return; + } + command = "go run " + filesystem::escape_argument(filesystem::get_short_path(view->file_path).string()); + path = view->file_path.parent_path(); + } + + if(Config::get().terminal.clear_on_compile) + Terminal::get().clear(); + + Terminal::get().print("\e[2mRunning: " + command + "\e[m\n"); + Terminal::get().async_process(command, build->project_path, [command](int exit_status) { + Terminal::get().print("\e[2m" + command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + }); +} diff --git a/src/project.hpp b/src/project.hpp index e5e3f94..5f37798 100644 --- a/src/project.hpp +++ b/src/project.hpp @@ -162,6 +162,15 @@ namespace Project { std::string get_language_id() override { return "rust"; } }; + class Go : public LanguageProtocol { + public: + Go(std::unique_ptr &&build) : Base(std::move(build)) {} + + void compile_and_run() override; + + std::string get_language_id() override { return "go"; } + }; + std::shared_ptr create(); extern std::shared_ptr current; }; // namespace Project diff --git a/src/project_build.cpp b/src/project_build.cpp index a73cccb..6bc8f1d 100644 --- a/src/project_build.cpp +++ b/src/project_build.cpp @@ -52,6 +52,12 @@ std::unique_ptr Project::Build::create(const boost::filesystem:: return build; } + if(boost::filesystem::exists(search_path / "go.mod", ec)) { + std::unique_ptr build(new GoBuild()); + build->project_path = search_path; + return build; + } + if(search_path == search_path.root_directory()) break; search_path = search_path.parent_path(); diff --git a/src/project_build.hpp b/src/project_build.hpp index a69add0..b9ade14 100644 --- a/src/project_build.hpp +++ b/src/project_build.hpp @@ -72,10 +72,11 @@ namespace Project { }; class NpmBuild : public Build { - public: }; class PythonMain : public Build { - public: + }; + + class GoBuild : public Build { }; } // namespace Project diff --git a/src/source_base.cpp b/src/source_base.cpp index 29759c4..eaa94a5 100644 --- a/src/source_base.cpp +++ b/src/source_base.cpp @@ -287,14 +287,18 @@ Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib: is_bracket_language = true; } -#ifndef __APPLE__ - set_tab_width(4); //Visual size of a \t hardcoded to be equal to visual size of 4 spaces. Buggy on OS X -#endif + set_tab_width(4); // Visual size of a \t hardcoded to be equal to visual size of 4 spaces tab_char = Config::get().source.default_tab_char; tab_size = Config::get().source.default_tab_size; - if(language && (language->get_id() == "python" || language->get_id() == "rust")) { - tab_char = ' '; - tab_size = 4; + if(language) { + if(language->get_id() == "python" || language->get_id() == "rust") { + tab_char = ' '; + tab_size = 4; + } + else if(language->get_id() == "go") { + tab_char = '\t'; + tab_size = 1; + } } if(Config::get().source.auto_tab_char_and_size) { auto tab_char_and_size = find_tab_char_and_size();