Skip to content

Commit 5eeea2b

Browse files
authored
Merge branch 'master' into feat-exec_dynamic
2 parents 7b8e5ed + 559e294 commit 5eeea2b

File tree

8 files changed

+45
-3
lines changed

8 files changed

+45
-3
lines changed

.github/workflows/nix.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
steps:
5050
- uses: actions/checkout@v3
5151

52-
- uses: cachix/install-nix-action@v29
52+
- uses: cachix/install-nix-action@v30
5353
with:
5454
extra_nix_config: |
5555
experimental-features = nix-command flakes

.github/workflows/pre-commit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-
5454
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-
5555
56-
- uses: actions/setup-python@v5
56+
- uses: actions/setup-python@v3
5757
- uses: pre-commit/[email protected]
5858
with:
5959
extra_args: --files ${{ needs.file-diff.outputs.git-diff }}

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ getDependencyEdit recorder env cabalFilePath buildTarget dependency = do
278278
pure edit
279279

280280
-- | Given a path to a haskell file, returns the closest cabal file.
281+
-- If a package.yaml is present in same directory as the .cabal file, returns nothing, because adding a dependency to a generated cabal file
282+
-- will break propagation of changes from package.yaml to cabal files in stack projects.
281283
-- If cabal file wasn't found, gives Nothing.
282284
findResponsibleCabalFile :: FilePath -> IO (Maybe FilePath)
283285
findResponsibleCabalFile haskellFilePath = do
@@ -293,7 +295,12 @@ findResponsibleCabalFile haskellFilePath = do
293295
cabalFiles <- filterM (\c -> doesFileExist c) objectsCabalExtension
294296
case safeHead cabalFiles of
295297
Nothing -> go ps
296-
Just cabalFile -> pure $ Just cabalFile
298+
Just cabalFile -> guardAgainstHpack path cabalFile
299+
where
300+
guardAgainstHpack :: FilePath -> FilePath -> IO (Maybe FilePath)
301+
guardAgainstHpack path cabalFile = do
302+
exists <- doesFileExist $ path </> "package.yaml"
303+
if exists then pure Nothing else pure $ Just cabalFile
297304

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

plugins/hls-cabal-plugin/test/CabalAdd.hs

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ cabalAddTests =
2929
"CabalAdd Tests"
3030
[ runHaskellTestCaseSession "Code Actions - Can add hidden package" ("cabal-add-testdata" </> "cabal-add-exe")
3131
(generateAddDependencyTestSession "cabal-add-exe.cabal" ("src" </> "Main.hs") "split" [253])
32+
, runHaskellTestCaseSession "Code Actions - Guard against HPack" ("cabal-add-testdata" </> "cabal-add-packageYaml")
33+
(generatePackageYAMLTestSession ("src" </> "Main.hs"))
3234
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a library" ("cabal-add-testdata" </> "cabal-add-lib")
3335
(generateAddDependencyTestSession "cabal-add-lib.cabal" ("src" </> "MyLib.hs") "split" [348])
3436
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a test" ("cabal-add-testdata" </> "cabal-add-tests")
@@ -139,3 +141,12 @@ cabalAddTests =
139141
, _codeDescription = Nothing
140142
, _data_ = Nothing
141143
}
144+
145+
146+
generatePackageYAMLTestSession :: FilePath -> Session ()
147+
generatePackageYAMLTestSession haskellFile = do
148+
hsdoc <- openDoc haskellFile "haskell"
149+
_ <- waitForDiagnosticsFrom hsdoc
150+
cas <- Maybe.mapMaybe (^? _R) <$> getAllCodeActions hsdoc
151+
let selectedCas = filter (\ca -> "Add dependency" `T.isPrefixOf` (ca ^. L.title)) cas
152+
liftIO $ assertEqual "PackageYAML" [] selectedCas
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cabal-version: 2.4
2+
name: cabal-add-packageYaml
3+
version: 0.1.0.0
4+
license: NONE
5+
author: George Gerasev
6+
maintainer: [email protected]
7+
build-type: Simple
8+
9+
common warnings
10+
ghc-options: -Wall
11+
12+
benchmark benchmark-packageYaml
13+
type: exitcode-stdio-1.0
14+
ghc-options: -threaded
15+
main-is: Main.hs
16+
hs-source-dirs: bench
17+
build-depends: base

plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/package.yaml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main (main) where
2+
3+
import Data.List.Split
4+
5+
main :: IO ()
6+
main = putStrLn "Test suite not yet implemented."

plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ packages: cabal-add-exe
22
cabal-add-lib
33
cabal-add-tests
44
cabal-add-bench
5+
cabal-add-packageYaml

0 commit comments

Comments
 (0)