Skip to content

Commit

Permalink
switch xml bean ref content-assist to new index
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlippert committed Dec 20, 2024
1 parent 617bc6c commit d81feb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ SpringProcessConnectorRemote localAppsFromCommandsConnector(SimpleLanguageServer
return new JdtReconciler(cuCache, config, reconcilers, projectObserver);
}

@Bean SpringXMLCompletionEngine xmlCompletionEngine(SimpleLanguageServer server, JavaProjectFinder projectFinder, SpringSymbolIndex symbolIndex, BootJavaConfig config) {
return new SpringXMLCompletionEngine(server, projectFinder, symbolIndex, config);
@Bean SpringXMLCompletionEngine xmlCompletionEngine(SimpleLanguageServer server, JavaProjectFinder projectFinder, SpringSymbolIndex symbolIndex, SpringMetamodelIndex springIndex, BootJavaConfig config) {
return new SpringXMLCompletionEngine(server, projectFinder, symbolIndex, springIndex, config);
}

@Bean SpringPropertiesCompletionEngine propertiesCompletionEngine(BootLanguageServerParams params, JavaProjectFinder projectFinder, SourceLinks sourceLinks, BootJavaConfig config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.eclipse.lsp4j.CompletionItemKind;
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.boot.xml.completions.BeanRefCompletionProposalProvider;
import org.springframework.ide.vscode.boot.xml.completions.ConstructorArgNameCompletionProposalProvider;
import org.springframework.ide.vscode.boot.xml.completions.GenericXMLCompletionProposal;
Expand Down Expand Up @@ -91,7 +92,8 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
public SpringXMLCompletionEngine(
SimpleLanguageServer server,
JavaProjectFinder projectFinder,
SpringSymbolIndex symbolIndex,
SpringSymbolIndex symbolIndex,
SpringMetamodelIndex springIndex,
BootJavaConfig config
) {

Expand All @@ -102,7 +104,7 @@ public SpringXMLCompletionEngine(
TypeCompletionProposalProvider classesAndInterfacesProvider = new TypeCompletionProposalProvider(server, projectFinder, true, true, true, false);
TypeCompletionProposalProvider packagesProvider = new TypeCompletionProposalProvider(server, projectFinder, true, false, false, false);

BeanRefCompletionProposalProvider beanRefProvider = new BeanRefCompletionProposalProvider(projectFinder, symbolIndex);
BeanRefCompletionProposalProvider beanRefProvider = new BeanRefCompletionProposalProvider(projectFinder, springIndex);
PropertyNameCompletionProposalProvider propertyNameProvider = new PropertyNameCompletionProposalProvider(projectFinder);
ConstructorArgNameCompletionProposalProvider constructorArgNameProvider = new ConstructorArgNameCompletionProposalProvider(projectFinder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.xml.completions;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand All @@ -19,15 +20,14 @@
import org.eclipse.lemminx.dom.DOMNode;
import org.eclipse.lemminx.dom.parser.Scanner;
import org.eclipse.lsp4j.CompletionItemKind;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
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.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
import org.springframework.ide.vscode.commons.util.Renderable;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
Expand All @@ -40,11 +40,11 @@
public class BeanRefCompletionProposalProvider implements XMLCompletionProvider {

private final JavaProjectFinder projectFinder;
private final SpringSymbolIndex symbolIndex;
private final SpringMetamodelIndex index;

public BeanRefCompletionProposalProvider(JavaProjectFinder projectFinder, SpringSymbolIndex symbolIndex) {
public BeanRefCompletionProposalProvider(JavaProjectFinder projectFinder, SpringMetamodelIndex index) {
this.projectFinder = projectFinder;
this.symbolIndex = symbolIndex;
this.index = index;
}

@Override
Expand All @@ -66,11 +66,9 @@ public InternalCompletionList getCompletions(TextDocument doc, String namespace,

final String searchPrefix = prefix;

List<SymbolAddOnInformation> addonInfos = symbolIndex.getAllAdditionalInformation(addonInfo -> addonInfo instanceof BeansSymbolAddOnInformation);

List<ICompletionProposal> completionItems = addonInfos.stream()
.map(info -> (BeansSymbolAddOnInformation) info)
.map(beanInfo -> beanInfo.getBeanID())
Bean[] beansOfProject = this.index.getBeansOfProject(project.getElementName());
List<ICompletionProposal> completionItems = Arrays.stream(beansOfProject)
.map(bean -> bean.getName())
.filter(beanID -> beanID != null && beanID.length() > 0)
.map(beanID -> Tuples.of(beanID, FuzzyMatcher.matchScore(searchPrefix, beanID)))
.filter(tuple -> tuple.getT2() != 0.0)
Expand Down

0 comments on commit d81feb0

Please sign in to comment.