@@ -7,7 +7,7 @@ import { DebugProtocol } from 'vscode-debugprotocol';
7
7
import { LogOutputEvent , LogLevel } from 'vscode-debugadapter/lib/logger' ;
8
8
import { MCMessageStreamParser } from './MCMessageStreamParser' ;
9
9
import { MCSourceMaps } from './MCSourceMaps' ;
10
- import { window } from 'vscode' ;
10
+ import { FileSystemWatcher , window , workspace } from 'vscode' ;
11
11
import * as path from 'path' ;
12
12
13
13
interface PendingResponse {
@@ -20,7 +20,7 @@ interface PendingResponse {
20
20
interface IAttachRequestArguments extends DebugProtocol . AttachRequestArguments {
21
21
mode : string ;
22
22
localRoot : string ;
23
- remoteRoot : string ;
23
+ generatedSourceRoot : string ;
24
24
sourceMapRoot : string ;
25
25
host : string ;
26
26
port : number ;
@@ -39,8 +39,8 @@ export class MCDebugSession extends DebugSession {
39
39
private _terminated : boolean = false ;
40
40
private _threads = new Set < number > ( ) ;
41
41
private _requests = new Map < number , PendingResponse > ( ) ;
42
- private _sourceMaps : MCSourceMaps = new MCSourceMaps ( "" , "" ) ;
43
- private _localRoot : string = "" ;
42
+ private _sourceMaps : MCSourceMaps = new MCSourceMaps ( "" ) ;
43
+ private _fileWatcher ?: FileSystemWatcher ;
44
44
private _activeThreadId : number = 0 ; // the one being debugged
45
45
46
46
public constructor ( ) {
@@ -72,11 +72,6 @@ export class MCDebugSession extends DebugSession {
72
72
73
73
// VSCode wants to attach to a debugee (MC), create socket connection on specified port
74
74
protected async attachRequest ( response : DebugProtocol . AttachResponse , args : IAttachRequestArguments , request ?: DebugProtocol . Request ) {
75
- // capture arguments from launch.json
76
- this . _localRoot = path . normalize ( args . localRoot ) ;
77
- // init source maps
78
- this . _sourceMaps = new MCSourceMaps ( args . localRoot , args . remoteRoot , args . sourceMapRoot ) ;
79
-
80
75
this . closeSession ( ) ;
81
76
82
77
const host = args . host || 'localhost' ;
@@ -101,6 +96,12 @@ export class MCDebugSession extends DebugSession {
101
96
return ;
102
97
}
103
98
99
+ // init source maps
100
+ this . _sourceMaps = new MCSourceMaps ( args . localRoot , args . sourceMapRoot , args . generatedSourceRoot ) ;
101
+
102
+ // watch for source map changes
103
+ this . createSourceMapFileWatcher ( args . sourceMapRoot ) ;
104
+
104
105
// tell VSCode that attach is complete
105
106
this . sendResponse ( response ) ;
106
107
}
@@ -194,8 +195,7 @@ export class MCDebugSession extends DebugSession {
194
195
line : line || 0 ,
195
196
column : column || 0
196
197
} ) ;
197
- let localOriginalAbsolutePath = path . join ( this . _localRoot , originalLocation . source ) ;
198
- const source = new Source ( path . basename ( originalLocation . source ) , localOriginalAbsolutePath ) ;
198
+ const source = new Source ( path . basename ( originalLocation . source ) , originalLocation . source ) ;
199
199
stackFrames . push ( new StackFrame ( id , name , source , originalLocation . line , originalLocation . column ) ) ;
200
200
}
201
201
catch ( e ) {
@@ -380,6 +380,11 @@ export class MCDebugSession extends DebugSession {
380
380
this . _connectionSocket . destroy ( ) ;
381
381
}
382
382
this . _connectionSocket = undefined ;
383
+
384
+ if ( this . _fileWatcher ) {
385
+ this . _fileWatcher . dispose ( ) ;
386
+ this . _fileWatcher = undefined ;
387
+ }
383
388
}
384
389
385
390
// close and terminate session (could be from debugee request)
@@ -439,7 +444,7 @@ export class MCDebugSession extends DebugSession {
439
444
// json = 1 line json + new line
440
445
let messageLength = jsonBuffer . byteLength + 1 ;
441
446
let length = '00000000' + messageLength . toString ( 16 ) + '\n' ;
442
- length = length . substr ( length . length - 9 ) ;
447
+ length = length . substring ( length . length - 9 ) ;
443
448
let lengthBuffer = Buffer . from ( length ) ;
444
449
let newline = Buffer . from ( '\n' ) ;
445
450
let buffer = Buffer . concat ( [ lengthBuffer , jsonBuffer , newline ] ) ;
@@ -517,6 +522,19 @@ export class MCDebugSession extends DebugSession {
517
522
}
518
523
}
519
524
525
+ private createSourceMapFileWatcher ( sourceMapRoot ?: string ) {
526
+ if ( this . _fileWatcher ) {
527
+ this . _fileWatcher . dispose ( ) ;
528
+ this . _fileWatcher = undefined
529
+ }
530
+ if ( sourceMapRoot ) {
531
+ this . _fileWatcher = workspace . createFileSystemWatcher ( '**/*.{map}' , false , false , false ) ;
532
+ this . _fileWatcher . onDidChange ( uri => { this . _sourceMaps . reset ( ) } ) ;
533
+ this . _fileWatcher . onDidCreate ( uri => { this . _sourceMaps . reset ( ) } ) ;
534
+ this . _fileWatcher . onDidDelete ( uri => { this . _sourceMaps . reset ( ) } ) ;
535
+ }
536
+ }
537
+
520
538
// ------------------------------------------------------------------------
521
539
522
540
private log ( message : string , logLevel : LogLevel ) {
0 commit comments