mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
Adding test and comments. Override file content even if already opened.
This commit is contained in:
@@ -385,9 +385,9 @@ namespace FourSlash {
|
||||
}
|
||||
|
||||
// Opens a file given its 0-based index or fileName
|
||||
public openFile(index: number): void;
|
||||
public openFile(name: string): void;
|
||||
public openFile(indexOrName: any) {
|
||||
public openFile(index: number, content?: string): void;
|
||||
public openFile(name: string, content?: string): void;
|
||||
public openFile(indexOrName: any, content?: string) {
|
||||
const fileToOpen: FourSlashFile = this.findFile(indexOrName);
|
||||
fileToOpen.fileName = ts.normalizeSlashes(fileToOpen.fileName);
|
||||
this.activeFile = fileToOpen;
|
||||
@@ -395,7 +395,7 @@ namespace FourSlash {
|
||||
this.scenarioActions.push(`<OpenFile FileName="" SrcFileId="${fileName}" FileId="${fileName}" />`);
|
||||
|
||||
// Let the host know that this file is now open
|
||||
this.languageServiceAdapterHost.openFile(fileToOpen.fileName);
|
||||
this.languageServiceAdapterHost.openFile(fileToOpen.fileName, content);
|
||||
}
|
||||
|
||||
public verifyErrorExistsBetweenMarkers(startMarkerName: string, endMarkerName: string, negative: boolean) {
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace Harness.LanguageService {
|
||||
throw new Error("No script with name '" + fileName + "'");
|
||||
}
|
||||
|
||||
public openFile(fileName: string): void {
|
||||
public openFile(fileName: string, content?: string): void {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,9 +493,9 @@ namespace Harness.LanguageService {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
openFile(fileName: string): void {
|
||||
super.openFile(fileName);
|
||||
this.client.openFile(fileName);
|
||||
openFile(fileName: string, content?: string): void {
|
||||
super.openFile(fileName, content);
|
||||
this.client.openFile(fileName, content);
|
||||
}
|
||||
|
||||
editScript(fileName: string, start: number, end: number, newText: string) {
|
||||
|
||||
@@ -120,8 +120,8 @@ namespace ts.server {
|
||||
return response;
|
||||
}
|
||||
|
||||
openFile(fileName: string): void {
|
||||
var args: protocol.FileRequestArgs = { file: fileName };
|
||||
openFile(fileName: string, content?: string): void {
|
||||
var args: protocol.OpenRequestArgs = { file: fileName, fileContent: content };
|
||||
this.processRequest(CommandNames.Open, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -1031,6 +1031,9 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
if (info) {
|
||||
if (fileContent) {
|
||||
info.svc.reload(fileContent);
|
||||
}
|
||||
if (openedByClient) {
|
||||
info.isOpen = true;
|
||||
}
|
||||
|
||||
4
src/server/protocol.d.ts
vendored
4
src/server/protocol.d.ts
vendored
@@ -513,6 +513,10 @@ declare namespace ts.server.protocol {
|
||||
* Information found in an "open" request.
|
||||
*/
|
||||
export interface OpenRequestArgs extends FileRequestArgs {
|
||||
/**
|
||||
* Used when a version of the file content is known to be more up to date than the one on disk.
|
||||
* Then the known content will be used upon opening instead of the disk copy
|
||||
*/
|
||||
fileContent?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,10 +169,10 @@ module FourSlashInterface {
|
||||
// Opens a file, given either its index as it
|
||||
// appears in the test source, or its filename
|
||||
// as specified in the test metadata
|
||||
public file(index: number);
|
||||
public file(name: string);
|
||||
public file(indexOrName: any) {
|
||||
FourSlash.currentTestState.openFile(indexOrName);
|
||||
public file(index: number, content?: string);
|
||||
public file(name: string, content?: string);
|
||||
public file(indexOrName: any, content?: string) {
|
||||
FourSlash.currentTestState.openFile(indexOrName, content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
tests/cases/fourslash/server/openFile.ts
Normal file
17
tests/cases/fourslash/server/openFile.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference path="../fourslash.ts"/>
|
||||
|
||||
// @Filename: test1.ts
|
||||
////t.
|
||||
|
||||
// @Filename: test.ts
|
||||
////var t = '10';
|
||||
|
||||
// @Filename: tsconfig.json
|
||||
////{ "files": ["test.ts", "test1.ts"] }
|
||||
|
||||
var overridingContent = "var t = 10; t.";
|
||||
debugger;
|
||||
goTo.file("test.ts", overridingContent);
|
||||
goTo.file("test1.ts");
|
||||
goTo.eof();
|
||||
verify.completionListContains("toExponential");
|
||||
Reference in New Issue
Block a user