Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const prev: ts.Node = ts.tslab.findPrecedingToken(pos, srcFile);
// Note: In contradiction to the docstring, findPrecedingToken may return prev with
// prev.end > pos (e.g. `members with surrounding` test case).
//
// Note: Be careful. node.pos != node.getStart().
// (e.g. `globals with prefix` test case)
if (prev && ts.isIdentifier(prev) && prev.end >= pos) {
return completionWithId(info, prev, srcFile);
}
const next: ts.Node = prev
? ts.tslab.findNextToken(prev, srcFile, srcFile)
: null;
if (
next &&
ts.isIdentifier(next) &&
next.getStart(srcFile) <= pos &&
pos <= next.end
) {
return completionWithId(info, next, srcFile);
}
let entries = info && info.entries ? info.entries.slice() : [];
entries.sort((a, b) => {
const ord = a.sortText.localeCompare(b.sortText);
return ord !== 0 ? ord : a.name.localeCompare(b.name);
});
const candidates = entries.map(e => e.name);
return {
start: pos - srcPrefix.length,
end: pos - srcPrefix.length,
candidates,
original: info
() => {
// ignore log messages
},
srcFile,
pos,
{},
undefined
);
const prev: ts.Node = ts.tslab.findPrecedingToken(pos, srcFile);
// Note: In contradiction to the docstring, findPrecedingToken may return prev with
// prev.end > pos (e.g. `members with surrounding` test case).
//
// Note: Be careful. node.pos != node.getStart().
// (e.g. `globals with prefix` test case)
if (prev && ts.isIdentifier(prev) && prev.end >= pos) {
return completionWithId(info, prev, srcFile);
}
const next: ts.Node = prev
? ts.tslab.findNextToken(prev, srcFile, srcFile)
: null;
if (
next &&
ts.isIdentifier(next) &&
next.getStart(srcFile) <= pos &&
pos <= next.end
) {
return completionWithId(info, next, srcFile);
}
let entries = info && info.entries ? info.entries.slice() : [];
entries.sort((a, b) => {
const ord = a.sortText.localeCompare(b.sortText);
stmt.declarationList.declarations.forEach(decl => {
if (!ts.isIdentifier(decl.name)) {
// This must not happen.
return;
}
if (!names.has(decl.name.escapedText)) {
return;
}
decls.push(decl);
});
stmt.declarationList.declarations = ts.createNodeArray(decls);