Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes leaking tests #192299

Merged
merged 1 commit into from
Sep 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/vs/editor/browser/services/abstractCodeEditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export abstract class AbstractCodeEditorService extends Disposable implements IC
this._editorStyleSheets.delete(editorId);
}

public registerDecorationType(description: string, key: string, options: IDecorationRenderOptions, parentTypeKey?: string, editor?: ICodeEditor): void {
public registerDecorationType(description: string, key: string, options: IDecorationRenderOptions, parentTypeKey?: string, editor?: ICodeEditor): IDisposable {
let provider = this._decorationOptionProviders.get(key);
if (!provider) {
const styleSheet = this._getOrCreateStyleSheet(editor);
Expand All @@ -169,6 +169,11 @@ export abstract class AbstractCodeEditorService extends Disposable implements IC
this._onDecorationTypeRegistered.fire(key);
}
provider.refCount++;
return {
dispose: () => {
this.removeDecorationType(key);
}
};
}

public listDecorationTypes(): string[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import * as assert from 'assert';
import * as platform from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
import { TestCodeEditorService, TestGlobalStyleSheet } from 'vs/editor/test/browser/editorTestServices';
import { TestColorTheme, TestThemeService } from 'vs/platform/theme/test/common/testThemeService';

suite('Decoration Render Options', () => {
const store = ensureNoDisposablesAreLeakedInTestSuite();

const themeServiceMock = new TestThemeService();

const options: IDecorationRenderOptions = {
Expand All @@ -20,12 +23,12 @@ suite('Decoration Render Options', () => {
borderColor: 'yellow'
};
test('register and resolve decoration type', () => {
const s = new TestCodeEditorService(themeServiceMock);
s.registerDecorationType('test', 'example', options);
const s = store.add(new TestCodeEditorService(themeServiceMock));
store.add(s.registerDecorationType('test', 'example', options));
assert.notStrictEqual(s.resolveDecorationOptions('example', false), undefined);
});
test('remove decoration type', () => {
const s = new TestCodeEditorService(themeServiceMock);
const s = store.add(new TestCodeEditorService(themeServiceMock));
s.registerDecorationType('test', 'example', options);
assert.notStrictEqual(s.resolveDecorationOptions('example', false), undefined);
s.removeDecorationType('example');
Expand All @@ -37,9 +40,9 @@ suite('Decoration Render Options', () => {
}

test('css properties', () => {
const s = new TestCodeEditorService(themeServiceMock);
const s = store.add(new TestCodeEditorService(themeServiceMock));
const styleSheet = s.globalStyleSheet;
s.registerDecorationType('test', 'example', options);
store.add(s.registerDecorationType('test', 'example', options));
const sheet = readStyleSheet(styleSheet);
assert(sheet.indexOf(`{background:url('https://github.com/microsoft/vscode/blob/main/resources/linux/code.png') center center no-repeat;background-size:contain;}`) >= 0);
assert(sheet.indexOf(`{background-color:red;border-color:yellow;box-sizing: border-box;}`) >= 0);
Expand All @@ -54,7 +57,7 @@ suite('Decoration Render Options', () => {
const themeService = new TestThemeService(new TestColorTheme({
editorBackground: '#FF0000'
}));
const s = new TestCodeEditorService(themeService);
const s = store.add(new TestCodeEditorService(themeService));
const styleSheet = s.globalStyleSheet;
s.registerDecorationType('test', 'example', options);
assert.strictEqual(readStyleSheet(styleSheet), '.monaco-editor .ced-example-0 {background-color:#ff0000;border-color:transparent;box-sizing: border-box;}');
Expand Down Expand Up @@ -87,7 +90,7 @@ suite('Decoration Render Options', () => {
editorBackground: '#FF0000',
infoForeground: '#444444'
}));
const s = new TestCodeEditorService(themeService);
const s = store.add(new TestCodeEditorService(themeService));
const styleSheet = s.globalStyleSheet;
s.registerDecorationType('test', 'example', options);
const expected = [
Expand All @@ -103,7 +106,7 @@ suite('Decoration Render Options', () => {
});

test('css properties, gutterIconPaths', () => {
const s = new TestCodeEditorService(themeServiceMock);
const s = store.add(new TestCodeEditorService(themeServiceMock));
const styleSheet = s.globalStyleSheet;

// URI, only minimal encoding
Expand Down
18 changes: 6 additions & 12 deletions src/vs/editor/test/common/model/modelInjectedText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Range } from 'vs/editor/common/core/range';
import { TextModel } from 'vs/editor/common/model/textModel';
import { InternalModelContentChangeEvent, LineInjectedText, ModelRawChange, RawContentChangedType } from 'vs/editor/common/textModelEvents';
import { createTextModel } from 'vs/editor/test/common/testTextModel';

suite('Editor Model - Injected Text Events', () => {
let thisModel: TextModel;

setup(() => {
thisModel = createTextModel('First Line\nSecond Line');
});

teardown(() => {
thisModel.dispose();
});
const store = ensureNoDisposablesAreLeakedInTestSuite();

test('Basic', () => {
const thisModel = store.add(createTextModel('First Line\nSecond Line'));

const recordedChanges = new Array<unknown>();

thisModel.onDidChangeContentOrInjectedText((e) => {
store.add(thisModel.onDidChangeContentOrInjectedText((e) => {
const changes = (e instanceof InternalModelContentChangeEvent ? e.rawContentChangedEvent.changes : e.changes);
for (const change of changes) {
recordedChanges.push(mapChange(change));
}
});
}));

// Initial decoration
let decorations = thisModel.deltaDecorations([], [{
Expand Down