Skip to content

Commit

Permalink
Bean completion invocation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Feb 26, 2025
1 parent f78a41a commit 2512212
Show file tree
Hide file tree
Showing 16 changed files with 284 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Pivotal, Inc.
* Copyright (c) 2016, 2025 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
Expand All @@ -15,7 +15,7 @@

import org.springframework.ide.vscode.commons.util.Assert;

public abstract class ScoreableProposal implements ICompletionProposal {
public abstract class AbstractScoreableProposal implements ICompletionProposalWithScore {

public static final double DEEMP_EXISTS = 0.1;
public static final double DEEMP_DEPRECATION = 0.2;
Expand All @@ -34,21 +34,21 @@ public abstract class ScoreableProposal implements ICompletionProposal {
public static final Comparator<ICompletionProposal> COMPARATOR = new Comparator<ICompletionProposal>() {
@Override
public int compare(ICompletionProposal p1, ICompletionProposal p2) {
if (p1 instanceof ScoreableProposal && p2 instanceof ScoreableProposal) {
double s1 = ((ScoreableProposal)p1).getScore();
double s2 = ((ScoreableProposal)p2).getScore();
if (p1 instanceof ICompletionProposalWithScore && p2 instanceof ICompletionProposalWithScore) {
double s1 = ((ICompletionProposalWithScore)p1).getScore();
double s2 = ((ICompletionProposalWithScore)p2).getScore();
if (s1 == s2) {
String name1 = ((ScoreableProposal)p1).getLabel();
String name2 = ((ScoreableProposal)p2).getLabel();
String name1 = ((ICompletionProposalWithScore)p1).getLabel();
String name2 = ((ICompletionProposalWithScore)p2).getLabel();
return name1.compareTo(name2);
} else {
return Double.compare(s2, s1);
}
}
if (p1 instanceof ScoreableProposal) {
if (p1 instanceof ICompletionProposalWithScore) {
return -1;
}
if (p2 instanceof ScoreableProposal) {
if (p2 instanceof ICompletionProposalWithScore) {
return +1;
}
return p1.getLabel().compareTo(p2.getLabel());
Expand All @@ -59,7 +59,7 @@ public final double getScore() {
return getBaseScore() - deemphasizedBy;
}
@Override
public ScoreableProposal deemphasize(double howmuch) {
public AbstractScoreableProposal deemphasize(double howmuch) {
Assert.isLegal(howmuch>=0.0);
deemphasizedBy+= howmuch*DEEMP_VALUE;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2025 Broadcom, 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:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.languageserver.completion;

public interface ICompletionProposalWithScore extends ICompletionProposal {

double getScore();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2023 Pivotal, Inc.
* Copyright (c) 2017, 2025 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
Expand All @@ -23,7 +23,7 @@
*
* @author Kris De Volder
*/
public abstract class TransformedCompletion extends ScoreableProposal {
public abstract class TransformedCompletion extends AbstractScoreableProposal {

protected final ICompletionProposal original;

Expand Down Expand Up @@ -71,8 +71,8 @@ public String getDetail() {

@Override
public double getBaseScore() {
if (original instanceof ScoreableProposal) {
return ((ScoreableProposal) original).getScore();
if (original instanceof AbstractScoreableProposal) {
return ((AbstractScoreableProposal) original).getScore();
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2023 VMware Inc.
* Copyright (c) 2016, 2025 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
Expand Down Expand Up @@ -218,7 +218,7 @@ public CompletionList getCompletions(CancelChecker cancelToken, TextDocumentPosi
cancelToken.checkCanceled();

List<ICompletionProposal> completions = filter(rawCompletionList.completionItems());
Collections.sort(completions, ScoreableProposal.COMPARATOR);
Collections.sort(completions, AbstractScoreableProposal.COMPARATOR);

cancelToken.checkCanceled();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Pivotal, Inc.
* Copyright (c) 2016, 2025 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
Expand All @@ -14,7 +14,7 @@
import org.eclipse.lsp4j.CompletionItemKind;
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.ScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
import org.springframework.ide.vscode.commons.util.Renderable;
import org.springframework.ide.vscode.commons.util.Renderables;
import org.springframework.ide.vscode.commons.util.text.IDocument;
Expand All @@ -27,7 +27,7 @@ public class DefaultCompletionFactory implements CompletionFactory {

private static final int ERROR_COMPLETION_SCORE = -10000000;

public static class BeanPropertyProposal extends ScoreableProposal {
public static class BeanPropertyProposal extends AbstractScoreableProposal {

// private IDocument doc;
private String contextProperty;
Expand Down Expand Up @@ -81,7 +81,7 @@ public Renderable getDocumentation() {
}
}

public class ValueProposal extends ScoreableProposal {
public class ValueProposal extends AbstractScoreableProposal {

private String value;
private String label;
Expand Down Expand Up @@ -137,7 +137,7 @@ public Renderable getDocumentation() {
}
}

public static final class ErrorProposal extends ScoreableProposal {
public static final class ErrorProposal extends AbstractScoreableProposal {
private final String longMessage;
private String shortMessage;
private String filterText;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2019 Pivotal, Inc.
* Copyright (c) 2016, 2025 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
Expand All @@ -10,8 +10,8 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.yaml.completion;

import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DASH_PROPOSAL;
import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DEPRECATION;
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_DASH_PROPOSAL;
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_DEPRECATION;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -25,7 +25,7 @@
import org.slf4j.LoggerFactory;
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.ScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
import org.springframework.ide.vscode.commons.languageserver.util.PlaceHolderString;
import org.springframework.ide.vscode.commons.util.CollectionUtil;
Expand Down Expand Up @@ -206,7 +206,7 @@ public List<ICompletionProposal> getKeyCompletions(YamlDocument doc, SNode node,
ICompletionProposal completion = completionFactory().beanProperty(doc.getDocument(),
contextPath.toPropString(), getType(),
query, p, score, edits, typeUtil);
if (p.isDeprecated() && completion instanceof ScoreableProposal) {
if (p.isDeprecated() && completion instanceof AbstractScoreableProposal) {
completion.deemphasize(DEEMP_DEPRECATION);
}
proposals.add(completion);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2024 Pivotal, Inc.
* Copyright (c) 2016, 2025 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
Expand All @@ -10,8 +10,8 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.yaml.completion;

import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DEDENTED_PROPOSAL;
import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_INDENTED_PROPOSAL;
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_DEDENTED_PROPOSAL;
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_INDENTED_PROPOSAL;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -26,7 +26,7 @@
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.AbstractScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
import org.springframework.ide.vscode.commons.util.Assert;
import org.springframework.ide.vscode.commons.util.Unicodes;
Expand Down Expand Up @@ -97,7 +97,7 @@ public InternalCompletionList getCompletions(TextDocument _doc, int offset) thro
double deempasizeBy = 0.0;
for (SNode contextNode : contextNodes) {
completions.addAll(getRelaxedCompletions(offset, doc, current, contextNode, baseIndent, deempasizeBy));
deempasizeBy += ScoreableProposal.DEEMP_NEXT_CONTEXT;
deempasizeBy += AbstractScoreableProposal.DEEMP_NEXT_CONTEXT;
}
return new InternalCompletionList(completions, false);
} else {
Expand Down Expand Up @@ -129,7 +129,7 @@ protected Collection<? extends ICompletionProposal> fixIndentations(Collection<I
List<ICompletionProposal> transformed = new ArrayList<>();
for (ICompletionProposal p : completions) {
int targetIndent = p.getLabel().startsWith("- ") ? dashyIndent : plainIndent;
ScoreableProposal p_fixed = indentFix((ScoreableProposal)p, targetIndent - baseIndent, currentNode, contextNode, doc);
AbstractScoreableProposal p_fixed = indentFix((AbstractScoreableProposal)p, targetIndent - baseIndent, currentNode, contextNode, doc);
if (p_fixed!=null) {
p_fixed.deemphasize(deempasizeBy);
transformed.add(p_fixed);
Expand All @@ -140,7 +140,7 @@ protected Collection<? extends ICompletionProposal> fixIndentations(Collection<I
return Collections.emptyList();
}

protected ScoreableProposal indentFix(ScoreableProposal p, int fixIndentBy, SNode currentNode, SNode contextNode, YamlDocument doc) {
protected AbstractScoreableProposal indentFix(AbstractScoreableProposal p, int fixIndentBy, SNode currentNode, SNode contextNode, YamlDocument doc) {
if (fixIndentBy==0) {
return p;
} else if (fixIndentBy>0) {
Expand Down Expand Up @@ -190,15 +190,15 @@ private int getTargetIndent(SNode contextNode, SNode currentNode, boolean dashy)
: contextNode.getIndent() + YamlIndentUtil.INDENT_BY;
}

public ScoreableProposal dedented(ICompletionProposal proposal, int numSpacesToRemove, IDocument doc) {
public AbstractScoreableProposal dedented(ICompletionProposal proposal, int numSpacesToRemove, IDocument doc) {
Assert.isLegal(numSpacesToRemove>0);
int spacesEnd = proposal.getTextEdit().getFirstEditStart();
int spacesStart = spacesEnd-numSpacesToRemove;
int numArrows = numSpacesToRemove / YamlIndentUtil.INDENT_BY;
String spaces = new DocumentRegion(doc, spacesStart, spacesEnd).toString();
YamlIndentUtil indenter = new YamlIndentUtil(doc);
if (spaces.length()==numSpacesToRemove && SPACES.matcher(spaces).matches()) {
ScoreableProposal transformed = new TransformedCompletion(proposal) {
AbstractScoreableProposal transformed = new TransformedCompletion(proposal) {
@Override public String tranformLabel(String originalLabel) {
return Strings.repeat(Unicodes.LEFT_ARROW+" ", numArrows) + originalLabel;
}
Expand Down Expand Up @@ -228,9 +228,9 @@ public String getFilterText() {
return null;
}

public ScoreableProposal indented(ICompletionProposal proposal, String indentStr, YamlDocument doc) {
public AbstractScoreableProposal indented(ICompletionProposal proposal, String indentStr, YamlDocument doc) {
int numArrows = (indentStr.length()+1)/2;
ScoreableProposal transformed = new TransformedCompletion(proposal) {
AbstractScoreableProposal transformed = new TransformedCompletion(proposal) {
@Override public String tranformLabel(String originalLabel) {
return Strings.repeat(Unicodes.RIGHT_ARROW+" ", numArrows) + originalLabel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2023 Pivotal, Inc.
* Copyright (c) 2015, 2025 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
Expand All @@ -12,11 +12,11 @@

import org.eclipse.lsp4j.CompletionItemKind;
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
import org.springframework.ide.vscode.commons.util.text.IDocument;
import org.springframework.ide.vscode.commons.yaml.schema.YType;

public abstract class AbstractPropertyProposal extends ScoreableProposal {
public abstract class AbstractPropertyProposal extends AbstractScoreableProposal {

@Override
public String getDetail() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 Pivotal, Inc.
* Copyright (c) 2014, 2025 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
Expand All @@ -18,7 +18,7 @@
import org.springframework.ide.vscode.boot.metadata.types.TypedProperty;
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.ScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
import org.springframework.ide.vscode.commons.util.FuzzyMap.Match;
import org.springframework.ide.vscode.commons.util.Renderable;
import org.springframework.ide.vscode.commons.util.text.IDocument;
Expand All @@ -28,7 +28,7 @@
public class PropertyCompletionFactory {

public ICompletionProposal valueProposal(String value, String query, String niceTypeName, double score, DocumentEdits edits, Renderable info) {
return new ScoreableProposal() {
return new AbstractScoreableProposal() {

@Override
public DocumentEdits getTextEdit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom
* Copyright (c) 2024, 2025 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
Expand All @@ -12,13 +12,13 @@

import org.eclipse.lsp4j.CompletionItemKind;
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
import org.springframework.ide.vscode.commons.util.Renderable;

/**
* @author Martin Lippert
*/
public class AnnotationAttributeCompletionProposal extends ScoreableProposal {
public class AnnotationAttributeCompletionProposal extends AbstractScoreableProposal {

private final AnnotationAttributeProposal coreProposal;

Expand Down
Loading

0 comments on commit 2512212

Please sign in to comment.