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

Bug fixed. Wrong filename for jump to definition #1042

Open
rowend36 opened this issue Dec 22, 2020 · 0 comments
Open

Bug fixed. Wrong filename for jump to definition #1042

rowend36 opened this issue Dec 22, 2020 · 0 comments

Comments

@rowend36
Copy link

Discovered a small issue in tern when files are not loaded in order. Jump to definition gives the right position but wrong filename. Found it and fixed it but no time to clone && make a pull request for something so small :). Thanks y'all for good software.
The issue crops when you have files like;
a.js

var c;
function b(a){
c = a
}

b.js

b({hello:'hi'})

c.js

c.hello

If files are loaded in this order c.js>b.js>a.js, jumpToDef on 'hello' takes you to a.js.

Here's my ignorant quick fix.

if (span && span.node) { // refers to a loaded file
      var spanFile = span.node.sourceFile || srv.fileMap[span.origin];
      var start = outputPos(query, spanFile, span.node.start), end = outputPos(query, spanFile, span.node.end);
      result.start = start; result.end = end;
   ---result.file = span.origin      
   +++result.file = (spanFile && spanFile.name)||span.origin;
      var cxStart = Math.max(0, span.node.start - 50);
      result.contextOffset = span.node.start - cxStart;
      result.context = spanFile.text.slice(cxStart, cxStart + 50);
    } else if (span) { // external
      result.file = span.origin;
      storeSpan(srv, query, span, result);
    }
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

1 participant