Skip to content

supermaven: Improve completion caching and position validation#37047

Merged
notpeter merged 1 commit intozed-industries:mainfrom
raphaelluethy:main
Aug 29, 2025
Merged

supermaven: Improve completion caching and position validation#37047
notpeter merged 1 commit intozed-industries:mainfrom
raphaelluethy:main

Conversation

@raphaelluethy
Copy link
Copy Markdown
Contributor

@raphaelluethy raphaelluethy commented Aug 27, 2025

Closes #36981

  • Add completion text and position caching to reduce redundant API calls
  • Only trigger new completion requests on text changes, not cursor movement
  • Validate cursor position to ensure completions show at correct location
  • Improve end-of-line range calculation for more accurate deletions
  • Extract reset_completion_cache helper for cleaner code organization
  • Update completion diff algorithm documentation for clarity

Edit: Sorry this is the 2nd PR, I forgot that the forks history was messy; I cherrypicked and cleaned it properly with this PR

Release Notes:

  • supermaven: Improved caching of predictions
  • supermaven: Fixed an issue where changing cursor position would incorrectly trigger new completions

- Add completion text and position caching to reduce redundant API calls
- Only trigger new completion requests on text changes, not cursor movement
- Validate cursor position to ensure completions show at correct location
- Improve end-of-line range calculation for more accurate deletions
- Extract reset_completion_cache helper for cleaner code organization
- Update completion diff algorithm documentation for clarity
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Aug 27, 2025
@maxdeviant maxdeviant changed the title Supermaven: improve completion caching and position validation supermaven: Improve completion caching and position validation Aug 27, 2025
@SomeoneToIgnore SomeoneToIgnore added the area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features label Aug 29, 2025
@notpeter
Copy link
Copy Markdown
Contributor

notpeter commented Aug 29, 2025

I was able to get Supermaven setup and reproduce this nasty bug described in #36981.

This PR fixes that. I'm not immediately sure about the caching implementation, but it seems to work. Definitely better than the status quo.

I don't know if this is related / pre-existing, but if I moved the cursor away and back to the previous cursor position it shows the cached completion. But if I move >10 lines away it doesn't?

Screen.Recording.2025-08-29.at.16.05.33.mov

Thank you @raphaelluethy for the followup.

@notpeter notpeter merged commit fcc3d10 into zed-industries:main Aug 29, 2025
27 checks passed
@notpeter notpeter self-assigned this Aug 29, 2025
tidely pushed a commit to tidely/zed that referenced this pull request Sep 10, 2025
…ndustries#37047)

Closes zed-industries#36981 

- Add completion text and position caching to reduce redundant API calls
- Only trigger new completion requests on text changes, not cursor
movement
- Validate cursor position to ensure completions show at correct
location
- Improve end-of-line range calculation for more accurate deletions
- Extract reset_completion_cache helper for cleaner code organization
- Update completion diff algorithm documentation for clarity

Edit: Sorry this is the 2nd PR, I forgot that the forks history was
messy; I cherrypicked and cleaned it properly with this PR

Release Notes:

- supermaven: Improved caching of predictions
- supermaven: Fixed an issue where changing cursor position would
incorrectly trigger new completions
benbrandt added a commit that referenced this pull request Mar 17, 2026
Closes #37836

This behavior was already fixed for Supermaven in #37047, but is still
present in Copilot. What's actually happening:
- Receive a multi-line edit prediction
- Dismiss it with escape
- Clicking anywhere in the editor below the cursor calls
`Editor::select` which starts out by calling `Editor::hide_context_menu`
-> `Editor::update_visible_edit_prediction`, bringing back the
prediction that was just dismissed and updating the editor's display map
- The subsequent selection logic in `Editor::select` now operates using
a display map that is inconsistent with what the user saw when clicking
- If the click was anywhere where the prediction inlay used to be,
`Editor::select` thinks the user clicked on the inlay and does nothing,
and the inlay reappears
- If the click was below where the prediction inlay used to be, the
inlay is immediately removed again but the cursor is moved to the wrong
position because the inlay temporarily added a vertical offset to all
lines after it in the buffer

Ultimately, `Editor::select` should be handling the user input using the
same display map that the user saw when making the input. This can
obviously be solved in multiple ways, I chose to clear the current
completions in `CopilotCompletionProvider::discard` such that any
subsequent calls to `Editor::update_visible_edit_prediction` doesn't
immediately nullify the dismissal of the edit prediction by the user.

Note that this also changes the behavior that occurs after dismissing an
edit prediction, moving to a different position in the buffer, and then
returning: currently, this resurfaces the dismissed edit prediction
(which the `test_copilot` test exercises), and after this change it
doesn’t. This current behavior didn't seem desirable to me because it
doesn't happen when using Zeta or Supermaven, but if we want to keep it,
then we could fix the incorrect selection behavior some other way.

Release Notes:

- Fixed bug that resurfaced dismissed Copilot edit predictions when
moving the cursor around

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI: Intrusive completions on click / cursor movement

3 participants