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