@@ -22,24 +22,24 @@ plugin = mkPluginTestDescriptor ExplicitFields.descriptor "explicit-fields"
2222test :: TestTree
2323test = testGroup " explicit-fields"
2424 [ testGroup " code actions"
25- [ mkTest " WildcardOnly" " WildcardOnly" 12 10 12 20
26- , mkTest " Unused" " Unused" 12 10 12 20
27- , mkTest " Unused2" " Unused2" 12 10 12 20
28- , mkTest " WithPun" " WithPun" 13 10 13 25
29- , mkTest " WithExplicitBind" " WithExplicitBind" 12 10 12 32
30- , mkTest " Mixed" " Mixed" 14 10 14 37
31- , mkTest " Construction" " Construction" 16 5 16 15
32- , mkTest " PositionalConstruction" " PositionalConstruction" 15 5 15 15
33- , mkTest " HsExpanded1" " HsExpanded1" 17 10 17 20
34- , mkTest " HsExpanded2" " HsExpanded2" 23 10 23 22
25+ [ mkExpansionTest " WildcardOnly" " WildcardOnly" 12 10 12 20
26+ , mkExpansionTest " Unused" " Unused" 12 10 12 20
27+ , mkExpansionTest " Unused2" " Unused2" 12 10 12 20
28+ , mkExpansionTest " WithPun" " WithPun" 13 10 13 25
29+ , mkExpansionTest " WithExplicitBind" " WithExplicitBind" 12 10 12 32
30+ , mkExpansionTest " Mixed" " Mixed" 14 10 14 37
31+ , mkExpansionTest " Construction" " Construction" 16 5 16 15
32+ , mkConversionTest " PositionalConstruction" " PositionalConstruction" 15 5 15 15
33+ , mkExpansionTest " HsExpanded1" " HsExpanded1" 17 10 17 20
34+ , mkExpansionTest " HsExpanded2" " HsExpanded2" 23 10 23 22
3535 , mkTestNoAction " ExplicitBinds" " ExplicitBinds" 11 10 11 52
3636 , mkTestNoAction " Puns" " Puns" 12 10 12 31
3737 , mkTestNoAction " Infix" " Infix" 11 11 11 31
3838 , mkTestNoAction " Prefix" " Prefix" 10 11 10 28
3939 , mkTestNoAction " PartiallyAppliedCon" " PartiallyAppliedCon" 7 8 7 12
40- , mkTest " PolymorphicRecordConstruction" " PolymorphicRecordConstruction" 15 5 15 15
41- , mkTest " CursorAwarePositional" " CursorPositional" 15 26 15 34
42- , mkTest " CursorAwareRecords" " CursorRecords" 9 40 9 40
40+ , mkConversionTest " PolymorphicRecordConstruction" " PolymorphicRecordConstruction" 15 5 15 15
41+ , mkConversionTest " CursorAwarePositional" " CursorPositional" 15 26 15 34
42+ , mkExpansionTest " CursorAwareRecords" " CursorRecords" 9 40 9 40
4343 ]
4444 , testGroup " inlay hints"
4545 [ mkInlayHintsTest " Construction" Nothing 16 $ \ ih -> do
@@ -86,19 +86,19 @@ test = testGroup "explicit-fields"
8686 [ defInlayHint { _position = Position 15 11
8787 , _label = InR [ foo ]
8888 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
89- , _tooltip = Just $ InL " Expand positional record"
89+ , _tooltip = Just $ InL " Convert to traditional record syntax "
9090 , _paddingLeft = Nothing
9191 }
9292 , defInlayHint { _position = Position 15 13
9393 , _label = InR [ bar ]
9494 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
95- , _tooltip = Just $ InL " Expand positional record"
95+ , _tooltip = Just $ InL " Convert to traditional record syntax "
9696 , _paddingLeft = Nothing
9797 }
9898 , defInlayHint { _position = Position 15 15
9999 , _label = InR [ baz ]
100100 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
101- , _tooltip = Just $ InL " Expand positional record"
101+ , _tooltip = Just $ InL " Convert to traditional record syntax "
102102 , _paddingLeft = Nothing
103103 }
104104 ]
@@ -111,19 +111,19 @@ test = testGroup "explicit-fields"
111111 [ defInlayHint { _position = Position 15 11
112112 , _label = InR [ foo ]
113113 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
114- , _tooltip = Just $ InL " Expand positional record"
114+ , _tooltip = Just $ InL " Convert to traditional record syntax "
115115 , _paddingLeft = Nothing
116116 }
117117 , defInlayHint { _position = Position 15 13
118118 , _label = InR [ bar ]
119119 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
120- , _tooltip = Just $ InL " Expand positional record"
120+ , _tooltip = Just $ InL " Convert to traditional record syntax "
121121 , _paddingLeft = Nothing
122122 }
123123 , defInlayHint { _position = Position 15 15
124124 , _label = InR [ baz ]
125125 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
126- , _tooltip = Just $ InL " Expand positional record"
126+ , _tooltip = Just $ InL " Convert to traditional record syntax "
127127 , _paddingLeft = Nothing
128128 }
129129 ]
@@ -144,7 +144,7 @@ test = testGroup "explicit-fields"
144144 [defInlayHint { _position = Position 13 21
145145 , _label = InR [ foo ]
146146 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = 5 }" 13 15 22 ]
147- , _tooltip = Just $ InL " Expand positional record"
147+ , _tooltip = Just $ InL " Convert to traditional record syntax "
148148 , _paddingLeft = Nothing
149149 }]
150150 , mkInlayHintsTest " HsExpanded1DuplicateRecordFields" (Just " (positional)" ) 13 $ \ ih -> do
@@ -154,7 +154,7 @@ test = testGroup "explicit-fields"
154154 [defInlayHint { _position = Position 13 21
155155 , _label = InR [ foo ]
156156 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = 5 }" 13 15 22 ]
157- , _tooltip = Just $ InL " Expand positional record"
157+ , _tooltip = Just $ InL " Convert to traditional record syntax "
158158 , _paddingLeft = Nothing
159159 }]
160160 , mkInlayHintsTest " HsExpanded2" Nothing 23 $ \ ih -> do
@@ -174,7 +174,7 @@ test = testGroup "explicit-fields"
174174 [defInlayHint { _position = Position 16 21
175175 , _label = InR [ foo ]
176176 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = 5 }" 16 15 22 ]
177- , _tooltip = Just $ InL " Expand positional record"
177+ , _tooltip = Just $ InL " Convert to traditional record syntax "
178178 , _paddingLeft = Nothing
179179 }]
180180 , mkInlayHintsTest " Mixed" Nothing 14 $ \ ih -> do
@@ -278,19 +278,19 @@ test = testGroup "explicit-fields"
278278 [ defInlayHint { _position = Position 15 11
279279 , _label = InR [ foo ]
280280 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
281- , _tooltip = Just $ InL " Expand positional record"
281+ , _tooltip = Just $ InL " Convert to traditional record syntax "
282282 , _paddingLeft = Nothing
283283 }
284284 , defInlayHint { _position = Position 15 13
285285 , _label = InR [ bar ]
286286 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
287- , _tooltip = Just $ InL " Expand positional record"
287+ , _tooltip = Just $ InL " Convert to traditional record syntax "
288288 , _paddingLeft = Nothing
289289 }
290290 , defInlayHint { _position = Position 15 15
291291 , _label = InR [ baz ]
292292 , _textEdits = Just [ mkLineTextEdit " MyRec { foo = a, bar = b, baz = c }" 15 5 16 ]
293- , _tooltip = Just $ InL " Expand positional record"
293+ , _tooltip = Just $ InL " Convert to traditional record syntax "
294294 , _paddingLeft = Nothing
295295 }
296296 ]
@@ -350,30 +350,30 @@ test = testGroup "explicit-fields"
350350 { _position = Position 15 14
351351 , _label = InR [ middle ]
352352 , _textEdits = Just [ mkLineTextEdit " RecOuter { middle = (RecMiddle (RecInner 'c' 42)) }" 15 5 43 ]
353- , _tooltip = Just $ InL " Expand positional record"
353+ , _tooltip = Just $ InL " Convert to traditional record syntax "
354354 , _paddingLeft = Nothing
355355 }
356356 , defInlayHint
357357 { _position = Position 15 25
358358 , _label = InR [ inner ]
359359 , _textEdits = Just [ mkLineTextEdit " RecMiddle { inner = (RecInner 'c' 42) }" 15 15 42 ]
360- , _tooltip = Just $ InL " Expand positional record"
360+ , _tooltip = Just $ InL " Convert to traditional record syntax "
361361 , _paddingLeft = Nothing
362362 }
363363 , defInlayHint
364364 { _position = Position 15 35
365365 , _label = InR [ foo ]
366366 , _textEdits =
367367 Just [ mkLineTextEdit " RecInner { foo = 'c', bar = 42 }" 15 26 41 ]
368- , _tooltip = Just $ InL " Expand positional record"
368+ , _tooltip = Just $ InL " Convert to traditional record syntax "
369369 , _paddingLeft = Nothing
370370 }
371371 , defInlayHint
372372 { _position = Position 15 39
373373 , _label = InR [ bar ]
374374 , _textEdits =
375375 Just [ mkLineTextEdit " RecInner { foo = 'c', bar = 42 }" 15 26 41 ]
376- , _tooltip = Just $ InL " Expand positional record"
376+ , _tooltip = Just $ InL " Convert to traditional record syntax "
377377 , _paddingLeft = Nothing
378378 }
379379 ]
@@ -395,35 +395,47 @@ mkTestNoAction title fp x1 y1 x2 y2 =
395395 testCase title $
396396 runSessionWithServer def plugin (testDataDir </> " noop" ) $ do
397397 doc <- openDoc (fp <.> " hs" ) " haskell"
398- actions <- getExplicitFieldsActions doc x1 y1 x2 y2
398+ actions <- getActions isExplicitFieldsCodeAction doc x1 y1 x2 y2
399399 liftIO $ actions @?= []
400400
401- mkTestWithCount :: Int -> TestName -> FilePath -> UInt -> UInt -> UInt -> UInt -> TestTree
402- mkTestWithCount cnt title fp x1 y1 x2 y2 =
401+ mkTestWithCountAndMessage :: ( CodeAction -> Bool ) -> Int -> TestName -> FilePath -> UInt -> UInt -> UInt -> UInt -> TestTree
402+ mkTestWithCountAndMessage msgPredicate cnt title fp x1 y1 x2 y2 =
403403 goldenWithHaskellAndCaps def codeActionResolveCaps plugin title testDataDir fp " expected" " hs" $ \ doc -> do
404- acts@ (act: _) <- getExplicitFieldsActions doc x1 y1 x2 y2
404+ acts@ (act: _) <- getActions msgPredicate doc x1 y1 x2 y2
405405 liftIO $ length acts @?= cnt
406406 executeCodeAction act
407407
408- mkTest :: TestName -> FilePath -> UInt -> UInt -> UInt -> UInt -> TestTree
409- mkTest = mkTestWithCount 1
408+ mkExpansionTest :: TestName -> FilePath -> UInt -> UInt -> UInt -> UInt -> TestTree
409+ mkExpansionTest = mkTestWithCountAndMessage isRecWildcardExpansionCodeAction 1
410410
411- getExplicitFieldsActions
412- :: TextDocumentIdentifier
411+ mkConversionTest :: TestName -> FilePath -> UInt -> UInt -> UInt -> UInt -> TestTree
412+ mkConversionTest = mkTestWithCountAndMessage isRecLiteralConversionCodeAction 1
413+
414+ getActions
415+ :: (CodeAction -> Bool ) -> TextDocumentIdentifier
413416 -> UInt -> UInt -> UInt -> UInt
414417 -> Session [CodeAction ]
415- getExplicitFieldsActions doc x1 y1 x2 y2 =
416- findExplicitFieldsAction <$> getAndResolveCodeActions doc range
418+ getActions p doc x1 y1 x2 y2 =
419+ findAction p <$> getAndResolveCodeActions doc range
417420 where
418421 range = Range (Position x1 y1) (Position x2 y2)
419422
420- findExplicitFieldsAction :: [a |? CodeAction ] -> [CodeAction ]
421- findExplicitFieldsAction = filter isExplicitFieldsCodeAction . rights . map toEither
423+ findAction :: ( CodeAction -> Bool ) -> [a |? CodeAction ] -> [CodeAction ]
424+ findAction p = filter p . rights . map toEither
422425
423426isExplicitFieldsCodeAction :: CodeAction -> Bool
424- isExplicitFieldsCodeAction CodeAction {_title} =
427+ isExplicitFieldsCodeAction act =
428+ isRecWildcardExpansionCodeAction act
429+ || isRecLiteralConversionCodeAction act
430+
431+ isRecWildcardExpansionCodeAction :: CodeAction -> Bool
432+ isRecWildcardExpansionCodeAction CodeAction {_title} =
425433 " Expand record wildcard" `T.isPrefixOf` _title
426434
435+ isRecLiteralConversionCodeAction :: CodeAction -> Bool
436+ isRecLiteralConversionCodeAction CodeAction {_title} =
437+ " Convert to traditional record syntax" `T.isPrefixOf` _title
438+
427439defInlayHint :: InlayHint
428440defInlayHint =
429441 InlayHint
0 commit comments