aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-09 18:55:44 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-09 18:55:44 +0100
commit2fc2d4373b2c4e96bebf320a84270eee3afe34aa (patch)
tree5bdb33ae377b4004f0b28ec5e2edff71b41e8c4e /crates/ra_lsp_server/src
parent5f700179fc7ed16d2848a6dbc7cf23da3b8df6c7 (diff)
parent45a2b9252401cc580dfa2e0e761313cc8334d47c (diff)
Merge #1110
1110: Introduce display module and implement new FunctionSignature for CallInfo's r=matklad a=vipentti This introduces a new module `display` in `ra_ide_api` that contains UI-related things, in addition this refactors CallInfo's function signatures into a new `FunctionSignature` type, which implements `Display` and can be converted into `lsp_types::SignatureInformation` in the `conv` layer. Currently only `CallInfo` uses the `FunctionSignature` directly, but `function_label` now uses the same signature and returns it as a string, using the `Display` implementation. This also fixes #960 I think this similar structure could be applied to other UI-displayable items, so instead of the `ra_ide_api` returning `Strings` we could return some intermediate structures that can be converted into a UI-displayable `String` easily, but that could also provide some additional information. Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/conv.rs22
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs23
2 files changed, 27 insertions, 18 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 74e91c236..4d6ede316 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -174,6 +174,28 @@ impl Conv for ra_ide_api::Documentation {
174 } 174 }
175} 175}
176 176
177impl Conv for ra_ide_api::FunctionSignature {
178 type Output = lsp_types::SignatureInformation;
179 fn conv(self) -> Self::Output {
180 use lsp_types::{ParameterInformation, ParameterLabel, SignatureInformation};
181
182 let label = self.to_string();
183
184 let documentation = self.doc.map(|it| it.conv());
185
186 let parameters: Vec<ParameterInformation> = self
187 .parameters
188 .into_iter()
189 .map(|param| ParameterInformation {
190 label: ParameterLabel::Simple(param),
191 documentation: None,
192 })
193 .collect();
194
195 SignatureInformation { label, documentation, parameters: Some(parameters) }
196 }
197}
198
177impl ConvWith for TextEdit { 199impl ConvWith for TextEdit {
178 type Ctx = LineIndex; 200 type Ctx = LineIndex;
179 type Output = Vec<lsp_types::TextEdit>; 201 type Output = Vec<lsp_types::TextEdit>;
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 89e96a33a..b96deb061 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -3,8 +3,8 @@ use lsp_types::{
3 CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, CodeAction, 3 CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, CodeAction,
4 DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, 4 DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange,
5 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, 5 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent,
6 MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, 6 MarkupKind, Position, PrepareRenameResponse, Range,
7 RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, 7 RenameParams,SymbolInformation, TextDocumentIdentifier, TextEdit,
8 WorkspaceEdit, 8 WorkspaceEdit,
9}; 9};
10use ra_ide_api::{ 10use ra_ide_api::{
@@ -403,26 +403,13 @@ pub fn handle_signature_help(
403) -> Result<Option<req::SignatureHelp>> { 403) -> Result<Option<req::SignatureHelp>> {
404 let position = params.try_conv_with(&world)?; 404 let position = params.try_conv_with(&world)?;
405 if let Some(call_info) = world.analysis().call_info(position)? { 405 if let Some(call_info) = world.analysis().call_info(position)? {
406 let parameters: Vec<ParameterInformation> = call_info 406 let active_parameter = call_info.active_parameter.map(|it| it as i64);
407 .parameters 407 let sig_info = call_info.signature.conv();
408 .into_iter()
409 .map(|param| ParameterInformation {
410 label: ParameterLabel::Simple(param.clone()),
411 documentation: None,
412 })
413 .collect();
414 408
415 let documentation = call_info.doc.map(|it| it.conv());
416
417 let sig_info = SignatureInformation {
418 label: call_info.label,
419 documentation,
420 parameters: Some(parameters),
421 };
422 Ok(Some(req::SignatureHelp { 409 Ok(Some(req::SignatureHelp {
423 signatures: vec![sig_info], 410 signatures: vec![sig_info],
424 active_signature: Some(0), 411 active_signature: Some(0),
425 active_parameter: call_info.active_parameter.map(|it| it as i64), 412 active_parameter,
426 })) 413 }))
427 } else { 414 } else {
428 Ok(None) 415 Ok(None)