-
-
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
A plugin for GADT syntax converter #2899
Conversation
getNextPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $ do | ||
ghcSession <- liftIO $ runAction "GADT.GhcSession" state $ useWithStale GhcSession nfp | ||
(_, fileContents) <- liftIO $ runAction "GADT.GetFileContents" state $ getFileContents nfp | ||
case ghcSession of |
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's from hls-alternate-number-format-plugin, we can't move this to hls-plugin-api unless hls-plugin-api has dependency of ghcide.
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 think it would be good to move the pragma-insertion logic to hls-plugin-api
from ghcide
, since it's a very common thing to want to do. Ideally we could wrap it all up in something like insertPragmaIfNotPresent
or something.
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.
Did you figure out whether there was anything sensible we can do to share code here? Or do you want to leave it as a follow-up?
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'm a little worried that the re-formatting logic looks quite complicated and version-dependent, is this going to be a pain to maintain?
_isPreferred = Nothing | ||
_disabled = Nothing | ||
_edit = Nothing | ||
_command = Just |
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.
Why are you doing the indirection via a command? You could just compute the edit in the code action handler and return it here!
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 don't think your command handler is significantly more expensive - I think it also mostly relies on the parsed module, which you also need here.
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 think users won't use this plugin in most cases, it's unfair to give GADT results every time for these cases.
getNextPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $ do | ||
ghcSession <- liftIO $ runAction "GADT.GhcSession" state $ useWithStale GhcSession nfp | ||
(_, fileContents) <- liftIO $ runAction "GADT.GetFileContents" state $ getFileContents nfp | ||
case ghcSession of |
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 think it would be good to move the pragma-insertion logic to hls-plugin-api
from ghcide
, since it's a very common thing to want to do. Ideally we could wrap it all up in something like insertPragmaIfNotPresent
or something.
format, and may have different ident size between constructors. | ||
|
||
Hence, we first use `printOutputable` to get an initial GADT syntax, | ||
then use `ghc-exactprint` to parse the initial result, and finally |
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.
Why aren't we just using exactprint for everything? 🤔
{-# LANGUAGE TupleSections #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# OPTIONS_GHC -Wno-missing-signatures #-} | ||
module Ide.Plugin.GHC where |
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 haven't really reviewed this, it seems complicated and we should probably get one of our exactprint experts to take a look.
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'm not an exactprint expert either, but I have no concerns about the code in this module since it is well commented and isolated in this plugin
See the next comment. |
I decide to keep the current design without a better substitute. Why?
data A where -- comment
-- comment
{- comment -} B | C {-comment-} |
D -- comment
deriving () Something like the above is hard to track its semantic place.
data (Eq a) => A a = B a after we convert to GADT syntax, it would be data A a BEqaaAa while using data A a
where
B :: (Eq a) => a -> A a and use this to continue later pretty adjustment. |
The re-formatting relies on the behavior of |
Can't agree more, but currently, pragma insertion functions have dependencies on |
I am not following this conversation, just wanted to make a few points:
Based on those points, I would rather extract the pragma insertion logic to |
Agree with your words. But maybe we can't extract pragma insertion logic from ghcide to hls-pragma-plugin, because hls-pragma-plugin has dependency of ghcide. I hope it's better to have a package like |
I don't see why this would be a problem
This is a fine option too. |
For some reason I thought we already had
This is non-haddock comments, right? Haddock comments should be attached to their piece of AST so shouldn't be too hard to put in the right place? I'm inclined to not worry about non-Haddock comments and just have that be a limitation of the plugin. Or have them all printed above the new declaration.
I don't understand this example. Why would we get nonsense from exactprint like you wrote? Surely if we construct a correct AST then exactprint should emit it properly?? |
All comments with
Agree.
Comments without their target are nonsense, I prefer abandon them.
It is because we printed an incomplete GADT decl, it only has a semantic presentation but all place info is for H98 decl, that's why I use |
I really don't understand what's going on, sorry :/ But it seems like we should be able to mess with the AST and print it out again nicely, I thought that was half the point of exactprint... Maybe @alanz can help us? |
Something that can convert ast's all absolute locations to relative locations is much helpful. I have been thinking about edit data constructors one by one instead of edit the whole data decl, maybe it can keep comments for us, I'll try this later. |
Don't have a feasible solution, I want to merge this and left improvement in the future. cc @michaelpj |
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.
Couple of nits, but otherwise I'm happy so long as you're on the hook for maintaining it, @July541 😆
getNextPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $ do | ||
ghcSession <- liftIO $ runAction "GADT.GhcSession" state $ useWithStale GhcSession nfp | ||
(_, fileContents) <- liftIO $ runAction "GADT.GetFileContents" state $ getFileContents nfp | ||
case ghcSession of |
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.
Did you figure out whether there was anything sensible we can do to share code here? Or do you want to leave it as a follow-up?
Sure, I'm glad to improve it if we have any better solution.
I forgot it, thank you point it out!
Currently not, let's leave it here, I have the same code in hls-class-plugin. I'll follow #2899 (comment), it's a big work but worth doing. |
* initial hls-gadt-plugin * Correct condition * Render context correctly * Fix typo * Support from ghc-8.6 to ghc-9.0 * ghc8.6 compat * Try to fix test for ghc-8.6 * Pretty name * Add GADTs pragma automatically * Enrich Readme * Clean up * Update hls docs * Update CODEOWNERS * Fix typo * Rename withTempDir with withCanonicalTempDir * Add @michaelpj's suggestions * Pass PluginId through descriptor * Explicit forall
This plugin is for #2261
Currently only work for ghc-9.2.Fully support now!Known limits:
Origin comments missing(I hope gives comments up since they are not easy to put in a proper place).(It's not handy, I'll try to keep some comments)It's hard to trace comments, so I decide to put it on hold.