tern icon indicating copy to clipboard operation
tern copied to clipboard

Bug fixed. Wrong filename for jump to definition

Open rowend36 opened this issue 4 years ago • 0 comments

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);
    }

rowend36 avatar Dec 22 '20 08:12 rowend36