Skip to content

Commit 2512212

Browse files
committed
Bean completion invocation fixes
1 parent f78a41a commit 2512212

File tree

16 files changed

+284
-76
lines changed

16 files changed

+284
-76
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2017 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -15,7 +15,7 @@
1515

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

18-
public abstract class ScoreableProposal implements ICompletionProposal {
18+
public abstract class AbstractScoreableProposal implements ICompletionProposalWithScore {
1919

2020
public static final double DEEMP_EXISTS = 0.1;
2121
public static final double DEEMP_DEPRECATION = 0.2;
@@ -34,21 +34,21 @@ public abstract class ScoreableProposal implements ICompletionProposal {
3434
public static final Comparator<ICompletionProposal> COMPARATOR = new Comparator<ICompletionProposal>() {
3535
@Override
3636
public int compare(ICompletionProposal p1, ICompletionProposal p2) {
37-
if (p1 instanceof ScoreableProposal && p2 instanceof ScoreableProposal) {
38-
double s1 = ((ScoreableProposal)p1).getScore();
39-
double s2 = ((ScoreableProposal)p2).getScore();
37+
if (p1 instanceof ICompletionProposalWithScore && p2 instanceof ICompletionProposalWithScore) {
38+
double s1 = ((ICompletionProposalWithScore)p1).getScore();
39+
double s2 = ((ICompletionProposalWithScore)p2).getScore();
4040
if (s1 == s2) {
41-
String name1 = ((ScoreableProposal)p1).getLabel();
42-
String name2 = ((ScoreableProposal)p2).getLabel();
41+
String name1 = ((ICompletionProposalWithScore)p1).getLabel();
42+
String name2 = ((ICompletionProposalWithScore)p2).getLabel();
4343
return name1.compareTo(name2);
4444
} else {
4545
return Double.compare(s2, s1);
4646
}
4747
}
48-
if (p1 instanceof ScoreableProposal) {
48+
if (p1 instanceof ICompletionProposalWithScore) {
4949
return -1;
5050
}
51-
if (p2 instanceof ScoreableProposal) {
51+
if (p2 instanceof ICompletionProposalWithScore) {
5252
return +1;
5353
}
5454
return p1.getLabel().compareTo(p2.getLabel());
@@ -59,7 +59,7 @@ public final double getScore() {
5959
return getBaseScore() - deemphasizedBy;
6060
}
6161
@Override
62-
public ScoreableProposal deemphasize(double howmuch) {
62+
public AbstractScoreableProposal deemphasize(double howmuch) {
6363
Assert.isLegal(howmuch>=0.0);
6464
deemphasizedBy+= howmuch*DEEMP_VALUE;
6565
return this;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.commons.languageserver.completion;
12+
13+
public interface ICompletionProposalWithScore extends ICompletionProposal {
14+
15+
double getScore();
16+
17+
}

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/completion/TransformedCompletion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2023 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -23,7 +23,7 @@
2323
*
2424
* @author Kris De Volder
2525
*/
26-
public abstract class TransformedCompletion extends ScoreableProposal {
26+
public abstract class TransformedCompletion extends AbstractScoreableProposal {
2727

2828
protected final ICompletionProposal original;
2929

@@ -71,8 +71,8 @@ public String getDetail() {
7171

7272
@Override
7373
public double getBaseScore() {
74-
if (original instanceof ScoreableProposal) {
75-
return ((ScoreableProposal) original).getScore();
74+
if (original instanceof AbstractScoreableProposal) {
75+
return ((AbstractScoreableProposal) original).getScore();
7676
}
7777
return 0;
7878
}

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/completion/VscodeCompletionEngineAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2023 VMware Inc.
2+
* Copyright (c) 2016, 2025 VMware Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -218,7 +218,7 @@ public CompletionList getCompletions(CancelChecker cancelToken, TextDocumentPosi
218218
cancelToken.checkCanceled();
219219

220220
List<ICompletionProposal> completions = filter(rawCompletionList.completionItems());
221-
Collections.sort(completions, ScoreableProposal.COMPARATOR);
221+
Collections.sort(completions, AbstractScoreableProposal.COMPARATOR);
222222

223223
cancelToken.checkCanceled();
224224

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/DefaultCompletionFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2017 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -14,7 +14,7 @@
1414
import org.eclipse.lsp4j.CompletionItemKind;
1515
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
1616
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
17-
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
17+
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
1818
import org.springframework.ide.vscode.commons.util.Renderable;
1919
import org.springframework.ide.vscode.commons.util.Renderables;
2020
import org.springframework.ide.vscode.commons.util.text.IDocument;
@@ -27,7 +27,7 @@ public class DefaultCompletionFactory implements CompletionFactory {
2727

2828
private static final int ERROR_COMPLETION_SCORE = -10000000;
2929

30-
public static class BeanPropertyProposal extends ScoreableProposal {
30+
public static class BeanPropertyProposal extends AbstractScoreableProposal {
3131

3232
// private IDocument doc;
3333
private String contextProperty;
@@ -81,7 +81,7 @@ public Renderable getDocumentation() {
8181
}
8282
}
8383

84-
public class ValueProposal extends ScoreableProposal {
84+
public class ValueProposal extends AbstractScoreableProposal {
8585

8686
private String value;
8787
private String label;
@@ -137,7 +137,7 @@ public Renderable getDocumentation() {
137137
}
138138
}
139139

140-
public static final class ErrorProposal extends ScoreableProposal {
140+
public static final class ErrorProposal extends AbstractScoreableProposal {
141141
private final String longMessage;
142142
private String shortMessage;
143143
private String filterText;

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/YTypeAssistContext.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2019 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -10,8 +10,8 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.yaml.completion;
1212

13-
import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DASH_PROPOSAL;
14-
import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DEPRECATION;
13+
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_DASH_PROPOSAL;
14+
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_DEPRECATION;
1515

1616
import java.util.ArrayList;
1717
import java.util.Collection;
@@ -25,7 +25,7 @@
2525
import org.slf4j.LoggerFactory;
2626
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
2727
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
28-
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
28+
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
2929
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
3030
import org.springframework.ide.vscode.commons.languageserver.util.PlaceHolderString;
3131
import org.springframework.ide.vscode.commons.util.CollectionUtil;
@@ -206,7 +206,7 @@ public List<ICompletionProposal> getKeyCompletions(YamlDocument doc, SNode node,
206206
ICompletionProposal completion = completionFactory().beanProperty(doc.getDocument(),
207207
contextPath.toPropString(), getType(),
208208
query, p, score, edits, typeUtil);
209-
if (p.isDeprecated() && completion instanceof ScoreableProposal) {
209+
if (p.isDeprecated() && completion instanceof AbstractScoreableProposal) {
210210
completion.deemphasize(DEEMP_DEPRECATION);
211211
}
212212
proposals.add(completion);

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/YamlCompletionEngine.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2024 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -10,8 +10,8 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.yaml.completion;
1212

13-
import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DEDENTED_PROPOSAL;
14-
import static org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_INDENTED_PROPOSAL;
13+
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_DEDENTED_PROPOSAL;
14+
import static org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal.DEEMP_INDENTED_PROPOSAL;
1515

1616
import java.util.ArrayList;
1717
import java.util.Collection;
@@ -26,7 +26,7 @@
2626
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
2727
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
2828
import org.springframework.ide.vscode.commons.languageserver.completion.InternalCompletionList;
29-
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
29+
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
3030
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
3131
import org.springframework.ide.vscode.commons.util.Assert;
3232
import org.springframework.ide.vscode.commons.util.Unicodes;
@@ -97,7 +97,7 @@ public InternalCompletionList getCompletions(TextDocument _doc, int offset) thro
9797
double deempasizeBy = 0.0;
9898
for (SNode contextNode : contextNodes) {
9999
completions.addAll(getRelaxedCompletions(offset, doc, current, contextNode, baseIndent, deempasizeBy));
100-
deempasizeBy += ScoreableProposal.DEEMP_NEXT_CONTEXT;
100+
deempasizeBy += AbstractScoreableProposal.DEEMP_NEXT_CONTEXT;
101101
}
102102
return new InternalCompletionList(completions, false);
103103
} else {
@@ -129,7 +129,7 @@ protected Collection<? extends ICompletionProposal> fixIndentations(Collection<I
129129
List<ICompletionProposal> transformed = new ArrayList<>();
130130
for (ICompletionProposal p : completions) {
131131
int targetIndent = p.getLabel().startsWith("- ") ? dashyIndent : plainIndent;
132-
ScoreableProposal p_fixed = indentFix((ScoreableProposal)p, targetIndent - baseIndent, currentNode, contextNode, doc);
132+
AbstractScoreableProposal p_fixed = indentFix((AbstractScoreableProposal)p, targetIndent - baseIndent, currentNode, contextNode, doc);
133133
if (p_fixed!=null) {
134134
p_fixed.deemphasize(deempasizeBy);
135135
transformed.add(p_fixed);
@@ -140,7 +140,7 @@ protected Collection<? extends ICompletionProposal> fixIndentations(Collection<I
140140
return Collections.emptyList();
141141
}
142142

143-
protected ScoreableProposal indentFix(ScoreableProposal p, int fixIndentBy, SNode currentNode, SNode contextNode, YamlDocument doc) {
143+
protected AbstractScoreableProposal indentFix(AbstractScoreableProposal p, int fixIndentBy, SNode currentNode, SNode contextNode, YamlDocument doc) {
144144
if (fixIndentBy==0) {
145145
return p;
146146
} else if (fixIndentBy>0) {
@@ -190,15 +190,15 @@ private int getTargetIndent(SNode contextNode, SNode currentNode, boolean dashy)
190190
: contextNode.getIndent() + YamlIndentUtil.INDENT_BY;
191191
}
192192

193-
public ScoreableProposal dedented(ICompletionProposal proposal, int numSpacesToRemove, IDocument doc) {
193+
public AbstractScoreableProposal dedented(ICompletionProposal proposal, int numSpacesToRemove, IDocument doc) {
194194
Assert.isLegal(numSpacesToRemove>0);
195195
int spacesEnd = proposal.getTextEdit().getFirstEditStart();
196196
int spacesStart = spacesEnd-numSpacesToRemove;
197197
int numArrows = numSpacesToRemove / YamlIndentUtil.INDENT_BY;
198198
String spaces = new DocumentRegion(doc, spacesStart, spacesEnd).toString();
199199
YamlIndentUtil indenter = new YamlIndentUtil(doc);
200200
if (spaces.length()==numSpacesToRemove && SPACES.matcher(spaces).matches()) {
201-
ScoreableProposal transformed = new TransformedCompletion(proposal) {
201+
AbstractScoreableProposal transformed = new TransformedCompletion(proposal) {
202202
@Override public String tranformLabel(String originalLabel) {
203203
return Strings.repeat(Unicodes.LEFT_ARROW+" ", numArrows) + originalLabel;
204204
}
@@ -228,9 +228,9 @@ public String getFilterText() {
228228
return null;
229229
}
230230

231-
public ScoreableProposal indented(ICompletionProposal proposal, String indentStr, YamlDocument doc) {
231+
public AbstractScoreableProposal indented(ICompletionProposal proposal, String indentStr, YamlDocument doc) {
232232
int numArrows = (indentStr.length()+1)/2;
233-
ScoreableProposal transformed = new TransformedCompletion(proposal) {
233+
AbstractScoreableProposal transformed = new TransformedCompletion(proposal) {
234234
@Override public String tranformLabel(String originalLabel) {
235235
return Strings.repeat(Unicodes.RIGHT_ARROW+" ", numArrows) + originalLabel;
236236
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/common/AbstractPropertyProposal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015, 2023 Pivotal, Inc.
2+
* Copyright (c) 2015, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,11 +12,11 @@
1212

1313
import org.eclipse.lsp4j.CompletionItemKind;
1414
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
15-
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
15+
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
1616
import org.springframework.ide.vscode.commons.util.text.IDocument;
1717
import org.springframework.ide.vscode.commons.yaml.schema.YType;
1818

19-
public abstract class AbstractPropertyProposal extends ScoreableProposal {
19+
public abstract class AbstractPropertyProposal extends AbstractScoreableProposal {
2020

2121
@Override
2222
public String getDetail() {

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/common/PropertyCompletionFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2014, 2023 Pivotal, Inc.
2+
* Copyright (c) 2014, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
1818
import org.springframework.ide.vscode.boot.metadata.types.TypedProperty;
1919
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
2020
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
21-
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
21+
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
2222
import org.springframework.ide.vscode.commons.util.FuzzyMap.Match;
2323
import org.springframework.ide.vscode.commons.util.Renderable;
2424
import org.springframework.ide.vscode.commons.util.text.IDocument;
@@ -28,7 +28,7 @@
2828
public class PropertyCompletionFactory {
2929

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

3333
@Override
3434
public DocumentEdits getTextEdit() {

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/annotations/AnnotationAttributeCompletionProposal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Broadcom
2+
* Copyright (c) 2024, 2025 Broadcom
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,13 +12,13 @@
1212

1313
import org.eclipse.lsp4j.CompletionItemKind;
1414
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
15-
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
15+
import org.springframework.ide.vscode.commons.languageserver.completion.AbstractScoreableProposal;
1616
import org.springframework.ide.vscode.commons.util.Renderable;
1717

1818
/**
1919
* @author Martin Lippert
2020
*/
21-
public class AnnotationAttributeCompletionProposal extends ScoreableProposal {
21+
public class AnnotationAttributeCompletionProposal extends AbstractScoreableProposal {
2222

2323
private final AnnotationAttributeProposal coreProposal;
2424

0 commit comments

Comments
 (0)