fix tests issues

This commit is contained in:
Vladimir Matveev 2016-06-14 17:51:19 -07:00
parent adb726643a
commit c3b1645868
6 changed files with 28 additions and 26 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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));

View File

@ -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 } );

View File

@ -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

View File

@ -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);