Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Show documentation on hover for symbols defined in the same module #691

Merged
merged 2 commits into from
Sep 2, 2020

Conversation

wz1000
Copy link
Collaborator

@wz1000 wz1000 commented Jul 12, 2020

When parsing a module, if parsing haddocks succeeds, then use them
Previously, even though we were parsing modules twice, with and without
haddocks, we were just returning the result of parsing without haddocks.

The reason for this was that Opt_KeepRawTokenStream and Opt_Haddock do
not interact nicely. We decided that for now it was better to fix an
actual issue and then solve the problem when hlint requires a module
with Opt_KeepRawTokenStream.

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.

I had this in my list of things to fix. Thank you @wz1000 !

@@ -50,6 +50,9 @@ type instance RuleResult GetDependencies = TransitiveDependencies
-- that module.
data TcModuleResult = TcModuleResult
{ tmrModule :: TypecheckedModule
-- ^ warning, the ModIface in the tm_checked_module_info of the
-- TypecheckedModule will always be Nothing, use the ModIface in the
-- HomeModInfo instead
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very helpful, thanks!

@pepeiborra
Copy link
Collaborator

(a test would be very nice)

@wz1000
Copy link
Collaborator Author

wz1000 commented Jul 12, 2020

@pepeiborra the test already existed :)

(good to see a CI failure because of unexpected success !)

Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

I’m fine with this change but it needs to be configurable in ideOptions. We already have HLint integration in DAML that would be broken by this.

@jneira
Copy link
Member

jneira commented Jul 16, 2020

In hls we are about to add hlint support including refactoring and it will be broken with this. Could be return both version of the parsed modules and make hlint (and other tools that needs the original parsed module version) use the existing one?
It would duplicate the memory used (not sure it it could be an issue), but only if you are using hlint.

I think @shayne_fletcher mentioned some wip to make compatible the parsing with haddock options though.

@wz1000
Copy link
Collaborator Author

wz1000 commented Jul 16, 2020

@jneira I'm confused, this patch is already included in the branch of ghcide that hls is using.

@jneira
Copy link
Member

jneira commented Jul 16, 2020

Yeah, but as we have to make it optional for daml hlint i was proposing another way to do it: make two versions available at runtime instead only one or another using cpp.
I have to admit i haven't hit a issue in my tests of the hlint plugin that i can confirm it is caused by the haddock version of the parsed module.

But it could be added afterwards, if it is really needed, i suppose.

@pepeiborra
Copy link
Collaborator

@wz1000 I think we need a configuration option before this can be merged to avoid a breaking change, unless @cocreature no longer needs it

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 2, 2020

Ok, I can do that. However, I think @jneira has hlint working in the presence of this patch.

When parsing a module, if parsing haddocks succeeds, then use them
Previously, even though we were parsing modules twice, with and without
haddocks, we were just returning the result of parsing without haddocks.

The reason for this was that Opt_KeepRawTokenStream and Opt_Haddock do
not interact nicely. We decided that for now it was better to fix an
actual issue and then solve the problem when hlint requires a module
with Opt_KeepRawTokenStream.
@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 2, 2020

@pepeiborra done and rebased.

@jneira
Copy link
Member

jneira commented Sep 2, 2020

@wz1000 i've not seen any error using the hlint plugin + GetParsedModule in hls so far, using a ghcide version with this patch.
But @cocreature mentioned that they were incompatible, maybe cause they are using an older version?

@pepeiborra pepeiborra merged commit bfafe3b into haskell:master Sep 2, 2020
@cocreature
Copy link
Collaborator

They are not fully incompatible. But the haddock parsing options doesn’t include some stuff, e.g., extensions iirc so HLint won’t show you the corresponding hints if you use haddock parsing. That said, I don’t care all that much about those hints (neither here nor in DAML) so it’s probably reasonable to go for this approach for now. Hopefully, this will be addressed on GHC’s side at some point.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 3, 2020

Is it not possible to manually tell hlint about extensions etc. by extracting them from the dynflags?

/cc @ndmitchell

@ndmitchell
Copy link
Collaborator

You can tell HLint that the code should be parsed with the OverloadedStrings or GADTs extension just fine. So HLint will still be able to parse the file.

You can't tell HLint that the {-# LANGUAGE GADTs #-} pragma was used other than by it being in the source code. HLint can warn if certain extensions are unused, or duplicates, or imply other hints, so you wouldn't get those hints.

@pepeiborra
Copy link
Collaborator

Hlint also supports ANN pragmas for annotations which presumably need full tokens

pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…askell/ghcide#691)

* Show documentation on hover for symbols defined in the same module

When parsing a module, if parsing haddocks succeeds, then use them
Previously, even though we were parsing modules twice, with and without
haddocks, we were just returning the result of parsing without haddocks.

The reason for this was that Opt_KeepRawTokenStream and Opt_Haddock do
not interact nicely. We decided that for now it was better to fix an
actual issue and then solve the problem when hlint requires a module
with Opt_KeepRawTokenStream.

* Add option to decide which ParsedModule to return
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…askell/ghcide#691)

* Show documentation on hover for symbols defined in the same module

When parsing a module, if parsing haddocks succeeds, then use them
Previously, even though we were parsing modules twice, with and without
haddocks, we were just returning the result of parsing without haddocks.

The reason for this was that Opt_KeepRawTokenStream and Opt_Haddock do
not interact nicely. We decided that for now it was better to fix an
actual issue and then solve the problem when hlint requires a module
with Opt_KeepRawTokenStream.

* Add option to decide which ParsedModule to return
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…askell/ghcide#691)

* Show documentation on hover for symbols defined in the same module

When parsing a module, if parsing haddocks succeeds, then use them
Previously, even though we were parsing modules twice, with and without
haddocks, we were just returning the result of parsing without haddocks.

The reason for this was that Opt_KeepRawTokenStream and Opt_Haddock do
not interact nicely. We decided that for now it was better to fix an
actual issue and then solve the problem when hlint requires a module
with Opt_KeepRawTokenStream.

* Add option to decide which ParsedModule to return
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants