@@ -33,12 +33,19 @@ import {
3333
3434import shellescape from 'shell-escape' ;
3535
36+ const RE_FILE_URI : RegExp = / ^ f i l e : (?: \/ \/ ) ? / ;
37+
3638/**
3739 * Accessor interface for interacting with LFortran. Possible implementations
3840 * include a CLI accessor and service accessor.
3941 */
4042export interface LFortranAccessor {
4143
44+ resolve ( uri : string ,
45+ filename : string ,
46+ flags : string [ ] ,
47+ resolved ?: Map < string , string > ) : string ;
48+
4249 version ( settings : LFortranSettings ) : Promise < string > ;
4350
4451 /**
@@ -299,12 +306,21 @@ export class LFortranCLIAccessor implements LFortranAccessor {
299306 return output ;
300307 }
301308
302- resolve ( filename : string , flags : string [ ] , resolved ?: Map < string , string > ) : string {
309+ resolve ( uri : string ,
310+ filename : string ,
311+ flags : string [ ] ,
312+ resolved ?: Map < string , string > ) : string {
303313 const fnid : string = "resolve" ;
304314 const start : number = performance . now ( ) ;
305315
306316 let filePath : string = filename ;
307317
318+ if ( filePath === this . tmpFile . name ) {
319+ filePath = uri ;
320+ }
321+
322+ filePath = filePath . replace ( RE_FILE_URI , "" ) ;
323+
308324 if ( ! fs . existsSync ( filePath ) ) {
309325 let resolution : string | undefined = resolved ?. get ( filePath ) ;
310326 if ( resolution === undefined ) {
@@ -331,8 +347,12 @@ export class LFortranCLIAccessor implements LFortranAccessor {
331347
332348 // if file name is `b.f90` then it will be replaced with `$(pwd)/b.f90`
333349 // if file name is `a/b.f90` then it will be replaced with `$(pwd)/a/b.f90`
334-
350+ // -----------------------------------------------------------------------
351+ // TODO: Collect an example that demonstrates the need for this resolution
352+ // that does not work with `fs.realpathSync`, above.
353+ // -----------------------------------------------------------------------
335354 const newFilePath : string = path . resolve ( filePath ) ;
355+
336356 if ( this . logger . isBenchmarkOrTraceEnabled ( ) ) {
337357 this . logBenchmarkAndTrace (
338358 fnid , start ,
@@ -374,7 +394,7 @@ export class LFortranCLIAccessor implements LFortranAccessor {
374394 for ( let i = 0 , k = symbols . length ; i < k ; i ++ ) {
375395 const symbol : Record < string , any > = symbols [ i ] ;
376396 const symbolPath : string =
377- this . resolve ( symbol . filename , settings . compiler . flags , resolved ) ;
397+ this . resolve ( uri , symbol . filename , settings . compiler . flags , resolved ) ;
378398
379399 const location : Location = symbol . location ;
380400 // location.uri = uri;
@@ -428,8 +448,8 @@ export class LFortranCLIAccessor implements LFortranAccessor {
428448 const results : Record < string , any > [ ] = JSON . parse ( stdout ) ;
429449 for ( let i = 0 , k = results . length ; i < k ; i ++ ) {
430450 const result : Record < string , any > = results [ i ] ;
431- let symbolPath : string =
432- this . resolve ( result . filename , settings . compiler . flags ) ;
451+ const symbolPath : string =
452+ this . resolve ( uri , result . filename , settings . compiler . flags ) ;
433453
434454 const location = result . location ;
435455
@@ -443,9 +463,6 @@ export class LFortranCLIAccessor implements LFortranAccessor {
443463 end . line -- ;
444464 end . character -- ;
445465
446- if ( symbolPath . endsWith ( ".tmp" ) ) {
447- symbolPath = uri ;
448- }
449466 definitions . push ( {
450467 targetUri : symbolPath ,
451468 targetRange : range ,
0 commit comments