Skip to content

Commit 839ae86

Browse files
committed
Upgrade to latest lsp/lsp-types/lsp-test
1 parent 8afc65a commit 839ae86

File tree

27 files changed

+189
-185
lines changed

27 files changed

+189
-185
lines changed

cabal.project

+8
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ constraints:
4242
-- We want to be able to benefit from the performance optimisations
4343
-- in the future, thus: TODO: remove this flag.
4444
bitvec -simd
45+
46+
source-repository-package
47+
type:git
48+
location: https://github.com/haskell/lsp
49+
tag: 1e5940b4c85d53f01831bca487f3cd0a9466d3de
50+
subdir: lsp
51+
subdir: lsp-test
52+
subdir: lsp-types

ghcide-bench/src/Experiments.hs

+32-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE GADTs #-}
33
{-# LANGUAGE ImplicitParams #-}
44
{-# LANGUAGE ImpredicativeTypes #-}
5-
{-# LANGUAGE OverloadedLabels #-}
65
{-# LANGUAGE OverloadedStrings #-}
76
{-# OPTIONS_GHC -Wno-deprecations -Wno-unticked-promoted-constructors #-}
87

@@ -43,7 +42,6 @@ import Data.Either (fromRight)
4342
import Data.List
4443
import Data.Maybe
4544
import Data.Proxy
46-
import Data.Row hiding (switch)
4745
import Data.Text (Text)
4846
import qualified Data.Text as T
4947
import Data.Version
@@ -71,15 +69,19 @@ import Text.Printf
7169

7270
charEdit :: Position -> TextDocumentContentChangeEvent
7371
charEdit p =
74-
TextDocumentContentChangeEvent $ InL $ #range .== Range p p
75-
.+ #rangeLength .== Nothing
76-
.+ #text .== "a"
72+
TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
73+
{ _range = Range p p
74+
, _rangeLength = Nothing
75+
, _text = "a"
76+
}
7777

7878
headerEdit :: TextDocumentContentChangeEvent
7979
headerEdit =
80-
TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 0 0) (Position 0 0)
81-
.+ #rangeLength .== Nothing
82-
.+ #text .== "-- header comment \n"
80+
TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
81+
{ _range = Range (Position 0 0) (Position 0 0)
82+
, _rangeLength = Nothing
83+
, _text = "-- header comment \n"
84+
}
8385

8486
data DocumentPositions = DocumentPositions {
8587
-- | A position that can be used to generate non null goto-def and completion responses
@@ -240,9 +242,11 @@ experiments =
240242
benchWithSetup
241243
"hole fit suggestions"
242244
( mapM_ $ \DocumentPositions{..} -> do
243-
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
244-
.+ #rangeLength .== Nothing
245-
.+ #text .== t
245+
let edit = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
246+
{ _range = Range bottom bottom
247+
, _rangeLength = Nothing
248+
, _text = t
249+
}
246250
bottom = Position maxBound 0
247251
t = T.unlines
248252
[""
@@ -270,9 +274,11 @@ experiments =
270274
benchWithSetup
271275
"eval execute single-line code lens"
272276
( mapM_ $ \DocumentPositions{..} -> do
273-
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
274-
.+ #rangeLength .== Nothing
275-
.+ #text .== t
277+
let edit = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
278+
{ _range = Range bottom bottom
279+
, _rangeLength = Nothing
280+
, _text = t
281+
}
276282
bottom = Position maxBound 0
277283
t = T.unlines
278284
[ ""
@@ -295,9 +301,11 @@ experiments =
295301
benchWithSetup
296302
"eval execute multi-line code lens"
297303
( mapM_ $ \DocumentPositions{..} -> do
298-
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
299-
.+ #rangeLength .== Nothing
300-
.+ #text .== t
304+
let edit = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
305+
{ _range = Range bottom bottom
306+
, _rangeLength = Nothing
307+
, _text = t
308+
}
301309
bottom = Position maxBound 0
302310
t = T.unlines
303311
[ ""
@@ -551,7 +559,7 @@ runBenchmarksFun dir allBenchmarks = do
551559
lspTestCaps =
552560
fullCaps
553561
& (L.window . _Just) .~ WindowClientCapabilities (Just True) Nothing Nothing
554-
& (L.textDocument . _Just . L.codeAction . _Just . L.resolveSupport . _Just) .~ (#properties .== ["edit"])
562+
& (L.textDocument . _Just . L.codeAction . _Just . L.resolveSupport . _Just) .~ (ClientCodeActionResolveOptions ["edit"])
555563
& (L.textDocument . _Just . L.codeAction . _Just . L.dataSupport . _Just) .~ True
556564

557565
showMs :: Seconds -> String
@@ -755,10 +763,12 @@ setupDocumentContents config =
755763

756764
-- Setup the special positions used by the experiments
757765
lastLine <- fromIntegral . length . T.lines <$> documentContents doc
758-
changeDoc doc [TextDocumentContentChangeEvent $ InL
759-
$ #range .== Range (Position lastLine 0) (Position lastLine 0)
760-
.+ #rangeLength .== Nothing
761-
.+ #text .== T.unlines [ "_hygienic = \"hygienic\"" ]]
766+
changeDoc doc [TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
767+
{ _range = Range (Position lastLine 0) (Position lastLine 0)
768+
, _rangeLength = Nothing
769+
, _text = T.unlines [ "_hygienic = \"hygienic\"" ]
770+
}
771+
]
762772
let
763773
-- Points to a string in the target file,
764774
-- convenient for hygienic edits

ghcide/src/Development/IDE/Core/PositionMapping.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE OverloadedLabels #-}
21
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
32
-- SPDX-License-Identifier: Apache-2.0
43
module Development.IDE.Core.PositionMapping
@@ -25,13 +24,15 @@ module Development.IDE.Core.PositionMapping
2524
) where
2625

2726
import Control.DeepSeq
27+
import Control.Lens ((^.))
2828
import Control.Monad
2929
import Data.Algorithm.Diff
3030
import Data.Bifunctor
3131
import Data.List
3232
import Data.Row
3333
import qualified Data.Text as T
3434
import qualified Data.Vector.Unboxed as V
35+
import qualified Language.LSP.Protocol.Lens as L
3536
import Language.LSP.Protocol.Types (Position (Position),
3637
Range (Range),
3738
TextDocumentContentChangeEvent (TextDocumentContentChangeEvent),
@@ -131,8 +132,8 @@ addOldDelta delta (PositionMapping pm) = PositionMapping (composeDelta pm delta)
131132
-- that was what was done with lsp* 1.6 packages
132133
applyChange :: PositionDelta -> TextDocumentContentChangeEvent -> PositionDelta
133134
applyChange PositionDelta{..} (TextDocumentContentChangeEvent (InL x)) = PositionDelta
134-
{ toDelta = toCurrent (x .! #range) (x .! #text) <=< toDelta
135-
, fromDelta = fromDelta <=< fromCurrent (x .! #range) (x .! #text)
135+
{ toDelta = toCurrent (x ^. L.range) (x ^. L.text) <=< toDelta
136+
, fromDelta = fromDelta <=< fromCurrent (x ^. L.range) (x ^. L.text)
136137
}
137138
applyChange posMapping _ = posMapping
138139

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE DuplicateRecordFields #-}
33
{-# LANGUAGE GADTs #-}
44
{-# LANGUAGE MultiWayIf #-}
5-
{-# LANGUAGE OverloadedLabels #-}
65

76
-- Mostly taken from "haskell-ide-engine"
87
module Development.IDE.Plugin.Completions.Logic (
@@ -530,7 +529,7 @@ toggleSnippets ClientCapabilities {_textDocument} CompletionsConfig{..} =
530529
removeSnippetsWhen (not $ enableSnippets && supported)
531530
where
532531
supported =
533-
Just True == (_textDocument >>= _completion >>= view L.completionItem >>= (\x -> x .! #snippetSupport))
532+
Just True == (_textDocument >>= _completion >>= view L.completionItem >>= view L.snippetSupport)
534533

535534
toggleAutoExtend :: CompletionsConfig -> CompItem -> CompItem
536535
toggleAutoExtend CompletionsConfig{enableAutoExtend=False} x = x {additionalTextEdits = Nothing}

ghcide/test/exe/CompletionTests.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Control.Monad.IO.Class (liftIO)
1515
import Data.Default
1616
import Data.List.Extra
1717
import Data.Maybe
18-
import Data.Row
1918
import qualified Data.Text as T
2019
import Development.IDE.GHC.Compat (GhcVersion (..), ghcVersion)
2120
import Development.IDE.Types.Location
@@ -205,7 +204,7 @@ localCompletionTests = [
205204
doc <- createDoc "A.hs" "haskell" $ src "AAA"
206205
void $ waitForTypecheck doc
207206
let editA rhs =
208-
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) #text $ src rhs]
207+
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ src rhs]
209208
editA "AAAA"
210209
void $ waitForTypecheck doc
211210
editA "AAAAA"

ghcide/test/exe/CradleTests.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

2-
{-# LANGUAGE GADTs #-}
3-
{-# LANGUAGE OverloadedLabels #-}
2+
{-# LANGUAGE GADTs #-}
43

54
module CradleTests (tests) where
65

76
import Control.Applicative.Combinators
87
import Control.Monad.IO.Class (liftIO)
9-
import Data.Row
108
import qualified Data.Text as T
119
import Development.IDE.GHC.Compat (GhcVersion (..))
1210
import Development.IDE.GHC.Util
@@ -63,7 +61,7 @@ loadCradleOnlyonce = testGroup "load cradle only once"
6361
doc <- createDoc "B.hs" "haskell" "module B where\nimport Data.Foo"
6462
msgs <- someTill (skipManyTill anyMessage cradleLoadedMessage) (skipManyTill anyMessage (message SMethod_TextDocumentPublishDiagnostics))
6563
liftIO $ length msgs @?= 1
66-
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) #text $ "module B where\nimport Data.Maybe"]
64+
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ "module B where\nimport Data.Maybe"]
6765
msgs <- manyTill (skipManyTill anyMessage cradleLoadedMessage) (skipManyTill anyMessage (message SMethod_TextDocumentPublishDiagnostics))
6866
liftIO $ length msgs @?= 0
6967
_ <- createDoc "A.hs" "haskell" "module A where\nimport LoadCradleBar"
@@ -222,9 +220,11 @@ sessionDepsArePickedUp = testSession'
222220
[FileEvent (filePathToUri $ dir </> "hie.yaml") FileChangeType_Changed ]
223221
-- Send change event.
224222
let change =
225-
TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 4 0) (Position 4 0)
226-
.+ #rangeLength .== Nothing
227-
.+ #text .== "\n"
223+
TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
224+
{ _range = Range (Position 4 0) (Position 4 0)
225+
, _rangeLength = Nothing
226+
, _text = "\n"
227+
}
228228
changeDoc doc [change]
229229
-- Now no errors.
230230
expectDiagnostics [("Foo.hs", [])]

ghcide/test/exe/DependentFileTest.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11

2-
{-# LANGUAGE GADTs #-}
3-
{-# LANGUAGE OverloadedLabels #-}
2+
{-# LANGUAGE GADTs #-}
43

54
module DependentFileTest (tests) where
65

76
import Control.Monad.IO.Class (liftIO)
8-
import Data.Row
97
import qualified Data.Text as T
108
import Development.IDE.Test (expectDiagnostics)
119
import Development.IDE.Types.Location
@@ -51,8 +49,10 @@ tests = testGroup "addDependentFile"
5149
[FileEvent (filePathToUri "dep-file.txt") FileChangeType_Changed ]
5250

5351
-- Modifying Baz will now trigger Foo to be rebuilt as well
54-
let change = TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 2 0) (Position 2 6)
55-
.+ #rangeLength .== Nothing
56-
.+ #text .== "f = ()"
52+
let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
53+
{ _range = Range (Position 2 0) (Position 2 6)
54+
, _rangeLength = Nothing
55+
, _text = "f = ()"
56+
}
5757
changeDoc doc [change]
5858
expectDiagnostics [("Foo.hs", [])]

ghcide/test/exe/DiagnosticTests.hs

+38-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
{-# LANGUAGE GADTs #-}
3-
{-# LANGUAGE OverloadedLabels #-}
2+
{-# LANGUAGE GADTs #-}
43

54
module DiagnosticTests (tests) where
65

@@ -9,7 +8,6 @@ import qualified Control.Lens as Lens
98
import Control.Monad
109
import Control.Monad.IO.Class (liftIO)
1110
import Data.List.Extra
12-
import Data.Row
1311
import qualified Data.Text as T
1412
import Development.IDE.GHC.Compat (GhcVersion (..), ghcVersion)
1513
import Development.IDE.GHC.Util
@@ -46,28 +44,34 @@ tests = testGroup "diagnostics"
4644
let content = T.unlines [ "module Testing wher" ]
4745
doc <- createDoc "Testing.hs" "haskell" content
4846
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error")])]
49-
let change = TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 0 15) (Position 0 19)
50-
.+ #rangeLength .== Nothing
51-
.+ #text .== "where"
47+
let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
48+
{ _range = Range (Position 0 15) (Position 0 19)
49+
, _rangeLength = Nothing
50+
, _text = "where"
51+
}
5252
changeDoc doc [change]
5353
expectDiagnostics [("Testing.hs", [])]
5454
, testSessionWait "introduce syntax error" $ do
5555
let content = T.unlines [ "module Testing where" ]
5656
doc <- createDoc "Testing.hs" "haskell" content
5757
void $ skipManyTill anyMessage (message SMethod_WindowWorkDoneProgressCreate)
5858
waitForProgressBegin
59-
let change = TextDocumentContentChangeEvent$ InL $ #range .== Range (Position 0 15) (Position 0 18)
60-
.+ #rangeLength .== Nothing
61-
.+ #text .== "wher"
59+
let change = TextDocumentContentChangeEvent$ InL TextDocumentContentChangePartial
60+
{ _range = Range (Position 0 15) (Position 0 18)
61+
, _rangeLength = Nothing
62+
, _text = "wher"
63+
}
6264
changeDoc doc [change]
6365
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error")])]
6466
, testSessionWait "update syntax error" $ do
6567
let content = T.unlines [ "module Testing(missing) where" ]
6668
doc <- createDoc "Testing.hs" "haskell" content
6769
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'missing'")])]
68-
let change = TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 0 15) (Position 0 16)
69-
.+ #rangeLength .== Nothing
70-
.+ #text .== "l"
70+
let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
71+
{ _range = Range (Position 0 15) (Position 0 16)
72+
, _rangeLength = Nothing
73+
, _text = "l"
74+
}
7175
changeDoc doc [change]
7276
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'lissing'")])]
7377
, testSessionWait "variable not in scope" $ do
@@ -143,9 +147,11 @@ tests = testGroup "diagnostics"
143147
, "import ModuleA"
144148
]
145149
_ <- createDoc "ModuleB.hs" "haskell" contentB
146-
let change = TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 0 0) (Position 0 20)
147-
.+ #rangeLength .== Nothing
148-
.+ #text .== ""
150+
let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
151+
{ _range = Range (Position 0 0) (Position 0 20)
152+
, _rangeLength = Nothing
153+
, _text = ""
154+
}
149155
changeDoc docA [change]
150156
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Error, (1, 0), "Could not find module")])]
151157
, testSessionWait "add missing module" $ do
@@ -397,7 +403,7 @@ tests = testGroup "diagnostics"
397403
-- Check that if we put a lower-case drive in for A.A
398404
-- the diagnostics for A.B will also be lower-case.
399405
liftIO $ fileUri @?= uriB
400-
let msg :: T.Text = (head diags) ^. L.message
406+
let msg :: T.Text = head diags ^. L.message
401407
liftIO $ unless ("redundant" `T.isInfixOf` msg) $
402408
assertFailure ("Expected redundant import but got " <> T.unpack msg)
403409
closeDoc a
@@ -463,15 +469,15 @@ tests = testGroup "diagnostics"
463469
[("P.hs", [(DiagnosticSeverity_Warning,(4,0), "Top-level binding")])] -- So that we know P has been loaded
464470

465471
-- Change y from Int to B which introduces a type error in A (imported from P)
466-
changeDoc bdoc [TextDocumentContentChangeEvent . InR . (.==) #text $
472+
changeDoc bdoc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $
467473
T.unlines ["module B where", "y :: Bool", "y = undefined"]]
468474
expectDiagnostics
469475
[("A.hs", [(DiagnosticSeverity_Error, (5, 4), "Couldn't match expected type 'Int' with actual type 'Bool'")])
470476
]
471477

472478
-- Open A and edit to fix the type error
473479
adoc <- createDoc aPath "haskell" aSource
474-
changeDoc adoc [TextDocumentContentChangeEvent . InR . (.==) #text $
480+
changeDoc adoc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $
475481
T.unlines ["module A where", "import B", "x :: Bool", "x = y"]]
476482

477483
expectDiagnostics
@@ -489,10 +495,10 @@ tests = testGroup "diagnostics"
489495
doc <- createDoc "Foo.hs" "haskell" fooContent
490496
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (1,7), "Could not find module 'MissingModule'")])]
491497

492-
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) #text $ "module Foo() where" ]
498+
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ "module Foo() where" ]
493499
expectDiagnostics []
494500

495-
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) #text $ T.unlines
501+
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ T.unlines
496502
[ "module Foo() where" , "import MissingModule" ] ]
497503
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (1,7), "Could not find module 'MissingModule'")])]
498504

@@ -504,12 +510,18 @@ tests = testGroup "diagnostics"
504510
]
505511
where
506512
editPair x y = let p = Position x y ; p' = Position x (y+2) in
507-
(TextDocumentContentChangeEvent $ InL $ #range .== Range p p
508-
.+ #rangeLength .== Nothing
509-
.+ #text .== "fd"
510-
,TextDocumentContentChangeEvent $ InL $ #range .== Range p p'
511-
.+ #rangeLength .== Nothing
512-
.+ #text .== "")
513+
(TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
514+
{ _range = Range p p
515+
, _rangeLength = Nothing
516+
, _text = "fd"
517+
}
518+
519+
,TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
520+
{ _range = Range p' p'
521+
, _rangeLength = Nothing
522+
, _text = ""
523+
}
524+
)
513525
editHeader = editPair 0 0
514526
editImport = editPair 2 10
515527
editBody = editPair 3 10

0 commit comments

Comments
 (0)