Skip to content

Commit 155023f

Browse files
pranaysashankAilrunjneira
authored
Use maxBound of uinteger not Int. (#2169)
* Use maxBound of uinteger not Int. * Add a comment explaining the magic number 2147483647. * Replace usages of maxBound with maxBoundUinteger in test and bench. * Update lsp issue link Co-authored-by: Junyoung "Clare" Jang <[email protected]> Co-authored-by: Javier Neira <[email protected]>
1 parent c3e2e23 commit 155023f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

ghcide/bench/lib/Experiments.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ experiments =
187187
let edit :: TextDocumentContentChangeEvent =TextDocumentContentChangeEvent
188188
{ _range = Just Range {_start = bottom, _end = bottom}
189189
, _rangeLength = Nothing, _text = t}
190-
bottom = Position maxBound 0
190+
bottom = Position maxBoundUinteger 0
191191
t = T.unlines
192192
[""
193193
,"holef :: [Int] -> [Int]"
@@ -625,3 +625,8 @@ searchSymbol doc@TextDocumentIdentifier{_uri} fileContents pos = do
625625
_ -> return False
626626
checkCompletions pos =
627627
not . null <$> getCompletions doc pos
628+
629+
-- | We don't have a uinteger type yet. So hardcode the maxBound of uinteger, 2 ^ 31 - 1
630+
-- as a constant.
631+
maxBoundUinteger :: Int
632+
maxBoundUinteger = 2147483647

ghcide/src/Development/IDE/LSP/Outline.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif
4848
(defDocumentSymbol l :: DocumentSymbol)
4949
{ _name = pprText m
5050
, _kind = SkFile
51-
, _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0
51+
, _range = Range (Position 0 0) (Position 2147483647 0) -- _ltop is 0 0 0 0
52+
-- In the lsp spec from 3.16 Position takes a uinteger,
53+
-- where uinteger is 0 - 2^31 - 1. lsp-types currently has the type of line
54+
-- as Int. So instead of using `maxBound :: Int` we hardcode the maxBound of
55+
-- uinteger. 2 ^ 31 - 1 == 2147483647
56+
-- Check this issue for tracking https://github.com/haskell/lsp/issues/354
57+
-- the change in lsp-types.
5258
}
5359
_ -> Nothing
5460
importSymbols = maybe [] pure $

ghcide/test/exe/Main.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ suggestImportTests = testGroup "suggest import actions"
17291729
-- there isn't a good way to wait until the whole project is checked atm
17301730
when waitForCheckProject $ liftIO $ sleep 0.5
17311731
let defLine = length imps + 1
1732-
range = Range (Position defLine 0) (Position defLine maxBound)
1732+
range = Range (Position defLine 0) (Position defLine maxBoundUinteger)
17331733
actions <- getCodeActions doc range
17341734
if wanted
17351735
then do
@@ -2467,7 +2467,7 @@ fillTypedHoleTests = let
24672467
let expectedCode = sourceCode newA newB newC
24682468
doc <- createDoc "Testing.hs" "haskell" originalCode
24692469
_ <- waitForDiagnostics
2470-
actionsOrCommands <- getCodeActions doc (Range (Position 9 0) (Position 9 maxBound))
2470+
actionsOrCommands <- getCodeActions doc (Range (Position 9 0) (Position 9 maxBoundUinteger))
24712471
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
24722472
executeCodeAction chosenAction
24732473
modifiedCode <- documentContents doc
@@ -2508,7 +2508,7 @@ fillTypedHoleTests = let
25082508
, "ioToSome = " <> x ]
25092509
doc <- createDoc "Test.hs" "haskell" $ mkDoc "_toException"
25102510
_ <- waitForDiagnostics
2511-
actions <- getCodeActions doc (Range (Position 3 0) (Position 3 maxBound))
2511+
actions <- getCodeActions doc (Range (Position 3 0) (Position 3 maxBoundUinteger))
25122512
chosen <- liftIO $ pickActionWithTitle "replace _toException with E.toException" actions
25132513
executeCodeAction chosen
25142514
modifiedCode <- documentContents doc
@@ -3003,7 +3003,7 @@ addSigActionTests = let
30033003
let expectedCode = after' def sig
30043004
doc <- createDoc "Sigs.hs" "haskell" originalCode
30053005
_ <- waitForDiagnostics
3006-
actionsOrCommands <- getCodeActions doc (Range (Position 5 1) (Position 5 maxBound))
3006+
actionsOrCommands <- getCodeActions doc (Range (Position 5 1) (Position 5 maxBoundUinteger))
30073007
chosenAction <- liftIO $ pickActionWithTitle ("add signature: " <> sig) actionsOrCommands
30083008
executeCodeAction chosenAction
30093009
modifiedCode <- documentContents doc
@@ -4800,7 +4800,7 @@ outlineTests = testGroup
48004800
SkFile
48014801
Nothing
48024802
Nothing
4803-
(R 0 0 maxBound 0)
4803+
(R 0 0 maxBoundUinteger 0)
48044804
loc
48054805
(Just $ List cc)
48064806
classSymbol name loc cc = DocumentSymbol name
@@ -5991,3 +5991,8 @@ listOfChar | ghcVersion >= GHC90 = "String"
59915991
thDollarIdx :: Int
59925992
thDollarIdx | ghcVersion >= GHC90 = 1
59935993
| otherwise = 0
5994+
5995+
-- | We don't have a uinteger type yet. So hardcode the maxBound of uinteger, 2 ^ 31 - 1
5996+
-- as a constant.
5997+
maxBoundUinteger :: Int
5998+
maxBoundUinteger = 2147483647

0 commit comments

Comments
 (0)