55
66import { asArray } from 'vs/base/common/arrays' ;
77import { DeferredPromise , timeout } from 'vs/base/common/async' ;
8- import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
8+ import { CancellationToken , CancellationTokenSource } from 'vs/base/common/cancellation' ;
99import { Emitter } from 'vs/base/common/event' ;
10- import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
10+ import { Disposable , DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
1111import { ResourceMap } from 'vs/base/common/map' ;
1212import { URI , UriComponents } from 'vs/base/common/uri' ;
1313import { ExtensionIdentifier , IExtensionDescription } from 'vs/platform/extensions/common/extensions' ;
1414import { ILogService } from 'vs/platform/log/common/log' ;
15+ import { Cache } from 'vs/workbench/api/common/cache' ;
1516import { ExtHostNotebookKernelsShape , ICellExecuteUpdateDto , IMainContext , INotebookKernelDto2 , MainContext , MainThreadNotebookKernelsShape , NotebookOutputDto } from 'vs/workbench/api/common/extHost.protocol' ;
1617import { ApiCommand , ApiCommandArgument , ApiCommandResult , ExtHostCommands } from 'vs/workbench/api/common/extHostCommands' ;
1718import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService' ;
@@ -20,7 +21,7 @@ import { ExtHostCell } from 'vs/workbench/api/common/extHostNotebookDocument';
2021import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters' ;
2122import { NotebookCellExecutionState as ExtHostNotebookCellExecutionState , NotebookCellOutput , NotebookControllerAffinity2 } from 'vs/workbench/api/common/extHostTypes' ;
2223import { asWebviewUri } from 'vs/workbench/contrib/webview/common/webview' ;
23- import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
24+ import { INotebookKernelSourceAction , NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
2425import { CellExecutionUpdateType } from 'vs/workbench/contrib/notebook/common/notebookExecutionService' ;
2526import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions' ;
2627import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier' ;
@@ -47,6 +48,10 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
4748 private _kernelDetectionTask = new Map < number , vscode . NotebookControllerDetectionTask > ( ) ;
4849 private _kernelDetectionTaskHandlePool : number = 0 ;
4950
51+ private _kernelSourceActionProviders = new Map < number , vscode . NotebookKernelSourceActionProvider > ( ) ;
52+ private _kernelSourceActionProviderHandlePool : number = 0 ;
53+ private _kernelSourceActionProviderCache = new Cache < IDisposable > ( 'NotebookKernelSourceActionProviderCache' ) ;
54+
5055 private readonly _kernelData = new Map < number , IKernelData > ( ) ;
5156 private _handlePool : number = 0 ;
5257
@@ -292,6 +297,33 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
292297 return detectionTask ;
293298 }
294299
300+ registerKernelSourceActionProvider ( extension : IExtensionDescription , viewType : string , provider : vscode . NotebookKernelSourceActionProvider ) {
301+ const handle = this . _kernelSourceActionProviderHandlePool ++ ;
302+ const that = this ;
303+
304+ this . _kernelSourceActionProviders . set ( handle , provider ) ;
305+ this . _logService . trace ( `NotebookKernelSourceActionProvider[${ handle } ], CREATED by ${ extension . identifier . value } ` ) ;
306+ this . _proxy . $addKernelSourceActionProvider ( handle , viewType ) ;
307+
308+ return {
309+ dispose : ( ) => {
310+ this . _kernelSourceActionProviders . delete ( handle ) ;
311+ that . _proxy . $removeKernelSourceActionProvider ( handle ) ;
312+ }
313+ } ;
314+ }
315+
316+ async $provideKernelSourceActions ( handle : number , token : CancellationToken ) : Promise < INotebookKernelSourceAction [ ] > {
317+ const provider = this . _kernelSourceActionProviders . get ( handle ) ;
318+ if ( provider ) {
319+ const disposables = new DisposableStore ( ) ;
320+ this . _kernelSourceActionProviderCache . add ( [ disposables ] ) ;
321+ const ret = await provider . provideNotebookKernelSourceActions ( token ) ;
322+ return ( ret ?? [ ] ) . map ( item => extHostTypeConverters . NotebookKernelSourceAction . from ( item , this . _commands . converter , disposables ) ) ;
323+ }
324+ return [ ] ;
325+ }
326+
295327 $acceptNotebookAssociation ( handle : number , uri : UriComponents , value : boolean ) : void {
296328 const obj = this . _kernelData . get ( handle ) ;
297329 if ( obj ) {
0 commit comments