CMD + click Value in .yml File and Jump to Class with Same Name

Answered

Hello,

I'm totally new to IntelliJ plugin development and could use some help getting started on my idea. I'd like to create a plugin provides a better navigation experience when looking at Conjure files, which are used to define APIs and generate java classes. (https://github.com/palantir/conjure)

There's two main features I'd like to have:

1. cmd + click on a value to jump to the definition of that value in the conjure file

2. option + click on a value to open the corresponding java class definition (matches the name of the value)

Here's an example of a Conjure file to show what I'm talking about:

types:
  definitions:
    default-package: com.palantir.flightsearch
    objects:
      Airport:
        alias: string
      SearchRequest:
        fields:
          from: Airport
          to: Airport
          time: datetime
      SearchResult:
        alias: list<Connection>
      Connection:
        fields:
          from: Airport
          to: Airport
          number: string

The parts that I'm struggling with are:

a. How to tell the plugin to only do this for certain .yml files, my thought being to check that its (1) a yml file and (2) is in a folder name "conjure"

b. how to respond to cmd + click and option + click and get the text that was clicked to do things with

Would greatly appreciate any type of help I can get for any part of this problem. I've read a lot of the docs and all the related forum posts I can find, but I'm still having trouble with what I mentioned.

 
2
1 comment

This functionality is built with PsiReference http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_references.html

You'll need to add your own references implementing the resolving logic and provide them for the relevant YAML file's PsiElements. For references to FQN class, you can reuse com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet

Provide implementation of PsiReferenceContributor and register in plugin.xml, then register your providers with a pattern like this:

registrar.registerReferenceProvider(
PlatformPatterns.psiElement(YAMLScalar.class).with(<<condition, e.g. check filename/file location etc. // name of containing YamlKey>>),
new MyPsiReferenceProvider())
1

Please sign in to leave a comment.