Navigation within JSON schema

I have JSON schema files which have fields that reference classes (by FQN), other files, and refs within JSON files (e.g. #/someOtherSpot). 

I would like to be able to implement my plugin so that unresolvable references are highlighted, and users can click on resolvable references and navigate to the appropriate file/spot.

How do I wire this into the JSON editor? I don't have my own language -- it's JSON (and only some specific JSON files) -- so although a Reference contributor "feels" right, it doesn't seem to fit the pattern.

 

0

You're correct about using a reference contributor. You'll need to create a PsiReferenceContributor and an Annotator. The first one will provide the references, the second one will highlight the errors.

You can find an example of providing JSON Pointer references via a reference contributor for JSON Schema files here and here.

A sample of implementing an annotator can be also found there.

And here is how corresponding plugin metadata looks like (i.e., extension point names and how to register the components).

In case of any further questions, don't hesitate to ask.

0
Avatar
Permanently deleted user

Thank you, Anton. I notice that those reference contributors are actually having effects on my files...but in this situation, I want some of those references to be hidden. For example, it shows me all of the places where the word "MyDetail" shows up in the schema, but at a particular spot I want to navigate specifically to the spot where "MyDetail" has a particular parent property "MyParent".  Is there a mechanism for me to filter the references?

0
You can try unregistering JsonSchemaReferenceContributor in your plugin using

ExtensionPoint ep = Extensions.getRootArea()
.getExtensionPoint<PsiReferenceContributorEP>(PsiReferenceContributor.EP_NAME.name);

ep.getExtensions() // <-- find one by class name "JsonSchemaReferenceContributor" in this list
ep.unregisterExtension(...) // <-- suppress this way

but I'm not fully sure it will work in plugin. But at least, it works in our tests. :)
0

请先登录再写评论。