]> git.lizzy.rs Git - rust.git/blob - crates/ra_lsp_server/src/req.rs
Merge #924
[rust.git] / crates / ra_lsp_server / src / req.rs
1 use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
2 use rustc_hash::FxHashMap;
3 use serde::{Deserialize, Serialize};
4 use url_serde;
5
6 pub use lsp_types::{
7     notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, CodeLensParams,
8     CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
9     DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
10     PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit,
11     TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams
12 };
13
14 pub enum AnalyzerStatus {}
15
16 impl Request for AnalyzerStatus {
17     type Params = ();
18     type Result = String;
19     const METHOD: &'static str = "rust-analyzer/analyzerStatus";
20 }
21
22 pub enum CollectGarbage {}
23
24 impl Request for CollectGarbage {
25     type Params = ();
26     type Result = ();
27     const METHOD: &'static str = "rust-analyzer/collectGarbage";
28 }
29
30 pub enum SyntaxTree {}
31
32 impl Request for SyntaxTree {
33     type Params = SyntaxTreeParams;
34     type Result = String;
35     const METHOD: &'static str = "rust-analyzer/syntaxTree";
36 }
37
38 #[derive(Deserialize, Debug)]
39 #[serde(rename_all = "camelCase")]
40 pub struct SyntaxTreeParams {
41     pub text_document: TextDocumentIdentifier,
42     pub range: Option<Range>,
43 }
44
45 pub enum ExtendSelection {}
46
47 impl Request for ExtendSelection {
48     type Params = ExtendSelectionParams;
49     type Result = ExtendSelectionResult;
50     const METHOD: &'static str = "rust-analyzer/extendSelection";
51 }
52
53 #[derive(Deserialize, Debug)]
54 #[serde(rename_all = "camelCase")]
55 pub struct ExtendSelectionParams {
56     pub text_document: TextDocumentIdentifier,
57     pub selections: Vec<Range>,
58 }
59
60 #[derive(Serialize, Debug)]
61 #[serde(rename_all = "camelCase")]
62 pub struct ExtendSelectionResult {
63     pub selections: Vec<Range>,
64 }
65
66 pub enum FindMatchingBrace {}
67
68 impl Request for FindMatchingBrace {
69     type Params = FindMatchingBraceParams;
70     type Result = Vec<Position>;
71     const METHOD: &'static str = "rust-analyzer/findMatchingBrace";
72 }
73
74 #[derive(Deserialize, Debug)]
75 #[serde(rename_all = "camelCase")]
76 pub struct FindMatchingBraceParams {
77     pub text_document: TextDocumentIdentifier,
78     pub offsets: Vec<Position>,
79 }
80
81 pub enum DecorationsRequest {}
82
83 impl Request for DecorationsRequest {
84     type Params = TextDocumentIdentifier;
85     type Result = Vec<Decoration>;
86     const METHOD: &'static str = "rust-analyzer/decorationsRequest";
87 }
88
89 pub enum PublishDecorations {}
90
91 impl Notification for PublishDecorations {
92     type Params = PublishDecorationsParams;
93     const METHOD: &'static str = "rust-analyzer/publishDecorations";
94 }
95
96 #[derive(Serialize, Debug)]
97 #[serde(rename_all = "camelCase")]
98 pub struct PublishDecorationsParams {
99     #[serde(with = "url_serde")]
100     pub uri: Url,
101     pub decorations: Vec<Decoration>,
102 }
103
104 #[derive(Serialize, Debug)]
105 #[serde(rename_all = "camelCase")]
106 pub struct Decoration {
107     pub range: Range,
108     pub tag: &'static str,
109 }
110
111 pub enum ParentModule {}
112
113 impl Request for ParentModule {
114     type Params = TextDocumentPositionParams;
115     type Result = Vec<Location>;
116     const METHOD: &'static str = "rust-analyzer/parentModule";
117 }
118
119 pub enum JoinLines {}
120
121 impl Request for JoinLines {
122     type Params = JoinLinesParams;
123     type Result = SourceChange;
124     const METHOD: &'static str = "rust-analyzer/joinLines";
125 }
126
127 #[derive(Deserialize, Debug)]
128 #[serde(rename_all = "camelCase")]
129 pub struct JoinLinesParams {
130     pub text_document: TextDocumentIdentifier,
131     pub range: Range,
132 }
133
134 pub enum OnEnter {}
135
136 impl Request for OnEnter {
137     type Params = TextDocumentPositionParams;
138     type Result = Option<SourceChange>;
139     const METHOD: &'static str = "rust-analyzer/onEnter";
140 }
141
142 pub enum Runnables {}
143
144 impl Request for Runnables {
145     type Params = RunnablesParams;
146     type Result = Vec<Runnable>;
147     const METHOD: &'static str = "rust-analyzer/runnables";
148 }
149
150 #[derive(Serialize, Deserialize, Debug)]
151 #[serde(rename_all = "camelCase")]
152 pub struct RunnablesParams {
153     pub text_document: TextDocumentIdentifier,
154     pub position: Option<Position>,
155 }
156
157 #[derive(Serialize, Debug)]
158 #[serde(rename_all = "camelCase")]
159 pub struct Runnable {
160     pub range: Range,
161     pub label: String,
162     pub bin: String,
163     pub args: Vec<String>,
164     pub env: FxHashMap<String, String>,
165 }
166
167 #[derive(Serialize, Debug)]
168 #[serde(rename_all = "camelCase")]
169 pub struct SourceChange {
170     pub label: String,
171     pub workspace_edit: WorkspaceEdit,
172     pub cursor_position: Option<TextDocumentPositionParams>,
173 }
174
175 pub enum InternalFeedback {}
176
177 impl Notification for InternalFeedback {
178     const METHOD: &'static str = "internalFeedback";
179     type Params = String;
180 }