mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
simplify
This commit is contained in:
parent
e5e6c363dc
commit
3da52d2e93
2 changed files with 8 additions and 10 deletions
|
@ -19,14 +19,10 @@ use syntax::{
|
||||||
pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> {
|
pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> {
|
||||||
const BRACES: &[SyntaxKind] =
|
const BRACES: &[SyntaxKind] =
|
||||||
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]];
|
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]];
|
||||||
let (brace_token, brace_idx) = file
|
let (brace_token, brace_idx) = file.syntax().token_at_offset(offset).find_map(|node| {
|
||||||
.syntax()
|
|
||||||
.token_at_offset(offset)
|
|
||||||
.filter_map(|node| {
|
|
||||||
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
|
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
|
||||||
Some((node, idx))
|
Some((node, idx))
|
||||||
})
|
})?;
|
||||||
.next()?;
|
|
||||||
let parent = brace_token.parent()?;
|
let parent = brace_token.parent()?;
|
||||||
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
|
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
|
||||||
cov_mark::hit!(pipes_not_braces);
|
cov_mark::hit!(pipes_not_braces);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use ide_db::base_db::{CrateId, FileId, FilePosition};
|
use ide_db::{
|
||||||
use ide_db::RootDatabase;
|
base_db::{CrateId, FileId, FilePosition},
|
||||||
|
RootDatabase,
|
||||||
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::find_node_at_offset,
|
algo::find_node_at_offset,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue