Skip to content

Commit

Permalink
update test for dotdot location in label part
Browse files Browse the repository at this point in the history
  • Loading branch information
jetjinser committed Jul 16, 2024
1 parent 9a4d7f5 commit f229b81
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 101 deletions.
1 change: 1 addition & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ test-suite hls-explicit-record-fields-plugin-tests
, base
, filepath
, text
, ghcide
, haskell-language-server:hls-explicit-record-fields-plugin
, hls-test-utils == 2.9.0.1

Expand Down
245 changes: 144 additions & 101 deletions plugins/hls-explicit-record-fields-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Main ( main ) where
import Data.Either (rights)
import Data.Text (Text)
import qualified Data.Text as T
import Development.IDE (filePathToUri',
toNormalizedFilePath')
import Development.IDE.Test (canonicalizeUri)
import qualified Ide.Plugin.ExplicitFields as ExplicitFields
import System.FilePath ((<.>), (</>))
import Test.Hls
Expand Down Expand Up @@ -34,99 +37,135 @@ test = testGroup "explicit-fields"
, mkTestNoAction "Prefix" "Prefix" 10 11 10 28
]
, testGroup "inlay hints"
[ mkInlayHintsTest "Construction" 16 $ (@=?)
[defInlayHint { _position = Position 16 14
, _label = InR [ mkLabelPart "foo", commaPart
, mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar, baz}" 16 5 15
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
}]
, mkInlayHintsTest "HsExpanded1" 17 $ (@=?)
[defInlayHint { _position = Position 17 19
, _label = InR [ mkLabelPart "foo" ]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo}" 17 10 20 ]
, _tooltip = Just $ InL "Expand record wildcard"
}]
, mkInlayHintsTest "HsExpanded2" 23 $ (@=?)
[defInlayHint { _position = Position 23 21
, _label = InR [ mkLabelPart "bar" ]
, _textEdits = Just [ mkLineTextEdit "YourRec {bar}" 23 10 22 ]
, _tooltip = Just $ InL "Expand record wildcard"
}]
, mkInlayHintsTest "Mixed" 14 $ (@=?)
[defInlayHint { _position = Position 14 36
, _label = InR [ mkLabelPart "baz", commaPart
, mkLabelPart "quux"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar = bar', baz}" 14 10 37 ]
, _tooltip = Just $ InL "Expand record wildcard"
}]
, mkInlayHintsTest "Unused" 12 $ (@=?)
[defInlayHint { _position = Position 12 19
, _label = InR [ mkLabelPart "foo", commaPart
, mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
}]
, mkInlayHintsTest "Unused2" 12 $ (@=?)
[defInlayHint { _position = Position 12 19
, _label = InR [ mkLabelPart "foo", commaPart
, mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
}]
, mkInlayHintsTest "Unused2" 12 $ (@=?)
[defInlayHint { _position = Position 12 19
, _label = InR [ mkLabelPart "foo", commaPart
, mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
}]
, mkInlayHintsTest "WildcardOnly" 12 $ (@=?)
[defInlayHint { _position = Position 12 19
, _label = InR [ mkLabelPart "foo", commaPart
, mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar, baz}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
}]
, mkInlayHintsTest "WithExplicitBind" 12 $ (@=?)
[defInlayHint { _position = Position 12 31
, _label = InR [ mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo = foo', bar, baz}" 12 10 32
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
}]
, mkInlayHintsTest "WithPun" 13 $ (@=?)
[defInlayHint { _position = Position 13 24
, _label = InR [ mkLabelPart "bar", commaPart
, mkLabelPart "baz"
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar, baz}" 13 10 25 ]
, _tooltip = Just $ InL "Expand record wildcard"
}]
[ mkInlayHintsTest "Construction" 16 $ \ih -> do
let mkLabelPart' = mkLabelPart "Construction" 16 12
foo <- mkLabelPart' "foo"
bar <- mkLabelPart' "bar"
baz <- mkLabelPart' "baz"
(@?=) ih
[defInlayHint { _position = Position 16 14
, _label = InR [ foo, commaPart
, bar, commaPart
, baz
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar, baz}" 16 5 15
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "HsExpanded1" 17 $ \ih -> do
let mkLabelPart' = mkLabelPart "HsExpanded1" 17 17
foo <- mkLabelPart' "foo"
(@?=) ih
[defInlayHint { _position = Position 17 19
, _label = InR [ foo ]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo}" 17 10 20 ]
, _tooltip = Just $ InL "Expand record wildcard"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "HsExpanded2" 23 $ \ih -> do
let mkLabelPart' = mkLabelPart "HsExpanded2" 23 19
bar <- mkLabelPart' "bar"
(@?=) ih
[defInlayHint { _position = Position 23 21
, _label = InR [ bar ]
, _textEdits = Just [ mkLineTextEdit "YourRec {bar}" 23 10 22 ]
, _tooltip = Just $ InL "Expand record wildcard"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "Mixed" 14 $ \ih -> do
let mkLabelPart' = mkLabelPart "Mixed" 14 34
baz <- mkLabelPart' "baz"
quux <- mkLabelPart' "quux"
(@?=) ih
[defInlayHint { _position = Position 14 36
, _label = InR [ baz, commaPart
, quux
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar = bar', baz}" 14 10 37 ]
, _tooltip = Just $ InL "Expand record wildcard"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "Unused" 12 $ \ih -> do
let mkLabelPart' = mkLabelPart "Unused" 12 17
foo <- mkLabelPart' "foo"
bar <- mkLabelPart' "bar"
baz <- mkLabelPart' "baz"
(@?=) ih
[defInlayHint { _position = Position 12 19
, _label = InR [ foo, commaPart
, bar, commaPart
, baz
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "Unused2" 12 $ \ih -> do
let mkLabelPart' = mkLabelPart "Unused2" 12 17
foo <- mkLabelPart' "foo"
bar <- mkLabelPart' "bar"
baz <- mkLabelPart' "baz"
(@?=) ih
[defInlayHint { _position = Position 12 19
, _label = InR [ foo, commaPart
, bar, commaPart
, baz
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "WildcardOnly" 12 $ \ih -> do
let mkLabelPart' = mkLabelPart "WildcardOnly" 12 17
foo <- mkLabelPart' "foo"
bar <- mkLabelPart' "bar"
baz <- mkLabelPart' "baz"
(@?=) ih
[defInlayHint { _position = Position 12 19
, _label = InR [ foo, commaPart
, bar, commaPart
, baz
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar, baz}" 12 10 20
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "WithExplicitBind" 12 $ \ih -> do
let mkLabelPart' = mkLabelPart "WithExplicitBind" 12 29
bar <- mkLabelPart' "bar"
baz <- mkLabelPart' "baz"
(@?=) ih
[defInlayHint { _position = Position 12 31
, _label = InR [ bar, commaPart
, baz
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo = foo', bar, baz}" 12 10 32
, mkPragmaTextEdit 2
]
, _tooltip = Just $ InL "Expand record wildcard (needs extension: NamedFieldPuns)"
, _paddingLeft = Just True
}]
, mkInlayHintsTest "WithPun" 13 $ \ih -> do
let mkLabelPart' = mkLabelPart "WithPun" 13 22
bar <- mkLabelPart' "bar"
baz <- mkLabelPart' "baz"
(@?=) ih
[defInlayHint { _position = Position 13 24
, _label = InR [ bar, commaPart
, baz
]
, _textEdits = Just [ mkLineTextEdit "MyRec {foo, bar, baz}" 13 10 25 ]
, _tooltip = Just $ InL "Expand record wildcard"
, _paddingLeft = Just True
}]
]
]

Expand Down Expand Up @@ -187,14 +226,18 @@ defInlayHint =
, _data_ = Nothing
}

mkLabelPart :: Text -> InlayHintLabelPart
mkLabelPart value =
InlayHintLabelPart
{ _location = Nothing
, _value = value
, _tooltip = Nothing
, _command = Nothing
}
mkLabelPart :: FilePath -> UInt -> UInt -> Text -> IO InlayHintLabelPart
mkLabelPart fp dotline dotstart value = do
uri' <- uri
pure $ InlayHintLabelPart { _location = Just (location uri' dotline dotstart)
, _value = value
, _tooltip = Nothing
, _command = Nothing
}
where
toUri = fromNormalizedUri . filePathToUri' . toNormalizedFilePath'
uri = canonicalizeUri $ toUri (testDataDir </> (fp ++ ".hs"))
location uri line char = Location uri (Range (Position line char) (Position line (char + 2)))

commaPart :: InlayHintLabelPart
commaPart =
Expand Down

0 comments on commit f229b81

Please sign in to comment.