Skip to content

notes: don't report an error for positions past the last line - #5175

Open
swinilohani616-dot wants to merge 1 commit into
haskell:masterfrom
swinilohani616-dot:notes-hover-final-line
Open

swinilohani616-dot wants to merge 1 commit into
haskell:masterfrom
swinilohani616-dot:notes-hover-final-line

Conversation

@swinilohani616-dot

Copy link
Copy Markdown

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: when lineAt couldn't find the line, it raised an internal error. There
can'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 getNote too, 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 own
hover 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.

  • 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

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 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 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

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.

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.

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.

The file has the line, it lineAt just strips it away if it is empty, right?

This branch has not been deployed

No deployments
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.

notes: "Internal Error: Line not found in file" when hovering the empty line after a file's final newline

2 participants