-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix parser and highlighting for qualified path in attributes (#253)
- Loading branch information
Showing
18 changed files
with
235 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,55 @@ | ||
package org.move.lang.core.psi.ext | ||
|
||
import com.intellij.lang.ASTNode | ||
import com.intellij.psi.PsiElement | ||
import org.move.lang.core.psi.* | ||
import org.move.lang.core.psi.impl.MvNamedElementImpl | ||
import org.move.lang.core.resolve.ref.MvPath2Reference | ||
import org.move.lang.core.resolve.ref.MvPolyVariantReference | ||
import org.move.lang.core.resolve.ref.MvPolyVariantReferenceBase | ||
import org.move.lang.core.resolve.ref.MvPolyVariantReferenceCached | ||
|
||
val MvAttrItem.unqualifiedName: String get() = this.identifier.text | ||
import org.move.lang.core.resolve2.PathKind | ||
import org.move.lang.core.resolve2.pathKind | ||
|
||
val MvAttrItem.unqualifiedIdent: PsiElement? | ||
get() { | ||
val path = this.path | ||
if (path.pathKind(false) !is PathKind.UnqualifiedPath) return null | ||
return path.identifier | ||
} | ||
val MvAttrItem.unqualifiedName: String? get() = this.unqualifiedIdent?.text | ||
|
||
val MvAttrItem.attr: MvAttr? get() = this.parent as? MvAttr | ||
val MvAttrItem.innerAttrItems: List<MvAttrItem> get() = this.attrItemList?.attrItemList.orEmpty() | ||
|
||
val MvAttrItem.isAbortCode: Boolean get() = this.identifier.textMatches("abort_code") | ||
val MvAttrItem.isTest: Boolean get() = this.identifier.textMatches("test") | ||
val MvAttrItem.isAbortCode: Boolean get() = this.unqualifiedIdent?.textMatches("abort_code") == true | ||
val MvAttrItem.isTest: Boolean get() = this.unqualifiedIdent?.textMatches("test") == true | ||
|
||
class AttrItemReferenceImpl( | ||
element: MvAttrItem, | ||
element: MvPath, | ||
val ownerFunction: MvFunction | ||
) : MvPolyVariantReferenceCached<MvAttrItem>(element) { | ||
) : MvPolyVariantReferenceBase<MvPath>(element), MvPath2Reference { | ||
|
||
override fun multiResolveInner(): List<MvNamedElement> { | ||
override fun multiResolve(): List<MvNamedElement> { | ||
return ownerFunction.parameters | ||
.map { it.patBinding } | ||
.filter { it.name == element.referenceName } | ||
} | ||
|
||
// override fun multiResolveInner(): List<MvNamedElement> { | ||
// } | ||
} | ||
|
||
abstract class MvAttrItemMixin(node: ASTNode): MvNamedElementImpl(node), | ||
MvAttrItem { | ||
|
||
override fun getReference(): MvPolyVariantReference? { | ||
val attr = this.ancestorStrict<MvAttr>() ?: return null | ||
attr.attrItemList | ||
.singleOrNull() | ||
?.takeIf { it.isTest } ?: return null | ||
val ownerFunction = attr.attributeOwner as? MvFunction ?: return null | ||
return AttrItemReferenceImpl(this, ownerFunction) | ||
} | ||
// override fun getReference(): MvPolyVariantReference? { | ||
// val attr = this.ancestorStrict<MvAttr>() ?: return null | ||
// attr.attrItemList | ||
// .singleOrNull() | ||
// ?.takeIf { it.isTest } ?: return null | ||
// val ownerFunction = attr.attributeOwner as? MvFunction ?: return null | ||
// return AttrItemReferenceImpl(this, ownerFunction) | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/kotlin/org/move/ide/annotator/AttrHighlightingAnnotatorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.move.ide.annotator | ||
|
||
import org.move.ide.colors.MvColor | ||
import org.move.utils.tests.annotation.AnnotatorTestCase | ||
|
||
class AttrHighlightingAnnotatorTest: AnnotatorTestCase(HighlightingAnnotator::class) { | ||
override fun setUp() { | ||
super.setUp() | ||
annotationFixture.registerSeverities(MvColor.entries.map(MvColor::testSeverity)) | ||
} | ||
|
||
fun `test highlight annotator identifier`() = checkHighlighting(""" | ||
module 0x1::m { | ||
<ATTRIBUTE>#</ATTRIBUTE><ATTRIBUTE>[</ATTRIBUTE><ATTRIBUTE>view</ATTRIBUTE><ATTRIBUTE>]</ATTRIBUTE> | ||
fun foo() {} | ||
} | ||
""") | ||
|
||
fun `test highlight annotator fq name`() = checkHighlighting(""" | ||
module 0x1::m { | ||
<ATTRIBUTE>#</ATTRIBUTE><ATTRIBUTE>[</ATTRIBUTE><ATTRIBUTE>lint</ATTRIBUTE><ATTRIBUTE>::</ATTRIBUTE><ATTRIBUTE>view</ATTRIBUTE><ATTRIBUTE>]</ATTRIBUTE> | ||
fun foo() {} | ||
} | ||
""") | ||
|
||
fun `test highlight annotator initializer`() = checkHighlighting(""" | ||
module 0x1::m { | ||
<ATTRIBUTE>#</ATTRIBUTE><ATTRIBUTE>[</ATTRIBUTE><ATTRIBUTE>test</ATTRIBUTE><ATTRIBUTE>(</ATTRIBUTE><ATTRIBUTE>signer</ATTRIBUTE> <ATTRIBUTE>=</ATTRIBUTE> <ADDRESS>@0x1</ADDRESS>)<ATTRIBUTE>]</ATTRIBUTE> | ||
fun foo() {} | ||
} | ||
""") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.