1 //! rust-analyzer extensions to the LSP.
3 use std::{collections::HashMap, path::PathBuf};
5 use lsp_types::request::Request;
7 notification::Notification, CodeActionKind, Position, Range, TextDocumentIdentifier,
9 use serde::{Deserialize, Serialize};
11 pub enum AnalyzerStatus {}
13 impl Request for AnalyzerStatus {
14 type Params = AnalyzerStatusParams;
16 const METHOD: &'static str = "rust-analyzer/analyzerStatus";
19 #[derive(Deserialize, Serialize, Debug)]
20 #[serde(rename_all = "camelCase")]
21 pub struct AnalyzerStatusParams {
22 pub text_document: Option<TextDocumentIdentifier>,
25 pub enum MemoryUsage {}
27 impl Request for MemoryUsage {
30 const METHOD: &'static str = "rust-analyzer/memoryUsage";
33 pub enum ReloadWorkspace {}
35 impl Request for ReloadWorkspace {
38 const METHOD: &'static str = "rust-analyzer/reloadWorkspace";
41 pub enum SyntaxTree {}
43 impl Request for SyntaxTree {
44 type Params = SyntaxTreeParams;
46 const METHOD: &'static str = "rust-analyzer/syntaxTree";
49 #[derive(Deserialize, Serialize, Debug)]
50 #[serde(rename_all = "camelCase")]
51 pub struct SyntaxTreeParams {
52 pub text_document: TextDocumentIdentifier,
53 pub range: Option<Range>,
56 pub enum ExpandMacro {}
58 impl Request for ExpandMacro {
59 type Params = ExpandMacroParams;
60 type Result = Option<ExpandedMacro>;
61 const METHOD: &'static str = "rust-analyzer/expandMacro";
64 #[derive(Deserialize, Serialize, Debug)]
65 #[serde(rename_all = "camelCase")]
66 pub struct ExpandMacroParams {
67 pub text_document: TextDocumentIdentifier,
68 pub position: Position,
71 #[derive(Deserialize, Serialize, Debug)]
72 #[serde(rename_all = "camelCase")]
73 pub struct ExpandedMacro {
75 pub expansion: String,
78 pub enum MatchingBrace {}
80 impl Request for MatchingBrace {
81 type Params = MatchingBraceParams;
82 type Result = Vec<Position>;
83 const METHOD: &'static str = "experimental/matchingBrace";
86 #[derive(Deserialize, Serialize, Debug)]
87 #[serde(rename_all = "camelCase")]
88 pub struct MatchingBraceParams {
89 pub text_document: TextDocumentIdentifier,
90 pub positions: Vec<Position>,
93 pub enum ParentModule {}
95 impl Request for ParentModule {
96 type Params = lsp_types::TextDocumentPositionParams;
97 type Result = Option<lsp_types::GotoDefinitionResponse>;
98 const METHOD: &'static str = "experimental/parentModule";
101 pub enum JoinLines {}
103 impl Request for JoinLines {
104 type Params = JoinLinesParams;
105 type Result = Vec<lsp_types::TextEdit>;
106 const METHOD: &'static str = "experimental/joinLines";
109 #[derive(Deserialize, Serialize, Debug)]
110 #[serde(rename_all = "camelCase")]
111 pub struct JoinLinesParams {
112 pub text_document: TextDocumentIdentifier,
113 pub ranges: Vec<Range>,
118 impl Request for OnEnter {
119 type Params = lsp_types::TextDocumentPositionParams;
120 type Result = Option<Vec<SnippetTextEdit>>;
121 const METHOD: &'static str = "experimental/onEnter";
124 pub enum Runnables {}
126 impl Request for Runnables {
127 type Params = RunnablesParams;
128 type Result = Vec<Runnable>;
129 const METHOD: &'static str = "experimental/runnables";
132 #[derive(Serialize, Deserialize, Debug)]
133 #[serde(rename_all = "camelCase")]
134 pub struct RunnablesParams {
135 pub text_document: TextDocumentIdentifier,
136 pub position: Option<Position>,
139 #[derive(Deserialize, Serialize, Debug)]
140 #[serde(rename_all = "camelCase")]
141 pub struct Runnable {
143 #[serde(skip_serializing_if = "Option::is_none")]
144 pub location: Option<lsp_types::LocationLink>,
145 pub kind: RunnableKind,
146 pub args: CargoRunnable,
149 #[derive(Serialize, Deserialize, Debug)]
150 #[serde(rename_all = "lowercase")]
151 pub enum RunnableKind {
155 #[derive(Deserialize, Serialize, Debug)]
156 #[serde(rename_all = "camelCase")]
157 pub struct CargoRunnable {
158 // command to be executed instead of cargo
159 pub override_cargo: Option<String>,
160 #[serde(skip_serializing_if = "Option::is_none")]
161 pub workspace_root: Option<PathBuf>,
162 // command, --package and --lib stuff
163 pub cargo_args: Vec<String>,
164 // user-specified additional cargo args, like `--release`.
165 pub cargo_extra_args: Vec<String>,
167 pub executable_args: Vec<String>,
168 #[serde(skip_serializing_if = "Option::is_none")]
169 pub expect_test: Option<bool>,
172 pub enum InlayHints {}
174 impl Request for InlayHints {
175 type Params = InlayHintsParams;
176 type Result = Vec<InlayHint>;
177 const METHOD: &'static str = "rust-analyzer/inlayHints";
180 #[derive(Serialize, Deserialize, Debug)]
181 #[serde(rename_all = "camelCase")]
182 pub struct InlayHintsParams {
183 pub text_document: TextDocumentIdentifier,
186 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
193 #[derive(Debug, Deserialize, Serialize)]
194 pub struct InlayHint {
202 impl Request for Ssr {
203 type Params = SsrParams;
204 type Result = lsp_types::WorkspaceEdit;
205 const METHOD: &'static str = "experimental/ssr";
208 #[derive(Debug, Deserialize, Serialize)]
209 #[serde(rename_all = "camelCase")]
210 pub struct SsrParams {
212 pub parse_only: bool,
214 /// File position where SSR was invoked. Paths in `query` will be resolved relative to this
217 pub position: lsp_types::TextDocumentPositionParams,
219 /// Current selections. Search/replace will be restricted to these if non-empty.
220 pub selections: Vec<lsp_types::Range>,
223 pub enum StatusNotification {}
225 #[serde(rename_all = "camelCase")]
226 #[derive(Serialize, Deserialize)]
234 #[derive(Deserialize, Serialize)]
235 pub struct StatusParams {
239 impl Notification for StatusNotification {
240 type Params = StatusParams;
241 const METHOD: &'static str = "rust-analyzer/status";
244 pub enum CodeActionRequest {}
246 impl Request for CodeActionRequest {
247 type Params = lsp_types::CodeActionParams;
248 type Result = Option<Vec<CodeAction>>;
249 const METHOD: &'static str = "textDocument/codeAction";
252 pub enum CodeActionResolveRequest {}
253 impl Request for CodeActionResolveRequest {
254 type Params = CodeAction;
255 type Result = CodeAction;
256 const METHOD: &'static str = "codeAction/resolve";
259 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
260 #[serde(rename_all = "camelCase")]
261 pub struct CodeAction {
263 #[serde(skip_serializing_if = "Option::is_none")]
264 pub group: Option<String>,
265 #[serde(skip_serializing_if = "Option::is_none")]
266 pub kind: Option<CodeActionKind>,
267 // We don't handle commands on the client-side
268 // #[serde(skip_serializing_if = "Option::is_none")]
269 // pub command: Option<lsp_types::Command>,
270 #[serde(skip_serializing_if = "Option::is_none")]
271 pub edit: Option<SnippetWorkspaceEdit>,
272 #[serde(skip_serializing_if = "Option::is_none")]
273 pub is_preferred: Option<bool>,
275 #[serde(skip_serializing_if = "Option::is_none")]
276 pub data: Option<CodeActionData>,
279 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
280 #[serde(rename_all = "camelCase")]
281 pub struct CodeActionData {
282 pub code_action_params: lsp_types::CodeActionParams,
286 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
287 #[serde(rename_all = "camelCase")]
288 pub struct SnippetWorkspaceEdit {
289 #[serde(skip_serializing_if = "Option::is_none")]
290 pub changes: Option<HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>>>,
291 #[serde(skip_serializing_if = "Option::is_none")]
292 pub document_changes: Option<Vec<SnippetDocumentChangeOperation>>,
295 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
296 #[serde(untagged, rename_all = "lowercase")]
297 pub enum SnippetDocumentChangeOperation {
298 Op(lsp_types::ResourceOp),
299 Edit(SnippetTextDocumentEdit),
302 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
303 #[serde(rename_all = "camelCase")]
304 pub struct SnippetTextDocumentEdit {
305 pub text_document: lsp_types::VersionedTextDocumentIdentifier,
306 pub edits: Vec<SnippetTextEdit>,
309 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
310 #[serde(rename_all = "camelCase")]
311 pub struct SnippetTextEdit {
313 pub new_text: String,
314 #[serde(skip_serializing_if = "Option::is_none")]
315 pub insert_text_format: Option<lsp_types::InsertTextFormat>,
318 pub enum HoverRequest {}
320 impl Request for HoverRequest {
321 type Params = lsp_types::HoverParams;
322 type Result = Option<Hover>;
323 const METHOD: &'static str = "textDocument/hover";
326 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
329 pub hover: lsp_types::Hover,
330 #[serde(skip_serializing_if = "Vec::is_empty")]
331 pub actions: Vec<CommandLinkGroup>,
334 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
335 pub struct CommandLinkGroup {
336 #[serde(skip_serializing_if = "Option::is_none")]
337 pub title: Option<String>,
338 pub commands: Vec<CommandLink>,
341 // LSP v3.15 Command does not have a `tooltip` field, vscode supports one.
342 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
343 pub struct CommandLink {
345 pub command: lsp_types::Command,
346 #[serde(skip_serializing_if = "Option::is_none")]
347 pub tooltip: Option<String>,
350 pub enum ExternalDocs {}
352 impl Request for ExternalDocs {
353 type Params = lsp_types::TextDocumentPositionParams;
354 type Result = Option<lsp_types::Url>;
355 const METHOD: &'static str = "experimental/externalDocs";