luaur_analysis/methods/
ast_json_encoder_write_comments.rs1use crate::records::ast_json_encoder::AstJsonEncoder;
5use luaur_ast::records::comment::Comment;
6use luaur_ast::records::lexeme::Type;
7
8impl AstJsonEncoder {
9 pub fn write_comments(&mut self, comment_locations: Vec<Comment>) {
10 let mut comment_comma = false;
11 for comment in comment_locations {
12 if comment_comma {
13 self.write_raw_string_view(",");
14 } else {
15 comment_comma = true;
16 }
17 self.write_raw_string_view("{");
18 let c = self.push_comma();
19 match comment.r#type {
20 Type::Comment => self.write_type_string_view("Comment"),
21 Type::BlockComment => self.write_type_string_view("BlockComment"),
22 Type::BrokenComment => self.write_type_string_view("BrokenComment"),
23 _ => {}
24 }
25 self.write("location", &comment.location);
26 self.pop_comma(c);
27 self.write_raw_string_view("}");
28 }
29 }
30}