Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: Add support for doctest runnables #24806

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/languages/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,26 @@ impl ContextProvider for RustContextProvider {
cwd: Some("$ZED_DIRNAME".to_owned()),
..TaskTemplate::default()
},
TaskTemplate {
label: format!(
"DocTest '{}' (package: {})",
VariableName::Symbol.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(),
),
command: "cargo".into(),
args: vec![
"test".into(),
"--doc".into(),
"-p".into(),
RUST_PACKAGE_TASK_VARIABLE.template_value(),
VariableName::Symbol.template_value(),
"--".into(),
"--nocapture".into(),
],
tags: vec!["rust-doc-test".to_owned()],
cwd: Some("$ZED_DIRNAME".to_owned()),
..TaskTemplate::default()
},
TaskTemplate {
label: format!(
"Test '{}' (package: {})",
Expand Down
42 changes: 41 additions & 1 deletion crates/languages/src/rust/runnables.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

; Rust mod test
(
(mod_item
name: (_) @run
Expand All @@ -7,6 +7,7 @@
(#set! tag rust-mod-test)
)

; Rust test
(
(
(attribute_item (attribute
Expand All @@ -28,6 +29,45 @@
(#set! tag rust-test)
)

; Rust doc test
(
(
(line_comment) *
(line_comment
doc: (_) @_comment_content
) @start
(#match? @_comment_content "```")
(line_comment) *
(line_comment
doc: (_) @_end_comment_content
) @_end_code_block
(#match? @_end_comment_content "```")
.
(attribute_item) *
.
[(line_comment) (block_comment)] *
.
[(function_item
name: (_) @run
body: _
) (function_signature_item
name: (_) @run
) (struct_item
name: (_) @run
) (enum_item
name: (_) @run
body: _
) (
(attribute_item) ?
(macro_definition
name: (_) @run)
) (mod_item
name: (_) @run
)] @_end
)
(#set! tag rust-doc-test)
)

; Rust main function
(
(
Expand Down
Loading