Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findDef (find definition) doesn't always work #67

Closed
jeffkenton opened this issue Apr 17, 2013 · 4 comments
Closed

findDef (find definition) doesn't always work #67

jeffkenton opened this issue Apr 17, 2013 · 4 comments

Comments

@jeffkenton
Copy link

Using the following code to test findDef (called jump-to-definition on the tern.js demo page):

var base = {foo: 10, foo2: { bb : "test" }};
base.foo2.bb = "hello";
base.foo = 10;

If I place the cursor on foo2 on the second line, jump-to-definition works. But if I put the cursor on foo on the third line (or bb on the second line) it does not. I have traced the code into infer.expressionType() but haven't figured out a solution myself.

@marijnh
Copy link
Member

marijnh commented Apr 17, 2013

Definition locations are currently only tracked for variables and function/object types. base.foo is not a variable, and holds a number, so Tern currently doesn't associate a location with it.

I could store locations in property definitions, but I'm not sure how useful that would be. Thoughts?

@jeffkenton
Copy link
Author

Thanks. That was what I was seeing during debugging, but wasn't sure why. Our testers thought it was a natural thing to try.

@petetronic
Copy link
Contributor

That would explain another scenario I believe this impacts - module exports... in the code below, usages of this module cannot jump to the exported title var definition because it is assigned a String. If you assign it an Object, jump to definition works.

/*global define */

define(function (require, exports, module) {
    "use strict";

    var title = "Apples";

    function getCompleteTitle() {
        return title + " and Oranges";
    }

    exports.getCompleteTitle = getCompleteTitle;
    exports.title = title;
});

marijnh added a commit that referenced this issue Apr 18, 2013
And track them for all properties.

Issue #67
@marijnh
Copy link
Member

marijnh commented Apr 18, 2013

See commit aa3bcb8 , which cleans up the way properties and variables have their definition tracked, and fixes this issue in the process.

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

No branches or pull requests

3 participants