@@ -54,9 +54,13 @@ descriptor recorder plId =
54
54
, pluginConfigDescriptor = defaultConfigDescriptor{configCustomConfig = mkCustomConfig properties}
55
55
}
56
56
57
- properties :: Properties '[ 'PropertyKey " external" 'TBoolean]
57
+ properties :: Properties '[ 'PropertyKey " external" 'TBoolean, 'PropertyKey " path " 'TString ]
58
58
properties =
59
59
emptyProperties
60
+ & defineStringProperty
61
+ # path
62
+ " Set path to executable (for \" external\" mode)."
63
+ " fourmolu"
60
64
& defineBooleanProperty
61
65
# external
62
66
" 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
68
72
maybe [] (convertDynFlags . hsc_dflags . hscEnv)
69
73
<$> liftIO (runAction " Fourmolu" ideState $ use GhcSession fp)
70
74
useCLI <- liftIO $ runAction " Fourmolu" ideState $ usePropertyAction # external plId properties
75
+ fourmoluExePath <- fmap T. unpack $ liftIO $ runAction " Fourmolu" ideState $ usePropertyAction # path plId properties
71
76
if useCLI
72
77
then ExceptT . liftIO $
73
78
handle @ IOException (pure . Left . PluginInternalError . T. pack . show ) $
74
- runExceptT (cliHandler fileOpts)
79
+ runExceptT (cliHandler fourmoluExePath fileOpts)
75
80
else do
76
81
logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu
77
82
FourmoluConfig {.. } <-
@@ -115,10 +120,10 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
115
120
RegionIndices Nothing Nothing
116
121
FormatRange (Range (Position sl _) (Position el _)) ->
117
122
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
120
125
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" ] ) " "
122
127
let version = do
123
128
guard $ exitCode == ExitSuccess
124
129
" fourmolu" : v : _ <- pure $ T. words out
@@ -137,7 +142,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
137
142
}
138
143
(exitCode, out, err) <- -- run Fourmolu
139
144
liftIO $ readCreateProcessWithExitCode
140
- ( proc " fourmolu " $
145
+ ( proc path $
141
146
map (" -o" <> ) fileOpts
142
147
<> mwhen noCabal [" --no-cabal" ]
143
148
<> catMaybes
0 commit comments