Skip to content

Commit

Permalink
Merge pull request #306 from koxudaxi/change_versionCache_to_concurre…
Browse files Browse the repository at this point in the history
…ntHashMap

Fix async version checking
  • Loading branch information
koxudaxi authored Nov 10, 2023
2 parents aa7f1cd + 9ffe311 commit 16375dd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 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 async version checking [[#306](https://github.com/koxudaxi/ruff-pycharm-plugin/pull/306)]

## [0.0.25] - 2023-11-03

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.25
pluginVersion = 0.0.26

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

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

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
14 changes: 11 additions & 3 deletions src/com/koxudaxi/ruff/Ruff.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.jetbrains.annotations.SystemDependent
import java.io.File
import java.io.IOError
import java.io.IOException
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import java.util.regex.Pattern
Expand All @@ -58,7 +59,7 @@ val RUFF_LSP_COMMAND = when {
}
const val WSL_RUFF_LSP_COMMAND = "ruff-lsp"

val ruffVersionCache: HashMap<String, RuffVersion> = hashMapOf()
val ruffVersionCache: ConcurrentHashMap<String, RuffVersion> = ConcurrentHashMap()

fun getRuffCommand(lsp: Boolean) = if (lsp) RUFF_LSP_COMMAND else RUFF_COMMAND

Expand All @@ -81,7 +82,13 @@ val NO_FIX_FORMAT_ARGS = ARGS_BASE + listOf("--no-fix", "--format", "json")
val NO_FIX_OUTPUT_FORMAT_ARGS = ARGS_BASE + listOf("--no-fix", "--output-format", "json")
val FORMAT_ARGS = listOf("format", "--force-exclude", "--quiet")
val FORMAT_CHECK_ARGS = FORMAT_ARGS + listOf("--check")
val Project.NO_FIX_ARGS get() = if (RuffCacheService.hasOutputFormat(this)) NO_FIX_OUTPUT_FORMAT_ARGS else NO_FIX_FORMAT_ARGS
val Project.NO_FIX_ARGS: List<String>?
get() = when (RuffCacheService.hasOutputFormat(this)) {
true -> NO_FIX_OUTPUT_FORMAT_ARGS
false -> NO_FIX_FORMAT_ARGS
else -> null
}


private var wslSdkIsSupported: Boolean? = null
val Sdk.wslIsSupported: Boolean
Expand Down Expand Up @@ -429,7 +436,8 @@ fun Document.getStartEndRange(startLocation: Location, endLocation: Location, of
fun checkFixResult(sourceFile: SourceFile, fixResult: String?): String? {
if (fixResult == null) return null
if (fixResult.isNotBlank()) return fixResult
val noFixResult = runRuff(sourceFile, sourceFile.project.NO_FIX_ARGS) ?: return null
val noFixArgs = sourceFile.project.NO_FIX_ARGS ?: return null
val noFixResult = runRuff(sourceFile, noFixArgs) ?: return null

// check the file is excluded
if (noFixResult.trim() == "[]") return null
Expand Down
6 changes: 3 additions & 3 deletions src/com/koxudaxi/ruff/RuffCacheService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ class RuffCacheService(val project: Project) {
return hasFormatter ?: false
}

internal fun hasOutputFormat(): Boolean {
return hasOutputFormat ?: false
internal fun hasOutputFormat(): Boolean? {
return hasOutputFormat
}

internal
companion object {
fun hasFormatter(project: Project): Boolean = getInstance(project).hasFormatter()

fun hasOutputFormat(project: Project): Boolean = getInstance(project).hasOutputFormat()
fun hasOutputFormat(project: Project): Boolean? = getInstance(project).hasOutputFormat()


internal fun getInstance(project: Project): RuffCacheService {
Expand Down
3 changes: 2 additions & 1 deletion src/com/koxudaxi/ruff/RuffExternalAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class RuffExternalAnnotator :
val highlightDisplayLevel = highlightSeverityLevels[level] ?: return null
val problemHighlightType = problemHighlightTypeLevels[level] ?: return null
val showRuleCode = config.showRuleCode
val commandArgs = generateCommandArgs(file.sourceFile, project.NO_FIX_ARGS) ?: return null
val noFixArgs = project.NO_FIX_ARGS ?: return null
val commandArgs = generateCommandArgs(file.sourceFile, noFixArgs) ?: return null
return RuffExternalAnnotatorInfo(showRuleCode, highlightDisplayLevel, problemHighlightType, commandArgs)
}

Expand Down

0 comments on commit 16375dd

Please sign in to comment.