Skip to content

Commit

Permalink
Merge pull request #479 from Shuricks2015/feature/fix_docu_on_noqa
Browse files Browse the repository at this point in the history
Use rule or --explain dependent on version.
  • Loading branch information
koxudaxi authored Sep 2, 2024
2 parents 5e19f0b + 13b162d commit cbffebd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/com/koxudaxi/ruff/Ruff.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ val Project.LSP_ARGS: List<String>
RuffCacheService.hasStableServer(this) == true -> LSP_ARGS_BASE
else -> LSP_ARGS_BASE + PREVIEW_ARGS
}
val Project.RULE_ARGS: List<String>
get() = when {
RuffCacheService.hasCheck(this) == true -> listOf("rule")
else -> listOf("--explain")
}

val Project.FIX_ARGS: List<String>
get() = when {
RuffCacheService.hasCheck(this) == true -> CHECK + FIX_ARGS_BASE
Expand Down
22 changes: 13 additions & 9 deletions src/com/koxudaxi/ruff/RuffNoqaDocumentationTarget.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.koxudaxi.ruff

import com.intellij.codeInsight.navigation.targetPresentation
import com.intellij.markdown.utils.doc.DocMarkdownToHtmlConverter
import com.intellij.model.Pointer
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.Computable
import com.intellij.platform.backend.documentation.DocumentationResult
import com.intellij.platform.backend.documentation.DocumentationTarget
import com.intellij.platform.backend.presentation.TargetPresentation
import com.intellij.psi.PsiComment
import com.intellij.refactoring.suggested.createSmartPointer
import com.intellij.refactoring.suggested.startOffset
import com.intellij.psi.createSmartPointer
import com.intellij.psi.util.startOffset

import com.intellij.webSymbols.utils.HtmlMarkdownUtils

class RuffNoqaDocumentationTarget(private val psiComment: PsiComment, private val originalElement: PsiComment?, private val offset: Int): DocumentationTarget {
@Suppress("UnstableApiUsage")
Expand All @@ -32,12 +34,14 @@ class RuffNoqaDocumentationTarget(private val psiComment: PsiComment, private va
override fun computeDocumentation(): DocumentationResult? {
val noqaCode = getNoqaCode(psiComment, offset) ?: return null
return DocumentationResult.asyncDocumentation {
val markdown = runRuff(psiComment.project, listOf("--explain", noqaCode), true) ?: return@asyncDocumentation null
val html = HtmlMarkdownUtils.toHtml(markdown, true) ?: return@asyncDocumentation null
val downscaledHtml = replaceHtmlTags.fold(html) { acc, (from, to) ->
acc.replace(from, to)
}
DocumentationResult.documentation(downscaledHtml)
val markdown = runRuff(psiComment.project, psiComment.project.RULE_ARGS + noqaCode, true) ?: return@asyncDocumentation null
ApplicationManager.getApplication().runReadAction(Computable {
val html = DocMarkdownToHtmlConverter.convert(psiComment.project, markdown) ?: return@Computable null

Check warning on line 39 in src/com/koxudaxi/ruff/RuffNoqaDocumentationTarget.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of redundant or deprecated syntax or deprecated symbols

Elvis operator (?:) always returns the left operand of non-nullable type String
val downscaledHtml = replaceHtmlTags.fold(html) { acc, (from, to) ->
acc.replace(from, to)
}
DocumentationResult.documentation(downscaledHtml)
})
}
}

Expand Down

0 comments on commit cbffebd

Please sign in to comment.