Skip to content

Commit c0ec87d

Browse files
committed
Add option for setting manual path to Fourmolu binary
1 parent 3f52aa7 commit c0ec87d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ descriptor recorder plId =
5454
, pluginConfigDescriptor = defaultConfigDescriptor{configCustomConfig = mkCustomConfig properties}
5555
}
5656

57-
properties :: Properties '[ 'PropertyKey "external" 'TBoolean]
57+
properties :: Properties '[ 'PropertyKey "external" 'TBoolean, 'PropertyKey "path" 'TString]
5858
properties =
5959
emptyProperties
60+
& defineStringProperty
61+
#path
62+
"Set path to executable (for \"external\" mode)."
63+
"fourmolu"
6064
& defineBooleanProperty
6165
#external
6266
"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
6872
maybe [] (convertDynFlags . hsc_dflags . hscEnv)
6973
<$> liftIO (runAction "Fourmolu" ideState $ use GhcSession fp)
7074
useCLI <- liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #external plId properties
75+
fourmoluExePath <- fmap T.unpack $ liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #path plId properties
7176
if useCLI
7277
then ExceptT . liftIO $
7378
handle @IOException (pure . Left . PluginInternalError . T.pack . show) $
74-
runExceptT (cliHandler fileOpts)
79+
runExceptT (cliHandler fourmoluExePath fileOpts)
7580
else do
7681
logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu
7782
FourmoluConfig{..} <-
@@ -115,10 +120,10 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
115120
RegionIndices Nothing Nothing
116121
FormatRange (Range (Position sl _) (Position el _)) ->
117122
RegionIndices (Just $ fromIntegral $ sl + 1) (Just $ fromIntegral $ el + 1)
118-
cliHandler :: [String] -> ExceptT PluginError IO ([TextEdit] |? Null)
119-
cliHandler fileOpts = do
123+
cliHandler :: FilePath -> [String] -> ExceptT PluginError IO ([TextEdit] |? Null)
124+
cliHandler path fileOpts = do
120125
CLIVersionInfo{noCabal} <- do -- check Fourmolu version so that we know which flags to use
121-
(exitCode, out, _err) <- liftIO $ readCreateProcessWithExitCode ( proc "fourmolu" ["-v"] ) ""
126+
(exitCode, out, _err) <- liftIO $ readCreateProcessWithExitCode ( proc path ["-v"] ) ""
122127
let version = do
123128
guard $ exitCode == ExitSuccess
124129
"fourmolu" : v : _ <- pure $ T.words out
@@ -137,7 +142,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
137142
}
138143
(exitCode, out, err) <- -- run Fourmolu
139144
liftIO $ readCreateProcessWithExitCode
140-
( proc "fourmolu" $
145+
( proc path $
141146
map ("-o" <>) fileOpts
142147
<> mwhen noCabal ["--no-cabal"]
143148
<> catMaybes

0 commit comments

Comments
 (0)