Skip to content

Fixed duplicate results in YAML service name completion #1928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public ServiceYamlReference(@NotNull PsiElement psiElement, @NotNull TextRange r

this.serviceId = serviceId;
}

@Override
public @NotNull Object[] getVariants() {
return new Object[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.stream.Collectors;

import static java.util.function.Function.identity;

/**
* @author Daniel Espendiller <[email protected]>
Expand Down Expand Up @@ -87,6 +90,30 @@ public void assertCompletionNotContains(String filename, String configureByText,
assertFalse(myFixture.getLookupElementStrings().containsAll(Arrays.asList(lookupStrings)));
}


public void assertCompletionResultsAreUnique(
@NotNull LanguageFileType languageFileType,
@NotNull String configureByText,
@NotNull String... lookupStrings
) {
myFixture.configureByText(languageFileType, configureByText);
myFixture.completeBasic();

var results = myFixture.getLookupElementStrings();
if (results != null) {
var duplicates = results.stream()
.filter(result -> Arrays.asList(lookupStrings).contains(result))
.collect(Collectors.groupingBy(identity()))
.entrySet()
.stream()
.filter(result -> result.getValue().size() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toList());

assertTrue("The following results are duplicated: " + String.join(", ", duplicates), duplicates.isEmpty());
}
}

public void assertCompletionNotContains(LanguageFileType languageFileType, String configureByText, String... lookupStrings) {

myFixture.configureByText(languageFileType, configureByText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public void testServiceCompletion() {
);
}

public void testServiceCompletionResultsAreUnique() {
assertCompletionResultsAreUnique(
YAMLFileType.YML,
"services:\n" +
" newsletter_manager:\n" +
" parent: <caret>\n",
"data_collector.router"
);
}

public void testServiceStaticCompletion() {

assertCompletionContains(YAMLFileType.YML, "services:\n" +
Expand Down