Skip to content

Commit b2b41df

Browse files
authored
hls-notes-plugin: Do not error if no note is under the cursor (#4136)
1 parent 82148dc commit b2b41df

File tree

1 file changed

+9
-7
lines changed
  • plugins/hls-notes-plugin/src/Ide/Plugin

1 file changed

+9
-7
lines changed

plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ jumpToNote state _ param
8484
=<< lift (LSP.getVirtualFile uriOrig)
8585
line <- err "Line not found in file" (listToMaybe $ Rope.lines $ fst
8686
(Rope.splitAtLine 1 $ snd $ Rope.splitAtLine (fromIntegral l) contents))
87-
note <- err "No note at this position" $ listToMaybe $
88-
mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line
89-
notes <- runActionE "notes.definedNotes" state $ useE MkGetNotes nfp
90-
(noteFp, pos) <- err ("Note definition (a comment of the form `{- Note [" <> note <> "]\\n~~~ ... -}`) not found") (HM.lookup note notes)
91-
pure $ InL (Definition (InL
92-
(Location (fromNormalizedUri $ normalizedFilePathToUri noteFp) (Range pos pos))
93-
))
87+
let noteOpt = listToMaybe $ mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line
88+
case noteOpt of
89+
Nothing -> pure (InR (InR Null))
90+
Just note -> do
91+
notes <- runActionE "notes.definedNotes" state $ useE MkGetNotes nfp
92+
(noteFp, pos) <- err ("Note definition (a comment of the form `{- Note [" <> note <> "]\\n~~~ ... -}`) not found") (HM.lookup note notes)
93+
pure $ InL (Definition (InL
94+
(Location (fromNormalizedUri $ normalizedFilePathToUri noteFp) (Range pos pos))
95+
))
9496
where
9597
uriOrig = toNormalizedUri $ param ^. (L.textDocument . L.uri)
9698
err s = maybe (throwError $ PluginInternalError s) pure

0 commit comments

Comments
 (0)