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?

Craig Gidney
  • 831
  • 7
  • 16
  • 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. – Hey Feb 01 '15 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. – Craig Gidney Feb 01 '15 at 19:12
  • So you're really asking where to find annotations someone else has already written, or what? – Hey Feb 01 '15 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. – Craig Gidney Feb 01 '15 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. – Hey Feb 01 '15 at 19:29

1 Answers1

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/

Michaelangel007
  • 213
  • 1
  • 5
lena
  • 216
  • 2
  • 3