From 65ff05147ecceb97e7dd68a7bdaf01c12af7de2d Mon Sep 17 00:00:00 2001 From: pranaysashank Date: Tue, 7 Sep 2021 22:27:00 +0530 Subject: [PATCH 1/4] Use maxBound of uinteger not Int. --- ghcide/src/Development/IDE/LSP/Outline.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index 22e1a3fa85..10483de7bf 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -48,7 +48,7 @@ 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 } _ -> Nothing importSymbols = maybe [] pure $ From 629a724a0adf909d1e82af0fe923235c32efbf16 Mon Sep 17 00:00:00 2001 From: pranaysashank Date: Wed, 8 Sep 2021 00:26:40 +0530 Subject: [PATCH 2/4] Add a comment explaining the magic number 2147483647. --- ghcide/src/Development/IDE/LSP/Outline.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index 10483de7bf..988f144aec 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -49,6 +49,12 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif { _name = pprText m , _kind = SkFile , _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/134 + -- the change in lsp-types. } _ -> Nothing importSymbols = maybe [] pure $ From f92905c773d7c1f528a3e123d58db8fa4770d497 Mon Sep 17 00:00:00 2001 From: pranaysashank Date: Wed, 8 Sep 2021 00:36:46 +0530 Subject: [PATCH 3/4] Replace usages of maxBound with maxBoundUinteger in test and bench. --- ghcide/bench/lib/Experiments.hs | 7 ++++++- ghcide/test/exe/Main.hs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ghcide/bench/lib/Experiments.hs b/ghcide/bench/lib/Experiments.hs index 4b3396d7db..3007d8d242 100644 --- a/ghcide/bench/lib/Experiments.hs +++ b/ghcide/bench/lib/Experiments.hs @@ -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]" @@ -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 diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index 800027c569..99c0b7c7a2 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file From 1e56090e9616deac0460dc86c7684f7a9192c4b6 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Thu, 9 Sep 2021 09:31:49 +0200 Subject: [PATCH 4/4] Update lsp issue link --- ghcide/src/Development/IDE/LSP/Outline.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index 988f144aec..44714f23d7 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -53,7 +53,7 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif -- 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 + -- Check this issue for tracking https://github.com/haskell/lsp/issues/354 -- the change in lsp-types. } _ -> Nothing