@@ -54,17 +54,18 @@ import { findAllReferences } from "./references";
54
54
import { registerDebugDecorator , unregisterDebugDecorator } from "./tokenizer/debug-decorator" ;
55
55
import { clearTokenCache } from "./tokenizer/tokenizer" ;
56
56
import { getSignatureHelp } from "./signature" ;
57
+ import { LogCategory , LogLevel , logCatMessage , logMessage , logToast } from "./logger" ;
57
58
58
59
const selector : DocumentSelector = { scheme : "file" , language : "renpy" } ;
59
60
let myStatusBarItem : StatusBarItem ;
60
61
61
62
export async function activate ( context : ExtensionContext ) : Promise < void > {
62
- console . log ( "Ren'Py extension activated" ) ;
63
+ logMessage ( LogLevel . Info , "Ren'Py extension activated" ) ;
63
64
64
65
const filepath = getNavigationJsonFilepath ( ) ;
65
66
const jsonFileExists = fs . existsSync ( filepath ) ;
66
67
if ( ! jsonFileExists ) {
67
- console . log ( "Navigation.json file is missing." ) ;
68
+ logMessage ( LogLevel . Warning , "Navigation.json file is missing." ) ;
68
69
}
69
70
70
71
// hide rpyc files if the setting is enabled
@@ -224,7 +225,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
224
225
try {
225
226
await NavigationData . refresh ( true ) ;
226
227
} catch ( error ) {
227
- console . log ( error ) ;
228
+ logMessage ( LogLevel . Error , error as string ) ;
228
229
} finally {
229
230
updateStatusBar ( getStatusBarText ( ) ) ;
230
231
}
@@ -238,7 +239,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
238
239
try {
239
240
window . showTextDocument ( uri , { selection : range } ) ;
240
241
} catch ( error ) {
241
- window . showWarningMessage ( `Could not jump to the location (error: ${ error } )` ) ;
242
+ logToast ( LogLevel . Warning , `Could not jump to the location (error: ${ error } )` ) ;
242
243
}
243
244
} ) ;
244
245
context . subscriptions . push ( gotoFileLocationCommand ) ;
@@ -291,7 +292,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
291
292
const runCommand = commands . registerCommand ( "renpy.runCommand" , ( ) => {
292
293
//EsLint recommends config be removed as it has already been declared in a previous scope
293
294
if ( ! config || ! isValidExecutable ( config . renpyExecutableLocation ) ) {
294
- window . showErrorMessage ( "Ren'Py executable location not configured or is invalid." ) ;
295
+ logToast ( LogLevel . Error , "Ren'Py executable location not configured or is invalid." ) ;
295
296
} else {
296
297
//this is kinda a hob botched together attempt that I'm like 30% certain has a chance of working
297
298
debug . startDebugging (
@@ -308,7 +309,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
308
309
//call renpy
309
310
const result = RunWorkspaceFolder ( ) ;
310
311
if ( result ) {
311
- window . showInformationMessage ( "Ren'Py is running successfully" ) ;
312
+ logToast ( LogLevel . Info , "Ren'Py is running successfully" ) ;
312
313
}
313
314
}
314
315
} ) ;
@@ -320,16 +321,16 @@ export async function activate(context: ExtensionContext): Promise<void> {
320
321
// Call Ren'Py with the workspace folder and the json-dump argument
321
322
const config = workspace . getConfiguration ( "renpy" ) ;
322
323
if ( ! config ) {
323
- window . showErrorMessage ( "Ren'Py executable location not configured or is invalid." ) ;
324
+ logToast ( LogLevel . Error , "Ren'Py executable location not configured or is invalid." ) ;
324
325
} else {
325
326
if ( isValidExecutable ( config . renpyExecutableLocation ) ) {
326
327
// call renpy
327
328
const result = ExecuteRenpyCompile ( ) ;
328
329
if ( result ) {
329
- window . showInformationMessage ( "Ren'Py compilation has completed." ) ;
330
+ logToast ( LogLevel . Info , "Ren'Py compilation has completed." ) ;
330
331
}
331
332
} else {
332
- window . showErrorMessage ( "Ren'Py executable location not configured or is invalid." ) ;
333
+ logToast ( LogLevel . Error , "Ren'Py executable location not configured or is invalid." ) ;
333
334
}
334
335
}
335
336
} ) ;
@@ -349,50 +350,50 @@ export async function activate(context: ExtensionContext): Promise<void> {
349
350
try {
350
351
fs . watch ( getNavigationJsonFilepath ( ) , async ( event , filename ) => {
351
352
if ( filename ) {
352
- console . log ( `${ filename } changed` ) ;
353
+ logMessage ( LogLevel . Debug , `${ filename } changed` ) ;
353
354
updateStatusBar ( "$(sync~spin) Refreshing Ren'Py navigation data..." ) ;
354
355
try {
355
356
await NavigationData . refresh ( ) ;
356
357
} catch ( error ) {
357
- console . log ( `${ Date ( ) } : error refreshing NavigationData: ${ error } ` ) ;
358
+ logMessage ( LogLevel . Error , `${ Date ( ) } : error refreshing NavigationData: ${ error } ` ) ;
358
359
} finally {
359
360
updateStatusBar ( getStatusBarText ( ) ) ;
360
361
}
361
362
}
362
363
} ) ;
363
364
} catch ( error ) {
364
- console . log ( `Watch navigation.json file error: ${ error } ` ) ;
365
+ logMessage ( LogLevel . Error , `Watch navigation.json file error: ${ error } ` ) ;
365
366
}
366
367
367
368
if ( config && config . watchFoldersForChanges ) {
368
- console . log ( "Starting Watcher for images folder." ) ;
369
+ logMessage ( LogLevel . Info , "Starting Watcher for images folder." ) ;
369
370
try {
370
371
fs . watch ( getImagesFolder ( ) , { recursive : true } , async ( event , filename ) => {
371
372
if ( filename && event === "rename" ) {
372
- console . log ( `${ filename } created/deleted` ) ;
373
+ logMessage ( LogLevel . Debug , `${ filename } created/deleted` ) ;
373
374
await NavigationData . scanForImages ( ) ;
374
375
}
375
376
} ) ;
376
377
} catch ( error ) {
377
- console . log ( `Watch image folder error: ${ error } ` ) ;
378
+ logMessage ( LogLevel . Error , `Watch image folder error: ${ error } ` ) ;
378
379
}
379
380
380
- console . log ( "Starting Watcher for audio folder." ) ;
381
+ logMessage ( LogLevel . Info , "Starting Watcher for audio folder." ) ;
381
382
try {
382
383
fs . watch ( getAudioFolder ( ) , { recursive : true } , async ( event , filename ) => {
383
384
if ( filename && event === "rename" ) {
384
- console . log ( `${ filename } created/deleted` ) ;
385
+ logMessage ( LogLevel . Debug , `${ filename } created/deleted` ) ;
385
386
await NavigationData . scanForAudio ( ) ;
386
387
}
387
388
} ) ;
388
389
} catch ( error ) {
389
- console . log ( `Watch audio folder error: ${ error } ` ) ;
390
+ logMessage ( LogLevel . Error , `Watch audio folder error: ${ error } ` ) ;
390
391
}
391
392
}
392
393
}
393
394
394
395
export function deactivate ( ) {
395
- console . log ( "Ren'Py extension deactivating" ) ;
396
+ logMessage ( LogLevel . Info , "Ren'Py extension deactivating" ) ;
396
397
fs . unwatchFile ( getNavigationJsonFilepath ( ) ) ;
397
398
}
398
399
@@ -426,6 +427,7 @@ function updateStatusBar(text: string) {
426
427
if ( text === "" ) {
427
428
myStatusBarItem . hide ( ) ;
428
429
} else {
430
+ logCatMessage ( LogLevel . Info , LogCategory . Status , text ) ;
429
431
myStatusBarItem . text = text ;
430
432
myStatusBarItem . show ( ) ;
431
433
}
@@ -468,15 +470,15 @@ function RunWorkspaceFolder(): boolean {
468
470
env : { PATH : process . env . PATH } ,
469
471
} ) ;
470
472
if ( result . error ) {
471
- console . log ( `renpy spawn error: ${ result . error } ` ) ;
473
+ logMessage ( LogLevel . Error , `renpy spawn error: ${ result . error } ` ) ;
472
474
return false ;
473
475
}
474
476
if ( result . stderr && result . stderr . length > 0 ) {
475
- console . log ( `renpy spawn stderr: ${ result . stderr } ` ) ;
477
+ logMessage ( LogLevel . Error , `renpy spawn stderr: ${ result . stderr } ` ) ;
476
478
return false ;
477
479
}
478
480
} catch ( error ) {
479
- console . log ( `renpy spawn error: ${ error } ` ) ;
481
+ logMessage ( LogLevel . Error , `renpy spawn error: ${ error } ` ) ;
480
482
return false ;
481
483
} finally {
482
484
updateStatusBar ( getStatusBarText ( ) ) ;
@@ -485,7 +487,7 @@ function RunWorkspaceFolder(): boolean {
485
487
}
486
488
return false ;
487
489
} else {
488
- console . log ( "config for rennpy does not exist" ) ;
490
+ logMessage ( LogLevel . Warning , "config for rennpy does not exist" ) ;
489
491
return false ;
490
492
}
491
493
}
@@ -514,15 +516,15 @@ function ExecuteRenpyCompile(): boolean {
514
516
windowsHide : true ,
515
517
} ) ;
516
518
if ( result . error ) {
517
- console . log ( `renpy spawn error: ${ result . error } ` ) ;
519
+ logMessage ( LogLevel . Error , `renpy spawn error: ${ result . error } ` ) ;
518
520
return false ;
519
521
}
520
522
if ( result . stderr && result . stderr . length > 0 ) {
521
- console . log ( `renpy spawn stderr: ${ result . stderr } ` ) ;
523
+ logMessage ( LogLevel . Error , `renpy spawn stderr: ${ result . stderr } ` ) ;
522
524
return false ;
523
525
}
524
526
} catch ( error ) {
525
- console . log ( `renpy spawn error: ${ error } ` ) ;
527
+ logMessage ( LogLevel . Error , `renpy spawn error: ${ error } ` ) ;
526
528
return false ;
527
529
} finally {
528
530
NavigationData . isCompiling = false ;
0 commit comments