Skip to main content

codelens_engine/lsp/
types.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone)]
5pub struct LspRequest {
6    pub command: String,
7    pub args: Vec<String>,
8    pub file_path: String,
9    pub line: usize,
10    pub column: usize,
11    pub max_results: usize,
12}
13
14#[derive(Debug, Clone)]
15pub struct LspDiagnosticRequest {
16    pub command: String,
17    pub args: Vec<String>,
18    pub file_path: String,
19    pub max_results: usize,
20}
21
22#[derive(Debug, Clone)]
23pub struct LspWorkspaceSymbolRequest {
24    pub command: String,
25    pub args: Vec<String>,
26    pub query: String,
27    pub max_results: usize,
28}
29
30#[derive(Debug, Clone)]
31pub struct LspTypeHierarchyRequest {
32    pub command: String,
33    pub args: Vec<String>,
34    pub query: String,
35    pub relative_path: Option<String>,
36    pub hierarchy_type: String,
37    pub depth: usize,
38}
39
40#[derive(Debug, Clone)]
41pub struct LspResolveTargetRequest {
42    pub command: String,
43    pub args: Vec<String>,
44    pub file_path: String,
45    pub line: usize,
46    pub column: usize,
47    pub target: String,
48    pub max_results: usize,
49}
50
51#[derive(Debug, Clone)]
52pub struct LspRenamePlanRequest {
53    pub command: String,
54    pub args: Vec<String>,
55    pub file_path: String,
56    pub line: usize,
57    pub column: usize,
58    pub new_name: Option<String>,
59}
60
61#[derive(Debug, Clone)]
62pub struct LspRenameRequest {
63    pub command: String,
64    pub args: Vec<String>,
65    pub file_path: String,
66    pub line: usize,
67    pub column: usize,
68    pub new_name: String,
69    pub dry_run: bool,
70}
71
72#[derive(Debug, Clone)]
73pub struct LspCodeActionRequest {
74    pub command: String,
75    pub args: Vec<String>,
76    pub file_path: String,
77    pub start_line: usize,
78    pub start_column: usize,
79    pub end_line: usize,
80    pub end_column: usize,
81    pub only: Vec<String>,
82    pub action_id: Option<String>,
83    pub operation: String,
84    pub dry_run: bool,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct LspReference {
89    pub file_path: String,
90    pub line: usize,
91    pub column: usize,
92    pub end_line: usize,
93    pub end_column: usize,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct LspResolvedTarget {
98    pub file_path: String,
99    pub line: usize,
100    pub column: usize,
101    pub end_line: usize,
102    pub end_column: usize,
103    pub target: String,
104    pub method: String,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct LspDiagnostic {
109    pub file_path: String,
110    pub line: usize,
111    pub column: usize,
112    pub end_line: usize,
113    pub end_column: usize,
114    pub severity: Option<u8>,
115    pub severity_label: Option<String>,
116    pub code: Option<String>,
117    pub source: Option<String>,
118    pub message: String,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct LspWorkspaceSymbol {
123    pub name: String,
124    pub kind: Option<u32>,
125    pub kind_label: Option<String>,
126    pub container_name: Option<String>,
127    pub file_path: String,
128    pub line: usize,
129    pub column: usize,
130    pub end_line: usize,
131    pub end_column: usize,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
135pub struct LspTypeHierarchyNode {
136    pub name: String,
137    pub fully_qualified_name: String,
138    pub kind: String,
139    pub members: HashMap<String, Vec<String>>,
140    pub type_parameters: Vec<HashMap<String, String>>,
141    #[serde(skip_serializing_if = "Vec::is_empty")]
142    pub supertypes: Vec<LspTypeHierarchyNode>,
143    #[serde(skip_serializing_if = "Vec::is_empty")]
144    pub subtypes: Vec<LspTypeHierarchyNode>,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct LspRenamePlan {
149    pub file_path: String,
150    pub line: usize,
151    pub column: usize,
152    pub end_line: usize,
153    pub end_column: usize,
154    pub current_name: String,
155    pub placeholder: Option<String>,
156    pub new_name: Option<String>,
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize)]
160pub struct LspResourceOp {
161    pub kind: String,
162    pub file_path: String,
163    pub old_file_path: Option<String>,
164    pub new_file_path: Option<String>,
165}
166
167#[derive(Debug, Clone, Serialize)]
168pub struct LspWorkspaceEditTransaction {
169    pub edits: Vec<crate::rename::RenameEdit>,
170    pub resource_ops: Vec<LspResourceOp>,
171    pub modified_files: usize,
172    pub edit_count: usize,
173    #[deprecated(note = "use ApplyEvidence::status from substrate apply_with_evidence instead")]
174    pub rollback_available: bool,
175}
176
177impl From<LspWorkspaceEditTransaction> for crate::edit_transaction::WorkspaceEditTransaction {
178    fn from(value: LspWorkspaceEditTransaction) -> Self {
179        crate::edit_transaction::WorkspaceEditTransaction::new(value.edits, value.resource_ops)
180    }
181}
182
183#[derive(Debug, Clone, Serialize)]
184pub struct LspCodeActionRefactorPlan {
185    pub operation: String,
186    pub action_title: String,
187    pub action_kind: Option<String>,
188    pub resolved_via: String,
189    pub transaction: LspWorkspaceEditTransaction,
190}
191
192#[derive(Debug, Clone, Serialize)]
193pub struct LspCodeActionRefactorResult {
194    pub success: bool,
195    pub message: String,
196    pub operation: String,
197    pub action_title: String,
198    pub action_kind: Option<String>,
199    pub resolved_via: String,
200    pub applied: bool,
201    pub transaction: LspWorkspaceEditTransaction,
202}