diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index b2ef2f44b5..dd736dc875 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -56,12 +56,16 @@ descriptor recorder plId = where desc = "Provides formatting of Haskell files via fourmolu. Built with fourmolu-" <> VERSION_fourmolu -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" + "Call out to an external \"fourmolu\" executable, rather than using the bundled library." False provider :: Recorder (WithPriority LogEvent) -> PluginId -> FormattingHandler IdeState @@ -70,10 +74,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{..} <- @@ -117,10 +122,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 @@ -139,7 +144,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 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",