Skip to content

Commit 7d59f26

Browse files
authored
Merge pull request #478 from haskell/mpj/metamodel2
Generate types from the metamodel (attempt 2)
2 parents 7c1fcaa + 9590f48 commit 7d59f26

File tree

494 files changed

+39338
-8950
lines changed

Some content is hidden

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

494 files changed

+39338
-8950
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lsp-types/generated linguist-generated=true

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages:
66
package lsp
77
flags: +demo
88

9-
index-state: 2023-01-01T00:00:00Z
9+
index-state: 2023-05-18T00:00:00Z
1010

1111
tests: True
1212
benchmarks: True

lsp-test/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for lsp-test
22

3+
## 0.15.0.0
4+
5+
* Support `lsp-types-2.0.0.0` and `lsp-2.0.0.0`.
6+
37
## 0.14.1.0
48

59
* Compatibility with new `lsp-types` major version.

lsp-test/bench/SimpleBench.hs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
{-# LANGUAGE RankNTypes #-}
2-
{-# LANGUAGE GADTs, OverloadedStrings #-}
2+
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE DuplicateRecordFields #-}
35
module Main where
46

57
import Language.LSP.Server
68
import qualified Language.LSP.Test as Test
7-
import Language.LSP.Types
9+
import Language.LSP.Protocol.Types
10+
import Language.LSP.Protocol.Message
811
import Control.Monad.IO.Class
912
import Control.Monad
10-
import System.Process
13+
import System.Process hiding (env)
1114
import System.Environment
1215
import System.Time.Extra
1316
import Control.Concurrent
1417
import Data.IORef
1518

1619
handlers :: Handlers (LspM ())
1720
handlers = mconcat
18-
[ requestHandler STextDocumentHover $ \req responder -> do
19-
let RequestMessage _ _ _ (HoverParams _doc pos _workDone) = req
21+
[ requestHandler SMethod_TextDocumentHover $ \req responder -> do
22+
let TRequestMessage _ _ _ (HoverParams _doc pos _workDone) = req
2023
Position _l _c' = pos
2124
rsp = Hover ms (Just range)
22-
ms = HoverContents $ markedUpContent "lsp-demo-simple-server" "Hello world"
25+
ms = InL $ mkMarkdown "Hello world"
2326
range = Range pos pos
24-
responder (Right $ Just rsp)
25-
, requestHandler STextDocumentDefinition $ \req responder -> do
26-
let RequestMessage _ _ _ (DefinitionParams (TextDocumentIdentifier doc) pos _ _) = req
27-
responder (Right $ InL $ Location doc $ Range pos pos)
27+
responder (Right $ InL rsp)
28+
, requestHandler SMethod_TextDocumentDefinition $ \req responder -> do
29+
let TRequestMessage _ _ _ (DefinitionParams (TextDocumentIdentifier doc) pos _ _) = req
30+
responder (Right $ InL $ Definition $ InL $ Location doc $ Range pos pos)
2831
]
2932

3033
server :: ServerDefinition ()
@@ -44,19 +47,19 @@ main = do
4447

4548
n <- read . head <$> getArgs
4649

47-
forkIO $ void $ runServerWithHandles mempty mempty hinRead houtWrite server
50+
_ <- forkIO $ void $ runServerWithHandles mempty mempty hinRead houtWrite server
4851
liftIO $ putStrLn $ "Starting " <> show n <> " rounds"
4952

50-
i <- newIORef 0
53+
i <- newIORef (0 :: Integer)
5154

5255
Test.runSessionWithHandles hinWrite houtRead Test.defaultConfig Test.fullCaps "." $ do
5356
start <- liftIO offsetTime
5457
replicateM_ n $ do
55-
n <- liftIO $ readIORef i
56-
liftIO $ when (n `mod` 1000 == 0) $ putStrLn $ show n
57-
ResponseMessage{_result=Right (Just _)} <- Test.request STextDocumentHover $
58+
v <- liftIO $ readIORef i
59+
liftIO $ when (v `mod` 1000 == 0) $ putStrLn $ show v
60+
TResponseMessage{_result=Right (InL _)} <- Test.request SMethod_TextDocumentHover $
5861
HoverParams (TextDocumentIdentifier $ Uri "test") (Position 1 100) Nothing
59-
ResponseMessage{_result=Right (InL _)} <- Test.request STextDocumentDefinition $
62+
TResponseMessage{_result=Right (InL _)} <- Test.request SMethod_TextDocumentDefinition $
6063
DefinitionParams (TextDocumentIdentifier $ Uri "test") (Position 1000 100) Nothing Nothing
6164

6265
liftIO $ modifyIORef' i (+1)

lsp-test/example/Test.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import Control.Applicative.Combinators
33
import Control.Monad.IO.Class
44
import Language.LSP.Test
5-
import Language.LSP.Types
5+
import Language.LSP.Protocol.Types
6+
import Language.LSP.Protocol.Message
67

78
main = runSession "lsp-demo-reactor-server" fullCaps "test/data/" $ do
89
doc <- openDoc "Rename.hs" "haskell"
@@ -11,7 +12,7 @@ main = runSession "lsp-demo-reactor-server" fullCaps "test/data/" $ do
1112
skipManyTill loggingNotification (count 1 publishDiagnosticsNotification)
1213

1314
-- Send requests and notifications and receive responses
14-
rsp <- request STextDocumentDocumentSymbol $
15+
rsp <- request SMethod_TextDocumentDocumentSymbol $
1516
DocumentSymbolParams Nothing Nothing doc
1617
liftIO $ print rsp
1718

lsp-test/func-test/FuncTest.hs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ module Main where
44

55
import Language.LSP.Server
66
import qualified Language.LSP.Test as Test
7-
import Language.LSP.Types
8-
import Language.LSP.Types.Lens hiding (options)
7+
import Language.LSP.Protocol.Types
8+
import qualified Language.LSP.Protocol.Lens as L
9+
import Language.LSP.Protocol.Message
910
import Control.Monad.IO.Class
1011
import System.IO
1112
import Control.Monad
@@ -41,7 +42,7 @@ main = hspec $ do
4142

4243
handlers :: MVar () -> Handlers (LspM ())
4344
handlers killVar =
44-
notificationHandler SInitialized $ \noti -> do
45+
notificationHandler SMethod_Initialized $ \noti -> do
4546
tid <- withRunInIO $ \runInIO ->
4647
forkIO $ runInIO $
4748
withProgress "Doing something" NotCancellable $ \updater ->
@@ -55,20 +56,16 @@ main = hspec $ do
5556
Test.runSessionWithHandles hinWrite houtRead Test.defaultConfig Test.fullCaps "." $ do
5657
-- First make sure that we get a $/progress begin notification
5758
skipManyTill Test.anyMessage $ do
58-
x <- Test.message SProgress
59-
let isBegin (Begin _) = True
60-
isBegin _ = False
61-
guard $ isBegin $ x ^. params . value
59+
x <- Test.message SMethod_Progress
60+
guard $ has (L.params . L.value . _workDoneProgressBegin) x
6261

6362
-- Then kill the thread
6463
liftIO $ putMVar killVar ()
6564

6665
-- Then make sure we still get a $/progress end notification
6766
skipManyTill Test.anyMessage $ do
68-
x <- Test.message SProgress
69-
let isEnd (End _) = True
70-
isEnd _ = False
71-
guard $ isEnd $ x ^. params . value
67+
x <- Test.message SMethod_Progress
68+
guard $ has (L.params . L.value . _workDoneProgressEnd) x
7269

7370
describe "workspace folders" $
7471
it "keeps track of open workspace folders" $ do
@@ -77,9 +74,9 @@ main = hspec $ do
7774

7875
countVar <- newMVar 0
7976

80-
let wf0 = WorkspaceFolder "one" "Starter workspace"
81-
wf1 = WorkspaceFolder "/foo/bar" "My workspace"
82-
wf2 = WorkspaceFolder "/foo/baz" "My other workspace"
77+
let wf0 = WorkspaceFolder (filePathToUri "one") "Starter workspace"
78+
wf1 = WorkspaceFolder (filePathToUri "/foo/bar") "My workspace"
79+
wf2 = WorkspaceFolder (filePathToUri "/foo/baz") "My other workspace"
8380

8481
definition = ServerDefinition
8582
{ onConfigurationChange = const $ const $ Right ()
@@ -92,10 +89,10 @@ main = hspec $ do
9289

9390
handlers :: Handlers (LspM ())
9491
handlers = mconcat
95-
[ notificationHandler SInitialized $ \noti -> do
92+
[ notificationHandler SMethod_Initialized $ \noti -> do
9693
wfs <- fromJust <$> getWorkspaceFolders
9794
liftIO $ wfs `shouldContain` [wf0]
98-
, notificationHandler SWorkspaceDidChangeWorkspaceFolders $ \noti -> do
95+
, notificationHandler SMethod_WorkspaceDidChangeWorkspaceFolders $ \noti -> do
9996
i <- liftIO $ modifyMVar countVar (\i -> pure (i + 1, i))
10097
wfs <- fromJust <$> getWorkspaceFolders
10198
liftIO $ case i of
@@ -116,11 +113,9 @@ main = hspec $ do
116113
}
117114

118115
changeFolders add rmv =
119-
let addedFolders = List add
120-
removedFolders = List rmv
121-
ev = WorkspaceFoldersChangeEvent addedFolders removedFolders
116+
let ev = WorkspaceFoldersChangeEvent add rmv
122117
ps = DidChangeWorkspaceFoldersParams ev
123-
in Test.sendNotification SWorkspaceDidChangeWorkspaceFolders ps
118+
in Test.sendNotification SMethod_WorkspaceDidChangeWorkspaceFolders ps
124119

125120
Test.runSessionWithHandles hinWrite houtRead config Test.fullCaps "." $ do
126121
changeFolders [wf1] []

0 commit comments

Comments
 (0)