5
5
import { inject , injectable } from 'inversify' ;
6
6
import Cdp from '../cdp/api' ;
7
7
import { ILogger , LogTag } from '../common/logging' ;
8
- import { bisectArray , flatten } from '../common/objUtils' ;
8
+ import { bisectArrayAsync , flatten } from '../common/objUtils' ;
9
9
import { IPosition } from '../common/positions' ;
10
10
import { delay } from '../common/promiseUtil' ;
11
11
import { SourceMap } from '../common/sourceMaps/sourceMap' ;
@@ -25,15 +25,8 @@ import { NeverResolvedBreakpoint } from './breakpoints/neverResolvedBreakpoint';
25
25
import { PatternEntryBreakpoint } from './breakpoints/patternEntrypointBreakpoint' ;
26
26
import { UserDefinedBreakpoint } from './breakpoints/userDefinedBreakpoint' ;
27
27
import { DiagnosticToolSuggester } from './diagnosticToolSuggester' ;
28
- import {
29
- base0To1 ,
30
- base1To0 ,
31
- ISourceWithMap ,
32
- isSourceWithMap ,
33
- IUiLocation ,
34
- Source ,
35
- SourceContainer ,
36
- } from './sources' ;
28
+ import { ISourceWithMap , IUiLocation , Source , base0To1 , base1To0 , isSourceWithMap } from './source' ;
29
+ import { SourceContainer } from './sourceContainer' ;
37
30
import { ScriptWithSourceMapHandler , Thread } from './threads' ;
38
31
39
32
/**
@@ -226,23 +219,30 @@ export class BreakpointManager {
226
219
* location in the `toSource`, using the provided source map. Breakpoints
227
220
* are don't have a corresponding location won't be moved.
228
221
*/
229
- public moveBreakpoints ( fromSource : Source , sourceMap : SourceMap , toSource : Source ) {
222
+ public async moveBreakpoints (
223
+ thread : Thread ,
224
+ fromSource : Source ,
225
+ sourceMap : SourceMap ,
226
+ toSource : Source ,
227
+ ) {
230
228
const tryUpdateLocations = ( breakpoints : UserDefinedBreakpoint [ ] ) =>
231
- bisectArray ( breakpoints , bp => {
232
- const gen = this . _sourceContainer . getOptiminalOriginalPosition (
229
+ bisectArrayAsync ( breakpoints , async bp => {
230
+ const gen = await this . _sourceContainer . getOptiminalOriginalPosition (
233
231
sourceMap ,
234
232
bp . originalPosition ,
235
233
) ;
236
- if ( gen . column === null || gen . line === null ) {
234
+ if ( ! gen ) {
237
235
return false ;
238
236
}
239
237
238
+ const base1 = gen . position . base1 ;
240
239
bp . updateSourceLocation (
240
+ thread ,
241
241
{
242
242
path : toSource . absolutePath ,
243
243
sourceReference : toSource . sourceReference ,
244
244
} ,
245
- { lineNumber : gen . line , columnNumber : gen . column + 1 , source : toSource } ,
245
+ { lineNumber : base1 . lineNumber , columnNumber : base1 . columnNumber , source : toSource } ,
246
246
) ;
247
247
return false ;
248
248
} ) ;
@@ -251,14 +251,14 @@ export class BreakpointManager {
251
251
const toPath = toSource . absolutePath ;
252
252
const byPath = fromPath ? this . _byPath . get ( fromPath ) : undefined ;
253
253
if ( byPath && toPath ) {
254
- const [ remaining , moved ] = tryUpdateLocations ( byPath ) ;
254
+ const [ remaining , moved ] = await tryUpdateLocations ( byPath ) ;
255
255
this . _byPath . set ( fromPath , remaining ) ;
256
256
this . _byPath . set ( toPath , moved ) ;
257
257
}
258
258
259
259
const byRef = this . _byRef . get ( fromSource . sourceReference ) ;
260
260
if ( byRef ) {
261
- const [ remaining , moved ] = tryUpdateLocations ( byRef ) ;
261
+ const [ remaining , moved ] = await tryUpdateLocations ( byRef ) ;
262
262
this . _byRef . set ( fromSource . sourceReference , remaining ) ;
263
263
this . _byRef . set ( toSource . sourceReference , moved ) ;
264
264
}
@@ -317,18 +317,19 @@ export class BreakpointManager {
317
317
end : IPosition ,
318
318
) {
319
319
const start1 = start . base1 ;
320
- const startLocations = this . _sourceContainer . currentSiblingUiLocations ( {
321
- source,
322
- lineNumber : start1 . lineNumber ,
323
- columnNumber : start1 . columnNumber ,
324
- } ) ;
325
-
326
320
const end1 = end . base1 ;
327
- const endLocations = this . _sourceContainer . currentSiblingUiLocations ( {
328
- source,
329
- lineNumber : end1 . lineNumber ,
330
- columnNumber : end1 . columnNumber ,
331
- } ) ;
321
+ const [ startLocations , endLocations ] = await Promise . all ( [
322
+ this . _sourceContainer . currentSiblingUiLocations ( {
323
+ source,
324
+ lineNumber : start1 . lineNumber ,
325
+ columnNumber : start1 . columnNumber ,
326
+ } ) ,
327
+ this . _sourceContainer . currentSiblingUiLocations ( {
328
+ source,
329
+ lineNumber : end1 . lineNumber ,
330
+ columnNumber : end1 . columnNumber ,
331
+ } ) ,
332
+ ] ) ;
332
333
333
334
// As far as I know the number of start and end locations should be the
334
335
// same, log if this is not the case.
@@ -343,7 +344,7 @@ export class BreakpointManager {
343
344
// For each viable location, attempt to identify its script ID and then ask
344
345
// Chrome for the breakpoints in the given range. For almost all scripts
345
346
// we'll only every find one viable location with a script.
346
- const todo : Promise < void > [ ] = [ ] ;
347
+ const todo : Promise < unknown > [ ] = [ ] ;
347
348
const result : IPossibleBreakLocation [ ] = [ ] ;
348
349
for ( let i = 0 ; i < startLocations . length ; i ++ ) {
349
350
const start = startLocations [ i ] ;
@@ -383,15 +384,17 @@ export class BreakpointManager {
383
384
// Discard any that map outside of the source we're interested in,
384
385
// which is possible (e.g. if a section of code from one source is
385
386
// inlined amongst the range we request).
386
- for ( const breakLocation of r . locations ) {
387
- const { lineNumber, columnNumber = 0 } = breakLocation ;
388
- const uiLocations = this . _sourceContainer . currentSiblingUiLocations ( {
389
- source : lsrc ,
390
- ...lsrc . offsetScriptToSource ( base0To1 ( { lineNumber, columnNumber } ) ) ,
391
- } ) ;
392
-
393
- result . push ( { breakLocation, uiLocations } ) ;
394
- }
387
+ return Promise . all (
388
+ r . locations . map ( async breakLocation => {
389
+ const { lineNumber, columnNumber = 0 } = breakLocation ;
390
+ const uiLocations = await this . _sourceContainer . currentSiblingUiLocations ( {
391
+ source : lsrc ,
392
+ ...lsrc . offsetScriptToSource ( base0To1 ( { lineNumber, columnNumber } ) ) ,
393
+ } ) ;
394
+
395
+ result . push ( { breakLocation, uiLocations } ) ;
396
+ } ) ,
397
+ ) ;
395
398
} ) ,
396
399
) ;
397
400
}
@@ -671,7 +674,7 @@ export class BreakpointManager {
671
674
}
672
675
673
676
/**
674
- * Rreturns whether any of the given breakpoints are an entrypoint breakpoint.
677
+ * Returns whether any of the given breakpoints are an entrypoint breakpoint.
675
678
*/
676
679
public isEntrypointBreak (
677
680
hitBreakpointIds : ReadonlyArray < Cdp . Debugger . BreakpointId > ,
0 commit comments