Skip to content

Commit 93722c8

Browse files
author
Andy
authored
findAllReferences/rename: Search in all open projects (microsoft#25648)
* findAllReferences/rename: Search in all open projects * Avoid needing a dummy location when location is unused * Remove Program#getDeclarationEmitPath * Only iterate over enabled projects
1 parent 3d672d9 commit 93722c8

File tree

7 files changed

+189
-91
lines changed

7 files changed

+189
-91
lines changed

src/compiler/emitter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ namespace ts {
4949
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath };
5050
}
5151
else {
52-
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
52+
const jsFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
5353
const sourceMapFilePath = isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
5454
// For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error
5555
const isJs = isSourceFileJavaScript(sourceFile);
56-
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
56+
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined;
5757
const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
5858
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath: undefined };
5959
}

src/compiler/sourcemap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace ts {
170170
if (sourceFileOrBundle.kind === SyntaxKind.SourceFile) { // emitting single module file
171171
// For modules or multiple emit files the mapRoot will have directory structure like the sources
172172
// So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map
173-
sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir));
173+
sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir));
174174
}
175175

176176
if (!isRootedDiskPath(sourceMapDir) && !isUrl(sourceMapDir)) {

src/compiler/utilities.ts

+25-10
Original file line numberDiff line numberDiff line change
@@ -3152,26 +3152,38 @@ namespace ts {
31523152
return referencePath ? ensurePathIsNonModuleName(extensionless) : extensionless;
31533153
}
31543154

3155-
export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) {
3155+
export function getOwnEmitOutputFilePath(fileName: string, host: EmitHost, extension: string) {
31563156
const compilerOptions = host.getCompilerOptions();
31573157
let emitOutputFilePathWithoutExtension: string;
31583158
if (compilerOptions.outDir) {
3159-
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
3159+
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir));
31603160
}
31613161
else {
3162-
emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName);
3162+
emitOutputFilePathWithoutExtension = removeFileExtension(fileName);
31633163
}
31643164

31653165
return emitOutputFilePathWithoutExtension + extension;
31663166
}
31673167

3168-
export function getDeclarationEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost) {
3168+
export function getDeclarationEmitOutputFilePath(fileName: string, host: EmitHost) {
3169+
// TODO: GH#25810 following should work but makes the build break:
3170+
// return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f));
3171+
31693172
const options = host.getCompilerOptions();
31703173
const outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified
31713174

31723175
const path = outputDir
3173-
? getSourceFilePathInNewDir(sourceFile, host, outputDir)
3174-
: sourceFile.fileName;
3176+
? getSourceFilePathInNewDir(fileName, host, outputDir)
3177+
: fileName;
3178+
return removeFileExtension(path) + Extension.Dts;
3179+
}
3180+
3181+
export function getDeclarationEmitOutputFilePathWorker(fileName: string, options: CompilerOptions, currentDirectory: string, commonSourceDirectory: string, getCanonicalFileName: GetCanonicalFileName): string {
3182+
const outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified
3183+
3184+
const path = outputDir
3185+
? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName)
3186+
: fileName;
31753187
return removeFileExtension(path) + Extension.Dts;
31763188
}
31773189

@@ -3213,10 +3225,13 @@ namespace ts {
32133225
return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile);
32143226
}
32153227

3216-
export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) {
3217-
let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
3218-
const commonSourceDirectory = host.getCommonSourceDirectory();
3219-
const isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0;
3228+
export function getSourceFilePathInNewDir(fileName: string, host: EmitHost, newDirPath: string): string {
3229+
return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f));
3230+
}
3231+
3232+
export function getSourceFilePathInNewDirWorker(fileName: string, newDirPath: string, currentDirectory: string, commonSourceDirectory: string, getCanonicalFileName: GetCanonicalFileName): string {
3233+
let sourceFilePath = getNormalizedAbsolutePath(fileName, currentDirectory);
3234+
const isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0;
32203235
sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath;
32213236
return combinePaths(newDirPath, sourceFilePath);
32223237
}

src/server/editorServices.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,21 @@ namespace ts.server {
699699
}
700700

701701
/* @internal */
702-
forEachProject(cb: (project: Project) => void) {
702+
private forEachProject(cb: (project: Project) => void) {
703703
for (const p of this.inferredProjects) cb(p);
704704
this.configuredProjects.forEach(cb);
705705
this.externalProjects.forEach(cb);
706706
}
707707

708+
/* @internal */
709+
forEachEnabledProject(cb: (project: Project) => void) {
710+
this.forEachProject(project => {
711+
if (!project.isOrphan() && project.languageServiceEnabled) {
712+
cb(project);
713+
}
714+
});
715+
}
716+
708717
getDefaultProjectForFile(fileName: NormalizedPath, ensureProject: boolean): Project | undefined {
709718
return ensureProject ? this.ensureDefaultProjectForFile(fileName) : this.tryGetDefaultProjectForFile(fileName);
710719
}

0 commit comments

Comments
 (0)