Scroll From Source not working when implementing StructureViewTreeElement

I've been slowing building up the Structure view for my elixir plugin, https://github.com/KronicDeth/intellij-elixir, but I can' get Scroll From Source to work.  I assume I'm missing some method I need to override.  I click in the element that is scrolled to when using Scroll To Source and it doesn't trigger the `canNavigate` or `canNavigateFromSource` callback, so I'm not sure how to even debug the problem.  Currently, most of my StructureViewTreeElements are subclassing this class https://github.com/KronicDeth/intellij-elixir/blob/a7c8e6d7023112faf265595a5b2dbd0bfc01f8b0/src/org/elixir_lang/structure_view/element/Element.java , which delegates to the NavigatablePsiElement navigationElement for all the StructureViewElement interface methods.

4 comments
Comment actions Permalink

Please check com.intellij.ide.structureView.TextEditorBasedStructureViewModel#getSuitableClasses in your Model

1
Comment actions Permalink

Thanks! That worked.  Will JetBrains access just javadoc change PRs for intellij-community?  The docs don't make it obvious that getSuitableClasses controls Scroll From Source.

If anyone needs example code for this fix, here's the commit that fixed this issue for me: https://github.com/KronicDeth/intellij-elixir/commit/c0134533e76e25c4236b2de326fc2fa31f02c8d9

1
Comment actions Permalink

I had to also override `#isSuitable` (https://github.com/KronicDeth/intellij-elixir/commit/2b608354465bec0af88223b19775f6c19684c4fc) because most of my elements use the interface Call, but some Calls aren't used in the Structure view, so I wanted to ignore the inner, nested Calls and only return true from `isSuitable` for those I'm using the Structure view.  I ended up being able to use the `is(Call)` static methods I used to construct the structure view (https://github.com/KronicDeth/intellij-elixir/blob/2b608354465bec0af88223b19775f6c19684c4fc/src/org/elixir_lang/structure_view/element/modular/Module.java#L125-L157) to do the checking for `#isSuitable`.

I know the Java PSI is more specific because it can have elements for specific keywords, but Elixir is mostly macros, so it's a call that takes a call as argument to define a function for function.  This approach might be useful in other macro heavy languages.

0
Comment actions Permalink

Great. Yes, please submit javadoc-patches.

0

Please sign in to leave a comment.