-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
highlight not supported index expr in compiler v1 with quickfix
- Loading branch information
Showing
20 changed files
with
122 additions
and
24 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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/move/ide/inspections/fixes/EnableCompilerV2FeatureFix.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,38 @@ | ||
package org.move.ide.inspections.fixes | ||
|
||
import com.intellij.model.SideEffectGuard | ||
import com.intellij.model.SideEffectGuard.EffectType.SETTINGS | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import io.ktor.http.* | ||
import org.move.cli.settings.moveSettings | ||
import org.move.ide.inspections.DiagnosticIntentionFix | ||
import org.move.ide.inspections.fixes.CompilerV2Feat.INDEXING | ||
import org.move.ide.inspections.fixes.CompilerV2Feat.RESOURCE_CONTROL | ||
|
||
enum class CompilerV2Feat(val title: String) { | ||
INDEXING("Index notation"), | ||
RESOURCE_CONTROL("Resource access control"); | ||
} | ||
|
||
class EnableCompilerV2FeatureFix( | ||
element: PsiElement, | ||
val feature: CompilerV2Feat | ||
): | ||
DiagnosticIntentionFix<PsiElement>(element) { | ||
|
||
override fun getText(): String = | ||
"Enable ${feature.title.quote()} feature of Aptos Move V2 Compiler in the plugin settings" | ||
|
||
override fun invoke(project: Project, file: PsiFile, element: PsiElement) { | ||
@Suppress("UnstableApiUsage") | ||
SideEffectGuard.checkSideEffectAllowed(SETTINGS) | ||
project.moveSettings.modify { | ||
when (feature) { | ||
INDEXING -> it.enableIndexExpr = true | ||
RESOURCE_CONTROL -> it.enableResourceAccessControl = true | ||
} | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.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
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/org/move/ide/annotator/syntaxErrors/compilerV2/IndexExprTest.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,40 @@ | ||
package org.move.ide.annotator.syntaxErrors.compilerV2 | ||
|
||
import org.move.ide.annotator.MvSyntaxErrorAnnotator | ||
import org.move.ide.inspections.fixes.CompilerV2Feat.INDEXING | ||
import org.move.utils.tests.CompilerV2Features | ||
import org.move.utils.tests.annotation.AnnotatorTestCase | ||
|
||
class IndexExprTest: AnnotatorTestCase(MvSyntaxErrorAnnotator::class) { | ||
@CompilerV2Features() | ||
fun `test vector index expr in not allowed in main code with compiler v1`() = checkWarnings(""" | ||
module 0x1::m { | ||
fun main() { | ||
let v = vector[1, 2]; | ||
<error descr="Index operator is not supported in Aptos Move V1 outside specs">v[1]</error>; | ||
} | ||
} | ||
""") | ||
|
||
@CompilerV2Features() | ||
fun `test resource index expr in not allowed in main code with compiler v1`() = checkWarnings(""" | ||
module 0x1::m { | ||
fun main() { | ||
let v = vector[1, 2]; | ||
<error descr="Index operator is not supported in Aptos Move V1 outside specs">v[1]</error>; | ||
} | ||
} | ||
""") | ||
|
||
@CompilerV2Features(INDEXING) | ||
fun `test no error with index expr in compiler v2`() = checkWarnings(""" | ||
module 0x1::m { | ||
struct S has key { field: u8 } | ||
fun main() { | ||
let v1 = vector[1, 2]; | ||
v1[1]; | ||
S[@0x1].field = 11; | ||
} | ||
} | ||
""") | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/ide/inspections/MvMissingAcquiresInspectionTest.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
2 changes: 0 additions & 2 deletions
2
src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspectionTest.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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/ide/inspections/ReplaceWithMethodCallInspectionProjectTest.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
2 changes: 0 additions & 2 deletions
2
src/test/kotlin/org/move/ide/inspections/ReplaceWithMethodCallInspectionTest.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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/ide/inspections/compilerV2/TypeCheckIndexExprTest.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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.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
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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/lang/resolve/ResolveResourceAccessSpecifiersTest.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
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
2 changes: 0 additions & 2 deletions
2
src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.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
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/org/move/lang/types/compilerV2/IndexExprTypes.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