Skip to content

Commit 4848207

Browse files
author
steveluc
committed
Moved findConfigFile to program.ts. Addressed pull request comments.
1 parent 7b824ba commit 4848207

11 files changed

+50
-48
lines changed

src/compiler/program.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ module ts {
1010
/** The version of the TypeScript compiler release */
1111
export let version = "1.5.0.0";
1212

13+
export function findConfigFile(searchPath: string): string {
14+
var fileName = "tsconfig.json";
15+
while (true) {
16+
if (sys.fileExists(fileName)) {
17+
return fileName;
18+
}
19+
var parentPath = getDirectoryPath(searchPath);
20+
if (parentPath === searchPath) {
21+
break;
22+
}
23+
searchPath = parentPath;
24+
fileName = "../" + fileName;
25+
}
26+
return undefined;
27+
}
28+
1329
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
1430
let currentDirectory: string;
1531
let existingDirectories: Map<boolean> = {};

src/compiler/tsc.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,6 @@ module ts {
132132
return typeof JSON === "object" && typeof JSON.parse === "function";
133133
}
134134

135-
function findConfigFile(): string {
136-
var searchPath = normalizePath(sys.getCurrentDirectory());
137-
var fileName = "tsconfig.json";
138-
while (true) {
139-
if (sys.fileExists(fileName)) {
140-
return fileName;
141-
}
142-
var parentPath = getDirectoryPath(searchPath);
143-
if (parentPath === searchPath) {
144-
break;
145-
}
146-
searchPath = parentPath;
147-
fileName = "../" + fileName;
148-
}
149-
return undefined;
150-
}
151-
152135
export function executeCommandLine(args: string[]): void {
153136
var commandLine = parseCommandLine(args);
154137
var configFileName: string; // Configuration file name (if any)
@@ -198,7 +181,8 @@ module ts {
198181
}
199182
}
200183
else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
201-
configFileName = findConfigFile();
184+
var searchPath = normalizePath(sys.getCurrentDirectory());
185+
configFileName = findConfigFile(searchPath);
202186
}
203187

204188
if (commandLine.fileNames.length === 0 && !configFileName) {

src/server/editorServices.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,7 @@ module ts.server {
280280
openRefCount = 0;
281281

282282
constructor(public projectService: ProjectService, public projectOptions?: ProjectOptions) {
283-
if (projectOptions && projectOptions.compilerOptions) {
284-
this.compilerService = new CompilerService(this,projectOptions.compilerOptions);
285-
}
286-
else {
287-
this.compilerService = new CompilerService(this);
288-
}
283+
this.compilerService = new CompilerService(this,projectOptions && projectOptions.compilerOptions);
289284
}
290285

291286
addOpenRef() {
@@ -508,7 +503,7 @@ module ts.server {
508503
this.printProjects();
509504
}
510505

511-
gcConfiguredProjects() {
506+
updateConfiguredProjectList() {
512507
var configuredProjects: Project[] = [];
513508
for (var i = 0, len = this.configuredProjects.length; i < len; i++) {
514509
if (this.configuredProjects[i].openRefCount > 0) {
@@ -565,7 +560,7 @@ module ts.server {
565560
this.openFileRoots.push(info);
566561
}
567562
}
568-
this.gcConfiguredProjects();
563+
this.updateConfiguredProjectList();
569564
}
570565

571566
/**
@@ -762,13 +757,18 @@ module ts.server {
762757
*/
763758

764759
openClientFile(fileName: string) {
765-
var configFileName = this.findConfigFile(fileName);
760+
var searchPath = ts.normalizePath(getDirectoryPath(fileName));
761+
var configFileName = ts.findConfigFile(searchPath);
762+
if (configFileName) {
763+
configFileName = getAbsolutePath(configFileName, searchPath);
764+
}
766765
if (configFileName && (!this.configProjectIsActive(configFileName))) {
767766
var configResult = this.openConfigFile(configFileName, fileName);
768767
if (!configResult.success) {
769768
this.log("Error opening config file " + configFileName + " " + configResult.errorMsg);
770769
}
771770
else {
771+
this.log("Opened configuration file " + configFileName,"Info");
772772
this.configuredProjects.push(configResult.project);
773773
}
774774
}
@@ -859,22 +859,6 @@ module ts.server {
859859
}
860860
return false;
861861
}
862-
863-
findConfigFile(openedFileName: string): string {
864-
var searchPath = getDirectoryPath(openedFileName);
865-
while (true) {
866-
var fileName = searchPath + ts.directorySeparator + "tsconfig.json";
867-
if (sys.fileExists(fileName)) {
868-
return fileName;
869-
}
870-
var parentPath = getDirectoryPath(searchPath);
871-
if (parentPath === searchPath) {
872-
break;
873-
}
874-
searchPath = parentPath;
875-
}
876-
return undefined;
877-
}
878862

879863
openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult {
880864
configFilename = ts.normalizePath(configFilename);
@@ -915,9 +899,9 @@ module ts.server {
915899
}
916900

917901
createProject(projectFilename: string, projectOptions?: ProjectOptions) {
918-
var eproj = new Project(this, projectOptions);
919-
eproj.projectFilename = projectFilename;
920-
return eproj;
902+
var project = new Project(this, projectOptions);
903+
project.projectFilename = projectFilename;
904+
return project;
921905
}
922906

923907
}
@@ -943,8 +927,6 @@ module ts.server {
943927

944928
setCompilerOptions(opt: ts.CompilerOptions) {
945929
this.settings = opt;
946-
// override default ES6 (remove when compiler default back at ES5)
947-
this.settings.target = ts.ScriptTarget.ES5;
948930
this.host.setCompilationSettings(opt);
949931
}
950932

tests/baselines/reference/APISample_compile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ declare module "typescript" {
14751475
declare module "typescript" {
14761476
/** The version of the TypeScript compiler release */
14771477
let version: string;
1478+
function findConfigFile(searchPath: string): string;
14781479
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
14791480
function getPreEmitDiagnostics(program: Program): Diagnostic[];
14801481
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;

tests/baselines/reference/APISample_compile.types

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,6 +4736,10 @@ declare module "typescript" {
47364736
let version: string;
47374737
>version : string
47384738

4739+
function findConfigFile(searchPath: string): string;
4740+
>findConfigFile : (searchPath: string) => string
4741+
>searchPath : string
4742+
47394743
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
47404744
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
47414745
>options : CompilerOptions

tests/baselines/reference/APISample_linter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ declare module "typescript" {
15061506
declare module "typescript" {
15071507
/** The version of the TypeScript compiler release */
15081508
let version: string;
1509+
function findConfigFile(searchPath: string): string;
15091510
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
15101511
function getPreEmitDiagnostics(program: Program): Diagnostic[];
15111512
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;

tests/baselines/reference/APISample_linter.types

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4882,6 +4882,10 @@ declare module "typescript" {
48824882
let version: string;
48834883
>version : string
48844884

4885+
function findConfigFile(searchPath: string): string;
4886+
>findConfigFile : (searchPath: string) => string
4887+
>searchPath : string
4888+
48854889
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
48864890
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
48874891
>options : CompilerOptions

tests/baselines/reference/APISample_transform.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,7 @@ declare module "typescript" {
15071507
declare module "typescript" {
15081508
/** The version of the TypeScript compiler release */
15091509
let version: string;
1510+
function findConfigFile(searchPath: string): string;
15101511
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
15111512
function getPreEmitDiagnostics(program: Program): Diagnostic[];
15121513
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;

tests/baselines/reference/APISample_transform.types

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4832,6 +4832,10 @@ declare module "typescript" {
48324832
let version: string;
48334833
>version : string
48344834

4835+
function findConfigFile(searchPath: string): string;
4836+
>findConfigFile : (searchPath: string) => string
4837+
>searchPath : string
4838+
48354839
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
48364840
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
48374841
>options : CompilerOptions

tests/baselines/reference/APISample_watcher.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,7 @@ declare module "typescript" {
15441544
declare module "typescript" {
15451545
/** The version of the TypeScript compiler release */
15461546
let version: string;
1547+
function findConfigFile(searchPath: string): string;
15471548
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
15481549
function getPreEmitDiagnostics(program: Program): Diagnostic[];
15491550
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;

tests/baselines/reference/APISample_watcher.types

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5005,6 +5005,10 @@ declare module "typescript" {
50055005
let version: string;
50065006
>version : string
50075007

5008+
function findConfigFile(searchPath: string): string;
5009+
>findConfigFile : (searchPath: string) => string
5010+
>searchPath : string
5011+
50085012
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
50095013
>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost
50105014
>options : CompilerOptions

0 commit comments

Comments
 (0)