-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextension.ts
150 lines (132 loc) · 7.47 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
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
import * as vscode from 'vscode';
import { CXXRTLDebugger } from './debugger';
import * as sidebar from './ui/sidebar';
import { globalWatchList } from './debug/watch';
import { globalVariableOptions } from './debug/options';
import { HoverProvider } from './ui/hover';
import { DiagnosticProvider } from './ui/diagnostic';
import { inputTime } from './ui/input';
import { WaveformProvider } from './ui/waveform';
export function activate(context: vscode.ExtensionContext) {
const rtlDebugger = new CXXRTLDebugger();
const sidebarTreeDataProvider = new sidebar.TreeDataProvider(rtlDebugger);
const sidebarTreeView = vscode.window.createTreeView('rtlDebugger.sidebar', {
treeDataProvider: sidebarTreeDataProvider
});
context.subscriptions.push(sidebarTreeView);
const hoverProvider = new HoverProvider(rtlDebugger);
for (const language of HoverProvider.SUPPORTED_LANGUAGES) {
context.subscriptions.push(vscode.languages.registerHoverProvider(language, hoverProvider));
}
const diagnosticCollection = vscode.languages.createDiagnosticCollection('rtlDebugger');
const diagnosticProvider = new DiagnosticProvider(rtlDebugger, diagnosticCollection);
context.subscriptions.push(diagnosticProvider);
vscode.commands.executeCommand('setContext', 'rtlDebugger.sessionStatus', rtlDebugger.sessionStatus);
context.subscriptions.push(rtlDebugger.onDidChangeSessionStatus((state) =>
vscode.commands.executeCommand('setContext', 'rtlDebugger.sessionStatus', state)));
vscode.commands.executeCommand('setContext', 'rtlDebugger.simulationStatus', rtlDebugger.simulationStatus);
context.subscriptions.push(rtlDebugger.onDidChangeSimulationStatus((state) =>
vscode.commands.executeCommand('setContext', 'rtlDebugger.simulationStatus', state)));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.startSession', () =>
rtlDebugger.startSession()));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.stopSession', () =>
rtlDebugger.stopSession()));
context.subscriptions.push({ dispose: () => rtlDebugger.stopSession() });
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.runSimulation', () =>
rtlDebugger.session!.runSimulation()));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.pauseSimulation', () =>
rtlDebugger.session!.pauseSimulation()));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.runPauseSimulation', () => {
if (rtlDebugger.session!.isSimulationRunning) {
rtlDebugger.session!.pauseSimulation();
} else {
rtlDebugger.session!.runSimulation();
}
}));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.runSimulationUntil', async () => {
const untilTime = await inputTime({ prompt: 'Enter the time to simulate until.' });
if (untilTime !== undefined) {
rtlDebugger.session!.runSimulation({ untilTime });
}
}));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.stepBackward', () =>
rtlDebugger.session!.stepBackward()));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.stepForward', () =>
rtlDebugger.session!.stepForward()));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.continueForward', () =>
rtlDebugger.session!.continueForward()));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.goToTime', async () => {
const goToTime = await inputTime({ prompt: 'Enter the time to examine the state at.' });
if (goToTime !== undefined) {
if (rtlDebugger.session!.simulationStatus.latestTime.lessThan(goToTime)) {
vscode.window.showErrorMessage(`The simulation has not advanced to ${goToTime} yet.`);
} else {
rtlDebugger.session!.timeCursor = goToTime;
}
}
}));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.addToWaveform', (treeItem) => {
if (rtlDebugger.lastActiveWaveformTab) {
console.log(rtlDebugger.lastActiveWaveformTab);
const target = rtlDebugger.waveformProviders.get(rtlDebugger.lastActiveWaveformTab);
if (target) {
target.addVariable(treeItem.designation.variable);
}
}
}));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.2', (treeItem) =>
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier, { radix: 2 })));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.8', (treeItem) =>
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier, { radix: 8 })));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.10', (treeItem) =>
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier, { radix: 10 })));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.16', (treeItem) =>
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier, { radix: 16 })));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.watchVariable', (treeItem) =>
globalWatchList.append(treeItem.getWatchItem())));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.unWatchVariable', (treeItem) =>
globalWatchList.remove(treeItem.metadata.index)));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.browseWaveforms', () => {
const viewKey = `rtlDebugger.waveforms.${rtlDebugger.nextWaveformviewId++}`;
const webviewPanel = vscode.window.createWebviewPanel(
viewKey,
'Waveforms',
{
viewColumn: vscode.ViewColumn.Beside,
},
{
enableScripts: true,
retainContextWhenHidden: true,
}
);
console.log(`Creating web view panel with viewType ${webviewPanel.viewType}`);
const bundleRoot = vscode.Uri.joinPath(context.extensionUri, 'out/');
const waveformProvider = new WaveformProvider(rtlDebugger, webviewPanel, bundleRoot);
rtlDebugger.waveformProviders.set(viewKey, waveformProvider);
rtlDebugger.lastActiveWaveformTab = viewKey;
context.subscriptions.push(waveformProvider);
}));
vscode.window.tabGroups.onDidChangeTabs(event => {
const activeWaveformTab = event.changed.map((tab, _) => {
if (tab.input instanceof vscode.TabInputWebview) {
console.log(`${tab.input.viewType}`);
const key = tab.input.viewType.match(/.*(rtlDebugger.waveforms\.\d+)/);
if (key) {
return key[1];
} else {
return null;
}
} else {
return null;
}
}).find((id) => id !== null);
if (activeWaveformTab) {
rtlDebugger.lastActiveWaveformTab = activeWaveformTab;
}
});
// For an unknown reason, the `vscode.open` command (which does the exact same thing) ignores the options.
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.openDocument',
(uri: vscode.Uri, options: vscode.TextDocumentShowOptions) => {
vscode.window.showTextDocument(uri, options);
}));
}