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

Test lsp-test setIgnoreProgressNotifications #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ constraints:
-- We want to be able to benefit from the performance optimisations
-- in the future, thus: TODO: remove this flag.
bitvec -simd

source-repository-package
type:git
location: https://github.com/jhrcek/lsp
tag: 618e5d5955595518b85cf7234f8bb8fe994fab92
subdir: lsp
subdir: lsp-test
subdir: lsp-types
56 changes: 33 additions & 23 deletions ghcide-bench/src/Experiments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-deprecations -Wno-unticked-promoted-constructors #-}

Expand Down Expand Up @@ -43,13 +42,12 @@ import Data.Either (fromRight)
import Data.List
import Data.Maybe
import Data.Proxy
import Data.Row hiding (switch)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Version
import Development.IDE.Plugin.Test
import Development.IDE.Test.Diagnostic
import Development.Shake (CmdOption (Cwd, FileStdout),
import Development.Shake (CmdOption (Cwd),
cmd_)
import Experiments.Types
import Language.LSP.Protocol.Capabilities
Expand All @@ -72,15 +70,19 @@ import Text.Printf

charEdit :: Position -> TextDocumentContentChangeEvent
charEdit p =
TextDocumentContentChangeEvent $ InL $ #range .== Range p p
.+ #rangeLength .== Nothing
.+ #text .== "a"
TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range p p
, _rangeLength = Nothing
, _text = "a"
}

headerEdit :: TextDocumentContentChangeEvent
headerEdit =
TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 0 0) (Position 0 0)
.+ #rangeLength .== Nothing
.+ #text .== "-- header comment \n"
TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range (Position 0 0) (Position 0 0)
, _rangeLength = Nothing
, _text = "-- header comment \n"
}

data DocumentPositions = DocumentPositions {
-- | A position that can be used to generate non null goto-def and completion responses
Expand Down Expand Up @@ -241,9 +243,11 @@ experiments =
benchWithSetup
"hole fit suggestions"
( mapM_ $ \DocumentPositions{..} -> do
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
.+ #rangeLength .== Nothing
.+ #text .== t
let edit = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range bottom bottom
, _rangeLength = Nothing
, _text = t
}
bottom = Position maxBound 0
t = T.unlines
[""
Expand Down Expand Up @@ -271,9 +275,11 @@ experiments =
benchWithSetup
"eval execute single-line code lens"
( mapM_ $ \DocumentPositions{..} -> do
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
.+ #rangeLength .== Nothing
.+ #text .== t
let edit = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range bottom bottom
, _rangeLength = Nothing
, _text = t
}
bottom = Position maxBound 0
t = T.unlines
[ ""
Expand All @@ -296,9 +302,11 @@ experiments =
benchWithSetup
"eval execute multi-line code lens"
( mapM_ $ \DocumentPositions{..} -> do
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
.+ #rangeLength .== Nothing
.+ #text .== t
let edit = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range bottom bottom
, _rangeLength = Nothing
, _text = t
}
bottom = Position maxBound 0
t = T.unlines
[ ""
Expand Down Expand Up @@ -552,7 +560,7 @@ runBenchmarksFun dir allBenchmarks = do
lspTestCaps =
fullCaps
& (L.window . _Just) .~ WindowClientCapabilities (Just True) Nothing Nothing
& (L.textDocument . _Just . L.codeAction . _Just . L.resolveSupport . _Just) .~ (#properties .== ["edit"])
& (L.textDocument . _Just . L.codeAction . _Just . L.resolveSupport . _Just) .~ (ClientCodeActionResolveOptions ["edit"])
& (L.textDocument . _Just . L.codeAction . _Just . L.dataSupport . _Just) .~ True

showMs :: Seconds -> String
Expand Down Expand Up @@ -756,10 +764,12 @@ setupDocumentContents config =

-- Setup the special positions used by the experiments
lastLine <- fromIntegral . length . T.lines <$> documentContents doc
changeDoc doc [TextDocumentContentChangeEvent $ InL
$ #range .== Range (Position lastLine 0) (Position lastLine 0)
.+ #rangeLength .== Nothing
.+ #text .== T.unlines [ "_hygienic = \"hygienic\"" ]]
changeDoc doc [TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range (Position lastLine 0) (Position lastLine 0)
, _rangeLength = Nothing
, _text = T.unlines [ "_hygienic = \"hygienic\"" ]
}
]
let
-- Points to a string in the target file,
-- convenient for hygienic edits
Expand Down
1 change: 0 additions & 1 deletion ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ test-suite ghcide-tests
, QuickCheck
, random
, regex-tdfa ^>=1.3.1
, row-types
, shake
, sqlite-simple
, stm
Expand Down
7 changes: 4 additions & 3 deletions ghcide/src/Development/IDE/Core/PositionMapping.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedLabels #-}
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
module Development.IDE.Core.PositionMapping
Expand All @@ -25,13 +24,15 @@ module Development.IDE.Core.PositionMapping
) where

import Control.DeepSeq
import Control.Lens ((^.))
import Control.Monad
import Data.Algorithm.Diff
import Data.Bifunctor
import Data.List
import Data.Row
import qualified Data.Text as T
import qualified Data.Vector.Unboxed as V
import qualified Language.LSP.Protocol.Lens as L
import Language.LSP.Protocol.Types (Position (Position),
Range (Range),
TextDocumentContentChangeEvent (TextDocumentContentChangeEvent),
Expand Down Expand Up @@ -131,8 +132,8 @@ addOldDelta delta (PositionMapping pm) = PositionMapping (composeDelta pm delta)
-- that was what was done with lsp* 1.6 packages
applyChange :: PositionDelta -> TextDocumentContentChangeEvent -> PositionDelta
applyChange PositionDelta{..} (TextDocumentContentChangeEvent (InL x)) = PositionDelta
{ toDelta = toCurrent (x .! #range) (x .! #text) <=< toDelta
, fromDelta = fromDelta <=< fromCurrent (x .! #range) (x .! #text)
{ toDelta = toCurrent (x ^. L.range) (x ^. L.text) <=< toDelta
, fromDelta = fromDelta <=< fromCurrent (x ^. L.range) (x ^. L.text)
}
applyChange posMapping _ = posMapping

Expand Down
3 changes: 1 addition & 2 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedLabels #-}

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

toggleAutoExtend :: CompletionsConfig -> CompItem -> CompItem
toggleAutoExtend CompletionsConfig{enableAutoExtend=False} x = x {additionalTextEdits = Nothing}
Expand Down
6 changes: 2 additions & 4 deletions ghcide/test/exe/CompletionTests.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE GADTs #-}

module CompletionTests (tests) where

Expand All @@ -11,7 +10,6 @@ import Control.Monad.IO.Class (liftIO)
import Data.Default
import Data.List.Extra
import Data.Maybe
import Data.Row
import qualified Data.Text as T
import Development.IDE.GHC.Compat (GhcVersion (..), ghcVersion)
import Development.IDE.Test (waitForTypecheck)
Expand Down Expand Up @@ -190,7 +188,7 @@ localCompletionTests = [
doc <- createDoc "A.hs" "haskell" $ src "AAA"
void $ waitForTypecheck doc
let editA rhs =
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) #text $ src rhs]
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ src rhs]
editA "AAAA"
void $ waitForTypecheck doc
editA "AAAAA"
Expand Down
14 changes: 7 additions & 7 deletions ghcide/test/exe/CradleTests.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE GADTs #-}

module CradleTests (tests) where

import Control.Applicative.Combinators
import Control.Monad.IO.Class (liftIO)
import Data.Row
import qualified Data.Text as T
import Development.IDE.GHC.Compat (GhcVersion (..))
import Development.IDE.GHC.Util
Expand Down Expand Up @@ -63,7 +61,7 @@ loadCradleOnlyonce = testGroup "load cradle only once"
doc <- createDoc "B.hs" "haskell" "module B where\nimport Data.Foo"
msgs <- someTill (skipManyTill anyMessage cradleLoadedMessage) (skipManyTill anyMessage (message SMethod_TextDocumentPublishDiagnostics))
liftIO $ length msgs @?= 1
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) #text $ "module B where\nimport Data.Maybe"]
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ "module B where\nimport Data.Maybe"]
msgs <- manyTill (skipManyTill anyMessage cradleLoadedMessage) (skipManyTill anyMessage (message SMethod_TextDocumentPublishDiagnostics))
liftIO $ length msgs @?= 0
_ <- createDoc "A.hs" "haskell" "module A where\nimport LoadCradleBar"
Expand Down Expand Up @@ -222,9 +220,11 @@ sessionDepsArePickedUp = testSession'
[FileEvent (filePathToUri $ dir </> "hie.yaml") FileChangeType_Changed ]
-- Send change event.
let change =
TextDocumentContentChangeEvent $ InL $ #range .== Range (Position 4 0) (Position 4 0)
.+ #rangeLength .== Nothing
.+ #text .== "\n"
TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
{ _range = Range (Position 4 0) (Position 4 0)
, _rangeLength = Nothing
, _text = "\n"
}
changeDoc doc [change]
-- Now no errors.
expectDiagnostics [("Foo.hs", [])]
Expand Down
12 changes: 6 additions & 6 deletions ghcide/test/exe/DependentFileTest.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE GADTs #-}

module DependentFileTest (tests) where

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

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