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

adopt ensureNoDisposablesLeaked in code action model tests #209279

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"src/vs/base/test/browser/browser.test.ts",
"src/vs/base/test/browser/ui/scrollbar/scrollableElement.test.ts",
"src/vs/base/test/browser/ui/scrollbar/scrollbarState.test.ts",
"src/vs/editor/contrib/codeAction/test/browser/codeActionModel.test.ts",
"src/vs/editor/test/common/services/languageService.test.ts",
"src/vs/editor/test/node/classification/typescript.test.ts",
"src/vs/platform/configuration/test/common/configuration.test.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/codeAction/browser/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export async function getCodeActions(

try {
const actions = await Promise.all(promises);
const allActions = actions.map(x => x.actions).flat();
const allActions = actions.flatMap(x => x.actions);
const allDocumentation = [
...coalesce(actions.map(x => x.documentation)),
...getAdditionalDocumentationForShowingActions(registry, model, trigger, allActions)
Expand Down
7 changes: 5 additions & 2 deletions src/vs/editor/contrib/codeAction/browser/codeActionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class CodeActionModel extends Disposable {
const supportedActions: string[] = this._registry.all(model).flatMap(provider => provider.providedCodeActionKinds ?? []);
this._supportedCodeActions.set(supportedActions.join(' '));

this._codeActionOracle.value = new CodeActionOracle(this._editor, this._markerService, trigger => {
this._codeActionOracle.value = new CodeActionOracle(this._editor, this._markerService, async trigger => {
if (!trigger) {
this.setState(CodeActionsState.Empty);
return;
Expand Down Expand Up @@ -315,7 +315,8 @@ export class CodeActionModel extends Disposable {
}
}
}
// temporarilly hiding here as this is enabled/disabled behind a setting.

// This is for case where setting for nearby quickfixes is off.
return getCodeActions(this._registry, model, trigger.selection, trigger.trigger, Progress.None, token);
});
if (trigger.trigger.type === CodeActionTriggerType.Invoke) {
Expand All @@ -335,6 +336,8 @@ export class CodeActionModel extends Disposable {
if (!isManualToAutoTransition) {
this.setState(newState);
}
const toDisposeActions = await actions;
toDisposeActions.dispose();
justschen marked this conversation as resolved.
Show resolved Hide resolved
}, undefined);
this._codeActionOracle.value.trigger({ type: CodeActionTriggerType.Auto, triggerAction: CodeActionTriggerSource.Default });
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import * as assert from 'assert';
import { promiseWithResolvers } from 'vs/base/common/async';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { assertType } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
import * as languages from 'vs/editor/common/languages';
Expand Down Expand Up @@ -38,19 +38,18 @@ suite('CodeActionModel', () => {
let markerService: MarkerService;
let editor: ICodeEditor;
let registry: LanguageFeatureRegistry<languages.CodeActionProvider>;
const disposables = new DisposableStore();

setup(() => {
disposables.clear();
markerService = new MarkerService();
model = createTextModel('foobar foo bar\nfarboo far boo', languageId, undefined, uri);
editor = createTestCodeEditor(model);
editor.setPosition({ lineNumber: 1, column: 1 });
registry = new LanguageFeatureRegistry();
});

const store = ensureNoDisposablesAreLeakedInTestSuite();

teardown(() => {
disposables.clear();
editor.dispose();
model.dispose();
markerService.dispose();
Expand All @@ -61,11 +60,11 @@ suite('CodeActionModel', () => {

await runWithFakedTimers({ useFakeTimers: true }, () => {
const reg = registry.register(languageId, testProvider);
disposables.add(reg);
store.add(reg);

const contextKeys = new MockContextKeyService();
const model = disposables.add(new CodeActionModel(editor, registry, markerService, contextKeys, undefined));
disposables.add(model.onDidChangeState((e: CodeActionsState.State) => {
const model = store.add(new CodeActionModel(editor, registry, markerService, contextKeys, undefined));
store.add(model.onDidChangeState((e: CodeActionsState.State) => {
assertType(e.type === CodeActionsState.Type.Triggered);

assert.strictEqual(e.trigger.type, languages.CodeActionTriggerType.Auto);
Expand Down Expand Up @@ -93,7 +92,7 @@ suite('CodeActionModel', () => {
test('Oracle -> position changed', async () => {
await runWithFakedTimers({ useFakeTimers: true }, () => {
const reg = registry.register(languageId, testProvider);
disposables.add(reg);
store.add(reg);

markerService.changeOne('fake', uri, [{
startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 6,
Expand All @@ -107,8 +106,8 @@ suite('CodeActionModel', () => {

return new Promise((resolve, reject) => {
const contextKeys = new MockContextKeyService();
const model = disposables.add(new CodeActionModel(editor, registry, markerService, contextKeys, undefined));
disposables.add(model.onDidChangeState((e: CodeActionsState.State) => {
const model = store.add(new CodeActionModel(editor, registry, markerService, contextKeys, undefined));
store.add(model.onDidChangeState((e: CodeActionsState.State) => {
assertType(e.type === CodeActionsState.Type.Triggered);

assert.strictEqual(e.trigger.type, languages.CodeActionTriggerType.Auto);
Expand All @@ -129,12 +128,12 @@ suite('CodeActionModel', () => {
const { promise: donePromise, resolve: done } = promiseWithResolvers<void>();
await runWithFakedTimers({ useFakeTimers: true }, () => {
const reg = registry.register(languageId, testProvider);
disposables.add(reg);
store.add(reg);

let triggerCount = 0;
const contextKeys = new MockContextKeyService();
const model = disposables.add(new CodeActionModel(editor, registry, markerService, contextKeys, undefined));
disposables.add(model.onDidChangeState((e: CodeActionsState.State) => {
const model = store.add(new CodeActionModel(editor, registry, markerService, contextKeys, undefined));
store.add(model.onDidChangeState((e: CodeActionsState.State) => {
assertType(e.type === CodeActionsState.Type.Triggered);

assert.strictEqual(e.trigger.type, languages.CodeActionTriggerType.Auto);
Expand Down
Loading