mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[jvm-execution] show VM option completion variants if key partially entered (IDEA-318049)
GitOrigin-RevId: 9e2174e3727b39024b97e63671fe19ecf9eeeaa1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
60f56ba634
commit
78152cd461
@@ -36,6 +36,7 @@ import java.util.stream.Stream;
|
||||
public class VmOptionsCompletionContributor extends CompletionContributor implements DumbAware {
|
||||
private static final Pattern OPTION_SEPARATOR = Pattern.compile("\\s+");
|
||||
private static final Pattern OPTION_MATCHER = Pattern.compile("^-XX:[+\\-]?(\\w+)(=.+)?$");
|
||||
private static final char OPTION_VALUE_SEPRATOR = '=';
|
||||
|
||||
private static final VMOption[] STANDARD_OPTIONS = {
|
||||
opt("ea", "enable assertions with specified granularity"),
|
||||
@@ -50,7 +51,7 @@ public class VmOptionsCompletionContributor extends CompletionContributor implem
|
||||
opt("D", "set a system property in format <name>=<value>"),
|
||||
opt("XX:", "specify non-standard JVM-specific option")
|
||||
};
|
||||
|
||||
|
||||
private static VMOption opt(@NotNull String name, @NotNull String doc) {
|
||||
return new VMOption(name, null, null, VMOptionKind.Standard, doc, VMOptionVariant.DASH);
|
||||
}
|
||||
@@ -69,39 +70,41 @@ public class VmOptionsCompletionContributor extends CompletionContributor implem
|
||||
offset--;
|
||||
}
|
||||
JavaRunConfigurationBase settings = document.getUserData(VmOptionsEditor.SETTINGS_KEY);
|
||||
if (addXxCompletion(result, data, offset, currentText) || addSimpleOptions(result, settings, data, offset, currentText)) {
|
||||
if (addXxCompletion(result, data, offset, currentText) ||
|
||||
addSimpleOptions(result, settings, data, parameters.getOffset(), currentText)) {
|
||||
result.stopHere();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean addSimpleOptions(@NotNull CompletionResultSet result,
|
||||
@Nullable JavaRunConfigurationBase settings,
|
||||
@Nullable JavaRunConfigurationBase settings,
|
||||
@NotNull JdkOptionsData data,
|
||||
int offset,
|
||||
@NotNull String text) {
|
||||
String[] prefixes = {"--", "-", ""};
|
||||
for (String prefix : prefixes) {
|
||||
if (hasOptionPrefix(text, offset, prefix)) {
|
||||
addDashOptions(result, settings, data, prefix);
|
||||
return true;
|
||||
int optionStart = offset;
|
||||
while (optionStart > 0 && !Character.isWhitespace(text.charAt(optionStart - 1))) {
|
||||
if (text.charAt(optionStart - 1) == OPTION_VALUE_SEPRATOR) {
|
||||
return false;
|
||||
}
|
||||
optionStart--;
|
||||
}
|
||||
return false;
|
||||
String optionText = text.substring(optionStart, offset);
|
||||
result = result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(optionText));
|
||||
addDashOptions(result, settings, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void addDashOptions(@NotNull CompletionResultSet result,
|
||||
@Nullable JavaRunConfigurationBase settings,
|
||||
@NotNull JdkOptionsData data, String prefix) {
|
||||
@NotNull JdkOptionsData data) {
|
||||
Stream.of(
|
||||
data.getOptions().stream().filter(option1 -> option1.getVariant() != VMOptionVariant.XX),
|
||||
Stream.of(STANDARD_OPTIONS),
|
||||
Stream.of(STANDARD_OPTIONS),
|
||||
settings == null ? null : settings.getKnownVMOptions().stream())
|
||||
.flatMap(Function.identity())
|
||||
.forEach(option -> {
|
||||
String fullLookup = option.getVariant().prefix() + option.getOptionName();
|
||||
if (!fullLookup.startsWith(prefix)) return;
|
||||
String lookup = fullLookup.substring(prefix.length());
|
||||
result.addElement(LookupElementBuilder.create(option.createPointer(), lookup + option.getVariant().suffix())
|
||||
result.addElement(LookupElementBuilder.create(option.createPointer(), fullLookup + option.getVariant().suffix())
|
||||
.withTypeText(option.getType())
|
||||
.withPresentableText(fullLookup));
|
||||
});
|
||||
|
||||
@@ -36,19 +36,41 @@ public class VmOptionsCompletionContributorTest extends LightPlatformCodeInsight
|
||||
public void testSimpleOptions() {
|
||||
configure("-<caret>");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("-add-exports", "-add-opens",
|
||||
"agentlib:", "agentpath:", "D", "da", "disableassertions", "Djava.awt.headless=",
|
||||
"dsa", "Duser.dir=", "Duser.home=", "Duser.name=", "ea", "enableassertions", "esa",
|
||||
"javaagent:", "Xmx", "XX:"), myFixture.getLookupElementStrings());
|
||||
assertEquals(List.of("--add-exports", "--add-opens",
|
||||
"-agentlib:", "-agentpath:", "-D", "-da", "-disableassertions", "-Djava.awt.headless=",
|
||||
"-dsa", "-Duser.dir=", "-Duser.home=", "-Duser.name=", "-ea", "-enableassertions", "-esa",
|
||||
"-javaagent:", "-Xmx", "-XX:"), myFixture.getLookupElementStrings());
|
||||
checkPresentation(myFixture.getLookupElements()[0], "--add-exports|null/null");
|
||||
checkPresentation(myFixture.getLookupElements()[2], "-agentlib:|null/null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleOptionsAfterDot() {
|
||||
configure("-Duser.<caret>");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("-Duser.dir=", "-Duser.home=", "-Duser.name="), myFixture.getLookupElementStrings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleOptionsAfterDash() {
|
||||
configure("-add-<caret>");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("--add-exports", "--add-opens"), myFixture.getLookupElementStrings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleOptionsBeforeAnother() {
|
||||
configure("-<caret> -ea");
|
||||
myFixture.completeBasic();
|
||||
List<String> strings = myFixture.getLookupElementStrings();
|
||||
assertContainsElements(strings, "-Duser.dir=", "-Duser.home=", "-Duser.name=");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleDash() {
|
||||
configure("--<caret>");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("add-exports", "add-opens"), myFixture.getLookupElementStrings());
|
||||
assertEquals(List.of("--add-exports", "--add-opens"), myFixture.getLookupElementStrings());
|
||||
checkPresentation(myFixture.getLookupElements()[0], "--add-exports|null/null");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user