Skip to content

Commit

Permalink
Moved findConfigFile to program.ts. Addressed pull request comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluc committed Mar 24, 2015
1 parent 7b824ba commit 4848207
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 48 deletions.
16 changes: 16 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = {};
Expand Down
20 changes: 2 additions & 18 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 12 additions & 30 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -565,7 +560,7 @@ module ts.server {
this.openFileRoots.push(info);
}
}
this.gcConfiguredProjects();
this.updateConfiguredProjectList();
}

/**
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

}
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/APISample_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/APISample_compile.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/APISample_linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/APISample_linter.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/APISample_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/APISample_transform.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/APISample_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/APISample_watcher.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4848207

Please sign in to comment.