Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
And test to make sure text documents are not leaked
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Mar 3, 2020
1 parent d549360 commit 943d85c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/abcEditor.ts
Expand Up @@ -14,7 +14,6 @@ export namespace Testing {
}
}


export class AbcEditorProvider implements vscode.CustomTextEditorProvider {

public static readonly viewType = 'testWebviewEditor.abc';
Expand All @@ -27,13 +26,20 @@ export class AbcEditorProvider implements vscode.CustomTextEditorProvider {
) { }

public register(): vscode.Disposable {
const provider = vscode.window.registerCustomEditorProvider(AbcEditorProvider.viewType, this);
const provider = vscode.window.registerCustomEditorProvider(AbcEditorProvider.viewType, this, {
enableFindWidget: true
});

const commands: vscode.Disposable[] = [];
commands.push(vscode.commands.registerCommand(Testing.abcEditorTypeCommand, (content: string) => {
this.activeEditor?.testing_fakeInput(content);
}));

setInterval(() => {
console.log(vscode.workspace.textDocuments);

}, 1000)

return vscode.Disposable.from(provider, ...commands);
}

Expand Down
22 changes: 20 additions & 2 deletions src/test/abc.test.ts
Expand Up @@ -17,14 +17,14 @@ const commands = Object.freeze({

assert.ok(vscode.workspace.rootPath);
const testWorkspaceRoot = vscode.Uri.file(vscode.workspace.rootPath!);

const disposables: vscode.Disposable[] = [];
function _register<T extends vscode.Disposable>(disposable: T) {
disposables.push(disposable);
return disposable;
}

class CustomEditorUpdateListener {
class CustomEditorUpdateListener {

public static create() {
return _register(new CustomEditorUpdateListener());
Expand Down Expand Up @@ -278,6 +278,24 @@ suite('Abc editor tests', () => {
assert.ok(vscode.window.activeTextEditor);
assert.strictEqual(vscode.window.activeTextEditor?.document.uri.toString(), testDocument.toString());
});

test('Should release the text document when the editor is closed', async () => {
const startingContent = `release document init,`;
const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent });

const listener = CustomEditorUpdateListener.create();

await vscode.commands.executeCommand(commands.open, testDocument);
await listener.nextResponse();

const doc = vscode.workspace.textDocuments.find(x => x.uri.toString() === testDocument.toString());
assert.ok(doc);
assert.ok(!doc!.isClosed);

await closeAllEditors();
await wait(100);
assert.ok(doc!.isClosed);
});
});

function resetTestWorkspace() {
Expand Down

0 comments on commit 943d85c

Please sign in to comment.