"use strict";(self.webpackChunk_elyra_script_debugger_extension=self.webpackChunk_elyra_script_debugger_extension||[]).push([[509],{509:function(e,n,t){var o=this&&this.__awaiter||function(e,n,t,o){return new(t||(t=Promise))((function(i,c){function r(e){try{s(o.next(e))}catch(e){c(e)}}function a(e){try{s(o.throw(e))}catch(e){c(e)}}function s(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(r,a)}s((o=o.apply(e,n||[])).next())}))};Object.defineProperty(n,"__esModule",{value:!0});const i=t(85),c=t(909),r=t(34),a=t(710),s=t(354),l={id:"elyra-script-debugger",autoStart:!0,requires:[r.IDebugger,a.IEditorTracker],optional:[c.ILabShell],activate:(e,n,t,c)=>{console.log("Elyra - script-debugger extension is activated!");const a=new r.Debugger.Handler({type:"file",shell:e.shell,service:n}),l={},d=new s.KernelManager,u=new s.SessionManager({kernelManager:d}),f=n=>o(void 0,void 0,void 0,(function*(){const t=e.shell.currentWidget;if(n!==t)return;const i=n.kernelSelection,c=e.serviceManager.sessions;try{const t=n.context.path;let r=yield c.findByPath(t);if(!r){const e=yield v(i,t);r=yield c.findByPath(t),e&&r&&(l[r.id]=e)}if(r){let t=l[r.id];t||(t=c.connectTo({model:r}),l[r.id]=t),yield y(t,i),setTimeout((()=>o(void 0,void 0,void 0,(function*(){yield a.update(n,t),e.commands.notifyCommandChanged()}))),500)}}catch(e){console.warn("Exception: session connection = "+JSON.stringify(e))}})),g=new WeakMap,h=e=>o(void 0,void 0,void 0,(function*(){if(e instanceof i.ScriptEditor){let n=g.get(e);n||(n=()=>f(e),g.set(e,n)),f(e),e.kernelSelectionChanged.disconnect(n),e.kernelSelectionChanged.connect(n)}}));c&&c.currentChanged.connect(((e,n)=>h(n.newValue))),t&&t.currentChanged.connect(((e,n)=>h(n)));const v=(e,n)=>o(void 0,void 0,void 0,(function*(){const t={kernel:{name:e},path:n,type:"file",name:n};let o=null;try{e&&(o=yield u.startNew(t),o.setPath(n),console.log(`Kernel session started for ${e} kernel`))}catch(e){console.warn("Exception: start session = "+JSON.stringify(e))}return o})),y=(e,n)=>o(void 0,void 0,void 0,(function*(){var t;try{const o=null===(t=e.kernel)||void 0===t?void 0:t.name;n&&o!==n&&(yield e.changeKernel({name:n}),console.log(`Kernel change from ${o} to ${n}`))}catch(e){console.warn("Exception: change kernel = "+JSON.stringify(e))}}))}};n.default=l}}]);