Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findAllReferences/rename: Search in all open projects #25648

Merged
4 commits merged into from Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/emitter.ts
Expand Up @@ -49,11 +49,11 @@ namespace ts {
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath };
}
else {
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
const jsFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
const sourceMapFilePath = isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
// 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
const isJs = isSourceFileJavaScript(sourceFile);
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined;
const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath: undefined };
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/sourcemap.ts
Expand Up @@ -170,7 +170,7 @@ namespace ts {
if (sourceFileOrBundle.kind === SyntaxKind.SourceFile) { // emitting single module file
// For modules or multiple emit files the mapRoot will have directory structure like the sources
// 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
sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir));
sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir));
}

if (!isRootedDiskPath(sourceMapDir) && !isUrl(sourceMapDir)) {
Expand Down
35 changes: 25 additions & 10 deletions src/compiler/utilities.ts
Expand Up @@ -3152,26 +3152,38 @@ namespace ts {
return referencePath ? ensurePathIsNonModuleName(extensionless) : extensionless;
}

export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) {
export function getOwnEmitOutputFilePath(fileName: string, host: EmitHost, extension: string) {
const compilerOptions = host.getCompilerOptions();
let emitOutputFilePathWithoutExtension: string;
if (compilerOptions.outDir) {
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir));
}
else {
emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName);
emitOutputFilePathWithoutExtension = removeFileExtension(fileName);
}

return emitOutputFilePathWithoutExtension + extension;
}

export function getDeclarationEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost) {
export function getDeclarationEmitOutputFilePath(fileName: string, host: EmitHost) {
// TODO: GH#25810 following should work but makes the build break:
// return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f));

const options = host.getCompilerOptions();
const outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified

const path = outputDir
? getSourceFilePathInNewDir(sourceFile, host, outputDir)
: sourceFile.fileName;
? getSourceFilePathInNewDir(fileName, host, outputDir)
: fileName;
return removeFileExtension(path) + Extension.Dts;
}

export function getDeclarationEmitOutputFilePathWorker(fileName: string, options: CompilerOptions, currentDirectory: string, commonSourceDirectory: string, getCanonicalFileName: GetCanonicalFileName): string {
const outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified

const path = outputDir
? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName)
: fileName;
return removeFileExtension(path) + Extension.Dts;
}

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

export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) {
let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
const commonSourceDirectory = host.getCommonSourceDirectory();
const isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0;
export function getSourceFilePathInNewDir(fileName: string, host: EmitHost, newDirPath: string): string {
return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f));
}

export function getSourceFilePathInNewDirWorker(fileName: string, newDirPath: string, currentDirectory: string, commonSourceDirectory: string, getCanonicalFileName: GetCanonicalFileName): string {
let sourceFilePath = getNormalizedAbsolutePath(fileName, currentDirectory);
const isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0;
sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath;
return combinePaths(newDirPath, sourceFilePath);
}
Expand Down
11 changes: 10 additions & 1 deletion src/server/editorServices.ts
Expand Up @@ -699,12 +699,21 @@ namespace ts.server {
}

/* @internal */
forEachProject(cb: (project: Project) => void) {
private forEachProject(cb: (project: Project) => void) {
for (const p of this.inferredProjects) cb(p);
this.configuredProjects.forEach(cb);
this.externalProjects.forEach(cb);
}

/* @internal */
forEachEnabledProject(cb: (project: Project) => void) {
this.forEachProject(project => {
if (!project.isOrphan() && project.languageServiceEnabled) {
cb(project);
}
});
}

getDefaultProjectForFile(fileName: NormalizedPath, ensureProject: boolean): Project | undefined {
return ensureProject ? this.ensureDefaultProjectForFile(fileName) : this.tryGetDefaultProjectForFile(fileName);
}
Expand Down