Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/harness/unittests/textStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace ts.textStorage {

it("text based storage should be have exactly the same as script version cache", () => {

debugger
const host = ts.projectSystem.createServerHost([f]);

const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));
Expand Down
64 changes: 63 additions & 1 deletion src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ namespace ts.projectSystem {
export interface TestServerHostCreationParameters {
useCaseSensitiveFileNames?: boolean;
executingFilePath?: string;
libFile?: FileOrFolder;
currentDirectory?: string;
}

Expand Down Expand Up @@ -1145,6 +1144,69 @@ namespace ts.projectSystem {
checkNumberOfProjects(projectService, {});
});

it("reload regular file after closing", () => {
const f1 = {
path: "/a/b/app.ts",
content: "x."
};
const f2 = {
path: "/a/b/lib.ts",
content: "let x: number;"
};

const host = createServerHost([f1, f2, libFile]);
const service = createProjectService(host);
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: toExternalFiles([f1.path, f2.path]), options: {} })

service.openClientFile(f1.path);
service.openClientFile(f2.path, "let x: string");

service.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);

const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
// should contain completions for string
assert.isTrue(completions1.entries.some(e => e.name === "charAt"), "should contain 'charAt'");
assert.isFalse(completions1.entries.some(e => e.name === "toExponential"), "should not contain 'toExponential'");

service.closeClientFile(f2.path);
const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
// should contain completions for string
assert.isFalse(completions2.entries.some(e => e.name === "charAt"), "should not contain 'charAt'");
assert.isTrue(completions2.entries.some(e => e.name === "toExponential"), "should contain 'toExponential'");
});

it("clear mixed content file after closing", () => {
const f1 = {
path: "/a/b/app.ts",
content: " "
};
const f2 = {
path: "/a/b/lib.html",
content: "<html/>"
};

const host = createServerHost([f1, f2, libFile]);
const service = createProjectService(host);
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: [{ fileName: f1.path }, { fileName: f2.path, hasMixedContent: true }], options: {} })

service.openClientFile(f1.path);
service.openClientFile(f2.path, "let somelongname: string");

service.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);

const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
assert.isTrue(completions1.entries.some(e => e.name === "somelongname"), "should contain 'somelongname'");

service.closeClientFile(f2.path);
const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
assert.isFalse(completions2.entries.some(e => e.name === "somelongname"), "should not contain 'somelongname'");
const sf2 = service.externalProjects[0].getLanguageService().getProgram().getSourceFile(f2.path);
assert.equal(sf2.text, "");
});


it("external project with included config file opened after configured project", () => {
const file1 = {
path: "/a/b/f1.ts",
Expand Down
7 changes: 4 additions & 3 deletions src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace ts.server {
this.switchToScriptVersionCache(newText);
}

public useText() {
public useText(newText?: string) {
this.svc = undefined;
this.reloadFromFile();
this.setText(newText);
}

public edit(start: number, end: number, newText: string) {
Expand Down Expand Up @@ -199,7 +199,8 @@ namespace ts.server {

public close() {
this.isOpen = false;
this.textStorage.useText();
this.textStorage.useText(this.hasMixedContent ? "" : undefined);
this.markContainingProjectsAsDirty();
}

public getSnapshot() {
Expand Down