Skip to content

Commit ad0a154

Browse files
authored
Upgrade to lsp-1.0 (#1284)
* WIP integrate haskell-lsp-1.0.0.0 some progress Mostly everything except LanguageServer.hs make it compile make it work fix benchmarks update tweaks fix configuration and tests simplify handlers Update to renamed lsp/lsp-types modules redo plugin api and get library to compile fill in some missing details fix main fix rebase * handle executeCommand and codeaction compat * switch back to text * make ghcide tests compile * non-formatting plugins * simplify plugin api * port default plugins * fix hls tests * review comments * more fixes * more fixes * Fix more tests * cleanup * fix cabal.project * restore telemetry * don't wait for progress response * warnings and hlint * rebase fixes * rebase fixes * more warnings * hlint * warnings * more warnings * fix benchmarks * lsp from hackage * more stack * more stack * more stack * more stack * more stack * more stack * more stack
1 parent 57b78e7 commit ad0a154

File tree

120 files changed

+2107
-2491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2107
-2491
lines changed

cabal.project

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ packages:
1212
./plugins/hls-retrie-plugin
1313
./plugins/hls-haddock-comments-plugin
1414
./plugins/hls-splice-plugin
15-
1615
tests: true
1716

1817
package *
@@ -25,7 +24,7 @@ package ghcide
2524

2625
write-ghc-environment-files: never
2726

28-
index-state: 2021-02-08T19:11:03Z
27+
index-state: 2021-02-15T19:11:03Z
2928

3029
allow-newer:
3130
active:base,

ghcide/.hlint.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
- default: false
9999
- {name: [-Wno-missing-signatures, -Wno-orphans, -Wno-overlapping-patterns, -Wno-incomplete-patterns, -Wno-missing-fields, -Wno-unused-matches]}
100100
- {name: [-Wno-dodgy-imports,-Wno-incomplete-uni-patterns], within: [Main, Development.IDE.GHC.Compat, Development.Benchmark.Rules]}
101+
- {name: [-Wno-deprecations, -Wno-unticked-promoted-constructors], within: [Main, Experiments]}
101102
# - modules:
102103
# - {name: [Data.Set, Data.HashSet], as: Set} # if you import Data.Set qualified, it must be as 'Set'
103104
# - {name: Control.Arrow, within: []} # Certain modules are banned entirely

ghcide/bench/lib/Experiments.hs

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{-# LANGUAGE ConstraintKinds #-}
2+
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE ExistentialQuantification #-}
34
{-# LANGUAGE ImplicitParams #-}
45
{-# LANGUAGE ImpredicativeTypes #-}
6+
{-# OPTIONS_GHC -Wno-deprecations -Wno-unticked-promoted-constructors #-}
57

68
module Experiments
79
( Bench(..)
@@ -23,16 +25,16 @@ import Control.Applicative.Combinators (skipManyTill)
2325
import Control.Exception.Safe (IOException, handleAny, try)
2426
import Control.Monad.Extra
2527
import Control.Monad.IO.Class
26-
import Data.Aeson (Value(Null))
28+
import Data.Aeson (Value(Null), toJSON)
2729
import Data.List
2830
import Data.Maybe
2931
import qualified Data.Text as T
3032
import Data.Version
3133
import Development.IDE.Plugin.Test
3234
import Experiments.Types
33-
import Language.Haskell.LSP.Test
34-
import Language.Haskell.LSP.Types
35-
import Language.Haskell.LSP.Types.Capabilities
35+
import Language.LSP.Test
36+
import Language.LSP.Types
37+
import Language.LSP.Types.Capabilities
3638
import Numeric.Natural
3739
import Options.Applicative
3840
import System.Directory
@@ -79,13 +81,13 @@ experiments =
7981
isJust <$> getHover doc (fromJust identifierP),
8082
---------------------------------------------------------------------------------------
8183
bench "getDefinition" $ allWithIdentifierPos $ \DocumentPositions{..} ->
82-
not . null <$> getDefinitions doc (fromJust identifierP),
84+
either (not . null) (not . null) . toEither <$> getDefinitions doc (fromJust identifierP),
8385
---------------------------------------------------------------------------------------
8486
bench "getDefinition after edit" $ \docs -> do
8587
forM_ docs $ \DocumentPositions{..} ->
8688
changeDoc doc [charEdit stringLiteralP]
8789
flip allWithIdentifierPos docs $ \DocumentPositions{..} ->
88-
not . null <$> getDefinitions doc (fromJust identifierP),
90+
either (not . null) (not . null) . toEither <$> getDefinitions doc (fromJust identifierP),
8991
---------------------------------------------------------------------------------------
9092
bench "documentSymbols" $ allM $ \DocumentPositions{..} -> do
9193
fmap (either (not . null) (not . null)) . getDocumentSymbols $ doc,
@@ -148,7 +150,7 @@ experiments =
148150
( \docs -> do
149151
Just hieYaml <- uriToFilePath <$> getDocUri "hie.yaml"
150152
liftIO $ appendFile hieYaml "##\n"
151-
sendNotification WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
153+
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
152154
List [ FileEvent (filePathToUri "hie.yaml") FcChanged ]
153155
forM_ docs $ \DocumentPositions{..} ->
154156
changeDoc doc [charEdit stringLiteralP]
@@ -163,7 +165,7 @@ experiments =
163165
(\docs -> do
164166
Just hieYaml <- uriToFilePath <$> getDocUri "hie.yaml"
165167
liftIO $ appendFile hieYaml "##\n"
166-
sendNotification WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
168+
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
167169
List [ FileEvent (filePathToUri "hie.yaml") FcChanged ]
168170
flip allWithIdentifierPos docs $ \DocumentPositions{..} -> isJust <$> getHover doc (fromJust identifierP)
169171
)
@@ -359,7 +361,9 @@ waitForProgressDone :: Session ()
359361
waitForProgressDone = loop
360362
where
361363
loop = do
362-
void (skipManyTill anyMessage message :: Session WorkDoneProgressEndNotification)
364+
~() <- skipManyTill anyMessage $ satisfyMaybe $ \case
365+
FromServerMess SProgress (NotificationMessage _ _ (ProgressParams _ (End _))) -> Just ()
366+
_ -> Nothing
363367
done <- null <$> getIncompleteProgressSessions
364368
unless done loop
365369

@@ -393,8 +397,9 @@ runBench runSess b = handleAny (\e -> print e >> return badRun)
393397
else do
394398
output (showDuration t)
395399
-- Wait for the delayed actions to finish
396-
waitId <- sendRequest (CustomClientMethod "test") WaitForShakeQueue
397-
(td, resp) <- duration $ skipManyTill anyMessage $ responseForId waitId
400+
let m = SCustomMethod "test"
401+
waitId <- sendRequest m (toJSON WaitForShakeQueue)
402+
(td, resp) <- duration $ skipManyTill anyMessage $ responseForId m waitId
398403
case resp of
399404
ResponseMessage{_result=Right Null} -> do
400405
loop (userWaits+t) (delayedWork+td) (n -1)
@@ -562,7 +567,7 @@ searchSymbol doc@TextDocumentIdentifier{_uri} fileContents pos = do
562567
checkDefinitions pos = do
563568
defs <- getDefinitions doc pos
564569
case defs of
565-
[Location uri _] -> return $ uri /= _uri
570+
(InL [Location uri _]) -> return $ uri /= _uri
566571
_ -> return False
567572
checkCompletions pos =
568573
not . null <$> getCompletions doc pos

ghcide/exe/Main.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ main = do
112112
, optOTMemoryProfiling = IdeOTMemoryProfiling argsOTMemoryProfiling
113113
, optTesting = IdeTesting argsTesting
114114
, optShakeOptions = (optShakeOptions defOptions){shakeThreads = argsThreads}
115-
, optCheckParents = checkParents config
116-
, optCheckProject = checkProject config
115+
, optCheckParents = pure $ checkParents config
116+
, optCheckProject = pure $ checkProject config
117117
}
118118
}
119119

ghcide/ghcide.cabal

+18-13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ library
4646
data-default,
4747
deepseq,
4848
directory,
49+
dependent-map,
50+
dependent-sum,
4951
dlist,
5052
extra >= 1.7.4,
5153
fuzzy,
@@ -55,12 +57,12 @@ library
5557
Glob,
5658
haddock-library >= 1.8,
5759
hashable,
58-
haskell-lsp-types == 0.23.*,
59-
haskell-lsp == 0.23.*,
6060
hie-compat,
6161
hls-plugin-api >= 0.7.1,
6262
lens,
6363
hiedb == 0.3.0.1,
64+
lsp-types == 1.1.*,
65+
lsp == 1.1.*,
6466
mtl,
6567
network-uri,
6668
parallel,
@@ -88,7 +90,9 @@ library
8890
vector,
8991
bytestring-encoding,
9092
opentelemetry >=0.6.1,
91-
heapsize ==0.3.*
93+
heapsize ==0.3.*,
94+
unliftio,
95+
unliftio-core
9296
if flag(ghc-lib)
9397
build-depends:
9498
ghc-lib >= 8.8,
@@ -131,6 +135,9 @@ library
131135
TupleSections
132136
TypeApplications
133137
ViewPatterns
138+
DataKinds
139+
TypeOperators
140+
KindSignatures
134141

135142
hs-source-dirs:
136143
src
@@ -160,7 +167,6 @@ library
160167
Development.IDE.LSP.HoverDefinition
161168
Development.IDE.LSP.LanguageServer
162169
Development.IDE.LSP.Outline
163-
Development.IDE.LSP.Protocol
164170
Development.IDE.LSP.Server
165171
Development.IDE.Spans.Common
166172
Development.IDE.Spans.Documentation
@@ -205,9 +211,8 @@ library
205211
Development.IDE.LSP.Notifications
206212
Development.IDE.Plugin.CodeAction.PositionIndexed
207213
Development.IDE.Plugin.Completions.Logic
208-
Development.IDE.Plugin.HLS.Formatter
209214
Development.IDE.Types.Action
210-
ghc-options: -Wall -Wno-name-shadowing -Wincomplete-uni-patterns
215+
ghc-options: -Wall -Wno-name-shadowing -Wincomplete-uni-patterns -Wno-unticked-promoted-constructors
211216

212217
executable ghcide-test-preprocessor
213218
default-language: Haskell2010
@@ -285,8 +290,8 @@ executable ghcide
285290
safe-exceptions,
286291
ghc,
287292
hashable,
288-
haskell-lsp,
289-
haskell-lsp-types,
293+
lsp,
294+
lsp-types,
290295
heapsize,
291296
hie-bios,
292297
hls-plugin-api,
@@ -346,12 +351,12 @@ test-suite ghcide-tests
346351
ghcide,
347352
ghc-typelits-knownnat,
348353
haddock-library,
349-
haskell-lsp,
350-
haskell-lsp-types,
354+
lsp,
355+
lsp-types,
351356
hls-plugin-api,
352357
network-uri,
353358
lens,
354-
lsp-test >= 0.12.0.0 && < 0.13,
359+
lsp-test == 0.13.0.0,
355360
optparse-applicative,
356361
process,
357362
QuickCheck,
@@ -372,7 +377,7 @@ test-suite ghcide-tests
372377
record-hasfield
373378
hs-source-dirs: test/cabal test/exe test/src bench/lib
374379
include-dirs: include
375-
ghc-options: -threaded -Wall -Wno-name-shadowing -O0
380+
ghc-options: -threaded -Wall -Wno-name-shadowing -O0 -Wno-unticked-promoted-constructors
376381
main-is: Main.hs
377382
other-modules:
378383
Development.IDE.Test
@@ -408,7 +413,7 @@ executable ghcide-bench
408413
extra,
409414
filepath,
410415
ghcide,
411-
lsp-test >= 0.12.0.0 && < 0.13,
416+
lsp-test == 0.13.0.0,
412417
optparse-applicative,
413418
process,
414419
safe-exceptions,

ghcide/session-loader/Development/IDE/Session.hs

+17-28
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ import qualified HIE.Bios as HieBios
6060
import HIE.Bios.Environment hiding (getCacheDir)
6161
import HIE.Bios.Types
6262
import Hie.Implicit.Cradle (loadImplicitHieCradle)
63-
import Language.Haskell.LSP.Core
64-
import Language.Haskell.LSP.Messages
65-
import Language.Haskell.LSP.Types
63+
import Language.LSP.Server
64+
import Language.LSP.Types
6665
import System.Directory
6766
import qualified System.Directory.Extra as IO
6867
import System.FilePath
@@ -208,12 +207,11 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
208207
runningCradle <- newVar dummyAs :: IO (Var (Async (IdeResult HscEnvEq,[FilePath])))
209208

210209
return $ do
211-
extras@ShakeExtras{logger, eventer, restartShakeSession,
212-
withIndefiniteProgress, ideNc, knownTargetsVar
210+
extras@ShakeExtras{logger, restartShakeSession, ideNc, knownTargetsVar, lspEnv
213211
} <- getShakeExtras
214212

215213
IdeOptions{ optTesting = IdeTesting optTesting
216-
, optCheckProject = checkProject
214+
, optCheckProject = getCheckProject
217215
, optCustomDynFlags
218216
, optExtensions
219217
} <- getIdeOptions
@@ -358,6 +356,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
358356
restartShakeSession []
359357

360358
-- Typecheck all files in the project on startup
359+
checkProject <- getCheckProject
361360
unless (null cs || not checkProject) $ do
362361
cfps' <- liftIO $ filterM (IO.doesFileExist . fromNormalizedFilePath) (concatMap targetLocations cs)
363362
void $ shakeEnqueue extras $ mkDelayedAction "InitialLoad" Debug $ void $ do
@@ -376,17 +375,19 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
376375
lfp <- flip makeRelative cfp <$> getCurrentDirectory
377376
logInfo logger $ T.pack ("Consulting the cradle for " <> show lfp)
378377

379-
when (isNothing hieYaml) $ eventer $ notifyUserImplicitCradle lfp
378+
when (isNothing hieYaml) $ mRunLspT lspEnv $
379+
sendNotification SWindowShowMessage $ notifyUserImplicitCradle lfp
380380

381381
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
382382

383-
when optTesting $ eventer $ notifyCradleLoaded lfp
383+
when optTesting $ mRunLspT lspEnv $
384+
sendNotification (SCustomMethod "ghcide/cradle/loaded") (toJSON cfp)
384385

385386
-- Display a user friendly progress message here: They probably don't know what a cradle is
386387
let progMsg = "Setting up " <> T.pack (takeBaseName (cradleRootDir cradle))
387388
<> " (for " <> T.pack lfp <> ")"
388-
eopts <- withIndefiniteProgress progMsg NotCancellable $
389-
cradleToOptsAndLibDir cradle cfp
389+
eopts <- mRunLspTCallback lspEnv (withIndefiniteProgress progMsg NotCancellable) $
390+
cradleToOptsAndLibDir cradle cfp
390391

391392
logDebug logger $ T.pack ("Session loading result: " <> show eopts)
392393
case eopts of
@@ -796,24 +797,12 @@ getCacheDirsDefault prefix opts = do
796797
cacheDir :: String
797798
cacheDir = "ghcide"
798799

799-
notifyUserImplicitCradle:: FilePath -> FromServerMessage
800-
notifyUserImplicitCradle fp =
801-
NotShowMessage $
802-
NotificationMessage "2.0" WindowShowMessage $ ShowMessageParams MtInfo $
803-
"No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for "
804-
<> T.pack fp <>
805-
".\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).\n" <>
806-
"You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error."
807-
808-
notifyCradleLoaded :: FilePath -> FromServerMessage
809-
notifyCradleLoaded fp =
810-
NotCustomServer $
811-
NotificationMessage "2.0" (CustomServerMethod cradleLoadedMethod) $
812-
toJSON fp
813-
814-
cradleLoadedMethod :: T.Text
815-
cradleLoadedMethod = "ghcide/cradle/loaded"
816-
800+
notifyUserImplicitCradle:: FilePath -> ShowMessageParams
801+
notifyUserImplicitCradle fp =ShowMessageParams MtWarning $
802+
"No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for "
803+
<> T.pack fp <>
804+
".\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).\n"<>
805+
"You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error."
817806
----------------------------------------------------------------------------------------------------
818807

819808
data PackageSetupException

0 commit comments

Comments
 (0)