1
- use crate :: trap:: { DiagnosticSeverity , TrapFile } ;
1
+ use crate :: generated:: { self , AstNode } ;
2
+ use crate :: trap:: { DiagnosticSeverity , TrapFile , TrapId } ;
2
3
use crate :: trap:: { Label , TrapClass } ;
3
4
use codeql_extractor:: trap:: { self } ;
4
5
use ra_ap_ide_db:: line_index:: { LineCol , LineIndex } ;
6
+ use ra_ap_parser:: SyntaxKind ;
5
7
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 } ;
7
9
pub trait TextValue {
8
10
fn try_get_text ( & self ) -> Option < String > ;
9
11
}
@@ -87,10 +89,14 @@ impl Translator {
87
89
let end = self . line_index . line_col ( range_end) ;
88
90
( start, end)
89
91
}
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 ) {
91
93
let ( start, end) = self . location ( node. syntax ( ) . text_range ( ) ) ;
92
94
self . trap . emit_location ( self . label , label, start, end)
93
95
}
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
+ }
94
100
pub fn emit_parse_error ( & mut self , path : & str , err : SyntaxError ) {
95
101
let ( start, end) = self . location ( err. range ( ) ) ;
96
102
log:: warn!( "{}:{}:{}: {}" , path, start. line + 1 , start. col + 1 , err) ;
@@ -104,4 +110,18 @@ impl Translator {
104
110
location,
105
111
) ;
106
112
}
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
+ }
107
127
}
0 commit comments