-
Notifications
You must be signed in to change notification settings - Fork 188
/
extension.ts
81 lines (65 loc) · 2.39 KB
/
extension.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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import { WorkspaceFolder, DebugConfiguration, ProviderResult, CancellationToken } from 'vscode';
import { MockDebugSession } from './mockDebug';
import * as Net from 'net';
const EMBED_DEBUG_ADAPTER = false;
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('extension.mock-debug.getProgramName', config => {
return vscode.window.showInputBox({
placeHolder: "Please enter the name of a markdown file in the workspace folder",
value: "readme.md"
});
}));
// register a configuration provider for 'mock' debug type
const provider = new MockConfigurationProvider()
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('mock', provider));
context.subscriptions.push(provider);
}
export function deactivate() {
// nothing to do
}
class MockConfigurationProvider implements vscode.DebugConfigurationProvider {
private _server?: Net.Server;
/**
* Massage a debug configuration just before a debug session is being launched,
* e.g. add all missing attributes to the debug configuration.
*/
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, config: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {
// if launch.json is missing or empty
if (!config.type && !config.request && !config.name) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId === 'markdown' ) {
config.type = 'mock';
config.name = 'Launch';
config.request = 'launch';
config.program = '${file}';
config.stopOnEntry = true;
}
}
if (!config.program) {
return vscode.window.showInformationMessage("Cannot find a program to debug").then(_ => {
return undefined; // abort launch
});
}
if (EMBED_DEBUG_ADAPTER) {
if (!this._server) {
this._server = Net.createServer(socket => {
const session = new MockDebugSession();
session.setRunAsServer(true);
session.start(<NodeJS.ReadableStream>socket, socket);
}).listen(0);
}
config.debugServer = this._server.address().port;
}
return config;
}
dispose() {
if (this._server) {
this._server.close();
}
}
}