forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathdebugLocationTrackerFactory.ts
More file actions
61 lines (53 loc) · 2.08 KB
/
debugLocationTrackerFactory.ts
File metadata and controls
61 lines (53 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import {
DebugAdapterTracker,
DebugAdapterTrackerFactory,
DebugSession,
Event,
EventEmitter,
ProviderResult
} from 'vscode';
import { IDebugService } from '../common/application/types';
import { IDisposableRegistry } from '../common/types';
import { DebugLocationTracker } from './debugLocationTracker';
import { IDebugLocationTracker } from './types';
// Hook up our IDebugLocationTracker to python debugging sessions
@injectable()
export class DebugLocationTrackerFactory implements IDebugLocationTracker, DebugAdapterTrackerFactory {
private activeTrackers: Map<string, DebugLocationTracker> = new Map<string, DebugLocationTracker>();
private updatedEmitter: EventEmitter<void> = new EventEmitter<void>();
constructor(
@inject(IDebugService) debugService: IDebugService,
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry
) {
disposableRegistry.push(debugService.registerDebugAdapterTrackerFactory('python', this));
}
public createDebugAdapterTracker(session: DebugSession): ProviderResult<DebugAdapterTracker> {
const result = new DebugLocationTracker(session.id);
this.activeTrackers.set(session.id, result);
result.sessionEnded(this.onSessionEnd.bind(this));
result.debugLocationUpdated(this.onLocationUpdated.bind(this));
this.onLocationUpdated();
return result;
}
public get updated(): Event<void> {
return this.updatedEmitter.event;
}
public getLocation(session: DebugSession) {
const tracker = this.activeTrackers.get(session.id);
if (tracker) {
return tracker.debugLocation;
}
}
private onSessionEnd(locationTracker: DebugLocationTracker) {
if (locationTracker.sessionId) {
this.activeTrackers.delete(locationTracker.sessionId);
}
}
private onLocationUpdated() {
this.updatedEmitter.fire();
}
}