Skip to content

Commit

Permalink
Merge branch 'master' into inlay-hints-positional-record
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor authored Dec 1, 2024
2 parents b7f110f + fea0135 commit 84cc4fa
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 24 deletions.
25 changes: 9 additions & 16 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@ queue_rules:
- name: default
# Mergify always respects the branch protection settings
# so we can left empty mergify own ones
conditions: []

pull_request_rules:
- name: Automatically merge pull requests
conditions:
queue_conditions:
- label=merge me
- '#approved-reviews-by>=1'
actions:
queue:
method: squash
name: default
# The queue action automatically updates PRs that
# have entered the queue, but in order to do that
# they must have passed CI. Since our CI is a bit
# flaky, PRs can fail to get in, which then means
# they don't get updated, which is extra annoying.
# This just adds the updating as an independent
# step.
merge_conditions: []
merge_method: squash

pull_request_rules:
- name: Automatically update pull requests
conditions:
- label=merge me
actions:
update:
- name: refactored queue action rule
conditions: []
actions:
queue:
9 changes: 4 additions & 5 deletions plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ addDependencySuggestCodeAction plId verTxtDocId suggestions haskellFilePath caba
-- | Gives the build targets that are used in the `CabalAdd`.
-- Note the unorthodox usage of `readBuildTargets`:
-- If the relative path to the haskell file is provided,
-- the `readBuildTargets` will return a main build target.
-- This behaviour is acceptable for now, but changing to a way of getting
-- all build targets in a file is advised.
-- the `readBuildTargets` will return build targets, where this
-- module is mentioned (in exposed-modules or other-modules).
getBuildTargets :: GenericPackageDescription -> FilePath -> FilePath -> IO [BuildTarget]
getBuildTargets gpd cabalFilePath haskellFilePath = do
let haskellFileRelativePath = makeRelative (dropFileName cabalFilePath) haskellFilePath
Expand All @@ -167,10 +166,10 @@ addDependencySuggestCodeAction plId verTxtDocId suggestions haskellFilePath caba
mkCodeAction :: FilePath -> Maybe String -> (T.Text, T.Text) -> CodeAction
mkCodeAction cabalFilePath target (suggestedDep, suggestedVersion) =
let
versionTitle = if T.null suggestedVersion then T.empty else " version " <> suggestedVersion
versionTitle = if T.null suggestedVersion then T.empty else "-" <> suggestedVersion
targetTitle = case target of
Nothing -> T.empty
Just t -> " target " <> T.pack t
Just t -> " at " <> T.pack t
title = "Add dependency " <> suggestedDep <> versionTitle <> targetTitle
version = if T.null suggestedVersion then Nothing else Just suggestedVersion

Expand Down
20 changes: 17 additions & 3 deletions plugins/hls-cabal-plugin/test/CabalAdd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,30 @@ cabalAddTests :: TestTree
cabalAddTests =
testGroup
"CabalAdd Tests"
[ runHaskellTestCaseSession "Code Actions - Can add hidden package" ("cabal-add-testdata" </> "cabal-add-exe")
[ runHaskellTestCaseSession "Code Actions - Can add hidden package to an executable" ("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")
(generateAddDependencyTestSession "cabal-add-tests.cabal" ("test" </> "Main.hs") "split" [478])
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a benchmark" ("cabal-add-testdata" </> "cabal-add-bench")
(generateAddDependencyTestSession "cabal-add-bench.cabal" ("bench" </> "Main.hs") "split" [403])

, runHaskellTestCaseSession "Code Actions - Can add hidden package to an executable, multiple targets" ("cabal-add-testdata" </> "cabal-add-multitarget")
(generateAddDependencyTestSession "cabal-add-multitarget.cabal" ("src" </> "Main.hs") "split" [269])
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a library, multiple targets" ("cabal-add-testdata" </> "cabal-add-multitarget")
(generateAddDependencyTestSession "cabal-add-multitarget.cabal" ("lib" </> "MyLib.hs") "split" [413])
, runHaskellTestCaseSession "Code Actions - Can add hidden package to an internal library, multiple targets" ("cabal-add-testdata" </> "cabal-add-multitarget")
(generateAddDependencyTestSession "cabal-add-multitarget.cabal" ("lib" </> "InternalLib.hs") "split" [413])
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a test, multiple targets" ("cabal-add-testdata" </> "cabal-add-multitarget")
(generateAddDependencyTestSession "cabal-add-multitarget.cabal" ("test" </> "Main.hs") "split" [655])
, runHaskellTestCaseSession "Code Actions - Can add hidden package to a benchmark, multiple targets" ("cabal-add-testdata" </> "cabal-add-multitarget")
(generateAddDependencyTestSession "cabal-add-multitarget.cabal" ("bench" </> "Main.hs") "split" [776])


, runHaskellTestCaseSession "Code Actions - Guard against HPack" ("cabal-add-testdata" </> "cabal-add-packageYaml")
(generatePackageYAMLTestSession ("src" </> "Main.hs"))

, testHiddenPackageSuggestions "Check CabalAdd's parser, no version"
[ "It is a member of the hidden package 'base'"
, "It is a member of the hidden package 'Blammo-wai'"
Expand Down
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
@@ -0,0 +1,33 @@
cabal-version: 2.4
name: cabal-add-multitarget
version: 0.1.0.0
build-type: Simple

executable cabal-add-exe
main-is: Main.hs
hs-source-dirs: src
ghc-options: -Wall
build-depends: base
default-language: Haskell2010

library
exposed-modules: MyLib
other-modules: InternalLib
build-depends: base >= 4 && < 5
hs-source-dirs: lib
ghc-options: -Wall

test-suite cabal-add-tests-test
main-is: Main.hs
hs-source-dirs: test
type: exitcode-stdio-1.0
build-depends: base
default-language: Haskell2010

benchmark benchmark
main-is: Main.hs
build-depends: base
hs-source-dirs: bench
type: exitcode-stdio-1.0
ghc-options: -threaded

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module InternalLib (internalFunc) where

import Data.List.Split

internalFunc :: IO ()
internalFunc = putStrLn "internalFunc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MyLib (someFunc) where

import Data.List.Split

someFunc :: IO ()
someFunc = putStrLn "someFunc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Main where

import Data.List.Split

main = putStrLn "Hello, Haskell!"
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,4 +2,5 @@ packages: cabal-add-exe
cabal-add-lib
cabal-add-tests
cabal-add-bench
cabal-add-multitarget
cabal-add-packageYaml

0 comments on commit 84cc4fa

Please sign in to comment.