Skip to content

ports #12333 into release-2.1 #12337

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

Merged
merged 1 commit into from
Nov 18, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ namespace ts.projectSystem {
return;
}
assert.equal(e.eventName, server.ProjectLanguageServiceStateEvent);
assert.equal(e.data.project.getProjectName(), config.path, "project name");
lastEvent = <server.ProjectLanguageServiceStateEvent>e;
});
session.executeCommand(<protocol.OpenRequest>{
Expand All @@ -1628,6 +1629,7 @@ namespace ts.projectSystem {
assert.isFalse(project.languageServiceEnabled, "Language service enabled");
assert.isTrue(!!lastEvent, "should receive event");
assert.equal(lastEvent.data.project, project, "project name");
assert.equal(lastEvent.data.project.getProjectName(), config.path, "config path");
assert.isFalse(lastEvent.data.languageServiceEnabled, "Language service state");

host.reloadFS([f1, f2, configWithExclude]);
Expand Down
12 changes: 6 additions & 6 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ namespace ts.server {

private onTypeRootFileChanged(project: ConfiguredProject, fileName: string) {
this.logger.info(`Type root file ${fileName} changed`);
this.throttledOperations.schedule(project.configFileName + " * type root", /*delay*/ 250, () => {
this.throttledOperations.schedule(project.getConfigFilePath() + " * type root", /*delay*/ 250, () => {
project.updateTypes();
this.updateConfiguredProject(project); // TODO: Figure out why this is needed (should be redundant?)
this.refreshInferredProjects();
Expand All @@ -492,13 +492,13 @@ namespace ts.server {

this.logger.info(`Detected source file changes: ${fileName}`);
this.throttledOperations.schedule(
project.configFileName,
project.getConfigFilePath(),
/*delay*/250,
() => this.handleChangeInSourceFileForConfiguredProject(project, fileName));
}

private handleChangeInSourceFileForConfiguredProject(project: ConfiguredProject, triggerFile: string) {
const { projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.configFileName);
const { projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath());
this.reportConfigFileDiagnostics(project.getProjectName(), configFileErrors, triggerFile);

const newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f)));
Expand All @@ -520,7 +520,7 @@ namespace ts.server {
}

private onConfigChangedForConfiguredProject(project: ConfiguredProject) {
this.logger.info(`Config file changed: ${project.configFileName}`);
this.logger.info(`Config file changed: ${project.getConfigFilePath()}`);
this.updateConfiguredProject(project);
this.refreshInferredProjects();
}
Expand Down Expand Up @@ -1009,13 +1009,13 @@ namespace ts.server {
}

private updateConfiguredProject(project: ConfiguredProject) {
if (!this.host.fileExists(project.configFileName)) {
if (!this.host.fileExists(project.getConfigFilePath())) {
this.logger.info("Config file deleted");
this.removeProject(project);
return;
}

const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.configFileName);
const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath());
if (!success) {
// reset project settings to default
this.updateNonInferredProject(project, [], fileNamePropertyReader, {}, {}, /*compileOnSave*/false, configFileErrors);
Expand Down
59 changes: 27 additions & 32 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ namespace ts.server {
}

constructor(
private readonly projectName: string,
readonly projectKind: ProjectKind,
readonly projectService: ProjectService,
private documentRegistry: ts.DocumentRegistry,
Expand Down Expand Up @@ -307,7 +308,9 @@ namespace ts.server {
this.projectService.onUpdateLanguageServiceStateForProject(this, /*languageServiceEnabled*/ false);
}

abstract getProjectName(): string;
getProjectName() {
return this.projectName;
}
abstract getProjectRootPath(): string | undefined;
abstract getTypingOptions(): TypingOptions;

Expand Down Expand Up @@ -759,31 +762,27 @@ namespace ts.server {

export class InferredProject extends Project {

private static NextId = 1;

/**
* Unique name that identifies this particular inferred project
*/
private readonly inferredProjectName: string;
private static newName = (() => {
let nextId = 1;
return () => {
const id = nextId;
nextId++;
return makeInferredProjectName(id);
}
})();

// Used to keep track of what directories are watched for this project
directoriesWatchedForTsconfig: string[] = [];

constructor(projectService: ProjectService, documentRegistry: ts.DocumentRegistry, compilerOptions: CompilerOptions) {
super(ProjectKind.Inferred,
super(InferredProject.newName(),
ProjectKind.Inferred,
projectService,
documentRegistry,
/*files*/ undefined,
/*languageServiceEnabled*/ true,
compilerOptions,
/*compileOnSaveEnabled*/ false);

this.inferredProjectName = makeInferredProjectName(InferredProject.NextId);
InferredProject.NextId++;
}

getProjectName() {
return this.inferredProjectName;
}

getProjectRootPath() {
Expand Down Expand Up @@ -822,19 +821,23 @@ namespace ts.server {
/** Used for configured projects which may have multiple open roots */
openRefCount = 0;

constructor(readonly configFileName: NormalizedPath,
constructor(configFileName: NormalizedPath,
projectService: ProjectService,
documentRegistry: ts.DocumentRegistry,
hasExplicitListOfFiles: boolean,
compilerOptions: CompilerOptions,
private wildcardDirectories: Map<WatchDirectoryFlags>,
languageServiceEnabled: boolean,
public compileOnSaveEnabled: boolean) {
super(ProjectKind.Configured, projectService, documentRegistry, hasExplicitListOfFiles, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
super(configFileName, ProjectKind.Configured, projectService, documentRegistry, hasExplicitListOfFiles, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
}

getConfigFilePath() {
return this.getProjectName();
}

getProjectRootPath() {
return getDirectoryPath(this.configFileName);
return getDirectoryPath(this.getConfigFilePath());
}

setProjectErrors(projectErrors: Diagnostic[]) {
Expand All @@ -849,12 +852,8 @@ namespace ts.server {
return this.typingOptions;
}

getProjectName() {
return this.configFileName;
}

watchConfigFile(callback: (project: ConfiguredProject) => void) {
this.projectFileWatcher = this.projectService.host.watchFile(this.configFileName, _ => callback(this));
this.projectFileWatcher = this.projectService.host.watchFile(this.getConfigFilePath(), _ => callback(this));
}

watchTypeRoots(callback: (project: ConfiguredProject, path: string) => void) {
Expand All @@ -872,7 +871,7 @@ namespace ts.server {
return;
}

const directoryToWatch = getDirectoryPath(this.configFileName);
const directoryToWatch = getDirectoryPath(this.getConfigFilePath());
this.projectService.logger.info(`Add recursive watcher for: ${directoryToWatch}`);
this.directoryWatcher = this.projectService.host.watchDirectory(directoryToWatch, path => callback(this, path), /*recursive*/ true);
}
Expand All @@ -881,7 +880,7 @@ namespace ts.server {
if (!this.wildcardDirectories) {
return;
}
const configDirectoryPath = getDirectoryPath(this.configFileName);
const configDirectoryPath = getDirectoryPath(this.getConfigFilePath());
this.directoriesWatchedForWildcards = reduceProperties(this.wildcardDirectories, (watchers, flag, directory) => {
if (comparePaths(configDirectoryPath, directory, ".", !this.projectService.host.useCaseSensitiveFileNames) !== Comparison.EqualTo) {
const recursive = (flag & WatchDirectoryFlags.Recursive) !== 0;
Expand Down Expand Up @@ -941,14 +940,14 @@ namespace ts.server {

export class ExternalProject extends Project {
private typingOptions: TypingOptions;
constructor(readonly externalProjectName: string,
constructor(externalProjectName: string,
projectService: ProjectService,
documentRegistry: ts.DocumentRegistry,
compilerOptions: CompilerOptions,
languageServiceEnabled: boolean,
public compileOnSaveEnabled: boolean,
private readonly projectFilePath?: string) {
super(ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
super(externalProjectName, ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
}

getProjectRootPath() {
Expand All @@ -958,7 +957,7 @@ namespace ts.server {
// if the projectFilePath is not given, we make the assumption that the project name
// is the path of the project file. AS the project name is provided by VS, we need to
// normalize slashes before using it as a file name.
return getDirectoryPath(normalizeSlashes(this.externalProjectName));
return getDirectoryPath(normalizeSlashes(this.getProjectName()));
}

getTypingOptions() {
Expand Down Expand Up @@ -992,9 +991,5 @@ namespace ts.server {
}
this.typingOptions = newTypingOptions;
}

getProjectName() {
return this.externalProjectName;
}
}
}