Skip to content

Commit cf5359e

Browse files
committed
fix(devin-lang): improve code highlighting and completion #101
The commit fixes an issue with the DevInSyntaxHighlighter where the LANGUAGE_ID token was incorrectly highlighted as an instance field. It has been corrected to be highlighted as a constant. Additionally, the DevInCompletionContributor now uses appropriate patterns and imports to enhance the completion feature. Furthermore, the DevInTypedHandler has been updated to handle the `'` character more effectively during code completion.
1 parent cc45cf2 commit cf5359e

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

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

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

44
import cc.unitmesh.devti.language.psi.DevInFile
5-
import cc.unitmesh.devti.language.psi.DevInTypes
65
import com.intellij.codeInsight.AutoPopupController
76
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
87
import com.intellij.openapi.editor.Editor
98
import com.intellij.openapi.project.Project
109
import com.intellij.psi.PsiDocumentManager
1110
import com.intellij.psi.PsiFile
12-
import com.intellij.psi.util.elementType
1311

1412
class DevInTypedHandler : TypedHandlerDelegate() {
1513
override fun checkAutoPopup(charTyped: Char, project: Project, editor: Editor, file: PsiFile): Result {
@@ -19,15 +17,15 @@ class DevInTypedHandler : TypedHandlerDelegate() {
1917

2018
return when (charTyped) {
2119
'`' -> {
22-
val offset = editor.caretModel.primaryCaret.offset
23-
if (offset == 0) {
24-
return Result.CONTINUE
25-
}
26-
27-
val element = file.findElementAt(offset - 1)
28-
if (element?.elementType == DevInTypes.CODE_CONTENT || element?.elementType == DevInTypes.CODE_BLOCK_END) {
29-
return Result.CONTINUE
30-
}
20+
// val offset = editor.caretModel.primaryCaret.offset
21+
// if (offset == 0) {
22+
// return Result.CONTINUE
23+
// }
24+
//
25+
// val element = file.findElementAt(offset - 1)
26+
// if (element?.elementType == DevInTypes.CODE_CONTENT || element?.elementType == DevInTypes.CODE_BLOCK_END) {
27+
// return Result.CONTINUE
28+
// }
3129

3230
PsiDocumentManager.getInstance(project).commitDocument(editor.document)
3331
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import cc.unitmesh.devti.language.psi.DevInTypes
55
import com.intellij.codeInsight.completion.CompletionContributor
66
import com.intellij.codeInsight.completion.CompletionInitializationContext
77
import com.intellij.codeInsight.completion.CompletionType
8+
import com.intellij.patterns.*
89
import com.intellij.patterns.PlatformPatterns.psiElement
10+
import com.intellij.psi.PsiElement
11+
import com.intellij.psi.PsiWhiteSpace
12+
import com.intellij.psi.tree.TokenSet
13+
import com.intellij.util.ProcessingContext
914

1015
class DevInCompletionContributor : CompletionContributor() {
1116
private val INPUT_DUMMY_IDENTIFIER = "DevInDummy"
1217

1318
init {
14-
extend(CompletionType.BASIC, psiElement(DevInTypes.LANGUAGE_ID), CodeLanguageProvider())
19+
extend(CompletionType.BASIC, declarationPattern(), CodeLanguageProvider())
1520
extend(CompletionType.BASIC, psiElement(DevInTypes.VARIABLE_ID), CustomVariableProvider())
1621
}
1722

@@ -20,4 +25,8 @@ class DevInCompletionContributor : CompletionContributor() {
2025
context.dummyIdentifier = INPUT_DUMMY_IDENTIFIER
2126
}
2227
}
28+
29+
fun declarationPattern(): PsiElementPattern.Capture<PsiElement> =
30+
psiElement()
31+
.and(psiElement(DevInTypes.LANGUAGE_ID))
2332
}

exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/highlight/DevInSyntaxHighlighter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DevInSyntaxHighlighter : SyntaxHighlighter {
2525

2626
ATTRIBUTES[DevInTypes.CODE_BLOCK_START] = DefaultLanguageHighlighterColors.KEYWORD
2727
ATTRIBUTES[DevInTypes.CODE_BLOCK_END] = DefaultLanguageHighlighterColors.KEYWORD
28-
ATTRIBUTES[DevInTypes.LANGUAGE_ID] = DefaultLanguageHighlighterColors.INSTANCE_FIELD
28+
ATTRIBUTES[DevInTypes.LANGUAGE_ID] = DefaultLanguageHighlighterColors.CONSTANT
2929
}
3030
}
3131

0 commit comments

Comments
 (0)