code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function getMatches(candidateContainers, candidate) {
if (skipMatch(candidate)) {
return undefined;
}
// First, check that the last part of the dot separated pattern matches the name of the
// candidate. If not, then there's no point in proceeding and doing the more
// expensive work.
var candidateMatch = matchSegment(candidate, ts.lastOrUndefined(dotSeparatedSegments));
if (!candidateMatch) {
return undefined;
}
candidateContainers = candidateContainers || [];
// -1 because the last part was checked against the name, and only the rest
// of the parts are checked against the container.
if (dotSeparatedSegments.length - 1 > candidateContainers.length) {
// There weren't enough container parts to match against the pattern parts.
// So this definitely doesn't match.
return undefined;
}
// So far so good. Now break up the container for the candidate and check if all
// the dotted parts match up correctly.
var totalMatch = candidateMatch;
for (var i = dotSeparatedSegments.length - 2, j = candidateContainers.length - 1; i >= 0; i--, j--) {
var segment = dotSeparatedSegments[i];
var containerName = candidateContainers[j];
var containerMatch = matchSegment(containerName, segment);
if (!containerMatch) {
// This container didn't match the pattern piece. So there's no match at all.
return undefined;
}
ts.addRange(totalMatch, containerMatch);
}
// Success, this symbol's full name matched against the dotted name the user was asking
// about.
return totalMatch;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
getMatches
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getWordSpans(word) {
if (!ts.hasProperty(stringToWordSpans, word)) {
stringToWordSpans[word] = breakIntoWordSpans(word);
}
return stringToWordSpans[word];
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
getWordSpans
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function matchTextChunk(candidate, chunk, punctuationStripped) {
var index = indexOfIgnoringCase(candidate, chunk.textLowerCase);
if (index === 0) {
if (chunk.text.length === candidate.length) {
// a) Check if the part matches the candidate entirely, in an case insensitive or
// sensitive manner. If it does, return that there was an exact match.
return createPatternMatch(PatternMatchKind.exact, punctuationStripped, /*isCaseSensitive:*/ candidate === chunk.text);
}
else {
// b) Check if the part is a prefix of the candidate, in a case insensitive or sensitive
// manner. If it does, return that there was a prefix match.
return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
}
}
var isLowercase = chunk.isLowerCase;
if (isLowercase) {
if (index > 0) {
// c) If the part is entirely lowercase, then check if it is contained anywhere in the
// candidate in a case insensitive manner. If so, return that there was a substring
// match.
//
// Note: We only have a substring match if the lowercase part is prefix match of some
// word part. That way we don't match something like 'Class' when the user types 'a'.
// But we would match 'FooAttribute' (since 'Attribute' starts with 'a').
var wordSpans = getWordSpans(candidate);
for (var _i = 0, wordSpans_1 = wordSpans; _i < wordSpans_1.length; _i++) {
var span = wordSpans_1[_i];
if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) {
return createPatternMatch(PatternMatchKind.substring, punctuationStripped,
/*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false));
}
}
}
}
else {
// d) If the part was not entirely lowercase, then check if it is contained in the
// candidate in a case *sensitive* manner. If so, return that there was a substring
// match.
if (candidate.indexOf(chunk.text) > 0) {
return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ true);
}
}
if (!isLowercase) {
// e) If the part was not entirely lowercase, then attempt a camel cased match as well.
if (chunk.characterSpans.length > 0) {
var candidateParts = getWordSpans(candidate);
var camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false);
if (camelCaseWeight !== undefined) {
return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ true, /*camelCaseWeight:*/ camelCaseWeight);
}
camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ true);
if (camelCaseWeight !== undefined) {
return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ false, /*camelCaseWeight:*/ camelCaseWeight);
}
}
}
if (isLowercase) {
// f) Is the pattern a substring of the candidate starting on one of the candidate's word boundaries?
// We could check every character boundary start of the candidate for the pattern. However, that's
// an m * n operation in the wost case. Instead, find the first instance of the pattern
// substring, and see if it starts on a capital letter. It seems unlikely that the user will try to
// filter the list based on a substring that starts on a capital letter and also with a lowercase one.
// (Pattern: fogbar, Candidate: quuxfogbarFogBar).
if (chunk.text.length < candidate.length) {
if (index > 0 && isUpperCaseLetter(candidate.charCodeAt(index))) {
return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ false);
}
}
}
return undefined;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
matchTextChunk
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function containsSpaceOrAsterisk(text) {
for (var i = 0; i < text.length; i++) {
var ch = text.charCodeAt(i);
if (ch === 32 /* space */ || ch === 42 /* asterisk */) {
return true;
}
}
return false;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
containsSpaceOrAsterisk
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function matchSegment(candidate, segment) {
// First check if the segment matches as is. This is also useful if the segment contains
// characters we would normally strip when splitting into parts that we also may want to
// match in the candidate. For example if the segment is "@int" and the candidate is
// "@int", then that will show up as an exact match here.
//
// Note: if the segment contains a space or an asterisk then we must assume that it's a
// multi-word segment.
if (!containsSpaceOrAsterisk(segment.totalTextChunk.text)) {
var match = matchTextChunk(candidate, segment.totalTextChunk, /*punctuationStripped:*/ false);
if (match) {
return [match];
}
}
// The logic for pattern matching is now as follows:
//
// 1) Break the segment passed in into words. Breaking is rather simple and a
// good way to think about it that if gives you all the individual alphanumeric words
// of the pattern.
//
// 2) For each word try to match the word against the candidate value.
//
// 3) Matching is as follows:
//
// a) Check if the word matches the candidate entirely, in an case insensitive or
// sensitive manner. If it does, return that there was an exact match.
//
// b) Check if the word is a prefix of the candidate, in a case insensitive or
// sensitive manner. If it does, return that there was a prefix match.
//
// c) If the word is entirely lowercase, then check if it is contained anywhere in the
// candidate in a case insensitive manner. If so, return that there was a substring
// match.
//
// Note: We only have a substring match if the lowercase part is prefix match of
// some word part. That way we don't match something like 'Class' when the user
// types 'a'. But we would match 'FooAttribute' (since 'Attribute' starts with
// 'a').
//
// d) If the word was not entirely lowercase, then check if it is contained in the
// candidate in a case *sensitive* manner. If so, return that there was a substring
// match.
//
// e) If the word was not entirely lowercase, then attempt a camel cased match as
// well.
//
// f) The word is all lower case. Is it a case insensitive substring of the candidate starting
// on a part boundary of the candidate?
//
// Only if all words have some sort of match is the pattern considered matched.
var subWordTextChunks = segment.subWordTextChunks;
var matches = undefined;
for (var _i = 0, subWordTextChunks_1 = subWordTextChunks; _i < subWordTextChunks_1.length; _i++) {
var subWordTextChunk = subWordTextChunks_1[_i];
// Try to match the candidate with this word
var result = matchTextChunk(candidate, subWordTextChunk, /*punctuationStripped:*/ true);
if (!result) {
return undefined;
}
matches = matches || [];
matches.push(result);
}
return matches;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
matchSegment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function partStartsWith(candidate, candidateSpan, pattern, ignoreCase, patternSpan) {
var patternPartStart = patternSpan ? patternSpan.start : 0;
var patternPartLength = patternSpan ? patternSpan.length : pattern.length;
if (patternPartLength > candidateSpan.length) {
// Pattern part is longer than the candidate part. There can never be a match.
return false;
}
if (ignoreCase) {
for (var i = 0; i < patternPartLength; i++) {
var ch1 = pattern.charCodeAt(patternPartStart + i);
var ch2 = candidate.charCodeAt(candidateSpan.start + i);
if (toLowerCase(ch1) !== toLowerCase(ch2)) {
return false;
}
}
}
else {
for (var i = 0; i < patternPartLength; i++) {
var ch1 = pattern.charCodeAt(patternPartStart + i);
var ch2 = candidate.charCodeAt(candidateSpan.start + i);
if (ch1 !== ch2) {
return false;
}
}
}
return true;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
partStartsWith
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function tryCamelCaseMatch(candidate, candidateParts, chunk, ignoreCase) {
var chunkCharacterSpans = chunk.characterSpans;
// Note: we may have more pattern parts than candidate parts. This is because multiple
// pattern parts may match a candidate part. For example "SiUI" against "SimpleUI".
// We'll have 3 pattern parts Si/U/I against two candidate parts Simple/UI. However, U
// and I will both match in UI.
var currentCandidate = 0;
var currentChunkSpan = 0;
var firstMatch = undefined;
var contiguous = undefined;
while (true) {
// Let's consider our termination cases
if (currentChunkSpan === chunkCharacterSpans.length) {
// We did match! We shall assign a weight to this
var weight = 0;
// Was this contiguous?
if (contiguous) {
weight += 1;
}
// Did we start at the beginning of the candidate?
if (firstMatch === 0) {
weight += 2;
}
return weight;
}
else if (currentCandidate === candidateParts.length) {
// No match, since we still have more of the pattern to hit
return undefined;
}
var candidatePart = candidateParts[currentCandidate];
var gotOneMatchThisCandidate = false;
// Consider the case of matching SiUI against SimpleUIElement. The candidate parts
// will be Simple/UI/Element, and the pattern parts will be Si/U/I. We'll match 'Si'
// against 'Simple' first. Then we'll match 'U' against 'UI'. However, we want to
// still keep matching pattern parts against that candidate part.
for (; currentChunkSpan < chunkCharacterSpans.length; currentChunkSpan++) {
var chunkCharacterSpan = chunkCharacterSpans[currentChunkSpan];
if (gotOneMatchThisCandidate) {
// We've already gotten one pattern part match in this candidate. We will
// only continue trying to consumer pattern parts if the last part and this
// part are both upper case.
if (!isUpperCaseLetter(chunk.text.charCodeAt(chunkCharacterSpans[currentChunkSpan - 1].start)) ||
!isUpperCaseLetter(chunk.text.charCodeAt(chunkCharacterSpans[currentChunkSpan].start))) {
break;
}
}
if (!partStartsWith(candidate, candidatePart, chunk.text, ignoreCase, chunkCharacterSpan)) {
break;
}
gotOneMatchThisCandidate = true;
firstMatch = firstMatch === undefined ? currentCandidate : firstMatch;
// If we were contiguous, then keep that value. If we weren't, then keep that
// value. If we don't know, then set the value to 'true' as an initial match is
// obviously contiguous.
contiguous = contiguous === undefined ? true : contiguous;
candidatePart = ts.createTextSpan(candidatePart.start + chunkCharacterSpan.length, candidatePart.length - chunkCharacterSpan.length);
}
// Check if we matched anything at all. If we didn't, then we need to unset the
// contiguous bit if we currently had it set.
// If we haven't set the bit yet, then that means we haven't matched anything so
// far, and we don't want to change that.
if (!gotOneMatchThisCandidate && contiguous !== undefined) {
contiguous = false;
}
// Move onto the next candidate.
currentCandidate++;
}
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
tryCamelCaseMatch
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function comparePunctuation(result1, result2) {
// Consider a match to be better if it was successful without stripping punctuation
// versus a match that had to strip punctuation to succeed.
if (result1.punctuationStripped !== result2.punctuationStripped) {
return result1.punctuationStripped ? 1 : -1;
}
return 0;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
comparePunctuation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function compareCase(result1, result2) {
if (result1.isCaseSensitive !== result2.isCaseSensitive) {
return result1.isCaseSensitive ? -1 : 1;
}
return 0;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
compareCase
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function compareType(result1, result2) {
return result1.kind - result2.kind;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
compareType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function compareCamelCase(result1, result2) {
if (result1.kind === PatternMatchKind.camelCase && result2.kind === PatternMatchKind.camelCase) {
// Swap the values here. If result1 has a higher weight, then we want it to come
// first.
return result2.camelCaseWeight - result1.camelCaseWeight;
}
return 0;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
compareCamelCase
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createSegment(text) {
return {
totalTextChunk: createTextChunk(text),
subWordTextChunks: breakPatternIntoTextChunks(text)
};
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
createSegment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function segmentIsInvalid(segment) {
return segment.subWordTextChunks.length === 0;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
segmentIsInvalid
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isUpperCaseLetter(ch) {
// Fast check for the ascii range.
if (ch >= 65 /* A */ && ch <= 90 /* Z */) {
return true;
}
if (ch < 127 /* maxAsciiCharacter */ || !ts.isUnicodeIdentifierStart(ch, 2 /* Latest */)) {
return false;
}
// TODO: find a way to determine this for any unicode characters in a
// non-allocating manner.
var str = String.fromCharCode(ch);
return str === str.toUpperCase();
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
isUpperCaseLetter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isLowerCaseLetter(ch) {
// Fast check for the ascii range.
if (ch >= 97 /* a */ && ch <= 122 /* z */) {
return true;
}
if (ch < 127 /* maxAsciiCharacter */ || !ts.isUnicodeIdentifierStart(ch, 2 /* Latest */)) {
return false;
}
// TODO: find a way to determine this for any unicode characters in a
// non-allocating manner.
var str = String.fromCharCode(ch);
return str === str.toLowerCase();
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
isLowerCaseLetter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function containsUpperCaseLetter(string) {
for (var i = 0, n = string.length; i < n; i++) {
if (isUpperCaseLetter(string.charCodeAt(i))) {
return true;
}
}
return false;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
containsUpperCaseLetter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function startsWith(string, search) {
for (var i = 0, n = search.length; i < n; i++) {
if (string.charCodeAt(i) !== search.charCodeAt(i)) {
return false;
}
}
return true;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
startsWith
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function toLowerCase(ch) {
// Fast convert for the ascii range.
if (ch >= 65 /* A */ && ch <= 90 /* Z */) {
return 97 /* a */ + (ch - 65 /* A */);
}
if (ch < 127 /* maxAsciiCharacter */) {
return ch;
}
// TODO: find a way to compute this for any unicode characters in a
// non-allocating manner.
return String.fromCharCode(ch).toLowerCase().charCodeAt(0);
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
toLowerCase
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isDigit(ch) {
// TODO(cyrusn): Find a way to support this for unicode digits.
return ch >= 48 /* _0 */ && ch <= 57 /* _9 */;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
isDigit
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isWordChar(ch) {
return isUpperCaseLetter(ch) || isLowerCaseLetter(ch) || isDigit(ch) || ch === 95 /* _ */ || ch === 36 /* $ */;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
isWordChar
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function breakPatternIntoTextChunks(pattern) {
var result = [];
var wordStart = 0;
var wordLength = 0;
for (var i = 0; i < pattern.length; i++) {
var ch = pattern.charCodeAt(i);
if (isWordChar(ch)) {
if (wordLength++ === 0) {
wordStart = i;
}
}
else {
if (wordLength > 0) {
result.push(createTextChunk(pattern.substr(wordStart, wordLength)));
wordLength = 0;
}
}
}
if (wordLength > 0) {
result.push(createTextChunk(pattern.substr(wordStart, wordLength)));
}
return result;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
breakPatternIntoTextChunks
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createTextChunk(text) {
var textLowerCase = text.toLowerCase();
return {
text: text,
textLowerCase: textLowerCase,
isLowerCase: text === textLowerCase,
characterSpans: breakIntoCharacterSpans(text)
};
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
createTextChunk
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function breakIntoCharacterSpans(identifier) {
return breakIntoSpans(identifier, /*word:*/ false);
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
breakIntoCharacterSpans
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function breakIntoWordSpans(identifier) {
return breakIntoSpans(identifier, /*word:*/ true);
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
breakIntoWordSpans
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function breakIntoSpans(identifier, word) {
var result = [];
var wordStart = 0;
for (var i = 1, n = identifier.length; i < n; i++) {
var lastIsDigit = isDigit(identifier.charCodeAt(i - 1));
var currentIsDigit = isDigit(identifier.charCodeAt(i));
var hasTransitionFromLowerToUpper = transitionFromLowerToUpper(identifier, word, i);
var hasTransitionFromUpperToLower = transitionFromUpperToLower(identifier, word, i, wordStart);
if (charIsPunctuation(identifier.charCodeAt(i - 1)) ||
charIsPunctuation(identifier.charCodeAt(i)) ||
lastIsDigit !== currentIsDigit ||
hasTransitionFromLowerToUpper ||
hasTransitionFromUpperToLower) {
if (!isAllPunctuation(identifier, wordStart, i)) {
result.push(ts.createTextSpan(wordStart, i - wordStart));
}
wordStart = i;
}
}
if (!isAllPunctuation(identifier, wordStart, identifier.length)) {
result.push(ts.createTextSpan(wordStart, identifier.length - wordStart));
}
return result;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
breakIntoSpans
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function charIsPunctuation(ch) {
switch (ch) {
case 33 /* exclamation */:
case 34 /* doubleQuote */:
case 35 /* hash */:
case 37 /* percent */:
case 38 /* ampersand */:
case 39 /* singleQuote */:
case 40 /* openParen */:
case 41 /* closeParen */:
case 42 /* asterisk */:
case 44 /* comma */:
case 45 /* minus */:
case 46 /* dot */:
case 47 /* slash */:
case 58 /* colon */:
case 59 /* semicolon */:
case 63 /* question */:
case 64 /* at */:
case 91 /* openBracket */:
case 92 /* backslash */:
case 93 /* closeBracket */:
case 95 /* _ */:
case 123 /* openBrace */:
case 125 /* closeBrace */:
return true;
}
return false;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
charIsPunctuation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isAllPunctuation(identifier, start, end) {
for (var i = start; i < end; i++) {
var ch = identifier.charCodeAt(i);
// We don't consider _ or $ as punctuation as there may be things with that name.
if (!charIsPunctuation(ch) || ch === 95 /* _ */ || ch === 36 /* $ */) {
return false;
}
}
return true;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
isAllPunctuation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function transitionFromUpperToLower(identifier, word, index, wordStart) {
if (word) {
// Cases this supports:
// 1) IDisposable -> I, Disposable
// 2) UIElement -> UI, Element
// 3) HTMLDocument -> HTML, Document
//
// etc.
if (index !== wordStart &&
index + 1 < identifier.length) {
var currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index));
var nextIsLower = isLowerCaseLetter(identifier.charCodeAt(index + 1));
if (currentIsUpper && nextIsLower) {
// We have a transition from an upper to a lower letter here. But we only
// want to break if all the letters that preceded are uppercase. i.e. if we
// have "Foo" we don't want to break that into "F, oo". But if we have
// "IFoo" or "UIFoo", then we want to break that into "I, Foo" and "UI,
// Foo". i.e. the last uppercase letter belongs to the lowercase letters
// that follows. Note: this will make the following not split properly:
// "HELLOthere". However, these sorts of names do not show up in .Net
// programs.
for (var i = wordStart; i < index; i++) {
if (!isUpperCaseLetter(identifier.charCodeAt(i))) {
return false;
}
}
return true;
}
}
}
return false;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
transitionFromUpperToLower
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function transitionFromLowerToUpper(identifier, word, index) {
var lastIsUpper = isUpperCaseLetter(identifier.charCodeAt(index - 1));
var currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index));
// See if the casing indicates we're starting a new word. Note: if we're breaking on
// words, then just seeing an upper case character isn't enough. Instead, it has to
// be uppercase and the previous character can't be uppercase.
//
// For example, breaking "AddMetadata" on words would make: Add Metadata
//
// on characters would be: A dd M etadata
//
// Break "AM" on words would be: AM
//
// on characters would be: A M
//
// We break the search string on characters. But we break the symbol name on words.
var transition = word
? (currentIsUpper && !lastIsUpper)
: currentIsUpper;
return transition;
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
transitionFromLowerToUpper
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getSignatureHelpItems(program, sourceFile, position, cancellationToken) {
var typeChecker = program.getTypeChecker();
// Decide whether to show signature help
var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position);
if (!startingToken) {
// We are at the beginning of the file
return undefined;
}
var argumentInfo = getContainingArgumentInfo(startingToken);
cancellationToken.throwIfCancellationRequested();
// Semantic filtering of signature help
if (!argumentInfo) {
return undefined;
}
var call = argumentInfo.invocation;
var candidates = [];
var resolvedSignature = typeChecker.getResolvedSignature(call, candidates);
cancellationToken.throwIfCancellationRequested();
if (!candidates.length) {
// We didn't have any sig help items produced by the TS compiler. If this is a JS
// file, then see if we can figure out anything better.
if (ts.isSourceFileJavaScript(sourceFile)) {
return createJavaScriptSignatureHelpItems(argumentInfo);
}
return undefined;
}
return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo);
function createJavaScriptSignatureHelpItems(argumentInfo) {
if (argumentInfo.invocation.kind !== 168 /* CallExpression */) {
return undefined;
}
// See if we can find some symbol with the call expression name that has call signatures.
var callExpression = argumentInfo.invocation;
var expression = callExpression.expression;
var name = expression.kind === 69 /* Identifier */
? expression
: expression.kind === 166 /* PropertyAccessExpression */
? expression.name
: undefined;
if (!name || !name.text) {
return undefined;
}
var typeChecker = program.getTypeChecker();
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile_1 = _a[_i];
var nameToDeclarations = sourceFile_1.getNamedDeclarations();
var declarations = ts.getProperty(nameToDeclarations, name.text);
if (declarations) {
for (var _b = 0, declarations_7 = declarations; _b < declarations_7.length; _b++) {
var declaration = declarations_7[_b];
var symbol = declaration.symbol;
if (symbol) {
var type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
if (type) {
var callSignatures = type.getCallSignatures();
if (callSignatures && callSignatures.length) {
return createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo);
}
}
}
}
}
}
}
/**
* Returns relevant information for the argument list and the current argument if we are
* in the argument of an invocation; returns undefined otherwise.
*/
function getImmediatelyContainingArgumentInfo(node) {
if (node.parent.kind === 168 /* CallExpression */ || node.parent.kind === 169 /* NewExpression */) {
var callExpression = node.parent;
// There are 3 cases to handle:
// 1. The token introduces a list, and should begin a sig help session
// 2. The token is either not associated with a list, or ends a list, so the session should end
// 3. The token is buried inside a list, and should give sig help
//
// The following are examples of each:
//
// Case 1:
// foo<#T, U>(#a, b) -> The token introduces a list, and should begin a sig help session
// Case 2:
// fo#o<T, U>#(a, b)# -> The token is either not associated with a list, or ends a list, so the session should end
// Case 3:
// foo<T#, U#>(a#, #b#) -> The token is buried inside a list, and should give sig help
// Find out if 'node' is an argument, a type argument, or neither
if (node.kind === 25 /* LessThanToken */ ||
node.kind === 17 /* OpenParenToken */) {
// Find the list that starts right *after* the < or ( token.
// If the user has just opened a list, consider this item 0.
var list = getChildListThatStartsWithOpenerToken(callExpression, node, sourceFile);
var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
ts.Debug.assert(list !== undefined);
return {
kind: isTypeArgList ? 0 /* TypeArguments */ : 1 /* CallArguments */,
invocation: callExpression,
argumentsSpan: getApplicableSpanForArguments(list),
argumentIndex: 0,
argumentCount: getArgumentCount(list)
};
}
// findListItemInfo can return undefined if we are not in parent's argument list
// or type argument list. This includes cases where the cursor is:
// - To the right of the closing paren, non-substitution template, or template tail.
// - Between the type arguments and the arguments (greater than token)
// - On the target of the call (parent.func)
// - On the 'new' keyword in a 'new' expression
var listItemInfo = ts.findListItemInfo(node);
if (listItemInfo) {
var list = listItemInfo.list;
var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
var argumentIndex = getArgumentIndex(list, node);
var argumentCount = getArgumentCount(list);
ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex);
return {
kind: isTypeArgList ? 0 /* TypeArguments */ : 1 /* CallArguments */,
invocation: callExpression,
argumentsSpan: getApplicableSpanForArguments(list),
argumentIndex: argumentIndex,
argumentCount: argumentCount
};
}
}
else if (node.kind === 11 /* NoSubstitutionTemplateLiteral */ && node.parent.kind === 170 /* TaggedTemplateExpression */) {
// Check if we're actually inside the template;
// otherwise we'll fall out and return undefined.
if (ts.isInsideTemplateLiteral(node, position)) {
return getArgumentListInfoForTemplate(node.parent, /*argumentIndex*/ 0);
}
}
else if (node.kind === 12 /* TemplateHead */ && node.parent.parent.kind === 170 /* TaggedTemplateExpression */) {
var templateExpression = node.parent;
var tagExpression = templateExpression.parent;
ts.Debug.assert(templateExpression.kind === 183 /* TemplateExpression */);
var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1;
return getArgumentListInfoForTemplate(tagExpression, argumentIndex);
}
else if (node.parent.kind === 190 /* TemplateSpan */ && node.parent.parent.parent.kind === 170 /* TaggedTemplateExpression */) {
var templateSpan = node.parent;
var templateExpression = templateSpan.parent;
var tagExpression = templateExpression.parent;
ts.Debug.assert(templateExpression.kind === 183 /* TemplateExpression */);
// If we're just after a template tail, don't show signature help.
if (node.kind === 14 /* TemplateTail */ && !ts.isInsideTemplateLiteral(node, position)) {
return undefined;
}
var spanIndex = templateExpression.templateSpans.indexOf(templateSpan);
var argumentIndex = getArgumentIndexForTemplatePiece(spanIndex, node);
return getArgumentListInfoForTemplate(tagExpression, argumentIndex);
}
return undefined;
}
function getArgumentIndex(argumentsList, node) {
// The list we got back can include commas. In the presence of errors it may
// also just have nodes without commas. For example "Foo(a b c)" will have 3
// args without commas. We want to find what index we're at. So we count
// forward until we hit ourselves, only incrementing the index if it isn't a
// comma.
//
// Note: the subtlety around trailing commas (in getArgumentCount) does not apply
// here. That's because we're only walking forward until we hit the node we're
// on. In that case, even if we're after the trailing comma, we'll still see
// that trailing comma in the list, and we'll have generated the appropriate
// arg index.
var argumentIndex = 0;
var listChildren = argumentsList.getChildren();
for (var _i = 0, listChildren_1 = listChildren; _i < listChildren_1.length; _i++) {
var child = listChildren_1[_i];
if (child === node) {
break;
}
if (child.kind !== 24 /* CommaToken */) {
argumentIndex++;
}
}
return argumentIndex;
}
function getArgumentCount(argumentsList) {
// The argument count for a list is normally the number of non-comma children it has.
// For example, if you have "Foo(a,b)" then there will be three children of the arg
// list 'a' '<comma>' 'b'. So, in this case the arg count will be 2. However, there
// is a small subtlety. If you have "Foo(a,)", then the child list will just have
// 'a' '<comma>'. So, in the case where the last child is a comma, we increase the
// arg count by one to compensate.
//
// Note: this subtlety only applies to the last comma. If you had "Foo(a,," then
// we'll have: 'a' '<comma>' '<missing>'
// That will give us 2 non-commas. We then add one for the last comma, givin us an
// arg count of 3.
var listChildren = argumentsList.getChildren();
var argumentCount = ts.countWhere(listChildren, function (arg) { return arg.kind !== 24 /* CommaToken */; });
if (listChildren.length > 0 && ts.lastOrUndefined(listChildren).kind === 24 /* CommaToken */) {
argumentCount++;
}
return argumentCount;
}
// spanIndex is either the index for a given template span.
// This does not give appropriate results for a NoSubstitutionTemplateLiteral
function getArgumentIndexForTemplatePiece(spanIndex, node) {
// Because the TemplateStringsArray is the first argument, we have to offset each substitution expression by 1.
// There are three cases we can encounter:
// 1. We are precisely in the template literal (argIndex = 0).
// 2. We are in or to the right of the substitution expression (argIndex = spanIndex + 1).
// 3. We are directly to the right of the template literal, but because we look for the token on the left,
// not enough to put us in the substitution expression; we should consider ourselves part of
// the *next* span's expression by offsetting the index (argIndex = (spanIndex + 1) + 1).
//
// Example: f `# abcd $#{# 1 + 1# }# efghi ${ #"#hello"# } # `
// ^ ^ ^ ^ ^ ^ ^ ^ ^
// Case: 1 1 3 2 1 3 2 2 1
ts.Debug.assert(position >= node.getStart(), "Assumed 'position' could not occur before node.");
if (ts.isTemplateLiteralKind(node.kind)) {
if (ts.isInsideTemplateLiteral(node, position)) {
return 0;
}
return spanIndex + 2;
}
return spanIndex + 1;
}
function getArgumentListInfoForTemplate(tagExpression, argumentIndex) {
// argumentCount is either 1 or (numSpans + 1) to account for the template strings array argument.
var argumentCount = tagExpression.template.kind === 11 /* NoSubstitutionTemplateLiteral */
? 1
: tagExpression.template.templateSpans.length + 1;
ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex);
return {
kind: 2 /* TaggedTemplateArguments */,
invocation: tagExpression,
argumentsSpan: getApplicableSpanForTaggedTemplate(tagExpression),
argumentIndex: argumentIndex,
argumentCount: argumentCount
};
}
function getApplicableSpanForArguments(argumentsList) {
// We use full start and skip trivia on the end because we want to include trivia on
// both sides. For example,
//
// foo( /*comment */ a, b, c /*comment*/ )
// | |
//
// The applicable span is from the first bar to the second bar (inclusive,
// but not including parentheses)
var applicableSpanStart = argumentsList.getFullStart();
var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentsList.getEnd(), /*stopAfterLineBreak*/ false);
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getApplicableSpanForTaggedTemplate(taggedTemplate) {
var template = taggedTemplate.template;
var applicableSpanStart = template.getStart();
var applicableSpanEnd = template.getEnd();
// We need to adjust the end position for the case where the template does not have a tail.
// Otherwise, we will not show signature help past the expression.
// For example,
//
// ` ${ 1 + 1 foo(10)
// | |
//
// This is because a Missing node has no width. However, what we actually want is to include trivia
// leading up to the next token in case the user is about to type in a TemplateMiddle or TemplateTail.
if (template.kind === 183 /* TemplateExpression */) {
var lastSpan = ts.lastOrUndefined(template.templateSpans);
if (lastSpan.literal.getFullWidth() === 0) {
applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, /*stopAfterLineBreak*/ false);
}
}
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node) {
for (var n = node; n.kind !== 248 /* SourceFile */; n = n.parent) {
if (ts.isFunctionBlock(n)) {
return undefined;
}
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
if (n.pos < n.parent.pos || n.end > n.parent.end) {
ts.Debug.fail("Node of kind " + n.kind + " is not a subspan of its parent of kind " + n.parent.kind);
}
var argumentInfo_1 = getImmediatelyContainingArgumentInfo(n);
if (argumentInfo_1) {
return argumentInfo_1;
}
}
return undefined;
}
function getChildListThatStartsWithOpenerToken(parent, openerToken, sourceFile) {
var children = parent.getChildren(sourceFile);
var indexOfOpenerToken = children.indexOf(openerToken);
ts.Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1);
return children[indexOfOpenerToken + 1];
}
/**
* The selectedItemIndex could be negative for several reasons.
* 1. There are too many arguments for all of the overloads
* 2. None of the overloads were type compatible
* The solution here is to try to pick the best overload by picking
* either the first one that has an appropriate number of parameters,
* or the one with the most parameters.
*/
function selectBestInvalidOverloadIndex(candidates, argumentCount) {
var maxParamsSignatureIndex = -1;
var maxParams = -1;
for (var i = 0; i < candidates.length; i++) {
var candidate = candidates[i];
if (candidate.hasRestParameter || candidate.parameters.length >= argumentCount) {
return i;
}
if (candidate.parameters.length > maxParams) {
maxParams = candidate.parameters.length;
maxParamsSignatureIndex = i;
}
}
return maxParamsSignatureIndex;
}
function createSignatureHelpItems(candidates, bestSignature, argumentListInfo) {
var applicableSpan = argumentListInfo.argumentsSpan;
var isTypeParameterList = argumentListInfo.kind === 0 /* TypeArguments */;
var invocation = argumentListInfo.invocation;
var callTarget = ts.getInvokedExpression(invocation);
var callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget);
var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeChecker, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined);
var items = ts.map(candidates, function (candidateSignature) {
var signatureHelpParameters;
var prefixDisplayParts = [];
var suffixDisplayParts = [];
if (callTargetDisplayParts) {
ts.addRange(prefixDisplayParts, callTargetDisplayParts);
}
if (isTypeParameterList) {
prefixDisplayParts.push(ts.punctuationPart(25 /* LessThanToken */));
var typeParameters = candidateSignature.typeParameters;
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
suffixDisplayParts.push(ts.punctuationPart(27 /* GreaterThanToken */));
var parameterParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation);
});
ts.addRange(suffixDisplayParts, parameterParts);
}
else {
var typeParameterParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation);
});
ts.addRange(prefixDisplayParts, typeParameterParts);
prefixDisplayParts.push(ts.punctuationPart(17 /* OpenParenToken */));
var parameters = candidateSignature.parameters;
signatureHelpParameters = parameters.length > 0 ? ts.map(parameters, createSignatureHelpParameterForParameter) : emptyArray;
suffixDisplayParts.push(ts.punctuationPart(18 /* CloseParenToken */));
}
var returnTypeParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation);
});
ts.addRange(suffixDisplayParts, returnTypeParts);
return {
isVariadic: candidateSignature.hasRestParameter,
prefixDisplayParts: prefixDisplayParts,
suffixDisplayParts: suffixDisplayParts,
separatorDisplayParts: [ts.punctuationPart(24 /* CommaToken */), ts.spacePart()],
parameters: signatureHelpParameters,
documentation: candidateSignature.getDocumentationComment()
};
});
var argumentIndex = argumentListInfo.argumentIndex;
// argumentCount is the *apparent* number of arguments.
var argumentCount = argumentListInfo.argumentCount;
var selectedItemIndex = candidates.indexOf(bestSignature);
if (selectedItemIndex < 0) {
selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount);
}
ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex);
return {
items: items,
applicableSpan: applicableSpan,
selectedItemIndex: selectedItemIndex,
argumentIndex: argumentIndex,
argumentCount: argumentCount
};
function createSignatureHelpParameterForParameter(parameter) {
var displayParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation);
});
return {
name: parameter.name,
documentation: parameter.getDocumentationComment(),
displayParts: displayParts,
isOptional: typeChecker.isOptionalParameter(parameter.valueDeclaration)
};
}
function createSignatureHelpParameterForTypeParameter(typeParameter) {
var displayParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation);
});
return {
name: typeParameter.symbol.name,
documentation: emptyArray,
displayParts: displayParts,
isOptional: false
};
}
}
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
getSignatureHelpItems
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createJavaScriptSignatureHelpItems(argumentInfo) {
if (argumentInfo.invocation.kind !== 168 /* CallExpression */) {
return undefined;
}
// See if we can find some symbol with the call expression name that has call signatures.
var callExpression = argumentInfo.invocation;
var expression = callExpression.expression;
var name = expression.kind === 69 /* Identifier */
? expression
: expression.kind === 166 /* PropertyAccessExpression */
? expression.name
: undefined;
if (!name || !name.text) {
return undefined;
}
var typeChecker = program.getTypeChecker();
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile_1 = _a[_i];
var nameToDeclarations = sourceFile_1.getNamedDeclarations();
var declarations = ts.getProperty(nameToDeclarations, name.text);
if (declarations) {
for (var _b = 0, declarations_7 = declarations; _b < declarations_7.length; _b++) {
var declaration = declarations_7[_b];
var symbol = declaration.symbol;
if (symbol) {
var type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
if (type) {
var callSignatures = type.getCallSignatures();
if (callSignatures && callSignatures.length) {
return createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo);
}
}
}
}
}
}
}
|
Like removeComputedProperties, but retains the properties with well known symbol names
|
createJavaScriptSignatureHelpItems
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getArgumentIndex(argumentsList, node) {
// The list we got back can include commas. In the presence of errors it may
// also just have nodes without commas. For example "Foo(a b c)" will have 3
// args without commas. We want to find what index we're at. So we count
// forward until we hit ourselves, only incrementing the index if it isn't a
// comma.
//
// Note: the subtlety around trailing commas (in getArgumentCount) does not apply
// here. That's because we're only walking forward until we hit the node we're
// on. In that case, even if we're after the trailing comma, we'll still see
// that trailing comma in the list, and we'll have generated the appropriate
// arg index.
var argumentIndex = 0;
var listChildren = argumentsList.getChildren();
for (var _i = 0, listChildren_1 = listChildren; _i < listChildren_1.length; _i++) {
var child = listChildren_1[_i];
if (child === node) {
break;
}
if (child.kind !== 24 /* CommaToken */) {
argumentIndex++;
}
}
return argumentIndex;
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getArgumentIndex
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getArgumentCount(argumentsList) {
// The argument count for a list is normally the number of non-comma children it has.
// For example, if you have "Foo(a,b)" then there will be three children of the arg
// list 'a' '<comma>' 'b'. So, in this case the arg count will be 2. However, there
// is a small subtlety. If you have "Foo(a,)", then the child list will just have
// 'a' '<comma>'. So, in the case where the last child is a comma, we increase the
// arg count by one to compensate.
//
// Note: this subtlety only applies to the last comma. If you had "Foo(a,," then
// we'll have: 'a' '<comma>' '<missing>'
// That will give us 2 non-commas. We then add one for the last comma, givin us an
// arg count of 3.
var listChildren = argumentsList.getChildren();
var argumentCount = ts.countWhere(listChildren, function (arg) { return arg.kind !== 24 /* CommaToken */; });
if (listChildren.length > 0 && ts.lastOrUndefined(listChildren).kind === 24 /* CommaToken */) {
argumentCount++;
}
return argumentCount;
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getArgumentCount
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getArgumentIndexForTemplatePiece(spanIndex, node) {
// Because the TemplateStringsArray is the first argument, we have to offset each substitution expression by 1.
// There are three cases we can encounter:
// 1. We are precisely in the template literal (argIndex = 0).
// 2. We are in or to the right of the substitution expression (argIndex = spanIndex + 1).
// 3. We are directly to the right of the template literal, but because we look for the token on the left,
// not enough to put us in the substitution expression; we should consider ourselves part of
// the *next* span's expression by offsetting the index (argIndex = (spanIndex + 1) + 1).
//
// Example: f `# abcd $#{# 1 + 1# }# efghi ${ #"#hello"# } # `
// ^ ^ ^ ^ ^ ^ ^ ^ ^
// Case: 1 1 3 2 1 3 2 2 1
ts.Debug.assert(position >= node.getStart(), "Assumed 'position' could not occur before node.");
if (ts.isTemplateLiteralKind(node.kind)) {
if (ts.isInsideTemplateLiteral(node, position)) {
return 0;
}
return spanIndex + 2;
}
return spanIndex + 1;
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getArgumentIndexForTemplatePiece
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getArgumentListInfoForTemplate(tagExpression, argumentIndex) {
// argumentCount is either 1 or (numSpans + 1) to account for the template strings array argument.
var argumentCount = tagExpression.template.kind === 11 /* NoSubstitutionTemplateLiteral */
? 1
: tagExpression.template.templateSpans.length + 1;
ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex);
return {
kind: 2 /* TaggedTemplateArguments */,
invocation: tagExpression,
argumentsSpan: getApplicableSpanForTaggedTemplate(tagExpression),
argumentIndex: argumentIndex,
argumentCount: argumentCount
};
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getArgumentListInfoForTemplate
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getApplicableSpanForArguments(argumentsList) {
// We use full start and skip trivia on the end because we want to include trivia on
// both sides. For example,
//
// foo( /*comment */ a, b, c /*comment*/ )
// | |
//
// The applicable span is from the first bar to the second bar (inclusive,
// but not including parentheses)
var applicableSpanStart = argumentsList.getFullStart();
var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentsList.getEnd(), /*stopAfterLineBreak*/ false);
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getApplicableSpanForArguments
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getApplicableSpanForTaggedTemplate(taggedTemplate) {
var template = taggedTemplate.template;
var applicableSpanStart = template.getStart();
var applicableSpanEnd = template.getEnd();
// We need to adjust the end position for the case where the template does not have a tail.
// Otherwise, we will not show signature help past the expression.
// For example,
//
// ` ${ 1 + 1 foo(10)
// | |
//
// This is because a Missing node has no width. However, what we actually want is to include trivia
// leading up to the next token in case the user is about to type in a TemplateMiddle or TemplateTail.
if (template.kind === 183 /* TemplateExpression */) {
var lastSpan = ts.lastOrUndefined(template.templateSpans);
if (lastSpan.literal.getFullWidth() === 0) {
applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, /*stopAfterLineBreak*/ false);
}
}
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getApplicableSpanForTaggedTemplate
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getContainingArgumentInfo(node) {
for (var n = node; n.kind !== 248 /* SourceFile */; n = n.parent) {
if (ts.isFunctionBlock(n)) {
return undefined;
}
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
if (n.pos < n.parent.pos || n.end > n.parent.end) {
ts.Debug.fail("Node of kind " + n.kind + " is not a subspan of its parent of kind " + n.parent.kind);
}
var argumentInfo_1 = getImmediatelyContainingArgumentInfo(n);
if (argumentInfo_1) {
return argumentInfo_1;
}
}
return undefined;
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getContainingArgumentInfo
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getChildListThatStartsWithOpenerToken(parent, openerToken, sourceFile) {
var children = parent.getChildren(sourceFile);
var indexOfOpenerToken = children.indexOf(openerToken);
ts.Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1);
return children[indexOfOpenerToken + 1];
}
|
Returns relevant information for the argument list and the current argument if we are
in the argument of an invocation; returns undefined otherwise.
|
getChildListThatStartsWithOpenerToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createSignatureHelpItems(candidates, bestSignature, argumentListInfo) {
var applicableSpan = argumentListInfo.argumentsSpan;
var isTypeParameterList = argumentListInfo.kind === 0 /* TypeArguments */;
var invocation = argumentListInfo.invocation;
var callTarget = ts.getInvokedExpression(invocation);
var callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget);
var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeChecker, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined);
var items = ts.map(candidates, function (candidateSignature) {
var signatureHelpParameters;
var prefixDisplayParts = [];
var suffixDisplayParts = [];
if (callTargetDisplayParts) {
ts.addRange(prefixDisplayParts, callTargetDisplayParts);
}
if (isTypeParameterList) {
prefixDisplayParts.push(ts.punctuationPart(25 /* LessThanToken */));
var typeParameters = candidateSignature.typeParameters;
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
suffixDisplayParts.push(ts.punctuationPart(27 /* GreaterThanToken */));
var parameterParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation);
});
ts.addRange(suffixDisplayParts, parameterParts);
}
else {
var typeParameterParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation);
});
ts.addRange(prefixDisplayParts, typeParameterParts);
prefixDisplayParts.push(ts.punctuationPart(17 /* OpenParenToken */));
var parameters = candidateSignature.parameters;
signatureHelpParameters = parameters.length > 0 ? ts.map(parameters, createSignatureHelpParameterForParameter) : emptyArray;
suffixDisplayParts.push(ts.punctuationPart(18 /* CloseParenToken */));
}
var returnTypeParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation);
});
ts.addRange(suffixDisplayParts, returnTypeParts);
return {
isVariadic: candidateSignature.hasRestParameter,
prefixDisplayParts: prefixDisplayParts,
suffixDisplayParts: suffixDisplayParts,
separatorDisplayParts: [ts.punctuationPart(24 /* CommaToken */), ts.spacePart()],
parameters: signatureHelpParameters,
documentation: candidateSignature.getDocumentationComment()
};
});
var argumentIndex = argumentListInfo.argumentIndex;
// argumentCount is the *apparent* number of arguments.
var argumentCount = argumentListInfo.argumentCount;
var selectedItemIndex = candidates.indexOf(bestSignature);
if (selectedItemIndex < 0) {
selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount);
}
ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex);
return {
items: items,
applicableSpan: applicableSpan,
selectedItemIndex: selectedItemIndex,
argumentIndex: argumentIndex,
argumentCount: argumentCount
};
function createSignatureHelpParameterForParameter(parameter) {
var displayParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation);
});
return {
name: parameter.name,
documentation: parameter.getDocumentationComment(),
displayParts: displayParts,
isOptional: typeChecker.isOptionalParameter(parameter.valueDeclaration)
};
}
function createSignatureHelpParameterForTypeParameter(typeParameter) {
var displayParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation);
});
return {
name: typeParameter.symbol.name,
documentation: emptyArray,
displayParts: displayParts,
isOptional: false
};
}
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
createSignatureHelpItems
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createSignatureHelpParameterForParameter(parameter) {
var displayParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation);
});
return {
name: parameter.name,
documentation: parameter.getDocumentationComment(),
displayParts: displayParts,
isOptional: typeChecker.isOptionalParameter(parameter.valueDeclaration)
};
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
createSignatureHelpParameterForParameter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createSignatureHelpParameterForTypeParameter(typeParameter) {
var displayParts = ts.mapToDisplayParts(function (writer) {
return typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation);
});
return {
name: typeParameter.symbol.name,
documentation: emptyArray,
displayParts: displayParts,
isOptional: false
};
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
createSignatureHelpParameterForTypeParameter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getEndLinePosition(line, sourceFile) {
ts.Debug.assert(line >= 0);
var lineStarts = sourceFile.getLineStarts();
var lineIndex = line;
if (lineIndex + 1 === lineStarts.length) {
// last line - return EOF
return sourceFile.text.length - 1;
}
else {
// current line start
var start = lineStarts[lineIndex];
// take the start position of the next line -1 = it should be some line break
var pos = lineStarts[lineIndex + 1] - 1;
ts.Debug.assert(ts.isLineBreak(sourceFile.text.charCodeAt(pos)));
// walk backwards skipping line breaks, stop the the beginning of current line.
// i.e:
// <some text>
// $ <- end of line for this position should match the start position
while (start <= pos && ts.isLineBreak(sourceFile.text.charCodeAt(pos))) {
pos--;
}
return pos;
}
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
getEndLinePosition
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getLineStartPositionForPosition(position, sourceFile) {
var lineStarts = sourceFile.getLineStarts();
var line = sourceFile.getLineAndCharacterOfPosition(position).line;
return lineStarts[line];
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
getLineStartPositionForPosition
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function rangeContainsRange(r1, r2) {
return startEndContainsRange(r1.pos, r1.end, r2);
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
rangeContainsRange
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function startEndContainsRange(start, end, range) {
return start <= range.pos && end >= range.end;
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
startEndContainsRange
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function rangeContainsStartEnd(range, start, end) {
return range.pos <= start && range.end >= end;
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
rangeContainsStartEnd
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function rangeOverlapsWithStartEnd(r1, start, end) {
return startEndOverlapsWithStartEnd(r1.pos, r1.end, start, end);
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
rangeOverlapsWithStartEnd
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function startEndOverlapsWithStartEnd(start1, end1, start2, end2) {
var start = Math.max(start1, start2);
var end = Math.min(end1, end2);
return start < end;
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
startEndOverlapsWithStartEnd
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function positionBelongsToNode(candidate, position, sourceFile) {
return candidate.end > position || !isCompletedNode(candidate, sourceFile);
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
positionBelongsToNode
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isCompletedNode(n, sourceFile) {
if (ts.nodeIsMissing(n)) {
return false;
}
switch (n.kind) {
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
case 217 /* EnumDeclaration */:
case 165 /* ObjectLiteralExpression */:
case 161 /* ObjectBindingPattern */:
case 155 /* TypeLiteral */:
case 192 /* Block */:
case 219 /* ModuleBlock */:
case 220 /* CaseBlock */:
return nodeEndsWith(n, 16 /* CloseBraceToken */, sourceFile);
case 244 /* CatchClause */:
return isCompletedNode(n.block, sourceFile);
case 169 /* NewExpression */:
if (!n.arguments) {
return true;
}
// fall through
case 168 /* CallExpression */:
case 172 /* ParenthesizedExpression */:
case 160 /* ParenthesizedType */:
return nodeEndsWith(n, 18 /* CloseParenToken */, sourceFile);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
return isCompletedNode(n.type, sourceFile);
case 144 /* Constructor */:
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
case 213 /* FunctionDeclaration */:
case 173 /* FunctionExpression */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
case 148 /* ConstructSignature */:
case 147 /* CallSignature */:
case 174 /* ArrowFunction */:
if (n.body) {
return isCompletedNode(n.body, sourceFile);
}
if (n.type) {
return isCompletedNode(n.type, sourceFile);
}
// Even though type parameters can be unclosed, we can get away with
// having at least a closing paren.
return hasChildOfKind(n, 18 /* CloseParenToken */, sourceFile);
case 218 /* ModuleDeclaration */:
return n.body && isCompletedNode(n.body, sourceFile);
case 196 /* IfStatement */:
if (n.elseStatement) {
return isCompletedNode(n.elseStatement, sourceFile);
}
return isCompletedNode(n.thenStatement, sourceFile);
case 195 /* ExpressionStatement */:
return isCompletedNode(n.expression, sourceFile) ||
hasChildOfKind(n, 23 /* SemicolonToken */);
case 164 /* ArrayLiteralExpression */:
case 162 /* ArrayBindingPattern */:
case 167 /* ElementAccessExpression */:
case 136 /* ComputedPropertyName */:
case 157 /* TupleType */:
return nodeEndsWith(n, 20 /* CloseBracketToken */, sourceFile);
case 149 /* IndexSignature */:
if (n.type) {
return isCompletedNode(n.type, sourceFile);
}
return hasChildOfKind(n, 20 /* CloseBracketToken */, sourceFile);
case 241 /* CaseClause */:
case 242 /* DefaultClause */:
// there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed
return false;
case 199 /* ForStatement */:
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
case 198 /* WhileStatement */:
return isCompletedNode(n.statement, sourceFile);
case 197 /* DoStatement */:
// rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
var hasWhileKeyword = findChildOfKind(n, 104 /* WhileKeyword */, sourceFile);
if (hasWhileKeyword) {
return nodeEndsWith(n, 18 /* CloseParenToken */, sourceFile);
}
return isCompletedNode(n.statement, sourceFile);
case 154 /* TypeQuery */:
return isCompletedNode(n.exprName, sourceFile);
case 176 /* TypeOfExpression */:
case 175 /* DeleteExpression */:
case 177 /* VoidExpression */:
case 184 /* YieldExpression */:
case 185 /* SpreadElementExpression */:
var unaryWordExpression = n;
return isCompletedNode(unaryWordExpression.expression, sourceFile);
case 170 /* TaggedTemplateExpression */:
return isCompletedNode(n.template, sourceFile);
case 183 /* TemplateExpression */:
var lastSpan = ts.lastOrUndefined(n.templateSpans);
return isCompletedNode(lastSpan, sourceFile);
case 190 /* TemplateSpan */:
return ts.nodeIsPresent(n.literal);
case 179 /* PrefixUnaryExpression */:
return isCompletedNode(n.operand, sourceFile);
case 181 /* BinaryExpression */:
return isCompletedNode(n.right, sourceFile);
case 182 /* ConditionalExpression */:
return isCompletedNode(n.whenFalse, sourceFile);
default:
return true;
}
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
isCompletedNode
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function findListItemInfo(node) {
var list = findContainingList(node);
// It is possible at this point for syntaxList to be undefined, either if
// node.parent had no list child, or if none of its list children contained
// the span of node. If this happens, return undefined. The caller should
// handle this case.
if (!list) {
return undefined;
}
var children = list.getChildren();
var listItemIndex = ts.indexOf(children, node);
return {
listItemIndex: listItemIndex,
list: list
};
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
findListItemInfo
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function hasChildOfKind(n, kind, sourceFile) {
return !!findChildOfKind(n, kind, sourceFile);
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
hasChildOfKind
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function findChildOfKind(n, kind, sourceFile) {
return ts.forEach(n.getChildren(sourceFile), function (c) { return c.kind === kind && c; });
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
findChildOfKind
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function findContainingList(node) {
// The node might be a list element (nonsynthetic) or a comma (synthetic). Either way, it will
// be parented by the container of the SyntaxList, not the SyntaxList itself.
// In order to find the list item index, we first need to locate SyntaxList itself and then search
// for the position of the relevant node (or comma).
var syntaxList = ts.forEach(node.parent.getChildren(), function (c) {
// find syntax list that covers the span of the node
if (c.kind === 271 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) {
return c;
}
});
// Either we didn't find an appropriate list, or the list must contain us.
ts.Debug.assert(!syntaxList || ts.contains(syntaxList.getChildren(), node));
return syntaxList;
}
|
The selectedItemIndex could be negative for several reasons.
1. There are too many arguments for all of the overloads
2. None of the overloads were type compatible
The solution here is to try to pick the best overload by picking
either the first one that has an appropriate number of parameters,
or the one with the most parameters.
|
findContainingList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTouchingToken(sourceFile, position, includeItemAtEndPosition) {
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, includeItemAtEndPosition);
}
|
Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true
|
getTouchingToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTokenAtPosition(sourceFile, position) {
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ true, /*includeItemAtEndPosition*/ undefined);
}
|
Returns a token if position is in [start-of-leading-trivia, end)
|
getTokenAtPosition
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function findNextToken(previousToken, parent) {
return find(parent);
function find(n) {
if (isToken(n) && n.pos === previousToken.end) {
// this is token that starts at the end of previous token - return it
return n;
}
var children = n.getChildren();
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
var child = children_1[_i];
var shouldDiveInChildNode =
// previous token is enclosed somewhere in the child
(child.pos <= previousToken.pos && child.end > previousToken.end) ||
// previous token ends exactly at the beginning of child
(child.pos === previousToken.end);
if (shouldDiveInChildNode && nodeHasTokens(child)) {
return find(child);
}
}
return undefined;
}
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
findNextToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function find(n) {
if (isToken(n) && n.pos === previousToken.end) {
// this is token that starts at the end of previous token - return it
return n;
}
var children = n.getChildren();
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
var child = children_1[_i];
var shouldDiveInChildNode =
// previous token is enclosed somewhere in the child
(child.pos <= previousToken.pos && child.end > previousToken.end) ||
// previous token ends exactly at the beginning of child
(child.pos === previousToken.end);
if (shouldDiveInChildNode && nodeHasTokens(child)) {
return find(child);
}
}
return undefined;
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
find
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function findPrecedingToken(position, sourceFile, startNode) {
return find(startNode || sourceFile);
function findRightmostToken(n) {
if (isToken(n) || n.kind === 236 /* JsxText */) {
return n;
}
var children = n.getChildren();
var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length);
return candidate && findRightmostToken(candidate);
}
function find(n) {
if (isToken(n) || n.kind === 236 /* JsxText */) {
return n;
}
var children = n.getChildren();
for (var i = 0, len = children.length; i < len; i++) {
var child = children[i];
// condition 'position < child.end' checks if child node end after the position
// in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc'
// aaaa___bbbb___$__ccc
// after we found child node with end after the position we check if start of the node is after the position.
// if yes - then position is in the trivia and we need to look into the previous child to find the token in question.
// if no - position is in the node itself so we should recurse in it.
// NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia).
// if this is the case - then we should assume that token in question is located in previous child.
if (position < child.end && (nodeHasTokens(child) || child.kind === 236 /* JsxText */)) {
var start = child.getStart(sourceFile);
var lookInPreviousChild = (start >= position) ||
(child.kind === 236 /* JsxText */ && start === child.end); // whitespace only JsxText
if (lookInPreviousChild) {
// actual start of the node is past the position - previous token should be at the end of previous child
var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i);
return candidate && findRightmostToken(candidate);
}
else {
// candidate should be in this node
return find(child);
}
}
}
ts.Debug.assert(startNode !== undefined || n.kind === 248 /* SourceFile */);
// Here we know that none of child token nodes embrace the position,
// the only known case is when position is at the end of the file.
// Try to find the rightmost token in the file without filtering.
// Namely we are skipping the check: 'position < node.end'
if (children.length) {
var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length);
return candidate && findRightmostToken(candidate);
}
}
/// finds last node that is considered as candidate for search (isCandidate(node) === true) starting from 'exclusiveStartPosition'
function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) {
for (var i = exclusiveStartPosition - 1; i >= 0; --i) {
if (nodeHasTokens(children[i])) {
return children[i];
}
}
}
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
findPrecedingToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function findRightmostToken(n) {
if (isToken(n) || n.kind === 236 /* JsxText */) {
return n;
}
var children = n.getChildren();
var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length);
return candidate && findRightmostToken(candidate);
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
findRightmostToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function find(n) {
if (isToken(n) || n.kind === 236 /* JsxText */) {
return n;
}
var children = n.getChildren();
for (var i = 0, len = children.length; i < len; i++) {
var child = children[i];
// condition 'position < child.end' checks if child node end after the position
// in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc'
// aaaa___bbbb___$__ccc
// after we found child node with end after the position we check if start of the node is after the position.
// if yes - then position is in the trivia and we need to look into the previous child to find the token in question.
// if no - position is in the node itself so we should recurse in it.
// NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia).
// if this is the case - then we should assume that token in question is located in previous child.
if (position < child.end && (nodeHasTokens(child) || child.kind === 236 /* JsxText */)) {
var start = child.getStart(sourceFile);
var lookInPreviousChild = (start >= position) ||
(child.kind === 236 /* JsxText */ && start === child.end); // whitespace only JsxText
if (lookInPreviousChild) {
// actual start of the node is past the position - previous token should be at the end of previous child
var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i);
return candidate && findRightmostToken(candidate);
}
else {
// candidate should be in this node
return find(child);
}
}
}
ts.Debug.assert(startNode !== undefined || n.kind === 248 /* SourceFile */);
// Here we know that none of child token nodes embrace the position,
// the only known case is when position is at the end of the file.
// Try to find the rightmost token in the file without filtering.
// Namely we are skipping the check: 'position < node.end'
if (children.length) {
var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length);
return candidate && findRightmostToken(candidate);
}
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
find
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isInString(sourceFile, position) {
var token = getTokenAtPosition(sourceFile, position);
return token && token.kind === 9 /* StringLiteral */ && position > token.getStart();
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
isInString
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isInComment(sourceFile, position) {
return isInCommentHelper(sourceFile, position, /*predicate*/ undefined);
}
|
The token on the left of the position is the token that strictly includes the position
or sits to the left of the cursor if it is on a boundary. For example
fo|o -> will return foo
foo <comment> |bar -> will return foo
|
isInComment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isInCommentHelper(sourceFile, position, predicate) {
var token = getTokenAtPosition(sourceFile, position);
if (token && position <= token.getStart()) {
var commentRanges = ts.getLeadingCommentRanges(sourceFile.text, token.pos);
// The end marker of a single-line comment does not include the newline character.
// In the following case, we are inside a comment (^ denotes the cursor position):
//
// // asdf ^\n
//
// But for multi-line comments, we don't want to be inside the comment in the following case:
//
// /* asdf */^
//
// Internally, we represent the end of the comment at the newline and closing '/', respectively.
return predicate ?
ts.forEach(commentRanges, function (c) { return c.pos < position &&
(c.kind == 2 /* SingleLineCommentTrivia */ ? position <= c.end : position < c.end) &&
predicate(c); }) :
ts.forEach(commentRanges, function (c) { return c.pos < position &&
(c.kind == 2 /* SingleLineCommentTrivia */ ? position <= c.end : position < c.end); });
}
return false;
}
|
Returns true if the cursor at position in sourceFile is within a comment that additionally
satisfies predicate, and false otherwise.
|
isInCommentHelper
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function hasDocComment(sourceFile, position) {
var token = getTokenAtPosition(sourceFile, position);
// First, we have to see if this position actually landed in a comment.
var commentRanges = ts.getLeadingCommentRanges(sourceFile.text, token.pos);
return ts.forEach(commentRanges, jsDocPrefix);
function jsDocPrefix(c) {
var text = sourceFile.text;
return text.length >= c.pos + 3 && text[c.pos] === '/' && text[c.pos + 1] === '*' && text[c.pos + 2] === '*';
}
}
|
Returns true if the cursor at position in sourceFile is within a comment that additionally
satisfies predicate, and false otherwise.
|
hasDocComment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function jsDocPrefix(c) {
var text = sourceFile.text;
return text.length >= c.pos + 3 && text[c.pos] === '/' && text[c.pos + 1] === '*' && text[c.pos + 2] === '*';
}
|
Returns true if the cursor at position in sourceFile is within a comment that additionally
satisfies predicate, and false otherwise.
|
jsDocPrefix
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function nodeHasTokens(n) {
// If we have a token or node that has a non-zero width, it must have tokens.
// Note, that getWidth() does not take trivia into account.
return n.getWidth() !== 0;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
nodeHasTokens
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getNodeModifiers(node) {
var flags = ts.getCombinedNodeFlags(node);
var result = [];
if (flags & 16 /* Private */)
result.push(ts.ScriptElementKindModifier.privateMemberModifier);
if (flags & 32 /* Protected */)
result.push(ts.ScriptElementKindModifier.protectedMemberModifier);
if (flags & 8 /* Public */)
result.push(ts.ScriptElementKindModifier.publicMemberModifier);
if (flags & 64 /* Static */)
result.push(ts.ScriptElementKindModifier.staticModifier);
if (flags & 128 /* Abstract */)
result.push(ts.ScriptElementKindModifier.abstractModifier);
if (flags & 2 /* Export */)
result.push(ts.ScriptElementKindModifier.exportedModifier);
if (ts.isInAmbientContext(node))
result.push(ts.ScriptElementKindModifier.ambientModifier);
return result.length > 0 ? result.join(',') : ts.ScriptElementKindModifier.none;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
getNodeModifiers
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTypeArgumentOrTypeParameterList(node) {
if (node.kind === 151 /* TypeReference */ || node.kind === 168 /* CallExpression */) {
return node.typeArguments;
}
if (ts.isFunctionLike(node) || node.kind === 214 /* ClassDeclaration */ || node.kind === 215 /* InterfaceDeclaration */) {
return node.typeParameters;
}
return undefined;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
getTypeArgumentOrTypeParameterList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isToken(n) {
return n.kind >= 0 /* FirstToken */ && n.kind <= 134 /* LastToken */;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isWord(kind) {
return kind === 69 /* Identifier */ || ts.isKeyword(kind);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isWord
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isPropertyName(kind) {
return kind === 9 /* StringLiteral */ || kind === 8 /* NumericLiteral */ || isWord(kind);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isPropertyName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isComment(kind) {
return kind === 2 /* SingleLineCommentTrivia */ || kind === 3 /* MultiLineCommentTrivia */;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isComment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isStringOrRegularExpressionOrTemplateLiteral(kind) {
if (kind === 9 /* StringLiteral */
|| kind === 10 /* RegularExpressionLiteral */
|| ts.isTemplateLiteralKind(kind)) {
return true;
}
return false;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isStringOrRegularExpressionOrTemplateLiteral
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isPunctuation(kind) {
return 15 /* FirstPunctuation */ <= kind && kind <= 68 /* LastPunctuation */;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isPunctuation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isInsideTemplateLiteral(node, position) {
return ts.isTemplateLiteralKind(node.kind)
&& (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd());
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isInsideTemplateLiteral
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isAccessibilityModifier(kind) {
switch (kind) {
case 112 /* PublicKeyword */:
case 110 /* PrivateKeyword */:
case 111 /* ProtectedKeyword */:
return true;
}
return false;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isAccessibilityModifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function compareDataObjects(dst, src) {
for (var e in dst) {
if (typeof dst[e] === "object") {
if (!compareDataObjects(dst[e], src[e])) {
return false;
}
}
else if (typeof dst[e] !== "function") {
if (dst[e] !== src[e]) {
return false;
}
}
}
return true;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
compareDataObjects
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isFirstDeclarationOfSymbolParameter(symbol) {
return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 138 /* Parameter */;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
isFirstDeclarationOfSymbolParameter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getDisplayPartWriter() {
var displayParts;
var lineStart;
var indent;
resetWriter();
return {
displayParts: function () { return displayParts; },
writeKeyword: function (text) { return writeKind(text, ts.SymbolDisplayPartKind.keyword); },
writeOperator: function (text) { return writeKind(text, ts.SymbolDisplayPartKind.operator); },
writePunctuation: function (text) { return writeKind(text, ts.SymbolDisplayPartKind.punctuation); },
writeSpace: function (text) { return writeKind(text, ts.SymbolDisplayPartKind.space); },
writeStringLiteral: function (text) { return writeKind(text, ts.SymbolDisplayPartKind.stringLiteral); },
writeParameter: function (text) { return writeKind(text, ts.SymbolDisplayPartKind.parameterName); },
writeSymbol: writeSymbol,
writeLine: writeLine,
increaseIndent: function () { indent++; },
decreaseIndent: function () { indent--; },
clear: resetWriter,
trackSymbol: function () { },
reportInaccessibleThisError: function () { }
};
function writeIndent() {
if (lineStart) {
var indentString = ts.getIndentString(indent);
if (indentString) {
displayParts.push(displayPart(indentString, ts.SymbolDisplayPartKind.space));
}
lineStart = false;
}
}
function writeKind(text, kind) {
writeIndent();
displayParts.push(displayPart(text, kind));
}
function writeSymbol(text, symbol) {
writeIndent();
displayParts.push(symbolPart(text, symbol));
}
function writeLine() {
displayParts.push(lineBreakPart());
lineStart = true;
}
function resetWriter() {
displayParts = [];
lineStart = true;
indent = 0;
}
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
getDisplayPartWriter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeIndent() {
if (lineStart) {
var indentString = ts.getIndentString(indent);
if (indentString) {
displayParts.push(displayPart(indentString, ts.SymbolDisplayPartKind.space));
}
lineStart = false;
}
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
writeIndent
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeKind(text, kind) {
writeIndent();
displayParts.push(displayPart(text, kind));
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
writeKind
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeSymbol(text, symbol) {
writeIndent();
displayParts.push(symbolPart(text, symbol));
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
writeSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeLine() {
displayParts.push(lineBreakPart());
lineStart = true;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
writeLine
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function resetWriter() {
displayParts = [];
lineStart = true;
indent = 0;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
resetWriter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function symbolPart(text, symbol) {
return displayPart(text, displayPartKind(symbol), symbol);
function displayPartKind(symbol) {
var flags = symbol.flags;
if (flags & 3 /* Variable */) {
return isFirstDeclarationOfSymbolParameter(symbol) ? ts.SymbolDisplayPartKind.parameterName : ts.SymbolDisplayPartKind.localName;
}
else if (flags & 4 /* Property */) {
return ts.SymbolDisplayPartKind.propertyName;
}
else if (flags & 32768 /* GetAccessor */) {
return ts.SymbolDisplayPartKind.propertyName;
}
else if (flags & 65536 /* SetAccessor */) {
return ts.SymbolDisplayPartKind.propertyName;
}
else if (flags & 8 /* EnumMember */) {
return ts.SymbolDisplayPartKind.enumMemberName;
}
else if (flags & 16 /* Function */) {
return ts.SymbolDisplayPartKind.functionName;
}
else if (flags & 32 /* Class */) {
return ts.SymbolDisplayPartKind.className;
}
else if (flags & 64 /* Interface */) {
return ts.SymbolDisplayPartKind.interfaceName;
}
else if (flags & 384 /* Enum */) {
return ts.SymbolDisplayPartKind.enumName;
}
else if (flags & 1536 /* Module */) {
return ts.SymbolDisplayPartKind.moduleName;
}
else if (flags & 8192 /* Method */) {
return ts.SymbolDisplayPartKind.methodName;
}
else if (flags & 262144 /* TypeParameter */) {
return ts.SymbolDisplayPartKind.typeParameterName;
}
else if (flags & 524288 /* TypeAlias */) {
return ts.SymbolDisplayPartKind.aliasName;
}
else if (flags & 8388608 /* Alias */) {
return ts.SymbolDisplayPartKind.aliasName;
}
return ts.SymbolDisplayPartKind.text;
}
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
symbolPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function displayPartKind(symbol) {
var flags = symbol.flags;
if (flags & 3 /* Variable */) {
return isFirstDeclarationOfSymbolParameter(symbol) ? ts.SymbolDisplayPartKind.parameterName : ts.SymbolDisplayPartKind.localName;
}
else if (flags & 4 /* Property */) {
return ts.SymbolDisplayPartKind.propertyName;
}
else if (flags & 32768 /* GetAccessor */) {
return ts.SymbolDisplayPartKind.propertyName;
}
else if (flags & 65536 /* SetAccessor */) {
return ts.SymbolDisplayPartKind.propertyName;
}
else if (flags & 8 /* EnumMember */) {
return ts.SymbolDisplayPartKind.enumMemberName;
}
else if (flags & 16 /* Function */) {
return ts.SymbolDisplayPartKind.functionName;
}
else if (flags & 32 /* Class */) {
return ts.SymbolDisplayPartKind.className;
}
else if (flags & 64 /* Interface */) {
return ts.SymbolDisplayPartKind.interfaceName;
}
else if (flags & 384 /* Enum */) {
return ts.SymbolDisplayPartKind.enumName;
}
else if (flags & 1536 /* Module */) {
return ts.SymbolDisplayPartKind.moduleName;
}
else if (flags & 8192 /* Method */) {
return ts.SymbolDisplayPartKind.methodName;
}
else if (flags & 262144 /* TypeParameter */) {
return ts.SymbolDisplayPartKind.typeParameterName;
}
else if (flags & 524288 /* TypeAlias */) {
return ts.SymbolDisplayPartKind.aliasName;
}
else if (flags & 8388608 /* Alias */) {
return ts.SymbolDisplayPartKind.aliasName;
}
return ts.SymbolDisplayPartKind.text;
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
displayPartKind
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function displayPart(text, kind, symbol) {
return {
text: text,
kind: ts.SymbolDisplayPartKind[kind]
};
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
displayPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function spacePart() {
return displayPart(" ", ts.SymbolDisplayPartKind.space);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
spacePart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function keywordPart(kind) {
return displayPart(ts.tokenToString(kind), ts.SymbolDisplayPartKind.keyword);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
keywordPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function punctuationPart(kind) {
return displayPart(ts.tokenToString(kind), ts.SymbolDisplayPartKind.punctuation);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
punctuationPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function operatorPart(kind) {
return displayPart(ts.tokenToString(kind), ts.SymbolDisplayPartKind.operator);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
operatorPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function textOrKeywordPart(text) {
var kind = ts.stringToToken(text);
return kind === undefined
? textPart(text)
: keywordPart(kind);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
textOrKeywordPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function textPart(text) {
return displayPart(text, ts.SymbolDisplayPartKind.text);
}
|
Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
textPart
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getFormattingScanner(sourceFile, startPos, endPos) {
ts.Debug.assert(scanner === undefined);
scanner = sourceFile.languageVariant === 1 /* JSX */ ? jsxScanner : standardScanner;
scanner.setText(sourceFile.text);
scanner.setTextPos(startPos);
var wasNewLine = true;
var leadingTrivia;
var trailingTrivia;
var savedPos;
var lastScanAction;
var lastTokenInfo;
return {
advance: advance,
readTokenInfo: readTokenInfo,
isOnToken: isOnToken,
lastTrailingTriviaWasNewLine: function () { return wasNewLine; },
close: function () {
ts.Debug.assert(scanner !== undefined);
lastTokenInfo = undefined;
scanner.setText(undefined);
scanner = undefined;
}
};
function advance() {
ts.Debug.assert(scanner !== undefined);
lastTokenInfo = undefined;
var isStarted = scanner.getStartPos() !== startPos;
if (isStarted) {
if (trailingTrivia) {
ts.Debug.assert(trailingTrivia.length !== 0);
wasNewLine = ts.lastOrUndefined(trailingTrivia).kind === 4 /* NewLineTrivia */;
}
else {
wasNewLine = false;
}
}
leadingTrivia = undefined;
trailingTrivia = undefined;
if (!isStarted) {
scanner.scan();
}
var t;
var pos = scanner.getStartPos();
// Read leading trivia and token
while (pos < endPos) {
var t_1 = scanner.getToken();
if (!ts.isTrivia(t_1)) {
break;
}
// consume leading trivia
scanner.scan();
var item = {
pos: pos,
end: scanner.getStartPos(),
kind: t_1
};
pos = scanner.getStartPos();
if (!leadingTrivia) {
leadingTrivia = [];
}
leadingTrivia.push(item);
}
savedPos = scanner.getStartPos();
}
function shouldRescanGreaterThanToken(node) {
if (node) {
switch (node.kind) {
case 29 /* GreaterThanEqualsToken */:
case 64 /* GreaterThanGreaterThanEqualsToken */:
case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
case 45 /* GreaterThanGreaterThanGreaterThanToken */:
case 44 /* GreaterThanGreaterThanToken */:
return true;
}
}
return false;
}
function shouldRescanJsxIdentifier(node) {
if (node.parent) {
switch (node.parent.kind) {
case 238 /* JsxAttribute */:
case 235 /* JsxOpeningElement */:
case 237 /* JsxClosingElement */:
case 234 /* JsxSelfClosingElement */:
return node.kind === 69 /* Identifier */;
}
}
return false;
}
function shouldRescanSlashToken(container) {
return container.kind === 10 /* RegularExpressionLiteral */;
}
function shouldRescanTemplateToken(container) {
return container.kind === 13 /* TemplateMiddle */ ||
container.kind === 14 /* TemplateTail */;
}
function startsWithSlashToken(t) {
return t === 39 /* SlashToken */ || t === 61 /* SlashEqualsToken */;
}
function readTokenInfo(n) {
ts.Debug.assert(scanner !== undefined);
if (!isOnToken()) {
// scanner is not on the token (either advance was not called yet or scanner is already past the end position)
return {
leadingTrivia: leadingTrivia,
trailingTrivia: undefined,
token: undefined
};
}
// normally scanner returns the smallest available token
// check the kind of context node to determine if scanner should have more greedy behavior and consume more text.
var expectedScanAction = shouldRescanGreaterThanToken(n)
? 1 /* RescanGreaterThanToken */
: shouldRescanSlashToken(n)
? 2 /* RescanSlashToken */
: shouldRescanTemplateToken(n)
? 3 /* RescanTemplateToken */
: shouldRescanJsxIdentifier(n)
? 4 /* RescanJsxIdentifier */
: 0 /* Scan */;
if (lastTokenInfo && expectedScanAction === lastScanAction) {
// readTokenInfo was called before with the same expected scan action.
// No need to re-scan text, return existing 'lastTokenInfo'
// it is ok to call fixTokenKind here since it does not affect
// what portion of text is consumed. In opposize rescanning can change it,
// i.e. for '>=' when originally scanner eats just one character
// and rescanning forces it to consume more.
return fixTokenKind(lastTokenInfo, n);
}
if (scanner.getStartPos() !== savedPos) {
ts.Debug.assert(lastTokenInfo !== undefined);
// readTokenInfo was called before but scan action differs - rescan text
scanner.setTextPos(savedPos);
scanner.scan();
}
var currentToken = scanner.getToken();
if (expectedScanAction === 1 /* RescanGreaterThanToken */ && currentToken === 27 /* GreaterThanToken */) {
currentToken = scanner.reScanGreaterToken();
ts.Debug.assert(n.kind === currentToken);
lastScanAction = 1 /* RescanGreaterThanToken */;
}
else if (expectedScanAction === 2 /* RescanSlashToken */ && startsWithSlashToken(currentToken)) {
currentToken = scanner.reScanSlashToken();
ts.Debug.assert(n.kind === currentToken);
lastScanAction = 2 /* RescanSlashToken */;
}
else if (expectedScanAction === 3 /* RescanTemplateToken */ && currentToken === 16 /* CloseBraceToken */) {
currentToken = scanner.reScanTemplateToken();
lastScanAction = 3 /* RescanTemplateToken */;
}
else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 69 /* Identifier */) {
currentToken = scanner.scanJsxIdentifier();
lastScanAction = 4 /* RescanJsxIdentifier */;
}
else {
lastScanAction = 0 /* Scan */;
}
var token = {
pos: scanner.getStartPos(),
end: scanner.getTextPos(),
kind: currentToken
};
// consume trailing trivia
if (trailingTrivia) {
trailingTrivia = undefined;
}
while (scanner.getStartPos() < endPos) {
currentToken = scanner.scan();
if (!ts.isTrivia(currentToken)) {
break;
}
var trivia = {
pos: scanner.getStartPos(),
end: scanner.getTextPos(),
kind: currentToken
};
if (!trailingTrivia) {
trailingTrivia = [];
}
trailingTrivia.push(trivia);
if (currentToken === 4 /* NewLineTrivia */) {
// move past new line
scanner.scan();
break;
}
}
lastTokenInfo = {
leadingTrivia: leadingTrivia,
trailingTrivia: trailingTrivia,
token: token
};
return fixTokenKind(lastTokenInfo, n);
}
function isOnToken() {
ts.Debug.assert(scanner !== undefined);
var current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken();
var startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos();
return startPos < endPos && current !== 1 /* EndOfFileToken */ && !ts.isTrivia(current);
}
// when containing node in the tree is token
// but its kind differs from the kind that was returned by the scanner,
// then kind needs to be fixed. This might happen in cases
// when parser interprets token differently, i.e keyword treated as identifier
function fixTokenKind(tokenInfo, container) {
if (ts.isToken(container) && tokenInfo.token.kind !== container.kind) {
tokenInfo.token.kind = container.kind;
}
return tokenInfo;
}
}
|
Scanner that is currently used for formatting
|
getFormattingScanner
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function advance() {
ts.Debug.assert(scanner !== undefined);
lastTokenInfo = undefined;
var isStarted = scanner.getStartPos() !== startPos;
if (isStarted) {
if (trailingTrivia) {
ts.Debug.assert(trailingTrivia.length !== 0);
wasNewLine = ts.lastOrUndefined(trailingTrivia).kind === 4 /* NewLineTrivia */;
}
else {
wasNewLine = false;
}
}
leadingTrivia = undefined;
trailingTrivia = undefined;
if (!isStarted) {
scanner.scan();
}
var t;
var pos = scanner.getStartPos();
// Read leading trivia and token
while (pos < endPos) {
var t_1 = scanner.getToken();
if (!ts.isTrivia(t_1)) {
break;
}
// consume leading trivia
scanner.scan();
var item = {
pos: pos,
end: scanner.getStartPos(),
kind: t_1
};
pos = scanner.getStartPos();
if (!leadingTrivia) {
leadingTrivia = [];
}
leadingTrivia.push(item);
}
savedPos = scanner.getStartPos();
}
|
Scanner that is currently used for formatting
|
advance
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function shouldRescanGreaterThanToken(node) {
if (node) {
switch (node.kind) {
case 29 /* GreaterThanEqualsToken */:
case 64 /* GreaterThanGreaterThanEqualsToken */:
case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
case 45 /* GreaterThanGreaterThanGreaterThanToken */:
case 44 /* GreaterThanGreaterThanToken */:
return true;
}
}
return false;
}
|
Scanner that is currently used for formatting
|
shouldRescanGreaterThanToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function shouldRescanJsxIdentifier(node) {
if (node.parent) {
switch (node.parent.kind) {
case 238 /* JsxAttribute */:
case 235 /* JsxOpeningElement */:
case 237 /* JsxClosingElement */:
case 234 /* JsxSelfClosingElement */:
return node.kind === 69 /* Identifier */;
}
}
return false;
}
|
Scanner that is currently used for formatting
|
shouldRescanJsxIdentifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function shouldRescanSlashToken(container) {
return container.kind === 10 /* RegularExpressionLiteral */;
}
|
Scanner that is currently used for formatting
|
shouldRescanSlashToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.