Skip to content

Commit baac6d8

Browse files
committed
Merge pull request #2450 from Microsoft/tsconfigServer
Add support to TypeScript server for tsconfig.json files.
2 parents 62b5ffa + 4848207 commit baac6d8

13 files changed

+244
-105
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: 187 additions & 85 deletions
Large diffs are not rendered by default.

src/server/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,11 @@ module ts.server {
550550
}
551551

552552
return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => {
553-
if (completions.isMemberCompletion || entry.name.indexOf(prefix) == 0) {
553+
if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) == 0)) {
554554
result.push(entry);
555555
}
556556
return result;
557-
}, []);
557+
}, []).sort((a, b) => a.name.localeCompare(b.name));
558558
}
559559

560560
getCompletionEntryDetails(line: number, offset: number,

src/server/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"noImplicitAny": true,
5+
"removeComments": true,
6+
"preserveConstEnums": true,
7+
"out": "../../built/local/tsserver.js",
8+
"sourceMap": true
9+
},
10+
"files": [
11+
"node.d.ts",
12+
"editorServices.ts",
13+
"protocol.d.ts",
14+
"server.ts",
15+
"session.ts"
16+
]
17+
}

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)