mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
[Java] Add support for -X options in java command in java completion
IDEA-359244 GitOrigin-RevId: 47c6a7439cead3aee7f412ff68924838b0300838
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8c804d1a9f
commit
69c61a1c86
@@ -11,5 +11,7 @@
|
||||
<orderEntry type="library" scope="PROVIDED" name="kotlin-stdlib" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.terminal" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="module" module-name="intellij.java.execution.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -9,4 +9,5 @@ java.command.terminal.classpath.option.description=Class search path of director
|
||||
java.command.terminal.classpath.option.argument.path.text=filepath[{0}filepath]
|
||||
java.command.terminal.show.version.option.description=Print the product version to the output stream and continue
|
||||
java.command.terminal.dry.run.option.description=Create VM and load the main class but do not execute the main method
|
||||
java.command.terminal.argument.main.class.text=mainclass
|
||||
java.command.terminal.argument.main.class.text=mainclass
|
||||
java.command.terminal.default.argument.text=value
|
||||
@@ -1,11 +1,18 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.terminal
|
||||
|
||||
import com.intellij.execution.vmOptions.VMOption
|
||||
import com.intellij.execution.vmOptions.VMOptionKind
|
||||
import com.intellij.execution.vmOptions.VMOptionVariant
|
||||
import com.intellij.execution.vmOptions.VMOptionsService
|
||||
import com.intellij.terminal.completion.spec.ShellCommandSpec
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpec
|
||||
import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecConflictStrategy
|
||||
import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecInfo
|
||||
import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecsProvider
|
||||
import org.jetbrains.plugins.terminal.block.completion.spec.dsl.ShellChildOptionsContext
|
||||
|
||||
class JavaShellCommandSpecsProvider : ShellCommandSpecsProvider {
|
||||
override fun getCommandSpecs(): List<ShellCommandSpecInfo> {
|
||||
@@ -14,6 +21,14 @@ class JavaShellCommandSpecsProvider : ShellCommandSpecsProvider {
|
||||
}
|
||||
|
||||
private fun getSpecs(): ShellCommandSpec = ShellCommandSpec("java") {
|
||||
dynamicOptions { _ ->
|
||||
val javaHomePath = System.getenv("JAVA_HOME") ?: return@dynamicOptions
|
||||
val jdkOptionsData = withContext(Dispatchers.IO) {
|
||||
VMOptionsService.getInstance().getOrComputeOptionsForJdk(javaHomePath).get() ?: return@withContext null
|
||||
} ?: return@dynamicOptions
|
||||
val optionByVariant = jdkOptionsData.options.filter { it.kind == VMOptionKind.Standard || it.kind == VMOptionKind.Product }.groupBy { it.variant }
|
||||
addOptionsFromVM(optionByVariant[VMOptionVariant.X])
|
||||
}
|
||||
description(JavaTerminalBundle.message("java.command.terminal.description"))
|
||||
option("--help", "-help", "-h") {
|
||||
description(JavaTerminalBundle.message("java.command.terminal.help.option.description"))
|
||||
@@ -51,4 +66,31 @@ private fun getSpecs(): ShellCommandSpec = ShellCommandSpec("java") {
|
||||
argument {
|
||||
displayName(JavaTerminalBundle.message("java.command.terminal.argument.main.class.text"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ShellChildOptionsContext.addOptionsFromVM(optionList: List<VMOption>?) {
|
||||
if (optionList == null) return
|
||||
optionList.forEach { vmOption ->
|
||||
val vmOptionName = "${vmOption.variant.prefix()}${vmOption.optionName}"
|
||||
val vmOptionDescription = vmOption.doc ?: return@forEach
|
||||
option(vmOptionName) {
|
||||
repeatTimes = 1
|
||||
description(vmOptionDescription)
|
||||
if (!KNOWN_X_OPTIONS_WITH_ARGUMENT.contains(vmOptionName)) return@option
|
||||
separator = vmOption.variant.suffix()?.toString() ?: ""
|
||||
argument {
|
||||
displayName(JavaTerminalBundle.message("java.command.terminal.default.argument.text"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val KNOWN_X_OPTIONS_WITH_ARGUMENT = setOf(
|
||||
"-Xms",
|
||||
"-Xmx",
|
||||
"-Xmn",
|
||||
"-Xss",
|
||||
"-Xbootclasspath/a:",
|
||||
"-Xlog:",
|
||||
"-Xloggc:",
|
||||
)
|
||||
Reference in New Issue
Block a user