Set Schema of a File dynamically

Answered

Hi, 

i want to set the File Schema `GitHub Workflow` for yaml/yml files under `.github/workflows` with my GitHubWorkflowPlugin 

Unfortunately, I can't find any good example or documentation. I have tried many things, but I am always failing.

What I could find out is, how to get the current file schema:

final Optional<String> actual = ((JsonSchemaServiceImpl) JsonSchemaService.Impl.get(parameters.getOriginalFile().getProject())).getProvidersForFile(parameters.getPosition().getContainingFile().getOriginalFile().getViewProvider().getVirtualFile()).stream().map(JsonSchemaFileProvider::getName).filter("GitHub Workflow"::equals).findFirst();
final Optional<String> expected = JsonSchemaService.Impl.get(parameters.getOriginalFile().getProject()).getAllUserVisibleSchemas().stream().map(JsonSchemaInfo::getName).filter("GitHub Workflow"::equals).findFirst();
System.out.println("FILE SCHEMA [" + actual.orElse(null) + "] [" + expected.orElse(null) + "]");

How can I set the `expected` schema when the `actual` is not present?

And how to trigger this by opening a file?

 

0
1 comment

Hi Yuna,

As answered on Slack:

Implement JsonSchema.ProviderFactory.

I suggest checking the existing implementations in the platform code or on IntelliJ Platform Explorer.

Please note that JSON/JavaScript this extension point's name is historical and can be misleading. Provided schemas are used in JSON and YAML files.

0

Please sign in to leave a comment.