# lsp: Filter out-of-bounds inlay hints \(\#64659\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 532532bb804fc535dad54358eef714a5a45ed09f

Requested commit: 532532bb804fc535dad54358eef714a5a45ed09f

Commit: 532532bb804fc535dad54358eef714a5a45ed09f

Tree: 42b4b4b391afbb6a4c1ec9eb1bf1798c76948e2d

Author: HuaGu-Dragon

Committer: GitHub

## Message

```
lsp: Filter out-of-bounds inlay hints (#64659)

# Objective

Fix the filtering of inlay hints around the buffer bounds.

The per-chunk range filter compared anchors, and anchor order includes
the bias.
A parameter hint (`anchor_before`) clamped to the end of the buffer
sorted before the chunk's end anchor and was kept, while a type/other
hint (`anchor_after`) exactly at the end of a file without a trailing
newline compared equal to it and was dropped.

Also remove the redundant `anyhow::Result` and `async` from the
LSP-to-project inlay hint conversion.

## Solution

- Drop LSP inlay hints whose line is past the last buffer row before
converting them.
Positions past a line's end are still clipped to the line end, as the
LSP spec prescribes for `Position.character`.
- Compare offsets instead of anchors in the per-chunk range filter, so
it does not depend on the hint's anchor bias, and treat the range end as
inclusive when it is the end of the buffer.
- Make `lsp_to_project_hint` a pure function over a `BufferSnapshot`.
The resolve path now converts the response against the same snapshot the
request position was produced from.

## Testing

- `test_inlay_hints_at_buffer_bounds`: row overflow for both hint kinds,
column overflow clipping on a non-last row, and a type hint exactly at
the buffer end.
  Fails on `main` on the row overflow and the buffer end cases.
- An out-of-bounds parameter hint added to the collab
`test_inlay_hint_refresh_is_forwarded`.
- Manually verified that rust-analyzer's closing brace hint appears
after the final `}` of a file without a trailing newline.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed inlay hints positioned past the end of the buffer being shown on
its last line, and inlay hints exactly at the end of a file without a
trailing newline being hidden.

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
```

## Parents

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

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