Skip to content

Commit 278b35b

Browse files
committed
Adding test and comments. Override file content even if already opened.
1 parent b9778e6 commit 278b35b

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

src/harness/fourslash.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,17 @@ namespace FourSlash {
385385
}
386386

387387
// Opens a file given its 0-based index or fileName
388-
public openFile(index: number): void;
389-
public openFile(name: string): void;
390-
public openFile(indexOrName: any) {
388+
public openFile(index: number, content?: string): void;
389+
public openFile(name: string, content?: string): void;
390+
public openFile(indexOrName: any, content?: string) {
391391
const fileToOpen: FourSlashFile = this.findFile(indexOrName);
392392
fileToOpen.fileName = ts.normalizeSlashes(fileToOpen.fileName);
393393
this.activeFile = fileToOpen;
394394
const fileName = fileToOpen.fileName.replace(Harness.IO.directoryName(fileToOpen.fileName), "").substr(1);
395395
this.scenarioActions.push(`<OpenFile FileName="" SrcFileId="${fileName}" FileId="${fileName}" />`);
396396

397397
// Let the host know that this file is now open
398-
this.languageServiceAdapterHost.openFile(fileToOpen.fileName);
398+
this.languageServiceAdapterHost.openFile(fileToOpen.fileName, content);
399399
}
400400

401401
public verifyErrorExistsBetweenMarkers(startMarkerName: string, endMarkerName: string, negative: boolean) {

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace Harness.LanguageService {
153153
throw new Error("No script with name '" + fileName + "'");
154154
}
155155

156-
public openFile(fileName: string): void {
156+
public openFile(fileName: string, content?: string): void {
157157
}
158158

159159
/**
@@ -493,9 +493,9 @@ namespace Harness.LanguageService {
493493
this.client = client;
494494
}
495495

496-
openFile(fileName: string): void {
497-
super.openFile(fileName);
498-
this.client.openFile(fileName);
496+
openFile(fileName: string, content?: string): void {
497+
super.openFile(fileName, content);
498+
this.client.openFile(fileName, content);
499499
}
500500

501501
editScript(fileName: string, start: number, end: number, newText: string) {

src/server/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ namespace ts.server {
120120
return response;
121121
}
122122

123-
openFile(fileName: string): void {
124-
var args: protocol.FileRequestArgs = { file: fileName };
123+
openFile(fileName: string, content?: string): void {
124+
var args: protocol.OpenRequestArgs = { file: fileName, fileContent: content };
125125
this.processRequest(CommandNames.Open, args);
126126
}
127127

src/server/editorServices.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,9 @@ namespace ts.server {
10311031
}
10321032
}
10331033
if (info) {
1034+
if (fileContent) {
1035+
info.svc.reload(fileContent);
1036+
}
10341037
if (openedByClient) {
10351038
info.isOpen = true;
10361039
}

src/server/protocol.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,10 @@ declare namespace ts.server.protocol {
513513
* Information found in an "open" request.
514514
*/
515515
export interface OpenRequestArgs extends FileRequestArgs {
516+
/**
517+
* Used when a version of the file content is known to be more up to date than the one on disk.
518+
* Then the known content will be used upon opening instead of the disk copy
519+
*/
516520
fileContent?: string;
517521
}
518522

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ module FourSlashInterface {
169169
// Opens a file, given either its index as it
170170
// appears in the test source, or its filename
171171
// as specified in the test metadata
172-
public file(index: number);
173-
public file(name: string);
174-
public file(indexOrName: any) {
175-
FourSlash.currentTestState.openFile(indexOrName);
172+
public file(index: number, content?: string);
173+
public file(name: string, content?: string);
174+
public file(indexOrName: any, content?: string) {
175+
FourSlash.currentTestState.openFile(indexOrName, content);
176176
}
177177
}
178178

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="../fourslash.ts"/>
2+
3+
// @Filename: test1.ts
4+
////t.
5+
6+
// @Filename: test.ts
7+
////var t = '10';
8+
9+
// @Filename: tsconfig.json
10+
////{ "files": ["test.ts", "test1.ts"] }
11+
12+
var overridingContent = "var t = 10; t.";
13+
debugger;
14+
goTo.file("test.ts", overridingContent);
15+
goTo.file("test1.ts");
16+
goTo.eof();
17+
verify.completionListContains("toExponential");

0 commit comments

Comments
 (0)