Skip to main content

modelith_plugin_protocol/
edit.rs

1//! テキスト編集と診断。LSP と同じ形にそろえる(位置は 0 始まり、列は UTF-16 コード単位)。
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6#[cfg_attr(feature = "codegen", derive(schemars::JsonSchema, ts_rs::TS))]
7pub struct Position {
8    pub line: u32,
9    pub character: u32,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13#[cfg_attr(feature = "codegen", derive(schemars::JsonSchema, ts_rs::TS))]
14pub struct Range {
15    pub start: Position,
16    pub end: Position,
17}
18
19/// プラグインが返す変更案。ホストが検証してから適用する。
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21#[cfg_attr(feature = "codegen", derive(schemars::JsonSchema, ts_rs::TS))]
22#[serde(rename_all = "camelCase")]
23pub struct TextEdit {
24    pub range: Range,
25    pub new_text: String,
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
29#[cfg_attr(feature = "codegen", derive(schemars::JsonSchema, ts_rs::TS))]
30#[serde(rename_all = "lowercase")]
31pub enum DiagnosticSeverity {
32    Error,
33    Warning,
34    Information,
35    Hint,
36}
37
38/// 検査ルールなどが報告する診断。
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40#[cfg_attr(feature = "codegen", derive(schemars::JsonSchema, ts_rs::TS))]
41#[serde(rename_all = "camelCase")]
42pub struct Diagnostic {
43    pub range: Range,
44    pub severity: DiagnosticSeverity,
45    pub message: String,
46    /// ルール ID など。
47    #[serde(default, skip_serializing_if = "Option::is_none")]
48    #[cfg_attr(feature = "codegen", ts(optional))]
49    pub code: Option<String>,
50    /// 報告元のプラグイン ID など。
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    #[cfg_attr(feature = "codegen", ts(optional))]
53    pub source: Option<String>,
54}