Merge pull request #39 from ollef/master

Handle PackageImporting "this"
This commit is contained in:
Moritz Kiefer 2019-09-12 10:03:26 +02:00 committed by GitHub
commit f4553757dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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