Skip to content

Commit

Permalink
hls-notes-plugin: Do not error if no note is under the cursor (#4136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbruegge committed Mar 18, 2024
1 parent 82148dc commit b2b41df
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ jumpToNote state _ param
=<< lift (LSP.getVirtualFile uriOrig)
line <- err "Line not found in file" (listToMaybe $ Rope.lines $ fst
(Rope.splitAtLine 1 $ snd $ Rope.splitAtLine (fromIntegral l) contents))
note <- err "No note at this position" $ listToMaybe $
mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line
notes <- runActionE "notes.definedNotes" state $ useE MkGetNotes nfp
(noteFp, pos) <- err ("Note definition (a comment of the form `{- Note [" <> note <> "]\\n~~~ ... -}`) not found") (HM.lookup note notes)
pure $ InL (Definition (InL
(Location (fromNormalizedUri $ normalizedFilePathToUri noteFp) (Range pos pos))
))
let noteOpt = listToMaybe $ mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line
case noteOpt of
Nothing -> pure (InR (InR Null))
Just note -> do
notes <- runActionE "notes.definedNotes" state $ useE MkGetNotes nfp
(noteFp, pos) <- err ("Note definition (a comment of the form `{- Note [" <> note <> "]\\n~~~ ... -}`) not found") (HM.lookup note notes)
pure $ InL (Definition (InL
(Location (fromNormalizedUri $ normalizedFilePathToUri noteFp) (Range pos pos))
))
where
uriOrig = toNormalizedUri $ param ^. (L.textDocument . L.uri)
err s = maybe (throwError $ PluginInternalError s) pure
Expand Down

0 comments on commit b2b41df

Please sign in to comment.