diff --git a/src/abcEditor.ts b/src/abcEditor.ts index 1dbe9e8..803cc1b 100644 --- a/src/abcEditor.ts +++ b/src/abcEditor.ts @@ -14,7 +14,6 @@ export namespace Testing { } } - export class AbcEditorProvider implements vscode.CustomTextEditorProvider { public static readonly viewType = 'testWebviewEditor.abc'; @@ -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); } diff --git a/src/test/abc.test.ts b/src/test/abc.test.ts index f1a41be..0cd954a 100644 --- a/src/test/abc.test.ts +++ b/src/test/abc.test.ts @@ -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(disposable: T) { disposables.push(disposable); return disposable; } - class CustomEditorUpdateListener { +class CustomEditorUpdateListener { public static create() { return _register(new CustomEditorUpdateListener()); @@ -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() {