Repository navigation
notes: don't report an error for positions past the last line - #5175
Open
swinilohani616-dot wants to merge 1 commit into
Open
swinilohani616-dot wants to merge 1 commit into
swinilohani616-dot wants to merge 1 commit into
Conversation
Hovering on the empty line after a file's final newline made the notes plugin answer with "Internal Error: Line not found in file". Editors that request hovers at the cursor, like Emacs with eldoc, showed this constantly. There can't be a note reference on a line the file doesn't have, so treat it as "no note" instead of an error. This also covers go-to-definition and find-references, which share getNote. Fixes haskell#5063
fendor
approved these changes
Nov 13, 2026
fendor
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thank you for the contribution!
I have one question I would like to know more about, and one nitpick about the comment.
Comment on lines
+116
to
+118
| pure $ case lineAt (fromIntegral l) contents of | ||
| Nothing -> Nothing | ||
| Just line -> listToMaybe $ mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line |
Collaborator
There was a problem hiding this comment.
How does ghcide-hover-and-symbols respond to all positions accurately? Could we share code with ghcide instead of the pattern matching?
Comment on lines
+113
to
+115
| -- Clients can ask about a line the file doesn't have, such as the empty | ||
| -- line after the final newline, where the cursor rests at the end of the | ||
| -- buffer. There is no note reference there, so this is not an error. |
Collaborator
There was a problem hiding this comment.
The file has the line, it lineAt just strips it away if it is empty, right?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5063.
If you hover on the empty line after a file's final newline, the notes plugin answers with
notes: Internal Error: Line not found in file. In editors that ask for a hover wherever the cursor is,like Emacs with eldoc, that pops up all the time when you're typing at the end of a file.
The problem was in
getNote: whenlineAtcouldn't find the line, it raised an internal error. Therecan't be a note reference on a line the file doesn't have, so now it just returns "no note". Go-to-definition
and find-references go through
getNotetoo, so they're fixed as well.I added a hover test for the empty line after
HoverNote.hs's final newline. It turns off ghcide's ownhover for that test, because otherwise ghcide's successful empty answer hides the notes plugin's error.
Without the fix the test fails with the exact error from the issue, and with it all the notes tests pass.
I also checked it by hand in VS Code with HLS built from this branch: Show Hover on the last empty line
no longer returns an error.