MCPcopy Create free account
hub / github.com/nodejs/node / collectAutoImports

Function collectAutoImports

test/fixtures/snapshot/typescript.js:134016–134117  ·  view source on GitHub ↗

Mutates `symbols`, `symbolToOriginInfoMap`, and `symbolToSortTextMap`

()

Source from the content-addressed store, hash-verified

134014 }
134015 /** Mutates `symbols`, `symbolToOriginInfoMap`, and `symbolToSortTextMap` */
134016 function collectAutoImports() {
134017 var _a, _b;
134018 if (!shouldOfferImportCompletions())
134019 return;
134020 ts.Debug.assert(!(detailsEntryId === null || detailsEntryId === void 0 ? void 0 : detailsEntryId.data), "Should not run 'collectAutoImports' when faster path is available via `data`");
134021 if (detailsEntryId && !detailsEntryId.source) {
134022 // Asking for completion details for an item that is not an auto-import
134023 return;
134024 }
134025 flags |= 1 /* CompletionInfoFlags.MayIncludeAutoImports */;
134026 // import { type | -> token text should be blank
134027 var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
134028 && importCompletionNode
134029 && couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
134030 var lowerCaseTokenText = isAfterTypeOnlyImportSpecifierModifier ? "" :
134031 previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
134032 "";
134033 var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
134034 var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
134035 var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
134036 var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
134037 resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
134038 exportInfo.search(sourceFile.path,
134039 /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
134040 if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
134041 return false;
134042 if (!detailsEntryId && ts.isStringANonContextualKeyword(symbolName))
134043 return false;
134044 if (!isTypeOnlyLocation && !importCompletionNode && !(targetFlags & 111551 /* SymbolFlags.Value */))
134045 return false;
134046 if (isTypeOnlyLocation && !(targetFlags & (1536 /* SymbolFlags.Module */ | 788968 /* SymbolFlags.Type */)))
134047 return false;
134048 // Do not try to auto-import something with a lowercase first letter for a JSX tag
134049 var firstChar = symbolName.charCodeAt(0);
134050 if (isRightOfOpenTag && (firstChar < 65 /* CharacterCodes.A */ || firstChar > 90 /* CharacterCodes.Z */))
134051 return false;
134052 if (detailsEntryId)
134053 return true;
134054 return charactersFuzzyMatchInString(symbolName, lowerCaseTokenText);
134055 }, function (info, symbolName, isFromAmbientModule, exportMapKey) {
134056 var _a;
134057 if (detailsEntryId && !ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); })) {
134058 return;
134059 }
134060 // Do a relatively cheap check to bail early if all re-exports are non-importable
134061 // due to file location or package.json dependency filtering. For non-node16+
134062 // module resolution modes, getting past this point guarantees that we'll be
134063 // able to generate a suitable module specifier, so we can safely show a completion,
134064 // even if we defer computing the module specifier.
134065 var firstImportableExportInfo = ts.find(info, isImportableExportInfo);
134066 if (!firstImportableExportInfo) {
134067 return;
134068 }
134069 // In node16+, module specifier resolution can fail due to modules being blocked
134070 // by package.json `exports`. If that happens, don't show a completion item.
134071 // N.B. in this resolution mode we always try to resolve module specifiers here,
134072 // because we have to know now if it's going to fail so we can omit the completion
134073 // from the list.

Callers 2

getGlobalCompletionsFunction · 0.85

Calls 10

pushAutoImportSymbolFunction · 0.85
assertMethod · 0.80
someMethod · 0.80
findMethod · 0.65
callMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected