Skip to content

Commit 9d3d0e6

Browse files
committed
Accept the legacy "languageServerHaskell" config name
This also requires a bump to lsp-test to fix a test, and drops the trick that the wrapper tests used to find the wrapper executable since it was just confusing
1 parent f2384e1 commit 9d3d0e6

13 files changed

+36
-103
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
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

haskell-language-server.cabal

Lines changed: 2 additions & 2 deletions
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.10.0.3
249249
, tasty
250250
, tasty-ant-xml >= 1.1.6
251251
, tasty-expected-failure

src/Ide/Plugin/Config.hs

Lines changed: 4 additions & 1 deletion
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

stack-8.10.1.yaml

Lines changed: 1 addition & 1 deletion
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

stack-8.6.4.yaml

Lines changed: 1 addition & 1 deletion
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

stack-8.6.5.yaml

Lines changed: 1 addition & 1 deletion
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

stack-8.8.2.yaml

Lines changed: 1 addition & 1 deletion
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

stack-8.8.3.yaml

Lines changed: 1 addition & 1 deletion
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

stack-8.8.4.yaml

Lines changed: 1 addition & 1 deletion
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

stack.yaml

Lines changed: 1 addition & 1 deletion
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

test/functional/Format.hs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Language.Haskell.LSP.Test
1010
import Language.Haskell.LSP.Types
1111
import Test.Hls.Util
1212
import Test.Tasty
13-
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
1413
import Test.Tasty.Golden
1514
import Test.Tasty.HUnit
1615
import Test.Hspec.Expectations
@@ -56,7 +55,7 @@ providerTests = testGroup "formatting provider" [
5655
formatRange doc (FormattingOptions 2 True) (Range (Position 1 0) (Position 3 10))
5756
documentContents doc >>= liftIO . (`shouldBe` orig)
5857

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

6261
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
@@ -70,6 +69,17 @@ providerTests = testGroup "formatting provider" [
7069
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
7170
formatDoc doc (FormattingOptions 2 True)
7271
documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
72+
, testCase "supports both new and old configuration sections" $ runSession hieCommand fullCaps "test/testdata" $ do
73+
doc <- openDoc "Format.hs" "haskell"
74+
75+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "brittany"))
76+
formatDoc doc (FormattingOptions 2 True)
77+
documentContents doc >>= liftIO . (`shouldBe` formattedBrittany)
78+
79+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "floskell"))
80+
formatDoc doc (FormattingOptions 2 True)
81+
documentContents doc >>= liftIO . (`shouldBe` formattedFloskell)
82+
7383
]
7484

7585
stylishHaskellTests :: TestTree
@@ -89,22 +99,26 @@ stylishHaskellTests = testGroup "stylish-haskell" [
8999
brittanyTests :: TestTree
90100
brittanyTests = testGroup "brittany" [
91101
goldenVsStringDiff "formats a document with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_document.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
102+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
92103
doc <- openDoc "BrittanyLF.hs" "haskell"
93104
formatDoc doc (FormattingOptions 4 True)
94105
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
95106

96107
, goldenVsStringDiff "formats a document with CRLF endings" goldenGitDiff "test/testdata/BrittanyCRLF.formatted_document.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
108+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
97109
doc <- openDoc "BrittanyCRLF.hs" "haskell"
98110
formatDoc doc (FormattingOptions 4 True)
99111
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
100112

101113
, goldenVsStringDiff "formats a range with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_range.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
114+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
102115
doc <- openDoc "BrittanyLF.hs" "haskell"
103116
let range = Range (Position 1 0) (Position 2 22)
104117
formatRange doc (FormattingOptions 4 True) range
105118
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
106119

107120
, goldenVsStringDiff "formats a range with CRLF endings" goldenGitDiff "test/testdata/BrittanyCRLF.formatted_range.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
121+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
108122
doc <- openDoc "BrittanyCRLF.hs" "haskell"
109123
let range = Range (Position 1 0) (Position 2 22)
110124
formatRange doc (FormattingOptions 4 True) range
@@ -114,8 +128,6 @@ brittanyTests = testGroup "brittany" [
114128
ormoluTests :: TestTree
115129
ormoluTests = testGroup "ormolu" [
116130
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)] ]
119131
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
120132
doc <- openDoc "Format.hs" "haskell"
121133
formatDoc doc (FormattingOptions 2 True)
@@ -131,6 +143,10 @@ ormoluTests = testGroup "ormolu" [
131143
formatLspConfig :: Value -> Value
132144
formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ]
133145

146+
-- | The same as 'formatLspConfig' but using the legacy section name
147+
formatLspConfigOld :: Value -> Value
148+
formatLspConfigOld provider = object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
149+
134150
formatConfig :: Value -> SessionConfig
135151
formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
136152

test/utils/Test/Hls/Util.hs

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -14,91 +14,28 @@ module Test.Hls.Util
1414
, noLogConfig
1515
, setupBuildToolFiles
1616
, withFileLogging
17-
, findExe
1817
, withCurrentDirectoryInTmp
19-
-- , makeRequest
20-
-- , runIGM
21-
-- , runIGM'
22-
-- , runSingle
23-
-- , runSingle'
24-
-- , runSingleReq
25-
-- , testCommand
26-
-- , testOptions
2718
)
2819
where
2920

30-
import Control.Applicative
31-
-- import Control.Concurrent.STM
3221
import Control.Monad
33-
import Control.Monad.Trans.Maybe
3422
import Data.Default
3523
import Data.List (intercalate)
36-
-- import Data.Typeable
37-
-- import qualified Data.Map as Map
3824
import Data.Maybe
3925
import Language.Haskell.LSP.Core
4026
import Language.Haskell.LSP.Types
4127
import qualified Language.Haskell.LSP.Test as T
4228
import qualified Language.Haskell.LSP.Types.Capabilities as C
43-
-- import Haskell.Ide.Engine.MonadTypes hiding (withProgress, withIndefiniteProgress)
44-
-- import qualified Ide.Cradle as Bios
45-
-- import qualified Ide.Engine.Config as Config
4629
import System.Directory
4730
import System.Environment
4831
import System.FilePath
4932
import qualified System.Log.Logger as L
5033
import System.IO.Temp
51-
-- import Test.Hspec
5234
import Test.Hspec.Runner
5335
import Test.Hspec.Core.Formatters
5436
import Text.Blaze.Renderer.String (renderMarkup)
5537
import Text.Blaze.Internal
56-
-- import qualified Haskell.Ide.Engine.PluginApi as HIE (BiosOptions, defaultOptions)
57-
-- import HIE.Bios.Types
5838

59-
-- testOptions :: HIE.BiosOptions
60-
-- testOptions = HIE.defaultOptions { cradleOptsVerbosity = Verbose }
61-
62-
-- ---------------------------------------------------------------------
63-
64-
65-
-- testCommand :: (ToJSON a, Typeable b, ToJSON b, Show b, Eq b)
66-
-- => IdePlugins -> FilePath -> IdeGhcM (IdeResult b) -> PluginId -> CommandId -> a -> IdeResult b -> IO ()
67-
-- testCommand testPlugins fp act plugin cmd arg res = do
68-
-- flushStackEnvironment
69-
-- (newApiRes, oldApiRes) <- runIGM testPlugins fp $ do
70-
-- new <- act
71-
-- old <- makeRequest plugin cmd arg
72-
-- return (new, old)
73-
-- newApiRes `shouldBe` res
74-
-- fmap fromDynJSON oldApiRes `shouldBe` fmap Just res
75-
76-
-- runSingle :: IdePlugins -> FilePath -> IdeGhcM (IdeResult b) -> IO (IdeResult b)
77-
-- runSingle = runSingle' id
78-
79-
-- runSingle' :: (Config.Config -> Config.Config) -> IdePlugins -> FilePath -> IdeGhcM (IdeResult b) -> IO (IdeResult b)
80-
-- runSingle' modifyConfig testPlugins fp act = runIGM' modifyConfig testPlugins fp act
81-
82-
-- runSingleReq :: ToJSON a
83-
-- => IdePlugins -> FilePath -> PluginId -> CommandId -> a -> IO (IdeResult DynamicJSON)
84-
-- runSingleReq testPlugins fp plugin com arg = runIGM testPlugins fp (makeRequest plugin com arg)
85-
86-
-- makeRequest :: ToJSON a => PluginId -> CommandId -> a -> IdeGhcM (IdeResult DynamicJSON)
87-
-- makeRequest plugin com arg = runPluginCommand plugin com (toJSON arg)
88-
89-
-- runIGM :: IdePlugins -> FilePath -> IdeGhcM a -> IO a
90-
-- runIGM = runIGM' id
91-
92-
-- runIGM' :: (Config.Config -> Config.Config) -> IdePlugins -> FilePath -> IdeGhcM a -> IO a
93-
-- runIGM' modifyConfig testPlugins fp f = do
94-
-- stateVar <- newTVarIO $ IdeState emptyModuleCache Map.empty Map.empty Nothing
95-
-- crdl <- Bios.findLocalCradle fp
96-
-- mlibdir <- Bios.getProjectGhcLibDir crdl
97-
-- let tmpFuncs :: LspFuncs Config.Config
98-
-- tmpFuncs = dummyLspFuncs
99-
-- lspFuncs :: LspFuncs Config.Config
100-
-- lspFuncs = tmpFuncs { config = (fmap . fmap) modifyConfig (config tmpFuncs)}
101-
-- runIdeGhcM mlibdir testPlugins lspFuncs stateVar f
10239

10340
noLogConfig :: T.SessionConfig
10441
noLogConfig = T.defaultConfig { T.logMessages = False }
@@ -316,28 +253,6 @@ dummyLspFuncs = LspFuncs { clientCapabilities = def
316253
, withIndefiniteProgress = \_ _ f -> f
317254
}
318255

319-
findExeRecursive :: FilePath -> FilePath -> IO (Maybe FilePath)
320-
findExeRecursive exe dir = do
321-
me <- listToMaybe <$> findExecutablesInDirectories [dir] exe
322-
case me of
323-
Just e -> return (Just e)
324-
Nothing -> do
325-
subdirs <- (fmap (dir </>)) <$> listDirectory dir >>= filterM doesDirectoryExist
326-
foldM (\acc subdir -> case acc of
327-
Just y -> pure $ Just y
328-
Nothing -> findExeRecursive exe subdir)
329-
Nothing
330-
subdirs
331-
332-
-- | So we can find an executable with cabal run
333-
-- since it doesnt put build tools on the path (only cabal test)
334-
findExe :: String -> IO FilePath
335-
findExe name = do
336-
fp <- fmap fromJust $ runMaybeT $
337-
MaybeT (findExecutable name) <|>
338-
MaybeT (findExeRecursive name "dist-newstyle")
339-
makeAbsolute fp
340-
341256
-- | Like 'withCurrentDirectory', but will copy the directory over to the system
342257
-- temporary directory first to avoid haskell-language-server's source tree from
343258
-- interfering with the cradle

test/wrapper/Main.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ projectGhcVersionTests = testGroup "--project-ghc-version"
2323
]
2424

2525
testDir :: FilePath -> String -> Assertion
26-
testDir dir expectedVer = do
27-
wrapper <- findExe "haskell-language-server-wrapper"
26+
testDir dir expectedVer =
2827
withCurrentDirectoryInTmp dir $ do
29-
actualVer <- trim <$> readProcess wrapper ["--project-ghc-version"] ""
28+
actualVer <- trim <$> readProcess "haskell-language-server-wrapper" ["--project-ghc-version"] ""
3029
actualVer @?= expectedVer
3130

3231
trim :: String -> String

0 commit comments

Comments
 (0)