1- use crate :: trap:: { DiagnosticSeverity , TrapFile } ;
1+ use crate :: generated:: { self , AstNode } ;
2+ use crate :: trap:: { DiagnosticSeverity , TrapFile , TrapId } ;
23use crate :: trap:: { Label , TrapClass } ;
34use codeql_extractor:: trap:: { self } ;
45use ra_ap_ide_db:: line_index:: { LineCol , LineIndex } ;
6+ use ra_ap_parser:: SyntaxKind ;
57use ra_ap_syntax:: ast:: RangeItem ;
6- use ra_ap_syntax:: { ast, SyntaxError , TextRange } ;
8+ use ra_ap_syntax:: { ast, NodeOrToken , SyntaxElementChildren , SyntaxError , SyntaxToken , TextRange } ;
79pub 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