Skip to main content

luaur_analysis/methods/
ast_json_encoder_write_comments.rs

1//! Node: `cxx:Method:Luau.Analysis:Analysis/src/AstJsonEncoder.cpp:1519:ast_json_encoder_write_comments`
2//! Source: `Analysis/src/AstJsonEncoder.cpp` (AstJsonEncoder.cpp:1519-1552, hand-ported)
3
4use 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}