-
Notifications
You must be signed in to change notification settings - Fork 206
Conversation
First, thank you for this PR! It looks very promising. Is it possible that ormolu does not work with GHC versions below 8.6? |
Thanks @fendor! Mm yes it’s possible, currently I have only tested it in GHC 8.6.5... I’ll take a look on the Ormolu repo and the failing tests to see if I can make it work there. EDIT: Yes it’s an issue with |
Yeah, with the base restriction, I dont think it is possible with GHC versions below 8.6. |
@DavSanchez looks like you'll probably need to add ormolu to the |
I removed it because |
No, you can not disable the CI for certain tests. |
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.
Tests are still missing.
I suggest to use CPP guards to guard the implementation and provide noop formatters if ormolu is not available for the ghc version.
Ah, I didn't know you could insert C-like guards simply like that in Haskell code. I'll take a look and update the code accordingly. I'll also check As for the tests, yeah I don't have them at the moment, I'll add them during the holidays. |
Hi @fendor, if I guard the package imports in
At the moment my attempt just does |
@DavSanchez I think it would be better if we guard the functions in Ormolu, since we have to add the available formatters to the lsp-client, seemingly. iirc https://github.com/alanz/vscode-hie-server/blob/954e0a9ecc7be4d96bc71d05c65a730e642b65a6/package.json#L87. Maybe |
Hi again! A few questions. In the test suite ( How can I assert that a warning or error was emitted? This is for checking that a format selection action triggers the correct message. Also, should I make any tests for the noop formatter used when GHC < 8.6? |
@DavSanchez Sorry for the late response, I overlooked the notification. sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
formatDoc doc (FormattingOptions 2 True)
documentContents doc >>= liftIO . (`shouldBe` ormolu) For example, see the test-case in https://github.com/haskell/haskell-ide-engine/blob/master/test/functional/FormatSpec.hs#L49. You will test the noop formatter anyways, since the test-cases need to work across all CI jobs. formatDoc doc (FormattingOptions 2 True)
docContent <- documentContents doc
case ghcVersion of
GHC86 -> liftIO $ docContent `shouldBe` formattedOrmolu
_ -> liftIO $ docContent `shouldBe` unchangedDoc Tests relevant for hsimport are here: https://github.com/haskell/haskell-ide-engine/blob/master/test/functional/FunctionalCodeActionsSpec.hs#L529 hope this helps! (btw, did not try to compile any of the code snippets, might contain small errors but the idea is hopefully right) EDIT: Sending an error should in my opinion be done in |
I believe |
Looks like the tests for Happy new year everyone! 🎉 |
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.
The tests for hsimport https://github.com/haskell/haskell-ide-engine/blob/master/test/functional/FunctionalCodeActionsSpec.hs#L529 are missing.
Yeah, I’ll implement them in the next hours. |
Note, you will have problems with your implementation for format selection. I suggest, until @bubba disagrees, that format selection is a noop and that a warning is added to |
Co-Authored-By: Luke Lau <[email protected]>
Yeah but, what is exactly happening here? I would assume that the |
We should pass |
You mean adding them to the Cabal and/or Stack files for HIE or loading Ormolu as a submodule and doing it there? Why is it necessary? |
@DavSanchez while @Avi-D-coder is right, we will postpone this for now. None of the other formatters is doing this correctly at the moment, anyways, as far as I know. We can improve it iteratively. |
@DavSanchez Ormolu formats code differently if certain extensions or ghc options are enabled. E.g |
@fendor do we cache ghc flags anywhere or should we just call whatever function |
@Avi-D-coder We are currently not caching the results of |
@fendor I'm not aware of a At Avi-D-coder@baa12ac I call |
Using |
@fendor currently I'm filtering everything except plugins, preprocessor and extensions. Unless I missed something last time I took a look at getting strings out 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.
Last issue from my point of view, other than that LGTM!
@Avi-D-coder Caching the ghc options directly is possible, too. |
@alanz ping |
Thanks for all the help guys! It’s been a great ride contributing with Haskell. A lot to learn yet... |
@DavSanchez thank you for your contribution 👌 |
Hi! This addresses #1410 for the Ormolu formatter
I still have some work to do, that is sending a warning if the Format Selection option is used (in lines 31-33 of the committed
Ormolu.hs
), as this function is not yet supported by Ormolu, but I don't know exactly the best way to proceed. I was pointed toLspStdio.hs
and about throwing a warning on the right thread, but I'm still interpreting the file and how to make use of the functions in it.Feel free to provide any suggestions.
Also, I think I should put up some tests in
FormatSpec.hs
whenOrmolu.hs
is done, to let everyone check that everything works 😃