Skip to content

Commit

Permalink
Store the completion kinds requested by completion operation (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
testforstephen authored Sep 18, 2023
1 parent bae72c2 commit ff0190c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -78,6 +79,15 @@ public final class CompletionProposalRequestor extends CompletionRequestor {
private PreferenceManager preferenceManager;
private CompletionProposalReplacementProvider proposalProvider;
private CompletionItemDefaults itemDefaults = new CompletionItemDefaults();
/**
* The possible completion kinds requested by the completion engine:
* - {@link CompletionProposal#FIELD_REF}
* - {@link CompletionProposal#METHOD_REF}
* - {@link CompletionProposal#TYPE_REF}
* - {@link CompletionProposal#VARIABLE_DECLARATION}
* - etc.
*/
private Set<Integer> completionKinds = new TreeSet<>();

static class ProposalComparator implements Comparator<CompletionProposal> {

Expand Down Expand Up @@ -126,6 +136,14 @@ public boolean isComplete() {
}

public CompletionItemDefaults getCompletionItemDefaults() {
if (!completionKinds.isEmpty()) {
if (itemDefaults.getData() == null) {
itemDefaults.setData(new HashMap<>());
}
if (itemDefaults.getData() instanceof Map map) {
map.put("completionKinds", completionKinds);
}
}
return itemDefaults;
}
// Update SUPPORTED_KINDS when mapKind changes
Expand Down Expand Up @@ -644,6 +662,12 @@ public boolean isIgnored(char[] fullTypeName) {
return fullTypeName != null && TypeFilter.isFiltered(fullTypeName);
}

@Override
public boolean isIgnored(int completionProposalKind) {
completionKinds.add(completionProposalKind);
return super.isIgnored(completionProposalKind);
}

/**
* Check if the case is match between the proposal and the token according to the preference.
* @param proposal completion proposal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.core.resources.IFile;
Expand All @@ -39,6 +40,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
Expand Down Expand Up @@ -1003,6 +1005,11 @@ public void testCompletion_field_itemDefaults_enabled() throws JavaModelExceptio
assertNotNull(list.getItemDefaults().getEditRange());
assertEquals(InsertTextFormat.Snippet, list.getItemDefaults().getInsertTextFormat());
assertEquals(InsertTextMode.AdjustIndentation, list.getItemDefaults().getInsertTextMode());
assertNotNull(list.getItemDefaults().getData());
Map<String, Object> data = (Map)list.getItemDefaults().getData();
Set<Integer> completionKinds = (Set)data.get("completionKinds");
assertNotNull(completionKinds);
assertTrue(completionKinds.contains(CompletionProposal.FIELD_REF));

assertEquals(1, list.getItems().size());
CompletionItem item = list.getItems().get(0);
Expand Down

0 comments on commit ff0190c

Please sign in to comment.