Skip to content

Commit 100bc9f

Browse files
authored
Merge pull request #826 from dtolnay-contrib/procmacro
2 parents da0bdce + 5d52ff9 commit 100bc9f

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

compiler/base/modify-cargo-toml/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,20 @@ fn set_crate_type(cargo_toml: Value, crate_type: &str) -> Value {
114114
#[derive(Debug, Default, Serialize, Deserialize)]
115115
#[serde(rename_all = "kebab-case")]
116116
struct Lib {
117-
#[serde(default)]
117+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
118118
crate_type: Vec<String>,
119+
#[serde(default)]
120+
proc_macro: bool,
119121
#[serde(flatten)]
120122
other: Other,
121123
}
122124

123125
modify(cargo_toml, |mut cargo_toml: CargoToml| {
124-
ensure_string_in_vec(&mut cargo_toml.lib.crate_type, crate_type);
126+
if crate_type == "proc-macro" {
127+
cargo_toml.lib.proc_macro = true;
128+
} else {
129+
ensure_string_in_vec(&mut cargo_toml.lib.crate_type, crate_type);
130+
}
125131
cargo_toml
126132
})
127133
}

tests/Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ GEM
2222
matrix (0.4.2)
2323
mini_mime (1.1.2)
2424
mini_portile2 (2.8.0)
25-
nokogiri (1.13.6)
25+
nokogiri (1.13.7)
2626
mini_portile2 (~> 2.8.0)
2727
racc (~> 1.4)
2828
public_suffix (4.0.7)
2929
racc (1.6.0)
30-
rack (2.2.3.1)
31-
rack-test (1.1.0)
32-
rack (>= 1.0, < 3)
33-
regexp_parser (2.4.0)
30+
rack (2.2.4)
31+
rack-test (2.0.2)
32+
rack (>= 1.3)
33+
regexp_parser (2.5.0)
3434
rexml (3.2.5)
3535
rspec (3.11.0)
3636
rspec-core (~> 3.11.0)
@@ -46,7 +46,7 @@ GEM
4646
rspec-support (~> 3.11.0)
4747
rspec-support (3.11.0)
4848
rubyzip (2.3.2)
49-
selenium-webdriver (4.2.0)
49+
selenium-webdriver (4.3.0)
5050
childprocess (>= 0.5, < 5.0)
5151
rexml (~> 3.2, >= 3.2.5)
5252
rubyzip (>= 1.2.2, < 3.0)

tests/spec/features/automatic_primary_action_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@
3232
end
3333
end
3434

35+
scenario "when the crate is a procedural macro" do
36+
editor.set <<~EOF
37+
#![crate_type = "proc-macro"]
38+
39+
use proc_macro::TokenStream;
40+
41+
/// Example:
42+
/// ```
43+
/// playground::demo!();
44+
/// type T = aaa;
45+
/// ```
46+
#[proc_macro]
47+
pub fn demo(_input: TokenStream) -> TokenStream {
48+
eprintln!("wow wow");
49+
"struct Aaa;".parse().unwrap()
50+
}
51+
52+
/*
53+
#[test]*/
54+
EOF
55+
click_on("Test")
56+
57+
within(:output, :stdout) do
58+
expect(page).to have_content 'a struct with a similar name exists: `Aaa`'
59+
end
60+
end
61+
3562
scenario "when the crate is a library with tests" do
3663
editor.set <<~EOF
3764
#![crate_type="lib"]

ui/frontend/selectors/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const autoPrimaryActionSelector = createSelector(
2121
hasTestsSelector,
2222
hasMainFunctionSelector,
2323
(crateType, hasTests, hasMainFunction) => {
24-
if (crateType) {
24+
if (crateType && crateType !== 'proc-macro') {
2525
if (crateType === 'bin') {
2626
return PrimaryActionCore.Execute;
2727
} else {
@@ -43,9 +43,19 @@ export const runAsTest = createSelector(
4343
autoPrimaryActionSelector,
4444
primaryAction => primaryAction === PrimaryActionCore.Test,
4545
);
46+
4647
export const getCrateType = createSelector(
48+
crateTypeSelector,
4749
autoPrimaryActionSelector,
48-
primaryAction => primaryAction === PrimaryActionCore.Execute ? 'bin' : 'lib',
50+
(crateType, primaryAction) => {
51+
if (crateType) {
52+
return crateType;
53+
} else if (primaryAction === PrimaryActionCore.Execute) {
54+
return 'bin';
55+
} else {
56+
return 'lib';
57+
}
58+
},
4959
);
5060

5161
const rawPrimaryActionSelector = (state: State) => state.configuration.primaryAction;

0 commit comments

Comments
 (0)