File tree Expand file tree Collapse file tree 3 files changed +82
-2
lines changed
kotlin/org/move/ide/liveTemplates
test/kotlin/org/move/ide/liveTemplates Expand file tree Collapse file tree 3 files changed +82
-2
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,11 @@ import com.intellij.psi.util.PsiTreeUtil
10
10
import com.intellij.psi.util.PsiUtilCore
11
11
import org.move.ide.MvHighlighter
12
12
import org.move.lang.MoveLanguage
13
+ import org.move.lang.core.psi.MvBlockFields
13
14
import org.move.lang.core.psi.MvCodeBlock
15
+ import org.move.lang.core.psi.MvEnumBody
14
16
import org.move.lang.core.psi.MvModule
17
+ import org.move.lang.core.psi.MvType
15
18
16
19
sealed class MvContextType (presentableName : String ): TemplateContextType(presentableName) {
17
20
@@ -40,13 +43,22 @@ sealed class MvContextType(presentableName: String): TemplateContextType(present
40
43
override fun isInContext (element : PsiElement ): Boolean = owner(element) is MvModule
41
44
}
42
45
43
- class Block : MvContextType (" Block " ) {
46
+ class Block : MvContextType (" Code block " ) {
44
47
override fun isInContext (element : PsiElement ): Boolean = owner(element) is MvCodeBlock
45
48
}
46
49
50
+ class Type : MvContextType (" Type" ) {
51
+ override fun isInContext (element : PsiElement ): Boolean = owner(element) is MvType
52
+ }
53
+
47
54
companion object {
48
55
private fun owner (element : PsiElement ): PsiElement ? = PsiTreeUtil .findFirstParent(element) {
49
- it is MvCodeBlock || it is MvModule || it is PsiFile
56
+ it is MvCodeBlock
57
+ || it is MvModule
58
+ || it is PsiFile
59
+ || it is MvType
60
+ // filter out enum/struct body
61
+ || it is MvEnumBody || it is MvBlockFields
50
62
}
51
63
}
52
64
}
Original file line number Diff line number Diff line change 192
192
implementation =" org.move.ide.liveTemplates.MvContextType$Block"
193
193
contextId =" MOVE_BLOCK"
194
194
baseContextId =" MOVE_FILE" />
195
+ <liveTemplateContext
196
+ implementation =" org.move.ide.liveTemplates.MvContextType$Type"
197
+ contextId =" MOVE_TYPE"
198
+ baseContextId =" MOVE_FILE" />
195
199
196
200
<renamePsiElementProcessor implementation =" org.move.ide.refactoring.MvRenameProcessor"
197
201
order =" first"
Original file line number Diff line number Diff line change
1
+ package org.move.ide.liveTemplates
2
+
3
+ import com.intellij.openapi.actionSystem.IdeActions
4
+ import org.intellij.lang.annotations.Language
5
+ import org.move.utils.tests.MvTestBase
6
+
7
+ class MvLiveTemplatesTest : MvTestBase () {
8
+
9
+ fun `test no test function in type` () = noSnippet("""
10
+ module 0x1::m {
11
+ struct S { val: t/*caret*/}
12
+ }
13
+ """ )
14
+
15
+ fun `test no test function in struct fields block` () = noSnippet("""
16
+ module 0x1::m {
17
+ struct S { t/*caret*/ }
18
+ }
19
+ """ )
20
+
21
+ fun `test no test function in enum variants block` () = noSnippet("""
22
+ module 0x1::m {
23
+ enum S { t/*caret*/ }
24
+ }
25
+ """ )
26
+
27
+ fun `test no test function in tuple struct type` () = noSnippet("""
28
+ module 0x1::m {
29
+ struct S(u8, t/*caret*/)
30
+ }
31
+ """ )
32
+
33
+ fun `test no test function in expr` () = noSnippet("""
34
+ module 0x1::m {
35
+ fun main() {
36
+ t/*caret*/
37
+ }
38
+ }
39
+ """ )
40
+
41
+ fun `test no test function outside module` () = noSnippet("""
42
+ t/*caret*/
43
+ module 0x1::m {
44
+ }
45
+ """ )
46
+
47
+ fun `test test function in module body` () = expandSnippet("""
48
+ module 0x1::m {
49
+ t/*caret*/
50
+ }
51
+ """ , """
52
+ module 0x1::m {
53
+ #[test]
54
+ fun /*caret*/() {
55
+
56
+ }
57
+ }
58
+ """ )
59
+
60
+ private fun expandSnippet (@Language(" Move" ) before : String , @Language(" Move" ) after : String ) =
61
+ checkEditorAction(before, after, IdeActions .ACTION_EXPAND_LIVE_TEMPLATE_BY_TAB )
62
+
63
+ private fun noSnippet (@Language(" Move" ) code : String ) = expandSnippet(code, code)
64
+ }
You can’t perform that action at this time.
0 commit comments