diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index 8b9a4649e4bb1c93f165cab4e32b16f2982dff59..13a4cec85ff8554cd14cb835a4320662f79a41d4 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -635,6 +635,22 @@ impl ContextProvider for GoContextProvider { cwd: package_cwd.clone(), ..TaskTemplate::default() }, + TaskTemplate { + label: format!( + "go test {} -run {}", + GO_PACKAGE_TASK_VARIABLE.template_value(), + VariableName::Symbol.template_value(), + ), + command: "go".into(), + args: vec![ + "test".into(), + "-run".into(), + format!("\\^{}\\$", VariableName::Symbol.template_value(),), + ], + tags: vec!["go-example".to_owned()], + cwd: package_cwd.clone(), + ..TaskTemplate::default() + }, TaskTemplate { label: format!("go test {}", GO_PACKAGE_TASK_VARIABLE.template_value()), command: "go".into(), @@ -992,6 +1008,43 @@ mod tests { ); } + #[gpui::test] + fn test_go_example_test_detection(cx: &mut TestAppContext) { + let language = language("go", tree_sitter_go::LANGUAGE.into()); + + let example_test = r#" + package main + + import "fmt" + + func Example() { + fmt.Println("Hello, world!") + // Output: Hello, world! + } + "#; + + let buffer = + cx.new(|cx| crate::Buffer::local(example_test, cx).with_language(language.clone(), cx)); + cx.executor().run_until_parked(); + + let runnables: Vec<_> = buffer.update(cx, |buffer, _| { + let snapshot = buffer.snapshot(); + snapshot.runnable_ranges(0..example_test.len()).collect() + }); + + let tag_strings: Vec = runnables + .iter() + .flat_map(|r| &r.runnable.tags) + .map(|tag| tag.0.to_string()) + .collect(); + + assert!( + tag_strings.contains(&"go-example".to_string()), + "Should find go-example tag, found: {:?}", + tag_strings + ); + } + #[gpui::test] fn test_go_table_test_slice_detection(cx: &mut TestAppContext) { let language = language("go", tree_sitter_go::LANGUAGE.into()); diff --git a/crates/languages/src/go/runnables.scm b/crates/languages/src/go/runnables.scm index 15fafa11cb2ceae9e9a911edaecb700ab69cb5a6..d3002a06cce9f3a12456eca438ddc6cdbb0233a5 100644 --- a/crates/languages/src/go/runnables.scm +++ b/crates/languages/src/go/runnables.scm @@ -71,6 +71,15 @@ (#set! tag go-subtest) ) +; Functions names start with `Example` +( + ( + (function_declaration name: (_) @run @_name + (#match? @_name "^Example.*")) + ) @_ + (#set! tag go-example) +) + ; Functions names start with `Benchmark` ( (