mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-17 23:22:04 +03:00
Improvements to the IDE (#1006)
* Make the extensions of the Haskell files configurable * Make sure we capture the errors from parsing, not the warnings
This commit is contained in:
parent
73b9de2536
commit
bec100b635
@ -444,8 +444,8 @@ parseFileContents preprocessor filename (time, contents) = do
|
||||
dflags <- parsePragmasIntoDynFlags filename contents
|
||||
case unP Parser.parseModule (mkPState dflags contents loc) of
|
||||
#ifdef USE_GHC
|
||||
PFailed getMessages _ _ ->
|
||||
Ex.throwE $ toDiagnostics dflags $ snd $ getMessages dflags
|
||||
PFailed _ logMsg msgErr ->
|
||||
Ex.throwE $ mkErrorDoc dflags locErr msgErr
|
||||
#else
|
||||
PFailed s ->
|
||||
Ex.throwE $ toDiagnostics dflags $ snd $ getMessages s dflags
|
||||
|
@ -66,12 +66,12 @@ getImportsParsed dflags (L loc parsed) = do
|
||||
-- | locate a module in the file system. Where we go from *daml to Haskell
|
||||
locateModuleFile :: MonadIO m
|
||||
=> DynFlags
|
||||
-> [String]
|
||||
-> (FilePath -> m Bool)
|
||||
-> ModuleName
|
||||
-> m (Maybe FilePath)
|
||||
locateModuleFile dflags doesExist modName = do
|
||||
let libPaths = importPaths dflags
|
||||
let candidates = [ prefix </> M.moduleNameSlashes modName <.> "daml" | prefix <- libPaths ]
|
||||
locateModuleFile dflags exts doesExist modName = do
|
||||
let candidates = [ prefix </> M.moduleNameSlashes modName <.> ext | prefix <- importPaths dflags, ext <- exts]
|
||||
findM doesExist candidates
|
||||
|
||||
-- | locate a module in either the file system or the package database. Where we go from *daml to
|
||||
@ -79,18 +79,19 @@ locateModuleFile dflags doesExist modName = do
|
||||
locateModule
|
||||
:: MonadIO m
|
||||
=> DynFlags
|
||||
-> [String]
|
||||
-> (FilePath -> m Bool)
|
||||
-> Located ModuleName
|
||||
-> Maybe FastString
|
||||
-> m (Either [FileDiagnostic] Import)
|
||||
locateModule dflags doesExist modName mbPkgName = do
|
||||
locateModule dflags exts doesExist modName mbPkgName = do
|
||||
case mbPkgName of
|
||||
-- if a package name is given we only go look for a package
|
||||
Just _pkgName -> lookupInPackageDB dflags
|
||||
Nothing -> do
|
||||
-- first try to find the module as a file. If we can't find it try to find it in the package
|
||||
-- database.
|
||||
mbFile <- locateModuleFile dflags doesExist $ unLoc modName
|
||||
mbFile <- locateModuleFile dflags exts doesExist $ unLoc modName
|
||||
case mbFile of
|
||||
Nothing -> lookupInPackageDB dflags
|
||||
Just file -> return $ Right $ FileImport file
|
||||
|
@ -191,7 +191,7 @@ getLocatedImportsRule =
|
||||
opt <- getOpts
|
||||
dflags <- liftIO $ Compile.getGhcDynFlags opt pm packageState
|
||||
xs <- forM imports $ \(mbPkgName, modName) ->
|
||||
(modName, ) <$> locateModule dflags getFileExists modName mbPkgName
|
||||
(modName, ) <$> locateModule dflags (Compile.optExtensions opt) getFileExists modName mbPkgName
|
||||
return (concat $ lefts $ map snd xs, Just $ map (second eitherToMaybe) xs)
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@ data IdeOptions = IdeOptions
|
||||
-- the import path should be setup for that module.
|
||||
, optPkgLocationOpts :: IdePkgLocationOptions
|
||||
, optWriteIface :: Bool
|
||||
, optExtensions :: [String]
|
||||
|
||||
, optMbPackageName :: Maybe String
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user