auto-complete suggestion out of context

"log" is a function defined in logger.js (same top-level folder as app.js

which is the file I run with node) and exported to module, yet it shows up in the global scope suggest list instead of just the logger scope, which when used shows some obvious warnings:

and then when run, creates a ReferenceError of log is not defined:

This is kind of silly for the editor to be allowing and doing.

logger.js contains:

function log(message) {
// Send an HTTP request
console.log(message);
}

module.exports.log = log;

Why is PHPStorm showing the log function from the logger file as a suggestion in global scope?

logger shows too, which makes sense; once that's there, then typing a dot (. or period) then auto-complete suggestions (I use Ctrl+Space in Windows) also shows the log function, but adding it there of course runs it in the proper context.

What is going on?

PHPStorm (or WebStorm or IntelliJ) should not be showing non-functional suggestions outside of context.

3 comments
Comment actions Permalink

This is a feature - the IDE shows exported modules in completion, allowing to add and auto-import them. This is done at users' requests

0
Comment actions Permalink

I'm not understanding what you mean "shows exported modules in completion" and "allowing to add and auto-import them".

I'm new to Node obviously, so maybe I'm just not understanding your understanding of the terminology.

0
Comment actions Permalink

The editor does however show the suggestion while in the proper context:

Why someone would want it to show and be selectable in a context it will break, I don't know.

If it's allowed because of some unspecified or unpredictable auto-import that may or may not occur (and that I'm not even defining), then there should at least be an option for the project to disable this "feature" when the context is not determinable. Right now my project will not be using auto-import, and PHPStorm should not be acting like I might.

0

Please sign in to leave a comment.