10

I'm working on a project involving WebGL, and using WebStorm to do the development.

One issue with the development flow is that WebStorm isn't able to autocomplete things related to WebGL. In particular, if I annotate a value as being of type WebGLRenderingContext

/** @type {!WebGLRenderingContext} */
var gl;

WebStorm complains that WebGLRenderingContext is an unresolved variable. Also it complains about usages of methods on gl, warning that it can't find those methods so they may not exist.

My current workaround (besides just turning off the warnings) is to specify a record type like so:

 * @type {{
 *   texParameteri: function,
 *   TEXTURE_WRAP_T: *,
 *   ...
 * }}
 var gl;

But obviously it's a bit silly to be personally listing dozens and dozens of standardized members like this every time I want to use a rendering context. Is there an easier way?

5
  • Why is it silly? Aren't the things WebStorm recognizes annotated in the same way? You should be be to add your own annotations alongside the ones that ship with the IDE. Commented Feb 1, 2015 at 19:09
  • @Hey It's silly in this case because I'm doing it inefficiently and redundantly. That information is already out there somewhere, and in far more detail (e.g. notice I'm not including signatures or per-parameter docs). Someone has already done the listing, so it's silly for me to also do the listing. Commented Feb 1, 2015 at 19:12
  • So you're really asking where to find annotations someone else has already written, or what? Commented Feb 1, 2015 at 19:14
  • @Hey That would be acceptable. That's how it works for some libraries (with annotations being in the source). The fact that webgl is builtin to browsers makes it a bit of a different case, in that the docs don't have a natural external place to live. Commented Feb 1, 2015 at 19:17
  • They probably do have a place to live, though (wherever WebStorm keeps the annotations for the rest of the built-in stuff). What might really be useful is a thing to convert IDL to JS annotations. I don't know if anything like that exists. Commented Feb 1, 2015 at 19:29

1 Answer 1

10

you need to let WebStorm know about WebGL API. Just enable WebGL library in Settings | Languages & Frameworks | JavaScript | Libraries.

It will create/modify the file .idea/jsLibraryMappings.xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="JavaScriptLibraryMappings">
    <includedPredefinedLibrary name="WebGL" />
  </component>
</project>

See: http://blog.jetbrains.com/webstorm/2014/07/how-webstorm-works-completion-for-javascript-libraries/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.