@@ -111,8 +111,10 @@ public void testCommitWithResolveInsertPlainTextAndAdditionalEdits() throws IOEx
111111 new TestTextDocumentService () {
112112 @ Override
113113 public CompletableFuture <Either <List <CompletionItem >, CompletionList >> completion (CompletionParams position ) {
114+ CompletionItem item = new CompletionItem ("to-be-resolved" );
115+ item .setFilterText ("insert" );
114116 return CompletableFuture .completedFuture (Either .forLeft (List .of (
115- new CompletionItem ( "to-be-resolved" )
117+ item
116118 )));
117119 }
118120 @ Override
@@ -141,8 +143,10 @@ public void testCommitWithResolveInsertSnippetAndAdditionalEdits() throws IOExce
141143 new TestTextDocumentService () {
142144 @ Override
143145 public CompletableFuture <Either <List <CompletionItem >, CompletionList >> completion (CompletionParams position ) {
146+ CompletionItem item = new CompletionItem ("to-be-resolved" );
147+ item .setFilterText ("insert" );
144148 return CompletableFuture .completedFuture (Either .forLeft (List .of (
145- new CompletionItem ( "to-be-resolved" )
149+ item
146150 )));
147151 }
148152 @ Override
@@ -171,8 +175,10 @@ public void testCommitWithResolveSnippetMainEditAndAdditionalEdits() throws IOEx
171175 new TestTextDocumentService () {
172176 @ Override
173177 public CompletableFuture <Either <List <CompletionItem >, CompletionList >> completion (CompletionParams position ) {
178+ CompletionItem item = new CompletionItem ("to-be-resolved" );
179+ item .setFilterText ("insert" );
174180 return CompletableFuture .completedFuture (Either .forLeft (List .of (
175- new CompletionItem ( "to-be-resolved" )
181+ item
176182 )));
177183 }
178184 @ Override
@@ -201,8 +207,10 @@ public void testCommitWithResolveMainEditAndAdditionalEdits() throws IOException
201207 new TestTextDocumentService () {
202208 @ Override
203209 public CompletableFuture <Either <List <CompletionItem >, CompletionList >> completion (CompletionParams position ) {
210+ CompletionItem item = new CompletionItem ("to-be-resolved" );
211+ item .setFilterText ("insert" );
204212 return CompletableFuture .completedFuture (Either .forLeft (List .of (
205- new CompletionItem ( "to-be-resolved" )
213+ item
206214 )));
207215 }
208216 @ Override
@@ -227,7 +235,7 @@ public void testLabelDetails() throws IOException {
227235
228236 runCompletionTest (
229237 """
230- foo.ins |
238+ foo.|
231239 """ ,
232240 new TestTextDocumentService () {
233241 @ Override
@@ -305,6 +313,66 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
305313 assertFalse (notInvoked .get ());
306314 }
307315
316+ public void testFiltering () throws IOException {
317+ List <String > actualItems = new ArrayList <>();
318+ CompletionValidator printItems = (c , items ) -> {
319+ actualItems .addAll (printCompletionItems (items ));
320+ };
321+ TextDocumentService textDocumentService ;
322+ textDocumentService =
323+ new TestTextDocumentService () {
324+ @ Override
325+ public CompletableFuture <Either <List <CompletionItem >, CompletionList >> completion (CompletionParams position ) {
326+ List <CompletionItem > result = new ArrayList <>();
327+
328+ {
329+ CompletionItem resultItem = new CompletionItem ("addTest1" );
330+
331+ result .add (resultItem );
332+ }
333+ {
334+ CompletionItem resultItem = new CompletionItem ("X: addTest2" );
335+
336+ resultItem .setFilterText ("addTest2" );
337+ result .add (resultItem );
338+ }
339+ {
340+ CompletionItem resultItem = new CompletionItem ("removeTest1" );
341+
342+ result .add (resultItem );
343+ }
344+ {
345+ CompletionItem resultItem = new CompletionItem ("X: removeTest2" );
346+
347+ resultItem .setFilterText ("removeTest2" );
348+ result .add (resultItem );
349+ }
350+
351+ return CompletableFuture .completedFuture (Either .forLeft (result ));
352+ }
353+ };
354+
355+ actualItems .clear ();
356+ runCompletionTest ("""
357+ foo.|
358+ """ ,
359+ textDocumentService , printItems );
360+ assertEquals (List .of ("addTest1" ,
361+ "X: addTest2" ,
362+ "removeTest1" ,
363+ "X: removeTest2" ),
364+ actualItems );
365+
366+ actualItems .clear ();
367+ runCompletionTest ("""
368+ foo.add|
369+ """ ,
370+ textDocumentService , printItems );
371+ assertEquals (List .of ("addTest1" ,
372+ "X: addTest2" ),
373+ actualItems );
374+ }
375+
308376 public void testNoResolveProvider () throws IOException {
309377 AtomicBoolean notInvoked = new AtomicBoolean ();
310378
@@ -466,7 +534,7 @@ private void runAnyCompletionTest(String testCodeWithCaret,
466534 JEditorPane c = new JEditorPane ();
467535 c .setEditorKit (new NbEditorKit ());
468536 c .setDocument (doc );
469- c .setCaretPosition (4 );
537+ c .setCaretPosition (caret );
470538 runCompletion .accept (c );
471539 }
472540
0 commit comments