Skip to content

Commit

Permalink
GH-1471: do not filter bean proposals on the language server side
Browse files Browse the repository at this point in the history
Fixes GH-1471
  • Loading branch information
martinlippert committed Feb 6, 2025
1 parent c28c6d8 commit edbf870
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Broadcom, Inc.
* Copyright (c) 2017, 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
Expand Down Expand Up @@ -30,7 +30,6 @@
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
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.text.TextDocument;

/**
Expand Down Expand Up @@ -79,15 +78,13 @@ public void provideCompletions(ASTNode node, int offset, TextDocument doc,
String className = getFullyQualifiedName(topLevelClass);
Bean[] beans = this.springIndex.getBeansOfProject(project.getElementName());
for (Bean bean : beans) {
if (FuzzyMatcher.matchScore(node.toString(), bean.getName()) != 0.0) {
DocumentEdits edits = new DocumentEdits(doc, false);
edits.replace(offset - node.toString().length(), offset, bean.getName());

BeanCompletionProposal proposal = new BeanCompletionProposal(edits, doc, bean.getName(),
bean.getType(), className, rewriteRefactorings);

completions.add(proposal);
}
DocumentEdits edits = new DocumentEdits(doc, false);
edits.replace(offset - node.toString().length(), offset, bean.getName());

BeanCompletionProposal proposal = new BeanCompletionProposal(edits, doc, bean.getName(),
bean.getType(), className, rewriteRefactorings);

completions.add(proposal);
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Broadcom, Inc.
* Copyright (c) 2017, 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
Expand Down Expand Up @@ -96,8 +96,8 @@ public void restoreIndexState() {
}

@Test
public void testBeanCompletion_withMatches() throws Exception {
assertCompletions(getCompletion("owner<*>"), new String[] {"ownerRepository", "ownerService"}, 0,
public void testBeanCompletion_firstCompletion() throws Exception {
assertCompletions(getCompletion("owner<*>"), new String[] {"ownerRepository", "ownerService", "petService", "visitRepository", "visitService"}, 0,
"""
package org.sample.test;
Expand All @@ -121,13 +121,8 @@ public void test() {
}

@Test
public void testBeanCompletion_withoutMatches() throws Exception {
assertCompletions(getCompletion("rand<*>"), new String[] {}, 0, "");
}

@Test
public void testBeanCompletion_chooseSecondCompletion() throws Exception {
assertCompletions(getCompletion("owner<*>"), new String[] {"ownerRepository", "ownerService"}, 1,
public void testBeanCompletion_secondCompletion() throws Exception {
assertCompletions(getCompletion("owner<*>"), new String[] {"ownerRepository", "ownerService", "petService", "visitRepository", "visitService"}, 1,
"""
package org.sample.test;
Expand All @@ -152,7 +147,7 @@ public void test() {

@Test
public void testBeanCompletion_injectInnerClass() throws Exception {
assertCompletions(getCompletion("pet<*>"), new String[] {"petService"}, 0,
assertCompletions(getCompletion("owner<*>"), new String[] {"ownerRepository", "ownerService", "petService", "visitRepository", "visitService"}, 2,
"""
package org.sample.test;
Expand Down Expand Up @@ -204,7 +199,7 @@ public void test() {
}
""";

assertCompletions(content, new String[] {"ownerRepository", "ownerService"}, 1,
assertCompletions(content, new String[] {"ownerRepository", "ownerService", "petService", "visitRepository", "visitService"}, 1,
"""
package org.sample.test;
Expand Down Expand Up @@ -290,7 +285,7 @@ public void test() {
}
""";

assertCompletions(content, new String[] {"ownerRepository"}, 0,
assertCompletions(content, new String[] {"ownerRepository", "ownerService", "petService", "visitRepository", "visitService"}, 0,
"""
package org.sample.test;
Expand Down

0 comments on commit edbf870

Please sign in to comment.