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 showDocumentation command. #452

Merged
merged 6 commits into from
Sep 7, 2021
Merged

Conversation

pranaysashank
Copy link
Contributor

@pranaysashank pranaysashank commented Sep 5, 2021

It is not a perfect solution but I think it's a bit better than having an empty webview

Fix showDocumentation command

I removed the iframe and instead pass the html directly to the webview.

I had to set base url to the documentation directory so that the css files can be fetched properly.

The links in the opened documentation are broken and they can't be opened in the webview (at least I couldn't figure out how to do that), when you click on a link it opens it it the users browser but because we have base url set, the opened link points to something like https://file+.vscode-resource.vscode-webview.net/nix/store/n104dcsv7gc8l7c2mc2lixp220il8lk8-ghc-8.10.4-doc/share/doc/ghc/html/libraries/base-4.14.1.0/Control-Monad.html#t:Monad.

An alternative is to have the css files required for correct haddocks rendering in the extension itself, this can be done if the css file (linuwial.css) is the same for every library. This way we can set the base url to hackage docs and the external links should work fine.

New config option

Added a new configuration option openDocumentationInHackage which if set to true will always open documentation in user's browser on hackage and not in the webview.

Future work

  • Noticed that the source urls on my filesystem are different from the ones on hackage. For example,
    on my system: file:///nix/store/n104dcsv7gc8l7c2mc2lixp220il8lk8-ghc-8.10.4-doc/share/doc/ghc/html/libraries/mtl-2.2.2/src/Control-Monad-Reader-Class.html#t:MonadReader
    vs on hackage: https://hackage.haskell.org/package/mtl-2.2.2/docs/src/Control.Monad.Reader.Class.html#MonadReader (notice the .s vs the -s).
    This can be fixed in the processLink function. (Fixed in c59ae94)

  • It'll also be nice to have a separate command for showSource and a corresponding configuration option to either always view it in vscode vs hackage. (Added openSourceInHackage setting in c8f7039)

- Instead of using an iframe to render the content, we read
 and pass the html content to the webview.
- Refactor showDocumentation and openDocumentationOnHackage functions.
@pranaysashank
Copy link
Contributor Author

Forgot to mention, but there also doesn't seem to be a way to support navigation inside webview so links like (.../Control-Monad-Reader-Class.html#MonadReader) do not navigate to #MonadReader they just stay at the top of the file.

Probably better to always open the documentation on hackage

@jneira
Copy link
Member

jneira commented Sep 5, 2021

many thanks for trying to fix it, as you commented the limitations makes more reliable open docs in hackage, so I would set the config option to true by default

@pranaysashank
Copy link
Contributor Author

Pushed two commits to set the config option to true by default and fix the source file urls.

- Changed the regex so it only matches the last /*.html.
- Hard code the src directory in the hackage url.
@pranaysashank
Copy link
Contributor Author

This should now also fix #360. Please let me know if this change breaks any other working links.

@jneira
Copy link
Member

jneira commented Sep 7, 2021

Lets merge this, many thanks!

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.

Command "haskell.showDocumentation" not working Module documentation has broken link "Open on Hackage"
2 participants