How to implement client side fallback logic in IntelliJ (Pycharm)?

In VSCode and PyCharm, there is a command UX pattern:

  1. User cmd+ click on a symbol → Go to definition
  2. If User already at definition, it triggers → Reference instead.

This works fine with PyCharm native Python support, but when I want to add a Python base LSP, I cannot replicate this logic. What I want ideally is:

  1. Replicate this behavior, if nothing found, trigger the native Pycharm Python definition provider instead.

I understand in VSCode this is a client side fallback logic, and it can be customised via a settings called alternative declartion command.

In addition, is there anyway to control which one takes priority?

I don’t think so. Last time I checked, neither LspFindReferencesCustomizer nor LspGoToDefinitionCustomizer have any overridable properties/methods. What server are you working with?

(There’s also an LSP4IJ issue on this same topic.)

@insyncwithfoo I wasn’t so sure is this a IntelliJ thing of LSP4IJ thing.

It’s a LSP that I am working on, which support bi-direction YAML ← → Python navigation/reference. I got that working in VSCode but not in PyCharm.

LSP4IJ is an alternative client implementation that happens to have the same problem (hence the parentheses). If you are working with the native client (and you likely do), then you need to file a feature request on YouTrack.

Note that a plugin can make use of both clients. Say, if LSP4IJ fixes this but not the native client, it is entirely possible to let the user choose which client to use using a setting.