|
1 | 1 | use std::collections::HashSet; |
2 | 2 | use dprint_core::formatting::*; |
3 | | -use jsonc_parser::{parse_to_ast, ParseOptions}; |
4 | 3 | use jsonc_parser::ast::*; |
5 | 4 | use jsonc_parser::common::{Position, Ranged, Range}; |
6 | 5 | use jsonc_parser::tokens::{TokenAndRange}; |
7 | 6 | use super::super::configuration::Configuration; |
8 | 7 | use super::context::Context; |
9 | 8 | use super::token_finder::TokenFinder; |
10 | 9 |
|
11 | | -pub fn parse_items(text: &str, config: &Configuration) -> Result<PrintItems, String> { |
12 | | - let parse_result = parse_to_ast(text, &ParseOptions { comments: true, tokens: true }); |
13 | | - let parse_result = match parse_result { |
14 | | - Ok(result) => result, |
15 | | - Err(err) => return Err(dprint_core::formatting::utils::string_utils::format_diagnostic( |
16 | | - Some((err.range.start, err.range.end)), |
17 | | - &err.message, |
18 | | - text |
19 | | - )), |
20 | | - }; |
| 10 | +pub fn parse_items(parse_result: jsonc_parser::ParseResult, text: &str, config: &Configuration) -> PrintItems { |
21 | 11 | let comments = parse_result.comments.unwrap(); |
22 | 12 | let tokens = parse_result.tokens.unwrap(); |
23 | 13 | let node_value = parse_result.value; |
@@ -46,7 +36,7 @@ pub fn parse_items(text: &str, config: &Configuration) -> Result<PrintItems, Str |
46 | 36 | Signal::NewLine.into() |
47 | 37 | )); |
48 | 38 |
|
49 | | - Ok(items) |
| 39 | + items |
50 | 40 | } |
51 | 41 |
|
52 | 42 | fn parse_node<'a>(node: Node<'a>, context: &mut Context<'a>) -> PrintItems { |
|
0 commit comments