Skip to content

Commit

Permalink
Switch to ghcide 0.1.0 (digital-asset#4381)
Browse files Browse the repository at this point in the history
* Switch to ghcide 0.1.0

changelog_begin
changelog_end

* Bump hie-bios
  • Loading branch information
cocreature authored Feb 4, 2020
1 parent 9d3a0f8 commit 52d4f60
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 33 deletions.
6 changes: 3 additions & 3 deletions bazel-haskell-deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ load("@os_info//:os_info.bzl", "is_windows")
load("@dadew//:dadew.bzl", "dadew_tool_home")
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")

GHCIDE_REV = "8f74783835324ee6dad7faf83b7a62143a48e8c6"
GHCIDE_SHA256 = "36bed2b197dfc296488ed2e994b82193e4505051ffa3050d4844a6c66fab2baa"
GHCIDE_VERSION = "0.0.6"
GHCIDE_REV = "368cff7af5110f5cee4fa8a4648ac1e9893760de"
GHCIDE_SHA256 = "4be34f38143cf9b1cccfcd335505c443901d4e00ab11960d96100d0cff77aa62"
GHCIDE_VERSION = "0.1.0"

def daml_haskell_deps():
"""Load all Haskell dependencies of the DAML repository."""
Expand Down
21 changes: 10 additions & 11 deletions bazel_tools/haskell-ghcide-expose-compat.patch
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
diff --git a/ghcide.cabal b/ghcide.cabal
index 930b387..73f4b51 100644
index fa147ef..466249e 100644
--- a/ghcide.cabal
+++ b/ghcide.cabal
@@ -98,6 +98,7 @@ library
@@ -99,6 +99,7 @@ library
include-dirs:
include
exposed-modules:
+ Development.IDE.Core.Compile
Development.IDE.Core.Completions
Development.IDE.Core.CompletionsTypes
Development.IDE.Core.FileStore
@@ -107,7 +108,10 @@ library
Development.IDE.Core.OfInterest
Development.IDE.Core.PositionMapping
@@ -106,8 +107,10 @@ library
Development.IDE.Core.RuleTypes
Development.IDE.Core.Service
Development.IDE.Core.Shake
+ Development.IDE.GHC.Compat
+ Development.IDE.GHC.Error
Development.IDE.GHC.Error
Development.IDE.GHC.Util
+ Development.IDE.GHC.Warnings
Development.IDE.Import.DependencyInformation
Development.IDE.LSP.LanguageServer
Development.IDE.LSP.Protocol
@@ -118,14 +122,10 @@ library
Development.IDE.Types.Options
@@ -122,13 +125,10 @@ library
Development.IDE.Plugin.CodeAction
other-modules:
Development.IDE.Core.Debouncer
- Development.IDE.Core.Compile
Development.IDE.Core.Preprocessor
Development.IDE.Core.FileExists
- Development.IDE.GHC.Compat
Development.IDE.GHC.CPP
- Development.IDE.GHC.Error
Development.IDE.GHC.Orphans
- Development.IDE.GHC.Warnings
Development.IDE.Import.FindImports
Development.IDE.LSP.CodeAction
Development.IDE.LSP.Completions
Development.IDE.LSP.HoverDefinition
Development.IDE.LSP.Notifications
8 changes: 5 additions & 3 deletions compiler/damlc/daml-ide/src/DA/Daml/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Development.IDE.Core.FileStore
import Development.IDE.Core.Rules
import Development.IDE.Core.Rules.Daml
import Development.IDE.Core.Service.Daml
import Development.IDE.Plugin

import DA.Daml.SessionTelemetry
import DA.Daml.LanguageServer.Visualize
Expand All @@ -50,7 +51,7 @@ setHandlersKeepAlive = PartialHandlers $ \WithMessage{..} x -> return x
case _method of
CustomClientMethod "daml/keepAlive" ->
maybe (return ()) ($ msg) $
withResponse RspCustomServer (\_ _ _ -> return Aeson.Null)
withResponse RspCustomServer (\_ _ _ -> return (Right Aeson.Null))
_ -> whenJust (LSP.customRequestHandler x) ($ msg)
}

Expand Down Expand Up @@ -104,11 +105,12 @@ withUriDaml _ _ = return ()

runLanguageServer
:: Lgr.Handle IO
-> Plugin
-> (IO LSP.LspId -> (FromServerMessage -> IO ()) -> VFSHandle -> ClientCapabilities -> IO IdeState)
-> IO ()
runLanguageServer lgr getIdeState = withSessionPings lgr $ \setSessionHandlers -> do
runLanguageServer lgr plugins getIdeState = withSessionPings lgr $ \setSessionHandlers -> do
let handlers = setHandlersKeepAlive <> setHandlersVirtualResource <> setHandlersCodeLens <> setIgnoreOptionalHandlers <> setCommandHandler <> setSessionHandlers
LS.runLanguageServer options handlers getIdeState
LS.runLanguageServer options (pluginHandler plugins <> handlers) getIdeState


options :: LSP.Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import Development.IDE.Types.Location
handle
:: IdeState
-> CodeLensParams
-> IO (List CodeLens)
handle ide (CodeLensParams (TextDocumentIdentifier uri) _) = do
-> IO (Either e (List CodeLens))
handle ide (CodeLensParams (TextDocumentIdentifier uri) _) = Right <$> do
mbResult <- case uriToFilePath' uri of
Just (toNormalizedFilePath -> filePath) -> do
logInfo (ideLogger ide) $ "CodeLens request for file: " <> T.pack (fromNormalizedFilePath filePath)
Expand Down
12 changes: 6 additions & 6 deletions compiler/damlc/daml-ide/src/DA/Daml/LanguageServer/Visualize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ collectTexts :: List Aeson.Value -> Maybe NormalizedFilePath
collectTexts (List [Aeson.String file]) = Just (toNormalizedFilePath (T.unpack file))
collectTexts _= Nothing

-- TODO(Anup) - Return errors via LSP instead of (return Aeson.Null) for which we will need some changes to withResponse
onCommand
:: IdeState
-> ExecuteCommandParams
-> IO Aeson.Value
-> IO (Either ResponseError Aeson.Value)
onCommand ide execParsms = case execParsms of
ExecuteCommandParams "daml/damlVisualize" (Just _arguments) _ -> do
case collectTexts _arguments of
Expand All @@ -42,13 +41,14 @@ onCommand ide execParsms = case execParsms of
let extpkgs = map LF.dalfPackagePkg $ Map.elems pkgMap
let wrld = LF.initWorldSelf extpkgs package
let dots = T.pack $ Visual.dotFileGen modules wrld
return $ Aeson.String dots
return $ Right $ Aeson.String dots
Nothing -> do
logError (ideLogger ide) "Expected a single module to visualize, got multiple module"
return $ Aeson.String "Expected a single module to visualize, got multiple module"
return $ Right $ Aeson.String "Expected a single module to visualize, got multiple module"
ExecuteCommandParams command args _ -> do
logError (ideLogger ide) $ T.pack ("Unsupported command " ++ show command ++ "with args " ++ show args)
return Aeson.Null
let err = T.pack ("Unsupported command " ++ show command ++ "with args " ++ show args)
logError (ideLogger ide) err
return $ Left (ResponseError InvalidParams err Nothing)

setCommandHandler ::PartialHandlers
setCommandHandler = PartialHandlers $ \WithMessage{..} x -> return x {
Expand Down
2 changes: 1 addition & 1 deletion compiler/damlc/lib/DA/Cli/Damlc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ execIde telemetry (Debug debug) enableScenarioService options =
withScenarioService' enableScenarioService loggerH scenarioServiceConfig $ \mbScenarioService -> do
sdkVersion <- getSdkVersion `catchIO` const (pure "Unknown (not started via the assistant)")
Logger.logInfo loggerH (T.pack $ "SDK version: " <> sdkVersion)
runLanguageServer loggerH $ \getLspId sendMsg vfs caps ->
runLanguageServer loggerH enabledPlugins $ \getLspId sendMsg vfs caps ->
getDamlIdeState options mbScenarioService loggerH caps getLspId sendMsg vfs (clientSupportsProgress caps)


Expand Down
9 changes: 8 additions & 1 deletion compiler/damlc/lib/DA/Cli/Damlc/IdeState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module DA.Cli.Damlc.IdeState
( IdeState
, getDamlIdeState
, withDamlIdeState
, enabledPlugins
) where

import Data.Default
Expand All @@ -17,6 +18,9 @@ import qualified DA.Service.Logger as Logger
import qualified DA.Daml.Compiler.Scenario as Scenario
import Development.IDE.Core.Rules.Daml
import Development.IDE.Core.API
import Development.IDE.Plugin
import Development.IDE.Plugin.Completions as Completions
import Development.IDE.Plugin.CodeAction as CodeAction
import qualified Development.IDE.Types.Logger as IdeLogger
import Development.IDE.Types.Options
import qualified Language.Haskell.LSP.Types as LSP
Expand All @@ -33,10 +37,13 @@ getDamlIdeState
-> IdeReportProgress
-> IO IdeState
getDamlIdeState compilerOpts mbScenarioService loggerH caps getLspId eventHandler vfs reportProgress = do
let rule = mainRule compilerOpts
let rule = mainRule compilerOpts <> pluginRules enabledPlugins
damlEnv <- mkDamlEnv compilerOpts mbScenarioService
initialise caps rule getLspId eventHandler (toIdeLogger loggerH) damlEnv (toCompileOpts compilerOpts reportProgress) vfs

enabledPlugins :: Plugin
enabledPlugins = Completions.plugin <> CodeAction.plugin

-- Wrapper for the common case where the scenario service will be started automatically (if enabled)
-- and we use the builtin VFSHandle.
withDamlIdeState
Expand Down
11 changes: 6 additions & 5 deletions compiler/lsp-tests/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Data.Aeson (toJSON)
import Data.Char (toLower)
import Data.Foldable (toList)
import Data.List.Extra
import Data.Maybe
import qualified Data.Text as T
import qualified Language.Haskell.LSP.Test as LspTest
import Language.Haskell.LSP.Types
Expand Down Expand Up @@ -485,22 +486,22 @@ executeCommandTests run _ = testGroup "execute command"
let expectedDotString = "digraph G {\ncompound=true;\nrankdir=LR;\nsubgraph cluster_Coin{\nn0[label=Create][color=green]; \nn1[label=Archive][color=red]; \nn2[label=Delete][color=red]; \nlabel=<<table align = \"left\" border=\"0\" cellborder=\"0\" cellspacing=\"1\">\n<tr><td align=\"center\"><b>Coin</b></td></tr><tr><td align=\"left\">owner</td></tr> \n</table>>;color=blue\n}\n}\n"
liftIO $ assertEqual "Visulization command" (Just expectedDotString) (_result actualDotString)
closeDoc main'
, testCase "Invalid commands result in empty response" $ run $ do
, testCase "Invalid commands result in error" $ run $ do
main' <- openDoc' "Main.daml" damlId $ T.unlines
[ "daml 1.2"
, "module Empty where"
]
Just escapedFp <- pure $ uriToFilePath (main' ^. uri)
actualDotString :: ExecuteCommandResponse <- LSP.request WorkspaceExecuteCommand $ ExecuteCommandParams
"daml/NoCommand" (Just (List [Aeson.String $ T.pack escapedFp])) Nothing
let expectedNull = Just Aeson.Null
liftIO $ assertEqual "Invlalid command" expectedNull (_result actualDotString)
liftIO $ _result actualDotString @?= Nothing
liftIO $ assertBool "Expected response error but got Nothing" (isJust $ _error actualDotString)
closeDoc main'
, testCase "Visualization command with no arguments" $ run $ do
actualDotString :: ExecuteCommandResponse <- LSP.request WorkspaceExecuteCommand $ ExecuteCommandParams
"daml/damlVisualize" Nothing Nothing
let expectedNull = Just Aeson.Null
liftIO $ assertEqual "Invlalid command" expectedNull (_result actualDotString)
liftIO $ _result actualDotString @?= Nothing
liftIO $ assertBool "Expected response error but got Nothing" (isJust $ _error actualDotString)
]

-- | Do extreme things to the compiler service.
Expand Down
4 changes: 3 additions & 1 deletion stack-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ packages:
- grpc-haskell-core-0.0.0.0
- fuzzy-0.1.0.0
- haskell-lsp-0.19.0.0
- haddock-library-1.8.0
- haskell-lsp-types-0.19.0.0
- hie-bios-0.3.2
- hie-bios-0.4.0
- hpp-0.6.1
- lsp-test-0.9.0.0
- proto3-suite-0.4.0.0
- proto3-wire-1.1.0
- regex-base-0.94.0.0
- regex-tdfa-1.3.1.0
- shake-0.18.5
# Core packages, need to be listed for integer-simple flags.
- integer-simple-0.1.1.1
- text-1.2.3.1

0 comments on commit 52d4f60

Please sign in to comment.