Moved findConfigFile to program.ts. Addressed pull request comments.

This commit is contained in:
steveluc
2015-03-24 14:03:21 -07:00
parent 7b824bac41
commit 48482071f6
11 changed files with 50 additions and 48 deletions
+16
View File
@@ -10,6 +10,22 @@ module ts {
/** The version of the TypeScript compiler release */
export let version = "1.5.0.0";
export function findConfigFile(searchPath: string): string {
var fileName = "tsconfig.json";
while (true) {
if (sys.fileExists(fileName)) {
return fileName;
}
var parentPath = getDirectoryPath(searchPath);
if (parentPath === searchPath) {
break;
}
searchPath = parentPath;
fileName = "../" + fileName;
}
return undefined;
}
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
let currentDirectory: string;
let existingDirectories: Map<boolean> = {};
+2 -18
View File
@@ -132,23 +132,6 @@ module ts {
return typeof JSON === "object" && typeof JSON.parse === "function";
}
function findConfigFile(): string {
var searchPath = normalizePath(sys.getCurrentDirectory());
var fileName = "tsconfig.json";
while (true) {
if (sys.fileExists(fileName)) {
return fileName;
}
var parentPath = getDirectoryPath(searchPath);
if (parentPath === searchPath) {
break;
}
searchPath = parentPath;
fileName = "../" + fileName;
}
return undefined;
}
export function executeCommandLine(args: string[]): void {
var commandLine = parseCommandLine(args);
var configFileName: string; // Configuration file name (if any)
@@ -198,7 +181,8 @@ module ts {
}
}
else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
configFileName = findConfigFile();
var searchPath = normalizePath(sys.getCurrentDirectory());
configFileName = findConfigFile(searchPath);
}
if (commandLine.fileNames.length === 0 && !configFileName) {
+12 -30
View File
@@ -280,12 +280,7 @@ module ts.server {
openRefCount = 0;
constructor(public projectService: ProjectService, public projectOptions?: ProjectOptions) {
if (projectOptions && projectOptions.compilerOptions) {
this.compilerService = new CompilerService(this,projectOptions.compilerOptions);
}
else {
this.compilerService = new CompilerService(this);
}
this.compilerService = new CompilerService(this,projectOptions && projectOptions.compilerOptions);
}
addOpenRef() {
@@ -508,7 +503,7 @@ module ts.server {
this.printProjects();
}
gcConfiguredProjects() {
updateConfiguredProjectList() {
var configuredProjects: Project[] = [];
for (var i = 0, len = this.configuredProjects.length; i < len; i++) {
if (this.configuredProjects[i].openRefCount > 0) {
@@ -565,7 +560,7 @@ module ts.server {
this.openFileRoots.push(info);
}
}
this.gcConfiguredProjects();
this.updateConfiguredProjectList();
}
/**
@@ -762,13 +757,18 @@ module ts.server {
*/
openClientFile(fileName: string) {
var configFileName = this.findConfigFile(fileName);
var searchPath = ts.normalizePath(getDirectoryPath(fileName));
var configFileName = ts.findConfigFile(searchPath);
if (configFileName) {
configFileName = getAbsolutePath(configFileName, searchPath);
}
if (configFileName && (!this.configProjectIsActive(configFileName))) {
var configResult = this.openConfigFile(configFileName, fileName);
if (!configResult.success) {
this.log("Error opening config file " + configFileName + " " + configResult.errorMsg);
}
else {
this.log("Opened configuration file " + configFileName,"Info");
this.configuredProjects.push(configResult.project);
}
}
@@ -859,22 +859,6 @@ module ts.server {
}
return false;
}
findConfigFile(openedFileName: string): string {
var searchPath = getDirectoryPath(openedFileName);
while (true) {
var fileName = searchPath + ts.directorySeparator + "tsconfig.json";
if (sys.fileExists(fileName)) {
return fileName;
}
var parentPath = getDirectoryPath(searchPath);
if (parentPath === searchPath) {
break;
}
searchPath = parentPath;
}
return undefined;
}
openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult {
configFilename = ts.normalizePath(configFilename);
@@ -915,9 +899,9 @@ module ts.server {
}
createProject(projectFilename: string, projectOptions?: ProjectOptions) {
var eproj = new Project(this, projectOptions);
eproj.projectFilename = projectFilename;
return eproj;
var project = new Project(this, projectOptions);
project.projectFilename = projectFilename;
return project;
}
}
@@ -943,8 +927,6 @@ module ts.server {
setCompilerOptions(opt: ts.CompilerOptions) {
this.settings = opt;
// override default ES6 (remove when compiler default back at ES5)
this.settings.target = ts.ScriptTarget.ES5;
this.host.setCompilationSettings(opt);
}
@@ -1475,6 +1475,7 @@ declare module "typescript" {
declare module "typescript" {
/** The version of the TypeScript compiler release */
let version: string;
function findConfigFile(searchPath: string): string;
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
function getPreEmitDiagnostics(program: Program): Diagnostic[];
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
@@ -4736,6 +4736,10 @@ declare module "typescript" {
let version: string;␍
>version : string
function findConfigFile(searchPath: string): string;␍
>findConfigFile : (searchPath: string) => string
>searchPath : string
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;␍
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
>options : CompilerOptions
@@ -1506,6 +1506,7 @@ declare module "typescript" {
declare module "typescript" {
/** The version of the TypeScript compiler release */
let version: string;
function findConfigFile(searchPath: string): string;
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
function getPreEmitDiagnostics(program: Program): Diagnostic[];
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
@@ -4882,6 +4882,10 @@ declare module "typescript" {
let version: string;␍
>version : string
function findConfigFile(searchPath: string): string;␍
>findConfigFile : (searchPath: string) => string
>searchPath : string
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;␍
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
>options : CompilerOptions
@@ -1507,6 +1507,7 @@ declare module "typescript" {
declare module "typescript" {
/** The version of the TypeScript compiler release */
let version: string;
function findConfigFile(searchPath: string): string;
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
function getPreEmitDiagnostics(program: Program): Diagnostic[];
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
@@ -4832,6 +4832,10 @@ declare module "typescript" {
let version: string;
>version : string
function findConfigFile(searchPath: string): string;
>findConfigFile : (searchPath: string) => string
>searchPath : string
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
>options : CompilerOptions
@@ -1544,6 +1544,7 @@ declare module "typescript" {
declare module "typescript" {
/** The version of the TypeScript compiler release */
let version: string;
function findConfigFile(searchPath: string): string;
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
function getPreEmitDiagnostics(program: Program): Diagnostic[];
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
@@ -5005,6 +5005,10 @@ declare module "typescript" {
let version: string;
>version : string
function findConfigFile(searchPath: string): string;
>findConfigFile : (searchPath: string) => string
>searchPath : string
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
>options : CompilerOptions