Skip to content

Commit a30949b

Browse files
committed
Bringing in ability to select provider.
Needs haskell/ghcide#412 to land first, as a basis for the needed changes
1 parent 5e92113 commit a30949b

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

src/Ide/Plugin/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ instance Default Config where
6363
, formatOnImportOn = True
6464
-- , formattingProvider = "brittany"
6565
, formattingProvider = "ormolu"
66+
-- , formattingProvider = "floskell"
6667
}
6768

6869
-- TODO: Add API for plugins to expose their own LSP config options

src/Ide/Plugin/Formatter.hs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Text.Regex.TDFA.Text()
3434
-- ---------------------------------------------------------------------
3535

3636
formatterPlugins :: [(T.Text, FormattingProvider IO)] -> Plugin Config
37-
formatterPlugins providers = Plugin rules (handlers (Map.fromList providers))
37+
formatterPlugins providers = Plugin rules (handlers (Map.fromList (("none",noneProvider):providers)))
3838

3939
-- ---------------------------------------------------------------------
4040
-- New style plugin
@@ -50,14 +50,6 @@ handlers providers = PartialHandlers $ \WithMessage{..} x -> return x
5050
= withResponse RspDocumentRangeFormatting (rangeFormatting providers)
5151
}
5252

53-
-- handlers :: FormattingProvider IO -> T.Text -> PartialHandlers c
54-
-- handlers provider configName = PartialHandlers $ \WithMessage{..} x -> return x
55-
-- { LSP.documentFormattingHandler
56-
-- = withResponse RspDocumentFormatting (formatting provider configName)
57-
-- , LSP.documentRangeFormattingHandler
58-
-- = withResponse RspDocumentRangeFormatting (rangeFormatting provider configName)
59-
-- }
60-
6153
-- ---------------------------------------------------------------------
6254

6355
formatting :: Map.Map T.Text (FormattingProvider IO)
@@ -118,6 +110,11 @@ type FormattingProvider m
118110

119111
-- ---------------------------------------------------------------------
120112

113+
noneProvider :: FormattingProvider IO
114+
noneProvider _ _ _ _ _ = return $ Right (List [])
115+
116+
-- ---------------------------------------------------------------------
117+
121118
responseError :: T.Text -> ResponseError
122119
responseError txt = ResponseError InvalidParams txt Nothing
123120

src/Ide/Plugin/Ormolu.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ provider ideState typ contents fp _ = do
108108
ret r (Right new) = Right (List [TextEdit r new])
109109

110110
#else
111-
provider _ _ _ _ = return $ IdeResultOk [] -- NOP formatter
111+
provider _ _ _ _ = return $ Right [] -- NOP formatter
112112
#endif
113113

114114
-- ---------------------------------------------------------------------

test/functional/FormatSpec.hs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,38 @@ spec = do
3535
-- formatRange doc (FormattingOptions 5 True) (Range (Position 4 0) (Position 7 19))
3636
-- documentContents doc >>= liftIO . (`shouldBe` formattedRangeTabSize5)
3737

38-
-- describe "formatting provider" $ do
39-
-- let formatLspConfig provider =
40-
-- object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
41-
-- formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
38+
describe "formatting provider" $ do
39+
let formatLspConfig provider =
40+
object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
41+
formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
4242

43-
-- it "respects none" $ runSessionWithConfig (formatConfig "none") hieCommand fullCaps "test/testdata" $ do
44-
-- doc <- openDoc "Format.hs" "haskell"
45-
-- orig <- documentContents doc
43+
it "respects none" $ runSessionWithConfig (formatConfig "none") hieCommand fullCaps "test/testdata" $ do
44+
doc <- openDoc "Format.hs" "haskell"
45+
orig <- documentContents doc
4646

47-
-- formatDoc doc (FormattingOptions 2 True)
48-
-- documentContents doc >>= liftIO . (`shouldBe` orig)
47+
formatDoc doc (FormattingOptions 2 True)
48+
documentContents doc >>= liftIO . (`shouldBe` orig)
4949

50-
-- formatRange doc (FormattingOptions 2 True) (Range (Position 1 0) (Position 3 10))
51-
-- documentContents doc >>= liftIO . (`shouldBe` orig)
50+
formatRange doc (FormattingOptions 2 True) (Range (Position 1 0) (Position 3 10))
51+
documentContents doc >>= liftIO . (`shouldBe` orig)
5252

53-
-- it "can change on the fly" $ runSession hieCommand fullCaps "test/testdata" $ do
54-
-- doc <- openDoc "Format.hs" "haskell"
53+
it "can change on the fly" $ runSession hieCommand fullCaps "test/testdata" $ do
54+
doc <- openDoc "Format.hs" "haskell"
5555

56-
-- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
57-
-- formatDoc doc (FormattingOptions 2 True)
58-
-- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2)
56+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
57+
formatDoc doc (FormattingOptions 2 True)
58+
documentContents doc >>= liftIO . (`shouldBe` formattedDocOrmolu)
59+
-- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
60+
-- formatDoc doc (FormattingOptions 2 True)
61+
-- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2)
5962

60-
-- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell"))
61-
-- formatDoc doc (FormattingOptions 2 True)
62-
-- documentContents doc >>= liftIO . (`shouldBe` formattedFloskell)
63+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell"))
64+
formatDoc doc (FormattingOptions 2 True)
65+
documentContents doc >>= liftIO . (`shouldBe` formattedFloskell)
6366

64-
-- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
65-
-- formatDoc doc (FormattingOptions 2 True)
66-
-- documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
67+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
68+
formatDoc doc (FormattingOptions 2 True)
69+
documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
6770

6871
-- describe "brittany" $ do
6972
-- it "formats a document with LF endings" $ runSession hieCommand fullCaps "test/testdata" $ do

0 commit comments

Comments
 (0)