filters.ts ×21

Frontier kind: Code frontier

unlabeled · c_7db6756dcf95

37 tests · 5738 LOC · 29 files · introduces 0 tests · 125 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
21 ranges125 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
817 ranges5738 lines · 29 files · Browse complete extent
All tests (intent)
37 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 125 introduced LOC across 21 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/filters.ts 125 introduced LOC · 21 ranges

Open complete file

576 }
577
578 > function isSeparatorAtPos(value: string, index: number): boolean { filters.ts
579 > if (index < 0 || index >= value.length) {
580 return false;
581 }
582 > const code = value.codePointAt(index); filters.ts
583 > switch (code) {
584 > case CharCode.Underline:
585 > case CharCode.Dash:
586 > case CharCode.Period:
587 > case CharCode.Space:
588 > case CharCode.Slash:
589 > case CharCode.Backslash:
590 > case CharCode.SingleQuote:
591 > case CharCode.DoubleQuote:
592 > case CharCode.Colon:
593 > case CharCode.DollarSign:
594 > case CharCode.LessThan:
595 > case CharCode.GreaterThan:
596 > case CharCode.OpenParen:
597 > case CharCode.CloseParen:
598 > case CharCode.OpenSquareBracket:
599 > case CharCode.CloseSquareBracket:
600 > case CharCode.OpenCurlyBrace:
601 > case CharCode.CloseCurlyBrace:
602 return true;
603 > case undefined: filters.ts
604 return false;
605 > default: filters.ts
606 > if (strings.isEmojiImprecise(code)) {
607 return true;
608 }
609 return false;
610 > } filters.ts
611 > }
612
613 function isWhitespaceAtPos(value: string, index: number): boolean {
625 }
626
627 > function isUpperCaseAtPos(pos: number, word: string, wordLow: string): boolean { filters.ts
628 > return word[pos] !== wordLow[pos];
629 > }
630
631 export function isPatternInWord(patternLow: string, patternPos: number, patternLen: number, wordLow: string, wordPos: number, wordLen: number, fillMinWordPosArr = false): boolean {
696 return undefined;
697 }
698 > filters.ts
699 > // Find the max matching word position for each pattern position
700 > // NOTE: the min matching word position was filled in above, in the `isPatternInWord` call
701 > _fillInMaxWordMatchPos(patternLen, wordLen, patternStart, wordStart, patternLow, wordLow);
702 >
703 > let row: number = 1;
704 > let column: number = 1;
705 > let patternPos = patternStart;
706 > let wordPos = wordStart;
707 >
708 > const hasStrongFirstMatch = [false];
709 >
710 > // There will be a match, fill in tables
711 > for (row = 1, patternPos = patternStart; patternPos < patternLen; row++, patternPos++) {
712 >
713 > // Reduce search space to possible matching word positions and to possible access from next row
714 > const minWordMatchPos = _minWordMatchPos[patternPos];
715 > const maxWordMatchPos = _maxWordMatchPos[patternPos];
716 > const nextMaxWordMatchPos = (patternPos + 1 < patternLen ? _maxWordMatchPos[patternPos + 1] : wordLen);
717 >
718 > for (column = minWordMatchPos - wordStart + 1, wordPos = minWordMatchPos; wordPos < nextMaxWordMatchPos; column++, wordPos++) {
719 >
720 > let score = Number.MIN_SAFE_INTEGER;
721 > let canComeDiag = false;
722 >
723 > if (wordPos <= maxWordMatchPos) {
724 > score = _doScore(
725 > pattern, patternLow, patternPos, patternStart,
726 > word, wordLow, wordPos, wordLen, wordStart,
727 > _diag[row - 1][column - 1] === 0,
728 > hasStrongFirstMatch
729 > );
730 > }
731 >
732 > let diagScore = 0;
733 > if (score !== Number.MIN_SAFE_INTEGER) {
734 > canComeDiag = true;
735 > diagScore = score + _table[row - 1][column - 1];
736 > }
737 >
738 > const canComeLeft = wordPos > minWordMatchPos;
739 > const leftScore = canComeLeft ? _table[row][column - 1] + (_diag[row][column - 1] > 0 ? -5 : 0) : 0; // penalty for a gap start
740 >
741 > const canComeLeftLeft = wordPos > minWordMatchPos + 1 && _diag[row][column - 1] > 0;
742 > const leftLeftScore = canComeLeftLeft ? _table[row][column - 2] + (_diag[row][column - 2] > 0 ? -5 : 0) : 0; // penalty for a gap start
743 >
744 > if (canComeLeftLeft && (!canComeLeft || leftLeftScore >= leftScore) && (!canComeDiag || leftLeftScore >= diagScore)) {
745 // always prefer choosing left left to jump over a diagonal because that means a match is earlier in the word
746 _table[row][column] = leftLeftScore;
747 _arrows[row][column] = Arrow.LeftLeft;
748 _diag[row][column] = 0;
749 > } else if (canComeLeft && (!canComeDiag || leftScore >= diagScore)) { filters.ts
750 // always prefer choosing left since that means a match is earlier in the word
751 _table[row][column] = leftScore;
752 _arrows[row][column] = Arrow.Left;
753 _diag[row][column] = 0;
754 > } else if (canComeDiag) { filters.ts
755 > _table[row][column] = diagScore;
756 > _arrows[row][column] = Arrow.Diag;
757 > _diag[row][column] = _diag[row - 1][column - 1] + 1;
758 > } else {
759 throw new Error(`not possible`);
760 }
761 > } filters.ts
762 > }
763 >
764 > if (_debug) {
765 printTables(pattern, patternStart, word, wordStart);
766 }
767 > filters.ts
768 if (!hasStrongFirstMatch[0] && !options.firstMatchCanBeWeak) {
769 return undefined;
833 }
834
835 > function _fillInMaxWordMatchPos(patternLen: number, wordLen: number, patternStart: number, wordStart: number, patternLow: string, wordLow: string) { filters.ts
836 > let patternPos = patternLen - 1;
837 > let wordPos = wordLen - 1;
838 > while (patternPos >= patternStart && wordPos >= wordStart) {
839 > if (patternLow[patternPos] === wordLow[wordPos]) {
840 > _maxWordMatchPos[patternPos] = wordPos;
841 > patternPos--;
842 > }
843 > wordPos--;
844 > }
845 > }
846
847 > function _doScore( filters.ts
848 > pattern: string, patternLow: string, patternPos: number, patternStart: number,
849 > word: string, wordLow: string, wordPos: number, wordLen: number, wordStart: number,
850 > newMatchStart: boolean,
851 > outFirstMatchStrong: boolean[],
852 > ): number {
853 > if (patternLow[patternPos] !== wordLow[wordPos]) {
854 return Number.MIN_SAFE_INTEGER;
855 }
856 > filters.ts
857 > let score = 1;
858 > let isGapLocation = false;
859 > if (wordPos === (patternPos - patternStart)) {
860 // common prefix: `foobar <-> foobaz`
861 // ^^^^^
862 score = pattern[patternPos] === word[wordPos] ? 7 : 5;
863
864 > } else if (isUpperCaseAtPos(wordPos, word, wordLow) && (wordPos === 0 || !isUpperCaseAtPos(wordPos - 1, word, wordLow))) { filters.ts
865 // hitting upper-case: `foo <-> forOthers`
866 // ^^ ^
879 isGapLocation = true;
880 }
881 > filters.ts
882 > if (score > 1 && patternPos === patternStart) {
883 outFirstMatchStrong[0] = true;
884 }
885 > filters.ts
886 > if (!isGapLocation) {
887 isGapLocation = isUpperCaseAtPos(wordPos, word, wordLow) || isSeparatorAtPos(wordLow, wordPos - 1) || isWhitespaceAtPos(wordLow, wordPos - 1);
888 }
889 > filters.ts
890 > //
891 > if (patternPos === patternStart) { // first character in pattern
892 > if (wordPos > wordStart) {
893 // the first pattern character would match a word character that is not at the word start
894 // so introduce a penalty to account for the gap preceding this match
895 score -= isGapLocation ? 3 : 5;
896 }
897 > } else { filters.ts
898 if (newMatchStart) {
899 // this would be the beginning of a new match (i.e. there would be a gap before this location)
904 }
905 }
906 > filters.ts
907 > if (wordPos + 1 === wordLen) {
908 // we always penalize gaps, but this gives unfair advantages to a match that would match the last character in the word
909 // so pretend there is a gap after the last character in the word to normalize things
910 score -= isGapLocation ? 3 : 5;
911 }
912 > filters.ts
913 > return score;
914 > }
915
916 //#endregion