Skip to content

Commit e1c69d7

Browse files
authored
Merge pull request #9537 from Microsoft/removeContentFromScriptInfo
Remove the unused text buffer(content) from ScriptInfo
2 parents 3e42733 + 635826f commit e1c69d7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace ts.server {
3838
path: Path;
3939
scriptKind: ScriptKind;
4040

41-
constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) {
41+
constructor(private host: ServerHost, public fileName: string, content: string, public isOpen = false) {
4242
this.path = toPath(fileName, host.getCurrentDirectory(), createGetCanonicalFileName(host.useCaseSensitiveFileNames));
4343
this.svc = ScriptVersionCache.fromString(host, content);
4444
}

tests/cases/unittests/cachingInServerLSHost.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ namespace ts {
108108
let diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name);
109109
assert.equal(diags.length, 1);
110110

111+
let content = rootScriptInfo.getText();
112+
111113
const originalFileExists = serverHost.fileExists;
112114
{
113115
// patch fileExists to make sure that disk is not touched
@@ -118,7 +120,8 @@ namespace ts {
118120

119121
const newContent = `import {x} from "f1"
120122
var x: string = 1;`;
121-
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
123+
rootScriptInfo.editContent(0, content.length, newContent);
124+
content = newContent;
122125
// trigger synchronization to make sure that import will be fetched from the cache
123126
diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name);
124127
// ensure file has correct number of errors after edit
@@ -135,7 +138,8 @@ namespace ts {
135138
return originalFileExists.call(serverHost, fileName);
136139
};
137140
const newContent = `import {x} from "f2"`;
138-
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
141+
rootScriptInfo.editContent(0, content.length, newContent);
142+
content = newContent;
139143

140144
try {
141145
// trigger synchronization to make sure that LSHost will try to find 'f2' module on disk
@@ -160,7 +164,8 @@ namespace ts {
160164
};
161165

162166
const newContent = `import {x} from "f1"`;
163-
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
167+
rootScriptInfo.editContent(0, content.length, newContent);
168+
content = newContent;
164169
project.compilerService.languageService.getSemanticDiagnostics(imported.name);
165170
assert.isTrue(fileExistsCalled);
166171

@@ -205,7 +210,7 @@ namespace ts {
205210
};
206211

207212
const { project, rootScriptInfo } = createProject(root.name, serverHost);
208-
213+
const content = rootScriptInfo.getText();
209214
let diags = project.compilerService.languageService.getSemanticDiagnostics(root.name);
210215
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called");
211216
assert.isTrue(diags.length === 1, "one diagnostic expected");
@@ -214,7 +219,7 @@ namespace ts {
214219
// assert that import will success once file appear on disk
215220
fileMap[imported.name] = imported;
216221
fileExistsCalledForBar = false;
217-
rootScriptInfo.editContent(0, rootScriptInfo.content.length, `import {y} from "bar"`);
222+
rootScriptInfo.editContent(0, content.length, `import {y} from "bar"`);
218223

219224
diags = project.compilerService.languageService.getSemanticDiagnostics(root.name);
220225
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called");

0 commit comments

Comments
 (0)