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

Function getDefinitionAtPosition

test/fixtures/snapshot/typescript.js:139664–139781  ·  view source on GitHub ↗
(program, sourceFile, position, searchOtherFilesOnly, stopAtAlias)

Source from the content-addressed store, hash-verified

139662 var GoToDefinition;
139663 (function (GoToDefinition) {
139664 function getDefinitionAtPosition(program, sourceFile, position, searchOtherFilesOnly, stopAtAlias) {
139665 var _a;
139666 var _b;
139667 var resolvedRef = getReferenceAtPosition(sourceFile, position, program);
139668 var fileReferenceDefinition = resolvedRef && [getDefinitionInfoForFileReference(resolvedRef.reference.fileName, resolvedRef.fileName, resolvedRef.unverified)] || ts.emptyArray;
139669 if (resolvedRef === null || resolvedRef === void 0 ? void 0 : resolvedRef.file) {
139670 // If `file` is missing, do a symbol-based lookup as well
139671 return fileReferenceDefinition;
139672 }
139673 var node = ts.getTouchingPropertyName(sourceFile, position);
139674 if (node === sourceFile) {
139675 return undefined;
139676 }
139677 var parent = node.parent;
139678 var typeChecker = program.getTypeChecker();
139679 if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) {
139680 return getDefinitionFromOverriddenMember(typeChecker, node) || ts.emptyArray;
139681 }
139682 // Labels
139683 if (ts.isJumpStatementTarget(node)) {
139684 var label = ts.getTargetLabel(node.parent, node.text);
139685 return label ? [createDefinitionInfoFromName(typeChecker, label, "label" /* ScriptElementKind.label */, node.text, /*containerName*/ undefined)] : undefined; // TODO: GH#18217
139686 }
139687 if (ts.isStaticModifier(node) && ts.isClassStaticBlockDeclaration(node.parent)) {
139688 var classDecl = node.parent.parent;
139689 var _c = getSymbol(classDecl, typeChecker, stopAtAlias), symbol_1 = _c.symbol, failedAliasResolution_1 = _c.failedAliasResolution;
139690 var staticBlocks = ts.filter(classDecl.members, ts.isClassStaticBlockDeclaration);
139691 var containerName_1 = symbol_1 ? typeChecker.symbolToString(symbol_1, classDecl) : "";
139692 var sourceFile_1 = node.getSourceFile();
139693 return ts.map(staticBlocks, function (staticBlock) {
139694 var pos = ts.moveRangePastModifiers(staticBlock).pos;
139695 pos = ts.skipTrivia(sourceFile_1.text, pos);
139696 return createDefinitionInfoFromName(typeChecker, staticBlock, "constructor" /* ScriptElementKind.constructorImplementationElement */, "static {}", containerName_1, /*unverified*/ false, failedAliasResolution_1, { start: pos, length: "static".length });
139697 });
139698 }
139699 var _d = getSymbol(node, typeChecker, stopAtAlias), symbol = _d.symbol, failedAliasResolution = _d.failedAliasResolution;
139700 var fallbackNode = node;
139701 if (searchOtherFilesOnly && failedAliasResolution) {
139702 // We couldn't resolve the specific import, try on the module specifier.
139703 var importDeclaration = ts.forEach(__spreadArray([node], (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) || ts.emptyArray, true), function (n) { return ts.findAncestor(n, ts.isAnyImportOrBareOrAccessedRequire); });
139704 var moduleSpecifier = importDeclaration && ts.tryGetModuleSpecifierFromDeclaration(importDeclaration);
139705 if (moduleSpecifier) {
139706 (_a = getSymbol(moduleSpecifier, typeChecker, stopAtAlias), symbol = _a.symbol, failedAliasResolution = _a.failedAliasResolution);
139707 fallbackNode = moduleSpecifier;
139708 }
139709 }
139710 if (!symbol && ts.isModuleSpecifierLike(fallbackNode)) {
139711 // We couldn't resolve the module specifier as an external module, but it could
139712 // be that module resolution succeeded but the target was not a module.
139713 var ref = (_b = sourceFile.resolvedModules) === null || _b === void 0 ? void 0 : _b.get(fallbackNode.text, ts.getModeForUsageLocation(sourceFile, fallbackNode));
139714 if (ref) {
139715 return [{
139716 name: fallbackNode.text,
139717 fileName: ref.resolvedFileName,
139718 containerName: undefined,
139719 containerKind: undefined,
139720 kind: "script" /* ScriptElementKind.scriptElement */,
139721 textSpan: ts.createTextSpan(0, 0),

Callers 1

Tested by

no test coverage detected