Closed theY4Kman closed 1 year ago
With the introduction of the fileTypeContributor
and injectedLanguage
extension points in 4.0.0, this is now satisfied (with much better and more concise naming, too)
For reference, here is what my extension implementations look like for Python:
plugin.xml
PythonGraphQLFileTypeContributor.kt
PythonGraphQLInjectedLanguage.kt
It would be nice if there were an extension point enabling other plugins to support GQL-injected string literals in other languages.
Currently, informing the indexer to include a language's FileTypes can be accomplished with a
GraphQLFindUsagesFileTypeContributor
extension. However, only the elements allowed byGraphQLInjectionSearchHelper.isGraphQLLanguageInjectionTarget
may be included in indexing, so theGraphQLJavaScriptInjectionSearchHelper
service must be overridden. This gets indexing down to the language's injection host element... but the extraction of the GQL source is performed usingPsiElement.getText()
, which will also contain the string literal's bounding chars (e.g., quotes, or backticks). At the moment, this is rolled over for JavaScript by stripping whitespace and backticks, but this will not work for all languages.I've built out a working implementation branch, with the extension interface declared as:
Personally, I wanted to add support for Python. I implemented an extension in a plugin like so:
(Though, it should be noted
isGraphQLLanguageInjectionTarget
should only rely on what's available in the passed element's containing file, andpyModuleFunctionArgument
will lodge an error in the IDE. It's just a proof-of-concept.)If this seems useful to others, I can open a pull request.