diff --git a/src/main/grammar/Smithy.bnf b/src/main/grammar/Smithy.bnf index e1e791a..2bb1c8b 100644 --- a/src/main/grammar/Smithy.bnf +++ b/src/main/grammar/Smithy.bnf @@ -370,6 +370,7 @@ id ::= symbol | null | boolean | simple_type_name | TOKEN_PUT | TOKEN_READ | TOKEN_UPDATE | TOKEN_DELETE | TOKEN_COLLECTION_OPERATIONS | TOKEN_ENUM | TOKEN_INT_ENUM | TOKEN_FOR | TOKEN_WITH { methods=[null="" boolean=""] + mixin="software.amazon.smithy.intellij.psi.SmithyIdMixin" } //Specialized incomplete/intermediate elements which allow for a seamless parsing experience when typing out new entries diff --git a/src/main/kotlin/software/amazon/smithy/intellij/SmithyReference.kt b/src/main/kotlin/software/amazon/smithy/intellij/SmithyReference.kt index 4d9a497..014fb91 100644 --- a/src/main/kotlin/software/amazon/smithy/intellij/SmithyReference.kt +++ b/src/main/kotlin/software/amazon/smithy/intellij/SmithyReference.kt @@ -15,6 +15,7 @@ import software.amazon.smithy.intellij.psi.SmithyArray import software.amazon.smithy.intellij.psi.SmithyControl import software.amazon.smithy.intellij.psi.SmithyDefinition import software.amazon.smithy.intellij.psi.SmithyEntry +import software.amazon.smithy.intellij.psi.SmithyId import software.amazon.smithy.intellij.psi.SmithyKey import software.amazon.smithy.intellij.psi.SmithyMemberDefinition import software.amazon.smithy.intellij.psi.SmithyMemberId @@ -139,6 +140,18 @@ data class SmithyKeyReference(val key: SmithyKey) : SmithyReference(key, soft = } } +/** + * A [PsiReference] from a [SmithyId] to a [SmithyShapeDefinition] (through its parent [SmithyShapeId]). + * + * [SmithyKey] from fields within a [SmithyTrait] are resolved to their corresponding nested member. + * + * @author Ian Caffey + * @since 1.0 + */ +data class SmithyIdReference(val id: SmithyId) : SmithyReference(id, soft = id.parent !is SmithyShapeId) { + override fun resolve() = (id.parent as? SmithyShapeId)?.resolve() +} + /** * A [PsiReference] from a [SmithyMemberId] to a [SmithyMemberDefinition]. * diff --git a/src/main/kotlin/software/amazon/smithy/intellij/psi/ext.kt b/src/main/kotlin/software/amazon/smithy/intellij/psi/ext.kt index b98b771..c9f3520 100644 --- a/src/main/kotlin/software/amazon/smithy/intellij/psi/ext.kt +++ b/src/main/kotlin/software/amazon/smithy/intellij/psi/ext.kt @@ -20,6 +20,7 @@ import com.intellij.psi.util.PsiTreeUtil.getChildrenOfTypeAsList import com.intellij.psi.util.PsiTreeUtil.getParentOfType import com.intellij.psi.util.siblings import software.amazon.smithy.intellij.SmithyFile +import software.amazon.smithy.intellij.SmithyIdReference import software.amazon.smithy.intellij.SmithyKeyReference import software.amazon.smithy.intellij.SmithyLanguage import software.amazon.smithy.intellij.SmithyMemberReference @@ -256,6 +257,10 @@ abstract class SmithyEnumMemberMixin(node: ASTNode) : SmithyPsiElement(node), Sm } } +abstract class SmithyIdMixin(node: ASTNode) : SmithyPsiElement(node), SmithyId { + val reference by lazy { SmithyIdReference(this) } +} + interface SmithyImportExt : SmithyStatement abstract class SmithyImportMixin(node: ASTNode) : SmithyPsiElement(node), SmithyImport @@ -855,6 +860,7 @@ abstract class SmithyStringMixin(node: ASTNode) : SmithyPrimitiveImpl(node), Smi value = it parsed = true } + override val reference by lazy { SmithyShapeReference(this) } override fun subtreeChanged() { @@ -885,6 +891,7 @@ abstract class SmithyTextBlockMixin(node: ASTNode) : SmithyPrimitiveImpl(node), value = it parsed = true } + override val reference by lazy { SmithyShapeReference(this) } override fun subtreeChanged() {