mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +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> {
|
||||
const BRACES: &[SyntaxKind] =
|
||||
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]];
|
||||
let (brace_token, brace_idx) = file
|
||||
.syntax()
|
||||
.token_at_offset(offset)
|
||||
.filter_map(|node| {
|
||||
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
|
||||
Some((node, idx))
|
||||
})
|
||||
.next()?;
|
||||
let (brace_token, brace_idx) = file.syntax().token_at_offset(offset).find_map(|node| {
|
||||
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
|
||||
Some((node, idx))
|
||||
})?;
|
||||
let parent = brace_token.parent()?;
|
||||
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
|
||||
cov_mark::hit!(pipes_not_braces);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use hir::Semantics;
|
||||
use ide_db::base_db::{CrateId, FileId, FilePosition};
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{
|
||||
base_db::{CrateId, FileId, FilePosition},
|
||||
RootDatabase,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use syntax::{
|
||||
algo::find_node_at_offset,
|
||||
|
|
Loading…
Reference in a new issue