Skip to content

Commit

Permalink
Merge pull request #39 from ollef/master
Browse files Browse the repository at this point in the history
Handle PackageImporting "this"
  • Loading branch information
cocreature authored Sep 12, 2019
2 parents 10e5f15 + 2312cba commit f455375
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Development/IDE/Import/FindImports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ locateModule
-> m (Either [FileDiagnostic] Import)
locateModule dflags exts doesExist modName mbPkgName isSource = do
case mbPkgName of
-- "this" means that we should only look in the current package
Just "this" -> do
mbFile <- locateModuleFile dflags exts doesExist isSource $ unLoc modName
case mbFile of
Nothing -> return $ Left $ notFoundErr dflags modName $ LookupNotFound []
Just file -> return $ Right $ FileImport file
-- if a package name is given we only go look for a package
Just _pkgName -> lookupInPackageDB dflags
Nothing -> do
Expand Down
24 changes: 24 additions & 0 deletions test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ diagnosticTests = testGroup "diagnostics"
, [(DsWarning, (2, 0), "The import of 'ModuleA' is redundant")]
)
]
, testSession "package imports" $ do
let thisDataListContent = T.unlines
[ "module Data.List where"
, "x = 123"
]
let mainContent = T.unlines
[ "{-# LANGUAGE PackageImports #-}"
, "module Main where"
, "import qualified \"this\" Data.List as ThisList"
, "import qualified \"base\" Data.List as BaseList"
, "useThis = ThisList.x"
, "useBase = BaseList.map"
, "wrong1 = ThisList.map"
, "wrong2 = BaseList.x"
]
_ <- openDoc' "Data/List.hs" "haskell" thisDataListContent
_ <- openDoc' "Main.hs" "haskell" mainContent
expectDiagnostics
[ ( "Main.hs"
, [(DsError, (6, 9), "Not in scope: \8216ThisList.map\8217")
,(DsError, (7, 9), "Not in scope: \8216BaseList.x\8217")
]
)
]
]

codeActionTests :: TestTree
Expand Down

0 comments on commit f455375

Please sign in to comment.