Skip to content

Commit abec4f9

Browse files
committed
Wire tests to use the new server
1 parent 7b28f20 commit abec4f9

5 files changed

Lines changed: 63 additions & 25 deletions

File tree

src/harness/fourslash.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ module FourSlash {
282282
return new Harness.LanguageService.NativeLanugageServiceAdapter(cancellationToken, compilationOptions);
283283
case FourSlashTestType.Shims:
284284
return new Harness.LanguageService.ShimLanugageServiceAdapter(cancellationToken, compilationOptions);
285+
case FourSlashTestType.Server:
286+
return new Harness.LanguageService.ServerLanugageServiceAdapter(cancellationToken, compilationOptions);
285287
default:
286288
throw new Error("Unknown FourSlash test type: ");
287289
}

src/harness/fourslashRunner.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
const enum FourSlashTestType {
66
Native,
7-
Shims
7+
Shims,
8+
Server
89
}
910

1011
class FourSlashRunner extends RunnerBase {
@@ -22,6 +23,10 @@ class FourSlashRunner extends RunnerBase {
2223
this.basePath = 'tests/cases/fourslash/shims';
2324
this.testSuiteName = 'fourslash-shims';
2425
break;
26+
case FourSlashTestType.Server:
27+
this.basePath = 'tests/cases/fourslash/server';
28+
this.testSuiteName = 'fourslash-server';
29+
break;
2530
}
2631
}
2732

src/harness/harness.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
/// <reference path='..\services\services.ts' />
1818
/// <reference path='..\services\shims.ts' />
19+
/// <reference path='..\server\protocol.ts' />
20+
/// <reference path='..\server\client.ts' />
21+
/// <reference path='..\server\node.d.ts' />
1922
/// <reference path='external\mocha.d.ts'/>
2023
/// <reference path='external\chai.d.ts'/>
2124
/// <reference path='sourceMapRecorder.ts'/>
2225
/// <reference path='runnerbase.ts'/>
2326

24-
declare var require: any;
25-
declare var process: any;
26-
var Buffer = require('buffer').Buffer;
27+
var Buffer: BufferConstructor = require('buffer').Buffer;
2728

2829
// this will work in the browser via browserify
2930
var _chai: typeof chai = require('chai');

src/harness/harnessLanguageService.ts

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path='..\services\services.ts' />
22
/// <reference path='..\services\shims.ts' />
3+
/// <reference path='..\server\client.ts' />
34
/// <reference path='harness.ts' />
45

56
module Harness.LanguageService {
@@ -23,18 +24,18 @@ module Harness.LanguageService {
2324
this.version++;
2425
}
2526

26-
public editContent(minChar: number, limChar: number, newText: string): void {
27+
public editContent(start: number, end: number, newText: string): void {
2728
// Apply edits
28-
var prefix = this.content.substring(0, minChar);
29+
var prefix = this.content.substring(0, start);
2930
var middle = newText;
30-
var suffix = this.content.substring(limChar);
31+
var suffix = this.content.substring(end);
3132
this.setContent(prefix + middle + suffix);
3233

3334
// Store edit range + new length of script
3435
this.editRanges.push({
3536
length: this.content.length,
3637
textChangeRange: ts.createTextChangeRange(
37-
ts.createTextSpanFromBounds(minChar, limChar), newText.length)
38+
ts.createTextSpanFromBounds(start, end), newText.length)
3839
});
3940

4041
// Update version #
@@ -127,9 +128,7 @@ module Harness.LanguageService {
127128
protected settings = ts.getDefaultCompilerOptions()) {
128129
}
129130

130-
public getNewLine(): string {
131-
return "\r\n";
132-
}
131+
public getNewLine(): string { return "\r\n"; }
133132

134133
public getFilenames(): string[] {
135134
var fileNames: string[] = [];
@@ -145,20 +144,10 @@ module Harness.LanguageService {
145144
this.fileNameToScript[fileName] = new ScriptInfo(fileName, content);
146145
}
147146

148-
public updateScript(fileName: string, content: string) {
149-
var script = this.getScriptInfo(fileName);
150-
if (script !== null) {
151-
script.updateContent(content);
152-
return;
153-
}
154-
155-
this.addScript(fileName, content);
156-
}
157-
158-
public editScript(fileName: string, minChar: number, limChar: number, newText: string) {
147+
public editScript(fileName: string, start: number, end: number, newText: string) {
159148
var script = this.getScriptInfo(fileName);
160149
if (script !== null) {
161-
script.editContent(minChar, limChar, newText);
150+
script.editContent(start, end, newText);
162151
return;
163152
}
164153

@@ -236,8 +225,7 @@ module Harness.LanguageService {
236225
getFilenames(): string[] { return this.nativeHost.getFilenames(); }
237226
getScriptInfo(fileName: string): ScriptInfo { return this.nativeHost.getScriptInfo(fileName); }
238227
addScript(fileName: string, content: string): void { this.nativeHost.addScript(fileName, content); }
239-
updateScript(fileName: string, content: string): void { return this.nativeHost.updateScript(fileName, content); }
240-
editScript(fileName: string, minChar: number, limChar: number, newText: string): void { this.nativeHost.editScript(fileName, minChar, limChar, newText); }
228+
editScript(fileName: string, start: number, end: number, newText: string): void { this.nativeHost.editScript(fileName, start, end, newText); }
241229
lineColToPosition(fileName: string, line: number, col: number): number { return this.nativeHost.lineColToPosition(fileName, line, col); }
242230
positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineCol(fileName, position); }
243231

@@ -442,5 +430,43 @@ module Harness.LanguageService {
442430
return convertResult;
443431
}
444432
}
433+
434+
// Server adapter
435+
class ServerLanguageServiceHost extends NativeLanguageServiceHost {
436+
private client: ts.server.SessionClient;
437+
constructor(cancellationToken: ts.CancellationToken, settings: ts.CompilerOptions) {
438+
super(cancellationToken, settings);
439+
}
440+
441+
setClient(client: ts.server.SessionClient) {
442+
this.client = client;
443+
}
444+
445+
addScript(fileName: string, content: string): void {
446+
super.addScript(fileName, content);
447+
this.client.openFile(fileName);
448+
}
449+
450+
editScript(fileName: string, start: number, end: number, newText: string) {
451+
super.editScript(fileName, start, end, newText);
452+
this.client.changeFile(fileName, start, end, newText);
453+
}
454+
}
455+
456+
export class ServerLanugageServiceAdapter implements LanguageServiceAdapter {
457+
private host: ServerLanguageServiceHost;
458+
private client: ts.server.SessionClient;
459+
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
460+
debugger;
461+
462+
this.host = new ServerLanguageServiceHost(cancellationToken, options);
463+
this.client = new ts.server.SessionClient(this.host);
464+
this.host.setClient(this.client);
465+
}
466+
getHost() { return this.host; }
467+
getLanguageService(): ts.LanguageService { return this.client; }
468+
getClassifier(): ts.Classifier { throw new Error("getClassifier is not available using the server interface."); }
469+
getPreProcessedFileInfo(fileName: string, fileContents: string): ts.PreProcessedFileInfo { throw new Error("getPreProcessedFileInfo is not available using the server interface."); }
470+
}
445471
}
446472

src/harness/runner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ if (testConfigFile !== '') {
6666
case 'fourslash-shims':
6767
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
6868
break;
69+
case 'fourslash-server':
70+
runners.push(new FourSlashRunner(FourSlashTestType.Server));
71+
break;
6972
case 'fourslash-generated':
7073
runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native));
7174
break;
@@ -95,6 +98,7 @@ if (runners.length === 0) {
9598
// language services
9699
runners.push(new FourSlashRunner(FourSlashTestType.Native));
97100
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
101+
runners.push(new FourSlashRunner(FourSlashTestType.Server));
98102
//runners.push(new GeneratedFourslashRunner());
99103
}
100104

0 commit comments

Comments
 (0)