Skip to content

Commit

Permalink
Merge pull request #2450 from Microsoft/tsconfigServer
Browse files Browse the repository at this point in the history
Add support to TypeScript server for tsconfig.json files.
  • Loading branch information
steveluc committed Mar 24, 2015
2 parents 62b5ffa + 4848207 commit baac6d8
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 105 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
272 changes: 187 additions & 85 deletions src/server/editorServices.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ module ts.server {
}

return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => {
if (completions.isMemberCompletion || entry.name.indexOf(prefix) == 0) {
if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) == 0)) {
result.push(entry);
}
return result;
}, []);
}, []).sort((a, b) => a.name.localeCompare(b.name));
}

getCompletionEntryDetails(line: number, offset: number,
Expand Down
17 changes: 17 additions & 0 deletions src/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"out": "../../built/local/tsserver.js",
"sourceMap": true
},
"files": [
"node.d.ts",
"editorServices.ts",
"protocol.d.ts",
"server.ts",
"session.ts"
]
}
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 baac6d8

Please sign in to comment.