Skip to content

Commit 503f949

Browse files
committed
Follow matklad suggestions
- Move vis_offset() to utils.rs - Shorten explicit ra_syntax::ast -> ast - Undo refactoring exhaustive pattern to non-exhaustive
1 parent e75e2ae commit 503f949

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ra_syntax::{
99
};
1010
use test_utils::mark;
1111

12-
use crate::{AssistContext, AssistId, Assists};
12+
use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
1313

1414
// Assist: change_visibility
1515
//
@@ -70,13 +70,6 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
7070
})
7171
}
7272

73-
fn vis_offset(node: &SyntaxNode) -> TextSize {
74-
node.children_with_tokens()
75-
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
76-
.map(|it| it.text_range().start())
77-
.unwrap_or_else(|| node.text_range().start())
78-
}
79-
8073
fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
8174
if vis.syntax().text() == "pub" {
8275
let target = vis.syntax().text_range();

crates/ra_assists/src/handlers/fix_visibility.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ra_syntax::{
66
SyntaxNode, TextRange, TextSize,
77
};
88

9-
use crate::{AssistContext, AssistId, Assists};
9+
use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
1010

1111
// FIXME: this really should be a fix for diagnostic, rather than an assist.
1212

@@ -177,13 +177,6 @@ fn target_data_for_def(
177177
Some((offset, target, target_file, target_name))
178178
}
179179

180-
fn vis_offset(node: &SyntaxNode) -> TextSize {
181-
node.children_with_tokens()
182-
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
183-
.map(|it| it.text_range().start())
184-
.unwrap_or_else(|| node.text_range().start())
185-
}
186-
187180
#[cfg(test)]
188181
mod tests {
189182
use crate::tests::{check_assist, check_assist_not_applicable};

crates/ra_assists/src/handlers/merge_match_arms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
8181
}
8282

8383
fn contains_placeholder(a: &ast::MatchArm) -> bool {
84-
matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..)))
84+
matches!(a.pat(), Some(ast::Pat::PlaceholderPat(..)))
8585
}
8686

8787
#[cfg(test)]

crates/ra_assists/src/utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type};
77
use ra_ide_db::RootDatabase;
88
use ra_syntax::{
99
ast::{self, make, NameOwner},
10-
AstNode, SyntaxNode, T,
10+
AstNode,
11+
SyntaxKind::*,
12+
SyntaxNode, TextSize, T,
1113
};
1214
use rustc_hash::FxHashSet;
1315

@@ -120,6 +122,13 @@ pub(crate) fn resolve_target_trait(
120122
}
121123
}
122124

125+
pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize {
126+
node.children_with_tokens()
127+
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
128+
.map(|it| it.text_range().start())
129+
.unwrap_or_else(|| node.text_range().start())
130+
}
131+
123132
pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
124133
if let Some(expr) = invert_special_case(&expr) {
125134
return expr;

crates/ra_hir_def/src/nameres.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ impl ModuleOrigin {
137137
}
138138

139139
pub fn is_inline(&self) -> bool {
140-
matches!(self, ModuleOrigin::Inline { .. })
140+
match self {
141+
ModuleOrigin::Inline { .. } => true,
142+
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false,
143+
}
141144
}
142145

143146
/// Returns a node which defines this module.

0 commit comments

Comments
 (0)