# project: Fix ref-match rust completions dropping the leading & \(\#60521\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/001bda1a46af8a8e7d0abc89aaf67a6a1193426f)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 001bda1a46af8a8e7d0abc89aaf67a6a1193426f

Requested commit: 001bda1a46af8a8e7d0abc89aaf67a6a1193426f

Commit: 001bda1a46af8a8e7d0abc89aaf67a6a1193426f

Tree: 508d6507bb992adb5caddee308e024e0f6d617a0

Author: Smit Barmase

Committer: GitHub

## Message

```
project: Fix ref-match rust completions dropping the leading & (#60521)

Closes #56973, Follow-up for
https://github.com/zed-industries/zed/pull/56976

When a completion's `additionalTextEdits` contained a zero-width
insertion touching the edge of the primary edit, the overlap check
treated it as overlapping and silently skipped it. This broke
rust-analyzer's ref-match completions (`&foo`), which deliver the `&` as
a zero-width additional edit at the primary edit's start (#56973). The
same root cause previously broke auto-imports at the very start of a
file (#26136), which was worked around in #37746 with a special case for
edits at position (0, 0).

This PR replaces that special case with a general rule: a zero-width
additional edit only overlaps the primary edit when it falls strictly
inside it. i.e. touching the boundary is fine.

This one check handles both the file-start auto-import case and the `&`
ref-match case, so the (0, 0) workaround from #37746 is removed.
Non-insertion edits still go through the original overlap check from
#1871.

Added three regression tests:
- the file-start auto-import (#26136)
-  the `&` insertion at the primary edit's start (#56973)
- overlapping edits being skipped while non-overlapping ones apply
(general skip case)

Release Notes:

- Fixed rust-analyzer completions like `&some_var` inserting only the
variable name and dropping the leading `&` when accepted.
```

## Parents

- [d9ada8487bca20be32c7621e296030c9d68362f5](https://git.cafe/gitcafe/zed/commit/d9ada8487bca20be32c7621e296030c9d68362f5?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/001bda1a46af8a8e7d0abc89aaf67a6a1193426f?format=markdown)
