Skip to content

Drop position mappings when a document is closed - #5170

Merged
crtschin merged 1 commit into
haskell:masterfrom
crtschin:crtschin/drop-position-mapping-on-close
Nov 9, 2026
Merged

crtschin merged 1 commit into
haskell:masterfrom
crtschin:crtschin/drop-position-mapping-on-close

Conversation

@crtschin

@crtschin crtschin commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #5163.

Some quick context.

  1. When opening a document, an editor sends a didOpen notification to HLS. This includes a version number $V_0$.
  2. On every edit, the editor sends didChange incrementing the version number $V_1, V_2, ..., V_n$

The main idea here is that the version number allows the server to stay in sync with the client even if it may be lagging behind in the file's contents, i.e. HLS uses the old contents of the file to answer a hover request and then uses the version numbers to then translate the hover request to what's active in the buffer. Lastly there's

  1. on closing a document, a didClose notification that closes the loop.

The behavior in the issue is due to the editor, on having previously opened, edited and closed a file ending at $V_n$, re-opens that file at version $V_0$. HLS stores the position mapping from the previous edit loop. So when the editor re-opens the file at version $V_0$, HLS will incorrectly use the translation from $V_0 \rightarrow V_n$ on the editor requests.

This PR fixes it by deleting the position mappings for the file, when we receive a didClose.


  • I read and followed our AI policy
  • I proposed a solution draft in the corresponding issue (for non-trivial changes and new features)
    • This is especially encouraged for new contributors

@crtschin
crtschin force-pushed the crtschin/drop-position-mapping-on-close branch from 52d31a9 to 92099fe Compare November 7, 2026 17:42
@crtschin
crtschin marked this pull request as ready for review November 7, 2026 19:49
@crtschin
crtschin requested a review from wz1000 as a code owner November 7, 2026 19:49
@crtschin
crtschin force-pushed the crtschin/drop-position-mapping-on-close branch from 92099fe to 2f26237 Compare November 7, 2026 19:49

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@crtschin
crtschin merged commit 328b403 into haskell:master Nov 9, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hover shows wrong positions after closing and reopening an edited file

2 participants