This commit is contained in:
Lukas Wirth 2021-05-15 17:22:39 +02:00
parent e5e6c363dc
commit 3da52d2e93
2 changed files with 8 additions and 10 deletions

View file

@ -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);

View file

@ -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,