/**
 * Copyright (c) Microsoft Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { renderTitleForCall } from '@isomorphic/protocolFormatter';
import { Dispatcher } from './dispatcher';
import { Debugger } from '../debugger';
export class DebuggerDispatcher extends Dispatcher {
    _type_EventTarget = true;
    _type_Debugger = true;
    static from(scope, debugger_) {
        const result = scope.connection.existingDispatcher(debugger_);
        return result || new DebuggerDispatcher(scope, debugger_);
    }
    constructor(scope, debugger_) {
        super(scope, debugger_, 'Debugger', {});
        this.addObjectListener(Debugger.Events.PausedStateChanged, () => {
            this._dispatchEvent('pausedStateChanged', { pausedDetails: this._serializePausedDetails() });
        });
        this._dispatchEvent('pausedStateChanged', { pausedDetails: this._serializePausedDetails() });
    }
    _serializePausedDetails() {
        const details = this._object.pausedDetails();
        if (!details)
            return undefined;
        const { metadata } = details;
        return {
            location: {
                file: metadata.location?.file ?? '<unknown>',
                line: metadata.location?.line,
                column: metadata.location?.column,
            },
            title: renderTitleForCall(metadata),
        };
    }
    async requestPause(params, progress) {
        this._object.requestPause(progress);
    }
    async resume(params, progress) {
        this._object.doResume(progress);
    }
    async next(params, progress) {
        this._object.next(progress);
    }
    async runTo(params, progress) {
        this._object.runTo(progress, params.location);
    }
}
//# sourceMappingURL=debuggerDispatcher.js.map