Skip to content

Commit 4c563dc

Browse files
committed
chore: Update internal dprint-core version.
1 parent 2d9fe07 commit 4c563dc

4 files changed

Lines changed: 41 additions & 28 deletions

File tree

Cargo.lock

Lines changed: 25 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-jsonc"
33
description = "JSON formatter for dprint."
44
keywords = ["formatting", "formatter", "json", "jsonc"]
5-
version = "0.7.2"
5+
version = "0.7.3"
66
authors = ["David Sherret <dsherret@gmail.com>"]
77
license = "MIT"
88
edition = "2018"
@@ -24,7 +24,7 @@ panic = "abort"
2424
wasm = ["serde_json", "dprint-core/wasm"]
2525

2626
[dependencies]
27-
dprint-core = { version = "0.31.1", features = ["formatting"] }
27+
dprint-core = { version = "0.35.0", features = ["formatting"] }
2828
jsonc-parser = { version = "0.15.0" }
2929
serde = { version = "1.0.88", features = ["derive"] }
3030
serde_json = { version = "1.0", optional = true }

src/format_text.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
use dprint_core::formatting::{print, PrintOptions};
1+
use dprint_core::formatting::{PrintOptions};
22
use dprint_core::configuration::resolve_new_line_kind;
3+
use jsonc_parser::{parse_to_ast, ParseOptions};
34
use super::configuration::Configuration;
45
use super::parser::parse_items;
56

67
pub fn format_text(text: &str, config: &Configuration) -> Result<String, String> {
7-
let print_items = parse_items(text, config)?;
8+
let parse_result = parse_to_ast(text, &ParseOptions { comments: true, tokens: true });
9+
let parse_result = match parse_result {
10+
Ok(result) => result,
11+
Err(err) => return Err(dprint_core::formatting::utils::string_utils::format_diagnostic(
12+
Some((err.range.start, err.range.end)),
13+
&err.message,
14+
text
15+
)),
16+
};
817

9-
Ok(print(print_items, PrintOptions {
18+
Ok(dprint_core::formatting::format(|| parse_items(parse_result, text, config), PrintOptions {
1019
indent_width: config.indent_width,
1120
max_width: config.line_width,
1221
use_tabs: config.use_tabs,

src/parser/parse.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
use std::collections::HashSet;
22
use dprint_core::formatting::*;
3-
use jsonc_parser::{parse_to_ast, ParseOptions};
43
use jsonc_parser::ast::*;
54
use jsonc_parser::common::{Position, Ranged, Range};
65
use jsonc_parser::tokens::{TokenAndRange};
76
use super::super::configuration::Configuration;
87
use super::context::Context;
98
use super::token_finder::TokenFinder;
109

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 {
2111
let comments = parse_result.comments.unwrap();
2212
let tokens = parse_result.tokens.unwrap();
2313
let node_value = parse_result.value;
@@ -46,7 +36,7 @@ pub fn parse_items(text: &str, config: &Configuration) -> Result<PrintItems, Str
4636
Signal::NewLine.into()
4737
));
4838

49-
Ok(items)
39+
items
5040
}
5141

5242
fn parse_node<'a>(node: Node<'a>, context: &mut Context<'a>) -> PrintItems {

0 commit comments

Comments
 (0)