Closed RoloEdits closed 1 week ago
this loooks like a rust-analyzer bug. Lsp has two modes of returning completion edits: One simple mode where the lsp has to figure out what text to replace and an explicit mode where the lsp specifies the range.
RA always uses the explicit mode and all the setting does is switch between the two edits. In this case the edit RA provides is simply off by one so it's an off by one bug in rust-analyzer not in helix. Particularly these completions inside derive macros are new so I am not too surprised. It may also be a RA limitation since sered uses string literals.
A better case is you start with a file where the word is partially already written out and enter insertmode (so entirely new completion).
use chrono::serde::ts_milliseconds;
use chrono::{DateTime, Utc};
use serde::Deserialize;
#[derive(Deserialize)]
struct A {
#[serde(with = "ts_mill")]
time: DateTime<Utc>,
}
fn main() {
println!("Hello, world!");
}
it completes ts_milliseconds
and you endup with ts_millts_milliseconds
. This has nothing to do with complteon replace btw. Completion replace is about the remainedr of the word (to the right) not about keeping prefixes around (that would be stupid). Both the insert and replace completion text edit returned by RA are identical and don't replace any text.
Summary
When trying to add the
with
attribute forserde
, the completion menu popped up, but when selected, the replacement was off by 1 character; the first remained.Not sure if its related but #10689 also seems to be an off-by-one, with that pointing to #10279 that was a fix for an off-by-one.
Reproduction Steps
![helix_auto_complete_in_string](https://github.com/helix-editor/helix/assets/12489689/a5c9f52e-4bea-48d5-9c4f-f839e428e0de) ```toml completion-replace = true ``` ```toml [dependencies] serde = { version = "1", features = ["derive"]} chrono ={ version = "0.4", features = ["serde"]} ``` ```rust use chrono::serde::ts_milliseconds; use chrono::{DateTime, Utc}; use serde::Deserialize; #[derive(Deserialize)] struct A { #[serde(with = "tts_milliseconds")] time: DateTime~/.cache/helix/helix.log
```log 2024-06-21T15:55:44.186 helix_lsp::transport [INFO] rust-analyzer <- {"jsonrpc":"2.0","id":11,"result":[]} 2024-06-21T15:55:44.186 helix_lsp::transport [INFO] rust-analyzer <- [] 2024-06-21T15:55:44.186 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0 2024-06-21T15:55:44.452 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0 2024-06-21T15:55:44.516 helix_term::application [DEBUG] received editor event: IdleTimer 2024-06-21T15:55:44.610 helix_lsp::transport [INFO] rust-analyzer -> {"jsonrpc":"2.0","method":"completionItem/resolve","params":{"additionalTextEdits":[],"deprecated":false,"documentation":{"kind":"markdown","value":"Ser/de to/from timestamps in milliseconds\n\nIntended for use with `serde`s `with` attribute.\n\n# Example\n\n```rust\nuse chrono::serde::ts_milliseconds;\n#[derive(Deserialize, Serialize)]\nstruct S {\n #[serde(with = \"ts_milliseconds\")]\n time: DateTime