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

Function createCompletionEntry

test/fixtures/snapshot/typescript.js:132429–132567  ·  view source on GitHub ↗
(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag)

Source from the content-addressed store, hash-verified

132427 return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* ScriptElementKind.string */, kindModifiers: "" /* ScriptElementKindModifier.none */, sortText: Completions.SortText.LocationPriority };
132428 }
132429 function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag) {
132430 var _a, _b;
132431 var insertText;
132432 var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
132433 var data;
132434 var isSnippet;
132435 var source = getSourceFromOrigin(origin);
132436 var sourceDisplay;
132437 var hasAction;
132438 var labelDetails;
132439 var typeChecker = program.getTypeChecker();
132440 var insertQuestionDot = origin && originIsNullableMember(origin);
132441 var useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess;
132442 if (origin && originIsThisType(origin)) {
132443 insertText = needsConvertPropertyAccess
132444 ? "this".concat(insertQuestionDot ? "?." : "", "[").concat(quotePropertyName(sourceFile, preferences, name), "]")
132445 : "this".concat(insertQuestionDot ? "?." : ".").concat(name);
132446 }
132447 // We should only have needsConvertPropertyAccess if there's a property access to convert. But see #21790.
132448 // Somehow there was a global with a non-identifier name. Hopefully someone will complain about getting a "foo bar" global completion and provide a repro.
132449 else if ((useBraces || insertQuestionDot) && propertyAccessToConvert) {
132450 insertText = useBraces ? needsConvertPropertyAccess ? "[".concat(quotePropertyName(sourceFile, preferences, name), "]") : "[".concat(name, "]") : name;
132451 if (insertQuestionDot || propertyAccessToConvert.questionDotToken) {
132452 insertText = "?.".concat(insertText);
132453 }
132454 var dot = ts.findChildOfKind(propertyAccessToConvert, 24 /* SyntaxKind.DotToken */, sourceFile) ||
132455 ts.findChildOfKind(propertyAccessToConvert, 28 /* SyntaxKind.QuestionDotToken */, sourceFile);
132456 if (!dot) {
132457 return undefined;
132458 }
132459 // If the text after the '.' starts with this name, write over it. Else, add new text.
132460 var end = ts.startsWith(name, propertyAccessToConvert.name.text) ? propertyAccessToConvert.name.end : dot.end;
132461 replacementSpan = ts.createTextSpanFromBounds(dot.getStart(sourceFile), end);
132462 }
132463 if (isJsxInitializer) {
132464 if (insertText === undefined)
132465 insertText = name;
132466 insertText = "{".concat(insertText, "}");
132467 if (typeof isJsxInitializer !== "boolean") {
132468 replacementSpan = ts.createTextSpanFromNode(isJsxInitializer, sourceFile);
132469 }
132470 }
132471 if (origin && originIsPromise(origin) && propertyAccessToConvert) {
132472 if (insertText === undefined)
132473 insertText = name;
132474 var precedingToken = ts.findPrecedingToken(propertyAccessToConvert.pos, sourceFile);
132475 var awaitText = "";
132476 if (precedingToken && ts.positionIsASICandidate(precedingToken.end, precedingToken.parent, sourceFile)) {
132477 awaitText = ";";
132478 }
132479 awaitText += "(await ".concat(propertyAccessToConvert.expression.getText(), ")");
132480 insertText = needsConvertPropertyAccess ? "".concat(awaitText).concat(insertText) : "".concat(awaitText).concat(insertQuestionDot ? "?." : ".").concat(insertText);
132481 replacementSpan = ts.createTextSpanFromBounds(propertyAccessToConvert.getStart(sourceFile), propertyAccessToConvert.end);
132482 }
132483 if (originIsResolvedExport(origin)) {
132484 sourceDisplay = [ts.textPart(origin.moduleSpecifier)];
132485 if (importCompletionNode) {
132486 (_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);

Callers 1

Calls 15

getSourceFromOriginFunction · 0.85
originIsNullableMemberFunction · 0.85
originIsSymbolMemberFunction · 0.85
originIsThisTypeFunction · 0.85
quotePropertyNameFunction · 0.85
originIsPromiseFunction · 0.85
originIsResolvedExportFunction · 0.85
originIsExportFunction · 0.85

Tested by

no test coverage detected