Skip to main content

dprint_core/plugins/
plugin_info.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4/// Information about a plugin.
5#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
6#[serde(rename_all = "camelCase")]
7pub struct PluginInfo {
8  /// The name of the plugin.
9  pub name: String,
10  /// The version of the plugin.
11  pub version: String,
12  /// Gets the key that can be used in the configuration JSON.
13  pub config_key: String,
14  /// A url the user can go to in order to get help information about the plugin.
15  pub help_url: String,
16  /// Schema url for the plugin configuration.
17  ///
18  /// Generally in the format: https://plugins.dprint.dev/<org-or-user>/<repo>/<tag-name>/schema.json
19  /// For example: https://plugins.dprint.dev/dprint/dprint-plugin-typescript/0.60.0/schema.json
20  pub config_schema_url: String,
21  /// Plugin update url.
22  ///
23  /// Generally in the format: https://plugins.dprint.dev/<org-or-user>/<repo>/latest.json
24  /// For example: https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json
25  pub update_url: Option<String>,
26  /// Whether the plugin formats the range of a format request, which plugins
27  /// should always provide.
28  ///
29  /// - `Some(true)` - Editors give the plugin the range as it is and use what
30  ///   it formats, so it decides what to format around the range (ex. the
31  ///   nodes it overlaps).
32  /// - `Some(false)` - Editors don't format a range with the plugin.
33  /// - `None` - Only for plugins made before this existed.
34  #[serde(default, skip_serializing_if = "Option::is_none")]
35  pub supports_range_formatting: Option<bool>,
36}
37
38/// Message for when a plugin's [`FileMatchingInfo`] can't be deserialized. A
39/// newer plugin may describe its file matching in a way this version of the CLI
40/// doesn't understand, so point at upgrading rather than leaving the user with
41/// only a deserialization error.
42pub const FILE_MATCHING_INFO_ERROR_MESSAGE: &str =
43  "Failed getting the plugin's file matching info. This plugin may require a newer version of the dprint CLI. Try running: dprint upgrade";
44
45/// The plugin file matching information based on the configuration.
46#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
47#[serde(rename_all = "camelCase")]
48pub struct FileMatchingInfo {
49  /// The file extensions this plugin should format.
50  #[serde(default = "Vec::new")]
51  pub file_extensions: Vec<String>,
52  /// The file names this plugin should format.
53  #[serde(default = "Vec::new")]
54  pub file_names: Vec<String>,
55  /// Whether the plugin formats a file it matches in addition to the plugin
56  /// that claims the file, rather than claiming the file itself.
57  ///
58  /// This is for plugins that do something to a file other than format it
59  /// from scratch (ex. sorting the keys of a `package.json`), which would
60  /// otherwise stop the file's usual formatter from running.
61  #[serde(default)]
62  pub additive: bool,
63}