Skip to content

Commit

Permalink
Use preview only for non-stable server versions (<0.5.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuricks2015 committed Aug 28, 2024
1 parent 0391d0c commit ff12165
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/com/koxudaxi/ruff/Ruff.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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 LSP_PREVIEW_ARGS = listOf("server", "--preview")
val LSP_ARGS_BASE = listOf("server")
val PREVIEW_ARGS = listOf("--preview")
val Project.LSP_ARGS: List<String>
get() = when {
RuffCacheService.hasStableServer(this) == true -> LSP_ARGS_BASE
else -> LSP_ARGS_BASE + PREVIEW_ARGS
}
val Project.FIX_ARGS: List<String>
get() = when {
RuffCacheService.hasCheck(this) == true -> CHECK + FIX_ARGS_BASE
Expand Down
8 changes: 8 additions & 0 deletions src/com/koxudaxi/ruff/RuffCacheService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RuffCacheService(val project: Project) {
private var hasOutputFormat: Boolean? = null
private var hasCheck: Boolean? = null
private var hasLsp: Boolean? = null
private var hasStableServer: Boolean? = null

fun getVersion(): RuffVersion? {
return version
Expand Down Expand Up @@ -45,6 +46,7 @@ class RuffCacheService(val project: Project) {
hasOutputFormat = version?.hasOutputFormat
hasCheck = version?.hasCheck
hasLsp = version?.hasLsp
hasStableServer = version?.hasStableServer
}

internal fun clearVersion() {
Expand All @@ -70,6 +72,10 @@ class RuffCacheService(val project: Project) {
internal fun hasLsp(): Boolean? {
return hasLsp
}

internal fun hasStableServer(): Boolean? {
return hasStableServer
}
internal
companion object {
fun hasFormatter(project: Project): Boolean = getInstance(project).hasFormatter()
Expand All @@ -80,6 +86,8 @@ class RuffCacheService(val project: Project) {

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

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

internal fun getInstance(project: Project): RuffCacheService {
return project.getService(RuffCacheService::class.java)
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/ruff/RuffLspServerSupportProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ abstract class RuffLspServerDescriptorBase(project: Project, val executable: Fil
@Suppress("UnstableApiUsage")
private class RuffServerServerDescriptor(project: Project, executable: File, ruffConfig: RuffConfigService) :
RuffLspServerDescriptorBase(project, executable, ruffConfig) {
override fun createCommandLine(): GeneralCommandLine = GeneralCommandLine(listOf(executable.absolutePath) + LSP_PREVIEW_ARGS)
override fun createCommandLine(): GeneralCommandLine = GeneralCommandLine(listOf(executable.absolutePath) + project.LSP_ARGS)
}
@Serializable
data class Settings(
Expand Down
4 changes: 3 additions & 1 deletion src/com/koxudaxi/ruff/RuffVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class RuffVersion(private val major: Int, private val minor: Int = 0, private va
val hasCheck: Boolean get() = this >= SUPPORT_CHECK_VERSION

val hasLsp: Boolean get() = this >= SUPPORT_LSP_VERSION

val hasStableServer: Boolean get() = this >= SUPPORT_STABLE_SERVER_VERSION
companion object {
val SUPPORT_FORMAT_VERSION = RuffVersion(0, 0, 289)
val SUPPORT_OUTPUT_FORMAT_VERSION = RuffVersion(0, 0, 291)
val SUPPORT_CHECK_VERSION = RuffVersion(0, 3, 0)
val SUPPORT_LSP_VERSION = RuffVersion(0, 4, 5)

val SUPPORT_STABLE_SERVER_VERSION = RuffVersion(0, 5, 3)
}
}

0 comments on commit ff12165

Please sign in to comment.