Skip to content

Commit

Permalink
Merge pull request #226614 from BABA983/fix-146732
Browse files Browse the repository at this point in the history
Resolve custom editor with canonical resource
  • Loading branch information
mjbvz authored Dec 17, 2024
2 parents 648def3 + 72dba68 commit ad09e3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/vs/workbench/api/browser/mainThreadCustomEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { ResourceWorkingCopy } from '../../services/workingCopy/common/resourceW
import { IWorkingCopy, IWorkingCopyBackup, IWorkingCopySaveEvent, NO_TYPE_ID, WorkingCopyCapabilities } from '../../services/workingCopy/common/workingCopy.js';
import { IWorkingCopyFileService, WorkingCopyFileEvent } from '../../services/workingCopy/common/workingCopyFileService.js';
import { IWorkingCopyService } from '../../services/workingCopy/common/workingCopyService.js';
import { IUriIdentityService } from '../../../platform/uriIdentity/common/uriIdentity.js';

const enum CustomEditorModelType {
Custom,
Expand Down Expand Up @@ -73,6 +74,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
@IEditorService private readonly _editorService: IEditorService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IWebviewWorkbenchService private readonly _webviewWorkbenchService: IWebviewWorkbenchService,
@IUriIdentityService private readonly _uriIdentityService: IUriIdentityService,
) {
super();

Expand Down Expand Up @@ -197,7 +199,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
}

try {
await this._proxyCustomEditors.$resolveCustomEditor(resource, handle, viewType, {
await this._proxyCustomEditors.$resolveCustomEditor(this._uriIdentityService.asCanonicalUri(resource), handle, viewType, {
title: webviewInput.getTitle(),
contentOptions: webviewInput.webview.contentOptions,
options: webviewInput.webview.options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uri
import { DEFAULT_EDITOR_ASSOCIATION, EditorExtensions, GroupIdentifier, IEditorFactoryRegistry, IResourceDiffEditorInput } from '../../../common/editor.js';
import { DiffEditorInput } from '../../../common/editor/diffEditorInput.js';
import { EditorInput } from '../../../common/editor/editorInput.js';
import { CONTEXT_ACTIVE_CUSTOM_EDITOR_ID, CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CustomEditorCapabilities, CustomEditorInfo, CustomEditorInfoCollection, ICustomEditorService } from '../common/customEditor.js';
import { CONTEXT_ACTIVE_CUSTOM_EDITOR_ID, CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CustomEditorCapabilities, CustomEditorInfo, CustomEditorInfoCollection, ICustomEditorModelManager, ICustomEditorService } from '../common/customEditor.js';
import { CustomEditorModelManager } from '../common/customEditorModelManager.js';
import { IEditorGroup, IEditorGroupContextKeyProvider, IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';
import { IEditorResolverService, IEditorType, RegisteredEditorPriority } from '../../../services/editor/common/editorResolverService.js';
Expand All @@ -37,7 +37,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
private readonly _editorResolverDisposables = this._register(new DisposableStore());
private readonly _editorCapabilities = new Map<string, CustomEditorCapabilities>();

private readonly _models = new CustomEditorModelManager();
private readonly _models: ICustomEditorModelManager;

private readonly _onDidChangeEditorTypes = this._register(new Emitter<void>());
public readonly onDidChangeEditorTypes: Event<void> = this._onDidChangeEditorTypes.event;
Expand All @@ -55,6 +55,8 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
) {
super();

this._models = new CustomEditorModelManager(this.uriIdentityService);

this._contributedEditors = this._register(new ContributedCustomEditors(storageService));
// Register the contribution points only emitting one change from the resolver
this.editorResolverService.bufferChangeEvents(this.registerContributionPoints.bind(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
import { createSingleCallFunction } from '../../../../base/common/functional.js';
import { IReference } from '../../../../base/common/lifecycle.js';
import { URI } from '../../../../base/common/uri.js';
import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uriIdentity.js';
import { ICustomEditorModel, ICustomEditorModelManager } from './customEditor.js';

export class CustomEditorModelManager implements ICustomEditorModelManager {
private readonly _uriIdentityService: IUriIdentityService;

constructor(
uriIdentityService: IUriIdentityService,
) {
this._uriIdentityService = uriIdentityService;
}

private readonly _references = new Map<string, {
readonly viewType: string;
Expand Down Expand Up @@ -76,6 +84,7 @@ export class CustomEditorModelManager implements ICustomEditorModelManager {
}

private key(resource: URI, viewType: string): string {
resource = this._uriIdentityService.asCanonicalUri(resource);
return `${resource.toString()}@@@${viewType}`;
}
}

0 comments on commit ad09e3d

Please sign in to comment.