Proposals with same names but different origins can be ignored #797 #798

Open
wants to merge 1 commit into
from

Projects

None yet

2 participants

@mrennie
Contributor
mrennie commented Jun 29, 2016

Check all properties, not just the first, and check origins before
leaving out same-named properties

@mrennie mrennie Proposals with same names but different origins can be ignored #797
Check all properties, not just the first, and check origins before
leaving out same-named properties
419c2e9
@marijnh marijnh commented on the diff Jun 30, 2016
lib/tern.js
@@ -660,9 +660,14 @@
var typeInfo = query.types || query.docs || query.urls || query.origins;
var wrapAsObjs = typeInfo || query.depths;
- for (var i = 0; i < completions.length; ++i) {
+ for (var i = 0, len = completions.length; i < len; i++) {
@marijnh
marijnh Jun 30, 2016 Member

This is an unnecessary optimization which has nothing to do with the actual change you're making in this patch.

@marijnh marijnh commented on the diff Jun 30, 2016
lib/tern.js
var c = completions[i];
- if ((wrapAsObjs ? c.name : c) == name) return;
+ if ((wrapAsObjs ? c.name : c) == name) {
+ if(query.origins && aval && c.origin !== aval.origin) {
@marijnh
marijnh Jun 30, 2016 Member

Why not just add the inverse of this condition to the if above, rather than introducing extra control flow?

@marijnh marijnh commented on the diff Jun 30, 2016
lib/tern.js
@@ -761,8 +766,13 @@
if (!completions.length && query.guess !== false && objType && objType.guessProperties)
objType.guessProperties(function(p, o, d) {if (p != prop && p != "") gather(p, o, d);});
- if (!completions.length && word.length >= 2 && query.guess !== false)
- for (var prop in srv.cx.props) gather(prop, srv.cx.props[prop][0], 0);
+ if (!completions.length && word.length >= 2 && query.guess !== false) {
+ Object.keys(srv.cx.props).forEach(function(prop) {
+ srv.cx.props[prop].forEach(function(type) {
+ gather(prop, type, 0);
+ });
+ });
+ }
@marijnh
marijnh Jun 30, 2016 Member

Is it really a good idea to start adding guessed properties multiple times? That has the potential to create a lot of noise, for very little gain (we don't know the accurate anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment