Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/ide/src/lib.rs | 5 | ||||
| -rw-r--r-- | crates/ide/src/matching_brace.rs | 6 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/handlers/request.rs | 14 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/lsp/ext.rs | 2 |
4 files changed, 16 insertions, 11 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 81a771fec8..0bcd033412 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -366,7 +366,10 @@ impl Analysis { /// Returns position of the matching brace (all types of braces are /// supported). - pub fn matching_brace(&self, position: FilePosition) -> Cancellable<Option<TextSize>> { + pub fn matching_brace( + &self, + position: FilePosition, + ) -> Cancellable<Option<(TextSize, TextSize)>> { self.with_db(|db| { let file_id = EditionedFileId::current_edition(&self.db, position.file_id); let parse = db.parse(file_id); diff --git a/crates/ide/src/matching_brace.rs b/crates/ide/src/matching_brace.rs index b2b91d6e3c..faf3642942 100644 --- a/crates/ide/src/matching_brace.rs +++ b/crates/ide/src/matching_brace.rs @@ -14,7 +14,7 @@ use syntax::{ // | VS Code | **rust-analyzer: Find matching brace** | // //  -pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> { +pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<(TextSize, TextSize)> { const BRACES: &[SyntaxKind] = &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]]; let (brace_token, brace_idx) = file @@ -35,7 +35,7 @@ pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<Text .children_with_tokens() .filter_map(|it| it.into_token()) .find(|node| node.kind() == matching_kind && node != &brace_token)?; - Some(matching_node.text_range().start()) + Some((brace_token.text_range().start(), matching_node.text_range().start())) } #[cfg(test)] @@ -51,7 +51,7 @@ mod tests { let parse = SourceFile::parse(&before, span::Edition::CURRENT); let new_pos = match matching_brace(&parse.tree(), pos) { None => pos, - Some(pos) => pos, + Some(pos) => pos.1, }; let actual = add_cursor(&before, new_pos); assert_eq_text!(after, &actual); diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index dddddcec5d..eccf374421 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -395,7 +395,7 @@ pub(crate) fn handle_selection_range( pub(crate) fn handle_matching_brace( snap: GlobalStateSnapshot, params: lsp_ext::MatchingBraceParams, -) -> anyhow::Result<Vec<Position>> { +) -> anyhow::Result<Vec<Option<(Position, Position)>>> { let _p = tracing::info_span!("handle_matching_brace").entered(); let file_id = try_default!(from_proto::file_id(&snap, ¶ms.text_document.uri)?); let line_index = snap.file_line_index(file_id)?; @@ -405,11 +405,13 @@ pub(crate) fn handle_matching_brace( .map(|position| { let offset = from_proto::offset(&line_index, position); offset.map(|offset| { - let offset = match snap.analysis.matching_brace(FilePosition { file_id, offset }) { - Ok(Some(matching_brace_offset)) => matching_brace_offset, - Err(_) | Ok(None) => offset, - }; - to_proto::position(&line_index, offset) + match snap.analysis.matching_brace(FilePosition { file_id, offset }) { + Ok(Some((a, b))) => Some(( + to_proto::position(&line_index, a), + to_proto::position(&line_index, b), + )), + Err(_) | Ok(None) => None, + } }) }) .collect() diff --git a/crates/rust-analyzer/src/lsp/ext.rs b/crates/rust-analyzer/src/lsp/ext.rs index 729ac4678b..63c77e5d18 100644 --- a/crates/rust-analyzer/src/lsp/ext.rs +++ b/crates/rust-analyzer/src/lsp/ext.rs @@ -383,7 +383,7 @@ pub enum MatchingBrace {} impl Request for MatchingBrace { type Params = MatchingBraceParams; - type Result = Vec<Position>; + type Result = Vec<Option<(Position, Position)>>; const METHOD: &'static str = "experimental/matchingBrace"; } |