Skip to content

Commit d7a024e

Browse files
authored
Add Stack setup for GHC 9.2.8 (#2531)
* Bumped Stack snapshot to LTS 18.28 - dhall-lsp-server: Require lsp>=1.5.0.0. * Updated GitHub Actions * Added Stack configuration for GHC 9.2.8 * Added CI job for GHC 8.10 * Allow passing extra arguments to the doctest test suites * Cabal: Use hnix from Git repository * Use single quotes in GHA condition * GHA: Try nested os.runner * GHA: Include used stack.yaml file in job name * Updated mergify config * Also skip package preparation step if we are not using stack.yaml * Updated used actions * Added text-rope.nix * Added co-log-core.nix and lsp.nix * Added lsp-types.nix
1 parent 0e5971c commit d7a024e

File tree

20 files changed

+277
-91
lines changed

20 files changed

+277
-91
lines changed

.github/workflows/main.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,30 @@ jobs:
2121
archive-command: '7z a -tzip'
2222
file-extension: 'zip'
2323
executable-extension: '.exe'
24+
stack-yaml:
25+
- "stack.yaml"
26+
include:
27+
- os:
28+
runner: "ubuntu-latest"
29+
stack-yaml: "stack.ghc-8.10.yaml"
2430
fail-fast: false
25-
name: ${{ matrix.os.runner }}
31+
name: ${{ matrix.os.runner }} - ${{ matrix.stack-yaml }}
2632
runs-on: ${{ matrix.os.runner }}
2733
steps:
2834
- name: "Checkout repository"
29-
uses: actions/checkout@v2
35+
uses: actions/checkout@v4
3036
with:
3137
submodules: true
3238
- id: setup-haskell-cabal
3339
name: "Setup Haskell environment"
34-
uses: haskell/actions/setup@v2.4.6
40+
uses: haskell-actions/setup@v2.5
3541
with:
3642
enable-stack: true
43+
stack-version: "latest"
3744
- name: "Cache"
38-
uses: actions/cache@v2
45+
uses: actions/cache@v3
3946
with:
40-
key: ${{ matrix.os.runner }}-${{ hashFiles('stack.yaml') }}-${{ env.cache_generation }}
47+
key: ${{ matrix.os.runner }}-${{ hashFiles(matrix.stack-yaml) }}-${{ env.cache_generation }}
4148
restore-keys: |
4249
${{ matrix.os.runner }}-
4350
path: |
@@ -71,7 +78,7 @@ jobs:
7178
# We use --test --no-run-tests to avoid re-building all the local packages in the
7279
# subsequent test step.
7380
# See https://github.com/commercialhaskell/stack/issues/4977.
74-
stack build --test --no-run-tests --copy-bins --local-bin-path ./bin "${package}"
81+
stack --stack-yaml "${{matrix.stack-yaml}}" build --test --no-run-tests --copy-bins --local-bin-path ./bin "${package}"
7582
done
7683
- name: "Run tests"
7784
shell: bash
@@ -93,16 +100,18 @@ jobs:
93100
continue
94101
fi
95102
96-
stack test "${package}"
103+
stack --stack-yaml "${{matrix.stack-yaml}}" test "${package}"
97104
done
98105
- name: "Prepare packaging"
106+
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
99107
shell: bash
100108
run: |
101109
mkdir -p share/man/man1
102110
cp dhall/man/dhall.1 share/man/man1/
103111
cp dhall-docs/src/Dhall/data/man/dhall-docs.1 share/man/man1/
104112
- id: package
105113
name: "Create packages"
114+
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
106115
shell: bash
107116
run: |
108117
packages=(
@@ -143,7 +152,8 @@ jobs:
143152
package 'dhall-toml' "bin/dhall-to-toml${exe}" "bin/toml-to-dhall${exe}"
144153
package 'dhall-yaml' "bin/dhall-to-yaml-ng${exe}" "bin/yaml-to-dhall${exe}"
145154
- name: "Upload package"
146-
uses: actions/upload-artifact@v2
155+
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
156+
uses: actions/upload-artifact@v3
147157
with:
148158
name: 'dhall-${{runner.os}}.${{matrix.os.file-extension}}'
149159
path: 'dhall-*${{runner.os}}.${{matrix.os.file-extension}}'

.mergify.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ queue_rules:
44
- check-success=hydra
55
# Mergify explicitly recommends listing each status check separately:
66
# https://docs.mergify.io/conditions/#validating-all-status-checks
7-
- check-success=macOS-latest
8-
- check-success=ubuntu-latest
9-
- check-success=windows-latest
7+
- check-success=macOS-latest - stack.yaml
8+
- check-success=ubuntu-latest - stack.yaml
9+
- check-success=windows-latest - stack.yaml
1010
pull_request_rules:
1111
- actions:
1212
queue:

cabal.project

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
packages: ./dhall ./dhall-bash ./dhall-json ./dhall-yaml ./dhall-nix ./dhall-docs ./dhall-openapi ./dhall-nixpkgs ./dhall-csv ./dhall-toml ./dhall-lsp-server
1+
packages:
2+
./dhall
3+
./dhall-bash
4+
./dhall-csv
5+
./dhall-docs
6+
./dhall-json
7+
./dhall-lsp-server
8+
./dhall-nix
9+
./dhall-nixpkgs
10+
./dhall-openapi
11+
./dhall-toml
12+
./dhall-yaml
13+
14+
source-repository-package
15+
type: git
16+
location: https://github.com/haskell-nix/hnix.git
17+
tag: 2adbc502e62e755ca0372c913e6278ebe564d7d2

dhall-docs/doctest/Main.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
module Main where
1+
module Main (main) where
22

33
import System.FilePath ((</>))
44

55
import qualified GHC.IO.Encoding
66
import qualified System.Directory
7+
import qualified System.Environment
78
import qualified System.IO
89
import qualified Test.DocTest
910

1011
main :: IO ()
1112
main = do
1213
GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
13-
pwd <- System.Directory.getCurrentDirectory
14+
args <- System.Environment.getArgs
15+
pwd <- System.Directory.getCurrentDirectory
1416
prefix <- System.Directory.makeAbsolute pwd
15-
Test.DocTest.doctest
17+
let src = prefix </> "src"
18+
19+
Test.DocTest.doctest $
1620
[ "--fast"
17-
, prefix </> "src"
21+
] <> args <>
22+
[ src
1823
]

dhall-lsp-server/dhall-lsp-server.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ library
4646
, aeson-pretty >= 0.8.7 && < 0.9
4747
, base >= 4.11 && < 5
4848
, bytestring >= 0.10.8.2 && < 0.12
49+
, co-log-core >= 0.3.1.0 && < 0.4
4950
, containers >= 0.5.11.0 && < 0.7
5051
, data-default >= 0.7.1.1 && < 0.8
5152
, directory >= 1.2.2.0 && < 1.4
5253
, dhall >= 1.38.0 && < 1.43
5354
, dhall-json >= 1.4 && < 1.8
5455
, filepath >= 1.4.2 && < 1.5
55-
, lsp >= 1.2.0.0 && < 1.5
56-
, rope-utf16-splay >= 0.3.1.0 && < 0.5
57-
, hslogger >= 1.2.10 && < 1.4
56+
, lsp >= 1.5.0.0 && < 2
5857
, lens >= 4.16.1 && < 5.3
5958
-- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469
6059
, megaparsec >= 7.0.2 && < 10
6160
, mtl >= 2.2.2 && < 2.3
6261
, network-uri >= 2.6.1.0 && < 2.7
6362
, prettyprinter >= 1.7.0 && < 1.8
6463
, text >= 1.2.3.0 && < 2.1
64+
, text-rope >= 0.2 && < 0.3
6565
, transformers >= 0.5.5.0 && < 0.6
6666
, unordered-containers >= 0.2.9.0 && < 0.3
6767
, uri-encode >= 1.5.0.5 && < 1.6
@@ -104,7 +104,7 @@ Test-Suite tests
104104
GHC-Options: -Wall
105105
Build-Depends:
106106
base ,
107-
lsp-types >= 1.2.0.0 && < 1.5 ,
107+
lsp-types >= 1.2.0.0 && < 1.7 ,
108108
hspec >= 2.7 && < 2.11 ,
109109
lsp-test >= 0.13.0.0 && < 0.15 ,
110110
tasty >= 0.11.2 && < 1.5 ,

dhall-lsp-server/doctest/Main.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
module Main where
1+
module Main (main) where
22

33
import System.FilePath ((</>))
44

55
import qualified GHC.IO.Encoding
66
import qualified System.Directory
7+
import qualified System.Environment
78
import qualified System.IO
89
import qualified Test.DocTest
910

1011
main :: IO ()
1112
main = do
12-
1313
GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
14-
pwd <- System.Directory.getCurrentDirectory
14+
args <- System.Environment.getArgs
15+
pwd <- System.Directory.getCurrentDirectory
1516
prefix <- System.Directory.makeAbsolute pwd
17+
let src = prefix </> "src"
1618

17-
Test.DocTest.doctest
19+
Test.DocTest.doctest $
1820
[ "--fast"
1921
, "-XOverloadedStrings"
2022
, "-XRecordWildCards"
21-
, "-i" <> (prefix </> "src")
22-
, prefix </> "src/Dhall/LSP/Backend/Diagnostics.hs"
23+
] <> args <>
24+
[ "-i" <> src
25+
, src </> "Dhall/LSP/Backend/Diagnostics.hs"
2326
]

dhall-lsp-server/src/Dhall/LSP/Handlers.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import Text.Megaparsec (SourcePos (..), unPos)
7575
import qualified Data.Aeson as Aeson
7676
import qualified Data.HashMap.Strict as HashMap
7777
import qualified Data.Map.Strict as Map
78-
import qualified Data.Rope.UTF16 as Rope
78+
import qualified Data.Text.Utf16.Rope as Rope
7979
import qualified Data.Text as Text
8080
import qualified Language.LSP.Server as LSP
8181
import qualified Language.LSP.Types as LSP.Types
@@ -617,12 +617,12 @@ didSaveTextDocumentNotificationHandler =
617617

618618
-- this handler is a stab to prevent `lsp:no handler for:` messages.
619619
initializedHandler :: Handlers HandlerM
620-
initializedHandler =
620+
initializedHandler =
621621
LSP.notificationHandler SInitialized \_ -> return ()
622622

623623
-- this handler is a stab to prevent `lsp:no handler for:` messages.
624624
workspaceChangeConfigurationHandler :: Handlers HandlerM
625-
workspaceChangeConfigurationHandler =
625+
workspaceChangeConfigurationHandler =
626626
LSP.notificationHandler SWorkspaceDidChangeConfiguration \_ -> return ()
627627

628628
-- this handler is a stab to prevent `lsp:no handler for:` messages.
@@ -639,7 +639,7 @@ handleErrorWithDefault :: (Either a1 b -> HandlerM a2)
639639
-> b
640640
-> HandlerM a2
641641
-> HandlerM a2
642-
handleErrorWithDefault respond _default = flip catchE handler
642+
handleErrorWithDefault respond _default = flip catchE handler
643643
where
644644
handler (Log, _message) = do
645645
let _xtype = MtLog

dhall-lsp-server/src/Dhall/LSP/Server.hs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{-# LANGUAGE BlockArguments #-}
22
{-# LANGUAGE ExplicitNamespaces #-}
3+
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE RecordWildCards #-}
45

56
{-| This is the entry point for the LSP server. -}
67
module Dhall.LSP.Server(run) where
78

9+
import Colog.Core (LogAction, WithSeverity)
810
import Control.Monad.IO.Class (liftIO)
911
import Data.Aeson (fromJSON)
1012
import Data.Default
@@ -22,23 +24,28 @@ import Dhall.LSP.Handlers
2224
, cancelationHandler
2325
)
2426
import Dhall.LSP.State
25-
import Language.LSP.Server (Options(..), ServerDefinition(..), type (<~>)(..))
27+
import Language.LSP.Server (LspServerLog, Options(..), ServerDefinition(..), type (<~>)(..))
2628
import Language.LSP.Types
29+
import Prettyprinter (Doc, Pretty, pretty, viaShow)
2730
import System.Exit (ExitCode(..))
31+
import System.IO (stdin, stdout)
2832

33+
import qualified Colog.Core as Colog
2934
import qualified Control.Concurrent.MVar as MVar
3035
import qualified Control.Monad.Trans.Except as Except
3136
import qualified Control.Monad.Trans.State.Strict as State
3237
import qualified Data.Aeson as Aeson
3338
import qualified Data.Text as Text
39+
import qualified Language.LSP.Logging as LSP
3440
import qualified Language.LSP.Server as LSP
3541
import qualified System.Exit as Exit
36-
import qualified System.Log.Logger
3742

3843
-- | The main entry point for the LSP server.
3944
run :: Maybe FilePath -> IO ()
40-
run mlog = do
41-
setupLogger mlog
45+
run = withLogger $ \ioLogger -> do
46+
let clientLogger = Colog.cmap (fmap (Text.pack . show . pretty)) LSP.defaultClientLogger
47+
48+
let lspLogger = clientLogger <> Colog.hoistLogAction liftIO ioLogger
4249

4350
state <- MVar.newMVar initialState
4451

@@ -117,20 +124,26 @@ run mlog = do
117124

118125
backward = liftIO
119126

120-
exitCode <- LSP.runServer ServerDefinition{..}
127+
exitCode <- LSP.runServerWithHandles ioLogger lspLogger stdin stdout ServerDefinition{..}
121128

122129
case exitCode of
123130
0 -> return ()
124131
n -> Exit.exitWith (ExitFailure n)
125132

126-
-- | sets the output logger.
127-
-- | if no filename is provided then logger is disabled, if input is string `[OUTPUT]` then log goes to stderr,
128-
-- | which then redirects inside VSCode to the output pane of the plugin.
129-
setupLogger :: Maybe FilePath -> IO () -- TODO: ADD verbosity
130-
setupLogger Nothing = pure ()
131-
setupLogger (Just "[OUTPUT]") = LSP.setupLogger Nothing [] System.Log.Logger.DEBUG
132-
setupLogger file = LSP.setupLogger file [] System.Log.Logger.DEBUG
133-
133+
-- | Retrieve the output logger.
134+
-- If no filename is provided then logger is disabled, if input is the string
135+
-- `[OUTPUT]` then we log to stderr.
136+
-- TODO: ADD verbosity
137+
withLogger :: (LogAction IO (WithSeverity LspServerLog) -> IO ()) -> Maybe FilePath -> IO ()
138+
withLogger k = \case
139+
Nothing -> k (Colog.LogAction (const (pure ())))
140+
Just "[OUTPUT]" -> k' Colog.logStringStderr
141+
Just fp -> Colog.withLogStringFile fp k'
142+
where
143+
k' = k . Colog.cmap (show . prettyMsg)
144+
145+
prettyMsg :: Pretty a => WithSeverity a -> Doc ann
146+
prettyMsg l = "[" <> viaShow (Colog.getSeverity l) <> "] " <> pretty (Colog.getMsg l)
134147

135148
-- Tells the LSP client to notify us about file changes. Handled behind the
136149
-- scenes by haskell-lsp (in Language.Haskell.LSP.VFS); we don't handle the

dhall-toml/doctest/Main.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
module Main where
1+
module Main (main) where
22

33
import System.FilePath ((</>))
44

5+
import qualified GHC.IO.Encoding
56
import qualified System.Directory
7+
import qualified System.Environment
8+
import qualified System.IO
69
import qualified Test.DocTest
710

811
main :: IO ()
912
main = do
13+
GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
14+
args <- System.Environment.getArgs
1015
pwd <- System.Directory.getCurrentDirectory
1116
prefix <- System.Directory.makeAbsolute pwd
1217
let src = prefix </> "src"
13-
Test.DocTest.doctest [ "--fast", "-i" <> src, src ]
1418

19+
Test.DocTest.doctest $
20+
[ "--fast"
21+
] <> args <>
22+
[ "-i" <> src
23+
, src
24+
]

dhall/doctest/Main.hs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE CPP #-}
22

3-
module Main where
3+
module Main (main) where
44

55
import System.FilePath ((</>))
66

@@ -13,10 +13,11 @@ import qualified Test.Mockery.Directory
1313

1414
main :: IO ()
1515
main = do
16-
1716
GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
18-
pwd <- System.Directory.getCurrentDirectory
17+
args <- System.Environment.getArgs
18+
pwd <- System.Directory.getCurrentDirectory
1919
prefix <- System.Directory.makeAbsolute pwd
20+
let src = prefix </> "src"
2021

2122
System.Environment.setEnv "XDG_CACHE_HOME" (pwd </> ".cache")
2223

@@ -34,11 +35,12 @@ main = do
3435
, "in { name = \"Simon\", favoriteFont = Font.`Comic Sans` } : Person"
3536
]
3637

37-
Test.DocTest.doctest
38+
Test.DocTest.doctest $
3839
[ "-DWITH_HTTP"
3940
, "-DUSE_HTTP_CLIENT_TLS"
4041
, "--fast"
41-
, prefix </> "ghc-src"
42+
] <> args <>
43+
[ prefix </> "ghc-src"
4244

4345
-- Unfortunately we cannot target the entire @src@ directory.
4446
-- The reason is that src/Dhall/Version.hs depends on
@@ -47,11 +49,11 @@ main = do
4749
-- Instead, we target a selection of modules whose combined module
4850
-- dependency tree covers all modules that contain doctests.
4951

50-
-- , prefix </> "src"
51-
, "-i" <> (prefix </> "src")
52+
-- , src
53+
, "-i" <> src
5254
#if __GLASGOW_HASKELL__ >= 806
53-
, prefix </> "src/Dhall/Deriving.hs"
55+
, src </> "Dhall/Deriving.hs"
5456
#endif
55-
, prefix </> "src/Dhall/Tags.hs"
56-
, prefix </> "src/Dhall/Tutorial.hs"
57+
, src </> "Dhall/Tags.hs"
58+
, src </> "Dhall/Tutorial.hs"
5759
]

0 commit comments

Comments
 (0)