Skip to content

Commit 0aae68b

Browse files
authored
Merge pull request #243 from bubba/accept-legacy-config-section-name
Accept the legacy "languageServerHaskell" config name
2 parents f2384e1 + 95560b1 commit 0aae68b

20 files changed

+108
-162
lines changed

Diff for: cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ package ghcide
1414

1515
write-ghc-environment-files: never
1616

17-
index-state: 2020-07-16T17:24:10Z
17+
index-state: 2020-07-27T12:40:45Z

Diff for: haskell-language-server.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ common hls-test-utils
215215
, hslogger
216216
, hspec
217217
, hspec-core
218-
, lsp-test
218+
, lsp-test >= 0.11.0.3
219219
, stm
220220
, tasty-hunit
221221
, temporary
@@ -245,7 +245,7 @@ test-suite func-test
245245
, haskell-lsp-types
246246
, hspec-expectations
247247
, lens
248-
, lsp-test >= 0.10.0.0
248+
, lsp-test >= 0.11.0.3
249249
, tasty
250250
, tasty-ant-xml >= 1.1.6
251251
, tasty-expected-failure

Diff for: src/Ide/Plugin/Config.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Ide.Plugin.Config
1010
, Config(..)
1111
) where
1212

13+
import Control.Applicative
1314
import qualified Data.Aeson as A
1415
import Data.Aeson hiding ( Error )
1516
import Data.Default
@@ -70,7 +71,9 @@ instance Default Config where
7071
-- TODO: Add API for plugins to expose their own LSP config options
7172
instance A.FromJSON Config where
7273
parseJSON = A.withObject "Config" $ \v -> do
73-
s <- v .: "haskell"
74+
-- Officially, we use "haskell" as the section name but for
75+
-- backwards compatibility we also accept "languageServerHaskell"
76+
s <- v .: "haskell" <|> v .: "languageServerHaskell"
7477
flip (A.withObject "Config.settings") s $ \o -> Config
7578
<$> o .:? "hlintOn" .!= hlintOn def
7679
<*> o .:? "diagnosticsOnChange" .!= diagnosticsOnChange def

Diff for: stack-8.10.1.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extra-deps:
1515
- floskell-0.10.3
1616
- ghc-exactprint-0.6.3
1717
- lens-4.19.1
18-
- lsp-test-0.11.0.2
18+
- lsp-test-0.11.0.3
1919
- monad-dijkstra-0.1.1.2
2020
- optics-core-0.3
2121
- ormolu-0.1.2.0

Diff for: stack-8.6.4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extra-deps:
3939
- HsYAML-0.2.1.0@rev:1
4040
- HsYAML-aeson-0.2.0.0@rev:1
4141
- lens-4.18
42-
- lsp-test-0.11.0.2
42+
- lsp-test-0.11.0.3
4343
- microlens-th-0.4.2.3@rev:1
4444
- monad-dijkstra-0.1.1.2
4545
- monad-memo-0.4.1

Diff for: stack-8.6.5.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extra-deps:
3131
- HsYAML-aeson-0.2.0.0@rev:1
3232
- indexed-profunctors-0.1
3333
- lens-4.18
34-
- lsp-test-0.11.0.2
34+
- lsp-test-0.11.0.3
3535
- monad-dijkstra-0.1.1.2
3636
- opentelemetry-0.4.2
3737
- optics-core-0.2

Diff for: stack-8.8.2.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extra-deps:
3131
- HsYAML-0.2.1.0@rev:1
3232
- HsYAML-aeson-0.2.0.0@rev:1
3333
- ilist-0.3.1.0
34-
- lsp-test-0.11.0.2
34+
- lsp-test-0.11.0.3
3535
- monad-dijkstra-0.1.1.2
3636
- opentelemetry-0.4.2
3737
- ormolu-0.1.2.0

Diff for: stack-8.8.3.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extra-deps:
2222
- hoogle-5.0.17.11
2323
- hsimport-0.11.0
2424
- ilist-0.3.1.0
25-
- lsp-test-0.11.0.2
25+
- lsp-test-0.11.0.3
2626
- monad-dijkstra-0.1.1.2
2727
- semigroups-0.18.5
2828
# - github: wz1000/shake

Diff for: stack-8.8.4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extra-deps:
2424
- hoogle-5.0.17.11
2525
- hsimport-0.11.0
2626
- ilist-0.3.1.0
27-
- lsp-test-0.11.0.2
27+
- lsp-test-0.11.0.3
2828
- monad-dijkstra-0.1.1.2
2929
- semigroups-0.18.5
3030
# - github: wz1000/shake

Diff for: stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extra-deps:
3131
- HsYAML-aeson-0.2.0.0@rev:1
3232
- indexed-profunctors-0.1
3333
- lens-4.18
34-
- lsp-test-0.11.0.2
34+
- lsp-test-0.11.0.3
3535
- monad-dijkstra-0.1.1.2
3636
- opentelemetry-0.4.2
3737
- optics-core-0.2

Diff for: test/functional/Format.hs

+45-53
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
{-# LANGUAGE OverloadedStrings #-}
1+
{-# LANGUAGE OverloadedStrings, CPP #-}
22
module Format (tests) where
33

44
import Control.Monad.IO.Class
55
import Data.Aeson
66
import qualified Data.ByteString.Lazy as BS
7-
import qualified Data.Text as T
87
import qualified Data.Text.Encoding as T
98
import Language.Haskell.LSP.Test
109
import Language.Haskell.LSP.Types
1110
import Test.Hls.Util
1211
import Test.Tasty
13-
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
1412
import Test.Tasty.Golden
1513
import Test.Tasty.HUnit
16-
import Test.Hspec.Expectations
14+
15+
#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) || !defined(AGPL)
16+
#else
17+
import qualified Data.Text.IO as T
18+
#endif
1719

1820
tests :: TestTree
1921
tests = testGroup "format document" [
@@ -28,7 +30,11 @@ tests = testGroup "format document" [
2830
, rangeTests
2931
, providerTests
3032
, stylishHaskellTests
33+
-- There's no Brittany formatter on the 8.10.1 builds (yet)
34+
#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) || !defined(AGPL)
35+
#else
3136
, brittanyTests
37+
#endif
3238
, ormoluTests
3339
]
3440

@@ -51,25 +57,46 @@ providerTests = testGroup "formatting provider" [
5157
orig <- documentContents doc
5258

5359
formatDoc doc (FormattingOptions 2 True)
54-
documentContents doc >>= liftIO . (`shouldBe` orig)
60+
documentContents doc >>= liftIO . (@?= orig)
5561

5662
formatRange doc (FormattingOptions 2 True) (Range (Position 1 0) (Position 3 10))
57-
documentContents doc >>= liftIO . (`shouldBe` orig)
63+
documentContents doc >>= liftIO . (@?= orig)
64+
65+
-- There's no Brittany formatter on the 8.10.1 builds (yet)
66+
#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) || !defined(AGPL)
67+
#else
68+
, testCase "can change on the fly" $ runSession hieCommand fullCaps "test/testdata" $ do
69+
formattedBrittany <- liftIO $ T.readFile "test/testdata/Format.brittany.formatted.hs"
70+
formattedFloskell <- liftIO $ T.readFile "test/testdata/Format.floskell.formatted.hs"
71+
formattedBrittanyPostFloskell <- liftIO $ T.readFile "test/testdata/Format.brittany_post_floskell.formatted.hs"
5872

59-
, ignoreTestBecause "Broken" $ testCase "can change on the fly" $ runSession hieCommand fullCaps "test/testdata" $ do
6073
doc <- openDoc "Format.hs" "haskell"
6174

6275
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
6376
formatDoc doc (FormattingOptions 2 True)
64-
documentContents doc >>= liftIO . (`shouldBe` formattedBrittany)
77+
documentContents doc >>= liftIO . (@?= formattedBrittany)
6578

6679
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell"))
6780
formatDoc doc (FormattingOptions 2 True)
68-
documentContents doc >>= liftIO . (`shouldBe` formattedFloskell)
81+
documentContents doc >>= liftIO . (@?= formattedFloskell)
6982

7083
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
7184
formatDoc doc (FormattingOptions 2 True)
72-
documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
85+
documentContents doc >>= liftIO . (@?= formattedBrittanyPostFloskell)
86+
, testCase "supports both new and old configuration sections" $ runSession hieCommand fullCaps "test/testdata" $ do
87+
formattedBrittany <- liftIO $ T.readFile "test/testdata/Format.brittany.formatted.hs"
88+
formattedFloskell <- liftIO $ T.readFile "test/testdata/Format.floskell.formatted.hs"
89+
90+
doc <- openDoc "Format.hs" "haskell"
91+
92+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "brittany"))
93+
formatDoc doc (FormattingOptions 2 True)
94+
documentContents doc >>= liftIO . (@?= formattedBrittany)
95+
96+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "floskell"))
97+
formatDoc doc (FormattingOptions 2 True)
98+
documentContents doc >>= liftIO . (@?= formattedFloskell)
99+
#endif
73100
]
74101

75102
stylishHaskellTests :: TestTree
@@ -89,22 +116,26 @@ stylishHaskellTests = testGroup "stylish-haskell" [
89116
brittanyTests :: TestTree
90117
brittanyTests = testGroup "brittany" [
91118
goldenVsStringDiff "formats a document with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_document.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
119+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
92120
doc <- openDoc "BrittanyLF.hs" "haskell"
93121
formatDoc doc (FormattingOptions 4 True)
94122
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
95123

96124
, goldenVsStringDiff "formats a document with CRLF endings" goldenGitDiff "test/testdata/BrittanyCRLF.formatted_document.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
125+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
97126
doc <- openDoc "BrittanyCRLF.hs" "haskell"
98127
formatDoc doc (FormattingOptions 4 True)
99128
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
100129

101130
, goldenVsStringDiff "formats a range with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_range.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
131+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
102132
doc <- openDoc "BrittanyLF.hs" "haskell"
103133
let range = Range (Position 1 0) (Position 2 22)
104134
formatRange doc (FormattingOptions 4 True) range
105135
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
106136

107137
, goldenVsStringDiff "formats a range with CRLF endings" goldenGitDiff "test/testdata/BrittanyCRLF.formatted_range.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
138+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
108139
doc <- openDoc "BrittanyCRLF.hs" "haskell"
109140
let range = Range (Position 1 0) (Position 2 22)
110141
formatRange doc (FormattingOptions 4 True) range
@@ -114,8 +145,6 @@ brittanyTests = testGroup "brittany" [
114145
ormoluTests :: TestTree
115146
ormoluTests = testGroup "ormolu" [
116147
goldenVsStringDiff "formats correctly" goldenGitDiff ("test/testdata/Format.ormolu." ++ ormoluGoldenSuffix ++ ".hs") $ runSession hieCommand fullCaps "test/testdata" $ do
117-
let formatLspConfig provider =
118-
object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ]
119148
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
120149
doc <- openDoc "Format.hs" "haskell"
121150
formatDoc doc (FormattingOptions 2 True)
@@ -131,49 +160,12 @@ ormoluTests = testGroup "ormolu" [
131160
formatLspConfig :: Value -> Value
132161
formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ]
133162

163+
-- | The same as 'formatLspConfig' but using the legacy section name
164+
formatLspConfigOld :: Value -> Value
165+
formatLspConfigOld provider = object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
166+
134167
formatConfig :: Value -> SessionConfig
135168
formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
136169

137170
goldenGitDiff :: FilePath -> FilePath -> [String]
138171
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]
139-
140-
141-
formattedBrittany :: T.Text
142-
formattedBrittany =
143-
"module Format where\n\
144-
\foo :: Int -> Int\n\
145-
\foo 3 = 2\n\
146-
\foo x = x\n\
147-
\bar :: String -> IO String\n\
148-
\bar s = do\n\
149-
\ x <- return \"hello\"\n\
150-
\ return \"asdf\"\n\n\
151-
\data Baz = Baz { a :: Int, b :: String }\n\n"
152-
153-
formattedFloskell :: T.Text
154-
formattedFloskell =
155-
"module Format where\n\
156-
\\n\
157-
\foo :: Int -> Int\n\
158-
\foo 3 = 2\n\
159-
\foo x = x\n\
160-
\\n\
161-
\bar :: String -> IO String\n\
162-
\bar s = do\n\
163-
\ x <- return \"hello\"\n\
164-
\ return \"asdf\"\n\n\
165-
\data Baz = Baz { a :: Int, b :: String }\n\n"
166-
167-
formattedBrittanyPostFloskell :: T.Text
168-
formattedBrittanyPostFloskell =
169-
"module Format where\n\
170-
\\n\
171-
\foo :: Int -> Int\n\
172-
\foo 3 = 2\n\
173-
\foo x = x\n\
174-
\\n\
175-
\bar :: String -> IO String\n\
176-
\bar s = do\n\
177-
\ x <- return \"hello\"\n\
178-
\ return \"asdf\"\n\n\
179-
\data Baz = Baz { a :: Int, b :: String }\n\n"

Diff for: test/testdata/BrittanyCRLF.formatted_document.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
foo :: Int -> String -> IO ()
22
foo x y = do
3-
print x
4-
return 42
3+
print x
4+
return 42

Diff for: test/testdata/BrittanyCRLF.formatted_range.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
foo :: Int -> String -> IO ()
1+
foo :: Int -> String-> IO ()
22
foo x y = do
3-
print x
4-
return 42
3+
print x
4+
return 42

Diff for: test/testdata/BrittanyLF.formatted_document.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
foo :: Int -> String -> IO ()
22
foo x y = do
3-
print x
4-
return 42
3+
print x
4+
return 42

Diff for: test/testdata/BrittanyLF.formatted_range.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
foo :: Int -> String -> IO ()
1+
foo :: Int -> String-> IO ()
22
foo x y = do
3-
print x
4-
return 42
3+
print x
4+
return 42

Diff for: test/testdata/Format.brittany.formatted.hs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Format where
2+
foo :: Int -> Int
3+
foo 3 = 2
4+
foo x = x
5+
bar :: String -> IO String
6+
bar s = do
7+
x <- return "hello"
8+
return "asdf"
9+
10+
data Baz = Baz { a :: Int, b :: String }
11+
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Format where
2+
3+
foo :: Int -> Int
4+
foo 3 = 2
5+
foo x = x
6+
7+
bar :: String -> IO String
8+
bar s = do
9+
x <- return "hello"
10+
return "asdf"
11+
12+
data Baz = Baz { a :: Int, b :: String }
13+

Diff for: test/testdata/Format.floskell.formatted.hs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Format where
2+
3+
foo :: Int -> Int
4+
foo 3 = 2
5+
foo x = x
6+
7+
bar :: String -> IO String
8+
bar s = do
9+
x <- return "hello"
10+
return "asdf"
11+
12+
data Baz = Baz { a :: Int, b :: String }
13+

0 commit comments

Comments
 (0)