Skip to content
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

Merged
merged 16 commits into from
Apr 26, 2022
Merged

Conversation

July541
Copy link
Collaborator

@July541 July541 commented Apr 22, 2022

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

old1

new1


Scenario 2

old2

new2


Scenario 3

old3

new3

@July541 July541 requested a review from pepeiborra as a code owner April 22, 2022 13:59
test doc (Position 1 7) "id" (Just $ T.length expected) [expected]
]
where
broken = knownBrokenForGhcVersions [GHC90, GHC92] "Completion doc doesn't support ghc9"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

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

Copy link
Collaborator

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.
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Two newlines to get a new paragraph is correct, but one \n is enough to get a section separator(xxx\n***\nxxx)
  2. My idea is: we just ensure the last line should end up with \n, so the separator can rendered correctly.
    documentation = Just $ CompletionDocMarkup $
    MarkupContent MkMarkdown $
    T.intercalate sectionSeparator docs'

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@July541
Copy link
Collaborator Author

July541 commented Apr 24, 2022

Failure reason:

  • windows-ghc9.2 can't deal with extern doc (ubuntu-ghc9.2 works fine)
  • ubuntu-ghc9.0 can't deal with local doc

I'll remove doc test instead of just testing whether the defined doc(Defined at) ends with '\n', it weakens the test power:(

@July541
Copy link
Collaborator Author

July541 commented Apr 24, 2022

Failure reason:

  • windows-ghc9.2 can't deal with extern doc (ubuntu-ghc9.2 works fine)
  • ubuntu-ghc9.0 can't deal with local doc

I'll remove doc test instead of just testing whether the defined doc(Defined at) ends with '\n', it weakens the test power:(

I began to doubt the necessity of so many tests. In fact, it was just testing whether the "defined doc" ended with '\ n'.

@pepeiborra
Copy link
Collaborator

Failure reason:

  • windows-ghc9.2 can't deal with extern doc (ubuntu-ghc9.2 works fine)

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

  • ubuntu-ghc9.0 can't deal with local doc

I'll remove doc test instead of just testing whether the defined doc(Defined at) ends with '\n', it weakens the test power:(

Preferably keep the full test, mark it as broken, and then add a reduced test that only checks for the final '\n'.

@July541
Copy link
Collaborator Author

July541 commented Apr 24, 2022

OK, doc tests should exist, I'll check each ghc and platform.

@July541 July541 marked this pull request as draft April 24, 2022 15:07
@July541 July541 marked this pull request as ready for review April 25, 2022 06:42
Copy link
Collaborator

@pepeiborra pepeiborra left a 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 😍 !

Comment on lines 83 to 84
-- Return a list `Text` includes haddock, document uri and source code uri,
-- each item can be empty and must end with '\\n' if exist.
Copy link
Collaborator

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 ?

Copy link
Collaborator Author

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.

@pepeiborra pepeiborra enabled auto-merge (squash) April 26, 2022 20:44
@pepeiborra pepeiborra merged commit 8f1a59c into haskell:master Apr 26, 2022
@July541 July541 deleted the completion-doc branch April 27, 2022 03:59
sloorush pushed a commit to sloorush/haskell-language-server that referenced this pull request May 21, 2022
* 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]>
hololeap pushed a commit to hololeap/haskell-language-server that referenced this pull request Aug 26, 2022
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completion provenance for local definition is Just ModuleName instead of just ModuleName
3 participants