From 3f52aa7f70db3aa68da79febf3eb35424e3a3153 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 5 Nov 2023 23:12:42 +0000 Subject: [PATCH 1/3] Add full stop for consistency with most other settings --- plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index c125c5e957..7b23c6aedb 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -59,7 +59,7 @@ properties = emptyProperties & defineBooleanProperty #external - "Call out to an external \"fourmolu\" executable, rather than using the bundled library" + "Call out to an external \"fourmolu\" executable, rather than using the bundled library." False provider :: Recorder (WithPriority LogEvent) -> PluginId -> FormattingHandler IdeState From c0ec87d3cb6db62df95de66317f888e88baf6789 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 5 Nov 2023 23:16:11 +0000 Subject: [PATCH 2/3] Add option for setting manual path to Fourmolu binary --- .../src/Ide/Plugin/Fourmolu.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index 7b23c6aedb..e9e41ebdef 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -54,9 +54,13 @@ descriptor recorder plId = , pluginConfigDescriptor = defaultConfigDescriptor{configCustomConfig = mkCustomConfig properties} } -properties :: Properties '[ 'PropertyKey "external" 'TBoolean] +properties :: Properties '[ 'PropertyKey "external" 'TBoolean, 'PropertyKey "path" 'TString] properties = emptyProperties + & defineStringProperty + #path + "Set path to executable (for \"external\" mode)." + "fourmolu" & defineBooleanProperty #external "Call out to an external \"fourmolu\" executable, rather than using the bundled library." @@ -68,10 +72,11 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro maybe [] (convertDynFlags . hsc_dflags . hscEnv) <$> liftIO (runAction "Fourmolu" ideState $ use GhcSession fp) useCLI <- liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #external plId properties + fourmoluExePath <- fmap T.unpack $ liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #path plId properties if useCLI then ExceptT . liftIO $ handle @IOException (pure . Left . PluginInternalError . T.pack . show) $ - runExceptT (cliHandler fileOpts) + runExceptT (cliHandler fourmoluExePath fileOpts) else do logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu FourmoluConfig{..} <- @@ -115,10 +120,10 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro RegionIndices Nothing Nothing FormatRange (Range (Position sl _) (Position el _)) -> RegionIndices (Just $ fromIntegral $ sl + 1) (Just $ fromIntegral $ el + 1) - cliHandler :: [String] -> ExceptT PluginError IO ([TextEdit] |? Null) - cliHandler fileOpts = do + cliHandler :: FilePath -> [String] -> ExceptT PluginError IO ([TextEdit] |? Null) + cliHandler path fileOpts = do CLIVersionInfo{noCabal} <- do -- check Fourmolu version so that we know which flags to use - (exitCode, out, _err) <- liftIO $ readCreateProcessWithExitCode ( proc "fourmolu" ["-v"] ) "" + (exitCode, out, _err) <- liftIO $ readCreateProcessWithExitCode ( proc path ["-v"] ) "" let version = do guard $ exitCode == ExitSuccess "fourmolu" : v : _ <- pure $ T.words out @@ -137,7 +142,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro } (exitCode, out, err) <- -- run Fourmolu liftIO $ readCreateProcessWithExitCode - ( proc "fourmolu" $ + ( proc path $ map ("-o" <>) fileOpts <> mwhen noCabal ["--no-cabal"] <> catMaybes From f6b92bc317ddd7750b8b0e1ba11bd2f7bb26d8f0 Mon Sep 17 00:00:00 2001 From: Fendor Date: Tue, 16 Jan 2024 12:24:16 +0100 Subject: [PATCH 3/3] Update config files for new fourmolu option --- test/testdata/schema/ghc92/default-config.golden.json | 3 ++- .../schema/ghc92/vscode-extension-schema.golden.json | 8 +++++++- test/testdata/schema/ghc94/default-config.golden.json | 3 ++- .../schema/ghc94/vscode-extension-schema.golden.json | 8 +++++++- test/testdata/schema/ghc96/default-config.golden.json | 3 ++- .../schema/ghc96/vscode-extension-schema.golden.json | 8 +++++++- test/testdata/schema/ghc98/default-config.golden.json | 3 ++- .../schema/ghc98/vscode-extension-schema.golden.json | 8 +++++++- 8 files changed, 36 insertions(+), 8 deletions(-) diff --git a/test/testdata/schema/ghc92/default-config.golden.json b/test/testdata/schema/ghc92/default-config.golden.json index d4e9e717b7..b9b3b46b25 100644 --- a/test/testdata/schema/ghc92/default-config.golden.json +++ b/test/testdata/schema/ghc92/default-config.golden.json @@ -36,7 +36,8 @@ }, "fourmolu": { "config": { - "external": false + "external": false, + "path": "fourmolu" } }, "gadt": { diff --git a/test/testdata/schema/ghc92/vscode-extension-schema.golden.json b/test/testdata/schema/ghc92/vscode-extension-schema.golden.json index c063ad0b5a..525f3e1bce 100644 --- a/test/testdata/schema/ghc92/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc92/vscode-extension-schema.golden.json @@ -73,10 +73,16 @@ }, "haskell.plugin.fourmolu.config.external": { "default": false, - "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library", + "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.", "scope": "resource", "type": "boolean" }, + "haskell.plugin.fourmolu.config.path": { + "default": "fourmolu", + "markdownDescription": "Set path to executable (for \"external\" mode).", + "scope": "resource", + "type": "string" + }, "haskell.plugin.gadt.globalOn": { "default": true, "description": "Enables gadt plugin", diff --git a/test/testdata/schema/ghc94/default-config.golden.json b/test/testdata/schema/ghc94/default-config.golden.json index 6b1a3c3b5f..6cef581bc8 100644 --- a/test/testdata/schema/ghc94/default-config.golden.json +++ b/test/testdata/schema/ghc94/default-config.golden.json @@ -36,7 +36,8 @@ }, "fourmolu": { "config": { - "external": false + "external": false, + "path": "fourmolu" } }, "gadt": { diff --git a/test/testdata/schema/ghc94/vscode-extension-schema.golden.json b/test/testdata/schema/ghc94/vscode-extension-schema.golden.json index 6b3cdc4384..733f3596cf 100644 --- a/test/testdata/schema/ghc94/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc94/vscode-extension-schema.golden.json @@ -73,10 +73,16 @@ }, "haskell.plugin.fourmolu.config.external": { "default": false, - "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library", + "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.", "scope": "resource", "type": "boolean" }, + "haskell.plugin.fourmolu.config.path": { + "default": "fourmolu", + "markdownDescription": "Set path to executable (for \"external\" mode).", + "scope": "resource", + "type": "string" + }, "haskell.plugin.gadt.globalOn": { "default": true, "description": "Enables gadt plugin", diff --git a/test/testdata/schema/ghc96/default-config.golden.json b/test/testdata/schema/ghc96/default-config.golden.json index 6b1a3c3b5f..6cef581bc8 100644 --- a/test/testdata/schema/ghc96/default-config.golden.json +++ b/test/testdata/schema/ghc96/default-config.golden.json @@ -36,7 +36,8 @@ }, "fourmolu": { "config": { - "external": false + "external": false, + "path": "fourmolu" } }, "gadt": { diff --git a/test/testdata/schema/ghc96/vscode-extension-schema.golden.json b/test/testdata/schema/ghc96/vscode-extension-schema.golden.json index 6b3cdc4384..733f3596cf 100644 --- a/test/testdata/schema/ghc96/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc96/vscode-extension-schema.golden.json @@ -73,10 +73,16 @@ }, "haskell.plugin.fourmolu.config.external": { "default": false, - "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library", + "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.", "scope": "resource", "type": "boolean" }, + "haskell.plugin.fourmolu.config.path": { + "default": "fourmolu", + "markdownDescription": "Set path to executable (for \"external\" mode).", + "scope": "resource", + "type": "string" + }, "haskell.plugin.gadt.globalOn": { "default": true, "description": "Enables gadt plugin", diff --git a/test/testdata/schema/ghc98/default-config.golden.json b/test/testdata/schema/ghc98/default-config.golden.json index 0a8cd9afe7..28494adf51 100644 --- a/test/testdata/schema/ghc98/default-config.golden.json +++ b/test/testdata/schema/ghc98/default-config.golden.json @@ -32,7 +32,8 @@ }, "fourmolu": { "config": { - "external": false + "external": false, + "path": "fourmolu" } }, "ghcide-completions": { diff --git a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json index 962f3138b3..cf438c18b7 100644 --- a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json @@ -61,10 +61,16 @@ }, "haskell.plugin.fourmolu.config.external": { "default": false, - "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library", + "markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.", "scope": "resource", "type": "boolean" }, + "haskell.plugin.fourmolu.config.path": { + "default": "fourmolu", + "markdownDescription": "Set path to executable (for \"external\" mode).", + "scope": "resource", + "type": "string" + }, "haskell.plugin.ghcide-completions.config.autoExtendOn": { "default": true, "markdownDescription": "Extends the import list automatically when completing a out-of-scope identifier",