TypeScript/src/server/cancellationToken.ts
Zhengbo Li a082857ae8 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
2016-08-23 16:11:52 -07:00

34 lines
876 B
TypeScript

/// <reference types="node" />
// TODO: extract services types
interface HostCancellationToken {
isCancellationRequested(): boolean;
}
import fs = require("fs");
function createCancellationToken(args: string[]): HostCancellationToken {
let cancellationPipeName: string;
for (let i = 0; i < args.length - 1; i++) {
if (args[i] === "--cancellationPipeName") {
cancellationPipeName = args[i + 1];
break;
}
}
if (!cancellationPipeName) {
return { isCancellationRequested: () => false };
}
return {
isCancellationRequested() {
try {
fs.statSync(cancellationPipeName);
return true;
}
catch (e) {
return false;
}
}
};
}
export = createCancellationToken;