Skip to content

Commit 1495435

Browse files
committed
added guardAgainstHpack function
Revert "added guardAgainstHpack function" This reverts commit f7fb00c. added guardAgainstHpack function
1 parent 87b4d95 commit 1495435

File tree

1 file changed

+7
-2
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal

1 file changed

+7
-2
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ getDependencyEdit recorder env cabalFilePath buildTarget dependency = do
277277
logWith recorder Debug $ LogCreatedEdit edit
278278
pure edit
279279

280-
-- | Given a path to a haskell file, returns the closest cabal file.
280+
-- | Given a path to a haskell file, returns the closest cabal file, except if package.yaml is also present.
281281
-- If cabal file wasn't found, gives Nothing.
282282
findResponsibleCabalFile :: FilePath -> IO (Maybe FilePath)
283283
findResponsibleCabalFile haskellFilePath = do
@@ -293,7 +293,12 @@ findResponsibleCabalFile haskellFilePath = do
293293
cabalFiles <- filterM (\c -> doesFileExist c) objectsCabalExtension
294294
case safeHead cabalFiles of
295295
Nothing -> go ps
296-
Just cabalFile -> pure $ Just cabalFile
296+
Just cabalFile -> guardAgainstHpack path cabalFile
297+
where
298+
guardAgainstHpack :: FilePath -> FilePath -> IO (Maybe FilePath)
299+
guardAgainstHpack path cabalFile = do
300+
exists <- doesFileExist $ path </> "package.yaml"
301+
if exists then pure Nothing else pure $ Just cabalFile
297302

298303
-- | Gives cabal file's contents or throws error.
299304
-- Inspired by @readCabalFile@ in cabal-add,

0 commit comments

Comments
 (0)