Skip to content

Commit

Permalink
Merge pull request #414 from koxudaxi/fix_wsl_detection_on_2024.1
Browse files Browse the repository at this point in the history
Fix wsl detection on 2024.1
  • Loading branch information
koxudaxi authored Apr 7, 2024
2 parents 7add374 + 0328fae commit e22b642
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Fix wsl detection on 2024.1 [[#414](https://github.com/koxudaxi/ruff-pycharm-plugin/pull/414)]

## [0.0.32] - 2024-04-01

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pluginGroup = com.koxudaxi.ruff
pluginName = Ruff
pluginRepositoryUrl = https://github.com/koxudaxi/ruff-pycharm-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.0.32
pluginVersion = 0.0.33

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 233.11799.241
pluginUntilBuild = 241.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = PY
platformVersion = 241-EAP-SNAPSHOT
platformVersion = 2024.1

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
13 changes: 8 additions & 5 deletions src/com/koxudaxi/ruff/Ruff.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.jetbrains.python.packaging.PyExecutionException
import com.jetbrains.python.sdk.*
import com.jetbrains.python.sdk.flavors.conda.CondaEnvSdkFlavor
import com.jetbrains.python.target.PyTargetAwareAdditionalData
import com.jetbrains.python.wsl.isWsl
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import org.jetbrains.annotations.SystemDependent

Check warning on line 40 in src/com/koxudaxi/ruff/Ruff.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
Expand Down Expand Up @@ -162,6 +161,9 @@ fun detectRuffExecutable(project: Project, ruffConfigService: RuffConfigService,
it
}
}

val Sdk.isWsl: Boolean get() = (sdkAdditionalData as? PyTargetAwareAdditionalData)?.targetEnvironmentConfiguration is WslTargetEnvironmentConfiguration

fun findRuffExecutableInSDK(sdk: Sdk, lsp: Boolean): File? {
return when {
sdk.wslIsSupported && sdk.isWsl -> {
Expand Down Expand Up @@ -207,24 +209,25 @@ val PsiFile.isApplicableTo: Boolean
fun runCommand(
commandArgs: CommandArgs
): String? = runCommand(
commandArgs.executable, commandArgs.project.basePath, commandArgs.stdin, *commandArgs.args.toTypedArray()
commandArgs.executable, commandArgs.project, commandArgs.stdin, *commandArgs.args.toTypedArray()
)


fun getGeneralCommandLine(command: List<String>, projectPath: String?): GeneralCommandLine =
GeneralCommandLine(command).withWorkDirectory(projectPath).withCharset(Charsets.UTF_8)

fun runCommand(
executable: File, projectPath: @SystemDependent String?, stdin: ByteArray?, vararg args: String
executable: File, project: Project, stdin: ByteArray?, vararg args: String
): String? {

val projectPath = project.basePath
val indicator = ProgressManager.getInstance().progressIndicator
val handler = if (WslPath.isWslUncPath(executable.path)) {
val windowsUncPath = WslPath.parseWindowsUncPath(executable.path) ?: return null
val options = WSLCommandLineOptions()
options.setExecuteCommandInShell(false)
options.setLaunchWithWslExe(true)
val commandLine = getGeneralCommandLine(listOf(windowsUncPath.linuxPath) + args, projectPath)
windowsUncPath.distribution.patchCommandLine<GeneralCommandLine>(commandLine, null, WSLCommandLineOptions())
windowsUncPath.distribution.patchCommandLine<GeneralCommandLine>(commandLine, project, options)
} else {
getGeneralCommandLine(listOf(executable.path) + args, projectPath)
}.let { CapturingProcessHandler(it) }
Expand Down

0 comments on commit e22b642

Please sign in to comment.