Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/project-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { traceObservable, tracePromise, traceSync } from './tracing';
import {
isConfigFile,
isDeclarationFile,
isDependencyFile,
isGlobalTSFile,
isJSTSFile,
isPackageJsonFile,
Expand Down Expand Up @@ -597,12 +596,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).
Expand All @@ -621,11 +614,10 @@ export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
*/
private versions: Map<string, number>;

constructor(rootPath: string, options: ts.CompilerOptions, fs: InMemoryFileSystem, expectedFiles: string[], versions: Map<string, number>, private logger: Logger = new NoopLogger()) {
constructor(rootPath: string, options: ts.CompilerOptions, fs: InMemoryFileSystem, versions: Map<string, number>, 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 = [];
Expand Down Expand Up @@ -770,6 +762,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
*/
private expectedFilePaths = new Set<string>();

/**
* @param fs file system to use
* @param documentRegistry Shared DocumentRegistry that manages SourceFile objects
Expand Down Expand Up @@ -815,6 +813,7 @@ export class ProjectConfiguration {
this.ensuredAllFiles = false;
this.service = undefined;
this.host = undefined;
this.expectedFilePaths = new Set();
}

/**
Expand Down Expand Up @@ -877,7 +876,7 @@ export class ProjectConfiguration {
}
const base = dir || this.fs.path;
const configParseResult = ts.parseJsonConfigFileContent(configObject, this.fs, base);
const expFiles = configParseResult.fileNames;
this.expectedFilePaths = new Set(configParseResult.fileNames);

const options = configParseResult.options;
if (/(^|\/)jsconfig\.json$/.test(this.configFilePath)) {
Expand All @@ -890,7 +889,6 @@ export class ProjectConfiguration {
this.fs.path,
options,
this.fs,
expFiles,
this.versions,
this.logger
);
Expand Down Expand Up @@ -922,9 +920,10 @@ export class ProjectConfiguration {
return;
}

// 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) || (!isDependencyFile(fileName) && isDeclarationFile(fileName))) {
if (isGlobalTSFile(fileName) || (isDeclarationFile(fileName) && this.expectedFilePaths.has(toUnixPath(fileName)))) {
const sourceFile = program.getSourceFile(fileName);
if (!sourceFile) {
this.getHost().addFile(fileName);
Expand Down Expand Up @@ -966,7 +965,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);
Expand Down