Skip to content

Commit 6bc2ed4

Browse files
Handle new custom event structures and names (#433)
* Handle new custom event structures and names * Utilize new diagnostic structure * [email protected]
1 parent e575987 commit 6bc2ed4

File tree

8 files changed

+111
-88
lines changed

8 files changed

+111
-88
lines changed

package-lock.json

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"node-cache": "^4.2.0",
6969
"node-ssdp": "^4.0.0",
7070
"pretty-bytes": "^5.6.0",
71-
"roku-debug": "^0.15.0",
72-
"roku-deploy": "^3.8.1",
71+
"roku-debug": "^0.16.0",
72+
"roku-deploy": "^3.9.2",
7373
"roku-test-automation": "2.0.0-beta.5",
7474
"semver": "^7.1.3",
7575
"source-map": "^0.7.3",

src/LogOutputManager.spec.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Module.prototype.require = function hijacked(file) {
2020
import { DeclarationProvider } from './DeclarationProvider';
2121
import { LogDocumentLinkProvider } from './LogDocumentLinkProvider';
2222
import { LogLine, LogOutputManager } from './LogOutputManager';
23+
import type { BSDebugDiagnostic } from 'roku-debug';
24+
import { DiagnosticsEvent, LaunchStartEvent, LogOutputEvent } from 'roku-debug';
25+
import { util } from 'brighterscript';
2326

2427
describe('LogOutputManager ', () => {
2528
let logOutputManagerMock: Sinon.SinonMock;
@@ -69,34 +72,34 @@ describe('LogOutputManager ', () => {
6972
logOutputManagerMock.verify();
7073
});
7174

72-
it('tests onDidReceiveDebugSessionCustomEvent - BSLaunchStartEvent - clear flag', async () => {
75+
it('tests onDidReceiveDebugSessionCustomEvent - LaunchStartEvent - clear flag', async () => {
7376
collectionMock.expects('clear').once();
7477
logOutputManager.isClearingOutputOnLaunch = true;
75-
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: 'BSLaunchStartEvent' });
78+
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: 'LaunchStartEvent' });
7679
outputChannelMock.verify();
7780
collectionMock.verify();
7881
logOutputManagerMock.verify();
7982
});
8083

81-
it('tests onDidReceiveDebugSessionCustomEvent - BSLaunchStartEvent - no clear flag', async () => {
84+
it('tests onDidReceiveDebugSessionCustomEvent - LaunchStartEvent - no clear flag', async () => {
8285
collectionMock.expects('clear').never();
8386
logOutputManager.isClearingOutputOnLaunch = false;
84-
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: 'BSLaunchStartEvent' });
87+
await logOutputManager.onDidReceiveDebugSessionCustomEvent(new LaunchStartEvent({} as any));
8588
outputChannelMock.verify();
8689
collectionMock.verify();
8790
logOutputManagerMock.verify();
8891
});
8992

90-
it('tests onDidReceiveDebugSessionCustomEvent - BSLogOutputEvent', async () => {
93+
it('tests onDidReceiveDebugSessionCustomEvent - LogOutputEvent', async () => {
9194
outputChannelMock.expects('appendLine').once();
92-
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: 'BSLogOutputEvent', body: 'test1' });
95+
await logOutputManager.onDidReceiveDebugSessionCustomEvent(new LogOutputEvent('test 1'));
9396
outputChannelMock.verify();
9497
collectionMock.verify();
9598
logOutputManagerMock.verify();
9699
});
97100

98101
it('tests onDidReceiveDebugSessionCustomEvent - error - empty', async () => {
99-
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: '', body: [] });
102+
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: '', body: {} });
100103
outputChannelMock.verify();
101104
collectionMock.verify();
102105
logOutputManagerMock.verify();
@@ -111,8 +114,12 @@ describe('LogOutputManager ', () => {
111114

112115
it('tests onDidReceiveDebugSessionCustomEvent - errors', async () => {
113116
logOutputManagerMock.expects('addDiagnosticForError').once();
114-
let compileErrors = [{ path: 'path1', message: 'message1' }];
115-
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: '', body: compileErrors });
117+
let compileErrors: BSDebugDiagnostic[] = [{
118+
path: 'path1',
119+
message: 'message1',
120+
range: util.createRange(1, 2, 3, 4)
121+
}];
122+
await logOutputManager.onDidReceiveDebugSessionCustomEvent(new DiagnosticsEvent(compileErrors));
116123
outputChannelMock.verify();
117124
collectionMock.verify();
118125
logOutputManagerMock.verify();

src/LogOutputManager.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import type { DiagnosticCollection } from 'vscode';
3-
import type { BrightScriptDebugCompileError } from 'roku-debug';
3+
import type { BSDebugDiagnostic } from 'roku-debug';
4+
import { isChanperfEvent, isDiagnosticsEvent, isLaunchStartEvent, isLogOutputEvent, isPopupMessageEvent, isRendezvousEvent } from 'roku-debug';
45
import type { DeclarationProvider } from './DeclarationProvider';
56
import type { LogDocumentLinkProvider } from './LogDocumentLinkProvider';
67
import { CustomDocumentLink } from './LogDocumentLinkProvider';
@@ -130,16 +131,18 @@ export class LogOutputManager {
130131
}
131132

132133
public async onDidReceiveDebugSessionCustomEvent(e: { event: string; body?: any }) {
133-
if (e.event === 'BSRendezvousEvent' || e.event === 'BSChanperfEvent') {
134+
if (isRendezvousEvent(e) || isChanperfEvent(e)) {
134135
// No need to handle rendezvous type events
135136
return;
136137
}
137138

138-
if (e.event === 'BSLogOutputEvent') {
139-
this.appendLine(e.body);
140-
} else if (e.event === 'BSPopupMessageEvent') {
139+
if (isLogOutputEvent(e)) {
140+
this.appendLine(e.body.line);
141+
142+
} else if (isPopupMessageEvent(e)) {
141143
this.showMessage(e.body.message, e.body.severity);
142-
} else if (e.event === 'BSLaunchStartEvent') {
144+
145+
} else if (isLaunchStartEvent(e)) {
143146
this.isInMicroDebugger = false;
144147
this.isNextBreakpointSkipped = false;
145148
if (this.isFocusingOutputOnLaunch) {
@@ -149,14 +152,15 @@ export class LogOutputManager {
149152
if (this.isClearingOutputOnLaunch) {
150153
this.clearOutput();
151154
}
152-
} else if (e.body && Array.isArray(e.body)) {
155+
156+
} else if (isDiagnosticsEvent(e)) {
153157
let errorsByPath = {};
154-
for (const compileError of e.body) {
155-
if (compileError.path) {
156-
if (!errorsByPath[compileError.path]) {
157-
errorsByPath[compileError.path] = [];
158+
for (const diagnostic of e.body.diagnostics) {
159+
if (diagnostic.path) {
160+
if (!errorsByPath[diagnostic.path]) {
161+
errorsByPath[diagnostic.path] = [];
158162
}
159-
errorsByPath[compileError.path].push(compileError);
163+
errorsByPath[diagnostic.path].push(diagnostic);
160164
}
161165
}
162166
for (const path in errorsByPath) {
@@ -177,8 +181,7 @@ export class LogOutputManager {
177181
methods[severity](message);
178182
}
179183

180-
public async addDiagnosticForError(path: string, compileErrors: BrightScriptDebugCompileError[]) {
181-
184+
public async addDiagnosticForError(path: string, diagnostics: BSDebugDiagnostic[]) {
182185
//TODO get the actual folder
183186
let documentUri: vscode.Uri;
184187
let uri = vscode.Uri.file(path);
@@ -193,25 +196,21 @@ export class LogOutputManager {
193196
// const currentDocumentUri = document.uri;
194197
// console.log("currentDocumentUri " + currentDocumentUri);
195198
if (documentUri !== undefined) {
196-
let diagnostics: vscode.Diagnostic[] = [];
197-
for (const compileError of compileErrors) {
198-
199-
const path: string = compileError.path;
200-
const message: string = compileError.message;
201-
const source: string = compileError.errorText;
202-
const lineNumber: number = compileError.lineNumber;
203-
const charStart: number = compileError.charStart;
204-
const charEnd: number = compileError.charEnd;
205-
206-
diagnostics.push({
207-
code: '',
208-
message: message,
209-
range: new vscode.Range(new vscode.Position(lineNumber, charStart), new vscode.Position(lineNumber, charEnd)),
210-
severity: vscode.DiagnosticSeverity.Error,
211-
source: source
199+
let result: vscode.Diagnostic[] = [];
200+
for (const diagnostic of diagnostics) {
201+
result.push({
202+
code: diagnostic.code,
203+
message: diagnostic.message,
204+
source: diagnostic.source,
205+
severity: diagnostic.severity,
206+
tags: diagnostic.tags,
207+
range: new vscode.Range(
208+
new vscode.Position(diagnostic.range.start.line, diagnostic.range.start.character),
209+
new vscode.Position(diagnostic.range.end.line, diagnostic.range.end.character)
210+
)
212211
});
213212
}
214-
this.collection.set(documentUri, diagnostics);
213+
this.collection.set(documentUri, result);
215214
}
216215
}
217216

src/extension.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ describe('extension', () => {
135135
});
136136

137137
describe('debugSessionCustomEventHandler', () => {
138-
describe('BSChannelPublishedEvent', () => {
138+
describe('ChannelPublishedEvent', () => {
139139
const e = {
140-
event: 'BSChannelPublishedEvent',
140+
event: 'ChannelPublishedEvent',
141141
body: {
142142
launchConfiguration: config
143143
}

0 commit comments

Comments
 (0)