Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the missing filter text for completion items #2439

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -231,6 +232,11 @@ public List<CompletionItem> getCompletionItems(IProgressMonitor monitor) {
String decorators = rankingResult.getDecorators();
if (!decorators.isEmpty()) {
item.setLabel(decorators + " " + item.getLabel());
// when the item has decorators, set the filter text to avoid client takes the
// decorators into consideration when filtering.
if (StringUtils.isEmpty(item.getFilterText())) {
item.setFilterText(item.getInsertText());
}
}
Map<String, String> itemData = (Map<String, String>) item.getData();
Map<String, String> rankingData = rankingResult.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal.handlers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void testRank() throws Exception {
CompletionItem recommended = list.getItems().get(0);
assertTrue(recommended.getLabel().startsWith("★"));
assertTrue(((Map)recommended.getData()).containsKey("foo"));
assertEquals(recommended.getFilterText(), recommended.getInsertText());
assertTrue(((Map)recommended.getData()).containsKey(CompletionRanking.COMPLETION_EXECUTION_TIME));
}

Expand Down