@@ -117,12 +117,12 @@ function createLabel(name: string): string {
117
117
}
118
118
async function durationLogWrapper < T > (
119
119
name : string ,
120
- fn : ( ) => Promise < T >
120
+ fn : ( label : string ) => Promise < T >
121
121
) : Promise < T > {
122
122
console . log ( "Triggered " + name + ": ..." ) ;
123
123
const label = createLabel ( name ) ;
124
124
console . time ( label ) ;
125
- const result = await fn ( ) ;
125
+ const result = await fn ( label ) ;
126
126
127
127
// This purposefully has the same prefix length as the "Triggered " log above,
128
128
// also does not add a newline at the end.
@@ -244,7 +244,7 @@ async function validateTextDocument(
244
244
) : Promise < void > {
245
245
return await durationLogWrapper (
246
246
`validateTextDocument ${ textDocument . uri } ` ,
247
- async ( ) => {
247
+ async ( label ) => {
248
248
if ( ! hasDiagnosticRelatedInformationCapability ) {
249
249
console . error (
250
250
"Trying to validate a document with no diagnostic capability"
@@ -263,7 +263,8 @@ async function validateTextDocument(
263
263
text ,
264
264
"--ide-check" ,
265
265
settings ,
266
- textDocument . uri
266
+ textDocument . uri ,
267
+ { label : label }
267
268
) ;
268
269
269
270
textDocument . nuInlayHints = [ ] ;
@@ -403,7 +404,7 @@ async function runCompiler(
403
404
flags : string ,
404
405
settings : NushellIDESettings ,
405
406
uri : string ,
406
- options : { allowErrors ?: boolean } = { }
407
+ options : { allowErrors ?: boolean , label : string } = { label : "runCompiler" } ,
407
408
) : Promise < string > {
408
409
const allowErrors =
409
410
options . allowErrors === undefined ? true : options . allowErrors ;
@@ -412,7 +413,7 @@ async function runCompiler(
412
413
fs . writeFileSync ( tmpFile . name , text ) ;
413
414
// eslint-disable-next-line @typescript-eslint/no-explicit-any
414
415
} catch ( e : any ) {
415
- // connection.console.log(e );
416
+ connection . console . error ( `[ ${ options . label } ] error writing to tmp file: ${ e } ` ) ;
416
417
}
417
418
418
419
let stdout = "" ;
@@ -430,8 +431,7 @@ async function runCompiler(
430
431
}
431
432
432
433
connection . console . log (
433
- "running: " +
434
- `${ settings . nushellExecutablePath } ${ flags } ${ script_path_flag } ${ tmpFile . name } `
434
+ `[${ options . label } ] running: ${ settings . nushellExecutablePath } ${ flags } ${ script_path_flag } ${ tmpFile . name } `
435
435
) ;
436
436
437
437
const output = await exec (
@@ -441,17 +441,12 @@ async function runCompiler(
441
441
}
442
442
) ;
443
443
stdout = output . stdout ;
444
- console . log ( " stdout: " + stdout ) ;
444
+ console . log ( `[ ${ options . label } ] stdout: ${ stdout } ` ) ;
445
445
// eslint-disable-next-line @typescript-eslint/no-explicit-any
446
446
} catch ( e : any ) {
447
447
stdout = e . stdout ;
448
+ connection . console . log ( `[${ options . label } ] compile failed: ` + e ) ;
448
449
if ( ! allowErrors ) {
449
- if ( e . signal != null ) {
450
- connection . console . log ( "compile failed: " ) ;
451
- connection . console . log ( e ) ;
452
- } else {
453
- connection . console . log ( "Error:" + e ) ;
454
- }
455
450
throw e ;
456
451
}
457
452
}
@@ -568,21 +563,21 @@ connection.onCompletion(
568
563
) ;
569
564
570
565
connection . onDefinition ( async ( request ) => {
571
- return await durationLogWrapper ( `onDefinition` , async ( ) => {
566
+ return await durationLogWrapper ( `onDefinition` , async ( label ) => {
572
567
const document = documents . get ( request . textDocument . uri ) ;
573
568
if ( ! document ) return ;
574
569
const settings = await getDocumentSettings ( request . textDocument . uri ) ;
575
570
576
571
const text = document . getText ( ) ;
577
572
578
- // connection.console.log("request: ");
579
- // connection.console.log(request.textDocument.uri);
573
+ // connection.console.log(`[${label}] request: ${request.textDocument.uri}`);
580
574
// connection.console.log("index: " + convertPosition(request.position, text));
581
575
const stdout = await runCompiler (
582
576
text ,
583
577
"--ide-goto-def " + convertPosition ( request . position , text ) ,
584
578
settings ,
585
- request . textDocument . uri
579
+ request . textDocument . uri ,
580
+ { label : label }
586
581
) ;
587
582
return goToDefinition ( document , stdout ) ;
588
583
} ) ;
@@ -605,11 +600,19 @@ async function goToDefinition(
605
600
// connection.console.log(obj);
606
601
if ( obj . file === "" || obj . file === "__prelude__" ) return ;
607
602
608
- const lineBreaks = findLineBreaks (
609
- obj . file
610
- ? ( await fs . promises . readFile ( obj . file ) ) . toString ( )
611
- : document . getText ( ) ?? ""
612
- ) ;
603
+ let documentText : string ;
604
+ if ( obj . file ) {
605
+ if ( fs . existsSync ( obj . file ) ) {
606
+ documentText = await fs . promises . readFile ( obj . file ) . then ( ( b ) => b . toString ( ) ) ;
607
+ } else {
608
+ connection . console . log ( `File ${ obj . file } does not exist` ) ;
609
+ return ;
610
+ }
611
+ } else {
612
+ documentText = document . getText ( ) ;
613
+ }
614
+
615
+ const lineBreaks : number [ ] = findLineBreaks ( documentText ) ;
613
616
614
617
let uri = "" ;
615
618
if ( obj . file == tmpFile . name ) {
0 commit comments