2
2
{-# LANGUAGE GADTs #-}
3
3
{-# LANGUAGE DuplicateRecordFields #-}
4
4
{-# LANGUAGE OverloadedStrings #-}
5
+ {-# LANGUAGE ScopedTypeVariables #-}
5
6
{-# LANGUAGE DeriveGeneric #-}
6
7
{-# LANGUAGE DeriveAnyClass #-}
7
8
@@ -132,11 +133,40 @@ main = hspec $ around withDummyServer $ do
132
133
in runSessionWithHandles hin hout def fullCaps " ." sesh
133
134
`shouldThrow` selector
134
135
135
- describe " text document VFS" $
136
+ describe " text document VFS" $ do
137
+ it " sends back didChange notifications (documentChanges)" $ \ (hin, hout) ->
138
+ runSessionWithHandles hin hout def fullCaps " ." $ do
139
+ doc <- openDoc " test/data/refactor/Main.hs" " haskell"
140
+ VersionedTextDocumentIdentifier _ beforeVersion <- getVersionedDoc doc
141
+
142
+ let args = toJSON (VersionedTextDocumentIdentifier (doc ^. uri) beforeVersion)
143
+ reqParams = ExecuteCommandParams Nothing " doAVersionedEdit" (Just (List [args]))
144
+
145
+ request_ SWorkspaceExecuteCommand reqParams
146
+
147
+ editReq <- message SWorkspaceApplyEdit
148
+ liftIO $ do
149
+ let Just (List [InL (TextDocumentEdit vdoc (List [InL edit_]))]) =
150
+ editReq ^. params . edit . documentChanges
151
+ vdoc `shouldBe` VersionedTextDocumentIdentifier (doc ^. uri) beforeVersion
152
+ edit_ `shouldBe` TextEdit (Range (Position 0 0 ) (Position 0 5 )) " howdy"
153
+
154
+ change <- customNotification " custom/textDocument/didChange"
155
+ let NotMess (NotificationMessage _ _ (c:: Value )) = change
156
+ Success (DidChangeTextDocumentParams reportedVDoc _edit) = fromJSON c
157
+ VersionedTextDocumentIdentifier _ reportedVersion = reportedVDoc
158
+
159
+ contents <- documentContents doc
160
+
161
+ liftIO $ contents `shouldBe` " howdy:: IO Int\n main = return (42)\n "
162
+ VersionedTextDocumentIdentifier _ afterVersion <- getVersionedDoc doc
163
+ liftIO $ afterVersion `shouldNotBe` beforeVersion
164
+
165
+ liftIO $ reportedVersion `shouldNotBe` beforeVersion
166
+
136
167
it " sends back didChange notifications" $ \ (hin, hout) ->
137
168
runSessionWithHandles hin hout def fullCaps " ." $ do
138
169
doc <- openDoc " test/data/refactor/Main.hs" " haskell"
139
- VersionedTextDocumentIdentifier _ (Just v) <- getVersionedDoc doc
140
170
141
171
let args = toJSON (doc ^. uri)
142
172
reqParams = ExecuteCommandParams Nothing " doAnEdit" (Just (List [args]))
@@ -150,8 +180,6 @@ main = hspec $ around withDummyServer $ do
150
180
es `shouldBe` [TextEdit (Range (Position 0 0 ) (Position 0 5 )) " howdy" ]
151
181
contents <- documentContents doc
152
182
153
- VersionedTextDocumentIdentifier _ (Just v') <- getVersionedDoc doc
154
- liftIO $ v' `shouldNotBe` v
155
183
liftIO $ contents `shouldBe` " howdy:: IO Int\n main = return (42)\n "
156
184
157
185
describe " getDocumentEdit" $
@@ -206,6 +234,7 @@ main = hspec $ around withDummyServer $ do
206
234
liftIO $ newVersion `shouldBe` oldVersion + 1
207
235
VersionedTextDocumentIdentifier _ (Just v) <- getVersionedDoc doc
208
236
liftIO $ v `shouldBe` oldVersion + 1
237
+
209
238
it " changes the document contents" $ \ (hin, hout) -> runSessionWithHandles hin hout def fullCaps " ." $ do
210
239
doc <- openDoc " test/data/renamePass/Desktop/simple.hs" " haskell"
211
240
let edit = TextEdit (Range (Position 0 0 ) (Position 0 2 )) " foo"
0 commit comments