Skip to content

Commit

Permalink
Merge branch 'master' into feat-exec_dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
develop7 authored Oct 13, 2024
2 parents 7b8e5ed + 559e294 commit 5eeea2b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v29
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
experimental-features = nix-command flakes
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-
- uses: actions/setup-python@v5
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
with:
extra_args: --files ${{ needs.file-diff.outputs.git-diff }}
9 changes: 8 additions & 1 deletion plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ getDependencyEdit recorder env cabalFilePath buildTarget dependency = do
pure edit

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

-- | Gives cabal file's contents or throws error.
-- Inspired by @readCabalFile@ in cabal-add,
Expand Down
11 changes: 11 additions & 0 deletions plugins/hls-cabal-plugin/test/CabalAdd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ cabalAddTests =
"CabalAdd Tests"
[ runHaskellTestCaseSession "Code Actions - Can add hidden package" ("cabal-add-testdata" </> "cabal-add-exe")
(generateAddDependencyTestSession "cabal-add-exe.cabal" ("src" </> "Main.hs") "split" [253])
, runHaskellTestCaseSession "Code Actions - Guard against HPack" ("cabal-add-testdata" </> "cabal-add-packageYaml")
(generatePackageYAMLTestSession ("src" </> "Main.hs"))
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a library" ("cabal-add-testdata" </> "cabal-add-lib")
(generateAddDependencyTestSession "cabal-add-lib.cabal" ("src" </> "MyLib.hs") "split" [348])
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a test" ("cabal-add-testdata" </> "cabal-add-tests")
Expand Down Expand Up @@ -139,3 +141,12 @@ cabalAddTests =
, _codeDescription = Nothing
, _data_ = Nothing
}


generatePackageYAMLTestSession :: FilePath -> Session ()
generatePackageYAMLTestSession haskellFile = do
hsdoc <- openDoc haskellFile "haskell"
_ <- waitForDiagnosticsFrom hsdoc
cas <- Maybe.mapMaybe (^? _R) <$> getAllCodeActions hsdoc
let selectedCas = filter (\ca -> "Add dependency" `T.isPrefixOf` (ca ^. L.title)) cas
liftIO $ assertEqual "PackageYAML" [] selectedCas
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 2.4
name: cabal-add-packageYaml
version: 0.1.0.0
license: NONE
author: George Gerasev
maintainer: [email protected]
build-type: Simple

common warnings
ghc-options: -Wall

benchmark benchmark-packageYaml
type: exitcode-stdio-1.0
ghc-options: -threaded
main-is: Main.hs
hs-source-dirs: bench
build-depends: base
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main (main) where

import Data.List.Split

main :: IO ()
main = putStrLn "Test suite not yet implemented."
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ packages: cabal-add-exe
cabal-add-lib
cabal-add-tests
cabal-add-bench
cabal-add-packageYaml

0 comments on commit 5eeea2b

Please sign in to comment.