Skip to content

Commit

Permalink
Merge pull request #152 from pontem-network/remove-internal-apis
Browse files Browse the repository at this point in the history
Remove usages of `@Internal` apis
  • Loading branch information
mkurnikov authored Jun 6, 2024
2 parents d8a6f2f + 0e5434c commit 4a5eaf6
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 96 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ val pluginGroup = "org.move"
val javaVersion = JavaVersion.VERSION_17
val pluginJarName = "intellij-move-$pluginVersion"

val kotlinReflectVersion = "1.8.10"
val kotlinReflectVersion = "1.9.10"
val aptosVersion = "3.4.1"

val remoteRobotVersion = "0.11.22"
Expand Down Expand Up @@ -154,7 +154,7 @@ allprojects {
kotlinOptions {
jvmTarget = "17"
languageVersion = "1.9"
apiVersion = "1.8"
apiVersion = "1.9"
freeCompilerArgs = listOf("-Xjvm-default=all")
}
}
Expand Down Expand Up @@ -267,7 +267,6 @@ project(":plugin") {
// these are the only issues we tolerate
RunPluginVerifierTask.FailureLevel.DEPRECATED_API_USAGES,
RunPluginVerifierTask.FailureLevel.EXPERIMENTAL_API_USAGES,
RunPluginVerifierTask.FailureLevel.INTERNAL_API_USAGES,
RunPluginVerifierTask.FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/move/bytecode/AptosDecompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import org.move.cli.settings.getAptosCli
import org.move.openapiext.pathAsPath
import org.move.openapiext.rootDisposable
import org.move.openapiext.rootPluginDisposable
import org.move.openapiext.rootPath
import org.move.stdext.RsResult
import org.move.stdext.unwrapOrElse
Expand Down Expand Up @@ -121,6 +121,6 @@ fun Project.createDisposableOnFileChange(file: VirtualFile): Disposable {
}
}
)
Disposer.register(this.rootDisposable, disposable)
Disposer.register(this.rootPluginDisposable, disposable)
return disposable
}
8 changes: 2 additions & 6 deletions src/main/kotlin/org/move/cli/MoveProjectsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ class MoveProjectsService(val project: Project): Disposable {
// activate auto-reload
projectTracker.activate(moveProjectAware.projectId)

@Suppress("UnstableApiUsage")
project.messageBus.connect(disposable)
.subscribe(MOVE_SETTINGS_TOPIC, object: MoveSettingsListener {
override fun <T: MvProjectSettingsBase<T>> settingsChanged(e: SettingsChangedEventBase<T>) {
if (e.affectsMoveProjectsMetadata) {
val tracker = AutoImportProjectTracker.getInstance(project)
val tracker = ExternalSystemProjectTracker.getInstance(project)
tracker.markDirty(moveProjectAware.projectId)
tracker.scheduleProjectRefresh()
}
Expand All @@ -105,10 +104,9 @@ class MoveProjectsService(val project: Project): Disposable {

// default projectTracker cannot detect Move.toml file creation,
// as it's not present in the `settingsFiles`
@Suppress("UnstableApiUsage")
project.messageBus.connect(disposable)
.subscribe(VirtualFileManager.VFS_CHANGES, OnMoveTomlCreatedFileListener {
val tracker = AutoImportProjectTracker.getInstance(project)
val tracker = ExternalSystemProjectTracker.getInstance(project)
tracker.markDirty(moveProjectAware.projectId)
tracker.scheduleProjectRefresh()
})
Expand Down Expand Up @@ -214,8 +212,6 @@ class MoveProjectsService(val project: Project): Disposable {
private fun modifyProjectModel(
modifyProjects: (List<MoveProject>) -> CompletableFuture<List<MoveProject>>
): CompletableFuture<List<MoveProject>> {
val refreshStatusPublisher =
project.messageBus.syncPublisher(MOVE_PROJECTS_REFRESH_TOPIC)
val syncOnRefreshTopic = {
project.messageBus.takeIf { !it.isDisposed }
?.syncPublisher(MOVE_PROJECTS_REFRESH_TOPIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.move.openapiext.fullWidthCell
class MvExternalLinterConfigurable(val project: Project): BoundConfigurable("External Linters") {
private val additionalArguments: RsCommandLineEditor =
RsCommandLineEditor(project, RsCommandLineEditor.EmptyTextFieldCompletionProvider())
// RsCommandLineEditor(project, CargoCommandCompletionProvider(project.cargoProjects, "check ") { null })

private val environmentVariables: EnvironmentVariablesComponent = EnvironmentVariablesComponent()

Expand Down
43 changes: 3 additions & 40 deletions src/main/kotlin/org/move/cli/util/RsCommandLineEditor.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package org.move.cli.util

import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.project.Project
import com.intellij.ui.EditorTextField
import com.intellij.ui.ExpandableEditorSupport
import com.intellij.ui.TextAccessor
import com.intellij.util.Function
import com.intellij.util.TextFieldCompletionProvider
import com.intellij.util.textCompletion.TextFieldWithCompletion
import java.awt.BorderLayout
import java.awt.Dimension
import javax.swing.JComponent
import javax.swing.JPanel

class RsCommandLineEditor(
private val project: Project,
private val completionProvider: TextFieldCompletionProvider
) : JPanel(BorderLayout()), TextAccessor {
): JPanel(BorderLayout()), TextAccessor {

private val textField = createTextField("")

Expand Down Expand Up @@ -57,39 +52,7 @@ class RsCommandLineEditor(
private class ExpandableEditorSupportWithCustomPopup(
field: EditorTextField,
private val createPopup: (text: String) -> EditorTextField
) : ExpandableEditorSupport(field) {
@Suppress("UnstableApiUsage")
override fun prepare(field: EditorTextField, onShow: Function<in String, String>): Content {
val popup = createPopup(onShow.`fun`(field.text))
val background = field.background
): ExpandableEditorSupport(field) {

popup.background = background
popup.setOneLineMode(false)
popup.preferredSize = Dimension(field.width, 5 * field.height)
popup.addSettingsProvider { editor ->
initPopupEditor(editor, background)
copyCaretPosition(editor, field.editor)
}

return object : Content {
override fun getContentComponent(): JComponent = popup
override fun getFocusableComponent(): JComponent = popup
override fun cancel(onHide: Function<in String, String>) {
field.text = onHide.`fun`(popup.text)
val editor = field.editor
if (editor != null) copyCaretPosition(editor, popup.editor)
if (editor is EditorEx) updateFieldFolding((editor as EditorEx?)!!)
}
}
}

companion object {
private fun copyCaretPosition(destination: Editor, source: Editor?) {
if (source == null) return // unexpected
try {
destination.caretModel.caretsAndSelections = source.caretModel.caretsAndSelections
} catch (ignored: IllegalArgumentException) {
}
}
}
override fun createPopupEditor(field: EditorTextField, text: String): EditorTextField = createPopup(text)
}
17 changes: 0 additions & 17 deletions src/main/kotlin/org/move/ide/MoveIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ package org.move.ide
import com.intellij.icons.AllIcons
import com.intellij.openapi.util.IconLoader
import com.intellij.ui.AnimatedIcon
import com.intellij.ui.ColorUtil
import com.intellij.ui.JBColor
import com.intellij.ui.LayeredIcon
import com.intellij.ui.LayeredIcon.Companion.layeredIcon
import com.intellij.ui.icons.RgbImageFilterSupplier
import com.jetbrains.rd.generator.nova.array
import java.awt.Color
import java.awt.Component
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.image.RGBImageFilter
import javax.swing.Icon

object MoveIcons {
Expand Down Expand Up @@ -85,17 +79,6 @@ fun Icon.multiple(): Icon {
return compoundIcon
}

@Suppress("UnstableApiUsage")
fun Icon.grayed(): Icon =
IconLoader.filterIcon(this, object: RgbImageFilterSupplier {
override fun getFilter(): RGBImageFilter = object: RGBImageFilter() {
override fun filterRGB(x: Int, y: Int, rgb: Int): Int {
val color = Color(rgb, true)
return ColorUtil.toAlpha(color, (color.alpha / 2.2).toInt()).rgb
}
}
})

/**
* Rotates the icon by the given angle, in degrees.
*
Expand Down
15 changes: 2 additions & 13 deletions src/main/kotlin/org/move/ide/actions/RsRunExternalLinterAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import com.intellij.codeInspection.InspectionManager
import com.intellij.codeInspection.actions.RunInspectionIntention
import com.intellij.codeInspection.ex.InspectionManagerEx
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.util.Key
import com.intellij.profile.codeInspection.InspectionProjectProfileManager
import org.move.cli.MoveProject
import org.move.cli.runConfigurations.aptos.RunAptosCommandActionBase
import org.move.cli.runConfigurations.getAppropriateMoveProject
import org.move.ide.inspections.MvExternalLinterInspection

class MvRunExternalLinterAction: RunAptosCommandActionBase("Run External Linter") {
Expand All @@ -24,16 +21,8 @@ class MvRunExternalLinterAction: RunAptosCommandActionBase("Run External Linter"
val currentProfile = InspectionProjectProfileManager.getInstance(project).currentProfile
val wrapper = currentProfile.getInspectionTool(MvExternalLinterInspection.SHORT_NAME, project) ?: return
val managerEx = InspectionManager.getInstance(project) as InspectionManagerEx
val inspectionContext = RunInspectionIntention.createContext(wrapper, managerEx, null)

val cargoProject = getAppropriateMoveProject(e.dataContext)
inspectionContext.putUserData(CARGO_PROJECT, cargoProject)

inspectionContext.doInspections(AnalysisScope(project))
}

companion object {
@JvmField
val CARGO_PROJECT: Key<MoveProject> = Key.create("Move project")
val analysisScope = AnalysisScope(project)
RunInspectionIntention.rerunInspection(wrapper, managerEx, analysisScope, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class RsExternalLinterPassFactory(
)

override fun createHighlightingPass(file: PsiFile, editor: Editor): TextEditorHighlightingPass? {
FileStatusMap.getDirtyTextRange(editor, passId) ?: return null
FileStatusMap.getDirtyTextRange(editor.document, file, passId) ?: return null
return RsExternalLinterPass(this, file, editor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ package org.move.ide.inspections

import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.codeInspection.*
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl
import com.intellij.codeInspection.ex.GlobalInspectionContextEx
import com.intellij.codeInspection.ex.GlobalInspectionContextUtil
import com.intellij.codeInspection.reference.RefElement
import com.intellij.codeInspection.ui.InspectionToolPresentation
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runReadAction
Expand All @@ -33,6 +32,7 @@ import org.move.ide.annotator.createDisposableOnAnyPsiChange
import org.move.lang.MoveFile
import org.move.lang.core.psi.ext.ancestorOrSelf
import org.move.lang.moveProject
import org.move.openapiext.rootPluginDisposable

class MvExternalLinterInspection: GlobalSimpleInspectionTool() {

Expand Down Expand Up @@ -62,16 +62,16 @@ class MvExternalLinterInspection: GlobalSimpleInspectionTool() {
globalContext: GlobalInspectionContext,
problemDescriptionsProcessor: ProblemDescriptionsProcessor
) {
if (globalContext !is GlobalInspectionContextImpl) return
if (globalContext !is GlobalInspectionContextEx) return
val analyzedFiles = globalContext.getUserData(ANALYZED_FILES) ?: return

val project = manager.project
val currentProfile = InspectionProjectProfileManager.getInstance(project).currentProfile
val toolWrapper = currentProfile.getInspectionTool(SHORT_NAME, project) ?: return

while (true) {
val disposable = project.messageBus.createDisposableOnAnyPsiChange()
.also { Disposer.register(project, it) }
val anyPsiChangeDisposable = project.messageBus.createDisposableOnAnyPsiChange()
.also { Disposer.register(project.rootPluginDisposable, it) }
val moveProjects = run {
val allProjects = project.moveProjectsService.allProjects
if (allProjects.size == 1) {
Expand All @@ -84,14 +84,14 @@ class MvExternalLinterInspection: GlobalSimpleInspectionTool() {
}
val futures = moveProjects.map {
ApplicationManager.getApplication().executeOnPooledThread<RsExternalLinterResult?> {
checkProjectLazily(it, disposable)?.value
checkProjectLazily(it, anyPsiChangeDisposable)?.value
}
}
val annotationResults = futures.mapNotNull { it.get() }

val exit = runReadAction {
ProgressManager.checkCanceled()
if (Disposer.isDisposed(disposable)) return@runReadAction false
if (Disposer.isDisposed(anyPsiChangeDisposable)) return@runReadAction false
if (annotationResults.size < moveProjects.size) return@runReadAction true
for (annotationResult in annotationResults) {
val problemDescriptors = getProblemDescriptors(analyzedFiles, annotationResult)
Expand Down Expand Up @@ -140,7 +140,7 @@ class MvExternalLinterInspection: GlobalSimpleInspectionTool() {
}
}

private fun InspectionToolPresentation.addProblemDescriptors(
private fun InspectionToolResultExporter.addProblemDescriptors(
descriptors: List<ProblemDescriptor>,
context: GlobalInspectionContext
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class TypeInferenceWalker(
}
}

fun inferDotFieldTy(receiverTy: Ty, dotField: MvStructDotField, expected: Expectation): Ty {
fun inferDotFieldTy(receiverTy: Ty, dotField: MvStructDotField): Ty {
val structTy =
receiverTy.derefIfNeeded() as? TyStruct ?: return TyUnknown

Expand Down Expand Up @@ -563,7 +563,7 @@ class TypeInferenceWalker(
val field = dotExpr.structDotField
return when {
methodCall != null -> inferMethodCallTy(receiverTy, methodCall, expected)
field != null -> inferDotFieldTy(receiverTy, field, expected)
field != null -> inferDotFieldTy(receiverTy, field)
// incomplete
else -> TyUnknown
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/move/openapiext/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun saveAllDocuments() = FileDocumentManager.getInstance().saveAllDocuments()
* This function saves all documents "as they are" (see [FileDocumentManager.saveDocumentAsIs]), but also fires that
* these documents should be stripped later (when [saveAllDocuments] is called).
*/
fun saveAllDocumentsAsTheyAre(reformatLater: Boolean = true) {
fun saveAllDocumentsAsTheyAre() {
val documentManager = FileDocumentManager.getInstance()
// val rustfmtWatcher = RustfmtWatcher.getInstance()
// rustfmtWatcher.withoutReformatting {
Expand Down Expand Up @@ -207,7 +207,7 @@ inline fun <R> Project.nonBlocking(crossinline block: () -> R, crossinline uiCon
block()
})
.inSmartMode(this)
.expireWith(this.rootDisposable)
.expireWith(this.rootPluginDisposable)
.finishOnUiThread(ModalityState.current()) { result ->
uiContinuation(result)
}.submit(AppExecutorUtil.getAppExecutorService())
Expand All @@ -219,7 +219,7 @@ class RootPluginDisposable: Disposable {
override fun dispose() {}
}

val Project.rootDisposable get() = this.service<RootPluginDisposable>()
val Project.rootPluginDisposable get() = this.service<RootPluginDisposable>()

fun checkCommitIsNotInProgress(project: Project) {
val app = ApplicationManager.getApplication()
Expand Down

0 comments on commit 4a5eaf6

Please sign in to comment.