Skip to content

Commit e417c3b

Browse files
committed
Rust: Preserve documentation comment extraction
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a04d83d9-ceea-4109-8ce1-f420585125d4
1 parent 1abee71 commit e417c3b

11 files changed

Lines changed: 24 additions & 13 deletions

File tree

‎rust/extractor/src/translate/base.rs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,14 @@ impl<'db> Translator<'db> {
351351
children: SyntaxElementChildren,
352352
) {
353353
for child in children {
354-
if let NodeOrToken::Token(token) = child
355-
&& token.kind() == SyntaxKind::COMMENT
356-
{
354+
let token = match child {
355+
NodeOrToken::Token(token) if token.kind() == SyntaxKind::COMMENT => Some(token),
356+
NodeOrToken::Node(node) if node.kind() == SyntaxKind::DOC_COMMENT => {
357+
node.first_token()
358+
}
359+
_ => None,
360+
};
361+
if let Some(token) = token {
357362
let label = self.trap.emit(generated::Comment {
358363
id: TrapId::Star,
359364
parent: parent_label,

‎rust/ql/.generated.list‎

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

‎rust/ql/lib/codeql/rust/elements/Comment.qll‎

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

‎rust/ql/lib/codeql/rust/elements/internal/CommentImpl.qll‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Impl {
1717
* ```rust
1818
* // this is a comment
1919
* /// This is a doc comment
20+
* fn documented() {}
2021
* ```
2122
*/
2223
class Comment extends Generated::Comment {

‎rust/ql/lib/codeql/rust/elements/internal/generated/Comment.qll‎

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

‎rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll‎

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

‎rust/ql/test/extractor-tests/crate_graph/crates.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ main.rs:
104104
#-----| Crate(proc_macro@0.0.0)
105105
#-----| core -> Crate(core@0.0.0)
106106
#-----| std -> Crate(std@0.0.0)
107-
#-----| rustc_literal_escaper -> Crate(rustc_literal_escaper@0.0.7)
107+
#-----| rustc_literal_escaper -> Crate(rustc_literal_escaper@0.0.8)
108108

109109
#-----| Crate(rand@0.9.2)
110110
#-----| rand_core -> Crate(rand_core@0.9.3)
@@ -117,7 +117,7 @@ main.rs:
117117
#-----| Crate(rustc_demangle@0.1.27)
118118
#-----| core -> Crate(core@0.0.0)
119119

120-
#-----| Crate(rustc_literal_escaper@0.0.7)
120+
#-----| Crate(rustc_literal_escaper@0.0.8)
121121
#-----| core -> Crate(core@0.0.0)
122122

123123
#-----| Crate(std@0.0.0)

‎rust/ql/test/extractor-tests/generated/.generated_tests.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.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| comments.rs:1:1:3:2 | /**...*/ | getParent: | comments.rs:1:1:9:1 | fn foo | getText: | /** \n* A doc comment\n*/ |
22
| comments.rs:6:17:6:34 | //... | getParent: | comments.rs:6:17:8:16 | fn nested | getText: | // print some text |
33
| comments.rs:7:3:7:31 | ///... | getParent: | comments.rs:6:17:8:16 | fn nested | getText: | /// This is a nested function |
4-
| gen_comment.rs:1:1:1:36 | //... | getParent: | gen_comment.rs:1:1:7:2 | SourceFile | getText: | // generated by codegen, do not edit |
5-
| gen_comment.rs:4:5:4:30 | //... | getParent: | gen_comment.rs:3:25:7:1 | StmtList | getText: | // A comment. For example: |
6-
| gen_comment.rs:5:5:5:24 | //... | getParent: | gen_comment.rs:3:25:7:1 | StmtList | getText: | // this is a comment |
7-
| gen_comment.rs:6:5:6:29 | ///... | getParent: | gen_comment.rs:3:25:7:1 | StmtList | getText: | /// This is a doc comment |
4+
| gen_comment.rs:1:1:1:36 | //... | getParent: | gen_comment.rs:1:1:8:2 | SourceFile | getText: | // generated by codegen, do not edit |
5+
| gen_comment.rs:4:5:4:30 | //... | getParent: | gen_comment.rs:4:5:7:22 | fn documented | getText: | // A comment. For example: |
6+
| gen_comment.rs:5:5:5:24 | //... | getParent: | gen_comment.rs:4:5:7:22 | fn documented | getText: | // this is a comment |
7+
| gen_comment.rs:6:5:6:29 | ///... | getParent: | gen_comment.rs:4:5:7:22 | fn documented | getText: | /// This is a doc comment |

‎rust/ql/test/extractor-tests/generated/Comment/gen_comment.rs‎

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

0 commit comments

Comments
 (0)