Skip to content

Commit 70b4ecf

Browse files
authored
Merge pull request #17624 from github/aibaars/rust-comments
Rust: extract comments
2 parents d0831eb + 938e962 commit 70b4ecf

File tree

29 files changed

+745
-155
lines changed

29 files changed

+745
-155
lines changed

rust/extractor/src/generated/.generated.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/extractor/src/generated/top.rs

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/extractor/src/translate/base.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use crate::trap::{DiagnosticSeverity, TrapFile};
1+
use crate::generated::{self, AstNode};
2+
use crate::trap::{DiagnosticSeverity, TrapFile, TrapId};
23
use crate::trap::{Label, TrapClass};
34
use codeql_extractor::trap::{self};
45
use ra_ap_ide_db::line_index::{LineCol, LineIndex};
6+
use ra_ap_parser::SyntaxKind;
57
use ra_ap_syntax::ast::RangeItem;
6-
use ra_ap_syntax::{ast, SyntaxError, TextRange};
8+
use ra_ap_syntax::{ast, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxToken, TextRange};
79
pub trait TextValue {
810
fn try_get_text(&self) -> Option<String>;
911
}
@@ -87,10 +89,14 @@ impl Translator {
8789
let end = self.line_index.line_col(range_end);
8890
(start, end)
8991
}
90-
pub fn emit_location<T: TrapClass>(&mut self, label: Label<T>, node: impl ast::AstNode) {
92+
pub fn emit_location<T: TrapClass>(&mut self, label: Label<T>, node: &impl ast::AstNode) {
9193
let (start, end) = self.location(node.syntax().text_range());
9294
self.trap.emit_location(self.label, label, start, end)
9395
}
96+
pub fn emit_location_token(&mut self, label: Label<generated::Token>, token: &SyntaxToken) {
97+
let (start, end) = self.location(token.text_range());
98+
self.trap.emit_location(self.label, label, start, end)
99+
}
94100
pub fn emit_parse_error(&mut self, path: &str, err: SyntaxError) {
95101
let (start, end) = self.location(err.range());
96102
log::warn!("{}:{}:{}: {}", path, start.line + 1, start.col + 1, err);
@@ -104,4 +110,18 @@ impl Translator {
104110
location,
105111
);
106112
}
113+
pub fn emit_tokens(&mut self, parent: Label<AstNode>, children: SyntaxElementChildren) {
114+
for child in children {
115+
if let NodeOrToken::Token(token) = child {
116+
if token.kind() == SyntaxKind::COMMENT {
117+
let label = self.trap.emit(generated::Comment {
118+
id: TrapId::Star,
119+
parent,
120+
text: token.text().to_owned(),
121+
});
122+
self.emit_location_token(label.into(), &token);
123+
}
124+
}
125+
}
126+
}
107127
}

0 commit comments

Comments
 (0)