Skip to content

Commit

Permalink
Merge pull request #131 from pontem-network/1.33.1
Browse files Browse the repository at this point in the history
1.33.1
  • Loading branch information
mkurnikov authored Jan 20, 2024
2 parents d84d0aa + 8f430b1 commit 03201ba
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 86 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ fun prop(name: String): String =
?: error("Property `$name` is not defined in gradle.properties for environment `$shortPlatformVersion`")

val shortPlatformVersion = prop("shortPlatformVersion")
val codeVersion = "1.33.0"
val codeVersion = "1.33.1"
val pluginVersion = "$codeVersion.$shortPlatformVersion"
val pluginGroup = "org.move"
val javaVersion = JavaVersion.VERSION_17
val pluginJarName = "intellij-move-$pluginVersion"

val kotlinReflectVersion = "1.8.10"
val aptosVersion = "2.3.2"
val aptosVersion = "2.4.0"

group = pluginGroup
version = pluginVersion
Expand All @@ -37,7 +37,7 @@ plugins {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinReflectVersion")

implementation("io.sentry:sentry:6.25.0") {
implementation("io.sentry:sentry:7.2.0") {
exclude("org.slf4j")
}
implementation("com.github.ajalt.clikt:clikt:3.5.2")
Expand Down
16 changes: 16 additions & 0 deletions changelog/1.33.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# INTELLIJ MOVE CHANGELOG: 1.33.1

21 Jan 2024

## Fixes

* Parses packages correctly if `.aptos/config.yaml` has invalid entries. [#130s](https://github.com/pontem-network/intellij-move/issues/130)

* Removes crashes in sub-entries to the Aptos Tool Window.

* Handle some nullability cases to prevent crashes.

## Internal

* Disable projects serialization in the Sentry reporting.

4 changes: 4 additions & 0 deletions src/main/kotlin/org/move/cli/MoveProjectsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.move.cli.settings.MoveSettingsListener
import org.move.cli.settings.debugErrorOrFallback
import org.move.lang.core.psi.ext.elementType
import org.move.lang.toNioPathOrNull
import org.move.openapiext.checkReadAccessAllowed
import org.move.openapiext.common.isUnitTestMode
import org.move.openapiext.debugInProduction
import org.move.openapiext.toVirtualFile
Expand Down Expand Up @@ -82,7 +83,10 @@ class MoveProjectsService(val project: Project): Disposable {
return moveProjectsFut
}

// requires ReadAccess
fun findMoveProject(psiElement: PsiElement): MoveProject? {
// read access required for the psiElement.containingFile
checkReadAccessAllowed()
val file = when (psiElement) {
is PsiDirectory -> psiElement.virtualFile
is PsiFile -> psiElement.originalFile.virtualFile
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/org/move/cli/manifest/AptosConfigYaml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.move.cli.manifest

import com.intellij.util.io.readText
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.error.YAMLException
import java.nio.file.Path

data class AptosConfigYaml(
Expand All @@ -10,8 +11,13 @@ data class AptosConfigYaml(
) {
companion object {
fun fromPath(configYamlPath: Path): AptosConfigYaml? {
val yaml = Yaml().load<Map<String, Any>>(configYamlPath.readText())

val yaml =
try {
Yaml().load<Map<String, Any>>(configYamlPath.readText())
} catch (e: YAMLException) {
// TODO: error notification?
return null
}
@Suppress("UNCHECKED_CAST")
val profiles = (yaml["profiles"] as? Map<*, *>)?.keys as? Set<String> ?: return null
return AptosConfigYaml(configYamlPath, profiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class CommandConfigurationHandler {

val aptosConfig = moveProject.aptosConfigYaml
if (aptosConfig == null) {
return RsResult.Err("Aptos account is not initialized for the current project")
return RsResult.Err("Aptos account is not initialized / is invalid for the current project")
}

if (profileName !in aptosConfig.profiles) {
Expand Down
24 changes: 16 additions & 8 deletions src/main/kotlin/org/move/cli/sentryReporter/SentryErrorReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import io.sentry.SentryLevel
import io.sentry.UserFeedback
import io.sentry.protocol.Message
import io.sentry.protocol.SentryId
import org.move.cli.moveProjectsService
import org.move.cli.settings.moveSettings
import org.move.openapiext.project
import org.move.stdext.asMap
Expand Down Expand Up @@ -74,17 +73,26 @@ class SentryErrorReporter: ErrorReportSubmitter() {
sentryEvent.level = SentryLevel.ERROR

val plugin = IdeErrorsDialog.getPlugin(event)
sentryEvent.contexts["Plugin Info"] =
mapOf(
"Platform" to ApplicationInfo.getInstance().fullApplicationName,
"Plugin Version" to (plugin?.version ?: "unknown"),
)

val pluginInfoContext = mutableMapOf<String, Any>()
pluginInfoContext["Platform"] = ApplicationInfo.getInstance().fullApplicationName
pluginInfoContext["Plugin Version"] = plugin?.version ?: "unknown"
sentryEvent.contexts["Plugin Info"] = pluginInfoContext
// try {
// } catch (e: NoSuchFieldError) {
// // intellij 2023.1 on windows 11 throws this, catch and report that one instead
// // TODO: remove later
// sentryEvent.contexts["Runtime Error Stacktrace"] = mapOf("Value" to e.getThrowableText())
// }
//

if (project != null) {
val settings = project.moveSettings.state.asMap().toMutableMap()
settings.remove("aptosPath")
sentryEvent.contexts["Settings"] = settings
sentryEvent.contexts["Projects"] =
project.moveProjectsService.allProjects.map { MoveProjectContext.from(it) }
// TODO: serialization doesn't work for some reason
// sentryEvent.contexts["Projects"] =
// project.moveProjectsService.allProjects.map { MoveProjectContext.from(it) }.toList()
}
// IdeaLoggingEvent only provides text stacktrace
sentryEvent.contexts["Stacktrace"] = mapOf("Value" to event.throwableText)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.move.cli.toolwindow

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.runReadAction
import com.intellij.ui.tree.AsyncTreeModel
import com.intellij.ui.tree.StructureTreeModel
import com.intellij.ui.treeStructure.CachingSimpleNode
Expand Down Expand Up @@ -122,7 +123,7 @@ class MoveProjectsTreeStructure(
}

override fun buildChildren(): Array<SimpleNode> = emptyArray()
override fun getName(): String = module.qualName?.editorText() ?: "null"
override fun getName(): String = runReadAction { module.qualName?.editorText() ?: "null" }
override fun toTestString(): String = "Module($name)"
}

Expand All @@ -141,7 +142,7 @@ class MoveProjectsTreeStructure(
}

override fun buildChildren(): Array<SimpleNode> = emptyArray()
override fun getName(): String = function.qualName?.editorText() ?: "null"
override fun getName(): String = runReadAction { function.qualName?.editorText() ?: "null" }
override fun toTestString(): String = "Entrypoint($name)"
}

Expand All @@ -160,7 +161,7 @@ class MoveProjectsTreeStructure(
}

override fun buildChildren(): Array<SimpleNode> = emptyArray()
override fun getName(): String = function.qualName?.editorText() ?: "null"
override fun getName(): String = runReadAction { function.qualName?.editorText() ?: "null" }
override fun toTestString(): String = "View($name)"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MvRenameFileProcessor : RenamePsiFileProcessor() {
}

private fun MoveFile.singleModule(): MvModule? {
val virtualFile = virtualFile ?: return null
return modules()
.singleOrNull()
?.takeIf { it.name == virtualFile.nameWithoutExtension }
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/move/lang/MoveFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.move.lang.core.psi.*
import org.move.lang.core.psi.ext.ancestorOrSelf
import org.move.lang.core.psi.ext.childrenOfType
import org.move.lang.core.psi.ext.modules
import org.move.openapiext.checkReadAccessAllowed
import org.move.openapiext.resolveAbsPath
import org.move.openapiext.toPsiFile
import org.move.stdext.chain
Expand All @@ -35,6 +36,7 @@ fun findMoveTomlPath(currentFilePath: Path): Path? {
return null
}

// requires ReadAccess
val PsiElement.moveProject: MoveProject? get() {
return project.moveProjectsService.findMoveProject(this)
}
Expand All @@ -50,7 +52,7 @@ fun VirtualFile.toNioPathOrNull(): Path? {
}

fun PsiFile.toNioPathOrNull(): Path? {
return this.originalFile.virtualFile.toNioPathOrNull()
return this.originalFile.virtualFile?.toNioPathOrNull()
}

abstract class MoveFileBase(fileViewProvider: FileViewProvider): PsiFileBase(fileViewProvider, MoveLanguage) {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/org/move/lang/core/psi/ext/MvElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ val MvPath.isMslScope: Boolean get() = this.isMslInner()

val MvModuleRef.isMslScope: Boolean get() = this.isMslInner()

@Deprecated("Use specialized receiver type property isMslScope if possible")
fun PsiElement.isMsl(): Boolean = isMslInner()
//fun PsiElement.isMslLegacy(): Boolean {
// return CachedValuesManager.getProjectPsiDependentCache(this) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/move/lang/core/psi/ext/MvModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.move.lang.core.types.ItemQualName
import org.move.lang.core.types.address
import org.move.lang.index.MvModuleSpecIndex
import org.move.lang.moveProject
import org.move.openapiext.checkReadAccessAllowed
import org.move.openapiext.isReadAccessAllowed
import javax.swing.Icon

fun MvModule.hasTestFunctions(): Boolean = this.testFunctions().isNotEmpty()
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/move/openapiext/files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fun Project.allMoveFiles(): List<MoveFile> {
.sortedByDescending { it.contentRoot.fsDepth }
.map { moveProject ->
moveProject.processMoveFiles {
val filePath = it.virtualFile.path
// virtualFile can be null
val filePath = it.virtualFile?.path ?: return@processMoveFiles true

if (filePath in visited) return@processMoveFiles true
visited.add(filePath)
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/move/openapiext/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ fun checkWriteAccessNotAllowed() {
check(!ApplicationManager.getApplication().isWriteAccessAllowed)
}

fun isReadAccessAllowed() = ApplicationManager.getApplication().isReadAccessAllowed

fun checkReadAccessAllowed() {
check(ApplicationManager.getApplication().isReadAccessAllowed) {
"Needs read action"
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/move/utils/tests/FileTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class FileTree(val rootDirInfo: FilesystemEntry.Directory) {
}

class TestProject(
private val project: Project,
val project: Project,
val rootDirectory: VirtualFile,
private val filesWithCaret: List<String>,
private val filesWithNamedElement: List<String>
Expand Down
104 changes: 104 additions & 0 deletions src/test/kotlin/org/move/cli/LoadMoveProjectsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.move.cli

import org.move.utils.tests.FileTreeBuilder
import org.move.utils.tests.MvProjectTestBase

class LoadMoveProjectsTest: MvProjectTestBase() {
fun `test load project with invalid config yaml file`() {
val moveProject = moveProject {
_aptos {
config_yaml(
"""
---
profiles:
default:
"private_key": "0x1f9abf8196bd6b34731fdf99da384180ee43002befac0e55f39aceed9869e321",,,
"""
)
}
sources { main("""<caret>""") }
moveToml(
"""
[package]
name = "move_toml"
version = "0.1.0"
"""
)
}
check(moveProject.currentPackage.moveToml.packageName == "move_toml")
check(moveProject.currentPackage.aptosConfigYaml == null)
}

fun `test load project invalid move toml file`() {
moveProject {
sources { main("""<caret>""") }
moveToml(
"""
[package]]
name = "move_toml"
version = "0.1.0"
"""
)
}
}

fun `test load valid project`() {
val moveProject = moveProject {
_aptos {
config_yaml(
"""
---
profiles:
default:
private_key: "0x1f9abf8196bd6b34731fdf99da384180ee43002befac0e55f39aceed9869e321"
public_key: "0x21dae149d5c16ec825558eb86c6434a2aa4bd1a54b66430dfdea983f3f5faaec"
account: 2ec4190dd6eec80913e02da22de89700a9b5e13e27b51750191b7ceb3eee1a2f
rest_url: "https://fullnode.testnet.aptoslabs.com"
emergency:
private_key: "0x3976a9fa9196a4e0240e64d1837fec879d65229194aef942fb81a7b41ff62912"
public_key: "0xb1af70c600661e19d631296d89b8fd51aecafd2e7da76d27a9f462046647e17e"
account: c5f39b983cf06b9e26dc149b3a8c0d7fcb27733954fa86eff7f3c70427644b1f
rest_url: "https://fullnode.testnet.aptoslabs.com"
"""
)
}
sources { main("""<caret>""") }
moveToml(
"""
[package]
name = "move_toml"
version = "0.1.0"
[addresses]
Std = "0x1"
DiemFramework = "0xB1E55ED"
[dependencies]
Debug = { local = "./stdlib/Debug.move" }
"""
)
}
val movePackage = moveProject.currentPackage
val moveToml = movePackage.moveToml

check(movePackage.aptosConfigYaml?.profiles == setOf("default", "emergency"))

check(moveToml.packageTable?.name == "move_toml")
check(moveToml.packageTable?.version == "0.1.0")
check(moveToml.packageTable?.authors.orEmpty().isEmpty())
check(moveToml.packageTable?.license == null)

check(moveToml.addresses.size == 2)
check(moveToml.addresses["Std"]!!.first == "0x1")
check(moveToml.addresses["DiemFramework"]!!.first == "0xB1E55ED")

check(moveToml.deps.size == 1)
}

private fun moveProject(builder: FileTreeBuilder.() -> Unit): MoveProject {
val testProject = testProject(builder)
val moveProject = testProject.project.moveProjectsService.allProjects.singleOrNull()
?: error("Move project expected")
return moveProject
}
}
36 changes: 0 additions & 36 deletions src/test/kotlin/org/move/cli/MoveTomlTest.kt

This file was deleted.

Loading

0 comments on commit 03201ba

Please sign in to comment.