Description
Hey, sorry for opening yet another issue, I kinda feel guilty 😅 I noticed what appears to be a bug, and I took the opportunity to ask additional formatter-related questions, I can push them to other issues if it's simpler for you to manage.
I just tested in VS Code "Format document", which I assume relies on Ormolu (I configured the Ormolu formatter in languageServerHaskell.formattingProvider
).
1 - Format is bugged, and inconsistent
We see an inconsistency between applying "Format" from HLS (in VS Code) or applying Ormolu directly in CLI.
Consider this code:
module Foo where
import Prelude
import GHC.Generics (Generic)
import Data.Text (Text)
data Foo
= Foo
{ _name :: Text,
_description :: Maybe Text
}
deriving (Generic, Show, Eq)
Applying reformatting from VS Code (and I checked in HLS Output view that it uses Ormolu), this gets reformatted as such:
module Foo where
import GHC.Generics (Generic)
import Prelude
import Data.Text (Text)
data Foo = Foo
{ _name :: Text,
_description :: Maybe Text
}
deriving (Generic, Show, Eq)
Note in particular that import order was modified, yet it's not completely alphabetical
Now run the formatter again in VS Code (yes, without modifying anything) and the second time, import order is correct! 💥
module Foo where
import Data.Text (Text)
import GHC.Generics (Generic)
import Prelude
data Foo = Foo
{ _name :: Text,
_description :: Maybe Text
}
deriving (Generic, Show, Eq)
Now when running Ormolu in CLI, the original piece of code gets reformatted to:
module Foo where
import Data.Text (Text)
import GHC.Generics (Generic)
import Prelude
data Foo = Foo
{ _name :: Text,
_description :: Maybe Text
}
deriving (Generic, Show, Eq)
i.e. Ormolu in CLI run once behaves the same as formatting twice in a row in VS Code 💥
Edit: the situation seems to be even worse. Here's an additional example:
import Data.Text (Text)
import GHC.Generics (Generic)
import Prelude
import Data.Time.Calendar
import Data.Aeson
Even after 50 reformats, the import order remains:
import Data.Aeson
import Data.Text (Text)
import GHC.Generics (Generic)
import Data.Time.Calendar
import Prelude
While Ormolu in CLI correctly returns:
import Data.Aeson
import Data.Text (Text)
import Data.Time.Calendar
import GHC.Generics (Generic)
import Prelude
2 - Is it a packaged version of Ormolu, or does it use the path one?
3 - Custom options
If I am correct, how would one pass custom options to Ormolu, like --ghc-opt -XBangPatterns
? So far we were using Nix + a custom shell wrapper to force our own options as such:
ormolu-wrapped = symlinkJoin {
name = "ormolu";
paths = [ ormolu ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/ormolu \
--add-flags "\
--ghc-opt -XBangPatterns \
--ghc-opt -XTypeApplications \
"
'';
};
Would this still work/get picked up by HLS?
4 - Formatter (plugins) versions in HLS logs
Shouldn't the HLS logs display the formatter version? Currently there's no way to know which one is picked/used
I think the perfect opportunity would be at startup while listing plugins:
Starting (haskell-language-server)LSP server...
with arguments: Arguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsVersion = False, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0}
with plugins: [PluginId "brittany",PluginId "floskell",PluginId "ghcide",PluginId "ormolu",PluginId "pragmas",PluginId "stylish-haskell"]
Thank you again for the help, quick replies, and overall support 🙏 Let me know if I can help (with my modest understanding of this project)