Browse Source

Added support for Go projects

merge-requests/404/merge
eidheim 5 years ago
parent
commit
9c8f105780
  1. 2
      README.md
  2. 23
      docs/language_servers.md
  3. 30
      src/project.cpp
  4. 9
      src/project.hpp
  5. 6
      src/project_build.cpp
  6. 5
      src/project_build.hpp
  7. 12
      src/source_base.cpp

2
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 `[language identifier]-language-server` executable is found. This executable can be a symbolic
link to one of your installed language server binaries. link to one of your installed language server binaries.
- For additional instructions, see: [setup of tested language servers](docs/language_servers.md) - 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 - Git support through libgit2
- Find symbol through Ctags ([Universal Ctags](https://github.com/universal-ctags/ctags) is - Find symbol through Ctags ([Universal Ctags](https://github.com/universal-ctags/ctags) is
recommended) recommended)

23
docs/language_servers.md

@ -1,5 +1,11 @@
# Setup of tested language servers # Setup of tested language servers
- [JavaScript/TypeScript](#javascripttypescript)
- [Python3](#python3)
- [Rust](#rust)
- [Go](#go)
- [GLSL](#glsl)
## JavaScript/TypeScript ## JavaScript/TypeScript
### JavaScript with Flow static type checker ### 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: - Additional setup within a Rust project:
- Add an empty `.rustfmt.toml` file to enable style format on save - 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 ## GLSL
Install language server, and create a script to enable server in juCi++: Install language server, and create a script to enable server in juCi++:

30
src/project.cpp

@ -182,6 +182,8 @@ std::shared_ptr<Project::Base> Project::create() {
return std::shared_ptr<Project::Base>(new Project::Python(std::move(build))); return std::shared_ptr<Project::Base>(new Project::Python(std::move(build)));
if(language_id == "html") if(language_id == "html")
return std::shared_ptr<Project::Base>(new Project::HTML(std::move(build))); return std::shared_ptr<Project::Base>(new Project::HTML(std::move(build)));
if(language_id == "go")
return std::shared_ptr<Project::Base>(new Project::Go(std::move(build)));
} }
} }
else else
@ -195,6 +197,8 @@ std::shared_ptr<Project::Base> Project::create() {
return std::shared_ptr<Project::Base>(new Project::JavaScript(std::move(build))); return std::shared_ptr<Project::Base>(new Project::JavaScript(std::move(build)));
if(dynamic_cast<PythonMain *>(build.get())) if(dynamic_cast<PythonMain *>(build.get()))
return std::shared_ptr<Project::Base>(new Project::Python(std::move(build))); return std::shared_ptr<Project::Base>(new Project::Python(std::move(build)));
if(dynamic_cast<GoBuild *>(build.get()))
return std::shared_ptr<Project::Base>(new Project::Go(std::move(build)));
return std::shared_ptr<Project::Base>(new Project::Base(std::move(build))); return std::shared_ptr<Project::Base>(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<GoBuild *>(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");
});
}

9
src/project.hpp

@ -162,6 +162,15 @@ namespace Project {
std::string get_language_id() override { return "rust"; } std::string get_language_id() override { return "rust"; }
}; };
class Go : public LanguageProtocol {
public:
Go(std::unique_ptr<Build> &&build) : Base(std::move(build)) {}
void compile_and_run() override;
std::string get_language_id() override { return "go"; }
};
std::shared_ptr<Base> create(); std::shared_ptr<Base> create();
extern std::shared_ptr<Base> current; extern std::shared_ptr<Base> current;
}; // namespace Project }; // namespace Project

6
src/project_build.cpp

@ -52,6 +52,12 @@ std::unique_ptr<Project::Build> Project::Build::create(const boost::filesystem::
return build; return build;
} }
if(boost::filesystem::exists(search_path / "go.mod", ec)) {
std::unique_ptr<Project::Build> build(new GoBuild());
build->project_path = search_path;
return build;
}
if(search_path == search_path.root_directory()) if(search_path == search_path.root_directory())
break; break;
search_path = search_path.parent_path(); search_path = search_path.parent_path();

5
src/project_build.hpp

@ -72,10 +72,11 @@ namespace Project {
}; };
class NpmBuild : public Build { class NpmBuild : public Build {
public:
}; };
class PythonMain : public Build { class PythonMain : public Build {
public: };
class GoBuild : public Build {
}; };
} // namespace Project } // namespace Project

12
src/source_base.cpp

@ -287,15 +287,19 @@ Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib:
is_bracket_language = true; 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
set_tab_width(4); //Visual size of a \t hardcoded to be equal to visual size of 4 spaces. Buggy on OS X
#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")) { if(language) {
if(language->get_id() == "python" || language->get_id() == "rust") {
tab_char = ' '; tab_char = ' ';
tab_size = 4; tab_size = 4;
} }
else if(language->get_id() == "go") {
tab_char = '\t';
tab_size = 1;
}
}
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) {

Loading…
Cancel
Save