pub struct SourceChangeBuilder {
pub edit: TextEditBuilder,
pub file_id: FileId,
pub source_change: SourceChange,
pub command: Option<Command>,
pub file_editors: FxHashMap<FileId, SyntaxEditor>,
pub snippet_annotations: Vec<(AnnotationSnippet, SyntaxAnnotation)>,
pub mutated_tree: Option<TreeMutator>,
pub snippet_builder: Option<SnippetBuilder>,
}
Fields§
§edit: TextEditBuilder
§file_id: FileId
§source_change: SourceChange
§command: Option<Command>
§file_editors: FxHashMap<FileId, SyntaxEditor>
Keeps track of all edits performed on each file
snippet_annotations: Vec<(AnnotationSnippet, SyntaxAnnotation)>
Keeps track of which annotations correspond to which snippets
mutated_tree: Option<TreeMutator>
Maps the original, immutable SyntaxNode
to a clone_for_update
twin.
snippet_builder: Option<SnippetBuilder>
Keeps track of where to place snippets
Implementations§
source§impl SourceChangeBuilder
impl SourceChangeBuilder
pub fn new(file_id: impl Into<FileId>) -> SourceChangeBuilder
pub fn edit_file(&mut self, file_id: impl Into<FileId>)
pub fn make_editor(&self, node: &SyntaxNode) -> SyntaxEditor
pub fn add_file_edits(&mut self, file_id: impl Into<FileId>, edit: SyntaxEditor)
pub fn make_placeholder_snippet(&mut self, _cap: SnippetCap) -> SyntaxAnnotation
pub fn make_tabstop_before(&mut self, _cap: SnippetCap) -> SyntaxAnnotation
pub fn make_tabstop_after(&mut self, _cap: SnippetCap) -> SyntaxAnnotation
pub fn make_mut<N: AstNode>(&mut self, node: N) -> N
sourcepub fn make_syntax_mut(&mut self, node: SyntaxNode) -> SyntaxNode
pub fn make_syntax_mut(&mut self, node: SyntaxNode) -> SyntaxNode
Returns a copy of the node
, suitable for mutation.
Syntax trees in rust-analyzer are typically immutable, and mutating operations panic at runtime. However, it is possible to make a copy of the tree and mutate the copy freely. Mutation is based on interior mutability, and different nodes in the same tree see the same mutations.
The typical pattern for an assist is to find specific nodes in the read
phase, and then get their mutable counterparts using make_mut
in the
mutable state.
sourcepub fn insert(&mut self, offset: TextSize, text: impl Into<String>)
pub fn insert(&mut self, offset: TextSize, text: impl Into<String>)
Append specified text
at the given offset
sourcepub fn replace(&mut self, range: TextRange, replace_with: impl Into<String>)
pub fn replace(&mut self, range: TextRange, replace_with: impl Into<String>)
Replaces specified range
of text with a given string.
pub fn replace_ast<N: AstNode>(&mut self, old: N, new: N)
pub fn create_file(&mut self, dst: AnchoredPathBuf, content: impl Into<String>)
pub fn move_file(&mut self, src: impl Into<FileId>, dst: AnchoredPathBuf)
sourcepub fn trigger_parameter_hints(&mut self)
pub fn trigger_parameter_hints(&mut self)
Triggers the parameter hint popup after the assist is applied
sourcepub fn add_tabstop_before(&mut self, _cap: SnippetCap, node: impl AstNode)
pub fn add_tabstop_before(&mut self, _cap: SnippetCap, node: impl AstNode)
Adds a tabstop snippet to place the cursor before node
sourcepub fn add_tabstop_after(&mut self, _cap: SnippetCap, node: impl AstNode)
pub fn add_tabstop_after(&mut self, _cap: SnippetCap, node: impl AstNode)
Adds a tabstop snippet to place the cursor after node
sourcepub fn add_tabstop_before_token(&mut self, _cap: SnippetCap, token: SyntaxToken)
pub fn add_tabstop_before_token(&mut self, _cap: SnippetCap, token: SyntaxToken)
Adds a tabstop snippet to place the cursor before token
sourcepub fn add_tabstop_after_token(&mut self, _cap: SnippetCap, token: SyntaxToken)
pub fn add_tabstop_after_token(&mut self, _cap: SnippetCap, token: SyntaxToken)
Adds a tabstop snippet to place the cursor after token
sourcepub fn add_placeholder_snippet(&mut self, _cap: SnippetCap, node: impl AstNode)
pub fn add_placeholder_snippet(&mut self, _cap: SnippetCap, node: impl AstNode)
Adds a snippet to move the cursor selected over node
sourcepub fn add_placeholder_snippet_token(
&mut self,
_cap: SnippetCap,
token: SyntaxToken,
)
pub fn add_placeholder_snippet_token( &mut self, _cap: SnippetCap, token: SyntaxToken, )
Adds a snippet to move the cursor selected over token
sourcepub fn add_placeholder_snippet_group(
&mut self,
_cap: SnippetCap,
nodes: Vec<SyntaxNode>,
)
pub fn add_placeholder_snippet_group( &mut self, _cap: SnippetCap, nodes: Vec<SyntaxNode>, )
Adds a snippet to move the cursor selected over nodes
This allows for renaming newly generated items without having to go through a separate rename step.
pub fn finish(self) -> SourceChange
Auto Trait Implementations§
impl Freeze for SourceChangeBuilder
impl !RefUnwindSafe for SourceChangeBuilder
impl !Send for SourceChangeBuilder
impl !Sync for SourceChangeBuilder
impl Unpin for SourceChangeBuilder
impl !UnwindSafe for SourceChangeBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Cast for T
impl<T> Cast for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more