rust-lang / rust-lang/rust-analyzer
Didn't `SyntaxEditor::add_annotation` consider change offset?
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I am working on an assist, but it seems that the SyntaxEditor::add_annotation #15710 has not taken into account any editing offset, which makes it difficult to use.
Is this normal?
|builder: &mut SourceChangeBuilder| {
let mut edit = builder.make_editor(fn_.syntax());
// Insert 2 byte whitespace
edit.insert(Position::before(fn_.syntax()), make::tokens::whitespace(" "));
if let Some(cap) = ctx.config.snippet_cap {
let annotation = builder.make_tabstop_after(cap);
edit.add_annotation(fn_.syntax(), annotation);
}
builder.add_file_edits(ctx.vfs_file_id(), edit);
},
Input:
impl Foo {
fn foo(&self) -> &i32 {
&self.0
}
}
Current output:
impl Foo {
fn foo(&self) -> &i32 {
&self.0
$0 }
}
Expect output:
impl Foo {
fn foo(&self) -> &i32 {
&self.0
}$0
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at SyntaxEditor::add_annotation and reproduce the SourceChangeBuilder example from the issue, including the two-byte whitespace insertion. Trace how the editing offset is handled for the annotation, then verify that the tabstop appears after the closing brace as shown in the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100