Skip to content

Commit

Permalink
Remove duplicated getGeneralCommandLine
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi committed Sep 13, 2024
1 parent 99b27d0 commit 47433ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
4 changes: 1 addition & 3 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="com.koxudaxi.ruff.RuffProjectInitializer"/>
<projectConfigurable groupId="tools" instance="com.koxudaxi.ruff.RuffConfigurable"/>
<!-- <postFormatProcessor implementation="com.koxudaxi.ruff.RuffFixProcessor"/>-->
<!-- <postFormatProcessor implementation="com.koxudaxi.ruff.RuffFormatProcessor"/>-->
<localInspection language="Python" shortName="RuffInspection" suppressId="Ruff"
displayName="Ruff inspection"
enabledByDefault="true" level="WARNING"
implementationClass="com.koxudaxi.ruff.RuffInspection"/>
<externalAnnotator language="Python" implementationClass="com.koxudaxi.ruff.RuffExternalAnnotator"/>
<formattingService implementation="com.koxudaxi.ruff.RuffAsyncFormatter"></formattingService>
<formattingService implementation="com.koxudaxi.ruff.RuffAsyncFormatter"/>
<platform.backend.documentation.targetProvider
implementation="com.koxudaxi.ruff.RuffNoqaDocumentationTargetProvider"/>
<actionOnSave id="BlackFormatterActionOnSave" implementation="com.koxudaxi.ruff.RuffActionOnSave" order="last"/>
Expand Down
25 changes: 2 additions & 23 deletions src/com/koxudaxi/ruff/Ruff.kt
Original file line number Diff line number Diff line change
Expand Up @@ -273,36 +273,15 @@ fun runCommand(
commandArgs.executable, commandArgs.project, commandArgs.stdin, *commandArgs.args.toTypedArray()
)

fun getGeneralCommandLine(executable: File, project: Project?, vararg args: String): GeneralCommandLine? {
val projectPath = project?.basePath
if (!WslPath.isWslUncPath(executable.path)) {
return getGeneralCommandLine(listOf(executable.path) + args, projectPath)
}

val windowsUncPath = WslPath.parseWindowsUncPath(executable.path) ?: return null
val configArgIndex = args.indexOf(CONFIG_ARG)
val injectedArgs = if (configArgIndex != -1 && configArgIndex < args.size - 1) {
val configPathIndex = configArgIndex + 1
val configPath = args[configPathIndex]
val windowsUncConfigPath = WslPath.parseWindowsUncPath(configPath)?.linuxPath ?: configPath
args.toMutableList().apply { this[configPathIndex] = windowsUncConfigPath }.toTypedArray()
} else {
args
}
val commandLine = getGeneralCommandLine(listOf(windowsUncPath.linuxPath) + injectedArgs, projectPath)
val options = WSLCommandLineOptions()
options.setExecuteCommandInShell(false)
options.setLaunchWithWslExe(true)
return windowsUncPath.distribution.patchCommandLine<GeneralCommandLine>(commandLine, project, options)
}
private fun getGeneralCommandLine(command: List<String>, projectPath: String?): GeneralCommandLine =
GeneralCommandLine(command).withWorkDirectory(projectPath).withCharset(Charsets.UTF_8)

fun getGeneralCommandLine(executable: File, project: Project?, vararg args: String): GeneralCommandLine? {
val projectPath = project?.basePath ?: return null
if (!WslPath.isWslUncPath(executable.path)) {
return getGeneralCommandLine(listOf(executable.path) + args, projectPath)
return getGeneralCommandLine(listOf(executable.path) + args, projectPath)
}

val windowsUncPath = WslPath.parseWindowsUncPath(executable.path) ?: return null
val configArgIndex = args.indexOf(CONFIG_ARG)
val injectedArgs = if (configArgIndex != -1 && configArgIndex < args.size - 1) {
Expand Down

0 comments on commit 47433ac

Please sign in to comment.