feat: add hls-document-link-plugin to support LSP document links#4898
feat: add hls-document-link-plugin to support LSP document links#4898jetjinser wants to merge 9 commits intohaskell:masterfrom
hls-document-link-plugin to support LSP document links#4898Conversation
hls-document-link-plugin to support LSP document links
| [ (SimilarDocumentLink | ||
| (DocumentLink (Range (Position 0 10) (Position 0 13)) | ||
| (Just (Uri "GHC-Types.html#t:Int")) | ||
| Nothing | ||
| Nothing)), |
There was a problem hiding this comment.
These could most likely benefit from some helpers. E.g.,:
| [ (SimilarDocumentLink | |
| (DocumentLink (Range (Position 0 10) (Position 0 13)) | |
| (Just (Uri "GHC-Types.html#t:Int")) | |
| Nothing | |
| Nothing)), | |
| [ (SimilarDocumentLink (mkDocLink (mkRange 0 10 0 13) (Uri "GHC-Types.html#t:Int")), |
Just a suggestion, feel free to ignore
| goldenTest :: TestName -> FilePath -> [SimilarDocumentLink] -> TestTree | ||
| goldenTest title file expected = testCase title $ runWithDocumentLink filehs $ do |
| -- custom Eq to ignore some details, such as specific URI | ||
| -- not symmetry |
There was a problem hiding this comment.
| -- custom Eq to ignore some details, such as specific URI | |
| -- not symmetry | |
| -- Custom Eq to ignore some details, such as specific URI. | |
| -- This is not a lawful instance as it doesn't obey the `symmetry` law. Use at your own risk and only in tests. |
| import Data.Maybe (fromJust, fromMaybe) | ||
| f = (fromJust, fromMaybe) |
There was a problem hiding this comment.
Would this also work with constructors? E.g., Just or Nothing
| pretty = \case { | ||
| LogShake shakeLog -> pretty shakeLog | ||
| } |
There was a problem hiding this comment.
| pretty = \case { | |
| LogShake shakeLog -> pretty shakeLog | |
| } | |
| pretty = \case | |
| LogShake shakeLog -> pretty shakeLog |
| defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \GetDocumentLinks nfp -> runMaybeT $ do | ||
| HAR {hieAst} <- useMT GetHieAst nfp | ||
| DKMap {getDocMap} <- useMT GetDocMap nfp | ||
| ast <- hoistMaybe $ getAsts hieAst Map.!? (HiePath . mkFastString . fromNormalizedFilePath) nfp |
There was a problem hiding this comment.
| ast <- hoistMaybe $ getAsts hieAst Map.!? (HiePath . mkFastString . fromNormalizedFilePath) nfp | |
| ast <- hoistMaybe $ getAsts hieAst Map.!? HiePath (mkFastString $ fromNormalizedFilePath nfp) |
Just weird bracketing for my taste, feel free to ignore.
| pure $ DocumentLinks (foldAst lookup ast) | ||
|
|
||
| foldAst :: forall a t. Monoid a => ((Identifier, Span) -> a) -> HieAST t -> a | ||
| foldAst lookup ast = case (nodeChildren ast) of |
There was a problem hiding this comment.
| foldAst lookup ast = case (nodeChildren ast) of | |
| foldAst lookup ast = case nodeChildren ast of |
| foldAst :: forall a t. Monoid a => ((Identifier, Span) -> a) -> HieAST t -> a | ||
| foldAst lookup ast = case (nodeChildren ast) of |
There was a problem hiding this comment.
Some docs would be nice, what is this folding over?
There was a problem hiding this comment.
Added documentation.
This implementation is actually adapted from the Semantic Tokens plugin.
|
Also, I am wondering whether this has any overlap with #4746 and the |
Screencast_20260418_150352.webmThis is the behaviour on vscode... I suppose that's not the expected behaviour? |
Yes. The links provided in this PR share the same source as the 'Documentation' links in the hover messages. The goal here is to expose that information through a more native and convenient LSP feature (DocumentLink). Therefore, documentLink provides a local hackage link, not the online link provided in #4746. |
I’ve done some local testing and noticed the same behavior in VSCodium.
EDIT: "workbench.externalUriOpeners": {
"file:///*": "simpleBrowser.open"
},Ideally, this might work? However, I still couldn't get it to open in either an internal or external browser. |
I think this might be a lsp consumer problem. I'm using Helix and by default all I wonder, what's the hueristic nvim uses to determine whether to open files with |
Nvim doesn't attempt any heuristics. It simply uses It's possible that Neovim doesn't have a particular reason to open HTML, while a GUI editor does, and the former distinguishes between |

This PR introduces a new plugin
hls-document-link-pluginthat adds LSP documentLink support to Haskell Language Server.This plugin automatically extracts documentation links for symbols in source code. These links are the same ones that power the
[Documentation]link in the hover information.Changes
hls-document-link-plugin– extracts clickable links and provides them as document links. Editors can then open these links directly from the source code.documentLinkOnoption to enable/disable the feature (default:True).Usage
In Neovim 0.12 or later, you can place the cursor on the link and press
gxto open it directly in your default browser.The feature can be turned off by setting
documentLinkOn: falsein the HLS configuration.Note. The
getDocumentLinkshelper forlsp-testis implemented manually here, but a same change is also pending in haskell/lsp#638. After that PR is merged and the dependency is updated, this part can be simplified.