-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial IssueUriRequestHandler proposed API (#180363)
- Loading branch information
1 parent
bc0bdd3
commit 0724039
Showing
14 changed files
with
299 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { CancellationToken } from 'vs/base/common/cancellation'; | ||
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle'; | ||
import { URI } from 'vs/base/common/uri'; | ||
import { ExtHostContext, ExtHostIssueReporterShape, MainContext, MainThreadIssueReporterShape } from 'vs/workbench/api/common/extHost.protocol'; | ||
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers'; | ||
import { IIssueUriRequestHandler, IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue'; | ||
|
||
@extHostNamedCustomer(MainContext.MainThreadIssueReporter) | ||
export class MainThreadIssueReporter extends Disposable implements MainThreadIssueReporterShape { | ||
private readonly _proxy: ExtHostIssueReporterShape; | ||
private readonly _registrations = this._register(new DisposableMap<string>()); | ||
|
||
constructor( | ||
context: IExtHostContext, | ||
@IWorkbenchIssueService private readonly _issueService: IWorkbenchIssueService | ||
) { | ||
super(); | ||
this._proxy = context.getProxy(ExtHostContext.ExtHostIssueReporter); | ||
} | ||
|
||
$registerIssueUriRequestHandler(extensionId: string): void { | ||
const handler: IIssueUriRequestHandler = { | ||
provideIssueUrl: async (token: CancellationToken) => { | ||
const parts = await this._proxy.$getIssueReporterUri(extensionId, token); | ||
return URI.from(parts); | ||
} | ||
}; | ||
this._registrations.set(extensionId, this._issueService.registerIssueUriRequestHandler(extensionId, handler)); | ||
} | ||
|
||
$unregisterIssueUriRequestHandler(extensionId: string): void { | ||
this._registrations.deleteAndDispose(extensionId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { IssueUriRequestHandler } from 'vscode'; | ||
import { CancellationToken } from 'vs/base/common/cancellation'; | ||
import { UriComponents } from 'vs/base/common/uri'; | ||
import { ExtHostIssueReporterShape, IMainContext, MainContext, MainThreadIssueReporterShape } from 'vs/workbench/api/common/extHost.protocol'; | ||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; | ||
import { Disposable } from 'vs/workbench/api/common/extHostTypes'; | ||
|
||
export class ExtHostIssueReporter implements ExtHostIssueReporterShape { | ||
private _IssueUriRequestHandlers: Map<string, IssueUriRequestHandler> = new Map(); | ||
|
||
private readonly _proxy: MainThreadIssueReporterShape; | ||
|
||
constructor( | ||
mainContext: IMainContext | ||
) { | ||
this._proxy = mainContext.getProxy(MainContext.MainThreadIssueReporter); | ||
} | ||
|
||
async $getIssueReporterUri(extensionId: string, token: CancellationToken): Promise<UriComponents> { | ||
if (this._IssueUriRequestHandlers.size === 0) { | ||
throw new Error('No issue request handlers registered'); | ||
} | ||
|
||
const provider = this._IssueUriRequestHandlers.get(extensionId); | ||
if (!provider) { | ||
throw new Error('Issue request handler not found'); | ||
} | ||
|
||
const result = await provider.handleIssueUrlRequest(); | ||
if (!result) { | ||
throw new Error('Issue request handler returned no result'); | ||
} | ||
return result; | ||
} | ||
|
||
registerIssueUriRequestHandler(extension: IExtensionDescription, provider: IssueUriRequestHandler): Disposable { | ||
const extensionId = extension.identifier.value; | ||
this._IssueUriRequestHandlers.set(extensionId, provider); | ||
this._proxy.$registerIssueUriRequestHandler(extensionId); | ||
return new Disposable(() => { | ||
this._proxy.$unregisterIssueUriRequestHandler(extensionId); | ||
this._IssueUriRequestHandlers.delete(extensionId); | ||
}); | ||
} | ||
} |
Oops, something went wrong.