Skip to content

Commit

Permalink
Use maxBound of uinteger not Int. (#2169)
Browse files Browse the repository at this point in the history
* 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 <jjc9310@gmail.com>
Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
  • Loading branch information
3 people authored Sep 11, 2021
1 parent c3e2e23 commit 155023f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
7 changes: 6 additions & 1 deletion ghcide/bench/lib/Experiments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ experiments =
let edit :: TextDocumentContentChangeEvent =TextDocumentContentChangeEvent
{ _range = Just Range {_start = bottom, _end = bottom}
, _rangeLength = Nothing, _text = t}
bottom = Position maxBound 0
bottom = Position maxBoundUinteger 0
t = T.unlines
[""
,"holef :: [Int] -> [Int]"
Expand Down Expand Up @@ -625,3 +625,8 @@ searchSymbol doc@TextDocumentIdentifier{_uri} fileContents pos = do
_ -> return False
checkCompletions pos =
not . null <$> getCompletions doc pos

-- | We don't have a uinteger type yet. So hardcode the maxBound of uinteger, 2 ^ 31 - 1
-- as a constant.
maxBoundUinteger :: Int
maxBoundUinteger = 2147483647
8 changes: 7 additions & 1 deletion ghcide/src/Development/IDE/LSP/Outline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif
(defDocumentSymbol l :: DocumentSymbol)
{ _name = pprText m
, _kind = SkFile
, _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0
, _range = Range (Position 0 0) (Position 2147483647 0) -- _ltop is 0 0 0 0
-- In the lsp spec from 3.16 Position takes a uinteger,
-- where uinteger is 0 - 2^31 - 1. lsp-types currently has the type of line
-- as Int. So instead of using `maxBound :: Int` we hardcode the maxBound of
-- uinteger. 2 ^ 31 - 1 == 2147483647
-- Check this issue for tracking https://github.com/haskell/lsp/issues/354
-- the change in lsp-types.
}
_ -> Nothing
importSymbols = maybe [] pure $
Expand Down
15 changes: 10 additions & 5 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ suggestImportTests = testGroup "suggest import actions"
-- there isn't a good way to wait until the whole project is checked atm
when waitForCheckProject $ liftIO $ sleep 0.5
let defLine = length imps + 1
range = Range (Position defLine 0) (Position defLine maxBound)
range = Range (Position defLine 0) (Position defLine maxBoundUinteger)
actions <- getCodeActions doc range
if wanted
then do
Expand Down Expand Up @@ -2467,7 +2467,7 @@ fillTypedHoleTests = let
let expectedCode = sourceCode newA newB newC
doc <- createDoc "Testing.hs" "haskell" originalCode
_ <- waitForDiagnostics
actionsOrCommands <- getCodeActions doc (Range (Position 9 0) (Position 9 maxBound))
actionsOrCommands <- getCodeActions doc (Range (Position 9 0) (Position 9 maxBoundUinteger))
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
executeCodeAction chosenAction
modifiedCode <- documentContents doc
Expand Down Expand Up @@ -2508,7 +2508,7 @@ fillTypedHoleTests = let
, "ioToSome = " <> x ]
doc <- createDoc "Test.hs" "haskell" $ mkDoc "_toException"
_ <- waitForDiagnostics
actions <- getCodeActions doc (Range (Position 3 0) (Position 3 maxBound))
actions <- getCodeActions doc (Range (Position 3 0) (Position 3 maxBoundUinteger))
chosen <- liftIO $ pickActionWithTitle "replace _toException with E.toException" actions
executeCodeAction chosen
modifiedCode <- documentContents doc
Expand Down Expand Up @@ -3003,7 +3003,7 @@ addSigActionTests = let
let expectedCode = after' def sig
doc <- createDoc "Sigs.hs" "haskell" originalCode
_ <- waitForDiagnostics
actionsOrCommands <- getCodeActions doc (Range (Position 5 1) (Position 5 maxBound))
actionsOrCommands <- getCodeActions doc (Range (Position 5 1) (Position 5 maxBoundUinteger))
chosenAction <- liftIO $ pickActionWithTitle ("add signature: " <> sig) actionsOrCommands
executeCodeAction chosenAction
modifiedCode <- documentContents doc
Expand Down Expand Up @@ -4800,7 +4800,7 @@ outlineTests = testGroup
SkFile
Nothing
Nothing
(R 0 0 maxBound 0)
(R 0 0 maxBoundUinteger 0)
loc
(Just $ List cc)
classSymbol name loc cc = DocumentSymbol name
Expand Down Expand Up @@ -5991,3 +5991,8 @@ listOfChar | ghcVersion >= GHC90 = "String"
thDollarIdx :: Int
thDollarIdx | ghcVersion >= GHC90 = 1
| otherwise = 0

-- | We don't have a uinteger type yet. So hardcode the maxBound of uinteger, 2 ^ 31 - 1
-- as a constant.
maxBoundUinteger :: Int
maxBoundUinteger = 2147483647

0 comments on commit 155023f

Please # to comment.