Spring Data repo CA consecutive invocation while "query" is built

This commit is contained in:
aboyko
2023-03-06 19:29:16 -05:00
parent 86fd1e7c3a
commit c2a21e4002
8 changed files with 83 additions and 8 deletions

View File

@@ -95,6 +95,10 @@
class="org.springframework.tooling.ls.eclipse.commons.commands.JavaWorkspaceCommandHanlder"
commandId="java.execute.workspaceCommand">
</handler>
<handler
class="org.springframework.tooling.ls.eclipse.commons.commands.InvokeContentAssistCommandHandler"
commandId="editor.action.triggerSuggest">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
@@ -121,6 +125,22 @@
optional="false">
</commandParameter>
</command>
<command
id="editor.action.triggerSuggest"
name="Invoke Content Assist">
<commandParameter
id="org.eclipse.lsp4e.path.param"
name="Resource Path (unnecessary, only to make lsp4e happy)"
optional="true"
typeId="org.eclipse.lsp4e.pathParameterType">
</commandParameter>
<commandParameter
id="org.eclipse.lsp4e.command.param"
name="Command id (unnecessary, only to make lsp4e happy)"
optional="true"
typeId="org.eclipse.lsp4e.commandParameterType">
</commandParameter>
</command>
</extension>
<extension
point="org.eclipse.e4.ui.css.swt.theme">

View File

@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2023 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.ls.eclipse.commons.commands;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.progress.UIJob;
public class InvokeContentAssistCommandHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
UIJob.create("Invoke Content Assist", (ICoreRunnable) m -> {
try {
IHandlerService service = HandlerUtil.getActiveWorkbenchWindow(event).getService(IHandlerService.class);
service.executeCommand(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST, null);
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
throw new CoreException(Status.error("", e));
}
}).schedule();
return null;
}
}

View File

@@ -26,6 +26,7 @@ public interface ICompletionProposal {
CompletionItemKind getKind();
DocumentEdits getTextEdit();
default Optional<DocumentEdits> getAdditionalEdit() { return Optional.empty(); }
default boolean isTriggeringNextCompletionRequest() { return false; }
String getDetail();
Renderable getDocumentation();

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2022 VMware Inc.
* Copyright (c) 2016, 2023 VMware Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,6 +21,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionList;
import org.eclipse.lsp4j.InsertTextFormat;
@@ -228,6 +229,10 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
resolveItem(doc, completion, item);
}
}
if (completion.isTriggeringNextCompletionRequest()) {
item.setCommand(new Command("Completion Proposal Request", "editor.action.triggerSuggest"));
}
return item;
}

View File

@@ -26,9 +26,10 @@ public class FindByCompletionProposal implements ICompletionProposal {
private Renderable doc;
private Optional<DocumentEdits> additionalEdits;
private String filter;
private boolean triggerNextCompletion;
public FindByCompletionProposal(String label, CompletionItemKind kind, DocumentEdits edits, String details,
Renderable doc, Optional<DocumentEdits> additionalEdits, String filter) {
Renderable doc, Optional<DocumentEdits> additionalEdits, String filter, boolean triggerNextCompletion) {
super();
this.label = label;
this.kind = kind;
@@ -37,9 +38,10 @@ public class FindByCompletionProposal implements ICompletionProposal {
this.doc = doc;
this.additionalEdits = additionalEdits;
this.filter = filter;
this.triggerNextCompletion = triggerNextCompletion;
}
public static ICompletionProposal createProposal(int offset, CompletionItemKind completionItemKind, String prefix, String label, String completion) {
public static ICompletionProposal createProposal(int offset, CompletionItemKind completionItemKind, String prefix, String label, String completion, boolean triggerNextCompletion) {
DocumentEdits edits = new DocumentEdits(null, false);
String filter = label;
if (prefix != null && label.startsWith(prefix)) {
@@ -54,7 +56,7 @@ public class FindByCompletionProposal implements ICompletionProposal {
}
DocumentEdits additionalEdits = new DocumentEdits(null, false);
return new FindByCompletionProposal(label, completionItemKind, edits, null, null, Optional.of(additionalEdits), filter);
return new FindByCompletionProposal(label, completionItemKind, edits, null, null, Optional.of(additionalEdits), filter, triggerNextCompletion);
}
@Override
@@ -92,4 +94,9 @@ public class FindByCompletionProposal implements ICompletionProposal {
return filter;
}
@Override
public boolean isTriggeringNextCompletionRequest() {
return triggerNextCompletion;
}
}

View File

@@ -32,7 +32,7 @@ public class DataRepositoryQueryStartCompletionProvider implements DataRepositor
for(QueryMethodSubject queryMethodSubject : QueryMethodSubject.QUERY_METHOD_SUBJECTS){
String toInsert = queryMethodSubject.key() + "By";
if(prefix == null || toInsert.startsWith(localPrefix)||isOffsetAfterWhitespace(doc, offset)) {
completions.add(FindByCompletionProposal.createProposal(offset, CompletionItemKind.Text, prefix, toInsert, toInsert));
completions.add(FindByCompletionProposal.createProposal(offset, CompletionItemKind.Text, prefix, toInsert, toInsert, true));
}
}
}

View File

@@ -56,6 +56,6 @@ public class DataRepositoryStandardCompletionProvider implements DataRepositoryC
completion.append(StringUtils.uncapitalize(domainProperty.getName()));
completion.append(");");
return FindByCompletionProposal.createProposal(offset, CompletionItemKind.Method, prefix, label.toString(), completion.toString());
return FindByCompletionProposal.createProposal(offset, CompletionItemKind.Method, prefix, label.toString(), completion.toString(), false);
}
}

View File

@@ -94,7 +94,7 @@ public class DataRepositoryPrefixSensitiveCompletionProvider implements DataRepo
DocumentEdits edits = new DocumentEdits(null, false);
edits.replace(offset - lastWord.length(), offset, toReplace);
DocumentEdits additionalEdits = new DocumentEdits(null, false);
ICompletionProposal proposal = new FindByCompletionProposal(toReplace, CompletionItemKind.Text, edits, "property " + toReplace, null, Optional.of(additionalEdits), lastWord);
ICompletionProposal proposal = new FindByCompletionProposal(toReplace, CompletionItemKind.Text, edits, "property " + toReplace, null, Optional.of(additionalEdits), lastWord, true);
completions.add(proposal);
}
}
@@ -117,7 +117,7 @@ public class DataRepositoryPrefixSensitiveCompletionProvider implements DataRepo
int replaceStart = calculateReplaceOffset(offset, localPrefix, fullPrefix, returnType);
edits.replace(replaceStart, offset, newText.toString());
DocumentEdits additionalEdits = new DocumentEdits(null, false);
ICompletionProposal proposal = new FindByCompletionProposal(methodName, CompletionItemKind.Method, edits, null, null, Optional.of(additionalEdits), signature);
ICompletionProposal proposal = new FindByCompletionProposal(methodName, CompletionItemKind.Method, edits, null, null, Optional.of(additionalEdits), signature, false);
completions.add(proposal);
}