-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Completion document format #2848
Conversation
ghcide/test/exe/Main.hs
Outdated
test doc (Position 1 7) "id" (Just $ T.length expected) [expected] | ||
] | ||
where | ||
broken = knownBrokenForGhcVersions [GHC90, GHC92] "Completion doc doesn't support ghc9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:o do we have a ticket for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just found this
haskell-language-server/ghcide/src/Development/IDE/Spans/Documentation.hs
Lines 104 to 122 in da0379b
getDocumentation | |
:: HasSrcSpan name | |
=> [ParsedModule] -- ^ All of the possible modules it could be defined in. | |
-> name -- ^ The name you want documentation for. | |
-> [T.Text] | |
-- This finds any documentation between the name you want | |
-- documentation for and the one before it. This is only an | |
-- approximately correct algorithm and there are easily constructed | |
-- cases where it will be wrong (if so then usually slightly but there | |
-- may be edge cases where it is very wrong). | |
-- TODO : Build a version of GHC exactprint to extract this information | |
-- more accurately. | |
-- TODO : Implement this for GHC 9.2 with in-tree annotations | |
-- (alternatively, just remove it and rely soley on GHC's parsing) | |
getDocumentation sources targetName = fromMaybe [] $ do | |
#if MIN_VERSION_ghc(9,2,0) | |
Nothing | |
#else | |
-- Find the module the target is defined in. |
, ghc9.0 test fails on my machine, so I marked it as broken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this code path is only used to get documentation for local completions (from the same module). I dont' think that it is being used in your test.
Are you in Mac OS? Some ghc 9.x distributions are shipping without interface haddocks
where | ||
go [] uris = spanDocUrisToMarkdown uris | ||
go txt uris = init txt <> [render (last txt)] <> spanDocUrisToMarkdown uris | ||
-- If the doc is not end with an `'\n'`, we append it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is a bit confusing, because we have a collection of lines, some of them ending with newlines. The old comment is correct, we do need two newlines to get a paragraph break in markdown, but that works out here because T.unlines [ "foo\n", "bar" ]
will end up with two newlines. Confusing.
In fact, should the lines ever have trailing newlines? That seems odd.
I wonder if it would be simpler if this function just dealt with a single Text
representing the whole piece of doc. AFAICT it would be fine if spanDocToMarkdown
returned just a Text
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Two newlines to get a new paragraph is correct, but one
\n
is enough to get a section separator(xxx\n***\nxxx) - My idea is: we just ensure the last line should end up with
\n
, so the separator can rendered correctly.haskell-language-server/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Lines 211 to 213 in da0379b
documentation = Just $ CompletionDocMarkup $ MarkupContent MkMarkdown $ T.intercalate sectionSeparator docs'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be simpler if this function just dealt with a single Text representing the whole piece of doc. AFAICT it would be fine if spanDocToMarkdown returned just a Text.
Unfortunately, spanDocToMarkdown
is both used in completion and hover, and they have different UI(completion uses section separator, hover uses new line), so we can't return a Text
in spanDocToMarkdown
. Furthermore, the final documentation is the combination of Defined in
, haddock, and source link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it return a list of sections then? Please add a Haddock comment clarifying what spanDocToMarkdown
returns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Failure reason:
I'll remove doc test instead of just testing whether the defined doc( |
I began to doubt the necessity of so many tests. In fact, it was just testing whether the "defined doc" ended with '\ n'. |
This could be the same as Mac OS, where the ghc 9.2.1 and ghc 9.0.2 distributions shipped without haddock docs in interfaces: https://gitlab.haskell.org/ghc/ghc/-/issues/20903
Preferably keep the full test, mark it as broken, and then add a reduced test that only checks for the final |
OK, doc tests should exist, I'll check each ghc and platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix, and for reworking the broken tests support in the testsuite 😍 !
-- Return a list `Text` includes haddock, document uri and source code uri, | ||
-- each item can be empty and must end with '\\n' if exist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to explain why each item must end with a newline.
Also, I don't think all the items end with a newline - the ones produced by spanDocUrisToMarkdown
don't, do they ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to explain why each item must end with a newline.
Done.
Also, I don't think all the items end with a newline - the ones produced by spanDocUrisToMarkdown don't, do they ?
Latest commit added an extra render to make sure every item ends with a newline, even uri markdowns.
* Fix doc display * Fix doc display * Add tests * Fix broken tests * Remove extra docs * Rerun tests * Add spanDocToMarkdown doc * Fix tests * Adjust test for broken target * Fix test * Fix broken tests * Unify tests * Update spanDocToMarkdown doc Co-authored-by: Pepe Iborra <[email protected]>
* Fix doc display * Fix doc display * Add tests * Fix broken tests * Remove extra docs * Rerun tests * Add spanDocToMarkdown doc * Fix tests * Adjust test for broken target * Fix test * Fix broken tests * Unify tests * Update spanDocToMarkdown doc Co-authored-by: Pepe Iborra <[email protected]>
This pr contributes to repairing broken markdown format in completion documents, and close #683 since this bug does not exist.
The function
spanDocToMarkdown
is both used in completion and hover, hover looks well, let's look at the tests.Here are some comparations:
Scenario 1
Scenario 2
Scenario 3