rust-lang / rust-lang/rust-analyzer
`additionalTextEdits` used on the same line as the main `textEdit`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
This issue was prompted by https://gitlab.gnome.org/GNOME/gnome-builder/-/issues/1406.
RA currently uses additionalTextEdits to remove certain things when completing snippets.
Example 1
fn main() {
10.dbg|
// Expands to dbg!(10)
}
The dbg completion looks like this:
Click to expand
{
"label": "dbg",
"kind": 15,
"detail": "dbg!(expr)",
"deprecated": false,
"filterText": "dbg",
"insertTextFormat": 2,
"textEdit": {
"range": {
"start": {
"line": 1,
"character": 7
},
"end": {
"line": 1,
"character": 10
}
},
"newText": "dbg!(10)"
},
"additionalTextEdits": [
{
"range": {
"start": {
"line": 1,
"character": 4
},
"end": {
"line": 1,
"character": 7
}
},
"newText": ""
}
]
}
where the additional text edit removes the 10.
Example 2
trait T {
fn hello();
}
Struct S;
impl T for S {
fn|
// Expands to:
// fn hello() {
//
// }
}
The completion looks similar to example 1, here the initial fn is removed.
Click to expand
{
"label": "fn hello()",
"kind": 3,
"deprecated": false,
"sortText": "ffffffff",
"filterText": "hello",
"insertTextFormat": 2,
"textEdit": {
"newText": "fn hello() {\n $0\n}",
"insert": {
"start": {
"line": 12,
"character": 7
},
"end": {
"line": 12,
"character": 7
}
},
"replace": {
"start": {
"line": 12,
"character": 7
},
"end": {
"line": 12,
"character": 7
}
}
},
"additionalTextEdits": [
{
"range": {
"start": {
"line": 12,
"character": 4
},
"end": {
"line": 12,
"character": 7
}
},
"newText": ""
}
]
}
The LSP Spec currently discourages using additionalTextEdits on the cursor line. (See documentation of additionalTextEdits.
Relevant issues:
- https://github.com/microsoft/language-server-protocol/issues/543
- https://github.com/microsoft/vscode/issues/21836
Would it be possible to make those edits using only the main textEdit somehow?
Thanks!
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
Review the completion implementation that produces the shown textEdit and additionalTextEdits, then compare its behavior with the LSP completion-item specification and the two examples in this issue. Done means the same-line removals can be represented without additionalTextEdits on the cursor line while preserving the displayed completion results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100