MCPcopy Index your code
hub / github.com/nodejs/node / getCompletionsAtPosition

Function getCompletionsAtPosition

test/fixtures/snapshot/typescript.js:132129–132187  ·  view source on GitHub ↗
(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken, formatContext)

Source from the content-addressed store, hash-verified

132127 }
132128 }
132129 function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken, formatContext) {
132130 var _a;
132131 var previousToken = getRelevantTokens(position, sourceFile).previousToken;
132132 if (triggerCharacter && !ts.isInString(sourceFile, position, previousToken) && !isValidTrigger(sourceFile, triggerCharacter, previousToken, position)) {
132133 return undefined;
132134 }
132135 if (triggerCharacter === " ") {
132136 // `isValidTrigger` ensures we are at `import |`
132137 if (preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
132138 return { isGlobalCompletion: true, isMemberCompletion: false, isNewIdentifierLocation: true, isIncomplete: true, entries: [] };
132139 }
132140 return undefined;
132141 }
132142 // If the request is a continuation of an earlier `isIncomplete` response,
132143 // we can continue it from the cached previous response.
132144 var compilerOptions = program.getCompilerOptions();
132145 var incompleteCompletionsCache = preferences.allowIncompleteCompletions ? (_a = host.getIncompleteCompletionsCache) === null || _a === void 0 ? void 0 : _a.call(host) : undefined;
132146 if (incompleteCompletionsCache && completionKind === 3 /* CompletionTriggerKind.TriggerForIncompleteCompletions */ && previousToken && ts.isIdentifier(previousToken)) {
132147 var incompleteContinuation = continuePreviousIncompleteResponse(incompleteCompletionsCache, sourceFile, previousToken, program, host, preferences, cancellationToken);
132148 if (incompleteContinuation) {
132149 return incompleteContinuation;
132150 }
132151 }
132152 else {
132153 incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.clear();
132154 }
132155 var stringCompletions = Completions.StringCompletions.getStringLiteralCompletions(sourceFile, position, previousToken, compilerOptions, host, program, log, preferences);
132156 if (stringCompletions) {
132157 return stringCompletions;
132158 }
132159 if (previousToken && ts.isBreakOrContinueStatement(previousToken.parent)
132160 && (previousToken.kind === 81 /* SyntaxKind.BreakKeyword */ || previousToken.kind === 86 /* SyntaxKind.ContinueKeyword */ || previousToken.kind === 79 /* SyntaxKind.Identifier */)) {
132161 return getLabelCompletionAtPosition(previousToken.parent);
132162 }
132163 var completionData = getCompletionData(program, log, sourceFile, compilerOptions, position, preferences, /*detailsEntryId*/ undefined, host, formatContext, cancellationToken);
132164 if (!completionData) {
132165 return undefined;
132166 }
132167 switch (completionData.kind) {
132168 case 0 /* CompletionDataKind.Data */:
132169 var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position);
132170 if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
132171 incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
132172 }
132173 return response;
132174 case 1 /* CompletionDataKind.JsDocTagName */:
132175 // If the current position is a jsDoc tag name, only tag names should be provided for completion
132176 return jsdocCompletionInfo(ts.JsDoc.getJSDocTagNameCompletions());
132177 case 2 /* CompletionDataKind.JsDocTag */:
132178 // If the current position is a jsDoc tag, only tags should be provided for completion
132179 return jsdocCompletionInfo(ts.JsDoc.getJSDocTagCompletions());
132180 case 3 /* CompletionDataKind.JsDocParameterName */:
132181 return jsdocCompletionInfo(ts.JsDoc.getJSDocParameterNameCompletions(completionData.tag));
132182 case 4 /* CompletionDataKind.Keywords */:
132183 return specificKeywordCompletionInfo(completionData.keywordCompletions, completionData.isNewIdentifierLocation);
132184 default:
132185 return ts.Debug.assertNever(completionData);
132186 }

Callers

nothing calls this directly

Calls 13

getRelevantTokensFunction · 0.85
isValidTriggerFunction · 0.85
getCompletionDataFunction · 0.85
completionInfoFromDataFunction · 0.85
jsdocCompletionInfoFunction · 0.85
synchronizeHostDataFunction · 0.85
getValidSourceFileFunction · 0.85
clearMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected