Skip to content

Commit

Permalink
Merge pull request #61 from pontem-network/1.16.0
Browse files Browse the repository at this point in the history
1.16.0
  • Loading branch information
mkurnikov authored Aug 11, 2022
2 parents e3a83fb + c10b9a3 commit b526ed7
Show file tree
Hide file tree
Showing 77 changed files with 941 additions and 495 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
gradle-properties-version: [ 211, 212, 213, 221, 222 ]
gradle-properties-version: [ 212, 213, 221, 222 ]

runs-on: ${{ matrix.os }}
env:
Expand Down
21 changes: 3 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jetbrains.intellij.tasks.RunPluginVerifierTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*

val propsVersion = System.getenv("GRADLE_PROPS_VERSION") ?: "222"
val propsVersion = System.getenv("GRADLE_PROPS_VERSION") ?: "212"
val publishingToken = System.getenv("JB_PUB_TOKEN") ?: null

val baseProperties = "base-gradle.properties"
Expand All @@ -20,7 +20,7 @@ fun prop(key: String): String = props[key].toString()
val kotlinVersion = "1.7.10"

val pluginJarName = "intellij-move-$propsVersion"
val pluginVersion = "1.15.0"
val pluginVersion = "1.16.0"
val pluginGroup = "org.move"

group = pluginGroup
Expand All @@ -29,7 +29,7 @@ version = pluginVersion
plugins {
id("java")
kotlin("jvm") version "1.7.10"
id("org.jetbrains.intellij") version "1.7.0"
id("org.jetbrains.intellij") version "1.8.0"
id("org.jetbrains.grammarkit") version "2021.2.2"
}

Expand Down Expand Up @@ -95,20 +95,6 @@ allprojects {
purgeOldFiles.set(true)
}

// val generateMoveTomlLexer = task<GenerateLexerTask>("generateMoveTomlLexer") {
// source.set("src/main/grammars/MoveTomlLexer.flex")
// targetDir.set("src/main/gen/org/moveToml/lang")
// targetClass.set("_MoveTomlLexer")
// purgeOldFiles.set(true)
// }
// val generateMoveTomlParser = task<GenerateParserTask>("generateMoveTomlParser") {
// source.set("src/main/grammars/MoveTomlParser.bnf")
// targetRoot.set("src/main/gen")
// pathToParser.set("/org/move/lang/MoveTomlParser.java")
// pathToPsiRoot.set("/org/move/lang/psi")
// purgeOldFiles.set(true)
// }

tasks {
// workaround for gradle not seeing tests in 2021.3+
val test by getting(Test::class) {
Expand Down Expand Up @@ -146,7 +132,6 @@ allprojects {

withType<KotlinCompile> {
dependsOn(
// generateMoveTomlLexer, generateMoveTomlParser,
generateMoveLexer, generateMoveParser
)
kotlinOptions {
Expand Down
13 changes: 0 additions & 13 deletions gradle-211.properties

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/grammars/MoveParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ AttrItem ::= IDENTIFIER AttrItemArguments?
mixin = "org.move.lang.core.psi.ext.MvAttrItemMixin"
}
AttrItemArguments ::= '(' <<comma_sep_items AttrItemArgument>> ')'
AttrItemArgument ::= IDENTIFIER '=' LitExpr
AttrItemArgument ::= IDENTIFIER ('=' LitExpr)?
{
implements = [
"org.move.lang.core.resolve.MvReferenceElement"
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/move/cli/settings/MoveSettingsPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.move.cli.settings
import com.intellij.openapi.Disposable
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.util.Disposer
import com.intellij.ui.layout.CCFlags
import com.intellij.ui.layout.LayoutBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.SimpleToolWindowPanel
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowEP
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.openapi.wm.ex.ToolWindowManagerEx
import com.intellij.ui.ScrollPaneFactory
import com.intellij.ui.content.ContentFactory
import org.move.cli.MoveProject
Expand All @@ -23,14 +20,14 @@ import org.move.cli.hasMoveProject
import org.move.cli.moveProjects
import javax.swing.JComponent

class MoveToolWindowFactory : ToolWindowFactory, DumbAware {
class AptosToolWindowFactory : ToolWindowFactory, DumbAware {
private val lock: Any = Any()

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
// guessAndSetupRustProject(project)
project.moveProjects.refreshAllProjects()

val toolwindowPanel = MoveToolWindowPanel(project)
val toolwindowPanel = AptosToolWindowPanel(project)
val tab = ContentFactory.SERVICE.getInstance()
.createContent(toolwindowPanel, "", false)
toolWindow.contentManager.addContent(tab)
Expand All @@ -54,8 +51,8 @@ class MoveToolWindowFactory : ToolWindowFactory, DumbAware {
// }
}

private class MoveToolWindowPanel(project: Project) : SimpleToolWindowPanel(true, false) {
private val aptosTab = MoveToolWindow(project)
private class AptosToolWindowPanel(project: Project) : SimpleToolWindowPanel(true, false) {
private val aptosTab = AptosToolWindow(project)

init {
toolbar = aptosTab.toolbar.component
Expand All @@ -65,13 +62,13 @@ private class MoveToolWindowPanel(project: Project) : SimpleToolWindowPanel(true

override fun getData(dataId: String): Any? =
when {
MoveToolWindow.SELECTED_MOVE_PROJECT.`is`(dataId) -> aptosTab.selectedProject
AptosToolWindow.SELECTED_MOVE_PROJECT.`is`(dataId) -> aptosTab.selectedProject
PlatformDataKeys.TREE_EXPANDER.`is`(dataId) -> aptosTab.treeExpander
else -> super.getData(dataId)
}
}

class MoveToolWindow(private val project: Project) {
class AptosToolWindow(private val project: Project) {

val toolbar: ActionToolbar = run {
val actionManager = ActionManager.getInstance()
Expand Down Expand Up @@ -108,7 +105,7 @@ class MoveToolWindow(private val project: Project) {
}

companion object {
private val LOG: Logger = logger<MoveToolWindow>()
private val LOG: Logger = logger<AptosToolWindow>()

@JvmStatic
val SELECTED_MOVE_PROJECT: DataKey<MoveProject> = DataKey.create("SELECTED_MOVE_PROJECT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import com.intellij.ui.tree.StructureTreeModel
import com.intellij.ui.treeStructure.CachingSimpleNode
import com.intellij.ui.treeStructure.SimpleNode
import com.intellij.ui.treeStructure.SimpleTreeStructure
import com.intellij.util.containers.toArray
import org.move.cli.MovePackage
import org.move.cli.MoveProject
import org.move.ide.MoveIcons
import org.move.lang.core.psi.MvFunction
import org.move.lang.core.psi.MvModule
import org.move.lang.core.psi.ext.functions
import org.move.lang.core.psi.ext.isTest
import org.move.lang.core.psi.ext.isTestOnly
import org.move.lang.core.psi.ext.testFunctions
import org.move.lang.core.psi.ext.*
import org.move.lang.core.resolve.ref.Visibility
import org.move.lang.modules
import org.move.stdext.iterateMoveFiles
Expand Down Expand Up @@ -50,7 +49,7 @@ class MoveProjectsTreeStructure(
override fun toTestString() = "Root"
}

class Project(val moveProject: MoveProject, parent: SimpleNode) : MoveSimpleNode(parent) {
open class Package(val movePackage: MovePackage, parent: SimpleNode) : MoveSimpleNode(parent) {
init {
icon = MoveIcons.MOVE
}
Expand All @@ -59,29 +58,49 @@ class MoveProjectsTreeStructure(
val modules = mutableListOf<MvModule>()
val testModules = mutableListOf<MvModule>()
val scriptFunctions = mutableListOf<MvFunction>()
for (folder in moveProject.currentPackage.moveFolders()) {
folder.iterateMoveFiles(moveProject.project) {
for (folder in movePackage.moveFolders()) {
folder.iterateMoveFiles(movePackage.project) {
for (module in it.modules()) {
if (!module.isTestOnly) modules.add(module)
if (module.testFunctions().isNotEmpty()) testModules.add(module)
scriptFunctions.addAll(
module.functions(Visibility.PublicScript)
module.entryFunctions()
.filter { fn -> !fn.isTestOnly && !fn.isTest })
}
true
}
}
return arrayOf(
Modules(emptyList(), this),
Modules(modules, this),
Entrypoints(scriptFunctions, this),
Tests(emptyList(), this)
)
}

override fun getName(): String = movePackage.packageName
override fun toTestString(): String = "Package($name)"
}

class Project(val moveProject: MoveProject, parent: SimpleNode) : Package(moveProject.currentPackage, parent) {
override fun buildChildren(): Array<SimpleNode> {
val dependencyPackages = moveProject.dependencies.map { it.first }
return arrayOf(
*super.buildChildren(),
DependencyPackages(dependencyPackages, this),
)
}

override fun getName(): String = moveProject.currentPackage.packageName
override fun toTestString(): String = "Project($name)"
}

class DependencyPackages(val packages: List<MovePackage>, parent: SimpleNode): MoveSimpleNode(parent) {
override fun buildChildren(): Array<SimpleNode> {
return packages.map { Package(it, this) }.toTypedArray()
}
override fun getName(): String = "Dependencies"
override fun toTestString(): String = "Dependencies"
}

class Modules(val modules: List<MvModule>, parent: SimpleNode) : MoveSimpleNode(parent) {
override fun buildChildren(): Array<SimpleNode> =
modules.map { Module(it, this) }.toTypedArray()
Expand All @@ -91,6 +110,10 @@ class MoveProjectsTreeStructure(
}

class Module(val module: MvModule, parent: SimpleNode) : MoveSimpleNode(parent) {
init {
icon = MoveIcons.MODULE
}

override fun buildChildren(): Array<SimpleNode> = emptyArray()
override fun getName(): String = module.fqName
override fun toTestString(): String = "Module($name)"
Expand All @@ -106,6 +129,10 @@ class MoveProjectsTreeStructure(
}

class Entrypoint(val function: MvFunction, parent: SimpleNode) : MoveSimpleNode(parent) {
init {
icon = MoveIcons.FUNCTION
}

override fun buildChildren(): Array<SimpleNode> = emptyArray()
override fun getName(): String = function.fqName
override fun toTestString(): String = "Entrypoint($name)"
Expand Down
127 changes: 127 additions & 0 deletions src/main/kotlin/org/move/ide/MvBreadcrumbsProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.move.ide

import com.intellij.lang.Language
import com.intellij.psi.PsiElement
import com.intellij.ui.breadcrumbs.BreadcrumbsProvider
import org.move.lang.MoveLanguage
import org.move.lang.core.psi.*

class MvBreadcrumbsProvider : BreadcrumbsProvider {

private interface MvElementHandler<T : MvElement> {
fun accepts(e: PsiElement): Boolean
fun elementInfo(e: T): String
}

private val handlers = listOf<MvElementHandler<*>>(
MvModuleHandler,
MvFunctionHandler,
MvIfHandler,
MvElseHandler,
MvWhileHandler,
MvBlockHandler,
MvNamedHandler,
)

private object MvNamedHandler : MvElementHandler<MvNamedElement> {
override fun accepts(e: PsiElement): Boolean = e is MvNamedElement

override fun elementInfo(e: MvNamedElement): String = e.name.let { "$it" }
}

private object MvModuleHandler : MvElementHandler<MvModule> {
override fun accepts(e: PsiElement): Boolean = e is MvModule

override fun elementInfo(e: MvModule): String = e.fqName
}

private object MvFunctionHandler : MvElementHandler<MvFunction> {
override fun accepts(e: PsiElement): Boolean = e is MvFunction

override fun elementInfo(e: MvFunction): String = e.name.let { "$it()" }
}

private object MvBlockHandler : MvElementHandler<MvCodeBlock> {
override fun accepts(e: PsiElement): Boolean = e is MvCodeBlock

override fun elementInfo(e: MvCodeBlock): String = "{...}"
}

private object MvIfHandler : MvElementHandler<MvIfExpr> {
override fun accepts(e: PsiElement): Boolean = e is MvIfExpr

override fun elementInfo(e: MvIfExpr): String {
return buildString {
append("if")

val condition = e.condition
if (condition != null) {
if (condition.expr is MvCodeBlock) {
append(" {...}")
} else {
append(' ').append(condition.text.truncate(TextKind.INFO))
}
}
}
}
}

private object MvElseHandler : MvElementHandler<MvElseBlock> {
override fun accepts(e: PsiElement): Boolean = e is MvElseBlock

override fun elementInfo(e: MvElseBlock): String = "else"
}

private object MvWhileHandler : MvElementHandler<MvWhileExpr> {
override fun accepts(e: PsiElement): Boolean = e is MvWhileExpr

override fun elementInfo(e: MvWhileExpr): String {
return buildString {
append("while")

val condition = e.condition
if (condition != null) {
if (condition.expr is MvCodeBlock) {
append(" {...}")
} else {
append(' ').append(condition.text.truncate(TextKind.INFO))
}
}
}
}
}

@Suppress("UNCHECKED_CAST")
private fun handler(e: PsiElement): MvElementHandler<in MvElement>? {
return if (e is MvElement)
handlers.firstOrNull { it.accepts(e) } as MvElementHandler<in MvElement>?
else null
}

override fun getLanguages(): Array<Language> = LANGUAGES

override fun acceptElement(e: PsiElement): Boolean = handler(e) != null

override fun getElementInfo(e: PsiElement): String = handler(e)!!.elementInfo(e as MvElement)

override fun getElementTooltip(e: PsiElement): String? = null

companion object {
@Suppress("unused")
private enum class TextKind(val maxTextLength: Int) {
INFO(16),
TOOLTIP(100)
}

private val LANGUAGES: Array<Language> = arrayOf(MoveLanguage)

const val ellipsis = "${Typography.ellipsis}"

private fun String.truncate(kind: TextKind): String {
val maxLength = kind.maxTextLength
return if (length > maxLength)
"${substring(0, maxLength - ellipsis.length)}$ellipsis"
else this
}
}
}
Loading

0 comments on commit b526ed7

Please sign in to comment.