From 58495a22b2528fd02297bc93e5310dc03db15706 Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Sat, 3 Jun 2017 11:02:56 +0200 Subject: [PATCH 1/4] Only add expected declaration files, avoid generated declarations --- src/project-manager.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/project-manager.ts b/src/project-manager.ts index 447fe4ddc..2a4885305 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -12,7 +12,6 @@ import { traceObservable, tracePromise, traceSync } from './tracing'; import { isConfigFile, isDeclarationFile, - isDependencyFile, isGlobalTSFile, isJSTSFile, isPackageJsonFile, @@ -892,9 +891,14 @@ export class ProjectConfiguration { return; } + // paths have been forward-slashified by TS (see toUnixPath below) + // TODO: consider moving expectedFilePaths out of LanguageServiceHost? + const expectedFilePaths = this.getHost().expectedFilePaths; + for (const uri of this.fs.uris()) { const fileName = uri2path(uri); - if (isGlobalTSFile(fileName) || (!isDependencyFile(fileName) && isDeclarationFile(fileName))) { + if (isGlobalTSFile(fileName) || + (isDeclarationFile(fileName) && expectedFilePaths.includes(toUnixPath(fileName)))) { const sourceFile = program.getSourceFile(fileName); if (!sourceFile) { this.getHost().addFile(fileName); From 1568d34f5037b6b89233fff5c1a88b468cf54794 Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Sat, 3 Jun 2017 12:59:52 +0200 Subject: [PATCH 2/4] Move expected files into ProjectConfiguration where it is used. --- src/project-manager.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/project-manager.ts b/src/project-manager.ts index 2a4885305..93c410f39 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -568,12 +568,6 @@ export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost { */ private fs: InMemoryFileSystem; - /** - * List of files that project consist of (based on tsconfig includes/excludes and wildcards). - * Each item is a relative file path - */ - expectedFilePaths: string[]; - /** * Current list of files that were implicitly added to project * (every time when we need to extract data from a file that we haven't touched yet). @@ -592,11 +586,10 @@ export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost { */ private versions: Map; - constructor(rootPath: string, options: ts.CompilerOptions, fs: InMemoryFileSystem, expectedFiles: string[], versions: Map, private logger: Logger = new NoopLogger()) { + constructor(rootPath: string, options: ts.CompilerOptions, fs: InMemoryFileSystem, versions: Map, private logger: Logger = new NoopLogger()) { this.rootPath = rootPath; this.options = options; this.fs = fs; - this.expectedFilePaths = expectedFiles; this.versions = versions; this.projectVersion = 1; this.filePaths = []; @@ -748,6 +741,12 @@ export class ProjectConfiguration { */ private rootFilePath: string; + /** + * List of files that project consist of (based on tsconfig includes/excludes and wildcards). + * Each item is a relative file path + */ + expectedFilePaths: string[]; + /** * @param fs file system to use * @param rootFilePath root file path, absolute @@ -761,6 +760,7 @@ export class ProjectConfiguration { this.versions = versions; this.traceModuleResolution = traceModuleResolution || false; this.rootFilePath = rootFilePath; + this.expectedFilePaths = []; } /** @@ -784,6 +784,7 @@ export class ProjectConfiguration { this.service = undefined; this.program = undefined; this.host = undefined; + this.expectedFilePaths = []; } /** @@ -846,7 +847,7 @@ export class ProjectConfiguration { } const base = dir || this.fs.path; const configParseResult = ts.parseJsonConfigFileContent(configObject, this.fs, base); - const expFiles = configParseResult.fileNames; + this.expectedFilePaths = configParseResult.fileNames; const options = configParseResult.options; if (/(^|\/)jsconfig\.json$/.test(this.configFilePath)) { @@ -859,7 +860,6 @@ export class ProjectConfiguration { this.fs.path, options, this.fs, - expFiles, this.versions, this.logger ); @@ -892,13 +892,11 @@ export class ProjectConfiguration { } // paths have been forward-slashified by TS (see toUnixPath below) - // TODO: consider moving expectedFilePaths out of LanguageServiceHost? - const expectedFilePaths = this.getHost().expectedFilePaths; for (const uri of this.fs.uris()) { const fileName = uri2path(uri); if (isGlobalTSFile(fileName) || - (isDeclarationFile(fileName) && expectedFilePaths.includes(toUnixPath(fileName)))) { + (isDeclarationFile(fileName) && this.expectedFilePaths.includes(toUnixPath(fileName)))) { const sourceFile = program.getSourceFile(fileName); if (!sourceFile) { this.getHost().addFile(fileName); @@ -940,7 +938,7 @@ export class ProjectConfiguration { if (!program) { return; } - for (const fileName of (this.getHost().expectedFilePaths || [])) { + for (const fileName of this.expectedFilePaths) { const sourceFile = program.getSourceFile(fileName); if (!sourceFile) { this.getHost().addFile(fileName); From 56bfe751e9cdf290a95d88483b382783d2b5483b Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sat, 3 Jun 2017 15:17:25 +0200 Subject: [PATCH 3/4] Optimize implementation Keep expectedFilePaths in a Set that is iterated separately. --- src/project-manager.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/project-manager.ts b/src/project-manager.ts index 93c410f39..ae912a32e 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -11,7 +11,6 @@ import { InMemoryFileSystem } from './memfs'; import { traceObservable, tracePromise, traceSync } from './tracing'; import { isConfigFile, - isDeclarationFile, isGlobalTSFile, isJSTSFile, isPackageJsonFile, @@ -745,7 +744,7 @@ export class ProjectConfiguration { * List of files that project consist of (based on tsconfig includes/excludes and wildcards). * Each item is a relative file path */ - expectedFilePaths: string[]; + private expectedFilePaths = new Set(); /** * @param fs file system to use @@ -760,7 +759,6 @@ export class ProjectConfiguration { this.versions = versions; this.traceModuleResolution = traceModuleResolution || false; this.rootFilePath = rootFilePath; - this.expectedFilePaths = []; } /** @@ -784,7 +782,7 @@ export class ProjectConfiguration { this.service = undefined; this.program = undefined; this.host = undefined; - this.expectedFilePaths = []; + this.expectedFilePaths = new Set(); } /** @@ -847,7 +845,7 @@ export class ProjectConfiguration { } const base = dir || this.fs.path; const configParseResult = ts.parseJsonConfigFileContent(configObject, this.fs, base); - this.expectedFilePaths = configParseResult.fileNames; + this.expectedFilePaths = new Set(configParseResult.fileNames); const options = configParseResult.options; if (/(^|\/)jsconfig\.json$/.test(this.configFilePath)) { @@ -891,18 +889,24 @@ export class ProjectConfiguration { return; } - // paths have been forward-slashified by TS (see toUnixPath below) - + // Add global declaration files from the whole workspace for (const uri of this.fs.uris()) { const fileName = uri2path(uri); - if (isGlobalTSFile(fileName) || - (isDeclarationFile(fileName) && this.expectedFilePaths.includes(toUnixPath(fileName)))) { + if (isGlobalTSFile(fileName)) { const sourceFile = program.getSourceFile(fileName); if (!sourceFile) { this.getHost().addFile(fileName); } } } + + // Add files that belong to the project according to tsconfig.json settings + for (const filePath of this.expectedFilePaths) { + const sourceFile = program.getSourceFile(filePath); + if (!sourceFile) { + this.getHost().addFile(filePath); + } + } this.ensuredBasicFiles = true; } From 868c65107a0f44df049be0560f738f31590a6c19 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sat, 3 Jun 2017 20:12:36 +0200 Subject: [PATCH 4/4] Revert --- src/project-manager.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/project-manager.ts b/src/project-manager.ts index ae912a32e..57acc9200 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -11,6 +11,7 @@ import { InMemoryFileSystem } from './memfs'; import { traceObservable, tracePromise, traceSync } from './tracing'; import { isConfigFile, + isDeclarationFile, isGlobalTSFile, isJSTSFile, isPackageJsonFile, @@ -889,24 +890,16 @@ export class ProjectConfiguration { return; } - // Add global declaration files from the whole workspace + // Add all global declaration files from the workspace and all declarations from the project for (const uri of this.fs.uris()) { const fileName = uri2path(uri); - if (isGlobalTSFile(fileName)) { + if (isGlobalTSFile(fileName) || (isDeclarationFile(fileName) && this.expectedFilePaths.has(toUnixPath(fileName)))) { const sourceFile = program.getSourceFile(fileName); if (!sourceFile) { this.getHost().addFile(fileName); } } } - - // Add files that belong to the project according to tsconfig.json settings - for (const filePath of this.expectedFilePaths) { - const sourceFile = program.getSourceFile(filePath); - if (!sourceFile) { - this.getHost().addFile(filePath); - } - } this.ensuredBasicFiles = true; }