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