Follow matklad suggestions
- Move vis_offset() to utils.rs - Shorten explicit ra_syntax::ast -> ast - Undo refactoring exhaustive pattern to non-exhaustive
This commit is contained in:
parent
e75e2ae5b6
commit
503f9498cd
@ -9,7 +9,7 @@
|
||||
};
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{AssistContext, AssistId, Assists};
|
||||
use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
|
||||
|
||||
// Assist: change_visibility
|
||||
//
|
||||
@ -70,13 +70,6 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
})
|
||||
}
|
||||
|
||||
fn vis_offset(node: &SyntaxNode) -> TextSize {
|
||||
node.children_with_tokens()
|
||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
||||
.map(|it| it.text_range().start())
|
||||
.unwrap_or_else(|| node.text_range().start())
|
||||
}
|
||||
|
||||
fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
|
||||
if vis.syntax().text() == "pub" {
|
||||
let target = vis.syntax().text_range();
|
||||
|
@ -6,7 +6,7 @@
|
||||
SyntaxNode, TextRange, TextSize,
|
||||
};
|
||||
|
||||
use crate::{AssistContext, AssistId, Assists};
|
||||
use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
|
||||
|
||||
// FIXME: this really should be a fix for diagnostic, rather than an assist.
|
||||
|
||||
@ -177,13 +177,6 @@ fn offset_target_and_file_id<S, Ast>(
|
||||
Some((offset, target, target_file, target_name))
|
||||
}
|
||||
|
||||
fn vis_offset(node: &SyntaxNode) -> TextSize {
|
||||
node.children_with_tokens()
|
||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
||||
.map(|it| it.text_range().start())
|
||||
.unwrap_or_else(|| node.text_range().start())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::{check_assist, check_assist_not_applicable};
|
||||
|
@ -81,7 +81,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
|
||||
}
|
||||
|
||||
fn contains_placeholder(a: &ast::MatchArm) -> bool {
|
||||
matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..)))
|
||||
matches!(a.pat(), Some(ast::Pat::PlaceholderPat(..)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -7,7 +7,9 @@
|
||||
use ra_ide_db::RootDatabase;
|
||||
use ra_syntax::{
|
||||
ast::{self, make, NameOwner},
|
||||
AstNode, SyntaxNode, T,
|
||||
AstNode,
|
||||
SyntaxKind::*,
|
||||
SyntaxNode, TextSize, T,
|
||||
};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
@ -120,6 +122,13 @@ pub(crate) fn resolve_target_trait(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize {
|
||||
node.children_with_tokens()
|
||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
||||
.map(|it| it.text_range().start())
|
||||
.unwrap_or_else(|| node.text_range().start())
|
||||
}
|
||||
|
||||
pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
|
||||
if let Some(expr) = invert_special_case(&expr) {
|
||||
return expr;
|
||||
|
@ -137,7 +137,10 @@ pub fn file_id(&self) -> Option<FileId> {
|
||||
}
|
||||
|
||||
pub fn is_inline(&self) -> bool {
|
||||
matches!(self, ModuleOrigin::Inline { .. })
|
||||
match self {
|
||||
ModuleOrigin::Inline { .. } => true,
|
||||
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a node which defines this module.
|
||||
|
Loading…
Reference in New Issue
Block a user