zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
48.9k stars 2.94k forks source link

LSP auto completions are offered mid-word and results broken completions #18582

Open jansol opened 3 weeks ago

jansol commented 3 weeks ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Consider the following:

enum Menu {
  EggsWithBacon,
  EggsWithSpam,
}

let breakfast = Menu::EggsWithSpam;

Now if you navigate the cursor to this position:

let breakfast = Menu::EggsWith|Spam;

then trigger a LSP completion and pick Menu::EggsWithBacon instead, the state after completion becomes

let breakfast = Menu::EggsWithBacon|Spam;

Which is not the desired completion, in fact it's not even valid code (if you are lucky). Instead of this I would expect that if completions are done with the cursor in the middle of an identifier, the entire original identifier is deleted and the cursor is placed at the end of the completed identifier, so


let breakfast = Menu::EggsWithBacon|;

Environment

Zed: v0.156.0 (Zed Dev 7ce8797d78794f5a53e7a7d113e4c14a65e6297f) OS: Linux Wayland ubuntu 24.04 Memory: 31.3 GiB Architecture: x86_64 GPU: Radeon Vega Frontier Edition (RADV VEGA10) || radv || Mesa 24.0.9-0ubuntu0.1

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

No response

notpeter commented 3 weeks ago

I'm try to reproduce this, but was unable (MacOS, Zed Nightly 0.156.0).

My steps:

mkdir /tmp/issue18582
cd $_
cargo init
zed . src/main.rs

Make src/main.rs like this:

enum Menu {
    EggsWithBacon,
    EggsWithSpam,
}

fn main() {
    let breakfast = Menu::EggsWithSpam;
}

I position the cursor between 'With' and 'Spam' and trigger completions ("editor: show completions" from the command palette) and I don't get completions at all.

jansol commented 3 weeks ago

What if you start typing instead? I was able to repro this on Preview on macOS by inserting "B" at that location and picking from the popup that appeared then. I don't normally use the manual trigger command since the default hotkey conflicts with the default combination for switching between keyboard languages.

EDIT: I do get the completion popup at that position even without typing if I go through the command palette, though.

CharlesChen0823 commented 3 weeks ago

I tested in windows, behaviour same as linux. with current master

Zed: v0.156.0 (Zed Dev 1be24f77396aaade46739218e70cb059491aaedf) OS: Windows 10.0.22631 Memory: 63.2 GiB Architecture: x86_64 GPU: AMD Radeon(TM) Graphics || AMD proprietary driver || 24.7.1 (AMD proprietary shader compiler)

notpeter commented 3 weeks ago

I was able to repro this on Preview on macOS by inserting "B" at that location and picking from the popup that appeared then.

That's the magic. I can reproduce. Thanks image

For reference, VSCode does not offer completions when typing mid-word so they don't have this problem.

jansol commented 3 weeks ago

VSCode does not offer completions when typing mid-word so they don't have this problem

I would like to keep this functionality though, it's very handy when working with long enum or define names that have a shared prefix.