UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 13.7 kB
import*as Common from"../../core/common/common.js";import*as Host from"../../core/host/host.js";import*as i18n from"../../core/i18n/i18n.js";import*as Platform from"../../core/platform/platform.js";import*as SDK from"../../core/sdk/sdk.js";import*as Bindings from"../../models/bindings/bindings.js";import*as Persistence from"../../models/persistence/persistence.js";import*as SourceMapScopes from"../../models/source_map_scopes/source_map_scopes.js";import*as UI from"../../ui/legacy/legacy.js";import*as IconButton from"../../ui/components/icon_button/icon_button.js";import callStackSidebarPaneStyles from"./callStackSidebarPane.css.js";const UIStrings={callStack:"Call Stack",notPaused:"Not paused",onIgnoreList:"on ignore list",showIgnorelistedFrames:"Show ignore-listed frames",showMore:"Show more",copyStackTrace:"Copy stack trace",callFrameWarnings:"Some call frames have warnings",debugFileNotFound:'Failed to load debug file "{PH1}".',restartFrame:"Restart frame"},str_=i18n.i18n.registerUIStrings("panels/sources/CallStackSidebarPane.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let callstackSidebarPaneInstance;export class CallStackSidebarPane extends UI.View.SimpleView{ignoreListMessageElement;ignoreListCheckboxElement;notPausedMessageElement;callFrameWarningsElement;items;list;showMoreMessageElement;showIgnoreListed;locationPool;updateThrottler;maxAsyncStackChainDepth;updateItemThrottler;scheduledForUpdateItems;muteActivateItem;lastDebuggerModel=null;constructor(){super(i18nString(UIStrings.callStack),!0),({element:this.ignoreListMessageElement,checkbox:this.ignoreListCheckboxElement}=this.createIgnoreListMessageElementAndCheckbox()),this.contentElement.appendChild(this.ignoreListMessageElement),this.notPausedMessageElement=this.contentElement.createChild("div","gray-info-message"),this.notPausedMessageElement.textContent=i18nString(UIStrings.notPaused),this.notPausedMessageElement.tabIndex=-1,this.callFrameWarningsElement=this.contentElement.createChild("div","call-frame-warnings-message");const e=new IconButton.Icon.Icon;e.data={iconName:"warning-filled",color:"var(--icon-warning)",width:"14px",height:"14px"},e.classList.add("call-frame-warning-icon"),this.callFrameWarningsElement.appendChild(e),this.callFrameWarningsElement.appendChild(document.createTextNode(i18nString(UIStrings.callFrameWarnings))),this.callFrameWarningsElement.tabIndex=-1,this.items=new UI.ListModel.ListModel,this.list=new UI.ListControl.ListControl(this.items,this,UI.ListControl.ListMode.NonViewport),this.contentElement.appendChild(this.list.element),this.list.element.addEventListener("contextmenu",this.onContextMenu.bind(this),!1),self.onInvokeElement(this.list.element,(e=>{const t=this.list.itemForNode(e.target);t&&(this.activateItem(t),e.consume(!0))})),this.showMoreMessageElement=this.createShowMoreMessageElement(),this.showMoreMessageElement.classList.add("hidden"),this.contentElement.appendChild(this.showMoreMessageElement),this.showIgnoreListed=!1,this.locationPool=new Bindings.LiveLocation.LiveLocationPool,this.updateThrottler=new Common.Throttler.Throttler(100),this.maxAsyncStackChainDepth=defaultMaxAsyncStackChainDepth,this.update(),this.updateItemThrottler=new Common.Throttler.Throttler(100),this.scheduledForUpdateItems=new Set,SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebugInfoAttached,this.debugInfoAttached,this)}static instance(e={forceNew:null}){const{forceNew:t}=e;return callstackSidebarPaneInstance&&!t||(callstackSidebarPaneInstance=new CallStackSidebarPane),callstackSidebarPaneInstance}flavorChanged(e){this.showIgnoreListed=!1,this.ignoreListCheckboxElement.checked=!1,this.maxAsyncStackChainDepth=defaultMaxAsyncStackChainDepth,this.update()}debugInfoAttached(){this.update()}setSourceMapSubscription(e){this.lastDebuggerModel!==e&&(this.lastDebuggerModel&&this.lastDebuggerModel.sourceMapManager().removeEventListener(SDK.SourceMapManager.Events.SourceMapAttached,this.debugInfoAttached,this),this.lastDebuggerModel=e,this.lastDebuggerModel&&this.lastDebuggerModel.sourceMapManager().addEventListener(SDK.SourceMapManager.Events.SourceMapAttached,this.debugInfoAttached,this))}update(){this.updateThrottler.schedule((()=>this.doUpdate()))}async doUpdate(){this.locationPool.disposeAll(),this.callFrameWarningsElement.classList.add("hidden");const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.DebuggerPausedDetails);if(this.setSourceMapSubscription(e?.debuggerModel??null),!e)return this.notPausedMessageElement.classList.remove("hidden"),this.ignoreListMessageElement.classList.add("hidden"),this.showMoreMessageElement.classList.add("hidden"),this.items.replaceAll([]),void UI.Context.Context.instance().setFlavor(SDK.DebuggerModel.CallFrame,null);this.notPausedMessageElement.classList.add("hidden");const t=[],s=new Set;for(const i of e.callFrames){const e=Item.createForDebuggerCallFrame(i,this.locationPool,this.refreshItem.bind(this)).then((e=>(itemToCallFrame.set(e,i),e)));t.push(e),i.missingDebugInfoDetails&&s.add(i.missingDebugInfoDetails.details)}const i=await Promise.all(t);s.size&&(this.callFrameWarningsElement.classList.remove("hidden"),UI.Tooltip.Tooltip.install(this.callFrameWarningsElement,Array.from(s).join("\n")));let n=e.debuggerModel,a=e.asyncStackTraceId,o=e.asyncStackTrace,r=e.callFrames;for(let{maxAsyncStackChainDepth:e}=this;e>0;--e){if(!o){if(!a)break;if(a.debuggerId){const e=await SDK.DebuggerModel.DebuggerModel.modelForDebuggerId(a.debuggerId);if(!e)break;n=e}if(o=await n.fetchAsyncStackTrace(a),!o)break}const e=UI.UIUtils.asyncStackTraceLabel(o.description,r);i.push(...await Item.createItemsForAsyncStack(e,n,o.callFrames,this.locationPool,this.refreshItem.bind(this))),r=o.callFrames,a=o.parentId,o=o.parent}this.showMoreMessageElement.classList.toggle("hidden",!o),this.items.replaceAll(i);for(const e of this.items)this.refreshItem(e);if(this.maxAsyncStackChainDepth===defaultMaxAsyncStackChainDepth){this.list.selectNextItem(!0,!1);const e=this.list.selectedItem();e&&this.activateItem(e)}this.updatedForTest()}updatedForTest(){}refreshItem(e){this.scheduledForUpdateItems.add(e),this.updateItemThrottler.schedule((async()=>{const e=Array.from(this.scheduledForUpdateItems);if(this.scheduledForUpdateItems.clear(),this.muteActivateItem=!0,!this.showIgnoreListed&&this.items.every((e=>e.isIgnoreListed))){this.showIgnoreListed=!0;for(let e=0;e<this.items.length;++e)this.list.refreshItemByIndex(e);this.ignoreListMessageElement.classList.toggle("hidden",!0)}else{this.showIgnoreListed=this.ignoreListCheckboxElement.checked;const t=new Set(e);let s=!1;for(let e=0;e<this.items.length;++e){const i=this.items.at(e);t.has(i)&&this.list.refreshItemByIndex(e),s=s||i.isIgnoreListed}this.ignoreListMessageElement.classList.toggle("hidden",!s)}delete this.muteActivateItem}))}createElementForItem(e){const t=document.createElement("div");t.classList.add("call-frame-item");const s=t.createChild("div","call-frame-item-title").createChild("div","call-frame-title-text");if(s.textContent=e.title,e.isAsyncHeader)t.classList.add("async-header");else{UI.Tooltip.Tooltip.install(s,e.title);const i=t.createChild("div","call-frame-location");i.textContent=Platform.StringUtilities.trimMiddle(e.linkText,30),UI.Tooltip.Tooltip.install(i,e.linkText),t.classList.toggle("ignore-listed-call-frame",e.isIgnoreListed),e.isIgnoreListed&&UI.ARIAUtils.setDescription(t,i18nString(UIStrings.onIgnoreList)),itemToCallFrame.has(e)||UI.ARIAUtils.setDisabled(t,!0)}const i=itemToCallFrame.get(e),n=i===UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);t.classList.toggle("selected",n),UI.ARIAUtils.setSelected(t,n),t.classList.toggle("hidden",!this.showIgnoreListed&&e.isIgnoreListed);const a=new IconButton.Icon.Icon;if(a.data={iconName:"large-arrow-right-filled",color:"var(--icon-arrow-main-thread)",width:"14px",height:"14px"},a.classList.add("selected-call-frame-icon"),t.appendChild(a),t.tabIndex=e===this.list.selectedItem()?0:-1,i&&i.missingDebugInfoDetails){const e=new IconButton.Icon.Icon;e.data={iconName:"warning-filled",color:"var(--icon-warning)",width:"14px",height:"14px"},e.classList.add("call-frame-warning-icon");const s=i.missingDebugInfoDetails.resources.map((e=>i18nString(UIStrings.debugFileNotFound,{PH1:e})));UI.Tooltip.Tooltip.install(e,[i.missingDebugInfoDetails.details,...s].join("\n")),t.appendChild(e)}return t}heightForItem(e){return console.assert(!1),0}isItemSelectable(e){return!0}selectedItemChanged(e,t,s,i){s&&(s.tabIndex=-1),i&&(this.setDefaultFocusedElement(i),i.tabIndex=0,this.hasFocus()&&i.focus())}updateSelectedItemARIA(e,t){return!0}createIgnoreListMessageElementAndCheckbox(){const e=document.createElement("div");e.classList.add("ignore-listed-message");const t=e.createChild("label");t.classList.add("ignore-listed-message-label");const s=t.createChild("input");s.tabIndex=0,s.type="checkbox",s.classList.add("ignore-listed-checkbox"),t.append(i18nString(UIStrings.showIgnorelistedFrames));return s.addEventListener("click",(()=>{this.showIgnoreListed=s.checked;for(const e of this.items)this.refreshItem(e)})),{element:e,checkbox:s}}createShowMoreMessageElement(){const e=document.createElement("div");e.classList.add("show-more-message"),e.createChild("span");const t=e.createChild("span","link");return t.textContent=i18nString(UIStrings.showMore),t.addEventListener("click",(()=>{this.maxAsyncStackChainDepth+=defaultMaxAsyncStackChainDepth,this.update()}),!1),e}onContextMenu(e){const t=this.list.itemForNode(e.target);if(!t)return;const s=new UI.ContextMenu.ContextMenu(e),i=itemToCallFrame.get(t);i&&s.defaultSection().appendItem(i18nString(UIStrings.restartFrame),(()=>{Host.userMetrics.actionTaken(Host.UserMetrics.Action.StackFrameRestarted),i.restart()}),!i.canBeRestarted),s.defaultSection().appendItem(i18nString(UIStrings.copyStackTrace),this.copyStackTrace.bind(this)),t.uiLocation&&this.appendIgnoreListURLContextMenuItems(s,t.uiLocation.uiSourceCode),s.show()}onClick(e){const t=this.list.itemForNode(e.target);t&&this.activateItem(t)}activateItem(e){const t=e.uiLocation;if(this.muteActivateItem||!t)return;this.list.selectItem(e);const s=itemToCallFrame.get(e),i=this.activeCallFrameItem();s&&i!==e?(s.debuggerModel.setSelectedCallFrame(s),UI.Context.Context.instance().setFlavor(SDK.DebuggerModel.CallFrame,s),i&&this.refreshItem(i),this.refreshItem(e)):Common.Revealer.reveal(t)}activeCallFrameItem(){const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);return e&&this.items.find((t=>itemToCallFrame.get(t)===e))||null}appendIgnoreListURLContextMenuItems(e,t){const s=Persistence.Persistence.PersistenceImpl.instance().binding(t);s&&(t=s.network);const i=e.section("ignoreList");if(!(i.items.length>0))for(const{text:e,callback:s}of Bindings.IgnoreListManager.IgnoreListManager.instance().getIgnoreListURLContextMenuItems(t))i.appendItem(e,s)}selectNextCallFrameOnStack(){const e=this.activeCallFrameItem();for(let t=e?this.items.indexOf(e)+1:0;t<this.items.length;t++){const e=this.items.at(t);if(itemToCallFrame.has(e)){this.activateItem(e);break}}}selectPreviousCallFrameOnStack(){const e=this.activeCallFrameItem();for(let t=e?this.items.indexOf(e)-1:this.items.length-1;t>=0;t--){const e=this.items.at(t);if(itemToCallFrame.has(e)){this.activateItem(e);break}}}copyStackTrace(){const e=[];for(const t of this.items){let s=t.title;t.uiLocation&&(s+=" ("+t.uiLocation.linkText(!0)+")"),e.push(s)}Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(e.join("\n"))}wasShown(){super.wasShown(),this.registerCSSFiles([callStackSidebarPaneStyles])}}const itemToCallFrame=new WeakMap;export const elementSymbol=Symbol("element");export const defaultMaxAsyncStackChainDepth=32;let actionDelegateInstance;export class ActionDelegate{static instance(e={forceNew:null}){const{forceNew:t}=e;return actionDelegateInstance&&!t||(actionDelegateInstance=new ActionDelegate),actionDelegateInstance}handleAction(e,t){switch(t){case"debugger.next-call-frame":return CallStackSidebarPane.instance().selectNextCallFrameOnStack(),!0;case"debugger.previous-call-frame":return CallStackSidebarPane.instance().selectPreviousCallFrameOnStack(),!0}return!1}}export class Item{isIgnoreListed;title;linkText;uiLocation;isAsyncHeader;updateDelegate;static async createForDebuggerCallFrame(e,t,s){const i=e.functionName,n=new Item(UI.UIUtils.beautifyFunctionName(i),s);return await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createCallFrameLiveLocation(e.location(),n.update.bind(n),t),SourceMapScopes.NamesResolver.resolveDebuggerFrameFunctionName(e).then((e=>{e&&e!==i&&(n.title=e,n.updateDelegate(n))})),n}static async createItemsForAsyncStack(e,t,s,i,n){const a=new WeakMap,o=new Item(e,n);a.set(o,new Set),o.isAsyncHeader=!0;const r=[],l=[];for(const e of s){const s=new Item(UI.UIUtils.beautifyFunctionName(e.functionName),c),n=t.createRawLocationByScriptId(e.scriptId,e.lineNumber,e.columnNumber);l.push(Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createCallFrameLiveLocation(n,s.update.bind(s),i)),r.push(s)}return await Promise.all(l),n(o),[o,...r];function c(e){n(e);let t=!1;const s=a.get(o);s&&(e.isIgnoreListed?(s.delete(e),t=0===s.size):(t=0===s.size,s.add(e)),o.isIgnoreListed=0===s.size),t&&n(o)}}constructor(e,t){this.isIgnoreListed=!1,this.title=e,this.linkText="",this.uiLocation=null,this.isAsyncHeader=!1,this.updateDelegate=t}async update(e){const t=await e.uiLocation();this.isIgnoreListed=await e.isIgnoreListed(),this.linkText=t?t.linkText():"",this.uiLocation=t,this.updateDelegate(this)}}