How to annotate core Node.js modules with JSDoc to have code hinting in IntelliJ?

人走茶凉 提交于 2019-12-11 05:58:18

问题


So far I have a need for two of them, util and fs. Given a code like this:

var fs = require('fs');
var contents = fs.readFileSync('path/to/file', 'utf8');

Not only IntelliJ marks readFileSync as Unresolved function or method, but I am also devoid of, in my opinion, on of the best function given by IDEs - code hinting.

How can I annotate core Node.js functions with JSDoc to have code hinting and not have correct code erroneously marked as invalid?


回答1:


Why core libraries are not resolved?

The issue with the invalid code is that you have "not NodeJS project".

You should install the NodeJS plugin: http://plugins.jetbrains.com/plugin/6098?pr=phpStorm

And then create a new project with the given sources.

IntelliJ will automatically overwrite the metadata and hook the NodeJS environment and all your core modules will be resolved.

Why there is no code completion?

IntelliJ tries hard do determine the object signature, but some JS coding techniques prevent your IDE from reading the signature (it can be read only in runtime).

Regarding the type annotation you can have a look here, for example: https://groups.google.com/forum/#!topic/scripted-dev/xFtPiBJDO4c

Update: I have written an article describing how you can enable the type hinting for NodeJS in IntelliJ IDEA: http://www.fse.guru/nodejs-autocomplete-in-idea-and-webstorm



来源:https://stackoverflow.com/questions/23876604/how-to-annotate-core-node-js-modules-with-jsdoc-to-have-code-hinting-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!