Skip to content

Upgrade to latest lsp / lsp-types / lsp-test #4166

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

Merged
merged 5 commits into from
Apr 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
./hls-plugin-api
./hls-test-utils

index-state: 2024-04-23T12:00:00Z
index-state: 2024-04-30T10:44:19Z

tests: True
test-show-details: direct
Expand Down
54 changes: 32 additions & 22 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,7 +42,6 @@
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
Expand Down Expand Up @@ -71,15 +69,19 @@

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 @@ -240,9 +242,11 @@
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 @@ -270,9 +274,11 @@
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 @@ -295,9 +301,11 @@
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 @@ -334,7 +342,7 @@
examplesPath = "bench/example"

defConfig :: Config
Success defConfig = execParserPure defaultPrefs (info configP fullDesc) []

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / bench_init (9.6, ubuntu-latest)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

Pattern match(es) are non-exhaustive

Check warning on line 345 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

Pattern match(es) are non-exhaustive

quiet, verbose :: Config -> Bool
verbose = (== All) . verbosity
Expand Down Expand Up @@ -442,7 +450,7 @@
results <- forM benchmarks $ \b@Bench{name} -> do
let p = (proc (ghcide ?config) (allArgs name dir))
{ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
run sess = withCreateProcess p $ \(Just inH) (Just outH) (Just errH) pH -> do

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

Pattern match(es) are non-exhaustive

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

Pattern match(es) are non-exhaustive

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / bench_init (9.6, ubuntu-latest)

Pattern match(es) are non-exhaustive

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

Pattern match(es) are non-exhaustive

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

Pattern match(es) are non-exhaustive

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

Pattern match(es) are non-exhaustive

Check warning on line 453 in ghcide-bench/src/Experiments.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

Pattern match(es) are non-exhaustive
-- Need to continuously consume to stderr else it gets blocked
-- Can't pass NoStream either to std_err
hSetBuffering errH NoBuffering
Expand Down Expand Up @@ -551,7 +559,7 @@
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 @@ -755,10 +763,12 @@

-- 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
4 changes: 2 additions & 2 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ library
, implicit-hie >= 0.1.4.0 && < 0.1.5
, lens
, list-t
, lsp ^>=2.4.0.0
, lsp-types ^>=2.1.0.0
, lsp ^>=2.5.0.0
, lsp-types ^>=2.2.0.0
, mtl
, opentelemetry >=0.6.1
, optparse-applicative
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
3 changes: 1 addition & 2 deletions ghcide/test/exe/CompletionTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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.Types.Location
Expand Down Expand Up @@ -205,7 +204,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,12 +1,10 @@

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

module DependentFileTest (tests) where

import Config
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 @@ -52,8 +50,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