Skip to content

Commit f455375

Browse files
authored
Merge pull request #39 from ollef/master
Handle PackageImporting "this"
2 parents 10e5f15 + 2312cba commit f455375

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Development/IDE/Import/FindImports.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ locateModule
6868
-> m (Either [FileDiagnostic] Import)
6969
locateModule dflags exts doesExist modName mbPkgName isSource = do
7070
case mbPkgName of
71+
-- "this" means that we should only look in the current package
72+
Just "this" -> do
73+
mbFile <- locateModuleFile dflags exts doesExist isSource $ unLoc modName
74+
case mbFile of
75+
Nothing -> return $ Left $ notFoundErr dflags modName $ LookupNotFound []
76+
Just file -> return $ Right $ FileImport file
7177
-- if a package name is given we only go look for a package
7278
Just _pkgName -> lookupInPackageDB dflags
7379
Nothing -> do

test/exe/Main.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,30 @@ diagnosticTests = testGroup "diagnostics"
182182
, [(DsWarning, (2, 0), "The import of 'ModuleA' is redundant")]
183183
)
184184
]
185+
, testSession "package imports" $ do
186+
let thisDataListContent = T.unlines
187+
[ "module Data.List where"
188+
, "x = 123"
189+
]
190+
let mainContent = T.unlines
191+
[ "{-# LANGUAGE PackageImports #-}"
192+
, "module Main where"
193+
, "import qualified \"this\" Data.List as ThisList"
194+
, "import qualified \"base\" Data.List as BaseList"
195+
, "useThis = ThisList.x"
196+
, "useBase = BaseList.map"
197+
, "wrong1 = ThisList.map"
198+
, "wrong2 = BaseList.x"
199+
]
200+
_ <- openDoc' "Data/List.hs" "haskell" thisDataListContent
201+
_ <- openDoc' "Main.hs" "haskell" mainContent
202+
expectDiagnostics
203+
[ ( "Main.hs"
204+
, [(DsError, (6, 9), "Not in scope: \8216ThisList.map\8217")
205+
,(DsError, (7, 9), "Not in scope: \8216BaseList.x\8217")
206+
]
207+
)
208+
]
185209
]
186210

187211
codeActionTests :: TestTree

0 commit comments

Comments
 (0)