/
debug-session-contribution.ts
150 lines (138 loc) · 5.96 KB
/
debug-session-contribution.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// *****************************************************************************
// Copyright (C) 2018 Red Hat, Inc. and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { injectable, inject, named, postConstruct } from '@theia/core/shared/inversify';
import { MessageClient } from '@theia/core/lib/common';
import { LabelProvider } from '@theia/core/lib/browser';
import { EditorManager } from '@theia/editor/lib/browser';
import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
import { DebugSession } from './debug-session';
import { BreakpointManager } from './breakpoint/breakpoint-manager';
import { DebugConfigurationSessionOptions, DebugSessionOptions } from './debug-session-options';
import { OutputChannelManager, OutputChannel } from '@theia/output/lib/browser/output-channel';
import { DebugPreferences } from './debug-preferences';
import { DebugSessionConnection } from './debug-session-connection';
import { DebugChannel, DebugAdapterPath, ForwardingDebugChannel } from '../common/debug-service';
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { DebugContribution } from './debug-contribution';
import { WorkspaceService } from '@theia/workspace/lib/browser';
/**
* DebugSessionContribution symbol for DI.
*/
export const DebugSessionContribution = Symbol('DebugSessionContribution');
/**
* The [debug session](#DebugSession) contribution.
* Can be used to instantiate a specific debug sessions.
*/
export interface DebugSessionContribution {
/**
* The debug type.
*/
debugType: string;
/**
* The [debug session](#DebugSession) factory.
*/
debugSessionFactory(): DebugSessionFactory;
}
/**
* DebugSessionContributionRegistry symbol for DI.
*/
export const DebugSessionContributionRegistry = Symbol('DebugSessionContributionRegistry');
/**
* Debug session contribution registry.
*/
export interface DebugSessionContributionRegistry {
get(debugType: string): DebugSessionContribution | undefined;
}
@injectable()
export class DebugSessionContributionRegistryImpl implements DebugSessionContributionRegistry {
protected readonly contribs = new Map<string, DebugSessionContribution>();
@inject(ContributionProvider) @named(DebugSessionContribution)
protected readonly contributions: ContributionProvider<DebugSessionContribution>;
@postConstruct()
protected init(): void {
for (const contrib of this.contributions.getContributions()) {
this.contribs.set(contrib.debugType, contrib);
}
}
get(debugType: string): DebugSessionContribution | undefined {
return this.contribs.get(debugType);
}
}
/**
* DebugSessionFactory symbol for DI.
*/
export const DebugSessionFactory = Symbol('DebugSessionFactory');
/**
* The [debug session](#DebugSession) factory.
*/
export interface DebugSessionFactory {
get(sessionId: string, options: DebugSessionOptions, parentSession?: DebugSession): DebugSession;
}
@injectable()
export class DefaultDebugSessionFactory implements DebugSessionFactory {
@inject(WebSocketConnectionProvider)
protected readonly connectionProvider: WebSocketConnectionProvider;
@inject(TerminalService)
protected readonly terminalService: TerminalService;
@inject(EditorManager)
protected readonly editorManager: EditorManager;
@inject(BreakpointManager)
protected readonly breakpoints: BreakpointManager;
@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;
@inject(MessageClient)
protected readonly messages: MessageClient;
@inject(OutputChannelManager)
protected readonly outputChannelManager: OutputChannelManager;
@inject(DebugPreferences)
protected readonly debugPreferences: DebugPreferences;
@inject(FileService)
protected readonly fileService: FileService;
@inject(ContributionProvider) @named(DebugContribution)
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>;
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;
get(sessionId: string, options: DebugConfigurationSessionOptions, parentSession?: DebugSession): DebugSession {
const connection = new DebugSessionConnection(
sessionId,
() => new Promise<DebugChannel>(resolve =>
this.connectionProvider.openChannel(`${DebugAdapterPath}/${sessionId}`, wsChannel => {
resolve(new ForwardingDebugChannel(wsChannel));
}, { reconnecting: false })
),
this.getTraceOutputChannel());
return new DebugSession(
sessionId,
options,
parentSession,
connection,
this.terminalService,
this.editorManager,
this.breakpoints,
this.labelProvider,
this.messages,
this.fileService,
this.debugContributionProvider,
this.workspaceService);
}
protected getTraceOutputChannel(): OutputChannel | undefined {
if (this.debugPreferences['debug.trace']) {
return this.outputChannelManager.getChannel('Debug adapters');
}
}
}