11import * as vscode from 'vscode' ;
22import 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' ;
45import type { DeclarationProvider } from './DeclarationProvider' ;
56import type { LogDocumentLinkProvider } from './LogDocumentLinkProvider' ;
67import { 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
0 commit comments