Skip to content

Commit

Permalink
add typingOptions to the protocol.ExternalProject
Browse files Browse the repository at this point in the history
  • Loading branch information
vladima committed Aug 23, 2016
1 parent aff4556 commit d736db3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ namespace ts {
return { options, errors };
}

export function convertTypingOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: CompilerOptions, errors: Diagnostic[] } {
export function convertTypingOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: TypingOptions, errors: Diagnostic[] } {
const errors: Diagnostic[] = [];
const options = convertTypingOptionsFromJsonWorker(jsonOptions, basePath, errors, configFileName);
return { options, errors };
Expand Down
12 changes: 7 additions & 5 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,13 @@ namespace ts.server {
return false;
}

private createAndAddExternalProject(projectFileName: string, files: protocol.ExternalFile[], compilerOptions: CompilerOptions) {
private createAndAddExternalProject(projectFileName: string, files: protocol.ExternalFile[], compilerOptions: CompilerOptions, typingOptions: TypingOptions) {
const project = new ExternalProject(
projectFileName,
this,
this.documentRegistry,
compilerOptions,
typingOptions,
/*languageServiceEnabled*/ !this.exceededTotalSizeLimitForNonTsFiles(compilerOptions, files, externalFilePropertyReader));

const errors = this.addFilesToProjectAndUpdateGraph(project, files, externalFilePropertyReader, /*clientFileName*/ undefined);
Expand Down Expand Up @@ -774,7 +775,7 @@ namespace ts.server {
return { success: true, project, errors };
}

private updateNonInferredProject<T>(project: ExternalProject | ConfiguredProject, newUncheckedFiles: T[], propertyReader: FilePropertyReader<T>, newOptions: CompilerOptions) {
private updateNonInferredProject<T>(project: ExternalProject | ConfiguredProject, newUncheckedFiles: T[], propertyReader: FilePropertyReader<T>, newOptions: CompilerOptions, newTypingOptions: TypingOptions) {
const oldRootScriptInfos = project.getRootScriptInfos();
const newRootScriptInfos: ScriptInfo[] = [];
const newRootScriptInfoMap: NormalizedPathMap<ScriptInfo> = createNormalizedPathMap<ScriptInfo>();
Expand Down Expand Up @@ -834,6 +835,7 @@ namespace ts.server {
}

project.setCompilerOptions(newOptions);
(<ExternalProject | ConfiguredProject>project).setTypingOptions(newTypingOptions);
project.updateGraph();
}

Expand Down Expand Up @@ -863,7 +865,7 @@ namespace ts.server {
project.enableLanguageService();
}
this.watchConfigDirectoryForProject(project, projectOptions);
this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions);
this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typingOptions);
}
}

Expand Down Expand Up @@ -1133,7 +1135,7 @@ namespace ts.server {
openExternalProject(proj: protocol.ExternalProject): void {
const externalProject = this.findExternalProjectByProjectName(proj.projectFileName);
if (externalProject) {
this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, proj.options);
this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, proj.options, proj.typingOptions);
return;
}

Expand Down Expand Up @@ -1165,7 +1167,7 @@ namespace ts.server {
}
}
else {
this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options);
this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typingOptions);
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ namespace ts.server {
}
}

const jsOrDts = [".js", ".d.ts"];

export function allFilesAreJsOrDts(project: Project): boolean {
return project.getFileNames().every(f => fileExtensionIsAny(f, jsOrDts));
}

export abstract class Project {
private rootFiles: ScriptInfo[] = [];
private rootFilesMap: FileMap<ScriptInfo> = createFileMap<ScriptInfo>();
Expand Down Expand Up @@ -103,6 +109,7 @@ namespace ts.server {
}

abstract getProjectName(): string;
abstract getTypingOptions(): TypingOptions;

close() {
if (this.program) {
Expand Down Expand Up @@ -414,6 +421,14 @@ namespace ts.server {
this.projectService.stopWatchingDirectory(directory);
}
}

getTypingOptions(): TypingOptions {
return {
enableAutoDiscovery: allFilesAreJsOrDts(this),
include: [],
exclude: []
};
}
}

export class ConfiguredProject extends Project {
Expand All @@ -434,6 +449,10 @@ namespace ts.server {
super(ProjectKind.Configured, projectService, documentRegistry, hasExplicitListOfFiles, languageServiceEnabled, compilerOptions);
}

setTypingOptions(newTypingOptions: TypingOptions): void {
this.typingOptions = newTypingOptions;
}

getTypingOptions() {
return this.typingOptions;
}
Expand Down Expand Up @@ -508,12 +527,43 @@ namespace ts.server {
}

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

getTypingOptions() {
return this.typingOptions;
}

setTypingOptions(newTypingOptions: TypingOptions): void {
if (!newTypingOptions) {
// set default typings options
newTypingOptions = {
enableAutoDiscovery: allFilesAreJsOrDts(this),
include: [],
exclude: []
};
}
else {
if (newTypingOptions.enableAutoDiscovery === undefined) {
// if autoDiscovery was not specified by the caller - set it based on the content of the project
newTypingOptions.enableAutoDiscovery = allFilesAreJsOrDts(this);
}
if (!newTypingOptions.include) {
newTypingOptions.include = [];
}
if (!newTypingOptions.exclude) {
newTypingOptions.exclude = [];
}
}
this.typingOptions = newTypingOptions;
}

getProjectName() {
Expand Down
1 change: 1 addition & 0 deletions src/server/protocol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ declare namespace ts.server.protocol {
projectFileName: string;
rootFiles: ExternalFile[];
options: CompilerOptions;
typingOptions?: TypingOptions;
}

export interface ProjectVersionInfo {
Expand Down
18 changes: 2 additions & 16 deletions src/server/typingsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ namespace ts.server {
poisoned: boolean;
}

const emptyArray: any[] = [];
const jsOrDts = [".js", ".d.ts"];

function getTypingOptionsForProjects(proj: Project): TypingOptions {
if (proj.projectKind === ProjectKind.Configured) {
return (<ConfiguredProject>proj).getTypingOptions();
}

const enableAutoDiscovery = proj.getFileNames().every(f => fileExtensionIsAny(f, jsOrDts));

// TODO: add .d.ts files to excludes
return { enableAutoDiscovery, include: emptyArray, exclude: emptyArray };
}

function setIsEqualTo(arr1: string[], arr2: string[]): boolean {
if (arr1 === arr2) {
return true;
Expand Down Expand Up @@ -89,7 +75,7 @@ namespace ts.server {
}

getTypingsForProject(project: Project): TypingsArray {
const typingOptions = getTypingOptionsForProjects(project);
const typingOptions = project.getTypingOptions();

if (!typingOptions.enableAutoDiscovery) {
return <any>emptyArray;
Expand All @@ -113,7 +99,7 @@ namespace ts.server {
}

invalidateCachedTypingsForProject(project: Project) {
const typingOptions = getTypingOptionsForProjects(project);
const typingOptions = project.getTypingOptions();
if (!typingOptions.enableAutoDiscovery) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace ts.server {
verbose
}

export const emptyArray: ReadonlyArray<any> = [];

export interface Logger {
close(): void;
hasLevel(level: LogLevel): boolean;
Expand Down

0 comments on commit d736db3

Please sign in to comment.