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

JDT completions coming from LS application fixed #908

Merged
merged 3 commits into from
Feb 7, 2024
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
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e.jdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JDT Integration for LSP4E
Bundle-SymbolicName: org.eclipse.lsp4e.jdt;singleton:=true
Bundle-Version: 0.12.0.qualifier
Bundle-Version: 0.13.0.qualifier
Automatic-Module-Name: org.eclipse.lsp4e.jdt
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ClassPath: .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Pivotal Inc. and others.
* Copyright (c) 2017, 2024 Pivotal Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -23,6 +23,8 @@
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
Expand Down Expand Up @@ -84,7 +86,13 @@ private ICompletionProposal[] asJavaProposals(CompletableFuture<ICompletionPropo
final var javaProposals = new ICompletionProposal[originalProposals.length];

for (int i = 0; i < originalProposals.length; i++) {
javaProposals[i] = new LSJavaProposal(originalProposals[i], relevance--);
if (originalProposals[i] instanceof ICompletionProposalExtension2) {
javaProposals[i] = new LSJavaProposalExtension2(originalProposals[i], relevance--);
} else if (originalProposals[i] instanceof ICompletionProposalExtension) {
javaProposals[i] = new LSJavaProposalExtension(originalProposals[i], relevance--);
} else {
javaProposals[i] = new LSJavaProposal(originalProposals[i], relevance--);
}
}

return javaProposals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@
package org.eclipse.lsp4e.jdt;

import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.lsp4e.operations.completion.LSCompletionProposal;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;

@SuppressWarnings("restriction")
class LSJavaProposal implements IJavaCompletionProposal, ICompletionProposalExtension2 {
class LSJavaProposal implements IJavaCompletionProposal {

private ICompletionProposal delegate;
protected ICompletionProposal delegate;
private int relevance;

public LSJavaProposal(ICompletionProposal delegate, int relevance) {
Expand Down Expand Up @@ -67,34 +62,5 @@ public Point getSelection(IDocument document) {
public int getRelevance() {
return relevance;
}

@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
if (delegate instanceof LSCompletionProposal) {
((LSCompletionProposal) delegate).apply(viewer, trigger, stateMask, offset);
}
}

@Override
public void selected(ITextViewer viewer, boolean smartToggle) {
if (delegate instanceof LSCompletionProposal) {
((LSCompletionProposal) delegate).selected(viewer, smartToggle);
}
}

@Override
public void unselected(ITextViewer viewer) {
if (delegate instanceof LSCompletionProposal) {
((LSCompletionProposal) delegate).unselected(viewer);
}
}

@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
if (delegate instanceof LSCompletionProposal) {
return ((LSCompletionProposal) delegate).validate(document, offset, event);
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Alex Boyko (VMware Inc.) - Initial implementation
*******************************************************************************/
package org.eclipse.lsp4e.jdt;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;

class LSJavaProposalExtension extends LSJavaProposal implements ICompletionProposalExtension {

public LSJavaProposalExtension(ICompletionProposal delegate, int relevance) {
super(delegate, relevance);
}

@Override
public void apply(IDocument doc, char trigger, int offset) {
if (delegate instanceof ICompletionProposalExtension) {
((ICompletionProposalExtension) delegate).apply(doc, trigger, offset);
}
}

@Override
public int getContextInformationPosition() {
if (delegate instanceof ICompletionProposalExtension) {
((ICompletionProposalExtension) delegate).getContextInformationPosition();
}
return -1;
}

@Override
public char[] getTriggerCharacters() {
if (delegate instanceof ICompletionProposalExtension) {
((ICompletionProposalExtension) delegate).getTriggerCharacters();
}
return null;
}

@Override
public boolean isValidFor(IDocument doc, int offset) {
if (delegate instanceof ICompletionProposalExtension) {
((ICompletionProposalExtension) delegate).isValidFor(doc, offset);
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Alex Boyko (VMware Inc.) - Initial implementation
*******************************************************************************/
package org.eclipse.lsp4e.jdt;

import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;

class LSJavaProposalExtension2 extends LSJavaProposal implements ICompletionProposalExtension2 {

public LSJavaProposalExtension2(ICompletionProposal delegate, int relevance) {
super(delegate, relevance);
}

@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
if (delegate instanceof ICompletionProposalExtension2) {
((ICompletionProposalExtension2) delegate).apply(viewer, trigger, stateMask, offset);
}
}

@Override
public void selected(ITextViewer viewer, boolean smartToggle) {
if (delegate instanceof ICompletionProposalExtension2) {
((ICompletionProposalExtension2) delegate).selected(viewer, smartToggle);
}
}

@Override
public void unselected(ITextViewer viewer) {
if (delegate instanceof ICompletionProposalExtension2) {
((ICompletionProposalExtension2) delegate).unselected(viewer);
}
}

@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
if (delegate instanceof ICompletionProposalExtension2) {
return ((ICompletionProposalExtension2) delegate).validate(document, offset, event);
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 VMware Inc. and others.
* Copyright (c) 2022, 2024 VMware Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -17,11 +17,14 @@
import org.eclipse.jdt.ui.text.java.IProblemLocation;
import org.eclipse.jdt.ui.text.java.IQuickAssistProcessor;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.TextInvocationContext;
import org.eclipse.lsp4e.operations.codeactions.LSPCodeActionQuickAssistProcessor;

@SuppressWarnings("restriction")
public class LspJavaQuickAssistProcessor extends LSPCodeActionQuickAssistProcessor implements IQuickAssistProcessor {

private static final int RELEVANCE = 100;
Expand Down Expand Up @@ -59,7 +62,17 @@ public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblem
ICompletionProposal[] proposals = computeQuickAssistProposals(getContext(context));
final var javaProposals = new IJavaCompletionProposal[proposals.length];
for (int i = 0; i < proposals.length; i++) {
javaProposals[i] = new LSJavaProposal(proposals[i], RELEVANCE);
/*
* Different completion extension applied differently, hence each requires a wrapper implementing
* proper completion proposal extension
*/
if (proposals[i] instanceof ICompletionProposalExtension2) {
javaProposals[i] = new LSJavaProposalExtension2(proposals[i], RELEVANCE);
} else if (proposals[i] instanceof ICompletionProposalExtension) {
javaProposals[i] = new LSJavaProposalExtension(proposals[i], RELEVANCE);
} else {
javaProposals[i] = new LSJavaProposal(proposals[i], RELEVANCE);
}
}
return javaProposals;
}
Expand Down