Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use maxBound of uinteger not Int. #2169

Merged
merged 8 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
fendor marked this conversation as resolved.
Show resolved Hide resolved
-- 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/134
-- 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