Skip to content

Commit af440c3

Browse files
committed
Rust: fixes
1 parent a4af05d commit af440c3

File tree

13 files changed

+2976
-175
lines changed

13 files changed

+2976
-175
lines changed

rust/ast-generator/templates/extractor.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ impl Translator<'_> {
3434
{{#nodes}}
3535

3636
pub(crate) fn emit_{{snake_case_name}}(&mut self, node: &ast::{{ast_name}}) -> Option<Label<generated::{{name}}>> {
37-
{{#has_attrs}}
3837
if self.should_be_excluded(node) { return None; }
38+
{{#has_attrs}}
39+
if self.should_be_excluded_attrs(node) { return None; }
3940
{{/has_attrs}}
4041
{{#fields}}
4142
{{#predicate}}

rust/extractor/src/diagnostics.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::config::Config;
2+
use crate::translate::SourceKind;
23
use anyhow::Context;
34
use chrono::{DateTime, Utc};
45
use ra_ap_project_model::ProjectManifest;
@@ -83,6 +84,8 @@ pub enum ExtractionStepKind {
8384
LoadSource,
8485
Parse,
8586
Extract,
87+
ParseLibrary,
88+
ExtractLibrary,
8689
CrateGraph,
8790
}
8891

@@ -113,18 +116,24 @@ impl ExtractionStep {
113116
)
114117
}
115118

116-
pub fn parse(start: Instant, target: &Path) -> Self {
119+
pub fn parse(start: Instant, source_kind: SourceKind, target: &Path) -> Self {
117120
Self::new(
118121
start,
119-
ExtractionStepKind::Parse,
122+
match source_kind {
123+
SourceKind::Source => ExtractionStepKind::Parse,
124+
SourceKind::Library => ExtractionStepKind::ParseLibrary,
125+
},
120126
Some(PathBuf::from(target)),
121127
)
122128
}
123129

124-
pub fn extract(start: Instant, target: &Path) -> Self {
130+
pub fn extract(start: Instant, source_kind: SourceKind, target: &Path) -> Self {
125131
Self::new(
126132
start,
127-
ExtractionStepKind::Extract,
133+
match source_kind {
134+
SourceKind::Source => ExtractionStepKind::Extract,
135+
SourceKind::Library => ExtractionStepKind::ExtractLibrary,
136+
},
128137
Some(PathBuf::from(target)),
129138
)
130139
}

rust/extractor/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ impl<'a> Extractor<'a> {
6363
errors,
6464
semantics_info,
6565
} = rust_analyzer.parse(file);
66-
self.steps.push(ExtractionStep::parse(before_parse, file));
66+
self.steps
67+
.push(ExtractionStep::parse(before_parse, source_kind, file));
6768

6869
let before_extract = Instant::now();
6970
let line_index = LineIndex::new(text.as_ref());
@@ -108,7 +109,7 @@ impl<'a> Extractor<'a> {
108109
)
109110
});
110111
self.steps
111-
.push(ExtractionStep::extract(before_extract, file));
112+
.push(ExtractionStep::extract(before_extract, source_kind, file));
112113
}
113114

114115
pub fn extract_with_semantics(

rust/extractor/src/translate/base.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub enum ResolvePaths {
9393
Yes,
9494
No,
9595
}
96-
#[derive(PartialEq, Eq)]
96+
#[derive(Copy, Clone, PartialEq, Eq)]
9797
pub enum SourceKind {
9898
Source,
9999
Library,
@@ -619,7 +619,17 @@ impl<'a> Translator<'a> {
619619
})();
620620
}
621621

622-
pub(crate) fn should_be_excluded(&self, item: &impl ast::HasAttrs) -> bool {
622+
pub(crate) fn should_be_excluded_attrs(&self, item: &impl ast::HasAttrs) -> bool {
623+
self.semantics.is_some_and(|sema| {
624+
item.attrs().any(|attr| {
625+
attr.as_simple_call().is_some_and(|(name, tokens)| {
626+
name == "cfg" && sema.check_cfg_attr(&tokens) == Some(false)
627+
})
628+
})
629+
})
630+
}
631+
632+
pub(crate) fn should_be_excluded(&self, item: &impl ast::AstNode) -> bool {
623633
if self.source_kind == SourceKind::Library {
624634
let syntax = item.syntax();
625635
if let Some(body) = syntax.parent().and_then(Fn::cast).and_then(|x| x.body()) {
@@ -645,13 +655,7 @@ impl<'a> Translator<'a> {
645655
}
646656
}
647657
}
648-
self.semantics.is_some_and(|sema| {
649-
item.attrs().any(|attr| {
650-
attr.as_simple_call().is_some_and(|(name, tokens)| {
651-
name == "cfg" && sema.check_cfg_attr(&tokens) == Some(false)
652-
})
653-
})
654-
})
658+
return false;
655659
}
656660

657661
pub(crate) fn extract_types_from_path_segment(

0 commit comments

Comments
 (0)