Skip to content

Commit

Permalink
Recently opened: diff editors are not properly excluded when closed (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Apr 29, 2024
1 parent f25e5c3 commit 0ab35b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/vs/workbench/services/history/browser/historyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,14 @@ export class HistoryService extends Disposable implements IHistoryService {

// Side-by-side editors get special treatment: we try to distill the
// possibly untyped resource inputs from both sides to be able to
// offer these entries from the history to the user still.
// offer these entries from the history to the user still unless
// they are excluded.
else {
const resourceInputs: IResourceEditorInput[] = [];
const sideInputs = editor.primary.matches(editor.secondary) ? [editor.primary] : [editor.primary, editor.secondary];
for (const sideInput of sideInputs) {
const candidateResourceInput = this.editorHelper.preferResourceEditorInput(sideInput);
if (isResourceEditorInput(candidateResourceInput)) {
if (isResourceEditorInput(candidateResourceInput) && this.includeInHistory(candidateResourceInput)) {
resourceInputs.push(candidateResourceInput);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as assert from 'assert';
import { ensureNoDisposablesAreLeakedInTestSuite, toResource } from 'vs/base/test/common/utils';
import { URI } from 'vs/base/common/uri';
import { workbenchInstantiationService, TestFileEditorInput, registerTestEditor, createEditorPart, registerTestFileEditor, TestServiceAccessor, TestTextFileEditor, workbenchTeardown } from 'vs/workbench/test/browser/workbenchTestServices';
import { workbenchInstantiationService, TestFileEditorInput, registerTestEditor, createEditorPart, registerTestFileEditor, TestServiceAccessor, TestTextFileEditor, workbenchTeardown, registerTestSideBySideEditor } from 'vs/workbench/test/browser/workbenchTestServices';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupsService, GroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService';
Expand All @@ -28,13 +28,14 @@ import { Selection } from 'vs/editor/common/core/selection';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';

suite('HistoryService', function () {

const TEST_EDITOR_ID = 'MyTestEditorForEditorHistory';
const TEST_EDITOR_INPUT_ID = 'testEditorInputForHistoyService';

async function createServices(scope = GoScope.DEFAULT): Promise<[EditorPart, HistoryService, EditorService, ITextFileService, IInstantiationService, TestConfigurationService]> {
async function createServices(scope = GoScope.DEFAULT, configureSearchExclude = false): Promise<[EditorPart, HistoryService, EditorService, ITextFileService, IInstantiationService, TestConfigurationService]> {
const instantiationService = workbenchInstantiationService(undefined, disposables);

const part = await createEditorPart(instantiationService, disposables);
Expand All @@ -49,6 +50,9 @@ suite('HistoryService', function () {
} else if (scope === GoScope.EDITOR) {
configurationService.setUserConfiguration('workbench.editor.navigationScope', 'editor');
}
if (configureSearchExclude) {
configurationService.setUserConfiguration('search', { exclude: { "**/node_modules/**": true } });
}
instantiationService.stub(IConfigurationService, configurationService);

const historyService = disposables.add(instantiationService.createInstance(HistoryService));
Expand All @@ -63,6 +67,7 @@ suite('HistoryService', function () {

setup(() => {
disposables.add(registerTestEditor(TEST_EDITOR_ID, [new SyncDescriptor(TestFileEditorInput)]));
disposables.add(registerTestSideBySideEditor());
disposables.add(registerTestFileEditor());
});

Expand Down Expand Up @@ -660,8 +665,7 @@ suite('HistoryService', function () {
}
}

const [part, historyService, , , instantiationService, configurationService] = await createServices();
configurationService.setUserConfiguration('search.exclude', '{ "**/node_modules/**": true }');
const [part, historyService, editorService, , instantiationService] = await createServices(undefined, true);

let history = historyService.getHistory();
assert.strictEqual(history.length, 0);
Expand Down Expand Up @@ -698,6 +702,19 @@ suite('HistoryService', function () {
history = historyService.getHistory();
assert.strictEqual(history.length, 2);

// side by side
const input5 = disposables.add(new TestFileEditorInputWithUntyped(URI.parse('file://bar5'), TEST_EDITOR_INPUT_ID));
const input6 = disposables.add(new TestFileEditorInputWithUntyped(URI.file('file://bar1/node_modules/test.txt'), TEST_EDITOR_INPUT_ID));
const input7 = new SideBySideEditorInput(undefined, undefined, input6, input5, editorService);
await part.activeGroup.openEditor(input7, { pinned: true });

history = historyService.getHistory();
assert.strictEqual(history.length, 3);
input7.dispose();

history = historyService.getHistory();
assert.strictEqual(history.length, 3); // only input5 survived, input6 is excluded via search.exclude

return workbenchTeardown(instantiationService);
});

Expand Down

0 comments on commit 0ab35b5

Please sign in to comment.