GH-1317: allow individual context assist processors to devide whether the list is incomplete or not + refined the way class and package proposals show up in XML config files
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2024 Pivotal, 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
|
||||
@@ -50,23 +50,32 @@ public class CompositeCompletionEngine implements ICompletionEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument document, int offset) throws Exception {
|
||||
public InternalCompletionList getCompletions(TextDocument document, int offset) throws Exception {
|
||||
LanguageId language = document.getLanguageId();
|
||||
log.info("languageId = {}", language);
|
||||
Collection<ICompletionEngine> engines = subEngines.get(language);
|
||||
|
||||
if (engines.size()==1) {
|
||||
|
||||
//Special case to avoid some collection copying
|
||||
ICompletionEngine engine = engines.iterator().next();
|
||||
return engine.getCompletions(document, offset);
|
||||
|
||||
} else {
|
||||
|
||||
boolean isIncomplete = false;
|
||||
ImmutableList.Builder<ICompletionProposal> completions = ImmutableList.builder();
|
||||
|
||||
for (ICompletionEngine engine : engines) {
|
||||
Collection<ICompletionProposal> c = engine.getCompletions(document, offset);
|
||||
if (c!=null) {
|
||||
completions.addAll(c);
|
||||
InternalCompletionList c = engine.getCompletions(document, offset);
|
||||
if (c != null && c.completionItems() != null) {
|
||||
completions.addAll(c.completionItems());
|
||||
if (c.isIncomplete()) {
|
||||
isIncomplete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return completions.build();
|
||||
return new InternalCompletionList(completions.build(), isIncomplete);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2015, 2024 Pivotal, 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
|
||||
@@ -10,8 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.completion;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
@@ -19,6 +17,6 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
*/
|
||||
public interface ICompletionEngine {
|
||||
|
||||
Collection<ICompletionProposal> getCompletions(TextDocument document, int offset) throws Exception;
|
||||
InternalCompletionList getCompletions(TextDocument document, int offset) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
*/
|
||||
public interface ICompletionProposal {
|
||||
|
||||
|
||||
String getLabel();
|
||||
CompletionItemKind getKind();
|
||||
DocumentEdits getTextEdit();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2024 Broadcom
|
||||
* 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:
|
||||
* Broadcom - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.completion;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public record InternalCompletionList (Collection<ICompletionProposal> completionItems, boolean isIncomplete) {
|
||||
}
|
||||
@@ -213,16 +213,17 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
int offset = doc.toOffset(params.getPosition());
|
||||
|
||||
// get completions
|
||||
Collection<ICompletionProposal> rawCompletions = engine.getCompletions(doc, offset);
|
||||
InternalCompletionList rawCompletionList = engine.getCompletions(doc, offset);
|
||||
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
List<ICompletionProposal> completions = filter(rawCompletions);
|
||||
List<ICompletionProposal> completions = filter(rawCompletionList.completionItems());
|
||||
Collections.sort(completions, ScoreableProposal.COMPARATOR);
|
||||
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
list.setIsIncomplete(false);
|
||||
boolean isIncomplete = rawCompletionList.isIncomplete();
|
||||
|
||||
List<CompletionItem> items = new ArrayList<>(completions.size());
|
||||
SortKeys sortkeys = new SortKeys();
|
||||
int count = 0;
|
||||
@@ -230,8 +231,9 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
for (ICompletionProposal c : completions) {
|
||||
count++;
|
||||
|
||||
if (maxCompletions > 0 && count>maxCompletions) {
|
||||
list.setIsIncomplete(true);
|
||||
if (maxCompletions > 0 && count > maxCompletions) {
|
||||
// override whatever completion engines said about being incomplete
|
||||
isIncomplete = true;
|
||||
break;
|
||||
}
|
||||
try {
|
||||
@@ -244,6 +246,8 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
list.setItems(items);
|
||||
list.setIsIncomplete(isIncomplete);
|
||||
|
||||
//This is a hack is no longer needed but keeping it as a reference:
|
||||
// See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=535823
|
||||
// Reason hack is not needed is because of the fix in: https://www.pivotaltracker.com/story/show/159667257
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2024 Pivotal, 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
|
||||
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
@@ -81,7 +82,7 @@ public class YamlCompletionEngine implements ICompletionEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument _doc, int offset) throws Exception {
|
||||
public InternalCompletionList getCompletions(TextDocument _doc, int offset) throws Exception {
|
||||
YamlDocument doc = new YamlDocument(_doc, structureProvider);
|
||||
if (!doc.isCommented(offset)) {
|
||||
SRootNode root = doc.getStructure();
|
||||
@@ -98,16 +99,16 @@ public class YamlCompletionEngine implements ICompletionEngine {
|
||||
completions.addAll(getRelaxedCompletions(offset, doc, current, contextNode, baseIndent, deempasizeBy));
|
||||
deempasizeBy += ScoreableProposal.DEEMP_NEXT_CONTEXT;
|
||||
}
|
||||
return completions;
|
||||
return new InternalCompletionList(completions, false);
|
||||
} else {
|
||||
//precise indentation only
|
||||
Assert.isLegal(contextNodes.size()<=1);
|
||||
for (SNode contextNode : contextNodes) {
|
||||
return getBaseCompletions(offset, doc, current, contextNode);
|
||||
return new InternalCompletionList(getBaseCompletions(offset, doc, current, contextNode), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
protected Collection<? extends ICompletionProposal> getRelaxedCompletions(int offset, YamlDocument doc, SNode current, SNode contextNode, int baseIndent, double deempasizeBy) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2020, 2024 Pivotal, 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
|
||||
@@ -22,6 +22,7 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.PrefixFinder;
|
||||
@@ -73,7 +74,7 @@ public class ClasspathResourceCompletionProvider implements ICompletionEngine, L
|
||||
private PropertyCompletionFactory completionFactory = new PropertyCompletionFactory();
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, int offset) {
|
||||
public InternalCompletionList getCompletions(TextDocument doc, int offset) {
|
||||
ImmutableList.Builder<ICompletionProposal> proposals = ImmutableList.builder();
|
||||
IJavaProject jp = projectFinder.find(doc.getId()).orElse(null);
|
||||
if (jp!=null) {
|
||||
@@ -98,7 +99,7 @@ public class ClasspathResourceCompletionProvider implements ICompletionEngine, L
|
||||
}
|
||||
}
|
||||
}
|
||||
return proposals.build();
|
||||
return new InternalCompletionList(proposals.build(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2020, 2024 Pivotal, 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
|
||||
@@ -19,6 +19,7 @@ import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.PrefixFinder;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
@@ -51,7 +52,7 @@ public class DollarPropertyCompletionProvider implements ICompletionEngine, Lang
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, int offset) {
|
||||
public InternalCompletionList getCompletions(TextDocument doc, int offset) {
|
||||
ImmutableList.Builder<ICompletionProposal> proposals = ImmutableList.builder();
|
||||
String prefix = PREFIX_FINDER.getPrefix(doc, offset);
|
||||
int prefixStart = offset-prefix.length();
|
||||
@@ -74,7 +75,7 @@ public class DollarPropertyCompletionProvider implements ICompletionEngine, Lang
|
||||
} catch (BadLocationException e) {
|
||||
//ignore. Didn't find the '${'
|
||||
}
|
||||
return proposals.build();
|
||||
return new InternalCompletionList(proposals.build(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2024 Pivotal, 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
|
||||
@@ -25,6 +25,7 @@ import org.springframework.ide.vscode.boot.java.snippets.JavaSnippetManager;
|
||||
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
@@ -48,7 +49,7 @@ public class BootJavaCompletionEngine implements ICompletionEngine, LanguageSpec
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument document, int offset) throws Exception {
|
||||
public InternalCompletionList getCompletions(TextDocument document, int offset) throws Exception {
|
||||
return cuCache.withCompilationUnit(document, cu -> {
|
||||
if (cu != null) {
|
||||
ASTNode node = findNode(document, offset, cu);
|
||||
@@ -58,11 +59,12 @@ public class BootJavaCompletionEngine implements ICompletionEngine, LanguageSpec
|
||||
collectCompletionsForAnnotations(node, offset, document, completions);
|
||||
collectCompletions(node, offset, document, completions);
|
||||
snippets.getCompletions(document, offset, node, cu, completions);
|
||||
return completions;
|
||||
|
||||
return new InternalCompletionList(completions, false);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2024 Pivotal, 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
|
||||
@@ -19,6 +19,7 @@ import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.types.TypeUtilProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
@@ -54,9 +55,11 @@ public class SpringPropertiesCompletionEngine implements ICompletionEngine, Lang
|
||||
* Create completions proposals in the context of a properties text editor.
|
||||
*/
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, int offset) throws BadLocationException {
|
||||
return new PropertiesCompletionProposalsCalculator(indexProvider.getIndex(doc).getProperties(),
|
||||
public InternalCompletionList getCompletions(TextDocument doc, int offset) throws BadLocationException {
|
||||
Collection<ICompletionProposal> completionItems = new PropertiesCompletionProposalsCalculator(indexProvider.getIndex(doc).getProperties(),
|
||||
typeUtilProvider.getTypeUtil(sourceLinks, doc), completionFactory, doc, offset, preferLowerCaseEnums).calculate();
|
||||
|
||||
return new InternalCompletionList(completionItems, false);
|
||||
}
|
||||
|
||||
public boolean getPreferLowerCaseEnums() {
|
||||
|
||||
@@ -68,6 +68,7 @@ import org.springframework.ide.vscode.boot.xml.completions.TypeCompletionProposa
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
@@ -135,9 +136,9 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, int offset) throws Exception {
|
||||
public InternalCompletionList getCompletions(TextDocument doc, int offset) throws Exception {
|
||||
if (!config.isSpringXMLSupportEnabled() || !config.isXmlContentAssistEnabled()) {
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
String content = doc.get();
|
||||
@@ -175,7 +176,7 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
|
||||
|
||||
XMLCompletionProvider completionProvider = this.completionProviders.get(key);
|
||||
if (completionProvider != null) {
|
||||
Collection<ICompletionProposal> completions = completionProvider.getCompletions(doc, namespace, node, attributeAt, scanner, offset);
|
||||
InternalCompletionList completions = completionProvider.getCompletions(doc, namespace, node, attributeAt, scanner, offset);
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +186,7 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
|
||||
if (scanner.getTokenOffset() <= offset && offset < scanner.getTokenEnd()) {
|
||||
if (node.getParentNode() != null && node.getParentNode() instanceof DOMDocument
|
||||
&& namespace.equals("http://www.springframework.org/schema/beans") && node.getLocalName().equals("beans")) {
|
||||
return NamespaceCompletionProvider.createNamespaceCompletionProposals(doc, offset, token, node);
|
||||
return new InternalCompletionList(NamespaceCompletionProvider.createNamespaceCompletionProposals(doc, offset, token, node), false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -193,7 +194,7 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
|
||||
if (scanner.getTokenOffset() <= offset && offset < scanner.getTokenEnd()) {
|
||||
if (node.getParentNode() != null && node.getParentNode() instanceof DOMDocument
|
||||
&& namespace.equals("http://www.springframework.org/schema/beans") && node.getLocalName().equals("beans")) {
|
||||
return NamespaceCompletionProvider.createNamespaceCompletionProposals(doc, offset, token, node);
|
||||
return new InternalCompletionList(NamespaceCompletionProvider.createNamespaceCompletionProposals(doc, offset, token, node), false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -203,10 +204,10 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
|
||||
token = scanner.scan();
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
private Collection<ICompletionProposal> emptySpringXMLConfigSnippet(TextDocument doc) {
|
||||
private InternalCompletionList emptySpringXMLConfigSnippet(TextDocument doc) {
|
||||
|
||||
CompletionItemKind kind = CompletionItemKind.Snippet;
|
||||
|
||||
@@ -244,7 +245,7 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
|
||||
Collection<ICompletionProposal> completions = new ArrayList<>(1);
|
||||
completions.add(proposal);
|
||||
|
||||
return completions;
|
||||
return new InternalCompletionList(completions, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2024 Pivotal, 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
|
||||
@@ -10,12 +10,10 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.xml;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.lemminx.dom.DOMAttr;
|
||||
import org.eclipse.lemminx.dom.DOMNode;
|
||||
import org.eclipse.lemminx.dom.parser.Scanner;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
@@ -23,7 +21,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
*/
|
||||
public interface XMLCompletionProvider {
|
||||
|
||||
Collection<ICompletionProposal> getCompletions(TextDocument doc, String namespace, DOMNode node,
|
||||
InternalCompletionList getCompletions(TextDocument doc, String namespace, DOMNode node,
|
||||
DOMAttr attributeAt, Scanner scanner, int offset);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2024 Pivotal, 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
|
||||
@@ -10,7 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.xml.completions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -27,6 +26,7 @@ import org.springframework.ide.vscode.boot.xml.XMLCompletionProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
@@ -48,7 +48,7 @@ public class BeanRefCompletionProposalProvider implements XMLCompletionProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
public InternalCompletionList getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
Scanner scanner, int offset) {
|
||||
|
||||
int tokenOffset = scanner.getTokenOffset();
|
||||
@@ -68,7 +68,7 @@ public class BeanRefCompletionProposalProvider implements XMLCompletionProvider
|
||||
|
||||
List<SymbolAddOnInformation> addonInfos = symbolIndex.getAllAdditionalInformation(addonInfo -> addonInfo instanceof BeansSymbolAddOnInformation);
|
||||
|
||||
return addonInfos.stream()
|
||||
List<ICompletionProposal> completionItems = addonInfos.stream()
|
||||
.map(info -> (BeansSymbolAddOnInformation) info)
|
||||
.map(beanInfo -> beanInfo.getBeanID())
|
||||
.filter(beanID -> beanID != null && beanID.length() > 0)
|
||||
@@ -76,9 +76,11 @@ public class BeanRefCompletionProposalProvider implements XMLCompletionProvider
|
||||
.filter(tuple -> tuple.getT2() != 0.0)
|
||||
.map(tuple -> createProposal(tuple.getT1(), doc, offset, searchPrefix, tuple.getT2()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new InternalCompletionList(completionItems, false);
|
||||
};
|
||||
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
private ICompletionProposal createProposal(String beanID, TextDocument doc, int offset, String prefix, Double score) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
@@ -54,7 +55,7 @@ public class ConstructorArgNameCompletionProposalProvider implements XMLCompleti
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
public InternalCompletionList getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
Scanner scanner, int offset) {
|
||||
|
||||
int tokenOffset = scanner.getTokenOffset();
|
||||
@@ -82,14 +83,16 @@ public class ConstructorArgNameCompletionProposalProvider implements XMLCompleti
|
||||
log.info("Bean class '{}'", beanClass);
|
||||
|
||||
final String searchPrefix = prefix;
|
||||
return constructorArgNameCandidates(project, beanClass)
|
||||
List<ICompletionProposal> completionItems = constructorArgNameCandidates(project, beanClass)
|
||||
.filter(constructorArg -> constructorArg.getRight().startsWith(searchPrefix))
|
||||
.map(constructorArg -> createProposal(constructorArg, doc, offset, tokenOffset, tokenEnd))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new InternalCompletionList(completionItems, false);
|
||||
}
|
||||
};
|
||||
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
public static String identifyBeanClass(DOMNode node) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2024 Pivotal, 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
|
||||
@@ -15,6 +15,7 @@ import static org.springframework.ide.vscode.boot.xml.XmlConfigConstants.CLASS_A
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -30,6 +31,7 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
@@ -49,7 +51,7 @@ public class PropertyNameCompletionProposalProvider implements XMLCompletionProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
public InternalCompletionList getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
Scanner scanner, int offset) {
|
||||
|
||||
int tokenOffset = scanner.getTokenOffset();
|
||||
@@ -77,14 +79,16 @@ public class PropertyNameCompletionProposalProvider implements XMLCompletionProv
|
||||
log.info("Bean class '{}'", beanClass);
|
||||
|
||||
final String searchPrefix = prefix;
|
||||
return propertyNameCandidateMethods(project, beanClass)
|
||||
List<ICompletionProposal> completionItems = propertyNameCandidateMethods(project, beanClass)
|
||||
.filter(method -> getPropertyName(method).startsWith(searchPrefix))
|
||||
.map(method -> createProposal(method, doc, offset, tokenOffset, tokenEnd))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new InternalCompletionList(completionItems, false);
|
||||
}
|
||||
};
|
||||
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
public static String identifyBeanClass(DOMNode node) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2024 Pivotal, 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
|
||||
@@ -10,7 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.xml.completions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -27,6 +26,7 @@ import org.springframework.ide.vscode.boot.xml.XMLCompletionProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteData;
|
||||
@@ -59,7 +59,7 @@ public class TypeCompletionProposalProvider implements XMLCompletionProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
public InternalCompletionList getCompletions(TextDocument doc, String namespace, DOMNode node, DOMAttr attributeAt,
|
||||
Scanner scanner, int offset) {
|
||||
|
||||
int tokenOffset = scanner.getTokenOffset();
|
||||
@@ -92,7 +92,7 @@ public class TypeCompletionProposalProvider implements XMLCompletionProvider {
|
||||
|
||||
try {
|
||||
List<JavaCodeCompleteData> list = completions.get();
|
||||
return list.stream()
|
||||
List<ICompletionProposal> completionItems = list.stream()
|
||||
.filter(proposal -> {
|
||||
if (proposal.isClassProposal()) return classesAllowed;
|
||||
if (proposal.isInterfaceProposal()) return interfacesAllowed;
|
||||
@@ -103,13 +103,15 @@ public class TypeCompletionProposalProvider implements XMLCompletionProvider {
|
||||
.map(proposal -> createProposal(proposal, doc, finalPrefix, offset))
|
||||
.filter(proposal -> proposal != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new InternalCompletionList(completionItems, true);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("{}", e);
|
||||
}
|
||||
};
|
||||
|
||||
return Collections.emptyList();
|
||||
return new InternalCompletionList(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
private ICompletionProposal createProposal(JavaCodeCompleteData proposal, TextDocument doc, String prefix, int offset) {
|
||||
@@ -130,11 +132,12 @@ public class TypeCompletionProposalProvider implements XMLCompletionProvider {
|
||||
CompletionItemKind kind = CompletionItemKind.Module;
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
if (fqName.startsWith(prefix)) {
|
||||
edits.insert(offset, fqName.substring(prefix.length()));
|
||||
} else {
|
||||
edits.replace(offset - prefix.length(), offset, fqName);
|
||||
}
|
||||
edits.replace(offset - prefix.length(), offset, fqName);
|
||||
// if (fqName.startsWith(prefix)) {
|
||||
// edits.insert(offset, fqName.substring(prefix.length()));
|
||||
// } else {
|
||||
// edits.replace(offset - prefix.length(), offset, fqName);
|
||||
// }
|
||||
|
||||
Renderable renderable = null;
|
||||
|
||||
@@ -160,15 +163,18 @@ public class TypeCompletionProposalProvider implements XMLCompletionProvider {
|
||||
}
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
if (fqName.startsWith(prefix)) {
|
||||
edits.insert(offset, fqName.substring(prefix.length()));
|
||||
} else {
|
||||
edits.replace(offset - prefix.length(), offset, fqName);
|
||||
}
|
||||
edits.replace(offset - prefix.length(), offset, fqName);
|
||||
// if (fqName.startsWith(prefix)) {
|
||||
// edits.insert(offset, fqName.substring(prefix.length()));
|
||||
// } else {
|
||||
// edits.replace(offset - prefix.length(), offset, fqName);
|
||||
// }
|
||||
|
||||
Renderable renderable = null;
|
||||
|
||||
String filterText = prefix;
|
||||
|
||||
return new GenericXMLCompletionProposal(label, kind, edits, fqName, renderable, proposal.getRelevance());
|
||||
return new GenericXMLCompletionProposal(label, kind, edits, fqName, renderable, proposal.getRelevance(), filterText, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user