lapce_rpc/
plugin.rs

1use std::{collections::HashMap, path::PathBuf};
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::counter::Counter;
7
8#[derive(Eq, PartialEq, Hash, Clone, Copy, Debug, Serialize, Deserialize)]
9pub struct PluginId(pub u64);
10
11impl PluginId {
12    pub fn next() -> Self {
13        static PLUGIN_ID_COUNTER: Counter = Counter::new();
14        Self(PLUGIN_ID_COUNTER.next())
15    }
16}
17
18#[derive(Deserialize, Clone, Debug, Serialize)]
19pub struct PluginConfiguration {
20    #[serde(rename(deserialize = "type"))]
21    pub kind: String,
22    pub default: Value,
23    pub description: String,
24}
25
26#[derive(Deserialize, Clone, Debug, Serialize)]
27#[serde(rename_all = "kebab-case")]
28pub struct VoltInfo {
29    pub name: String,
30    pub version: String,
31    pub display_name: String,
32    pub author: String,
33    pub description: String,
34    pub meta: String,
35}
36
37impl VoltInfo {
38    pub fn id(&self) -> String {
39        format!("{}.{}", self.author, self.name)
40    }
41}
42
43#[derive(Deserialize, Clone, Debug, Serialize)]
44#[serde(rename_all = "kebab-case")]
45pub struct VoltActivation {
46    pub language: Option<Vec<String>>,
47    pub workspace_contains: Option<Vec<String>>,
48}
49
50#[derive(Deserialize, Clone, Debug, Serialize)]
51pub struct VoltConfig {
52    pub default: Value,
53    pub description: String,
54}
55
56#[derive(Deserialize, Clone, Debug, Serialize)]
57#[serde(rename_all = "kebab-case")]
58pub struct VoltMetadata {
59    pub name: String,
60    pub version: String,
61    pub display_name: String,
62    pub author: String,
63    pub description: String,
64    pub icon: Option<String>,
65    pub repository: Option<String>,
66    pub wasm: Option<String>,
67    pub color_themes: Option<Vec<String>>,
68    pub icon_themes: Option<Vec<String>>,
69    pub dir: Option<PathBuf>,
70    pub activation: Option<VoltActivation>,
71    pub config: Option<HashMap<String, VoltConfig>>,
72}
73
74impl VoltMetadata {
75    pub fn id(&self) -> String {
76        format!("{}.{}", self.author, self.name)
77    }
78
79    pub fn info(&self) -> VoltInfo {
80        VoltInfo {
81            name: self.name.clone(),
82            version: self.version.clone(),
83            display_name: self.display_name.clone(),
84            author: self.author.clone(),
85            description: self.description.clone(),
86            meta: "".to_string(),
87        }
88    }
89}