Load webSymbols.webTypes JSON file from URL


Hi all,

I am creating a plugin that needs to load a web-types JSON file from a URL and use the file to assist with type hinting and autocompletion.

From looking at the documentation (here and here), I need to use

<webSymbols.webTypes source="[SOURCE_HERE]"/>

which works fine, but I seem to be getting stuck, considering the following use cases;

  • The framework which I am trying to support does not follow versioning, so it can change, meaning the plugin will need to re-fetch the web types file once in a while to keep up to date, since the framework releases periodically
  • The plugin has an environment switch to toggle between a production version and a test version of the web-types file, so the plugin will need to switch environments & re-fetch the web types file

That means that I will need to support fetching the web types dynamically, making me believe that I cannot do this in the XML file, because that is static and won't change.

I might be mistaken, but I think it is not possible to write to the resources folder of my plugin. So my question is as follows.

How can I programmatically supply the web-types symbol parser with a web-types JSON file, and make it reload the file afterwards?  


1 comment
Official comment


If you need a more advanced use case, you need to create a  WebSymbolsQueryConfigurator, which will provide the loaded Web Types depending on the context. You would need to use some of the internal APIs, because I haven't yet exposed these to the public, but it is definitely doable. If you succeed we can consider making these APIs available of course.

So, to load WebTypes from an InputStream you can use internal com.intellij.webSymbols.webTypes#InputStream.readWebTypes() function. Next you need to create a scope, which will be returned by the query configurator. For that extend internal WebTypesScopeBase and call addWebTypes/removeWebTypes to update the set of available WebTypes within the scope.

WebSymbolsQueryConfigurator can return scopes depending on the current location. Configurator is called very often, so the scope calculations should be as optimized as possible. Scopes should be cached, i.e. they should not be rebuilt on every call.

Please note that there were some API changes between 2023.2 and 2023.3, as the framework is still under heavy development and is considered experimental for now.

Let me know if you have any more questions!



Please sign in to leave a comment.