Skip to content

Commit 8a8af33

Browse files
committed
Use pattern guard, move util to hls-test-utils
1 parent a571cba commit 8a8af33

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

ghcide/test/exe/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4937,7 +4937,8 @@ projectCompletionTests =
49374937
"import ALocal"
49384938
]
49394939
compls <- getCompletions doc (Position 1 13)
4940-
let item = head $ filter ((== "ALocalModule") . (^. Lens.label)) compls
4940+
--
4941+
item <- getCompletionByLabel "ALocalModule" compls
49414942
liftIO $ do
49424943
item ^. Lens.label @?= "ALocalModule",
49434944
testSession' "auto complete functions from qualified imports without alias" $ \dir-> do

hls-test-utils/src/Test/Hls/Util.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Test.Hls.Util
1818
, flushStackEnvironment
1919
, fromAction
2020
, fromCommand
21+
, getCompletionByLabel
2122
, getHspecFormattedConfig
2223
, ghcVersion, GhcVersion(..)
2324
, hostOS, OS(..)
@@ -447,3 +448,12 @@ actual `expectSameLocations` expected = do
447448
fp <- canonicalizePath file
448449
return (filePathToUri fp, l, c))
449450
actual' @?= expected'
451+
452+
-- ---------------------------------------------------------------------
453+
getCompletionByLabel :: MonadIO m => T.Text -> [CompletionItem] -> m CompletionItem
454+
getCompletionByLabel desiredLabel compls =
455+
case find (\c -> c ^. L.label == desiredLabel) compls of
456+
Just c -> pure c
457+
Nothing -> liftIO . assertFailure $
458+
"Completion with label " <> show desiredLabel
459+
<> " not found in " <> show (fmap (^. L.label) compls)

plugins/hls-pragmas-plugin/test/Main.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ completionTest testComment fileName te' label textFormat insertText detail [a, b
124124
let te = TextEdit (Range (Position a b) (Position c d)) te'
125125
_ <- applyEdit doc te
126126
compls <- getCompletions doc (Position x y)
127-
item <- case find (\c -> c ^. L.label == label) compls of
128-
Just c -> pure c
129-
Nothing -> liftIO . assertFailure $
130-
"Completion with label " <> show label
131-
<> " not found in " <> show (compls ^.. traversed . L.label)
127+
item <- getCompletionByLabel label compls
132128
liftIO $ do
133129
item ^. L.label @?= label
134130
item ^. L.kind @?= Just CiKeyword

plugins/hls-tactics-plugin/src/Wingman/Judgements.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ buildHypothesis
3232
= Hypothesis
3333
. mapMaybe go
3434
where
35-
go (occName -> occ, t)
36-
| Just ty <- t
37-
, maybe False isAlpha . listToMaybe . occNameString $ occ = Just $ HyInfo occ UserPrv $ CType ty
35+
go (occName -> occ, Just ty)
36+
| (h:_) <- occNameString occ
37+
, isAlpha h = Just $ HyInfo occ UserPrv $ CType ty
3838
| otherwise = Nothing
3939

4040

test/functional/Completion.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,3 @@ shouldNotContainCompl :: [CompletionItem] -> T.Text -> Assertion
338338
compls `shouldNotContainCompl` lbl =
339339
all ((/= lbl) . (^. label)) compls
340340
@? "Should not contain completion: " ++ show lbl
341-
342-
getCompletionByLabel :: T.Text -> [CompletionItem] -> Session CompletionItem
343-
getCompletionByLabel lbl compls =
344-
case find (\c -> c ^. label == lbl) compls of
345-
Just c -> pure c
346-
Nothing ->
347-
let knownLabels = compls ^.. traversed . label
348-
in liftIO . assertFailure $
349-
"Completion with label " <> show lbl
350-
<> " not found in " <> show knownLabels

0 commit comments

Comments
 (0)