Skip to content

Commit

Permalink
feat: Add a custom JSON schema provider for Oxc config files (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrayburn-tech authored Oct 14, 2024
1 parent 1b77031 commit 5964246
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.iwanabethatguy.oxcintellijplugin

object Constants {

val CONFIG_FILES = listOf("oxlintrc.json", "oxlint.json", ".oxlintrc.json", ".oxlint.json",
".oxlintrc")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.iwanabethatguy.oxcintellijplugin

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory
import com.jetbrains.jsonSchema.extension.SchemaType
import com.jetbrains.jsonSchema.remote.JsonFileResolver
import org.jetbrains.annotations.Nls

class OxcSchemaProviderFactory : JsonSchemaProviderFactory {

override fun getProviders(project: Project): List<JsonSchemaFileProvider?> {
return listOf(object : JsonSchemaFileProvider {
override fun isAvailable(file: VirtualFile): Boolean {
return Constants.CONFIG_FILES.contains(file.name)
}

override fun getName(): @Nls String {
return MyBundle.message("oxc.schema.name")
}

override fun getSchemaFile(): VirtualFile? {
return JsonFileResolver.urlToFile(
"https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json")
}

override fun getSchemaType(): SchemaType {
return SchemaType.remoteSchema
}
})
}
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
key="oxc.name"
/>
</extensions>

<extensions defaultExtensionNs="JavaScript">
<JsonSchema.ProviderFactory implementation="com.github.iwanabethatguy.oxcintellijplugin.OxcSchemaProviderFactory"/>
</extensions>

<actions>
<action id="com.github.iwanabethatguy.oxcintellijplugin.actions.RestartLanguageServer"
class="com.github.iwanabethatguy.oxcintellijplugin.actions.RestartLanguageServer"/>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/MyBundle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
action.com.github.iwanabethatguy.oxcintellijplugin.actions.RestartLanguageServer.text=Restart Oxc Server

oxc.name=Oxc
oxc.schema.name=Oxc

0 comments on commit 5964246

Please sign in to comment.