diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-21 10:14:10 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-21 10:14:10 +0100 |
commit | 57608ecd9d202323dc610d52a80bd3bccbefc172 (patch) | |
tree | 8837e4192d6121115a5a9b94044d33bd683184b2 /crates/ra_lsp_server | |
parent | 31b7697cf6f4ebb4ebc35b055e6b4ad9a28e28e9 (diff) | |
parent | fa12ed2b8f3466af88644e59127cd169549f8899 (diff) |
Merge #1179
1179: switch to official extend selection API r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/caps.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 47 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 22 |
5 files changed, 72 insertions, 3 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index bc181e4eb..c855d6f68 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -15,7 +15,7 @@ crossbeam-channel = "0.3.5" | |||
15 | flexi_logger = "0.11.0" | 15 | flexi_logger = "0.11.0" |
16 | log = "0.4.3" | 16 | log = "0.4.3" |
17 | url_serde = "0.2.0" | 17 | url_serde = "0.2.0" |
18 | lsp-types = "0.56.0" | 18 | lsp-types = "0.57.0" |
19 | rustc-hash = "1.0" | 19 | rustc-hash = "1.0" |
20 | parking_lot = "0.7.0" | 20 | parking_lot = "0.7.0" |
21 | 21 | ||
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index 2af2b89fe..f6d2b75e7 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -2,7 +2,7 @@ use lsp_types::{ | |||
2 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, | 2 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, |
3 | ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, | 3 | ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, |
4 | ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, | 4 | ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, |
5 | TextDocumentSyncOptions, ImplementationProviderCapability, | 5 | TextDocumentSyncOptions, ImplementationProviderCapability, GenericCapability, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | pub fn server_capabilities() -> ServerCapabilities { | 8 | pub fn server_capabilities() -> ServerCapabilities { |
@@ -37,6 +37,7 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
37 | first_trigger_character: "=".to_string(), | 37 | first_trigger_character: "=".to_string(), |
38 | more_trigger_character: Some(vec![".".to_string()]), | 38 | more_trigger_character: Some(vec![".".to_string()]), |
39 | }), | 39 | }), |
40 | selection_range_provider: Some(GenericCapability::default()), | ||
40 | folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), | 41 | folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), |
41 | rename_provider: Some(RenameProviderCapability::Options(RenameOptions { | 42 | rename_provider: Some(RenameProviderCapability::Options(RenameOptions { |
42 | prepare_provider: Some(true), | 43 | prepare_provider: Some(true), |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 07ac4917a..dc1f8f3f7 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -297,6 +297,7 @@ fn on_request( | |||
297 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? | 297 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? |
298 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? | 298 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? |
299 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? | 299 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? |
300 | .on::<req::SelectionRangeRequest>(handlers::handle_selection_range)? | ||
300 | .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? | 301 | .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? |
301 | .on::<req::JoinLines>(handlers::handle_join_lines)? | 302 | .on::<req::JoinLines>(handlers::handle_join_lines)? |
302 | .on::<req::OnEnter>(handlers::handle_on_enter)? | 303 | .on::<req::OnEnter>(handlers::handle_on_enter)? |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index eb8a53545..530081494 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -11,7 +11,7 @@ use ra_ide_api::{ | |||
11 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, | 11 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, |
12 | AssistId, | 12 | AssistId, |
13 | }; | 13 | }; |
14 | use ra_syntax::{AstNode, SyntaxKind, TextUnit}; | 14 | use ra_syntax::{AstNode, SyntaxKind, TextUnit, TextRange}; |
15 | use ra_prof::profile; | 15 | use ra_prof::profile; |
16 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
17 | use serde::{Serialize, Deserialize}; | 17 | use serde::{Serialize, Deserialize}; |
@@ -39,10 +39,15 @@ pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> | |||
39 | Ok(res) | 39 | Ok(res) |
40 | } | 40 | } |
41 | 41 | ||
42 | // FIXME: drop this API | ||
42 | pub fn handle_extend_selection( | 43 | pub fn handle_extend_selection( |
43 | world: ServerWorld, | 44 | world: ServerWorld, |
44 | params: req::ExtendSelectionParams, | 45 | params: req::ExtendSelectionParams, |
45 | ) -> Result<req::ExtendSelectionResult> { | 46 | ) -> Result<req::ExtendSelectionResult> { |
47 | log::error!( | ||
48 | "extend selection is deprecated and will be removed soon, | ||
49 | use the new selection range API in LSP", | ||
50 | ); | ||
46 | let file_id = params.text_document.try_conv_with(&world)?; | 51 | let file_id = params.text_document.try_conv_with(&world)?; |
47 | let line_index = world.analysis().file_line_index(file_id); | 52 | let line_index = world.analysis().file_line_index(file_id); |
48 | let selections = params | 53 | let selections = params |
@@ -55,6 +60,46 @@ pub fn handle_extend_selection( | |||
55 | Ok(req::ExtendSelectionResult { selections }) | 60 | Ok(req::ExtendSelectionResult { selections }) |
56 | } | 61 | } |
57 | 62 | ||
63 | pub fn handle_selection_range( | ||
64 | world: ServerWorld, | ||
65 | params: req::SelectionRangeParams, | ||
66 | ) -> Result<Vec<req::SelectionRange>> { | ||
67 | let file_id = params.text_document.try_conv_with(&world)?; | ||
68 | let line_index = world.analysis().file_line_index(file_id); | ||
69 | params | ||
70 | .positions | ||
71 | .into_iter() | ||
72 | .map_conv_with(&line_index) | ||
73 | .map(|position| { | ||
74 | let mut ranges = Vec::new(); | ||
75 | { | ||
76 | let mut range = TextRange::from_to(position, position); | ||
77 | loop { | ||
78 | ranges.push(range); | ||
79 | let frange = FileRange { file_id, range }; | ||
80 | let next = world.analysis().extend_selection(frange)?; | ||
81 | if next == range { | ||
82 | break; | ||
83 | } else { | ||
84 | range = next | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | let mut range = req::SelectionRange { | ||
89 | range: ranges.last().unwrap().conv_with(&line_index), | ||
90 | parent: None, | ||
91 | }; | ||
92 | for r in ranges.iter().rev().skip(1) { | ||
93 | range = req::SelectionRange { | ||
94 | range: r.conv_with(&line_index), | ||
95 | parent: Some(Box::new(range)), | ||
96 | } | ||
97 | } | ||
98 | Ok(range) | ||
99 | }) | ||
100 | .collect() | ||
101 | } | ||
102 | |||
58 | pub fn handle_find_matching_brace( | 103 | pub fn handle_find_matching_brace( |
59 | world: ServerWorld, | 104 | world: ServerWorld, |
60 | params: req::FindMatchingBraceParams, | 105 | params: req::FindMatchingBraceParams, |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 4f35ab9b5..6090eb7b9 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -64,6 +64,28 @@ pub struct ExtendSelectionResult { | |||
64 | pub selections: Vec<Range>, | 64 | pub selections: Vec<Range>, |
65 | } | 65 | } |
66 | 66 | ||
67 | pub enum SelectionRangeRequest {} | ||
68 | |||
69 | impl Request for SelectionRangeRequest { | ||
70 | type Params = SelectionRangeParams; | ||
71 | type Result = Vec<SelectionRange>; | ||
72 | const METHOD: &'static str = "textDocument/selectionRange"; | ||
73 | } | ||
74 | |||
75 | #[derive(Deserialize, Debug)] | ||
76 | #[serde(rename_all = "camelCase")] | ||
77 | pub struct SelectionRangeParams { | ||
78 | pub text_document: TextDocumentIdentifier, | ||
79 | pub positions: Vec<Position>, | ||
80 | } | ||
81 | |||
82 | #[derive(Serialize, Debug)] | ||
83 | #[serde(rename_all = "camelCase")] | ||
84 | pub struct SelectionRange { | ||
85 | pub range: Range, | ||
86 | pub parent: Option<Box<SelectionRange>>, | ||
87 | } | ||
88 | |||
67 | pub enum FindMatchingBrace {} | 89 | pub enum FindMatchingBrace {} |
68 | 90 | ||
69 | impl Request for FindMatchingBrace { | 91 | impl Request for FindMatchingBrace { |