Skip to content

Commit

Permalink
Add Stack setup for GHC 9.2.8 (dhall-lang#2531)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rvl committed Feb 23, 2024
1 parent e95da18 commit bcc1545
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 84 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@ jobs:
archive-command: '7z a -tzip'
file-extension: 'zip'
executable-extension: '.exe'
stack-yaml:
- "stack.yaml"
include:
- os:
runner: "ubuntu-latest"
stack-yaml: "stack.ghc-8.10.yaml"
fail-fast: false
name: ${{ matrix.os.runner }}
name: ${{ matrix.os.runner }} - ${{ matrix.stack-yaml }}
runs-on: ${{ matrix.os.runner }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: true
- id: setup-haskell-cabal
name: "Setup Haskell environment"
uses: haskell/actions/setup@v2.4.6
uses: haskell-actions/setup@v2.5
with:
enable-stack: true
stack-version: "latest"
- name: "Cache"
uses: actions/cache@v2
uses: actions/cache@v3
with:
key: ${{ matrix.os.runner }}-${{ hashFiles('stack.yaml') }}-${{ env.cache_generation }}
key: ${{ matrix.os.runner }}-${{ hashFiles(matrix.stack-yaml) }}-${{ env.cache_generation }}
restore-keys: |
${{ matrix.os.runner }}-
path: |
Expand Down Expand Up @@ -71,7 +78,7 @@ jobs:
# We use --test --no-run-tests to avoid re-building all the local packages in the
# subsequent test step.
# See https://github.com/commercialhaskell/stack/issues/4977.
stack build --test --no-run-tests --copy-bins --local-bin-path ./bin "${package}"
stack --stack-yaml "${{matrix.stack-yaml}}" build --test --no-run-tests --copy-bins --local-bin-path ./bin "${package}"
done
- name: "Run tests"
shell: bash
Expand All @@ -93,16 +100,18 @@ jobs:
continue
fi
stack test "${package}"
stack --stack-yaml "${{matrix.stack-yaml}}" test "${package}"
done
- name: "Prepare packaging"
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
shell: bash
run: |
mkdir -p share/man/man1
cp dhall/man/dhall.1 share/man/man1/
cp dhall-docs/src/Dhall/data/man/dhall-docs.1 share/man/man1/
- id: package
name: "Create packages"
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
shell: bash
run: |
packages=(
Expand Down Expand Up @@ -143,7 +152,8 @@ jobs:
package 'dhall-toml' "bin/dhall-to-toml${exe}" "bin/toml-to-dhall${exe}"
package 'dhall-yaml' "bin/dhall-to-yaml-ng${exe}" "bin/yaml-to-dhall${exe}"
- name: "Upload package"
uses: actions/upload-artifact@v2
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
uses: actions/upload-artifact@v3
with:
name: 'dhall-${{runner.os}}.${{matrix.os.file-extension}}'
path: 'dhall-*${{runner.os}}.${{matrix.os.file-extension}}'
6 changes: 3 additions & 3 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ queue_rules:
- check-success=hydra
# Mergify explicitly recommends listing each status check separately:
# https://docs.mergify.io/conditions/#validating-all-status-checks
- check-success=macOS-latest
- check-success=ubuntu-latest
- check-success=windows-latest
- check-success=macOS-latest - stack.yaml
- check-success=ubuntu-latest - stack.yaml
- check-success=windows-latest - stack.yaml
pull_request_rules:
- actions:
queue:
Expand Down
13 changes: 9 additions & 4 deletions dhall-docs/doctest/Main.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
module Main where
module Main (main) where

import System.FilePath ((</>))

import qualified GHC.IO.Encoding
import qualified System.Directory
import qualified System.Environment
import qualified System.IO
import qualified Test.DocTest

main :: IO ()
main = do
GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
pwd <- System.Directory.getCurrentDirectory
args <- System.Environment.getArgs
pwd <- System.Directory.getCurrentDirectory
prefix <- System.Directory.makeAbsolute pwd
Test.DocTest.doctest
let src = prefix </> "src"

Test.DocTest.doctest $
[ "--fast"
, prefix </> "src"
] <> args <>
[ src
]
4 changes: 2 additions & 2 deletions dhall-lsp-server/dhall-lsp-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ library
, aeson-pretty >= 0.8.7 && < 0.9
, base >= 4.11 && < 5
, bytestring >= 0.10.8.2 && < 0.12
, co-log-core >= 0.3.1.0 && < 0.4
, containers >= 0.5.11.0 && < 0.7
, data-default >= 0.7.1.1 && < 0.8
, directory >= 1.2.2.0 && < 1.4
, dhall >= 1.38.0 && < 1.43
, dhall-json >= 1.4 && < 1.8
, filepath >= 1.4.2 && < 1.5
, lsp >= 2.1.0.0 && < 2.2
, rope-utf16-splay >= 0.3.1.0 && < 0.5
, hslogger >= 1.2.10 && < 1.4
, lens >= 4.16.1 && < 5.3
-- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469
, megaparsec >= 7.0.2 && < 10
, mtl >= 2.2.2 && < 2.4
, network-uri >= 2.6.1.0 && < 2.7
, prettyprinter >= 1.7.0 && < 1.8
, text >= 1.2.3.0 && < 2.1
, text-rope >= 0.2 && < 0.3
, transformers >= 0.5.5.0 && < 0.7
, unordered-containers >= 0.2.9.0 && < 0.3
, uri-encode >= 1.5.0.5 && < 1.6
Expand Down
15 changes: 9 additions & 6 deletions dhall-lsp-server/doctest/Main.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
module Main where
module Main (main) where

import System.FilePath ((</>))

import qualified GHC.IO.Encoding
import qualified System.Directory
import qualified System.Environment
import qualified System.IO
import qualified Test.DocTest

main :: IO ()
main = do

GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
pwd <- System.Directory.getCurrentDirectory
args <- System.Environment.getArgs
pwd <- System.Directory.getCurrentDirectory
prefix <- System.Directory.makeAbsolute pwd
let src = prefix </> "src"

Test.DocTest.doctest
Test.DocTest.doctest $
[ "--fast"
, "-XOverloadedStrings"
, "-XRecordWildCards"
, "-i" <> (prefix </> "src")
, prefix </> "src/Dhall/LSP/Backend/Diagnostics.hs"
] <> args <>
[ "-i" <> src
, src </> "Dhall/LSP/Backend/Diagnostics.hs"
]
2 changes: 1 addition & 1 deletion dhall-lsp-server/src/Dhall/LSP/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import Text.Megaparsec (SourcePos (..), unPos)

import qualified Data.Aeson as Aeson
import qualified Data.Map.Strict as Map
import qualified Data.Rope.UTF16 as Rope
import qualified Data.Text.Utf16.Rope as Rope
import qualified Data.Text as Text
import qualified Language.LSP.Server as LSP
import qualified Language.LSP.Protocol.Types as LSP.Types
Expand Down
37 changes: 25 additions & 12 deletions dhall-lsp-server/src/Dhall/LSP/Server.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}

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

import Colog.Core (LogAction, WithSeverity)
import Control.Monad.IO.Class (liftIO)
import Data.Aeson (fromJSON)
import Data.Default
Expand All @@ -25,21 +27,26 @@ import Dhall.LSP.State
import Language.LSP.Server (LspServerLog, Options(..), ServerDefinition(..), type (<~>)(..))
import Language.LSP.Protocol.Types
import Language.LSP.Protocol.Message
import Prettyprinter (Doc, Pretty, pretty, viaShow)
import System.Exit (ExitCode(..))
import System.IO (stdin, stdout)

import qualified Colog.Core as Colog
import qualified Control.Concurrent.MVar as MVar
import qualified Control.Monad.Trans.Except as Except
import qualified Control.Monad.Trans.State.Strict as State
import qualified Data.Aeson as Aeson
import qualified Data.Text as Text
import qualified Language.LSP.Logging as LSP
import qualified Language.LSP.Server as LSP
import qualified System.Exit as Exit
import qualified System.Log.Logger

-- | The main entry point for the LSP server.
run :: Maybe FilePath -> IO ()
run mlog = do
setupLogger mlog
run = withLogger $ \ioLogger -> do
let clientLogger = Colog.cmap (fmap (Text.pack . show . pretty)) LSP.defaultClientLogger

let lspLogger = clientLogger <> Colog.hoistLogAction liftIO ioLogger

state <- MVar.newMVar initialState

Expand Down Expand Up @@ -118,20 +125,26 @@ run mlog = do

backward = liftIO

exitCode <- LSP.runServer ServerDefinition{..}
exitCode <- LSP.runServerWithHandles ioLogger lspLogger stdin stdout ServerDefinition{..}

case exitCode of
0 -> return ()
n -> Exit.exitWith (ExitFailure n)

-- | sets the output logger.
-- | if no filename is provided then logger is disabled, if input is string `[OUTPUT]` then log goes to stderr,
-- | which then redirects inside VSCode to the output pane of the plugin.
setupLogger :: Maybe FilePath -> IO () -- TODO: ADD verbosity
setupLogger Nothing = pure ()
setupLogger (Just "[OUTPUT]") = LSP.setupLogger Nothing [] System.Log.Logger.DEBUG
setupLogger file = LSP.setupLogger file [] System.Log.Logger.DEBUG

-- | Retrieve the output logger.
-- If no filename is provided then logger is disabled, if input is the string
-- `[OUTPUT]` then we log to stderr.
-- TODO: ADD verbosity
withLogger :: (LogAction IO (WithSeverity LspServerLog) -> IO ()) -> Maybe FilePath -> IO ()
withLogger k = \case
Nothing -> k (Colog.LogAction (const (pure ())))
Just "[OUTPUT]" -> k' Colog.logStringStderr
Just fp -> Colog.withLogStringFile fp k'
where
k' = k . Colog.cmap (show . prettyMsg)

prettyMsg :: Pretty a => WithSeverity a -> Doc ann
prettyMsg l = "[" <> viaShow (Colog.getSeverity l) <> "] " <> pretty (Colog.getMsg l)

-- Tells the LSP client to notify us about file changes. Handled behind the
-- scenes by haskell-lsp (in Language.Haskell.LSP.VFS); we don't handle the
Expand Down
14 changes: 12 additions & 2 deletions dhall-toml/doctest/Main.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
module Main where
module Main (main) where

import System.FilePath ((</>))

import qualified GHC.IO.Encoding
import qualified System.Directory
import qualified System.Environment
import qualified System.IO
import qualified Test.DocTest

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

Test.DocTest.doctest $
[ "--fast"
] <> args <>
[ "-i" <> src
, src
]
22 changes: 12 additions & 10 deletions dhall/doctest/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE CPP #-}

module Main where
module Main (main) where

import System.FilePath ((</>))

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

main :: IO ()
main = do

GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
pwd <- System.Directory.getCurrentDirectory
args <- System.Environment.getArgs
pwd <- System.Directory.getCurrentDirectory
prefix <- System.Directory.makeAbsolute pwd
let src = prefix </> "src"

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

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

Test.DocTest.doctest
Test.DocTest.doctest $
[ "-DWITH_HTTP"
, "-DUSE_HTTP_CLIENT_TLS"
, "--fast"
, prefix </> "ghc-src"
] <> args <>
[ prefix </> "ghc-src"

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

-- , prefix </> "src"
, "-i" <> (prefix </> "src")
-- , src
, "-i" <> src
#if __GLASGOW_HASKELL__ >= 806
, prefix </> "src/Dhall/Deriving.hs"
, src </> "Dhall/Deriving.hs"
#endif
, prefix </> "src/Dhall/Tags.hs"
, prefix </> "src/Dhall/Tutorial.hs"
, src </> "Dhall/Tags.hs"
, src </> "Dhall/Tutorial.hs"
]
3 changes: 3 additions & 0 deletions dhall/src/Dhall/Syntax/Expr.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StandaloneKindSignatures #-}

module Dhall.Syntax.Expr
( Expr(..)
) where

import Data.ByteString (ByteString)
import Data.Kind (Type)
import Data.List.NonEmpty (NonEmpty (..))
import Data.Sequence (Seq)
import Data.String (IsString (..))
Expand Down Expand Up @@ -41,6 +43,7 @@ import qualified Data.Time as Time
* If @a = `Data.Void.Void`@ then the code has no
`Dhall.Syntax.Import.Import`s
-}
type Expr :: Type -> Type -> Type
data Expr s a
-- | > Const c ~ c
= Const Const
Expand Down
5 changes: 5 additions & 0 deletions dhall/src/Dhall/Syntax/Expr.hs-boot
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{-# LANGUAGE StandaloneKindSignatures #-}

module Dhall.Syntax.Expr where

import Data.Kind (Type)

type Expr :: Type -> Type -> Type
data Expr s a
Loading

0 comments on commit bcc1545

Please sign in to comment.