Skip to content

Commit

Permalink
Merge pull request #185 from pontem-network/positional-fields
Browse files Browse the repository at this point in the history
Positional fields
  • Loading branch information
mkurnikov authored Aug 30, 2024
2 parents b2dedd4 + 6ac8fc6 commit 15c01ad
Show file tree
Hide file tree
Showing 145 changed files with 2,525 additions and 1,995 deletions.
187 changes: 125 additions & 62 deletions src/main/grammars/MoveParser.bnf

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions src/main/kotlin/org/move/cli/MoveProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.intellij.psi.util.CachedValuesManager
import com.intellij.psi.util.PsiModificationTracker
import org.move.cli.manifest.AptosConfigYaml
import org.move.cli.manifest.MoveToml
import org.move.cli.tests.NamedAddressService
import org.move.cli.tests.NamedAddressFromTestAnnotationService
import org.move.lang.MoveFile
import org.move.lang.core.psi.MvModule
import org.move.lang.core.types.Address
Expand Down Expand Up @@ -87,23 +87,20 @@ data class MoveProject(
return map
}

fun getNamedAddressValue(name: String): String? = addressValues()[name]?.value

fun getNamedAddress(name: String): Address.Named? {
val value = getNamedAddressValue(name) ?: return null
return Address.Named(name, value, this)
}

fun getNamedAddressTestAware(name: String): Address.Named? {
val namedAddress = getNamedAddress(name)
if (namedAddress != null) return namedAddress
val declaredNamedValue = getValueOfDeclaredNamedAddress(name)
if (declaredNamedValue != null) {
return Address.Named(name, declaredNamedValue)
}
if (isUnitTestMode) {
val namedAddressService = project.service<NamedAddressService>()
val namedAddressService = project.service<NamedAddressFromTestAnnotationService>()
return namedAddressService.getNamedAddress(this, name)
}
return null
}

fun getValueOfDeclaredNamedAddress(name: String): String? = addressValues()[name]?.value

fun getAddressNamesForValue(addressValue: String): List<String> {
val addressLit = AddressLit(addressValue)
val names = mutableListOf<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class CommandConfigurationHandler {
?: return null
val moveProject = function.moveProject ?: return null

val functionId = function.functionId(moveProject) ?: return null
val functionId = function.functionId() ?: return null
val profileName = moveProject.profiles.firstOrNull()
val workingDirectory = moveProject.contentRootPath

Expand All @@ -55,11 +55,10 @@ abstract class CommandConfigurationHandler {
abstract fun getFunctionParameters(function: MvFunction): List<MvFunctionParameter>

fun generateCommand(
moveProject: MoveProject,
functionCall: FunctionCall,
signerAccount: String?,
): RsResult<String, String> {
val functionId = functionCall.functionId(moveProject) ?: return RsResult.Err("FunctionId is null")
val functionId = functionCall.functionId() ?: return RsResult.Err("FunctionId is null")

val typeParams = functionCall.typeParams
.mapNotNull { it.value }.flatMap { listOf("--type-args", it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.move.cli.runConfigurations.aptos

import com.intellij.psi.SmartPsiElementPointer
import org.move.cli.MoveProject
import org.move.lang.core.psi.MvFunction
import org.move.lang.core.psi.parametersAsBindings
import org.move.lang.core.psi.ext.*
Expand Down Expand Up @@ -31,7 +30,7 @@ data class FunctionCall(
val valueParams: MutableMap<String, FunctionCallParam?>
) {
fun itemName(): String? = item?.element?.qualName?.editorText()
fun functionId(moveProject: MoveProject): String? = item?.element?.functionId(moveProject)
fun functionId(): String? = item?.element?.functionId()

fun parametersRequired(): Boolean {
val fn = item?.element ?: return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class FunctionCallConfigurationEditor<T: FunctionCallConfigurationBase>(

// editor.functionCall = functionCall
editor.rawCommandField.text =
commandHandler.generateCommand(mp, functionCall, accountTextField.text).unwrapOrNull() ?: ""
commandHandler.generateCommand(functionCall, accountTextField.text).unwrapOrNull() ?: ""
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ object AptosTestLocator : SMTestLocator {
val name = qualifiedName.substringAfterLast(NAME_SEPARATOR)
for (element in MvNamedElementIndex.getElementsByName(project, name, scope)) {
if (element is MvFunction) {
val moveProject = element.moveProject ?: continue
if (element.qualName?.cmdText(moveProject) == qualifiedName) {
if (element.qualName?.cmdText() == qualifiedName) {
add(PsiLocation.fromPsiElement(element))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package org.move.cli.tests

import org.move.cli.MoveProject
import org.move.lang.core.types.Address
import org.move.lang.core.types.Address.Named

interface NamedAddressService {
fun getNamedAddress(moveProject: MoveProject, name: String): Address.Named?
interface NamedAddressFromTestAnnotationService {
fun getNamedAddress(moveProject: MoveProject, name: String): Named?
}

class NamedAddressServiceImpl: NamedAddressService {
override fun getNamedAddress(moveProject: MoveProject, name: String): Address.Named? = null
class NamedAddressServiceImpl: NamedAddressFromTestAnnotationService {
override fun getNamedAddress(moveProject: MoveProject, name: String): Named? = null
}


class NamedAddressServiceTestImpl: NamedAddressService {
class NamedAddressServiceTestImpl: NamedAddressFromTestAnnotationService {
val namedAddresses: MutableMap<String, String> = mutableMapOf()

override fun getNamedAddress(moveProject: MoveProject, name: String): Named? {
val value = namedAddresses[name] ?: return null
return Named(name, value, moveProject)
return Named(name, value)
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/org/move/ide/MoveIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ object MoveIcons {
val STRUCT_FIELD = AllIcons.Nodes.Field
val SCHEMA = AllIcons.Nodes.Static

val FIELD = load("/icons/nodes/field.svg")
val ENUM_VARIANT = load("/icons/nodes/enumVariant.svg")

val CONST = AllIcons.Nodes.Constant
val FUNCTION = AllIcons.Nodes.Function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class HighlightingAnnotator: MvAnnotatorBase() {
}
if (element is MvStruct) return MvColor.STRUCT
if (element is MvNamedFieldDecl) return MvColor.FIELD
if (element is MvStructDotField) return MvColor.FIELD
if (element is MvFieldLookup) return MvColor.FIELD
if (element is MvMethodCall) return MvColor.METHOD_CALL
if (element is MvPatFieldFull) return MvColor.FIELD
if (element is MvPatField) return MvColor.FIELD
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ class MvErrorAnnotator: MvAnnotatorBase() {

private fun checkModuleDef(moveHolder: MvAnnotationHolder, mod: MvModule) {
val modName = mod.name ?: return
val moveProj = mod.moveProject ?: return
val addressIdent = mod.address(moveProj) ?: return
val moveProject = mod.moveProject ?: return
val addressIdent = mod.address(moveProject) ?: return
val modIdent = Pair(addressIdent.text(), modName)
val file = mod.containingMoveFile ?: return
val duplicateIdents =
file.modules()
.filter { it.name != null }
.groupBy { Pair(it.address(moveProj)?.text(), it.name) }
.groupBy { Pair(it.address(moveProject)?.text(), it.name) }
.filter { it.value.size > 1 }
.map { it.key }
.toSet()
Expand Down Expand Up @@ -310,7 +310,7 @@ class MvErrorAnnotator: MvAnnotatorBase() {

private fun checkTypeArgumentList(
typeArgumentList: MvTypeArgumentList,
item: MvTypeParametersOwner,
item: MvGenericDeclaration,
holder: MvAnnotationHolder,
) {
val qualName = (item as? MvQualNamedElement)?.qualName ?: return
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/org/move/ide/annotator/MvSyntaxErrorAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MvSyntaxErrorAnnotator: MvAnnotatorBase() {
val visitor = object: MvVisitor() {
override fun visitLitExpr(expr: MvLitExpr) = checkLitExpr(moveHolder, expr)
override fun visitCastExpr(expr: MvCastExpr) = checkCastExpr(moveHolder, expr)
override fun visitStruct(s: MvStruct) = checkStruct(moveHolder, s)
// override fun visitStruct(s: MvStruct) = checkStruct(moveHolder, s)
override fun visitFunction(o: MvFunction) = checkFunction(moveHolder, o)
override fun visitSpecFunction(o: MvSpecFunction) = checkSpecFunction(moveHolder, o)
override fun visitIndexExpr(o: MvIndexExpr) = checkIndexExpr(moveHolder, o)
Expand Down Expand Up @@ -75,12 +75,12 @@ class MvSyntaxErrorAnnotator: MvAnnotatorBase() {
}
}

private fun checkStruct(holder: MvAnnotationHolder, struct: MvStruct) {
val native = struct.native ?: return
val errorRange = TextRange.create(native.startOffset, struct.structKw.endOffset)
Diagnostic.NativeStructNotSupported(struct, errorRange)
.addToHolder(holder)
}
// private fun checkStruct(holder: MvAnnotationHolder, struct: MvStruct) {
// val native = struct.native ?: return
// val errorRange = TextRange.create(native.startOffset, struct.structKw.endOffset)
// Diagnostic.NativeStructNotSupported(struct, errorRange)
// .addToHolder(holder)
// }

private fun checkVisibilityModifiers(
holder: MvAnnotationHolder,
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class MvDocumentationProvider : AbstractDocumentationProvider() {
// TODO: add docs for both [addresses] and [dev-addresses]
val moveProject = docElement.moveProject ?: return null
val refName = docElement.referenceName
val named = moveProject.getNamedAddress(refName) ?: return null
val named = moveProject.getNamedAddressTestAware(refName) ?: return null
val address =
named.addressLit(moveProject)?.original ?: angleWrapped("unassigned")
named.addressLit()?.original ?: angleWrapped("unassigned")
return "$refName = \"$address\""
}
is MvDocAndAttributeOwner -> generateOwnerDoc(docElement, buffer)
Expand Down Expand Up @@ -178,7 +178,7 @@ private fun PsiElement.generateDocumentation(

is MvFunctionParameter -> {
buffer += this.patBinding.identifier.text
this.typeAnnotation?.type?.generateDocumentation(buffer, ": ")
this.type?.generateDocumentation(buffer, ": ")
}

is MvTypeParameterList ->
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/move/ide/formatter/impl/spacing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun createSpacingBuilder(commonSettings: CommonCodeStyleSettings): SpacingBuilde
.after(COLON).spaceIf(true)
.before(COLON).spaceIf(false)

.before(TYPE_ANNOTATION).spacing(0, 0, 0, true, 0)
// .before(TYPE_ANNOTATION).spacing(0, 0, 0, true, 0)
.before(INITIALIZER).spacing(1, 1, 0, true, 0)

.between(AND, MUT).spacing(0, 0, 0, false, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ class FieldsDescription(val fields: Array<String>) {
val structPath = block.litExpr.path
val struct = structPath.maybeStruct ?: return null
val msl = structPath.isMslScope
// val itemContext = struct.outerItemContext(msl)
val fieldParams =
struct.fieldsMap.entries.map { (name, field) ->
struct.namedFields.map { field ->
val name = field.name
val type = field.type?.loweredType(msl) ?: TyUnknown
// val type = itemContext.getStructFieldItemTy(field).fullname()
"$name: $type"
}.toTypedArray()
return FieldsDescription(fieldParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TypeParameterInfoHandler :
val parentPath = element.parent as? MvPath ?: return null
val owner = parentPath.reference?.resolveFollowingAliases() ?: return null
// if zero type parameters
if (owner !is MvTypeParametersOwner) return null
if (owner !is MvGenericDeclaration) return null

return arrayOf(typeParamsDescription(owner.typeParameters))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MvInlayTypeHintsProvider : InlayHintsProvider<MvInlayTypeHintsProvider.Set
private fun presentVariable(element: MvElement) {
when (element) {
is MvLetStmt -> {
if (element.typeAnnotation != null) return
if (element.type != null) return
val pat = element.pat ?: return
presentTypeForPat(pat, element.initializer?.expr)
}
Expand Down

This file was deleted.

Loading

0 comments on commit 15c01ad

Please sign in to comment.