feat: add hls-document-link-plugin to support LSP document links#4898
Open
jetjinser wants to merge 5 commits intohaskell:masterfrom
Open
feat: add hls-document-link-plugin to support LSP document links#4898jetjinser wants to merge 5 commits intohaskell:masterfrom
hls-document-link-plugin to support LSP document links#4898jetjinser wants to merge 5 commits intohaskell:masterfrom
Conversation
hls-document-link-plugin to support LSP document links
fendor
requested changes
Apr 18, 2026
Comment on lines
+28
to
+32
| [ (SimilarDocumentLink | ||
| (DocumentLink (Range (Position 0 10) (Position 0 13)) | ||
| (Just (Uri "GHC-Types.html#t:Int")) | ||
| Nothing | ||
| Nothing)), |
Collaborator
There was a problem hiding this comment.
These could most likely benefit from some helpers. E.g.,:
Suggested change
| [ (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
Comment on lines
+68
to
+69
| goldenTest :: TestName -> FilePath -> [SimilarDocumentLink] -> TestTree | ||
| goldenTest title file expected = testCase title $ runWithDocumentLink filehs $ do |
Comment on lines
+98
to
+99
| -- custom Eq to ignore some details, such as specific URI | ||
| -- not symmetry |
Collaborator
There was a problem hiding this comment.
Suggested change
| -- 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. |
Comment on lines
+1
to
+2
| import Data.Maybe (fromJust, fromMaybe) | ||
| f = (fromJust, fromMaybe) |
Collaborator
There was a problem hiding this comment.
Would this also work with constructors? E.g., Just or Nothing
Comment on lines
+61
to
+63
| pretty = \case { | ||
| LogShake shakeLog -> pretty shakeLog | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| 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 |
Collaborator
There was a problem hiding this comment.
Suggested change
| 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 |
Collaborator
There was a problem hiding this comment.
Suggested change
| foldAst lookup ast = case (nodeChildren ast) of | |
| foldAst lookup ast = case nodeChildren ast of |
Comment on lines
+108
to
+109
| foldAst :: forall a t. Monoid a => ((Identifier, Span) -> a) -> HieAST t -> a | ||
| foldAst lookup ast = case (nodeChildren ast) of |
Collaborator
There was a problem hiding this comment.
Some docs would be nice, what is this folding over?
Collaborator
|
Also, I am wondering whether this has any overlap with #4746 and the |
Collaborator
Screencast_20260418_150352.webmThis is the behaviour on vscode... I suppose that's not the expected behaviour? |
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.
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.