Skip to content

Commit 9c26ffa

Browse files
authored
JDT completions compatible with any ICompletionProposal (#1256)
JDT completions changes 1443a66 broke CodeAction for JDT coming from LS. This change should restore the behaviour for CodeActions.
1 parent b7c09e6 commit 9c26ffa

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Broadcom Inc. and others.
3+
* This program and the accompanying materials are made
4+
* available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* - Alex Boyko (Broadcom Inc.) - Initial implementation
11+
*******************************************************************************/
12+
package org.eclipse.lsp4e.jdt;
13+
14+
import org.eclipse.jdt.annotation.Nullable;
15+
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
16+
import org.eclipse.jface.text.IDocument;
17+
import org.eclipse.jface.text.contentassist.ICompletionProposal;
18+
import org.eclipse.jface.text.contentassist.IContextInformation;
19+
import org.eclipse.swt.graphics.Image;
20+
import org.eclipse.swt.graphics.Point;
21+
22+
class LSJavaCompletionWrappingCompletionProposal implements IJavaCompletionProposal {
23+
24+
private final ICompletionProposal delegate;
25+
26+
public LSJavaCompletionWrappingCompletionProposal(ICompletionProposal delegate) {
27+
this.delegate = delegate;
28+
}
29+
30+
@Override
31+
public void apply(IDocument document) {
32+
delegate.apply(document);
33+
}
34+
35+
@Override
36+
public @Nullable Point getSelection(IDocument document) {
37+
return delegate.getSelection(document);
38+
}
39+
40+
@Override
41+
public @Nullable String getAdditionalProposalInfo() {
42+
return delegate.getAdditionalProposalInfo();
43+
}
44+
45+
@Override
46+
public String getDisplayString() {
47+
return delegate.getDisplayString();
48+
}
49+
50+
@Override
51+
public @Nullable Image getImage() {
52+
return delegate.getImage();
53+
}
54+
55+
@Override
56+
public @Nullable IContextInformation getContextInformation() {
57+
return delegate.getContextInformation();
58+
}
59+
60+
@Override
61+
public int getRelevance() {
62+
return -1;
63+
}
64+
65+
}

org.eclipse.lsp4e.jdt/src/org/eclipse/lsp4e/jdt/LspJavaQuickAssistProcessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ public boolean hasAssists(final IInvocationContext context) throws CoreException
6464
ICompletionProposal[] proposals = computeQuickAssistProposals(getContext(context));
6565
if (proposals == null)
6666
return NO_JAVA_COMPLETION_PROPOSALS;
67-
68-
return Arrays.stream(proposals).filter(LSCompletionProposal.class::isInstance)
69-
.map(LSCompletionProposal.class::cast).map(LSJavaProposal::new).toArray(LSJavaProposal[]::new);
70-
67+
68+
return Arrays.stream(proposals).map(p -> {
69+
if (p instanceof LSCompletionProposal lscp) {
70+
return new LSJavaProposal(lscp);
71+
}
72+
return new LSJavaCompletionWrappingCompletionProposal(p);
73+
}).toArray(IJavaCompletionProposal[]::new);
7174
}
7275

7376
}

0 commit comments

Comments
 (0)