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, 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.
27  ///
28  /// - `true` - Editors give the plugin the range as it is and use what it
29  ///   formats, so it decides what to format around the range (ex. the nodes
30  ///   it overlaps).
31  /// - `false` - Editors don't format a range with the plugin.
32  pub supports_range_formatting: bool,
33  /// Whether dprint should skip formatting a file again until the output is
34  /// stable when the plugin changes the file.
35  ///
36  /// By default, dprint formats the text a plugin changed again until it
37  /// stops changing to catch plugins that format differently each time. Only
38  /// set this to `true` when formatting the plugin's output again never
39  /// changes it with any configuration. This saves formatting each changed
40  /// file at least one more time and the output is still stored as formatted
41  /// for incremental formatting.
42  ///
43  /// When the plugin formats embedded text with other plugins (ex. code
44  /// blocks), dprint formats that text again until it's stable unless those
45  /// plugins say the same.
46  pub skip_stable_format: bool,
47}
48
49/// Information about a process plugin.
50#[derive(Clone, Serialize, Debug, PartialEq, Eq)]
51#[serde(rename_all = "camelCase")]
52pub struct ProcessPluginInfo {
53  /// The information that every plugin provides.
54  #[serde(flatten)]
55  pub info: PluginInfo,
56  /// Whether another plugin may change this plugin's non-global configuration
57  /// when it asks dprint to format text with this plugin (ex. a Wasm plugin
58  /// formatting a code block). Another plugin can always change the global
59  /// configuration (ex. `lineWidth`). This doesn't affect configuration from
60  /// anywhere else, such as a config file.
61  ///
62  /// Process plugins don't run sandboxed and the requesting plugin might be a
63  /// Wasm plugin from an untrusted source (ex. remote configuration), so only
64  /// set this to `true` when no configuration could make the plugin do
65  /// something harmful, such as run a command provided in the configuration
66  /// (ex. dprint-plugin-exec).
67  pub allow_plugin_override_config: bool,
68}
69
70/// Message for when a plugin's [`FileMatchingInfo`] can't be deserialized. A
71/// newer plugin may describe its file matching in a way this version of the CLI
72/// doesn't understand, so point at upgrading rather than leaving the user with
73/// only a deserialization error.
74pub const FILE_MATCHING_INFO_ERROR_MESSAGE: &str =
75  "Failed getting the plugin's file matching info. This plugin may require a newer version of the dprint CLI. Try running: dprint upgrade";
76
77/// The plugin file matching information based on the configuration.
78#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
79#[serde(rename_all = "camelCase")]
80pub struct FileMatchingInfo {
81  /// The file extensions this plugin should format.
82  #[serde(default = "Vec::new")]
83  pub file_extensions: Vec<String>,
84  /// The file names this plugin should format.
85  #[serde(default = "Vec::new")]
86  pub file_names: Vec<String>,
87  /// Whether the plugin formats a file it matches in addition to the plugin
88  /// that claims the file, rather than claiming the file itself.
89  ///
90  /// This is for plugins that do something to a file other than format it
91  /// from scratch (ex. sorting the keys of a `package.json`), which would
92  /// otherwise stop the file's usual formatter from running.
93  #[serde(default)]
94  pub additive: bool,
95}