-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): 0.8.0 - Upgrade dprint-core to 0.42.0 (#44)
* 0.8.0 * Upgrade to use new PluginHandler trait. Co-authored-by: David Sherret <[email protected]>
- Loading branch information
1 parent
2946499
commit 63e5efe
Showing
7 changed files
with
96 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "dprint-plugin-markdown" | ||
description = "Markdown formatter for dprint." | ||
version = "0.7.1" | ||
version = "0.8.0" | ||
authors = ["David Sherret <[email protected]>"] | ||
license = "MIT" | ||
edition = "2018" | ||
|
@@ -24,12 +24,12 @@ wasm = ["serde_json", "dprint-core/wasm"] | |
tracing = ["dprint-core/tracing"] | ||
|
||
[dependencies] | ||
dprint-core = { version = "0.39.0", features = ["formatting"] } | ||
dprint-core = { version = "0.42.0", features = ["formatting"] } | ||
pulldown-cmark = { version = "0.8.0", default-features = false } | ||
serde = { version = "1.0.88", features = ["derive"] } | ||
serde_json = { version = "1.0", optional = true } | ||
regex = "1" | ||
|
||
[dev-dependencies] | ||
dprint-development = "0.3.0" | ||
dprint-development = "0.4.0" | ||
serde_json = { version = "1.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,86 @@ | ||
use std::path::PathBuf; | ||
use std::path::{Path, PathBuf}; | ||
use std::collections::HashMap; | ||
|
||
use dprint_core::generate_plugin_code; | ||
use dprint_core::configuration::{ConfigKeyMap, GlobalConfiguration, ResolveConfigurationResult}; | ||
use dprint_core::plugins::{PluginHandler, PluginInfo}; | ||
use dprint_core::types::ErrBox; | ||
use super::configuration::{Configuration, resolve_config}; | ||
|
||
fn get_plugin_config_key() -> String { | ||
String::from("markdown") | ||
struct MarkdownPluginHandler { | ||
} | ||
|
||
fn get_plugin_file_extensions() -> Vec<String> { | ||
vec![String::from("md")] | ||
impl MarkdownPluginHandler { | ||
pub const fn new() -> Self { | ||
MarkdownPluginHandler {} | ||
} | ||
} | ||
|
||
fn format_text(_: &PathBuf, file_text: &str, config: &Configuration) -> Result<String, String> { | ||
return super::format_text( | ||
file_text, | ||
config, | ||
Box::new(|tag, file_text, line_width| { | ||
if let Some(ext) = tag_to_extension(tag) { | ||
let file_path = PathBuf::from(format!("file.{}", ext)); | ||
let mut additional_config = HashMap::new(); | ||
additional_config.insert("lineWidth".into(), (line_width as i32).into()); | ||
format_with_host(&file_path, file_text.to_string(), &additional_config) | ||
} else { | ||
Ok(file_text.to_string()) | ||
} | ||
}) | ||
); | ||
|
||
fn tag_to_extension(tag: &str) -> Option<&'static str> { | ||
match tag.trim().to_lowercase().as_str() { | ||
"typescript" | "ts" => Some("ts"), | ||
"tsx" => Some("tsx"), | ||
"javascript" | "js" => Some("js"), | ||
"jsx" => Some("jsx"), | ||
"json" | "jsonc" => Some("json"), | ||
"rust" | "rs" => Some("rs"), | ||
"csharp" | "cs" => Some("cs"), | ||
"visualbasic" | "vb" => Some("vb"), | ||
"css" => Some("css"), | ||
"less" => Some("less"), | ||
"toml" => Some("toml"), | ||
"scss" => Some("scss"), | ||
"vue" => Some("vue"), | ||
_ => None, | ||
impl PluginHandler<Configuration> for MarkdownPluginHandler { | ||
fn resolve_config( | ||
&mut self, | ||
config: ConfigKeyMap, | ||
global_config: &GlobalConfiguration, | ||
) -> ResolveConfigurationResult<Configuration> { | ||
resolve_config(config, global_config) | ||
} | ||
|
||
fn get_plugin_info(&mut self) -> PluginInfo { | ||
PluginInfo { | ||
name: env!("CARGO_PKG_NAME").to_string(), | ||
version: env!("CARGO_PKG_VERSION").to_string(), | ||
config_key: "markdown".to_string(), | ||
file_extensions: vec!["md".to_string()], | ||
help_url: "https://dprint.dev/plugins/markdown".to_string(), | ||
config_schema_url: "".to_string(), // none until https://github.com/microsoft/vscode/issues/98443 is resolved | ||
} | ||
} | ||
} | ||
|
||
fn get_plugin_help_url() -> String { | ||
String::from("https://dprint.dev/plugins/markdown") | ||
} | ||
fn get_license_text(&mut self) -> String { | ||
std::str::from_utf8(include_bytes!("../LICENSE")).unwrap().into() | ||
} | ||
|
||
fn get_plugin_config_schema_url() -> String { | ||
String::new() // none until https://github.com/microsoft/vscode/issues/98443 is resolved | ||
} | ||
fn format_text( | ||
&mut self, | ||
_file_path: &Path, | ||
file_text: &str, | ||
config: &Configuration, | ||
mut format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> Result<String, ErrBox>, | ||
) -> Result<String, ErrBox> { | ||
return super::format_text( | ||
file_text, | ||
config, | ||
|tag, file_text, line_width| { | ||
if let Some(ext) = tag_to_extension(tag) { | ||
let file_path = PathBuf::from(format!("file.{}", ext)); | ||
let mut additional_config = HashMap::new(); | ||
additional_config.insert("lineWidth".into(), (line_width as i32).into()); | ||
format_with_host(&file_path, file_text.to_string(), &additional_config) | ||
} else { | ||
Ok(file_text.to_string()) | ||
} | ||
} | ||
); | ||
|
||
fn get_plugin_license_text() -> String { | ||
std::str::from_utf8(include_bytes!("../LICENSE")).unwrap().into() | ||
fn tag_to_extension(tag: &str) -> Option<&'static str> { | ||
match tag.trim().to_lowercase().as_str() { | ||
"typescript" | "ts" => Some("ts"), | ||
"tsx" => Some("tsx"), | ||
"javascript" | "js" => Some("js"), | ||
"jsx" => Some("jsx"), | ||
"json" | "jsonc" => Some("json"), | ||
"rust" | "rs" => Some("rs"), | ||
"csharp" | "cs" => Some("cs"), | ||
"visualbasic" | "vb" => Some("vb"), | ||
"css" => Some("css"), | ||
"less" => Some("less"), | ||
"toml" => Some("toml"), | ||
"scss" => Some("scss"), | ||
"vue" => Some("vue"), | ||
_ => None, | ||
} | ||
} | ||
} | ||
} | ||
|
||
generate_plugin_code!(); | ||
generate_plugin_code!(MarkdownPluginHandler, MarkdownPluginHandler::new()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters