mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 19:45:07 -06:00
Remove dependncy on NodeJs from editor services
This commit is contained in:
parent
c9ab20c13b
commit
c884fee3eb
@ -641,6 +641,14 @@ namespace Harness.LanguageService {
|
||||
|
||||
startGroup(): void {
|
||||
}
|
||||
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any {
|
||||
return setTimeout(callback, ms, args);
|
||||
}
|
||||
|
||||
clearTimeout(timeoutId: any): void {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
export class ServerLanguageServiceAdapter implements LanguageServiceAdapter {
|
||||
|
||||
@ -533,7 +533,7 @@ namespace ts.server {
|
||||
// number becomes 0 for a watcher, then we should close it.
|
||||
directoryWatchersRefCount: ts.Map<number> = {};
|
||||
hostConfiguration: HostConfiguration;
|
||||
timerForDetectingProjectFileListChanges: Map<NodeJS.Timer> = {};
|
||||
timerForDetectingProjectFileListChanges: Map<any> = {};
|
||||
|
||||
constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) {
|
||||
// ts.disableIncrementalParsing = true;
|
||||
@ -593,9 +593,9 @@ namespace ts.server {
|
||||
|
||||
startTimerForDetectingProjectFileListChanges(project: Project) {
|
||||
if (this.timerForDetectingProjectFileListChanges[project.projectFilename]) {
|
||||
clearTimeout(this.timerForDetectingProjectFileListChanges[project.projectFilename]);
|
||||
this.host.clearTimeout(this.timerForDetectingProjectFileListChanges[project.projectFilename]);
|
||||
}
|
||||
this.timerForDetectingProjectFileListChanges[project.projectFilename] = setTimeout(
|
||||
this.timerForDetectingProjectFileListChanges[project.projectFilename] = this.host.setTimeout(
|
||||
() => this.handleProjectFileListChanges(project),
|
||||
250
|
||||
);
|
||||
|
||||
@ -266,16 +266,21 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
const sys = <ServerHost>ts.sys;
|
||||
|
||||
// Override sys.write because fs.writeSync is not reliable on Node 4
|
||||
ts.sys.write = (s: string) => writeMessage(s);
|
||||
ts.sys.watchFile = (fileName, callback) => {
|
||||
sys.write = (s: string) => writeMessage(s);
|
||||
sys.watchFile = (fileName, callback) => {
|
||||
const watchedFile = pollingWatchedFileSet.addFile(fileName, callback);
|
||||
return {
|
||||
close: () => pollingWatchedFileSet.removeFile(watchedFile)
|
||||
};
|
||||
};
|
||||
|
||||
const ioSession = new IOSession(ts.sys, logger);
|
||||
sys.setTimeout = setTimeout;
|
||||
sys.clearTimeout = clearTimeout;
|
||||
|
||||
const ioSession = new IOSession(sys, logger);
|
||||
process.on("uncaughtException", function(err: Error) {
|
||||
ioSession.logError(err, "unknown");
|
||||
});
|
||||
|
||||
@ -133,6 +133,8 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
export interface ServerHost extends ts.System {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout(timeoutId: any): void;
|
||||
}
|
||||
|
||||
export class Session {
|
||||
|
||||
@ -60,6 +60,12 @@ module ts {
|
||||
return {
|
||||
close: () => { }
|
||||
}
|
||||
},
|
||||
setTimeout: (callback, ms, ...args) => {
|
||||
return setTimeout(callback, ms, args);
|
||||
},
|
||||
clearTimeout: (timeoutId) => {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@ namespace ts.server {
|
||||
getExecutingFilePath(): string { return void 0; },
|
||||
getCurrentDirectory(): string { return void 0; },
|
||||
readDirectory(): string[] { return []; },
|
||||
exit(): void {}
|
||||
exit(): void { },
|
||||
setTimeout(callback, ms, ...args) { return 0; },
|
||||
clearTimeout(timeoutId) { }
|
||||
};
|
||||
const mockLogger: Logger = {
|
||||
close(): void {},
|
||||
|
||||
@ -271,7 +271,7 @@ and grew 1cm per day`;
|
||||
});
|
||||
|
||||
it("Edit ScriptVersionCache ", () => {
|
||||
let svc = server.ScriptVersionCache.fromString(ts.sys, testContent);
|
||||
let svc = server.ScriptVersionCache.fromString(<server.ServerHost>ts.sys, testContent);
|
||||
let checkText = testContent;
|
||||
|
||||
for (let i = 0; i < iterationCount; i++) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user