import*as Bindings from"../bindings/bindings.js";export class LanguageExtensionEndpoint extends Bindings.DebuggerLanguagePlugins.DebuggerLanguagePlugin{constructor(e,s,n){super(e),this._commands=Extensions.extensionAPI.LanguageExtensionPluginCommands,this._events=Extensions.extensionAPI.LanguageExtensionPluginEvents,this._supportedScriptTypes=s,this._port=n,this._port.onmessage=this._onResponse.bind(this),this._nextRequestId=0,this._pendingRequests=new Map}_sendRequest(e,s){return new Promise(((n,t)=>{const o=this._nextRequestId++;this._pendingRequests.set(o,{resolve:n,reject:t}),this._port.postMessage({requestId:o,method:e,parameters:s})}))}_onResponse({data:e}){if("event"in e){const{event:s}=e;switch(s){case this._events.UnregisteredLanguageExtensionPlugin:{for(const{reject:s}of this._pendingRequests.values())s(new Error("Language extension endpoint disconnected"));this._pendingRequests.clear(),this._port.close();const{pluginManager:e}=Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance();e&&e.removePlugin(this);break}}return}const{requestId:s,result:n,error:t}=e;if(!this._pendingRequests.has(s))return void console.error(`No pending request ${s}`);const{resolve:o,reject:i}=this._pendingRequests.get(s);this._pendingRequests.delete(s),t?i(new Error(t.message)):o(n)}handleScript(e){const s=e.scriptLanguage();return null!==s&&null!==e.debugSymbols&&s===this._supportedScriptTypes.language&&this._supportedScriptTypes.symbol_types.includes(e.debugSymbols.type)}addRawModule(e,s,n){return this._sendRequest(this._commands.AddRawModule,{rawModuleId:e,symbolsURL:s,rawModule:n})}removeRawModule(e){return this._sendRequest(this._commands.RemoveRawModule,{rawModuleId:e})}sourceLocationToRawLocation(e){return this._sendRequest(this._commands.SourceLocationToRawLocation,{sourceLocation:e})}rawLocationToSourceLocation(e){return this._sendRequest(this._commands.RawLocationToSourceLocation,{rawLocation:e})}getScopeInfo(e){return this._sendRequest(this._commands.GetScopeInfo,{type:e})}listVariablesInScope(e){return this._sendRequest(this._commands.ListVariablesInScope,{rawLocation:e})}getFunctionInfo(e){return this._sendRequest(this._commands.GetFunctionInfo,{rawLocation:e})}getInlinedFunctionRanges(e){return this._sendRequest(this._commands.GetInlinedFunctionRanges,{rawLocation:e})}getInlinedCalleesRanges(e){return this._sendRequest(this._commands.GetInlinedCalleesRanges,{rawLocation:e})}getTypeInfo(e,s){return this._sendRequest(this._commands.GetTypeInfo,{expression:e,context:s})}getFormatter(e,s){return this._sendRequest(this._commands.GetFormatter,{expressionOrField:e,context:s})}getInspectableAddress(e){return this._sendRequest(this._commands.GetInspectableAddress,{field:e})}async getMappedLines(e,s){return this._sendRequest(this._commands.GetMappedLines,{rawModuleId:e,sourceFileURL:s})}dispose(){}}