Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 4f0c017

Browse files
committed
Return an error diagnostic when no TypeCheckedModule
1 parent 085b816 commit 4f0c017

File tree

8 files changed

+80
-3
lines changed

8 files changed

+80
-3
lines changed

haskell-ide-engine.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ test-suite func-test
289289
, DefinitionSpec
290290
, DiagnosticsSpec
291291
, FormatSpec
292+
, FunctionalBadProjectSpec
292293
, FunctionalCodeActionsSpec
293294
, FunctionalLiquidSpec
294295
, FunctionalSpec

src/Haskell/Ide/Engine/Plugin/GhcMod.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ setTypecheckedModule uri =
193193

194194
canonUri <- canonicalizeUri uri
195195
let diags = Map.insertWith Set.union canonUri Set.empty diags'
196-
case (mpm,mtm) of
196+
diags2 <- case (mpm,mtm) of
197197
(Just pm, Nothing) -> do
198198
debugm $ "setTypecheckedModule: Did get parsed module for: " ++ show fp
199199
cacheModule fp (Left pm)
200200
debugm "setTypecheckedModule: done"
201+
return diags
201202

202203
(_, Just tm) -> do
203204
debugm $ "setTypecheckedModule: Did get typechecked module for: " ++ show fp
@@ -208,13 +209,21 @@ setTypecheckedModule uri =
208209
modifyMTS (\s -> s {ghcSession = sess})
209210
cacheModule fp (Right tm)
210211
debugm "setTypecheckedModule: done"
212+
return diags
211213

212214
_ -> do
213215
debugm $ "setTypecheckedModule: Didn't get typechecked or parsed module for: " ++ show fp
216+
debugm $ "setTypecheckedModule: errs: " ++ show errs
214217

215218
failModule fp
216219

217-
return $ IdeResultOk (diags,errs)
220+
let sev = Just DsError
221+
range = Range (Position 0 0) (Position 1 0)
222+
msgTxt = T.unlines errs
223+
let d = Diagnostic range sev Nothing (Just "ghcmod") msgTxt Nothing
224+
return $ Map.insertWith Set.union canonUri (Set.singleton d) diags
225+
226+
return $ IdeResultOk (diags2,errs)
218227

219228
-- ---------------------------------------------------------------------
220229

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module FunctionalBadProjectSpec where
4+
5+
import Control.Lens hiding (List)
6+
import Control.Monad.IO.Class
7+
import qualified Data.Text as T
8+
import Language.Haskell.LSP.Test hiding (message)
9+
import Language.Haskell.LSP.Types as LSP
10+
import Language.Haskell.LSP.Types.Lens as LSP hiding (contents, error )
11+
import Test.Hspec
12+
import TestUtils
13+
import Utils
14+
15+
-- ---------------------------------------------------------------------
16+
17+
spec :: Spec
18+
spec = describe "behaviour on malformed projects" $ do
19+
it "deals with cabal file with unsatisfiable dependency" $
20+
runSession hieCommandExamplePlugin codeActionSupportCaps "test/testdata/badProjects/cabal" $ do
21+
-- runSessionWithConfig logConfig hieCommandExamplePlugin codeActionSupportCaps "test/testdata" $ do
22+
_doc <- openDoc "Foo.hs" "haskell"
23+
24+
diags@(d:_) <- waitForDiagnosticsSource "ghcmod"
25+
-- liftIO $ show diags `shouldBe` ""
26+
-- liftIO $ putStrLn $ show diags
27+
-- liftIO $ putStrLn "a"
28+
liftIO $ do
29+
length diags `shouldBe` 1
30+
d ^. range `shouldBe` Range (Position 0 0) (Position 1 0)
31+
d ^. severity `shouldBe` (Just DsError)
32+
d ^. code `shouldBe` Nothing
33+
d ^. source `shouldBe` Just "ghcmod"
34+
d ^. message `shouldBe`
35+
(T.pack "readCreateProcess: stack \"build\" \"--only-configure\" \".\" (exit 1): failed\n")
36+
37+
-- ---------------------------------
38+
39+
-- ---------------------------------------------------------------------

test/functional/FunctionalCodeActionsSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ spec = describe "code actions" $ do
139139
it "respects format config" $ runSession hieCommand fullCaps "test/testdata" $ do
140140
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
141141
_ <- waitForDiagnosticsSource "ghcmod"
142-
142+
143143
let config = def { formatOnImportOn = False }
144144
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
145145

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Foo where
2+
3+
foo :: Int
4+
foo = 3
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: bad-cabal
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Alan Zimmerman
5+
maintainer: [email protected]
6+
build-type: Simple
7+
extra-source-files: ChangeLog.md
8+
cabal-version: >=1.10
9+
10+
library
11+
exposed-modules: Foo
12+
build-depends: base >=4.7 && <5
13+
-- missing dependency
14+
, does-not-exist
15+
-- hs-source-dirs:
16+
default-language: Haskell2010
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# WARNING: THIS FILE IS AUTOGENERATED IN test/Main.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN
2+
resolver: lts-13.0
3+
packages:
4+
- '.'
5+
extra-deps: []
6+
flags: {}
7+
extra-package-dbs: []

test/utils/TestUtils.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ files =
109109
, "./test/testdata/addPackageTest/cabal/"
110110
, "./test/testdata/addPackageTest/hpack/"
111111
, "./test/testdata/addPragmas/"
112+
, "./test/testdata/badProjects/cabal/"
112113
, "./test/testdata/completion/"
113114
, "./test/testdata/definition/"
114115
, "./test/testdata/gototest/"

0 commit comments

Comments
 (0)