on master help sign in
Merge pull request #39 from ollef/master

Handle PackageImporting "this"

commitf4553757ddf92b77cfbca9f4daa2bcc9e8e86d28 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateThu 12 Sep 2019, 10:03 (7 years ago) parent10e5f152312cba
2 files changed+30
src/Development/IDE/Import/FindImports.hs+6 test/exe/Main.hs+24
src/Development/IDE/Import/FindImports.hs+6
@@ -68,6 +68,12 @@ locateModule
6868 -> m (Either [FileDiagnostic] Import)
6969locateModule 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+24
@@ -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
187211codeActionTests :: TestTree