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}
34
35/// Information about a process plugin.
36#[derive(Clone, Serialize, Debug, PartialEq, Eq)]
37#[serde(rename_all = "camelCase")]
38pub struct ProcessPluginInfo {
39  /// The information that every plugin provides.
40  #[serde(flatten)]
41  pub info: PluginInfo,
42  /// Whether another plugin may change this plugin's non-global configuration
43  /// when it asks dprint to format text with this plugin (ex. a Wasm plugin
44  /// formatting a code block). Another plugin can always change the global
45  /// configuration (ex. `lineWidth`). This doesn't affect configuration from
46  /// anywhere else, such as a config file.
47  ///
48  /// Process plugins don't run sandboxed and the requesting plugin might be a
49  /// Wasm plugin from an untrusted source (ex. remote configuration), so only
50  /// set this to `true` when no configuration could make the plugin do
51  /// something harmful, such as run a command provided in the configuration
52  /// (ex. dprint-plugin-exec).
53  pub allow_plugin_override_config: bool,
54}
55
56/// Message for when a plugin's [`FileMatchingInfo`] can't be deserialized. A
57/// newer plugin may describe its file matching in a way this version of the CLI
58/// doesn't understand, so point at upgrading rather than leaving the user with
59/// only a deserialization error.
60pub const FILE_MATCHING_INFO_ERROR_MESSAGE: &str =
61  "Failed getting the plugin's file matching info. This plugin may require a newer version of the dprint CLI. Try running: dprint upgrade";
62
63/// The plugin file matching information based on the configuration.
64#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
65#[serde(rename_all = "camelCase")]
66pub struct FileMatchingInfo {
67  /// The file extensions this plugin should format.
68  #[serde(default = "Vec::new")]
69  pub file_extensions: Vec<String>,
70  /// The file names this plugin should format.
71  #[serde(default = "Vec::new")]
72  pub file_names: Vec<String>,
73  /// Whether the plugin formats a file it matches in addition to the plugin
74  /// that claims the file, rather than claiming the file itself.
75  ///
76  /// This is for plugins that do something to a file other than format it
77  /// from scratch (ex. sorting the keys of a `package.json`), which would
78  /// otherwise stop the file's usual formatter from running.
79  #[serde(default)]
80  pub additive: bool,
81}