mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Add convenience functions to SourceChange for creating single edits
This commit is contained in:
parent
449eea1161
commit
22e1c7a112
4 changed files with 63 additions and 44 deletions
|
@ -31,12 +31,14 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
|
|||
let cursor_position = position.offset + TextUnit::of_str(&inserted);
|
||||
let mut edit = TextEditBuilder::default();
|
||||
edit.insert(position.offset, inserted);
|
||||
Some(SourceChange {
|
||||
label: "on enter".to_string(),
|
||||
source_file_edits: vec![SourceFileEdit { edit: edit.finish(), file_id: position.file_id }],
|
||||
file_system_edits: vec![],
|
||||
cursor_position: Some(FilePosition { offset: cursor_position, file_id: position.file_id }),
|
||||
})
|
||||
|
||||
Some(
|
||||
SourceChange::source_edit(
|
||||
"on enter",
|
||||
SourceFileEdit { edit: edit.finish(), file_id: position.file_id },
|
||||
)
|
||||
.with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }),
|
||||
)
|
||||
}
|
||||
|
||||
fn node_indent<'a>(file: &'a SourceFile, node: &SyntaxNode) -> Option<&'a str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue