Skip to content

Commit 4361687

Browse files
authored
Merge pull request #3860 from haskell/fourmolu-custom-path
Add option for setting manual path to Fourmolu binary
2 parents 8697f5f + e3d3e94 commit 4361687

File tree

9 files changed

+48
-15
lines changed

9 files changed

+48
-15
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ descriptor recorder plId =
5656
where
5757
desc = "Provides formatting of Haskell files via fourmolu. Built with fourmolu-" <> VERSION_fourmolu
5858

59-
properties :: Properties '[ 'PropertyKey "external" 'TBoolean]
59+
properties :: Properties '[ 'PropertyKey "external" 'TBoolean, 'PropertyKey "path" 'TString]
6060
properties =
6161
emptyProperties
62+
& defineStringProperty
63+
#path
64+
"Set path to executable (for \"external\" mode)."
65+
"fourmolu"
6266
& defineBooleanProperty
6367
#external
64-
"Call out to an external \"fourmolu\" executable, rather than using the bundled library"
68+
"Call out to an external \"fourmolu\" executable, rather than using the bundled library."
6569
False
6670

6771
provider :: Recorder (WithPriority LogEvent) -> PluginId -> FormattingHandler IdeState
@@ -70,10 +74,11 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
7074
maybe [] (convertDynFlags . hsc_dflags . hscEnv)
7175
<$> liftIO (runAction "Fourmolu" ideState $ use GhcSession fp)
7276
useCLI <- liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #external plId properties
77+
fourmoluExePath <- fmap T.unpack $ liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #path plId properties
7378
if useCLI
7479
then ExceptT . liftIO $
7580
handle @IOException (pure . Left . PluginInternalError . T.pack . show) $
76-
runExceptT (cliHandler fileOpts)
81+
runExceptT (cliHandler fourmoluExePath fileOpts)
7782
else do
7883
logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu
7984
FourmoluConfig{..} <-
@@ -117,10 +122,10 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
117122
RegionIndices Nothing Nothing
118123
FormatRange (Range (Position sl _) (Position el _)) ->
119124
RegionIndices (Just $ fromIntegral $ sl + 1) (Just $ fromIntegral $ el + 1)
120-
cliHandler :: [String] -> ExceptT PluginError IO ([TextEdit] |? Null)
121-
cliHandler fileOpts = do
125+
cliHandler :: FilePath -> [String] -> ExceptT PluginError IO ([TextEdit] |? Null)
126+
cliHandler path fileOpts = do
122127
CLIVersionInfo{noCabal} <- do -- check Fourmolu version so that we know which flags to use
123-
(exitCode, out, _err) <- liftIO $ readCreateProcessWithExitCode ( proc "fourmolu" ["-v"] ) ""
128+
(exitCode, out, _err) <- liftIO $ readCreateProcessWithExitCode ( proc path ["-v"] ) ""
124129
let version = do
125130
guard $ exitCode == ExitSuccess
126131
"fourmolu" : v : _ <- pure $ T.words out
@@ -139,7 +144,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
139144
}
140145
(exitCode, out, err) <- -- run Fourmolu
141146
liftIO $ readCreateProcessWithExitCode
142-
( proc "fourmolu" $
147+
( proc path $
143148
map ("-o" <>) fileOpts
144149
<> mwhen noCabal ["--no-cabal"]
145150
<> catMaybes

test/testdata/schema/ghc92/default-config.golden.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
},
3737
"fourmolu": {
3838
"config": {
39-
"external": false
39+
"external": false,
40+
"path": "fourmolu"
4041
}
4142
},
4243
"gadt": {

test/testdata/schema/ghc92/vscode-extension-schema.golden.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@
7373
},
7474
"haskell.plugin.fourmolu.config.external": {
7575
"default": false,
76-
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library",
76+
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.",
7777
"scope": "resource",
7878
"type": "boolean"
7979
},
80+
"haskell.plugin.fourmolu.config.path": {
81+
"default": "fourmolu",
82+
"markdownDescription": "Set path to executable (for \"external\" mode).",
83+
"scope": "resource",
84+
"type": "string"
85+
},
8086
"haskell.plugin.gadt.globalOn": {
8187
"default": true,
8288
"description": "Enables gadt plugin",

test/testdata/schema/ghc94/default-config.golden.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
},
3737
"fourmolu": {
3838
"config": {
39-
"external": false
39+
"external": false,
40+
"path": "fourmolu"
4041
}
4142
},
4243
"gadt": {

test/testdata/schema/ghc94/vscode-extension-schema.golden.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@
7373
},
7474
"haskell.plugin.fourmolu.config.external": {
7575
"default": false,
76-
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library",
76+
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.",
7777
"scope": "resource",
7878
"type": "boolean"
7979
},
80+
"haskell.plugin.fourmolu.config.path": {
81+
"default": "fourmolu",
82+
"markdownDescription": "Set path to executable (for \"external\" mode).",
83+
"scope": "resource",
84+
"type": "string"
85+
},
8086
"haskell.plugin.gadt.globalOn": {
8187
"default": true,
8288
"description": "Enables gadt plugin",

test/testdata/schema/ghc96/default-config.golden.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
},
3737
"fourmolu": {
3838
"config": {
39-
"external": false
39+
"external": false,
40+
"path": "fourmolu"
4041
}
4142
},
4243
"gadt": {

test/testdata/schema/ghc96/vscode-extension-schema.golden.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@
7373
},
7474
"haskell.plugin.fourmolu.config.external": {
7575
"default": false,
76-
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library",
76+
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.",
7777
"scope": "resource",
7878
"type": "boolean"
7979
},
80+
"haskell.plugin.fourmolu.config.path": {
81+
"default": "fourmolu",
82+
"markdownDescription": "Set path to executable (for \"external\" mode).",
83+
"scope": "resource",
84+
"type": "string"
85+
},
8086
"haskell.plugin.gadt.globalOn": {
8187
"default": true,
8288
"description": "Enables gadt plugin",

test/testdata/schema/ghc98/default-config.golden.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
},
3333
"fourmolu": {
3434
"config": {
35-
"external": false
35+
"external": false,
36+
"path": "fourmolu"
3637
}
3738
},
3839
"ghcide-completions": {

test/testdata/schema/ghc98/vscode-extension-schema.golden.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@
6161
},
6262
"haskell.plugin.fourmolu.config.external": {
6363
"default": false,
64-
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library",
64+
"markdownDescription": "Call out to an external \"fourmolu\" executable, rather than using the bundled library.",
6565
"scope": "resource",
6666
"type": "boolean"
6767
},
68+
"haskell.plugin.fourmolu.config.path": {
69+
"default": "fourmolu",
70+
"markdownDescription": "Set path to executable (for \"external\" mode).",
71+
"scope": "resource",
72+
"type": "string"
73+
},
6874
"haskell.plugin.ghcide-completions.config.autoExtendOn": {
6975
"default": true,
7076
"markdownDescription": "Extends the import list automatically when completing a out-of-scope identifier",

0 commit comments

Comments
 (0)