Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Fix #28 #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.meanmail.codeInsight.completion

import com.intellij.codeInsight.completion.*
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.application.ApplicationManager
import com.intellij.patterns.PlatformPatterns
import com.intellij.psi.util.elementType
import com.intellij.psi.util.prevLeaf
Expand All @@ -12,6 +13,7 @@ import ru.meanmail.psi.Types
import ru.meanmail.pypi.getVersionsAsync



class RequirementsCompletionContributor : CompletionContributor() {
init {
extend(
Expand Down Expand Up @@ -48,25 +50,30 @@ class VersionCompletionProvider : CompletionProvider<CompletionParameters>() {
packageName ?: return

val task = getVersionsAsync(project, sdk, packageName)
val versions = task.get() ?: return
val latest = versions.firstOrNull {
it.pre == null
}

result.addAllElements(
versions.map {
val isLatest = it == latest
val lookupElement = LookupElementBuilder.create(it.presentableText)
if (it.pre != null) {
return@map lookupElement.withTypeText("pre")
}
if (isLatest) {
return@map lookupElement.withTypeText("latest")
val application = ApplicationManager.getApplication()
application.executeOnPooledThread {
val versions = task.get()
application.runReadAction {
val latest = versions.firstOrNull {
it.pre == null
}
return@map lookupElement
result.addAllElements(
versions.map {
val isLatest = it == latest
val lookupElement = LookupElementBuilder.create(it.presentableText)
if (it.pre != null) {
return@map lookupElement.withTypeText("pre")
}
if (isLatest) {
return@map lookupElement.withTypeText("latest")
}
return@map lookupElement
}
)
}
)
}
}

}

class ShortOptionCompletionProvider : CompletionProvider<CompletionParameters>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.application.ApplicationManager
import com.intellij.psi.PsiElementVisitor
import com.jetbrains.python.packaging.PyPackageVersion
import ru.meanmail.compareTo
Expand All @@ -14,6 +15,7 @@ import ru.meanmail.psi.NameReq
import ru.meanmail.pypi.getVersionsAsync
import ru.meanmail.quickfix.InstallPackageQuickFix


class InstalledPackageInspection : LocalInspectionTool() {
override fun buildVisitor(
holder: ProblemsHolder,
Expand Down Expand Up @@ -49,39 +51,51 @@ class InstalledPackageInspection : LocalInspectionTool() {
}
val packageName = element.name.text ?: return
val task = getVersionsAsync(project, sdk, packageName)
val versions = task.get() ?: return

val suitableVersion: PyPackageVersion? = versions.find {
isVersionActual(element, it)
}

val latest = versions.firstOrNull {
it.pre == null
}
val application = ApplicationManager.getApplication()
application.executeOnPooledThread {
val versions = task.get()
application.runReadAction {
val suitableVersion: PyPackageVersion? = versions.find {
isVersionActual(element, it)
}

val installed = getInstalledVersion(sdk, packageName)
val isInstalledIsActual = installed != null && isVersionActual(element, installed)
val versionsInfo = getVersionsInfo(
suitableVersion, installed, latest
)
val latest = versions.firstOrNull {
it.pre == null
}

if (suitableVersion == null) {
if (latest != null) {
noSuitableVersion(element, packageName, versionsInfo, latest)
} else {
noSuitablePackage(element, packageName)
}
} else {
if (isInstalledIsActual) {
if (installed < suitableVersion) {
installedPackageIsOutdated(element, packageName, versionsInfo, installed, suitableVersion)
val installed = getInstalledVersion(sdk, packageName)
val isInstalledIsActual = installed != null && isVersionActual(element, installed)
val versionsInfo = getVersionsInfo(
suitableVersion, installed, latest
)

if (suitableVersion == null) {
if (latest != null) {
noSuitableVersion(element, packageName, versionsInfo, latest)
} else {
noSuitablePackage(element, packageName)
}
} else {
if (isInstalledIsActual) {
if (installed < suitableVersion) {
installedPackageIsOutdated(
element,
packageName,
versionsInfo,
installed,
suitableVersion
)
}
} else {
requiredPackageIsNotInstalled(element, packageName, versionsInfo, suitableVersion)
}
}
if (latest != null && suitableVersion < latest) {
requirementIsOutdated(element, packageName, versionsInfo, suitableVersion, latest)
}
} else {
requiredPackageIsNotInstalled(element, packageName, versionsInfo, suitableVersion)
}
}
if (latest != null && suitableVersion < latest) {
requirementIsOutdated(element, packageName, versionsInfo, suitableVersion, latest)


}
}

Expand Down