Skip to content

Commit

Permalink
refactor: upgrade to dprint-core 0.49
Browse files Browse the repository at this point in the history
dsherret committed Dec 10, 2021
1 parent f7c34ec commit d56d35d
Showing 9 changed files with 100 additions and 99 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,11 +25,12 @@ wasm = ["serde_json", "dprint-core/wasm"]
tracing = ["dprint-core/tracing"]

[dependencies]
anyhow = "1.0.51"
dockerfile-parser = { git = "https://github.com/dsherret/dockerfile-parser-rs", branch = "span-for-nodes" }
dprint-core = { version = "0.47.1", features = ["formatting"] }
dprint-core = { version = "0.49.0", features = ["formatting"] }
serde = { version = "1.0.88", features = ["derive"] }
serde_json = { version = "1.0", optional = true }

[dev-dependencies]
dprint-development = "0.4.1"
dprint-development = "0.5.0"
serde_json = { version = "1.0" }
12 changes: 6 additions & 6 deletions src/format_text.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use anyhow::Result;
use dockerfile_parser::Dockerfile;
use dprint_core::configuration::resolve_new_line_kind;
use dprint_core::formatting::PrintOptions;
use dprint_core::types::ErrBox;
use std::path::Path;

use crate::configuration::Configuration;
use crate::parser::parse_items;
use crate::generation::generate;

pub fn format_text(_file_path: &Path, text: &str, config: &Configuration) -> Result<String, ErrBox> {
pub fn format_text(_file_path: &Path, text: &str, config: &Configuration) -> Result<String> {
let node = parse_node(text)?;

Ok(dprint_core::formatting::format(
|| parse_items(&node, text, config),
|| generate(&node, text, config),
config_to_print_options(text, config),
))
}
@@ -20,10 +20,10 @@ pub fn format_text(_file_path: &Path, text: &str, config: &Configuration) -> Res
pub fn trace_file(_file_path: &Path, text: &str, config: &Configuration) -> dprint_core::formatting::TracingResult {
let node = parse_node(text).unwrap();

dprint_core::formatting::trace_printing(|| parse_items(node, text, config), config_to_print_options(text, config))
dprint_core::formatting::trace_printing(|| generate(node, text, config), config_to_print_options(text, config))
}

fn parse_node(text: &str) -> Result<Dockerfile, ErrBox> {
fn parse_node(text: &str) -> Result<Dockerfile> {
Ok(Dockerfile::parse(text)?)
}

6 changes: 3 additions & 3 deletions src/parser/context.rs → src/generation/context.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ pub struct Context<'a> {
pub handled_comments: HashSet<usize>,
current_node: Option<Node<'a>>,
parent_stack: Vec<Node<'a>>,
pub parse_string_content: bool,
pub gen_string_content: bool,
}

impl<'a> Context<'a> {
@@ -27,7 +27,7 @@ impl<'a> Context<'a> {
handled_comments: HashSet::new(),
current_node: None,
parent_stack: Vec::new(),
parse_string_content: false,
gen_string_content: false,
}
}

@@ -50,7 +50,7 @@ impl<'a> Context<'a> {
self.parent_stack.last()
}

pub fn parse_nodes_with_comments(&mut self, start_pos: usize, end_pos: usize, nodes: impl Iterator<Item = Node<'a>>) -> Vec<Node<'a>> {
pub fn gen_nodes_with_comments(&mut self, start_pos: usize, end_pos: usize, nodes: impl Iterator<Item = Node<'a>>) -> Vec<Node<'a>> {
let mut result = Vec::new();
let mut last_pos = start_pos;
for node in nodes {
158 changes: 79 additions & 79 deletions src/parser/parse.rs → src/generation/generate.rs

Large diffs are not rendered by default.

File renamed without changes.
5 changes: 5 additions & 0 deletions src/generation/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod context;
mod generate;
mod helpers;

pub use generate::*;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod configuration;
mod format_text;
mod parser;
mod generation;

pub use format_text::format_text;

5 changes: 0 additions & 5 deletions src/parser/mod.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/wasm_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use dprint_core::configuration::{ConfigKeyMap, GlobalConfiguration, ResolveConfigurationResult};
use dprint_core::generate_plugin_code;
use dprint_core::plugins::{PluginHandler, PluginInfo};
use dprint_core::types::ErrBox;
use std::path::Path;

use super::configuration::{resolve_config, Configuration};
@@ -41,8 +41,8 @@ impl PluginHandler<Configuration> for DockerfilePluginHandler {
file_path: &Path,
file_text: &str,
config: &Configuration,
_format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> Result<String, ErrBox>,
) -> Result<String, ErrBox> {
_format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> Result<String>,
) -> Result<String> {
super::format_text(file_path, file_text, config)
}
}

0 comments on commit d56d35d

Please sign in to comment.