Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Tern - node plugin - Requires don't work if the extension is missing in the filename #5983

Open
tanguylebarzic opened this issue Nov 13, 2013 · 1 comment

Comments

@tanguylebarzic
Copy link

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

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!

@ghost ghost assigned dangoor Nov 18, 2013
@dangoor
Copy link
Contributor

dangoor commented Nov 18, 2013

I think I know the problem and will be fixing this in #4991. We don't fully support Node, but this particular case should work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants