You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
JS code hints (using the node plugin of Tern) don't work for a required module if the filename for this module is not 'full', eg. no '.js' at the end.
Example:
a.js
exports.hello = function() { return 10; };
b.js
var a = require('./a');
Typing a. in b won't trigger the expected hint (hello), but a lot of hints (variables in the project). The modified b2.js would trigger correct results (notice the '.js' at the end of the require call)
b2.js
var a = require('./a.js');
Possible explanation / fix
This way of requiring modules is valid (according to http://nodejs.org/docs/latest/api/modules.html#modules_file_modules). While tern in 'node' mode manages to find them (as it uses the native nodejs module._resolveFilename method), with brackets Tern just asks for './a', which is not found by Brackets. A possible fix (that I applied locally), would be to change handleTernGetFile in extensions/default/JavascriptCodeHints/ScopeManager.js, from
getDocText(name).fail(function () {
getDocText(rootTernDir + name).fail(function () {
// check relative to project root
getDocText(projectRoot + name)
// last look for any files that end with the right path
// in the project
.fail(findNameInProject);
}
to
getDocText(name).fail(function () {
getDocText(name + ".js").fail(function () {
getDocText(rootTernDir + name).fail(function () {
// check relative to project root
getDocText(projectRoot + name)
// last look for any files that end with the right path
// in the project
.fail(findNameInProject);
});
});
});
(possibly adding also nave + ".json" and name + ".node").
However, this seems to be the wrong place to do it (as it should be specific to the node plugin IMO). Would love to hear your thoughts, thanks!
The text was updated successfully, but these errors were encountered:
Hi,
Issue
JS code hints (using the node plugin of Tern) don't work for a required module if the filename for this module is not 'full', eg. no '.js' at the end.
Example:
a.js
b.js
Typing a. in b won't trigger the expected hint (hello), but a lot of hints (variables in the project). The modified b2.js would trigger correct results (notice the '.js' at the end of the require call)
b2.js
Possible explanation / fix
This way of requiring modules is valid (according to http://nodejs.org/docs/latest/api/modules.html#modules_file_modules). While tern in 'node' mode manages to find them (as it uses the native nodejs module._resolveFilename method), with brackets Tern just asks for './a', which is not found by Brackets. A possible fix (that I applied locally), would be to change handleTernGetFile in extensions/default/JavascriptCodeHints/ScopeManager.js, from
to
(possibly adding also nave + ".json" and name + ".node").
However, this seems to be the wrong place to do it (as it should be specific to the node plugin IMO). Would love to hear your thoughts, thanks!
The text was updated successfully, but these errors were encountered: