1
1
package cc.unitmesh.devti.gui.component
2
2
3
3
import com.intellij.json.JsonLanguage
4
+ import com.intellij.lang.Language
5
+ import com.intellij.openapi.application.runReadAction
6
+ import com.intellij.openapi.editor.Document
4
7
import com.intellij.openapi.editor.colors.EditorColorsUtil
5
8
import com.intellij.openapi.editor.ex.EditorEx
6
9
import com.intellij.openapi.project.Project
10
+ import com.intellij.openapi.vfs.VirtualFile
11
+ import com.intellij.psi.PsiFile
7
12
import com.intellij.ui.LanguageTextField
13
+ import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider
14
+ import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory
15
+ import com.jetbrains.jsonSchema.extension.SchemaType
8
16
import java.awt.Dimension
9
17
import java.awt.FontMetrics
10
18
19
+ private const val CUSTOM_AGENT_NAME = " AutoDevCustomAgentFile.json"
20
+
11
21
class JsonLanguageField (private val myProject : Project , val value : String , private val placeholder : String ) :
12
- LanguageTextField (JsonLanguage .INSTANCE , myProject, value) {
22
+ LanguageTextField (JsonLanguage .INSTANCE , myProject, value,
23
+ object : SimpleDocumentCreator () {
24
+ override fun createDocument (value : String? , language : Language ? , project : Project ? ): Document {
25
+ return createDocument(value, language, project, this )
26
+ }
27
+
28
+ override fun customizePsiFile (file : PsiFile ? ) {
29
+ file?.name = CUSTOM_AGENT_NAME
30
+ }
31
+ }
32
+ ) {
33
+
13
34
override fun createEditor (): EditorEx {
14
35
return super .createEditor().apply {
15
36
setShowPlaceholderWhenFocused(true )
@@ -26,4 +47,38 @@ class JsonLanguageField(private val myProject: Project, val value: String, priva
26
47
preferredSize = Dimension (25 * columnWidth, 25 * metrics.height)
27
48
}
28
49
}
29
- }
50
+ }
51
+
52
+ internal class AutoDevJsonJsonSchemaProviderFactory : JsonSchemaProviderFactory {
53
+ override fun getProviders (project : Project ): MutableList <JsonSchemaFileProvider > {
54
+ return mutableListOf (AutoDevJsonSchemaFileProvider (project))
55
+ }
56
+ }
57
+
58
+ class AutoDevJsonSchemaFileProvider (val project : Project ): JsonSchemaFileProvider {
59
+ override fun isAvailable (file : VirtualFile ): Boolean {
60
+ return runReadAction { isAutoDevCustomAgentFile(file) }
61
+ }
62
+
63
+ private fun isAutoDevCustomAgentFile (file : VirtualFile ): Boolean {
64
+ if (! file.isValid) {
65
+ return false
66
+ }
67
+
68
+ return file.name == CUSTOM_AGENT_NAME
69
+ }
70
+
71
+ override fun getName (): String = " AutoDevCustomAgentFile"
72
+
73
+ override fun getSchemaFile (): VirtualFile ? {
74
+ return JsonSchemaProviderFactory .getResourceFile(this ::class .java, schemaFileName)
75
+ }
76
+
77
+ override fun getSchemaType (): SchemaType {
78
+ return SchemaType .schema
79
+ }
80
+
81
+ companion object {
82
+ private const val schemaFileName = " autodev-custom-agent.json"
83
+ }
84
+ }
0 commit comments