aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs65
1 files changed, 36 insertions, 29 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 1baed73ad..51f134e8a 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -2,15 +2,16 @@ use std::collections::HashMap;
2 2
3use gen_lsp_server::ErrorCode; 3use gen_lsp_server::ErrorCode;
4use languageserver_types::{ 4use languageserver_types::{
5 CodeActionResponse, Command, Diagnostic, 5 CodeActionResponse, Command, Diagnostic, DiagnosticSeverity, DocumentFormattingParams,
6 DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, 6 DocumentHighlight, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind,
7 FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position, 7 FoldingRangeParams, Hover, HoverContents, Location, MarkedString, MarkupContent, MarkupKind,
8 PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, 8 ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, RenameParams,
9 Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, 9 SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
10 HoverContents, DocumentFormattingParams, DocumentHighlight,
11}; 10};
12use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; 11use ra_analysis::{
13use ra_syntax::{TextUnit, text_utils::intersect}; 12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange,
13};
14use ra_syntax::{text_utils::intersect, TextUnit};
14use ra_text_edit::text_utils::contains_offset_nonstrict; 15use ra_text_edit::text_utils::contains_offset_nonstrict;
15use rustc_hash::FxHashMap; 16use rustc_hash::FxHashMap;
16use serde_json::to_value; 17use serde_json::to_value;
@@ -92,29 +93,35 @@ pub fn handle_on_type_formatting(
92 world: ServerWorld, 93 world: ServerWorld,
93 params: req::DocumentOnTypeFormattingParams, 94 params: req::DocumentOnTypeFormattingParams,
94) -> Result<Option<Vec<TextEdit>>> { 95) -> Result<Option<Vec<TextEdit>>> {
95 if params.ch != "=" { 96 let analysis: Option<Box<Fn(FilePosition) -> Option<SourceChange>>> = match params.ch.as_str() {
96 return Ok(None); 97 "=" => Some(Box::new(|pos| world.analysis().on_eq_typed(pos))),
98 "." => Some(Box::new(|pos| world.analysis().on_dot_typed(pos))),
99 _ => None,
100 };
101
102 if let Some(ana) = analysis {
103 let file_id = params.text_document.try_conv_with(&world)?;
104 let line_index = world.analysis().file_line_index(file_id);
105 let position = FilePosition {
106 file_id,
107 offset: params.position.conv_with(&line_index),
108 };
109
110 if let Some(mut action) = ana(position) {
111 let change: Vec<TextEdit> = action
112 .source_file_edits
113 .pop()
114 .unwrap()
115 .edit
116 .as_atoms()
117 .iter()
118 .map_conv_with(&line_index)
119 .collect();
120 return Ok(Some(change));
121 }
97 } 122 }
98 123
99 let file_id = params.text_document.try_conv_with(&world)?; 124 return Ok(None);
100 let line_index = world.analysis().file_line_index(file_id);
101 let position = FilePosition {
102 file_id,
103 offset: params.position.conv_with(&line_index),
104 };
105 let edits = match world.analysis().on_eq_typed(position) {
106 None => return Ok(None),
107 Some(mut action) => action
108 .source_file_edits
109 .pop()
110 .unwrap()
111 .edit
112 .as_atoms()
113 .iter()
114 .map_conv_with(&line_index)
115 .collect(),
116 };
117 Ok(Some(edits))
118} 125}
119 126
120pub fn handle_document_symbol( 127pub fn handle_document_symbol(