@@ -5,42 +5,6 @@ use ra_syntax::{
5
5
} ;
6
6
use crate :: assist_ctx:: { AssistCtx , Assist , AssistBuilder } ;
7
7
8
- // TODO: refactor this before merge
9
- mod formatting {
10
- use ra_syntax:: {
11
- AstNode , SyntaxNode ,
12
- ast:: { self , AstToken } ,
13
- algo:: generate,
14
- } ;
15
-
16
- /// If the node is on the beginning of the line, calculate indent.
17
- pub fn leading_indent ( node : & SyntaxNode ) -> Option < & str > {
18
- for leaf in prev_leaves ( node) {
19
- if let Some ( ws) = ast:: Whitespace :: cast ( leaf) {
20
- let ws_text = ws. text ( ) ;
21
- if let Some ( pos) = ws_text. rfind ( '\n' ) {
22
- return Some ( & ws_text[ pos + 1 ..] ) ;
23
- }
24
- }
25
- if leaf. leaf_text ( ) . unwrap ( ) . contains ( '\n' ) {
26
- break ;
27
- }
28
- }
29
- None
30
- }
31
-
32
- fn prev_leaves ( node : & SyntaxNode ) -> impl Iterator < Item = & SyntaxNode > {
33
- generate ( prev_leaf ( node) , |& node| prev_leaf ( node) )
34
- }
35
-
36
- fn prev_leaf ( node : & SyntaxNode ) -> Option < & SyntaxNode > {
37
- generate ( node. ancestors ( ) . find_map ( SyntaxNode :: prev_sibling) , |it| {
38
- it. last_child ( )
39
- } )
40
- . last ( )
41
- }
42
- }
43
-
44
8
fn collect_path_segments ( path : & ast:: Path ) -> Option < Vec < & ast:: PathSegment > > {
45
9
let mut v = Vec :: new ( ) ;
46
10
collect_path_segments_raw ( & mut v, path) ?;
@@ -461,7 +425,7 @@ fn make_assist_add_new_use(
461
425
edit : & mut AssistBuilder ,
462
426
) {
463
427
if let Some ( anchor) = anchor {
464
- let indent = formatting :: leading_indent ( anchor) ;
428
+ let indent = ra_fmt :: leading_indent ( anchor) ;
465
429
let mut buf = String :: new ( ) ;
466
430
if after {
467
431
buf. push_str ( "\n " ) ;
0 commit comments