From 5f0b0b9c19dff0b792c172652bff8970ff6de7a7 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 8 Jun 2020 12:39:31 +0200 Subject: [PATCH] uris - do not rely on isLinux check for comparing mementos --- src/vs/base/common/extpath.ts | 2 +- src/vs/workbench/browser/parts/editor/baseEditor.ts | 9 ++++----- src/vs/workbench/browser/parts/editor/textEditor.ts | 5 +++-- src/vs/workbench/common/editor.ts | 3 ++- .../contrib/files/browser/editors/textFileEditor.ts | 6 ++++-- .../contrib/files/electron-sandbox/textFileEditor.ts | 6 ++++-- .../test/browser/parts/editor/baseEditor.test.ts | 5 +++-- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/vs/base/common/extpath.ts b/src/vs/base/common/extpath.ts index 8fe9f9e1c2a..d6e7d6ef5d7 100644 --- a/src/vs/base/common/extpath.ts +++ b/src/vs/base/common/extpath.ts @@ -285,7 +285,7 @@ export function isRootOrDriveLetter(path: string): boolean { return pathNormalized === posix.sep; } -export function indexOfPath(path: string, candidate: string, ignoreCase: boolean): number { +export function indexOfPath(path: string, candidate: string, ignoreCase?: boolean): number { if (candidate.length > path.length) { return -1; } diff --git a/src/vs/workbench/browser/parts/editor/baseEditor.ts b/src/vs/workbench/browser/parts/editor/baseEditor.ts index acbb267de08..fac5d32a8c9 100644 --- a/src/vs/workbench/browser/parts/editor/baseEditor.ts +++ b/src/vs/workbench/browser/parts/editor/baseEditor.ts @@ -16,8 +16,7 @@ import { Event } from 'vs/base/common/event'; import { isEmptyObject } from 'vs/base/common/types'; import { DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor'; import { MementoObject } from 'vs/workbench/common/memento'; -import { isEqualOrParent, joinPath } from 'vs/base/common/resources'; -import { isLinux } from 'vs/base/common/platform'; +import { joinPath, IExtUri } from 'vs/base/common/resources'; import { indexOfPath } from 'vs/base/common/extpath'; import { IDisposable } from 'vs/base/common/lifecycle'; @@ -259,7 +258,7 @@ export class EditorMemento implements IEditorMemento { } } - moveEditorState(source: URI, target: URI): void { + moveEditorState(source: URI, target: URI, comparer: IExtUri): void { const cache = this.doLoad(); // We need a copy of the keys to not iterate over @@ -268,7 +267,7 @@ export class EditorMemento implements IEditorMemento { for (const cacheKey of cacheKeys) { const resource = URI.parse(cacheKey); - if (!isEqualOrParent(resource, source)) { + if (!comparer.isEqualOrParent(resource, source)) { continue; // not matching our resource } @@ -277,7 +276,7 @@ export class EditorMemento implements IEditorMemento { if (source.toString() === resource.toString()) { targetResource = target; // file got moved } else { - const index = indexOfPath(resource.path, source.path, !isLinux); + const index = indexOfPath(resource.path, source.path); targetResource = joinPath(target, resource.path.substr(index + source.path.length + 1)); // parent folder got moved } diff --git a/src/vs/workbench/browser/parts/editor/textEditor.ts b/src/vs/workbench/browser/parts/editor/textEditor.ts index a6650603cf4..9536c9b971e 100644 --- a/src/vs/workbench/browser/parts/editor/textEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textEditor.ts @@ -24,6 +24,7 @@ import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor'; +import { IExtUri } from 'vs/base/common/resources'; export interface IEditorConfiguration { editor: object; @@ -250,8 +251,8 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa return this.group ? this.editorMemento.loadEditorState(this.group, resource) : undefined; } - protected moveTextEditorViewState(source: URI, target: URI): void { - return this.editorMemento.moveEditorState(source, target); + protected moveTextEditorViewState(source: URI, target: URI, comparer: IExtUri): void { + return this.editorMemento.moveEditorState(source, target, comparer); } protected clearTextEditorViewState(resources: URI[], group?: IEditorGroup): void { diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 8b04c9e6799..c981734c60c 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -22,6 +22,7 @@ import { IPathData } from 'vs/platform/windows/common/windows'; import { coalesce, firstOrDefault } from 'vs/base/common/arrays'; import { IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService'; import { IRange } from 'vs/editor/common/core/range'; +import { IExtUri } from 'vs/base/common/resources'; export const DirtyWorkingCopiesContext = new RawContextKey('dirtyWorkingCopies', false); export const ActiveEditorContext = new RawContextKey('activeEditor', null); @@ -1269,7 +1270,7 @@ export interface IEditorMemento { clearEditorState(resource: URI, group?: IEditorGroup): void; clearEditorState(editor: EditorInput, group?: IEditorGroup): void; - moveEditorState(source: URI, target: URI): void; + moveEditorState(source: URI, target: URI, comparer: IExtUri): void; } class EditorInputFactoryRegistry implements IEditorInputFactoryRegistry { diff --git a/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts b/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts index 91a1fc23a1d..308cf920a5a 100644 --- a/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts +++ b/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts @@ -32,6 +32,7 @@ import { createErrorWithActions } from 'vs/base/common/errorsWithActions'; import { MutableDisposable } from 'vs/base/common/lifecycle'; import { EditorActivation, IEditorOptions } from 'vs/platform/editor/common/editor'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; /** * An implementation of editor for file system resources. @@ -56,7 +57,8 @@ export class TextFileEditor extends BaseTextEditor { @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService private readonly textFileService: ITextFileService, @IExplorerService private readonly explorerService: IExplorerService, - @IConfigurationService private readonly configurationService: IConfigurationService + @IConfigurationService private readonly configurationService: IConfigurationService, + @IUriIdentityService private readonly uriIdentityService: IUriIdentityService ) { super(TextFileEditor.ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorService, editorGroupService); @@ -78,7 +80,7 @@ export class TextFileEditor extends BaseTextEditor { private onDidRunOperation(e: FileOperationEvent): void { if (e.operation === FileOperation.MOVE && e.target) { - this.moveTextEditorViewState(e.resource, e.target.resource); + this.moveTextEditorViewState(e.resource, e.target.resource, this.uriIdentityService.extUri); } } diff --git a/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts b/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts index b5e50bd3c54..2a08e3b26d9 100644 --- a/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts +++ b/src/vs/workbench/contrib/files/electron-sandbox/textFileEditor.ts @@ -24,6 +24,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr import { IExplorerService } from 'vs/workbench/contrib/files/common/files'; import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; /** * An implementation of editor for file system resources. @@ -45,9 +46,10 @@ export class NativeTextFileEditor extends TextFileEditor { @IElectronService private readonly electronService: IElectronService, @IPreferencesService private readonly preferencesService: IPreferencesService, @IExplorerService explorerService: IExplorerService, - @IConfigurationService configurationService: IConfigurationService + @IConfigurationService configurationService: IConfigurationService, + @IUriIdentityService uriIdentityService: IUriIdentityService ) { - super(telemetryService, fileService, viewletService, instantiationService, contextService, storageService, textResourceConfigurationService, editorService, themeService, editorGroupService, textFileService, explorerService, configurationService); + super(telemetryService, fileService, viewletService, instantiationService, contextService, storageService, textResourceConfigurationService, editorService, themeService, editorGroupService, textFileService, explorerService, configurationService, uriIdentityService); } protected handleSetInputError(error: Error, input: FileEditorInput, options: EditorOptions | undefined): void { diff --git a/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts b/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts index 635c4c865fe..b8a62fd8127 100644 --- a/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts @@ -20,6 +20,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorModel } from 'vs/platform/editor/common/editor'; import { dispose } from 'vs/base/common/lifecycle'; import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; +import { extUri } from 'vs/base/common/resources'; const NullThemeService = new TestThemeService(); @@ -266,7 +267,7 @@ suite('Workbench base editor', () => { memento.saveEditorState(testGroup0, URI.file('/some/folder/file-2.txt'), { line: 2 }); memento.saveEditorState(testGroup0, URI.file('/some/other/file.txt'), { line: 3 }); - memento.moveEditorState(URI.file('/some/folder/file-1.txt'), URI.file('/some/folder/file-moved.txt')); + memento.moveEditorState(URI.file('/some/folder/file-1.txt'), URI.file('/some/folder/file-moved.txt'), extUri); let res = memento.loadEditorState(testGroup0, URI.file('/some/folder/file-1.txt')); assert.ok(!res); @@ -274,7 +275,7 @@ suite('Workbench base editor', () => { res = memento.loadEditorState(testGroup0, URI.file('/some/folder/file-moved.txt')); assert.equal(res?.line, 1); - memento.moveEditorState(URI.file('/some/folder'), URI.file('/some/folder-moved')); + memento.moveEditorState(URI.file('/some/folder'), URI.file('/some/folder-moved'), extUri); res = memento.loadEditorState(testGroup0, URI.file('/some/folder-moved/file-moved.txt')); assert.equal(res?.line, 1); -- GitLab