From 8e00caf23bf0db92e45029d5cc648872de0d7a3c Mon Sep 17 00:00:00 2001 From: Roshan Padaki Date: Mon, 4 Nov 2024 04:13:15 -0500 Subject: [PATCH] go: Add `go-generate` runnables and tasks (#19987) I was missing the `go generate` runnable from other editors so I figured I'd implement one here! Now, comments of the form `//go:generate` can prompt for the `go generate ` task. Meanwhile, I've also added a global `go generate ./...` task. ~When making the global task, I noticed that the existing `go test ./...` task runs tests in subdirectories of the CWD of the active editor, whereas I would really expect it to run all tests across my project. I have changed to use the latter behavior (run relative to project root) for both `go generate ./...` and `go test ./...`. Please let me know if the prior behavior was intended, and I can revert.~ Release Notes: - Added runnable and tasks for `go generate` commands --- crates/languages/src/go.rs | 15 +++++++++++++++ crates/languages/src/go/runnables.scm | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index 135c080e00a14901a9fa46e46ba5e662a831048d..2c8649caadd5de1fd738d37d6947f1f7e5d3ca58 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -549,6 +549,21 @@ impl ContextProvider for GoContextProvider { tags: vec!["go-main".to_owned()], ..TaskTemplate::default() }, + TaskTemplate { + label: format!("go generate {}", GO_PACKAGE_TASK_VARIABLE.template_value()), + command: "go".into(), + args: vec!["generate".into()], + cwd: package_cwd.clone(), + tags: vec!["go-generate".to_owned()], + ..TaskTemplate::default() + }, + TaskTemplate { + label: "go generate ./...".into(), + command: "go".into(), + args: vec!["generate".into(), "./...".into()], + cwd: package_cwd.clone(), + ..TaskTemplate::default() + }, ])) } } diff --git a/crates/languages/src/go/runnables.scm b/crates/languages/src/go/runnables.scm index d689116007f1a4f71b31c3a1d36fd62b2255170c..eb643c448e7cd9589a430b6457cd70da4def1f6f 100644 --- a/crates/languages/src/go/runnables.scm +++ b/crates/languages/src/go/runnables.scm @@ -7,6 +7,13 @@ (#set! tag go-test) ) +; `go:generate` comments +( + ((comment) @_comment @run + (#match? @_comment "^//go:generate")) + (#set! tag go-generate) +) + ; `t.Run` ( (