diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index b3478e40609..05d718340bd 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -669,6 +669,7 @@ namespace Harness.LanguageService { // host to answer server queries about files on disk const serverHost = new SessionServerHost(clientHost); const server = new ts.server.Session(serverHost, + { isCancellationRequested: () => false }, Buffer ? Buffer.byteLength : (string: string, encoding?: string) => string.length, process.hrtime, serverHost); diff --git a/src/server/server.ts b/src/server/server.ts index da1996d341f..98762982d3f 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -83,8 +83,7 @@ namespace ts.server { if (this.fd >= 0) { fs.writeSync(this.fd, buf, 0, buf.length, null); } - if (this.traceToConsole) - { + if (this.traceToConsole) { console.warn(s); } } @@ -296,17 +295,14 @@ namespace ts.server { let cancellationToken: HostCancellationToken; try { - let cancellationPipeName: string; - if (cancellationPipeName) { - const factory = require("./cancellationToken"); - cancellationToken = factory(sys.args); - } + const factory = require("./cancellationToken"); + cancellationToken = factory(sys.args); } - catch(e) { + catch (e) { cancellationToken = { isCancellationRequested: () => false - } - } + }; + }; const ioSession = new IOSession(sys, cancellationToken, logger); process.on("uncaughtException", function(err: Error) { diff --git a/src/server/session.ts b/src/server/session.ts index 86d8dc0734f..9ee676bb06a 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -329,7 +329,7 @@ namespace ts.server { } const scriptInfo = project.getScriptInfo(file); - const position = this.getPosition(args, scriptInfo);; + const position = this.getPosition(args, scriptInfo); const definitions = project.languageService.getDefinitionAtPosition(file, position); if (!definitions) { @@ -764,7 +764,7 @@ namespace ts.server { } const scriptInfo = project.getScriptInfo(file); - const position = this.getPosition(args, scriptInfo) + const position = this.getPosition(args, scriptInfo); const completions = project.languageService.getCompletionsAtPosition(file, position); if (!completions) { @@ -1161,7 +1161,7 @@ namespace ts.server { return this.requiredResponse(this.getCompletions(request.arguments, /*simplifiedResult*/ false)); }, [CommandNames.CompletionDetails]: (request: protocol.CompletionDetailsRequest) => { - return this.requiredResponse(this.getCompletionEntryDetails(request.arguments)) + return this.requiredResponse(this.getCompletionEntryDetails(request.arguments)); }, [CommandNames.SignatureHelp]: (request: protocol.SignatureHelpRequest) => { return this.requiredResponse(this.getSignatureHelpItems(request.arguments, /*simplifiedResult*/ true)); diff --git a/tests/cases/unittests/cachingInServerLSHost.ts b/tests/cases/unittests/cachingInServerLSHost.ts index 31bd89955c7..b14b9a74350 100644 --- a/tests/cases/unittests/cachingInServerLSHost.ts +++ b/tests/cases/unittests/cachingInServerLSHost.ts @@ -79,7 +79,7 @@ namespace ts { msg: (s: string, type?: string) => { } }; - const projectService = new server.ProjectService(serverHost, logger); + const projectService = new server.ProjectService(serverHost, logger, { isCancellationRequested: () => false }); const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /* openedByClient */true); const project = projectService.createAndAddInferredProject(rootScriptInfo); project.setCompilerOptions({ module: ts.ModuleKind.AMD } ); diff --git a/tests/cases/unittests/session.ts b/tests/cases/unittests/session.ts index a2edb05b39b..6a5fa33d29c 100644 --- a/tests/cases/unittests/session.ts +++ b/tests/cases/unittests/session.ts @@ -23,6 +23,7 @@ namespace ts.server { setTimeout(callback, ms, ...args) { return 0; }, clearTimeout(timeoutId) { } }; + const nullCancellationToken: HostCancellationToken = { isCancellationRequested: () => false }; const mockLogger: Logger = { close(): void {}, isVerbose(): boolean { return false; }, @@ -39,7 +40,7 @@ namespace ts.server { let lastSent: protocol.Message; beforeEach(() => { - session = new Session(mockHost, Utils.byteLength, process.hrtime, mockLogger); + session = new Session(mockHost, nullCancellationToken, Utils.byteLength, process.hrtime, mockLogger); session.send = (msg: protocol.Message) => { lastSent = msg; }; @@ -264,7 +265,7 @@ namespace ts.server { lastSent: protocol.Message; customHandler = "testhandler"; constructor() { - super(mockHost, Utils.byteLength, process.hrtime, mockLogger); + super(mockHost, nullCancellationToken, Utils.byteLength, process.hrtime, mockLogger); this.addProtocolHandler(this.customHandler, () => { return {response: undefined, responseRequired: true}; }); @@ -322,7 +323,7 @@ namespace ts.server { class InProcSession extends Session { private queue: protocol.Request[] = []; constructor(private client: InProcClient) { - super(mockHost, Utils.byteLength, process.hrtime, mockLogger); + super(mockHost, nullCancellationToken, Utils.byteLength, process.hrtime, mockLogger); this.addProtocolHandler("echo", (req: protocol.Request) => ({ response: req.arguments, responseRequired: true diff --git a/tests/cases/unittests/tsserverProjectSystem.ts b/tests/cases/unittests/tsserverProjectSystem.ts index cf382d09463..9a1c69a0171 100644 --- a/tests/cases/unittests/tsserverProjectSystem.ts +++ b/tests/cases/unittests/tsserverProjectSystem.ts @@ -16,6 +16,10 @@ namespace ts { msg: () => void 0 }; + const nullCancellationToken: HostCancellationToken = { + isCancellationRequested: () => false + }; + const { content: libFileContent } = Harness.getDefaultLibraryFile(Harness.IO); function getExecutingFilePathFromLibFile(libFile: FileOrFolder): string { @@ -310,7 +314,7 @@ namespace ts { content: `export let x: number` }; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [appFile, moduleFile, libFile]); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); const { configFileName } = projectService.openClientFile(appFile.path); assert(!configFileName, `should not find config, got: '${configFileName}`); @@ -348,7 +352,7 @@ namespace ts { }; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [ configFile, libFile, file1, file2, file3 ]); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); const { configFileName, configFileErrors } = projectService.openClientFile(file1.path); assert(configFileName, "should find config file"); @@ -374,7 +378,7 @@ namespace ts { const filesWithoutConfig = [ libFile, commonFile1, commonFile2 ]; const filesWithConfig = [ libFile, commonFile1, commonFile2, configFile ]; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", filesWithoutConfig); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(commonFile1.path); projectService.openClientFile(commonFile2.path); @@ -405,7 +409,7 @@ namespace ts { content: `{}` }; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [commonFile1, libFile, configFile]); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(commonFile1.path); checkWatchedDirectories(host, ["/a/b"]); checkNumberOfConfiguredProjects(projectService, 1); @@ -433,7 +437,7 @@ namespace ts { }` }; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [commonFile1, commonFile2, configFile]); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(commonFile1.path); projectService.openClientFile(commonFile2.path); @@ -449,7 +453,7 @@ namespace ts { content: `{}` }; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [commonFile1, commonFile2, configFile]); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(commonFile1.path); checkNumberOfConfiguredProjects(projectService, 1); @@ -479,7 +483,7 @@ namespace ts { }; const files = [commonFile1, commonFile2, configFile]; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", files); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(commonFile1.path); const project = projectService.configuredProjects[0]; @@ -512,7 +516,7 @@ namespace ts { }; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [commonFile1, commonFile2, excludedFile1, configFile]); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(commonFile1.path); checkNumberOfConfiguredProjects(projectService, 1); @@ -546,7 +550,7 @@ namespace ts { }; const files = [file1, nodeModuleFile, classicModuleFile, configFile]; const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", files); - const projectService = new server.ProjectService(host, nullLogger); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken); projectService.openClientFile(file1.path); projectService.openClientFile(nodeModuleFile.path); projectService.openClientFile(classicModuleFile.path);