mirror of
https://github.com/haskell/ghcide.git
synced 2025-01-05 17:33:05 +03:00
Merge pull request #39 from ollef/master
Handle PackageImporting "this"
This commit is contained in:
commit
f4553757dd
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user