Skip to content

Commit c501fb9

Browse files
committed
Make Fourmolu CLI option specific to the Fourmolu plugin
1 parent 42f8df3 commit c501fb9

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

hls-plugin-api/src/Ide/Plugin/Config.hs

-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ data Config =
5050
{ checkParents :: CheckParents
5151
, checkProject :: !Bool
5252
, formattingProvider :: !T.Text
53-
, formattingCLI :: !Bool
5453
, maxCompletions :: !Int
5554
, plugins :: !(Map.Map T.Text PluginConfig)
5655
} deriving (Show,Eq)
@@ -63,7 +62,6 @@ instance Default Config where
6362
, formattingProvider = "ormolu"
6463
-- , formattingProvider = "floskell"
6564
-- , formattingProvider = "stylish-haskell"
66-
, formattingCLI = False
6765
, maxCompletions = 40
6866
, plugins = Map.empty
6967
}
@@ -80,7 +78,6 @@ parseConfig defValue = A.withObject "Config" $ \v -> do
8078
<$> (o .:? "checkParents" <|> v .:? "checkParents") .!= checkParents defValue
8179
<*> (o .:? "checkProject" <|> v .:? "checkProject") .!= checkProject defValue
8280
<*> o .:? "formattingProvider" .!= formattingProvider defValue
83-
<*> o .:? "formattingCLI" .!= formattingCLI defValue
8481
<*> o .:? "maxCompletions" .!= maxCompletions defValue
8582
<*> o .:? "plugin" .!= plugins defValue
8683

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{-# LANGUAGE LambdaCase #-}
33
{-# LANGUAGE OverloadedStrings #-}
44
{-# LANGUAGE TypeApplications #-}
5+
{-# LANGUAGE DataKinds #-}
6+
{-# LANGUAGE OverloadedLabels #-}
57

68
module Ide.Plugin.Fourmolu (
79
descriptor,
@@ -20,8 +22,8 @@ import Development.IDE hiding (pluginHandlers)
2022
import Development.IDE.GHC.Compat as Compat hiding (Cpp)
2123
import qualified Development.IDE.GHC.Compat.Util as S
2224
import GHC.LanguageExtensions.Type (Extension (Cpp))
23-
import Ide.Plugin.Config (formattingCLI)
24-
import Ide.PluginUtils (makeDiffTextEdit)
25+
import Ide.Plugin.Properties
26+
import Ide.PluginUtils (makeDiffTextEdit, usePropertyLsp)
2527
import Ide.Types
2628
import Language.LSP.Server hiding (defaultConfig)
2729
import Language.LSP.Types
@@ -32,22 +34,26 @@ import System.FilePath
3234
import System.IO (stderr)
3335
import System.Process.Text (readProcessWithExitCode)
3436

35-
-- ---------------------------------------------------------------------
36-
3737
descriptor :: PluginId -> PluginDescriptor IdeState
3838
descriptor plId =
3939
(defaultPluginDescriptor plId)
40-
{ pluginHandlers = mkFormattingHandlers provider
40+
{ pluginHandlers = mkFormattingHandlers $ provider plId
4141
}
4242

43-
-- ---------------------------------------------------------------------
43+
properties :: Properties '[ 'PropertyKey "cli" 'TBoolean]
44+
properties =
45+
emptyProperties
46+
& defineBooleanProperty
47+
#cli
48+
"Call out to `fourmolu` executable, rather than using the bundled library"
49+
False
4450

45-
provider :: FormattingHandler IdeState
46-
provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable $ do
51+
provider :: PluginId -> FormattingHandler IdeState
52+
provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancellable $ do
4753
fileOpts <-
4854
maybe [] (convertDynFlags . hsc_dflags . hscEnv)
4955
<$> liftIO (runAction "Fourmolu" ideState $ use GhcSession fp)
50-
useCLI <- formattingCLI <$> getConfig
56+
useCLI <- usePropertyLsp #cli plId properties
5157
if useCLI
5258
then liftIO
5359
. fmap (join . first (mkError . show))

0 commit comments

Comments
 (0)