@@ -40,9 +40,10 @@ public function testHandleNoSuggestions(): void
4040 );
4141 $ this ->assertInstanceOf (CompletionList::class, $ response ->result );
4242 $ this ->assertEquals ([], $ response ->result ->items );
43+ $ this ->assertFalse ($ response ->result ->isIncomplete );
4344 }
4445
45- public function testHandleSuggestions (): void
46+ public function testHandleACompleteListOfSuggestions (): void
4647 {
4748 $ tester = $ this ->create ([
4849 Suggestion::create ('hello ' ),
@@ -60,6 +61,28 @@ public function testHandleSuggestions(): void
6061 self ::completionItem ('hello ' , null ),
6162 self ::completionItem ('goodbye ' , null ),
6263 ], $ response ->result ->items );
64+ $ this ->assertFalse ($ response ->result ->isIncomplete );
65+ }
66+
67+ public function testHandleAnIncompleteListOfSuggestions ()
68+ {
69+ $ tester = $ this ->create ([
70+ Suggestion::create ('hello ' ),
71+ Suggestion::create ('goodbye ' ),
72+ ], true , true );
73+ $ response = $ tester ->requestAndWait (
74+ 'textDocument/completion ' ,
75+ [
76+ 'textDocument ' => ProtocolFactory::textDocumentIdentifier (self ::EXAMPLE_URI ),
77+ 'position ' => ProtocolFactory::position (0 , 0 )
78+ ]
79+ );
80+ $ this ->assertInstanceOf (CompletionList::class, $ response ->result );
81+ $ this ->assertEquals ([
82+ self ::completionItem ('hello ' , null ),
83+ self ::completionItem ('goodbye ' , null ),
84+ ], $ response ->result ->items );
85+ $ this ->assertTrue ($ response ->result ->isIncomplete );
6386 }
6487
6588 public function testHandleSuggestionsWithRange ()
@@ -80,6 +103,7 @@ public function testHandleSuggestionsWithRange()
80103 'hello '
81104 )])
82105 ], $ response ->result ->items );
106+ $ this ->assertFalse ($ response ->result ->isIncomplete );
83107 }
84108
85109 public function testCancelReturnsPartialResults ()
@@ -106,6 +130,7 @@ public function testCancelReturnsPartialResults()
106130 ]));
107131
108132 $ this ->assertGreaterThan (1 , count ($ responses [0 ]->result ->items ));
133+ $ this ->assertTrue ($ responses [0 ]->result ->isIncomplete );
109134 }
110135
111136 public function testHandleSuggestionsWithSnippets ()
@@ -135,6 +160,7 @@ public function testHandleSuggestionsWithSnippets()
135160 self ::completionItem ('goodbye ' , 2 , ['insertText ' => 'goodbye() ' , 'insertTextFormat ' => 2 ]),
136161 self ::completionItem ('var ' , 6 ),
137162 ], $ response ->result ->items );
163+ $ this ->assertFalse ($ response ->result ->isIncomplete );
138164 }
139165
140166 public function testHandleSuggestionsWithSnippetsWhenClientDoesNotSupportIt ()
@@ -164,6 +190,7 @@ public function testHandleSuggestionsWithSnippetsWhenClientDoesNotSupportIt()
164190 self ::completionItem ('goodbye ' , 2 ),
165191 self ::completionItem ('var ' , 6 ),
166192 ], $ response ->result ->items );
193+ $ this ->assertFalse ($ response ->result ->isIncomplete );
167194 }
168195
169196 private static function completionItem (
@@ -181,9 +208,9 @@ private static function completionItem(
181208 ], $ data ));
182209 }
183210
184- private function create (array $ suggestions , bool $ supportSnippets = true ): LanguageServerTester
211+ private function create (array $ suggestions , bool $ supportSnippets = true , bool $ isIncomplete = false ): LanguageServerTester
185212 {
186- $ completor = $ this ->createCompletor ($ suggestions );
213+ $ completor = $ this ->createCompletor ($ suggestions, $ isIncomplete );
187214 $ registry = new TypedCompletorRegistry ([
188215 'php ' => $ completor ,
189216 ]);
@@ -200,13 +227,15 @@ private function create(array $suggestions, bool $supportSnippets = true): Langu
200227 return $ tester ;
201228 }
202229
203- private function createCompletor (array $ suggestions ): Completor
230+ private function createCompletor (array $ suggestions, bool $ isIncomplete = false ): Completor
204231 {
205- return new class ($ suggestions ) implements Completor {
232+ return new class ($ suggestions, $ isIncomplete ) implements Completor {
206233 private $ suggestions ;
207- public function __construct (array $ suggestions )
234+ private $ isIncomplete ;
235+ public function __construct (array $ suggestions , bool $ isIncomplete )
208236 {
209237 $ this ->suggestions = $ suggestions ;
238+ $ this ->isIncomplete = $ isIncomplete ;
210239 }
211240
212241 public function complete (TextDocument $ source , ByteOffset $ offset ): Generator
@@ -217,6 +246,8 @@ public function complete(TextDocument $source, ByteOffset $offset): Generator
217246 // simulate work
218247 usleep (100 );
219248 }
249+
250+ return !$ this ->isIncomplete ;
220251 }
221252 };
222253 }
0 commit comments