55
66use std:: { collections:: hash_map:: Entry , fmt, iter, mem} ;
77
8- use crate :: imports:: insert_use:: { ImportScope , ImportScopeKind } ;
98use crate :: text_edit:: { TextEdit , TextEditBuilder } ;
109use crate :: { SnippetCap , assists:: Command , syntax_helpers:: tree_diff:: diff} ;
1110use base_db:: AnchoredPathBuf ;
@@ -16,7 +15,7 @@ use rustc_hash::FxHashMap;
1615use span:: FileId ;
1716use stdx:: never;
1817use syntax:: {
19- AstNode , SyntaxElement , SyntaxNode , SyntaxNodePtr , SyntaxToken , TextRange , TextSize ,
18+ AstNode , SyntaxElement , SyntaxNode , SyntaxToken , TextRange , TextSize ,
2019 syntax_editor:: { SyntaxAnnotation , SyntaxEditor } ,
2120} ;
2221
@@ -245,23 +244,6 @@ pub struct SnippetBuilder {
245244 places : Vec < PlaceSnippet > ,
246245}
247246
248- impl TreeMutator {
249- fn new ( immutable : & SyntaxNode ) -> TreeMutator {
250- let immutable = immutable. ancestors ( ) . last ( ) . unwrap ( ) ;
251- let mutable_clone = immutable. clone_for_update ( ) ;
252- TreeMutator { immutable, mutable_clone }
253- }
254-
255- fn make_mut < N : AstNode > ( & self , node : & N ) -> N {
256- N :: cast ( self . make_syntax_mut ( node. syntax ( ) ) ) . unwrap ( )
257- }
258-
259- fn make_syntax_mut ( & self , node : & SyntaxNode ) -> SyntaxNode {
260- let ptr = SyntaxNodePtr :: new ( node) ;
261- ptr. to_node ( & self . mutable_clone )
262- }
263- }
264-
265247impl SourceChangeBuilder {
266248 pub fn new ( file_id : impl Into < FileId > ) -> SourceChangeBuilder {
267249 SourceChangeBuilder {
@@ -366,34 +348,6 @@ impl SourceChangeBuilder {
366348 }
367349 }
368350
369- pub fn make_mut < N : AstNode > ( & mut self , node : N ) -> N {
370- self . mutated_tree . get_or_insert_with ( || TreeMutator :: new ( node. syntax ( ) ) ) . make_mut ( & node)
371- }
372-
373- pub fn make_import_scope_mut ( & mut self , scope : ImportScope ) -> ImportScope {
374- ImportScope {
375- kind : match scope. kind . clone ( ) {
376- ImportScopeKind :: File ( it) => ImportScopeKind :: File ( self . make_mut ( it) ) ,
377- ImportScopeKind :: Module ( it) => ImportScopeKind :: Module ( self . make_mut ( it) ) ,
378- ImportScopeKind :: Block ( it) => ImportScopeKind :: Block ( self . make_mut ( it) ) ,
379- } ,
380- required_cfgs : scope. required_cfgs . iter ( ) . map ( |it| self . make_mut ( it. clone ( ) ) ) . collect ( ) ,
381- }
382- }
383- /// Returns a copy of the `node`, suitable for mutation.
384- ///
385- /// Syntax trees in rust-analyzer are typically immutable, and mutating
386- /// operations panic at runtime. However, it is possible to make a copy of
387- /// the tree and mutate the copy freely. Mutation is based on interior
388- /// mutability, and different nodes in the same tree see the same mutations.
389- ///
390- /// The typical pattern for an assist is to find specific nodes in the read
391- /// phase, and then get their mutable counterparts using `make_mut` in the
392- /// mutable state.
393- pub fn make_syntax_mut ( & mut self , node : SyntaxNode ) -> SyntaxNode {
394- self . mutated_tree . get_or_insert_with ( || TreeMutator :: new ( & node) ) . make_syntax_mut ( & node)
395- }
396-
397351 /// Remove specified `range` of text.
398352 pub fn delete ( & mut self , range : TextRange ) {
399353 self . edit . delete ( range)
@@ -434,12 +388,6 @@ impl SourceChangeBuilder {
434388 self . add_snippet ( PlaceSnippet :: Before ( node. syntax ( ) . clone ( ) . into ( ) ) ) ;
435389 }
436390
437- /// Adds a tabstop snippet to place the cursor after `node`
438- pub fn add_tabstop_after ( & mut self , _cap : SnippetCap , node : impl AstNode ) {
439- assert ! ( node. syntax( ) . parent( ) . is_some( ) ) ;
440- self . add_snippet ( PlaceSnippet :: After ( node. syntax ( ) . clone ( ) . into ( ) ) ) ;
441- }
442-
443391 /// Adds a tabstop snippet to place the cursor before `token`
444392 pub fn add_tabstop_before_token ( & mut self , _cap : SnippetCap , token : SyntaxToken ) {
445393 assert ! ( token. parent( ) . is_some( ) ) ;
@@ -458,23 +406,6 @@ impl SourceChangeBuilder {
458406 self . add_snippet ( PlaceSnippet :: Over ( node. syntax ( ) . clone ( ) . into ( ) ) )
459407 }
460408
461- /// Adds a snippet to move the cursor selected over `token`
462- pub fn add_placeholder_snippet_token ( & mut self , _cap : SnippetCap , token : SyntaxToken ) {
463- assert ! ( token. parent( ) . is_some( ) ) ;
464- self . add_snippet ( PlaceSnippet :: Over ( token. into ( ) ) )
465- }
466-
467- /// Adds a snippet to move the cursor selected over `nodes`
468- ///
469- /// This allows for renaming newly generated items without having to go
470- /// through a separate rename step.
471- pub fn add_placeholder_snippet_group ( & mut self , _cap : SnippetCap , nodes : Vec < SyntaxNode > ) {
472- assert ! ( nodes. iter( ) . all( |node| node. parent( ) . is_some( ) ) ) ;
473- self . add_snippet ( PlaceSnippet :: OverGroup (
474- nodes. into_iter ( ) . map ( |node| node. into ( ) ) . collect ( ) ,
475- ) )
476- }
477-
478409 fn add_snippet ( & mut self , snippet : PlaceSnippet ) {
479410 let snippet_builder = self . snippet_builder . get_or_insert ( SnippetBuilder { places : vec ! [ ] } ) ;
480411 snippet_builder. places . push ( snippet) ;
@@ -553,9 +484,6 @@ enum PlaceSnippet {
553484 After ( SyntaxElement ) ,
554485 /// Place a placeholder snippet in place of the element
555486 Over ( SyntaxElement ) ,
556- /// Place a group of placeholder snippets which are linked together
557- /// in place of the elements
558- OverGroup ( Vec < SyntaxElement > ) ,
559487}
560488
561489impl PlaceSnippet {
@@ -564,9 +492,6 @@ impl PlaceSnippet {
564492 PlaceSnippet :: Before ( it) => vec ! [ Snippet :: Tabstop ( it. text_range( ) . start( ) ) ] ,
565493 PlaceSnippet :: After ( it) => vec ! [ Snippet :: Tabstop ( it. text_range( ) . end( ) ) ] ,
566494 PlaceSnippet :: Over ( it) => vec ! [ Snippet :: Placeholder ( it. text_range( ) ) ] ,
567- PlaceSnippet :: OverGroup ( it) => {
568- vec ! [ Snippet :: PlaceholderGroup ( it. into_iter( ) . map( |it| it. text_range( ) ) . collect( ) ) ]
569- }
570495 }
571496 }
572497}
0 commit comments