Skip to content

Commit

Permalink
Added underlying reference to SmithyId within SmithyShapeId to resolv…
Browse files Browse the repository at this point in the history
…e node conflict issues when IntelliJ is determining which node under the cursor to use for reference tracing.
  • Loading branch information
iancaffey committed Aug 31, 2022
1 parent 9bdef02 commit 299adb4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/grammar/Smithy.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/software/amazon/smithy/intellij/SmithyReference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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].
*
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/software/amazon/smithy/intellij/psi/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 299adb4

Please sign in to comment.