diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-07 06:26:09 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-07 06:26:09 +0000 |
commit | a6071c9f4c8441b4b8f2e970bc055d66cc9be5f0 (patch) | |
tree | 67fb82094ed6542f77f4ad1cc8b7bdbfb37bf6b1 /crates/ra_lsp_server | |
parent | c69bb8a7e737e09c667f9e343d0f1d3e4c13b8f7 (diff) | |
parent | f3c708ab7babc4e94250cbfbaae0fdd3919284ce (diff) |
Merge #442
442: WIP: indent on typing dot r=matklad a=simonvandel
Fixes #439.
The unit test passes, but I can't seem to make VS code perform the action. The existing action on "=" doesn't work either on my end either though.
I didn't add any smart way of detecting the current indent level. Any ideas how I would do that?
Co-authored-by: Simon Vandel Sillesen <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/caps.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 14 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 65 |
3 files changed, 42 insertions, 39 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index a74f9f27b..2599a4ca6 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -37,7 +37,7 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
37 | document_range_formatting_provider: None, | 37 | document_range_formatting_provider: None, |
38 | document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { | 38 | document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { |
39 | first_trigger_character: "=".to_string(), | 39 | first_trigger_character: "=".to_string(), |
40 | more_trigger_character: None, | 40 | more_trigger_character: Some(vec![".".to_string()]), |
41 | }), | 41 | }), |
42 | folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), | 42 | folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), |
43 | rename_provider: Some(RenameProviderCapability::Options(RenameOptions { | 43 | rename_provider: Some(RenameProviderCapability::Options(RenameOptions { |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 60d9671de..2dc1be26a 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -1,13 +1,11 @@ | |||
1 | mod handlers; | 1 | mod handlers; |
2 | mod subscriptions; | 2 | mod subscriptions; |
3 | 3 | ||
4 | use std::{ | 4 | use std::{fmt, path::PathBuf, sync::Arc}; |
5 | fmt, | ||
6 | path::PathBuf, | ||
7 | sync::Arc, | ||
8 | }; | ||
9 | 5 | ||
10 | use crossbeam_channel::{unbounded, select, Receiver, Sender, RecvError}; | 6 | use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; |
7 | use failure::{bail, format_err}; | ||
8 | use failure_derive::Fail; | ||
11 | use gen_lsp_server::{ | 9 | use gen_lsp_server::{ |
12 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, | 10 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, |
13 | }; | 11 | }; |
@@ -15,11 +13,9 @@ use languageserver_types::NumberOrString; | |||
15 | use ra_analysis::{Canceled, FileId, LibraryData}; | 13 | use ra_analysis::{Canceled, FileId, LibraryData}; |
16 | use ra_vfs::VfsTask; | 14 | use ra_vfs::VfsTask; |
17 | use rayon; | 15 | use rayon; |
18 | use threadpool::ThreadPool; | ||
19 | use rustc_hash::FxHashSet; | 16 | use rustc_hash::FxHashSet; |
20 | use serde::{de::DeserializeOwned, Serialize}; | 17 | use serde::{de::DeserializeOwned, Serialize}; |
21 | use failure::{format_err, bail}; | 18 | use threadpool::ThreadPool; |
22 | use failure_derive::Fail; | ||
23 | 19 | ||
24 | use crate::{ | 20 | use crate::{ |
25 | main_loop::subscriptions::Subscriptions, | 21 | main_loop::subscriptions::Subscriptions, |
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 | ||
3 | use gen_lsp_server::ErrorCode; | 3 | use gen_lsp_server::ErrorCode; |
4 | use languageserver_types::{ | 4 | use 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 | }; |
12 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; | 11 | use ra_analysis::{ |
13 | use ra_syntax::{TextUnit, text_utils::intersect}; | 12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, |
13 | }; | ||
14 | use ra_syntax::{text_utils::intersect, TextUnit}; | ||
14 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 15 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
15 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
16 | use serde_json::to_value; | 17 | use 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 | ||
120 | pub fn handle_document_symbol( | 127 | pub fn handle_document_symbol( |