tern
tern copied to clipboard
How can I apply 'guess' approach for definition retrieval?
Thank you for great job so far. Currently I am using ternjs for types and defs resolution. But I faced the next issue - amount of resolved defs are much lower than amount of resolved types. The issue is in didGuess() check in findDef function:
function findDef(srv, query, file) { var expr = findExpr(file, query); var type = findExprType(srv, query, file, expr); **if (infer.didGuess()) return {};**
This check prevents me from getting some meaningful definitions. Are there any workarounds for the issue?
Do you have an example of a source file where it finds no definition, but does find the correct definition if you disable that line?
For example for repo https://github.com/sgtest/javascript-nodejs-sample-0
Commenting out if (infer.didGuess()) return {}; helps resolve next identifiers:
Unresolved should [474-480] in test/animal_test.js Unresolved eql [481-484] in test/animal_test.js
I guess the prototype-mangling done by should isn't being recognized. It's being done by some rather indirect code, which, by using a variable for the property name, prevents Tern from seeing through it.
I'm not sure how removing the didGuess line could help here, though. Does it really take you to the lines I linked in the should library when your disable it, or to some unrelated property named should?
Data returned for should if didGuess is commented out:
DATA = { doc: 'Expose api via Object#should.\n\n@api public',
origin: 'node_modules/should/lib/should.js',
start: 1387,
end: 1395,
file: 'node_modules/should/lib/should.js',
contextOffset: 50,
context: 'blic\n */\n\nObject.defineProperty(Object.prototype, ' }
Looks quite realistic.
I was running my solution using ternjs on 10+ nodejs popular libs - statistics (amount of unresolved definition data) is much better when didGuess check is commented out.
That appears to be the exported should function, which is not the should property from Object.prototype that you're actually accessing at that point.
(My point being that yes, you can get a result if you comment out that line, but it's a wrong result, so that's not really an improvement.)