How to register findusagesprovider

已回答

I wrote 

<lang.findUsagesProvider language="XML" implementationClass="com.MyFindUsages"/> 
class MyFindUsages : FindUsagesProvider() { .... }

But still the provider is never triggered, but when I use

<findUsagesHandlerFactory implementation="com.MyFindUsagesFactory" id="xml" order="first, before default"/>

It's being triggered, but I need Provider as far as I understood from the documentation to provide WordScanner

https://plugins.jetbrains.com/docs/intellij/find-usages-provider.html

What is the issue?

 

1

You are specifying `XML` as the language, so by default it will be picking up the IntelliJ XML find usage provider. You'll need to change the language to the one supported in your plugin:

    <lang.findUsagesProvider language="MyLanguage" implementationClass="com.MyFindUsages"/>

1

Please note, the language ID is case-sensitive, "xml" is not "XML". What do you actually want to achieve?

1

Yes, it works, it is triggered, finally, the solution is to mention order first order="first". But there are two problems

1. It is triggered very rarely, so I need to press Ctrl+B around 5 - 10 times and only one time is triggered.

2. Only com.intellij.lang.findUsages.FindUsagesProvider#getType is called. Why other methods like canFindUsages, getWordsScanner are not triggered?

0

The method com.intellij.lang.findUsages.MyUsagesProvider#getType is called always when you press CTRL and hover the cursor over the element even with no click. But once per 5 click CTRL + B

1

I was wrong, the method FindUsagesProvider#getType is never called when I press CTRL + B, it is called only when I hold CTRL and move the cursor hover any XML element.  I removed my custom language from plugin.xml put breakpoints on all method of XmlFindUsagesProvier then rerun the plugin in debug mode, afterward I press CTRL + B on many XML elements (value, attributes, root) but never triggered. 

0

That is coming from the implementation of the getQuickNavigateInfo function in SingleTargetElementInfo that is used to generate a string of the form `typename "name"`, e.g. `tag "example"`, that is displayed on hover.

Why are you trying to override this behaviour for XML? -- Overriding the find usages logic for XML (or any language) will affect any XML element, not just what you are trying to achieve.

If you are building a plugin for an XML language like XSLT, you could take a look at how the XSLT code works in te intellij-community sources (plugins/xpath/xpath-lang).

0

Reece Dunn We have data in XML files. I want to implement navigation on these files by clicking on elements (attribute or values), like Number="11" CTRL+B (or other shortcuts) should lead a developer to the file and line with appropriate data. So, essentially I want to achieve the situation when the custom findUsagesProvider serves only files with specific root name, other XML files should be skipped by the new provider. I had thought it is possible by overriding XmlFindUsagesProvider, if there is no specific root name in XML then I delegate to XmlFindUsagesProvider if there is I will navigate. How can I achieve such action?

0

Sorry for delay.

It seems the best solution for this use-case of resolving from your XML to _anything_ else is to either add custom PsiReference to the XML, that resolve to target(s) (https://plugins.jetbrains.com/docs/intellij/psi-references.html#contributed-references).

Or, alternatively, use DOM to build full semantic model on top of XML, possibly adding many more layers of functionality https://plugins.jetbrains.com/docs/intellij/xml-dom-api.html.

0

请先登录再写评论。