Skip to content

Commit 1cb2ba6

Browse files
committed
Wow a bunch of code was unnecessary
1 parent 4e64659 commit 1cb2ba6

File tree

2 files changed

+1
-93
lines changed

2 files changed

+1
-93
lines changed

Diff for: src/server/session.ts

-92
Original file line numberDiff line numberDiff line change
@@ -1255,32 +1255,6 @@ namespace ts.server {
12551255
pushIfUnique(definitions, jsDefinition, documentSpansEqual);
12561256
}
12571257
}
1258-
else {
1259-
const ambientCandidates = definitions.filter(d => d.isAliasTarget && d.isAmbient);
1260-
for (const candidate of ambientCandidates) {
1261-
const candidateFileName = getEffectiveFileNameOfDefinition(candidate, project.getLanguageService().getProgram()!);
1262-
if (candidateFileName) {
1263-
const fileNameToSearch = findImplementationFileFromDtsFileName(candidateFileName, file, auxiliaryProject);
1264-
const scriptInfo = fileNameToSearch ? auxiliaryProject.getScriptInfo(fileNameToSearch) : undefined;
1265-
if (!scriptInfo) {
1266-
continue;
1267-
}
1268-
if (!auxiliaryProject.containsScriptInfo(scriptInfo)) {
1269-
auxiliaryProject.addRoot(scriptInfo);
1270-
}
1271-
const auxiliaryProgram = auxiliaryProject.getLanguageService().getProgram()!;
1272-
const fileToSearch = Debug.checkDefined(auxiliaryProgram.getSourceFile(fileNameToSearch!));
1273-
const matches = FindAllReferences.Core.getTopMostDeclarationNamesInFile(candidate.name, fileToSearch);
1274-
for (const match of matches) {
1275-
const symbol = match.symbol || auxiliaryProgram.getTypeChecker().getSymbolAtLocation(match);
1276-
const decl = getDeclarationFromName(match);
1277-
if (symbol && decl) {
1278-
pushIfUnique(definitions, GoToDefinition.createDefinitionInfo(decl, auxiliaryProgram.getTypeChecker(), symbol, match));
1279-
}
1280-
}
1281-
}
1282-
}
1283-
}
12841258
});
12851259
}
12861260

@@ -1299,72 +1273,6 @@ namespace ts.server {
12991273
textSpan,
13001274
};
13011275

1302-
function getEffectiveFileNameOfDefinition(definition: DefinitionInfo, program: Program) {
1303-
const sourceFile = program.getSourceFile(definition.fileName)!;
1304-
const checker = program.getTypeChecker();
1305-
const symbol = checker.getSymbolAtLocation(getTouchingPropertyName(sourceFile, definition.textSpan.start));
1306-
if (symbol) {
1307-
let parent = symbol.parent;
1308-
while (parent && !isExternalModuleSymbol(parent)) {
1309-
parent = parent.parent;
1310-
}
1311-
if (parent?.declarations && some(parent.declarations, isExternalModuleAugmentation)) {
1312-
// Always CommonJS right now, but who knows in the future
1313-
const mode = getModeForUsageLocation(sourceFile, find(parent.declarations, isExternalModuleAugmentation)!.name as StringLiteral);
1314-
const fileName = sourceFile.resolvedModules?.get(stripQuotes(parent.name), mode)?.resolvedFileName;
1315-
if (fileName) {
1316-
return fileName;
1317-
}
1318-
}
1319-
const fileName = tryCast(parent?.valueDeclaration, isSourceFile)?.fileName;
1320-
if (fileName) {
1321-
return fileName;
1322-
}
1323-
}
1324-
}
1325-
1326-
function findImplementationFileFromDtsFileName(fileName: string, resolveFromFile: string, auxiliaryProject: Project) {
1327-
const nodeModulesPathParts = getNodeModulePathParts(fileName);
1328-
if (nodeModulesPathParts && fileName.lastIndexOf(nodeModulesPathPart) === nodeModulesPathParts.topLevelNodeModulesIndex) {
1329-
// Second check ensures the fileName only contains one `/node_modules/`. If there's more than one I give up.
1330-
const packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
1331-
const packageJsonCache = project.getModuleResolutionCache()?.getPackageJsonInfoCache();
1332-
const compilerOptions = project.getCompilationSettings();
1333-
const packageJson = getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), packageJsonCache, project, compilerOptions);
1334-
if (!packageJson) return undefined;
1335-
// Use fake options instead of actual compiler options to avoid following export map if the project uses node12 or nodenext -
1336-
// Mapping from an export map entry across packages is out of scope for now. Returned entrypoints will only be what can be
1337-
// resolved from the package root under --moduleResolution node
1338-
const entrypoints = getEntrypointsFromPackageJsonInfo(
1339-
packageJson,
1340-
{ moduleResolution: ModuleResolutionKind.NodeJs },
1341-
project,
1342-
project.getModuleResolutionCache());
1343-
// This substring is correct only because we checked for a single `/node_modules/` at the top.
1344-
const packageNamePathPart = fileName.substring(
1345-
nodeModulesPathParts.topLevelPackageNameIndex + 1,
1346-
nodeModulesPathParts.packageRootIndex);
1347-
const packageName = getPackageNameFromTypesPackageName(unmangleScopedPackageName(packageNamePathPart));
1348-
const path = project.toPath(fileName);
1349-
if (entrypoints && some(entrypoints, e => project.toPath(e) === path)) {
1350-
// This file was the main entrypoint of a package. Try to resolve that same package name with
1351-
// the auxiliary project that only resolves to implementation files.
1352-
const [implementationResolution] = auxiliaryProject.resolveModuleNames([packageName], resolveFromFile);
1353-
return implementationResolution?.resolvedFileName;
1354-
}
1355-
else {
1356-
// It wasn't the main entrypoint but we are in node_modules. Try a subpath into the package.
1357-
const pathToFileInPackage = fileName.substring(nodeModulesPathParts.packageRootIndex + 1);
1358-
const specifier = `${packageName}/${removeFileExtension(pathToFileInPackage)}`;
1359-
const [implementationResolution] = auxiliaryProject.resolveModuleNames([specifier], resolveFromFile);
1360-
return implementationResolution?.resolvedFileName;
1361-
}
1362-
}
1363-
// We're not in node_modules, and we only get to this function if non-dts module resolution failed.
1364-
// I'm not sure what else I can do here that isn't already covered by that module resolution.
1365-
return undefined;
1366-
}
1367-
13681276
function tryRefineDefinition(definition: DefinitionInfo, program: Program, auxiliaryProgram: Program) {
13691277
const fileToSearch = auxiliaryProgram.getSourceFile(definition.fileName);
13701278
if (!fileToSearch) {

Diff for: tests/cases/fourslash/server/goToSource10_mapFromAtTypes3.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@
6464

6565

6666
// @Filename: /index.ts
67-
//// import { /*start*/add } from 'lodash';
67+
//// import { [|/*start*/add|] } from 'lodash';
6868

6969
verify.goToSourceDefinition("start", ["variable", "property"]);

0 commit comments

Comments
 (0)