Skip to content

Commit

Permalink
Add Stack setup for GHC 9.2.8 (#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
mmhat authored Dec 23, 2023
1 parent 0e5971c commit d7a024e
Show file tree
Hide file tree
Showing 20 changed files with 277 additions and 91 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
18 changes: 17 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
packages: ./dhall ./dhall-bash ./dhall-json ./dhall-yaml ./dhall-nix ./dhall-docs ./dhall-openapi ./dhall-nixpkgs ./dhall-csv ./dhall-toml ./dhall-lsp-server
packages:
./dhall
./dhall-bash
./dhall-csv
./dhall-docs
./dhall-json
./dhall-lsp-server
./dhall-nix
./dhall-nixpkgs
./dhall-openapi
./dhall-toml
./dhall-yaml

source-repository-package
type: git
location: https://github.com/haskell-nix/hnix.git
tag: 2adbc502e62e755ca0372c913e6278ebe564d7d2
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
]
8 changes: 4 additions & 4 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 >= 1.2.0.0 && < 1.5
, rope-utf16-splay >= 0.3.1.0 && < 0.5
, hslogger >= 1.2.10 && < 1.4
, lsp >= 1.5.0.0 && < 2
, 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.3
, 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.6
, unordered-containers >= 0.2.9.0 && < 0.3
, uri-encode >= 1.5.0.5 && < 1.6
Expand Down Expand Up @@ -104,7 +104,7 @@ Test-Suite tests
GHC-Options: -Wall
Build-Depends:
base ,
lsp-types >= 1.2.0.0 && < 1.5 ,
lsp-types >= 1.2.0.0 && < 1.7 ,
hspec >= 2.7 && < 2.11 ,
lsp-test >= 0.13.0.0 && < 0.15 ,
tasty >= 0.11.2 && < 1.5 ,
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"
]
8 changes: 4 additions & 4 deletions dhall-lsp-server/src/Dhall/LSP/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import Text.Megaparsec (SourcePos (..), unPos)
import qualified Data.Aeson as Aeson
import qualified Data.HashMap.Strict as HashMap
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.Types as LSP.Types
Expand Down Expand Up @@ -617,12 +617,12 @@ didSaveTextDocumentNotificationHandler =

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

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

-- this handler is a stab to prevent `lsp:no handler for:` messages.
Expand All @@ -639,7 +639,7 @@ handleErrorWithDefault :: (Either a1 b -> HandlerM a2)
-> b
-> HandlerM a2
-> HandlerM a2
handleErrorWithDefault respond _default = flip catchE handler
handleErrorWithDefault respond _default = flip catchE handler
where
handler (Log, _message) = do
let _xtype = MtLog
Expand Down
39 changes: 26 additions & 13 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 @@ -22,23 +24,28 @@ import Dhall.LSP.Handlers
, cancelationHandler
)
import Dhall.LSP.State
import Language.LSP.Server (Options(..), ServerDefinition(..), type (<~>)(..))
import Language.LSP.Server (LspServerLog, Options(..), ServerDefinition(..), type (<~>)(..))
import Language.LSP.Types
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 @@ -117,20 +124,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"
]
Loading

0 comments on commit d7a024e

Please sign in to comment.