Skip to main content

mcpls_core/bridge/translator/
dto.rs

1//! Public MCP-facing result/data-transfer types returned by the tool-call
2//! handlers in the sibling domain modules.
3
4use serde::{Deserialize, Serialize};
5
6/// Position in a document (1-based for MCP).
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct Position2D {
9    /// Line number (1-based).
10    pub line: u32,
11    /// Character offset (1-based).
12    pub character: u32,
13}
14
15/// Range in a document (1-based for MCP).
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub struct Range {
18    /// Start position.
19    pub start: Position2D,
20    /// End position.
21    pub end: Position2D,
22}
23
24/// Location in a document.
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct Location {
27    /// URI of the document.
28    pub uri: String,
29    /// Range within the document.
30    pub range: Range,
31}
32
33/// Result of a hover request.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct HoverResult {
36    /// Hover contents as markdown string.
37    pub contents: String,
38    /// Optional range the hover applies to.
39    pub range: Option<Range>,
40}
41
42/// Result of a definition request.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct DefinitionResult {
45    /// Locations of the definition.
46    pub locations: Vec<Location>,
47}
48
49/// Result of a references request.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct ReferencesResult {
52    /// Locations of all references.
53    pub locations: Vec<Location>,
54}
55
56/// Diagnostic severity.
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58#[serde(rename_all = "lowercase")]
59pub enum DiagnosticSeverity {
60    /// Error diagnostic.
61    Error,
62    /// Warning diagnostic.
63    Warning,
64    /// Informational diagnostic.
65    Information,
66    /// Hint diagnostic.
67    Hint,
68}
69
70/// A single diagnostic.
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
72pub struct Diagnostic {
73    /// Range where the diagnostic applies.
74    pub range: Range,
75    /// Severity of the diagnostic.
76    pub severity: DiagnosticSeverity,
77    /// Diagnostic message.
78    pub message: String,
79    /// Optional diagnostic code.
80    pub code: Option<String>,
81}
82
83/// Result of a diagnostics request.
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct DiagnosticsResult {
86    /// List of diagnostics for the document.
87    pub diagnostics: Vec<Diagnostic>,
88}
89
90/// A text edit operation.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct TextEdit {
93    /// Range to replace.
94    pub range: Range,
95    /// New text.
96    pub new_text: String,
97}
98
99/// Changes to a document.
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct DocumentChanges {
102    /// URI of the document.
103    pub uri: String,
104    /// List of edits to apply.
105    pub edits: Vec<TextEdit>,
106}
107
108/// Result of a rename request.
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct RenameResult {
111    /// Changes to apply across documents.
112    pub changes: Vec<DocumentChanges>,
113}
114
115/// A completion item.
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct Completion {
118    /// Label of the completion.
119    pub label: String,
120    /// Kind of completion.
121    pub kind: Option<String>,
122    /// Detail information.
123    pub detail: Option<String>,
124    /// Documentation.
125    pub documentation: Option<String>,
126}
127
128/// Result of a completions request.
129#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct CompletionsResult {
131    /// List of completion items.
132    pub items: Vec<Completion>,
133}
134
135/// A document symbol.
136#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct Symbol {
138    /// Name of the symbol.
139    pub name: String,
140    /// Kind of symbol.
141    pub kind: String,
142    /// Range of the symbol.
143    pub range: Range,
144    /// Selection range (identifier location).
145    pub selection_range: Range,
146    /// Child symbols.
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub children: Option<Vec<Self>>,
149}
150
151/// Result of a document symbols request.
152#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct DocumentSymbolsResult {
154    /// List of symbols in the document.
155    pub symbols: Vec<Symbol>,
156}
157
158/// Result of a format document request.
159#[derive(Debug, Clone, Serialize, Deserialize)]
160pub struct FormatDocumentResult {
161    /// List of edits to format the document.
162    pub edits: Vec<TextEdit>,
163}
164
165/// A workspace symbol.
166#[derive(Debug, Clone, Serialize, Deserialize)]
167pub struct WorkspaceSymbol {
168    /// Name of the symbol.
169    pub name: String,
170    /// Kind of symbol.
171    pub kind: String,
172    /// Location of the symbol.
173    pub location: Location,
174    /// Optional container name (parent scope).
175    #[serde(skip_serializing_if = "Option::is_none")]
176    pub container_name: Option<String>,
177}
178
179/// Result of workspace symbol search.
180#[derive(Debug, Clone, Serialize, Deserialize)]
181pub struct WorkspaceSymbolResult {
182    /// List of symbols found.
183    pub symbols: Vec<WorkspaceSymbol>,
184}
185
186/// A single code action.
187#[derive(Debug, Clone, Serialize, Deserialize)]
188pub struct CodeAction {
189    /// Title of the code action.
190    pub title: String,
191    /// Kind of code action (quickfix, refactor, etc.).
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub kind: Option<String>,
194    /// Diagnostics that this action resolves.
195    #[serde(skip_serializing_if = "Vec::is_empty", default)]
196    pub diagnostics: Vec<Diagnostic>,
197    /// Workspace edit to apply.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub edit: Option<WorkspaceEditDescription>,
200    /// Command to execute.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub command: Option<CommandDescription>,
203    /// Whether this is the preferred action.
204    #[serde(default)]
205    pub is_preferred: bool,
206}
207
208/// Description of a workspace edit.
209#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct WorkspaceEditDescription {
211    /// Changes to apply to documents.
212    pub changes: Vec<DocumentChanges>,
213}
214
215/// Description of a command.
216#[derive(Debug, Clone, Serialize, Deserialize)]
217pub struct CommandDescription {
218    /// Title of the command.
219    pub title: String,
220    /// Command identifier.
221    pub command: String,
222    /// Command arguments.
223    #[serde(skip_serializing_if = "Vec::is_empty", default)]
224    pub arguments: Vec<serde_json::Value>,
225}
226
227/// Result of code actions request.
228#[derive(Debug, Clone, Serialize, Deserialize)]
229pub struct CodeActionsResult {
230    /// Available code actions.
231    pub actions: Vec<CodeAction>,
232}
233
234/// A call hierarchy item.
235#[derive(Debug, Clone, Serialize, Deserialize)]
236pub struct CallHierarchyItemResult {
237    /// Name of the symbol.
238    pub name: String,
239    /// LSP numeric symbol kind (e.g. 12 for Function).
240    pub kind: u32,
241    /// More detail for this item.
242    #[serde(skip_serializing_if = "Option::is_none")]
243    pub detail: Option<String>,
244    /// URI of the document.
245    pub uri: String,
246    /// Range of the symbol.
247    pub range: Range,
248    /// Selection range (identifier location).
249    ///
250    /// Serialized as `selectionRange` (camelCase) so that the value returned by
251    /// `prepare_call_hierarchy` round-trips correctly when the MCP client passes
252    /// it back to `get_incoming_calls` / `get_outgoing_calls`, which deserialize
253    /// it as `lsp_types::CallHierarchyItem` (camelCase).
254    #[serde(rename = "selectionRange")]
255    pub selection_range: Range,
256    /// Opaque data to pass to incoming/outgoing calls.
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub data: Option<serde_json::Value>,
259}
260
261/// Result of call hierarchy prepare request.
262#[derive(Debug, Clone, Serialize, Deserialize)]
263pub struct CallHierarchyPrepareResult {
264    /// List of callable items at the position.
265    pub items: Vec<CallHierarchyItemResult>,
266}
267
268/// An incoming call (caller of the current item).
269#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct IncomingCall {
271    /// The item that calls the current item.
272    pub from: CallHierarchyItemResult,
273    /// Ranges where the call occurs.
274    pub from_ranges: Vec<Range>,
275}
276
277/// Result of incoming calls request.
278#[derive(Debug, Clone, Serialize, Deserialize)]
279pub struct IncomingCallsResult {
280    /// List of incoming calls.
281    pub calls: Vec<IncomingCall>,
282}
283
284/// An outgoing call (callee from the current item).
285#[derive(Debug, Clone, Serialize, Deserialize)]
286pub struct OutgoingCall {
287    /// The item being called.
288    pub to: CallHierarchyItemResult,
289    /// Ranges where the call occurs.
290    pub from_ranges: Vec<Range>,
291}
292
293/// Result of outgoing calls request.
294#[derive(Debug, Clone, Serialize, Deserialize)]
295pub struct OutgoingCallsResult {
296    /// List of outgoing calls.
297    pub calls: Vec<OutgoingCall>,
298}
299
300/// Result of server logs request.
301#[derive(Debug, Clone, Serialize, Deserialize)]
302pub struct ServerLogsResult {
303    /// List of log entries.
304    pub logs: Vec<crate::bridge::notifications::LogEntry>,
305}
306
307/// Result of server messages request.
308#[derive(Debug, Clone, Serialize, Deserialize)]
309pub struct ServerMessagesResult {
310    /// List of server messages.
311    pub messages: Vec<crate::bridge::notifications::ServerMessage>,
312}
313
314/// A single parameter in a signature.
315#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct SignatureParameter {
317    /// Label of the parameter.
318    pub label: String,
319    /// Optional documentation for the parameter.
320    #[serde(skip_serializing_if = "Option::is_none")]
321    pub documentation: Option<String>,
322}
323
324/// A single signature overload.
325#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct SignatureInfo {
327    /// Full label of the signature.
328    pub label: String,
329    /// Optional documentation for the signature.
330    #[serde(skip_serializing_if = "Option::is_none")]
331    pub documentation: Option<String>,
332    /// Parameters of the signature.
333    pub parameters: Vec<SignatureParameter>,
334}
335
336/// Result of a signature help request.
337#[derive(Debug, Clone, Serialize, Deserialize)]
338pub struct SignatureHelpResult {
339    /// Available signatures.
340    pub signatures: Vec<SignatureInfo>,
341    /// Index of the active signature.
342    #[serde(skip_serializing_if = "Option::is_none")]
343    pub active_signature: Option<u32>,
344    /// Index of the active parameter within the active signature.
345    #[serde(skip_serializing_if = "Option::is_none")]
346    pub active_parameter: Option<u32>,
347}
348
349/// Result of a go-to-implementation or go-to-type-definition request.
350#[derive(Debug, Clone, Serialize, Deserialize)]
351pub struct LocationsResult {
352    /// Locations found.
353    pub locations: Vec<Location>,
354}
355
356/// A single inlay hint entry.
357#[derive(Debug, Clone, Serialize, Deserialize)]
358pub struct InlayHintEntry {
359    /// Position of the hint (1-based MCP).
360    pub position: Position2D,
361    /// Label text for the hint.
362    pub label: String,
363    /// Hint kind (1 = Type, 2 = Parameter).
364    #[serde(skip_serializing_if = "Option::is_none")]
365    pub kind: Option<u8>,
366    /// Whether to add a space before the hint.
367    #[serde(skip_serializing_if = "Option::is_none")]
368    pub padding_left: Option<bool>,
369    /// Whether to add a space after the hint.
370    #[serde(skip_serializing_if = "Option::is_none")]
371    pub padding_right: Option<bool>,
372    /// Tooltip text.
373    #[serde(skip_serializing_if = "Option::is_none")]
374    pub tooltip: Option<String>,
375}
376
377/// Result of an inlay hints request.
378#[derive(Debug, Clone, Serialize, Deserialize)]
379pub struct InlayHintsResult {
380    /// List of inlay hints.
381    pub hints: Vec<InlayHintEntry>,
382}