@@ -76,7 +76,7 @@ fn completions_from_call(
7676 return Ok ( None ) ;
7777 } ;
7878
79- let callee = callee. node_as_str ( & document_context. document . contents ) ?;
79+ let callee = callee. node_as_str ( document_context. contents ) ?;
8080
8181 // - Prefer `root` as the first argument if it exists
8282 // - Then fall back to looking it up, if possible
@@ -122,7 +122,7 @@ fn get_first_argument(context: &DocumentContext, node: &Node) -> anyhow::Result<
122122 return Ok ( None ) ;
123123 } ;
124124
125- let text = value. node_as_str ( & context. document . contents ) ?;
125+ let text = value. node_as_str ( context. contents ) ?;
126126
127127 let options = RParseEvalOptions {
128128 forbid_function_calls : true ,
@@ -280,8 +280,7 @@ mod tests {
280280 use crate :: fixtures:: point_from_cursor;
281281 use crate :: lsp:: completions:: completion_context:: CompletionContext ;
282282 use crate :: lsp:: completions:: sources:: composite:: call:: completions_from_call;
283- use crate :: lsp:: document:: Document ;
284- use crate :: lsp:: document_context:: DocumentContext ;
283+ use crate :: lsp:: document_context:: TestDocument ;
285284 use crate :: lsp:: state:: WorldState ;
286285 use crate :: r_task;
287286
@@ -290,8 +289,8 @@ mod tests {
290289 r_task ( || {
291290 // Right after `tab`
292291 let ( text, point) = point_from_cursor ( "match(tab@)" ) ;
293- let document = Document :: new ( text. as_str ( ) , None ) ;
294- let document_context = DocumentContext :: new ( & document , point, None ) ;
292+ let doc = TestDocument :: new ( & text) ;
293+ let document_context = doc . context ( point) ;
295294 let state = WorldState :: default ( ) ;
296295 let context = CompletionContext :: new ( & document_context, & state) ;
297296 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -303,8 +302,8 @@ mod tests {
303302
304303 // Right after `tab`
305304 let ( text, point) = point_from_cursor ( "match(1, tab@)" ) ;
306- let document = Document :: new ( text. as_str ( ) , None ) ;
307- let document_context = DocumentContext :: new ( & document , point, None ) ;
305+ let doc = TestDocument :: new ( & text) ;
306+ let document_context = doc . context ( point) ;
308307 let state = WorldState :: default ( ) ;
309308 let context = CompletionContext :: new ( & document_context, & state) ;
310309 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -323,8 +322,8 @@ mod tests {
323322 r_task ( || {
324323 // Place cursor between `()`
325324 let ( text, point) = point_from_cursor ( "not_a_known_function(@)" ) ;
326- let document = Document :: new ( text. as_str ( ) , None ) ;
327- let document_context = DocumentContext :: new ( & document , point, None ) ;
325+ let doc = TestDocument :: new ( & text) ;
326+ let document_context = doc . context ( point) ;
328327 let state = WorldState :: default ( ) ;
329328 let context = CompletionContext :: new ( & document_context, & state) ;
330329 let completions = completions_from_call ( & context) . unwrap ( ) ;
@@ -343,8 +342,8 @@ mod tests {
343342
344343 // Place cursor between `()`
345344 let ( text, point) = point_from_cursor ( "my_fun(@)" ) ;
346- let document = Document :: new ( text. as_str ( ) , None ) ;
347- let document_context = DocumentContext :: new ( & document , point, None ) ;
345+ let doc = TestDocument :: new ( & text) ;
346+ let document_context = doc . context ( point) ;
348347 let state = WorldState :: default ( ) ;
349348 let context = CompletionContext :: new ( & document_context, & state) ;
350349 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -360,17 +359,17 @@ mod tests {
360359
361360 // Place just before the `()`
362361 let ( text, point) = point_from_cursor ( "my_fun@()" ) ;
363- let document = Document :: new ( text. as_str ( ) , None ) ;
364- let document_context = DocumentContext :: new ( & document , point, None ) ;
362+ let doc = TestDocument :: new ( & text) ;
363+ let document_context = doc . context ( point) ;
365364 let state = WorldState :: default ( ) ;
366365 let context = CompletionContext :: new ( & document_context, & state) ;
367366 let completions = completions_from_call ( & context) . unwrap ( ) ;
368367 assert ! ( completions. is_none( ) ) ;
369368
370369 // Place just after the `()`
371370 let ( text, point) = point_from_cursor ( "my_fun()@" ) ;
372- let document = Document :: new ( text. as_str ( ) , None ) ;
373- let document_context = DocumentContext :: new ( & document , point, None ) ;
371+ let doc = TestDocument :: new ( & text) ;
372+ let document_context = doc . context ( point) ;
374373 let state = WorldState :: default ( ) ;
375374 let context = CompletionContext :: new ( & document_context, & state) ;
376375 let completions = completions_from_call ( & context) . unwrap ( ) ;
@@ -392,8 +391,8 @@ mod tests {
392391
393392 // Place cursor between `()`
394393 let ( text, point) = point_from_cursor ( "my_fun(@)" ) ;
395- let document = Document :: new ( text. as_str ( ) , None ) ;
396- let document_context = DocumentContext :: new ( & document , point, None ) ;
394+ let doc = TestDocument :: new ( & text) ;
395+ let document_context = doc . context ( point) ;
397396 let state = WorldState :: default ( ) ;
398397 let context = CompletionContext :: new ( & document_context, & state) ;
399398 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -409,8 +408,8 @@ mod tests {
409408 r_task ( || {
410409 // No arguments typed yet
411410 let ( text, point) = point_from_cursor ( "match(\n @\n )" ) ;
412- let document = Document :: new ( text. as_str ( ) , None ) ;
413- let document_context = DocumentContext :: new ( & document , point, None ) ;
411+ let doc = TestDocument :: new ( & text) ;
412+ let document_context = doc . context ( point) ;
414413 let state = WorldState :: default ( ) ;
415414 let context = CompletionContext :: new ( & document_context, & state) ;
416415 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -421,8 +420,8 @@ mod tests {
421420
422421 // Partially typed argument
423422 let ( text, point) = point_from_cursor ( "match(\n tab@\n )" ) ;
424- let document = Document :: new ( text. as_str ( ) , None ) ;
425- let document_context = DocumentContext :: new ( & document , point, None ) ;
423+ let doc = TestDocument :: new ( & text) ;
424+ let document_context = doc . context ( point) ;
426425 let state = WorldState :: default ( ) ;
427426 let context = CompletionContext :: new ( & document_context, & state) ;
428427 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -433,8 +432,8 @@ mod tests {
433432
434433 // Partially typed second argument
435434 let ( text, point) = point_from_cursor ( "match(\n 1,\n tab@\n )" ) ;
436- let document = Document :: new ( text. as_str ( ) , None ) ;
437- let document_context = DocumentContext :: new ( & document , point, None ) ;
435+ let doc = TestDocument :: new ( & text) ;
436+ let document_context = doc . context ( point) ;
438437 let state = WorldState :: default ( ) ;
439438 let context = CompletionContext :: new ( & document_context, & state) ;
440439 let completions = completions_from_call ( & context) . unwrap ( ) . unwrap ( ) ;
@@ -450,8 +449,8 @@ mod tests {
450449 r_task ( || {
451450 fn assert_no_call_completions ( code_with_cursor : & str ) {
452451 let ( text, point) = point_from_cursor ( code_with_cursor) ;
453- let document = Document :: new ( text. as_str ( ) , None ) ;
454- let document_context = DocumentContext :: new ( & document , point, None ) ;
452+ let doc = TestDocument :: new ( & text) ;
453+ let document_context = doc . context ( point) ;
455454 let state = WorldState :: default ( ) ;
456455 let context = CompletionContext :: new ( & document_context, & state) ;
457456 let completions = completions_from_call ( & context) . unwrap ( ) ;
0 commit comments