]> git.lizzy.rs Git - rust.git/blob - crates/rust-analyzer/src/req.rs
lsp-types 0.74
[rust.git] / crates / rust-analyzer / src / req.rs
1 //! Defines `rust-analyzer` specific custom messages.
2
3 use lsp_types::{Location, Position, Range, TextDocumentIdentifier};
4 use rustc_hash::FxHashMap;
5 use serde::{Deserialize, Serialize};
6
7 pub use lsp_types::{
8     notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
9     CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
10     DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
11     DidChangeWatchedFilesRegistrationOptions, DocumentHighlightParams,
12     DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse,
13     FileSystemWatcher, GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams,
14     InitializeResult, MessageType, PartialResultParams, ProgressParams, ProgressParamsValue,
15     ProgressToken, PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams,
16     SelectionRange, SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams,
17     SemanticTokensRangeResult, SemanticTokensResult, ServerCapabilities, ShowMessageParams,
18     SignatureHelp, SignatureHelpParams, SymbolKind, TextDocumentEdit, TextDocumentPositionParams,
19     TextEdit, WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams,
20 };
21 use std::path::PathBuf;
22
23 pub enum AnalyzerStatus {}
24
25 impl Request for AnalyzerStatus {
26     type Params = ();
27     type Result = String;
28     const METHOD: &'static str = "rust-analyzer/analyzerStatus";
29 }
30
31 pub enum CollectGarbage {}
32
33 impl Request for CollectGarbage {
34     type Params = ();
35     type Result = ();
36     const METHOD: &'static str = "rust-analyzer/collectGarbage";
37 }
38
39 pub enum SyntaxTree {}
40
41 impl Request for SyntaxTree {
42     type Params = SyntaxTreeParams;
43     type Result = String;
44     const METHOD: &'static str = "rust-analyzer/syntaxTree";
45 }
46
47 #[derive(Deserialize, Serialize, Debug)]
48 #[serde(rename_all = "camelCase")]
49 pub struct SyntaxTreeParams {
50     pub text_document: TextDocumentIdentifier,
51     pub range: Option<Range>,
52 }
53
54 #[derive(Deserialize, Serialize, Debug)]
55 #[serde(rename_all = "camelCase")]
56 pub struct ExpandedMacro {
57     pub name: String,
58     pub expansion: String,
59 }
60
61 pub enum ExpandMacro {}
62
63 impl Request for ExpandMacro {
64     type Params = ExpandMacroParams;
65     type Result = Option<ExpandedMacro>;
66     const METHOD: &'static str = "rust-analyzer/expandMacro";
67 }
68
69 #[derive(Deserialize, Serialize, Debug)]
70 #[serde(rename_all = "camelCase")]
71 pub struct ExpandMacroParams {
72     pub text_document: TextDocumentIdentifier,
73     pub position: Option<Position>,
74 }
75
76 pub enum FindMatchingBrace {}
77
78 impl Request for FindMatchingBrace {
79     type Params = FindMatchingBraceParams;
80     type Result = Vec<Position>;
81     const METHOD: &'static str = "rust-analyzer/findMatchingBrace";
82 }
83
84 #[derive(Deserialize, Serialize, Debug)]
85 #[serde(rename_all = "camelCase")]
86 pub struct FindMatchingBraceParams {
87     pub text_document: TextDocumentIdentifier,
88     pub offsets: Vec<Position>,
89 }
90
91 pub enum ParentModule {}
92
93 impl Request for ParentModule {
94     type Params = TextDocumentPositionParams;
95     type Result = Vec<Location>;
96     const METHOD: &'static str = "rust-analyzer/parentModule";
97 }
98
99 pub enum JoinLines {}
100
101 impl Request for JoinLines {
102     type Params = JoinLinesParams;
103     type Result = SourceChange;
104     const METHOD: &'static str = "rust-analyzer/joinLines";
105 }
106
107 #[derive(Deserialize, Serialize, Debug)]
108 #[serde(rename_all = "camelCase")]
109 pub struct JoinLinesParams {
110     pub text_document: TextDocumentIdentifier,
111     pub range: Range,
112 }
113
114 pub enum OnEnter {}
115
116 impl Request for OnEnter {
117     type Params = TextDocumentPositionParams;
118     type Result = Option<SourceChange>;
119     const METHOD: &'static str = "rust-analyzer/onEnter";
120 }
121
122 pub enum Runnables {}
123
124 impl Request for Runnables {
125     type Params = RunnablesParams;
126     type Result = Vec<Runnable>;
127     const METHOD: &'static str = "rust-analyzer/runnables";
128 }
129
130 #[derive(Serialize, Deserialize, Debug)]
131 #[serde(rename_all = "camelCase")]
132 pub struct RunnablesParams {
133     pub text_document: TextDocumentIdentifier,
134     pub position: Option<Position>,
135 }
136
137 #[derive(Deserialize, Serialize, Debug)]
138 #[serde(rename_all = "camelCase")]
139 pub struct Runnable {
140     pub range: Range,
141     pub label: String,
142     pub bin: String,
143     pub args: Vec<String>,
144     pub extra_args: Vec<String>,
145     pub env: FxHashMap<String, String>,
146     pub cwd: Option<PathBuf>,
147 }
148
149 #[derive(Deserialize, Serialize, Debug)]
150 #[serde(rename_all = "camelCase")]
151 pub struct SourceChange {
152     pub label: String,
153     pub workspace_edit: WorkspaceEdit,
154     pub cursor_position: Option<TextDocumentPositionParams>,
155 }
156
157 pub enum InlayHints {}
158
159 impl Request for InlayHints {
160     type Params = InlayHintsParams;
161     type Result = Vec<InlayHint>;
162     const METHOD: &'static str = "rust-analyzer/inlayHints";
163 }
164
165 #[derive(Serialize, Deserialize, Debug)]
166 #[serde(rename_all = "camelCase")]
167 pub struct InlayHintsParams {
168     pub text_document: TextDocumentIdentifier,
169 }
170
171 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
172 pub enum InlayKind {
173     TypeHint,
174     ParameterHint,
175     ChainingHint,
176 }
177
178 #[derive(Debug, Deserialize, Serialize)]
179 pub struct InlayHint {
180     pub range: Range,
181     pub kind: InlayKind,
182     pub label: String,
183 }
184
185 pub enum Ssr {}
186
187 impl Request for Ssr {
188     type Params = SsrParams;
189     type Result = SourceChange;
190     const METHOD: &'static str = "rust-analyzer/ssr";
191 }
192
193 #[derive(Debug, Deserialize, Serialize)]
194 #[serde(rename_all = "camelCase")]
195 pub struct SsrParams {
196     pub query: String,
197     pub parse_only: bool,
198 }