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 pId mismatch bug in completion #2681

Merged
merged 1 commit into from
Jun 12, 2023
Merged
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 @@ -245,11 +245,13 @@ public List<CompletionItem> getCompletionItems(IProgressMonitor monitor) {
}

List<Map<String, String>> contributedData = new LinkedList<>();
//Let's compute replacement texts for the most relevant results only
for (int i = 0; i < limit; i++) {
CompletionProposal proposal = proposals.get(i);
int pId = 0; // store the index of the completion item in the list
int proposalIndex = 0; // to iterate through proposals
List<CompletionProposal> proposalsToBeCached = new LinkedList<>();
for (; pId < limit && proposalIndex < proposals.size(); proposalIndex++) {
CompletionProposal proposal = proposals.get(proposalIndex);
try {
CompletionItem item = toCompletionItem(proposal, i);
CompletionItem item = toCompletionItem(proposal, pId);
CompletionRankingAggregation rankingResult = proposalToRankingResult.get(proposal);
if (rankingResult != null) {
String decorators = rankingResult.getDecorators();
Expand All @@ -265,18 +267,21 @@ public List<CompletionItem> getCompletionItems(IProgressMonitor monitor) {
contributedData.add(rankingData);
}
completionItems.add(item);
proposalsToBeCached.add(proposal);
pId++;
} catch (Exception e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
JavaLanguageServerPlugin.logException(
"Failed to convert completion proposal to completion item",
e
);
}
}

if (proposals.size() > maxCompletions) {
if (proposals.size() > proposalIndex) {
//we keep receiving completions past our capacity so that makes the whole result incomplete
isComplete = false;
response.setProposals(proposals.subList(0, limit));
} else {
response.setProposals(proposals);
}
response.setProposals(proposalsToBeCached);
response.setItems(completionItems);
response.setCommonData(CompletionResolveHandler.DATA_FIELD_URI, uri);
response.setCompletionItemData(contributedData);
Expand Down