Skip to content

Commit f7990a6

Browse files
committed
feat(devin-lang): Add support for DevIn language syntax highlighting and completion. #101
The commit introduces several changes to add support for the DevIn programming language in an IntelliJ IDEA plugin. The `DevInFile` class is modified to use the correct `DevInFileType` instance. A new `CustomVariable` enum is added to provide static variables for completion.
1 parent eda58cd commit f7990a6

File tree

11 files changed

+74
-11
lines changed

11 files changed

+74
-11
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
8585
# Run tests
8686
- name: Run Tests
87-
run: ./gradlew check -Dorg.gradle.daemon.performance.enable-monitoring=false
87+
run: ./gradlew check -Dorg.gradle.daemon.performance.enable-monitoring=false -Dorg.gradle.jvmargs=-Xmx1g
8888

8989
# Collect Tests Result of failed tests
9090
- name: Collect Tests Result
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package cc.unitmesh.language
22

3+
import cc.unitmesh.language.psi.DevInTypes
34
import com.intellij.codeInsight.completion.CompletionContributor
5+
import com.intellij.codeInsight.completion.CompletionType
6+
import com.intellij.patterns.PlatformPatterns.psiElement
7+
import cc.unitmesh.language.completion.VariableProvider
48

59
class DevInCompletionContributor : CompletionContributor() {
610
init {
7-
// extend(CompletionType.BASIC, psiElement(DevInTypes), VariableProvider())
11+
extend(CompletionType.BASIC, psiElement(DevInTypes.REF_BLOCK), VariableProvider())
812
}
913
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package cc.unitmesh.language
22

3+
import com.intellij.openapi.fileTypes.FileType
34
import com.intellij.openapi.fileTypes.LanguageFileType
45
import com.intellij.openapi.vfs.VirtualFile
56
import javax.swing.Icon
67

7-
object DevInFileType : LanguageFileType(DevInLanguage) {
8-
override fun getName(): String = "DevIn File"
8+
class DevInFileType : LanguageFileType(DevInLanguage) {
9+
override fun getName(): String = "DevInFile"
910

1011
override fun getIcon(): Icon = DevInIcons.DEFAULT
1112

@@ -14,4 +15,9 @@ object DevInFileType : LanguageFileType(DevInLanguage) {
1415
override fun getCharset(file: VirtualFile, content: ByteArray): String = "UTF-8"
1516

1617
override fun getDescription(): String = "DevIn file"
18+
19+
companion object {
20+
val INSTANCE: FileType = DevInFileType()
21+
}
22+
1723
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cc.unitmesh.language
2+
3+
import cc.unitmesh.language.lexer.DevInTokenType
4+
import cc.unitmesh.language.psi.DevInElementType
5+
import cc.unitmesh.language.psi.DevInTypes
6+
import com.intellij.lexer.Lexer
7+
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
8+
import com.intellij.openapi.editor.colors.TextAttributesKey
9+
import com.intellij.openapi.fileTypes.SyntaxHighlighter
10+
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase
11+
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase.fillMap
12+
import com.intellij.psi.tree.IElementType
13+
14+
class DevInSyntaxHighlighter : SyntaxHighlighter {
15+
override fun getHighlightingLexer(): Lexer = DevInLexerAdapter()
16+
17+
override fun getTokenHighlights(tokenType: IElementType?): Array<TextAttributesKey> {
18+
return SyntaxHighlighterBase.pack(ATTRIBUTES[tokenType])
19+
}
20+
21+
companion object {
22+
private val ATTRIBUTES: MutableMap<IElementType, TextAttributesKey> = HashMap()
23+
24+
init {
25+
ATTRIBUTES[DevInTypes.REF_BLOCK] = DefaultLanguageHighlighterColors.IDENTIFIER
26+
}
27+
}
28+
29+
}

exts/devin-lang/src/main/kotlin/cc/unitmesh/language/DevInSyntaxHighlighterFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import com.intellij.openapi.vfs.VirtualFile
77

88
class DevInSyntaxHighlighterFactory : SyntaxHighlighterFactory() {
99
override fun getSyntaxHighlighter(project: Project?, virtualFile: VirtualFile?): SyntaxHighlighter {
10-
TODO("Not yet implemented")
10+
return DevInSyntaxHighlighter()
1111
}
1212
}

exts/devin-lang/src/main/kotlin/cc/unitmesh/language/DevInTypedHandler.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package cc.unitmesh.language
22

33
import cc.unitmesh.language.psi.DevInFile
4+
import com.intellij.codeInsight.AutoPopupController
45
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
56
import com.intellij.openapi.editor.Editor
67
import com.intellij.openapi.project.Project
8+
import com.intellij.psi.PsiDocumentManager
79
import com.intellij.psi.PsiFile
810

911
class DevInTypedHandler : TypedHandlerDelegate() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cc.unitmesh.language.completion
2+
3+
enum class CustomVariable(val variable: String, val description: String) {
4+
SELECTION("selection", "The selected text"),
5+
BEFORE_CURSOR("beforeCursor", "The text before the cursor"),
6+
AFTER_CURSOR("afterCursor", "The text after the cursor"),
7+
FILE_NAME("fileName", "The name of the file"),
8+
FILE_PATH("filePath", "The path of the file"),
9+
METHOD_NAME("methodName", "The name of the method"),
10+
LANGUAGE("language", "The language of the file"),
11+
COMMENT_SYMBOL("commentSymbol", "The comment symbol of the language"),
12+
FRAMEWORK_CONTEXT("frameworkContext", "The context of the framework"),
13+
14+
;
15+
16+
companion object {
17+
fun all(): List<CustomVariable> = values().toList()
18+
}
19+
}

exts/devin-lang/src/main/kotlin/cc/unitmesh/language/completion/VariableProvider.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.language.completion
33
import com.intellij.codeInsight.completion.CompletionParameters
44
import com.intellij.codeInsight.completion.CompletionProvider
55
import com.intellij.codeInsight.completion.CompletionResultSet
6+
import com.intellij.codeInsight.lookup.LookupElementBuilder
67
import com.intellij.util.ProcessingContext
78

89
class VariableProvider: CompletionProvider<CompletionParameters>() {
@@ -11,9 +12,10 @@ class VariableProvider: CompletionProvider<CompletionParameters>() {
1112
context: ProcessingContext,
1213
result: CompletionResultSet,
1314
) {
14-
// CustomVariable.all.forEach {
15-
// result.addElement(it.toLookupElement())
16-
// }
17-
}
15+
CustomVariable.all().forEach {
16+
val withTypeText = LookupElementBuilder.create(it.variable).withTypeText(it.description, true)
1817

18+
result.addElement(withTypeText)
19+
}
20+
}
1921
}

exts/devin-lang/src/main/kotlin/cc/unitmesh/language/psi/DevInFile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import com.intellij.openapi.fileTypes.FileType
77
import com.intellij.psi.FileViewProvider
88

99
class DevInFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, DevInLanguage) {
10-
override fun getFileType(): FileType = DevInFileType
10+
override fun getFileType(): FileType = DevInFileType.INSTANCE
1111

1212
}

exts/devin-lang/src/main/resources/cc.unitmesh.language.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<lang.ast.factory language="DevIn"
1212
implementationClass="cc.unitmesh.language.DevInAstFactory"/>
1313

14-
<!-- <typedHandler implementation="cc.unitmesh.language.DevInTypedHandler"/>-->
14+
<typedHandler implementation="cc.unitmesh.language.DevInTypedHandler"/>
1515

1616
<completion.contributor language="DevIn"
1717
implementationClass="cc.unitmesh.language.DevInCompletionContributor"/>

plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
<module name="cc.unitmesh.database"/>
3636
<module name="cc.unitmesh.android"/>
3737
<module name="cc.unitmesh.harmonyos"/>
38+
<module name="cc.unitmesh.language"/>
3839
</content>
3940
</idea-plugin>

0 commit comments

Comments
 (0)