|
381 | 381 | }
|
382 | 382 | }
|
383 | 383 |
|
384 |
| - function min(a, b) { |
385 |
| - if (a < b) { |
386 |
| - return a; |
387 |
| - } |
388 |
| - return b; |
389 |
| - } |
390 |
| - |
391 | 384 | function extractGenerics(val) {
|
392 | 385 | val = val.toLowerCase();
|
393 | 386 | if (val.indexOf('<') !== -1) {
|
|
425 | 418 | }
|
426 | 419 | if (lev.pos !== -1) {
|
427 | 420 | elems.splice(lev.pos, 1);
|
428 |
| - lev_distance = min(lev.lev, lev_distance); |
| 421 | + lev_distance = Math.min(lev.lev, lev_distance); |
429 | 422 | } else {
|
430 | 423 | return MAX_LEV_DISTANCE + 1;
|
431 | 424 | }
|
|
488 | 481 | var new_lev = levenshtein(obj.name, val.name);
|
489 | 482 | if (new_lev < lev_distance) {
|
490 | 483 | if ((lev = checkGenerics(obj, val)) <= MAX_LEV_DISTANCE) {
|
491 |
| - lev_distance = min(min(new_lev, lev), lev_distance); |
| 484 | + lev_distance = Math.min(Math.min(new_lev, lev), lev_distance); |
492 | 485 | }
|
493 | 486 | } else if (obj.generics && obj.generics.length > 0) {
|
494 | 487 | for (var x = 0; x < obj.generics.length; ++x) {
|
495 |
| - lev_distance = min(levenshtein(obj.generics[x], val.name), lev_distance); |
| 488 | + lev_distance = Math.min(levenshtein(obj.generics[x], val.name), |
| 489 | + lev_distance); |
496 | 490 | }
|
497 | 491 | }
|
498 | 492 | // Now whatever happens, the returned distance is "less good" so we should mark it
|
|
509 | 503 | if (literalSearch === true && tmp === true) {
|
510 | 504 | return true;
|
511 | 505 | }
|
512 |
| - lev_distance = min(tmp, lev_distance); |
| 506 | + lev_distance = Math.min(tmp, lev_distance); |
513 | 507 | if (lev_distance === 0) {
|
514 | 508 | return 0;
|
515 | 509 | }
|
|
526 | 520 | if (literalSearch === true && tmp === true) {
|
527 | 521 | return true;
|
528 | 522 | }
|
529 |
| - lev_distance = min(tmp, lev_distance); |
| 523 | + lev_distance = Math.min(tmp, lev_distance); |
530 | 524 | if (lev_distance === 0) {
|
531 | 525 | return 0;
|
532 | 526 | }
|
|
567 | 561 | var in_args = findArg(searchIndex[i], val, true);
|
568 | 562 | var returned = checkReturned(searchIndex[i], val, true);
|
569 | 563 | var ty = searchIndex[i];
|
| 564 | + var fullId = itemTypes[ty.ty] + ty.path + ty.name; |
| 565 | + |
570 | 566 | if (searchWords[i] === val.name) {
|
571 | 567 | // filter type: ... queries
|
572 | 568 | if (typePassesFilter(typeFilter, searchIndex[i].ty) &&
|
573 |
| - results[ty.path + ty.name] === undefined) |
| 569 | + results[fullId] === undefined) |
574 | 570 | {
|
575 |
| - results[ty.path + ty.name] = {id: i, index: -1}; |
| 571 | + results[fullId] = {id: i, index: -1}; |
576 | 572 | results_length += 1;
|
577 | 573 | }
|
578 | 574 | } else if ((in_args === true || returned === true) &&
|
579 | 575 | typePassesFilter(typeFilter, searchIndex[i].ty)) {
|
580 |
| - if (results[ty.path + ty.name] === undefined) { |
581 |
| - results[ty.path + ty.name] = { |
| 576 | + if (results[fullId] === undefined) { |
| 577 | + results[fullId] = { |
582 | 578 | id: i,
|
583 | 579 | index: -1,
|
584 | 580 | dontValidate: true,
|
|
588 | 584 | results_length += 1;
|
589 | 585 | } else {
|
590 | 586 | if (in_args === true) {
|
591 |
| - results[ty.path + ty.name].in_args = true; |
| 587 | + results[fullId].in_args = true; |
592 | 588 | }
|
593 | 589 | if (returned === true) {
|
594 |
| - results[ty.path + ty.name].returned = true; |
| 590 | + results[fullId].returned = true; |
595 | 591 | }
|
596 | 592 | }
|
597 | 593 | }
|
|
620 | 616 | if (!type) {
|
621 | 617 | continue;
|
622 | 618 | }
|
| 619 | + var fullId = itemTypes[ty.ty] + ty.path + ty.name; |
623 | 620 |
|
624 | 621 | // allow searching for void (no output) functions as well
|
625 | 622 | var typeOutput = type.output ? type.output.name : "";
|
|
638 | 635 | in_args = allFound;
|
639 | 636 | }
|
640 | 637 | if (in_args === true || returned === true || module === true) {
|
641 |
| - if (results[ty.path + ty.name] !== undefined) { |
| 638 | + if (results[fullId] !== undefined) { |
642 | 639 | if (returned === true) {
|
643 |
| - results[ty.path + ty.name].returned = true; |
| 640 | + results[fullId].returned = true; |
644 | 641 | }
|
645 | 642 | if (in_args === true) {
|
646 |
| - results[ty.path + ty.name].in_args = true; |
| 643 | + results[fullId].in_args = true; |
647 | 644 | }
|
648 | 645 | } else {
|
649 |
| - results[ty.path + ty.name] = { |
| 646 | + results[fullId] = { |
650 | 647 | id: i,
|
651 | 648 | index: -1,
|
652 | 649 | dontValidate: true,
|
|
681 | 678 | var index = -1;
|
682 | 679 | // we want lev results to go lower than others
|
683 | 680 | var lev = MAX_LEV_DISTANCE;
|
| 681 | + var fullId = itemTypes[ty.ty] + ty.path + ty.name; |
684 | 682 |
|
685 | 683 | if (searchWords[j].indexOf(split[i]) > -1 ||
|
686 | 684 | searchWords[j].indexOf(val) > -1 ||
|
687 | 685 | searchWords[j].replace(/_/g, "").indexOf(val) > -1)
|
688 | 686 | {
|
689 | 687 | // filter type: ... queries
|
690 |
| - if (typePassesFilter(typeFilter, searchIndex[j].ty) && |
691 |
| - results[ty.path + ty.name] === undefined) { |
| 688 | + if (typePassesFilter(typeFilter, ty) && |
| 689 | + results[fullId] === undefined) { |
692 | 690 | index = searchWords[j].replace(/_/g, "").indexOf(val);
|
693 | 691 | }
|
694 | 692 | }
|
695 | 693 | if ((lev_distance = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) {
|
696 |
| - if (typePassesFilter(typeFilter, searchIndex[j].ty) && |
697 |
| - (results[ty.path + ty.name] === undefined || |
698 |
| - results[ty.path + ty.name].lev > lev_distance)) { |
699 |
| - lev = min(lev, lev_distance); |
700 |
| - index = 0; |
| 694 | + if (typePassesFilter(typeFilter, ty) && |
| 695 | + (results[fullId] === undefined || |
| 696 | + results[fullId].lev > lev_distance)) { |
| 697 | + lev = Math.min(lev, lev_distance); |
| 698 | + index = Math.max(0, index); |
701 | 699 | }
|
702 | 700 | }
|
703 | 701 | if ((lev_distance = findArg(searchIndex[j], valGenerics))
|
704 | 702 | <= MAX_LEV_DISTANCE) {
|
705 |
| - if (typePassesFilter(typeFilter, searchIndex[j].ty) && |
706 |
| - (results[ty.path + ty.name] === undefined || |
707 |
| - results[ty.path + ty.name].lev > lev_distance)) { |
| 703 | + if (typePassesFilter(typeFilter, ty) && |
| 704 | + (results[fullId] === undefined || |
| 705 | + results[fullId].lev > lev_distance)) { |
708 | 706 | in_args = true;
|
709 |
| - lev = min(lev_distance, lev); |
710 |
| - index = 0; |
| 707 | + lev = Math.min(lev_distance, lev); |
| 708 | + index = Math.max(0, index); |
711 | 709 | }
|
712 | 710 | }
|
713 | 711 | if ((lev_distance = checkReturned(searchIndex[j], valGenerics)) <=
|
714 | 712 | MAX_LEV_DISTANCE) {
|
715 |
| - if (typePassesFilter(typeFilter, searchIndex[j].ty) && |
716 |
| - (results[ty.path + ty.name] === undefined || |
717 |
| - results[ty.path + ty.name].lev > lev_distance)) { |
| 713 | + if (typePassesFilter(typeFilter, ty) && |
| 714 | + (results[fullId] === undefined || |
| 715 | + results[fullId].lev > lev_distance)) { |
718 | 716 | returned = true;
|
719 |
| - lev = min(lev_distance, lev); |
720 |
| - index = 0; |
| 717 | + lev = Math.min(lev_distance, lev); |
| 718 | + index = Math.max(0, index); |
721 | 719 | }
|
722 | 720 | }
|
723 | 721 | if (index !== -1) {
|
724 |
| - if (results[ty.path + ty.name] === undefined) { |
725 |
| - results[ty.path + ty.name] = { |
| 722 | + if (results[fullId] === undefined) { |
| 723 | + results[fullId] = { |
726 | 724 | id: j,
|
727 | 725 | index: index,
|
728 | 726 | lev: lev,
|
|
731 | 729 | };
|
732 | 730 | results_length += 1;
|
733 | 731 | } else {
|
734 |
| - if (results[ty.path + ty.name].lev > lev) { |
735 |
| - results[ty.path + ty.name].lev = lev; |
| 732 | + if (results[fullId].lev > lev) { |
| 733 | + results[fullId].lev = lev; |
736 | 734 | }
|
737 | 735 | if (in_args === true) {
|
738 |
| - results[ty.path + ty.name].in_args = true; |
| 736 | + results[fullId].in_args = true; |
739 | 737 | }
|
740 | 738 | if (returned === true) {
|
741 |
| - results[ty.path + ty.name].returned = true; |
| 739 | + results[fullId].returned = true; |
742 | 740 | }
|
743 | 741 | }
|
744 | 742 | }
|
|
0 commit comments