Skip to content

Commit

Permalink
Merge branch 'master' into support-structured-diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor authored Dec 1, 2024
2 parents f4d5c24 + fea0135 commit af9cd22
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 29 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:
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ packages:
./hls-test-utils


index-state: 2024-10-21T00:00:00Z
index-state: 2024-11-02T00:00:00Z

tests: True
test-show-details: direct
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ initObjLinker env =
loadDLL :: HscEnv -> String -> IO (Maybe String)
loadDLL env str = do
res <- GHCi.loadDLL (GHCi.hscInterp env) str
#if MIN_VERSION_ghc(9,11,0)
#if MIN_VERSION_ghc(9,11,0) || (MIN_VERSION_ghc(9, 8, 3) && !MIN_VERSION_ghc(9, 9, 0))
pure $
case res of
Left err_msg -> Just err_msg
Expand Down
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
8 changes: 6 additions & 2 deletions plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ suggestDisableWarning diagnostic
pure ("Disable \"" <> w <> "\" warnings", OptGHC w)
| otherwise = []

-- Don't suggest disabling type errors as a solution to all type errors
warningBlacklist :: [T.Text]
warningBlacklist = ["deferred-type-errors"]
warningBlacklist =
-- Don't suggest disabling type errors as a solution to all type errors.
[ "deferred-type-errors"
-- Don't suggest disabling out of scope errors as a solution to all out of scope errors.
, "deferred-out-of-scope-variables"
]

-- ---------------------------------------------------------------------

Expand Down
7 changes: 6 additions & 1 deletion plugins/hls-pragmas-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,16 @@ codeActionTests' =
_ -> assertFailure $ "Expected one code action, but got: " <> show cas
liftIO $ (ca ^. L.title == "Add \"NamedFieldPuns\"") @? "NamedFieldPuns code action"
executeCodeAction ca
, goldenWithPragmas pragmasSuggestPlugin "doesn't suggest disabling type errors" "DeferredTypeErrors" $ \doc -> do
, goldenWithPragmas pragmasDisableWarningPlugin "doesn't suggest disabling type errors" "DeferredTypeErrors" $ \doc -> do
_ <- waitForDiagnosticsFrom doc
cas <- map fromAction <$> getAllCodeActions doc
liftIO $ "Disable \"deferred-type-errors\" warnings" `notElem` map (^. L.title) cas @? "Doesn't contain deferred-type-errors code action"
liftIO $ length cas == 0 @? "Expected no code actions, but got: " <> show cas
, goldenWithPragmas pragmasDisableWarningPlugin "doesn't suggest disabling out of scope variables" "DeferredOutOfScopeVariables" $ \doc -> do
_ <- waitForDiagnosticsFrom doc
cas <- map fromAction <$> getAllCodeActions doc
liftIO $ "Disable \"deferred-out-of-scope-variables\" warnings" `notElem` map (^. L.title) cas @? "Doesn't contain deferred-out-of-scope-variables code action"
liftIO $ length cas == 0 @? "Expected no code actions, but got: " <> show cas
]

completionTests :: TestTree
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module DeferredOutOfScopeVariables where

f :: ()
f = let x = Doesn'tExist
in undefined
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module DeferredOutOfScopeVariables where

f :: ()
f = let x = Doesn'tExist
in undefined

0 comments on commit af9cd22

Please sign in to comment.