@@ -17,9 +17,9 @@ extern crate json;
17
17
mod harness;
18
18
19
19
use analysis;
20
- use actions:: requests;
20
+ use actions:: { requests, notifications } ;
21
21
use config:: { Config , Inferrable } ;
22
- use server:: { self as ls_server, Request , ShutdownRequest } ;
22
+ use server:: { self as ls_server, Request , ShutdownRequest , Notification } ;
23
23
use jsonrpc_core;
24
24
use vfs;
25
25
@@ -90,6 +90,13 @@ pub fn request<'a, T: ls_server::RequestAction>(id: usize, params: T::Params) ->
90
90
}
91
91
}
92
92
93
+ fn notification < ' a , A : ls_server:: BlockingNotificationAction > ( params : A :: Params ) -> Notification < A > {
94
+ Notification {
95
+ params,
96
+ _action : PhantomData ,
97
+ }
98
+ }
99
+
93
100
#[ test]
94
101
fn test_shutdown ( ) {
95
102
let mut env = Environment :: new ( "common" ) ;
@@ -226,6 +233,118 @@ fn test_hover() {
226
233
) ;
227
234
}
228
235
236
+ /// Test hover continues to work after the source has moved line
237
+ #[ test]
238
+ fn test_hover_after_src_line_change ( ) {
239
+ let mut env = Environment :: new ( "common" ) ;
240
+
241
+ let source_file_path = Path :: new ( "src" ) . join ( "main.rs" ) ;
242
+
243
+ let root_path = env. cache . abs_path ( Path :: new ( "." ) ) ;
244
+ let url = Url :: from_file_path ( env. cache . abs_path ( & source_file_path) )
245
+ . expect ( "couldn't convert file path to URL" ) ;
246
+
247
+ let world_src_pos = env. cache . mk_ls_position ( src ( & source_file_path, 21 , "world" ) ) ;
248
+ let world_src_pos_after = Position {
249
+ line : world_src_pos. line + 1 ,
250
+ ..world_src_pos
251
+ } ;
252
+
253
+ let messages = vec ! [
254
+ initialize( 0 , root_path. as_os_str( ) . to_str( ) . map( |x| x. to_owned( ) ) ) . to_string( ) ,
255
+
256
+ request:: <requests:: Hover >(
257
+ 11 ,
258
+ TextDocumentPositionParams {
259
+ text_document: TextDocumentIdentifier :: new( url. clone( ) ) ,
260
+ position: world_src_pos,
261
+ } ,
262
+ ) . to_string( ) ,
263
+
264
+ notification:: <notifications:: DidChangeTextDocument >(
265
+ DidChangeTextDocumentParams {
266
+ text_document: VersionedTextDocumentIdentifier {
267
+ uri: url. clone( ) ,
268
+ version: Some ( 2 ) ,
269
+ } ,
270
+ content_changes: vec![ TextDocumentContentChangeEvent {
271
+ range: Some ( Range {
272
+ start: Position { line: 19 , character: 15 } ,
273
+ end: Position { line: 19 , character: 15 } ,
274
+ } ) ,
275
+ range_length: Some ( 0 ) ,
276
+ text: "\n " . into( ) ,
277
+ } ] ,
278
+ } ,
279
+ ) . to_string( ) ,
280
+
281
+ request:: <requests:: Hover >(
282
+ 13 ,
283
+ TextDocumentPositionParams {
284
+ text_document: TextDocumentIdentifier :: new( url) ,
285
+ position: world_src_pos_after,
286
+ } ,
287
+ ) . to_string( ) ,
288
+ ] ;
289
+
290
+ let ( mut server, results) = env. mock_server ( messages) ;
291
+ // Initialize and build.
292
+ assert_eq ! (
293
+ ls_server:: LsService :: handle_message( & mut server) ,
294
+ ls_server:: ServerStateChange :: Continue
295
+ ) ;
296
+ expect_messages (
297
+ results. clone ( ) ,
298
+ & [
299
+ ExpectedMessage :: new ( Some ( 0 ) ) . expect_contains ( "capabilities" ) ,
300
+ ExpectedMessage :: new ( None ) . expect_contains ( "beginBuild" ) ,
301
+ ExpectedMessage :: new ( None ) . expect_contains ( "diagnosticsBegin" ) ,
302
+ ExpectedMessage :: new ( None ) . expect_contains ( "diagnosticsEnd" ) ,
303
+ ] ,
304
+ ) ;
305
+
306
+ // first hover over unmodified
307
+ assert_eq ! (
308
+ ls_server:: LsService :: handle_message( & mut server) ,
309
+ ls_server:: ServerStateChange :: Continue
310
+ ) ;
311
+ expect_messages (
312
+ results. clone ( ) ,
313
+ & [
314
+ ExpectedMessage :: new ( Some ( 11 ) )
315
+ . expect_contains ( r#"[{"language":"rust","value":"&str"}]"# ) ,
316
+ ] ,
317
+ ) ;
318
+
319
+ // handle didChange notification and wait for rebuild
320
+ assert_eq ! (
321
+ ls_server:: LsService :: handle_message( & mut server) ,
322
+ ls_server:: ServerStateChange :: Continue
323
+ ) ;
324
+
325
+ expect_messages (
326
+ results. clone ( ) ,
327
+ & [
328
+ ExpectedMessage :: new ( None ) . expect_contains ( "beginBuild" ) ,
329
+ ExpectedMessage :: new ( None ) . expect_contains ( "diagnosticsBegin" ) ,
330
+ ExpectedMessage :: new ( None ) . expect_contains ( "diagnosticsEnd" ) ,
331
+ ] ,
332
+ ) ;
333
+
334
+ // hover after line change should work at the new line
335
+ assert_eq ! (
336
+ ls_server:: LsService :: handle_message( & mut server) ,
337
+ ls_server:: ServerStateChange :: Continue
338
+ ) ;
339
+ expect_messages (
340
+ results. clone ( ) ,
341
+ & [
342
+ ExpectedMessage :: new ( Some ( 13 ) )
343
+ . expect_contains ( r#"[{"language":"rust","value":"&str"}]"# ) ,
344
+ ] ,
345
+ ) ;
346
+ }
347
+
229
348
#[ test]
230
349
fn test_workspace_symbol ( ) {
231
350
let mut env = Environment :: new ( "workspace_symbol" ) ;
0 commit comments