Skip to content

Commit aa2c5d5

Browse files
committed
Implement Reviews
1 parent d5baf09 commit aa2c5d5

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import Data.List (find, intersperse,
2727
import qualified Data.Map as Map
2828
import Data.Maybe (fromMaybe, isJust,
2929
mapMaybe, maybeToList)
30-
import Data.Ord (Down (..))
3130
import Data.Text (Text)
3231
import qualified Data.Text as T
3332
import Data.Unique (hashUnique, newUnique)
@@ -165,12 +164,12 @@ codeActionProvider ideState _ (CodeActionParams _ _ docId range _) = do
165164
-- converted to the record syntax through the code action
166165
, isConvertible record
167166
]
168-
sortedRecords = sortOn (Down . recordDepth recordsWithUid . snd) recordsWithUid
167+
sortedRecords = sortOn (recordDepth recordsWithUid . snd) recordsWithUid
169168
pure $ InL $ case sortedRecords of
170-
(top : _) -> [mkCodeAction enabledExtensions top]
169+
(top : _) -> [mkCodeAction enabledExtensions (fst top)]
171170
[] -> []
172171
where
173-
mkCodeAction exts (uid, _record) = InR CodeAction
172+
mkCodeAction exts uid = InR CodeAction
174173
{ _title = mkTitle exts -- TODO: `Expand positional record` without NamedFieldPuns if RecordInfoApp
175174
, _kind = Just CodeActionKind_RefactorRewrite
176175
, _diagnostics = Nothing
@@ -303,6 +302,8 @@ mkTitle exts = "Expand record wildcard"
303302
then mempty
304303
else " (needs extension: NamedFieldPuns)"
305304

305+
-- Calculate the nesting depth of a record by counting how many other records
306+
-- contain it. Used to prioritize more deeply nested records in code actions.
306307
recordDepth :: [(Int, RecordInfo)] -> RecordInfo -> Int
307308
recordDepth allRecords record =
308309
let r = recordInfoToRange record

plugins/hls-explicit-record-fields-plugin/test/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ test = testGroup "explicit-fields"
3838
, mkTestNoAction "Prefix" "Prefix" 10 11 10 28
3939
, mkTestNoAction "PartiallyAppliedCon" "PartiallyAppliedCon" 7 8 7 12
4040
, mkTest "PolymorphicRecordConstruction" "PolymorphicRecordConstruction" 15 5 15 15
41+
, mkTest "CursorOnInnermost" "CursorPositional" 15 26 15 34
42+
, mkTest "CursorOnInnermost" "CursorRecords" 9 40 9 40
4143
]
4244
, testGroup "inlay hints"
4345
[ mkInlayHintsTest "Construction" Nothing 16 $ \ih -> do
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module CursorPositional where
2+
data RecOuter = RecOuter{
3+
middle :: RecMiddle
4+
}
5+
6+
data RecMiddle = RecMiddle {
7+
inner :: RecInner
8+
}
9+
10+
data RecInner = RecInner{
11+
foo :: Char
12+
, bar :: Int
13+
}
14+
15+
ex :: RecOuter
16+
ex = RecOuter (RecMiddle (RecInner { foo = 'c', bar = 42 }))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
module CursorRecords where
3+
4+
data L4 = L4{ a0 :: Int}
5+
data L3 = L3{ a1 :: Int, a11 :: Int, l4 :: L4}
6+
data L2 = L2{ a2 :: Int, l3 :: L3}
7+
data L1 = L1{ a3 :: Int, l2 :: L2}
8+
9+
test :: L1 -> Int
10+
test L1 {l2 = L2{ l3 = L3 {l4 = L4 {..}, a1, a11}, ..}, ..} =
11+
a0 + a1 + a2 + a3 + a11

0 commit comments

Comments
 (0)