Add APIs for enabling CompileOnSave on tsserver (#9837)

* Add API to get only the emited declarations output

* Add nonModuleBuilder

* Add basic tests for CompileOnSaveAffectedFileList API

* Add API for compile single file

* Avoid invoking project.languageService directly

* Add API to query if compileOnSave is enabled for a project

* Seperate check and emit signatures

* Use Path type for internal file name matching and simplifying builder logic

* Always return cascaded affected list

* Correct the tsconfig file in compileOnSave tests
Also move the CompileOnSave option out of compilerOptions

* Reduce string to path conversion
This commit is contained in:
Zhengbo Li
2016-08-23 16:11:52 -07:00
committed by GitHub
parent d736db3b01
commit a082857ae8
19 changed files with 4390 additions and 71 deletions

View File

@@ -5,12 +5,15 @@
/// <reference path="scanner.ts"/>
namespace ts {
/* @internal */
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };
/* @internal */
export const optionDeclarations: CommandLineOption[] = [
{
name: "charset",
type: "string",
},
compileOnSaveCommandLineOption,
{
name: "declaration",
shortName: "d",
@@ -808,6 +811,7 @@ namespace ts {
options.configFilePath = configFileName;
const { fileNames, wildcardDirectories } = getFileNames(errors);
const compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors);
return {
options,
@@ -815,7 +819,8 @@ namespace ts {
typingOptions,
raw: json,
errors,
wildcardDirectories
wildcardDirectories,
compileOnSave
};
function getFileNames(errors: Diagnostic[]): ExpandResult {
@@ -870,6 +875,17 @@ namespace ts {
}
}
export function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Diagnostic[]): boolean {
if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) {
return false;
}
const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption["compileOnSave"], basePath, errors);
if (typeof result === "boolean" && result) {
return result;
}
return false;
}
export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: CompilerOptions, errors: Diagnostic[] } {
const errors: Diagnostic[] = [];
const options = convertCompilerOptionsFromJsonWorker(jsonOptions, basePath, errors, configFileName);