Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | |
| 4 /** | 5 /** |
| 5 * @implements {Bindings.DebuggerSourceMapping} | 6 * @implements {Bindings.DebuggerSourceMapping} |
| 6 * @unrestricted | |
| 7 */ | 7 */ |
| 8 Sources.FormatterScriptMapping = class { | 8 Sources.FormatterScriptMapping = class { |
| 9 /** | 9 /** |
| 10 * @param {!SDK.DebuggerModel} debuggerModel | |
| 11 * @param {!Sources.ScriptFormatterEditorAction} editorAction | |
| 12 */ | |
| 13 constructor(debuggerModel, editorAction) { | |
| 14 this._debuggerModel = debuggerModel; | |
| 15 this._editorAction = editorAction; | |
| 16 } | |
| 17 | |
| 18 /** | |
| 19 * @override | 10 * @override |
| 20 * @param {!SDK.DebuggerModel.Location} rawLocation | 11 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 21 * @return {?Workspace.UILocation} | 12 * @return {?Workspace.UILocation} |
| 22 */ | 13 */ |
| 23 rawLocationToUILocation(rawLocation) { | 14 rawLocationToUILocation(rawLocation) { |
| 24 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL ocation); | 15 var script = rawLocation.script(); |
| 25 var script = debuggerModelLocation.script(); | 16 var formatData = script && script[Sources.ScriptFormatterEditorAction._forma tDataSymbol]; |
|
pfeldman
2017/04/06 00:46:26
type cast it?
| |
| 26 if (!script) | |
| 27 return null; | |
| 28 var uiSourceCode = this._editorAction._uiSourceCodes.get(script); | |
| 29 if (!uiSourceCode) | |
| 30 return null; | |
| 31 | |
| 32 var formatData = this._editorAction._formatData.get(uiSourceCode); | |
| 33 if (!formatData) | 17 if (!formatData) |
| 34 return null; | 18 return null; |
| 35 var mapping = formatData.mapping; | 19 var lineNumber = rawLocation.lineNumber; |
|
pfeldman
2017/04/06 00:46:26
inline those two
| |
| 36 var lineNumber = debuggerModelLocation.lineNumber; | 20 var columnNumber = rawLocation.columnNumber || 0; |
| 37 var columnNumber = debuggerModelLocation.columnNumber || 0; | 21 var formattedLocation = formatData.mapping.originalToFormatted(lineNumber, c olumnNumber); |
| 38 var formattedLocation = mapping.originalToFormatted(lineNumber, columnNumber ); | 22 return formatData.formattedSourceCode.uiLocation(formattedLocation[0], forma ttedLocation[1]); |
| 39 return uiSourceCode.uiLocation(formattedLocation[0], formattedLocation[1]); | |
| 40 } | 23 } |
| 41 | 24 |
| 42 /** | 25 /** |
| 43 * @override | 26 * @override |
| 44 * @param {!Workspace.UISourceCode} uiSourceCode | 27 * @param {!Workspace.UISourceCode} uiSourceCode |
| 45 * @param {number} lineNumber | 28 * @param {number} lineNumber |
| 46 * @param {number} columnNumber | 29 * @param {number} columnNumber |
| 47 * @return {?SDK.DebuggerModel.Location} | 30 * @return {?SDK.DebuggerModel.Location} |
| 48 */ | 31 */ |
| 49 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { | 32 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| 50 var formatData = this._editorAction._formatData.get(uiSourceCode); | 33 var formatData = uiSourceCode[Sources.ScriptFormatterEditorAction._formatDat aSymbol]; |
|
lushnikov
2017/04/05 18:29:48
don't you want to save script here instead?
| |
| 51 if (!formatData) | 34 if (!formatData) |
| 52 return null; | 35 return null; |
| 53 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber, co lumnNumber); | 36 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber, co lumnNumber); |
| 54 for (var i = 0; i < formatData.scripts.length; ++i) { | 37 var scripts = Sources.ScriptFormatterEditorAction._scriptsForUISourceCode(fo rmatData.originalSourceCode); |
|
pfeldman
2017/04/05 18:23:36
You are formatting UISourceCodes, not scripts. For
lushnikov
2017/04/05 18:29:48
let's bind formatted UISourceCode to a single scri
| |
| 55 if (formatData.scripts[i].debuggerModel === this._debuggerModel) | 38 if (!scripts.length) |
| 56 return this._debuggerModel.createRawLocation(formatData.scripts[i], orig inalLocation[0], originalLocation[1]); | 39 return null; |
| 57 } | 40 return scripts[0].debuggerModel.createRawLocation(scripts[0], originalLocati on[0], originalLocation[1]); |
|
pfeldman
2017/04/06 00:46:26
We'll burn in hell for this.
| |
| 58 return null; | |
| 59 } | 41 } |
| 60 | 42 |
| 61 /** | 43 /** |
| 62 * @override | 44 * @override |
| 63 * @return {boolean} | 45 * @return {boolean} |
| 64 */ | 46 */ |
| 65 isIdentity() { | 47 isIdentity() { |
| 66 return false; | 48 return false; |
| 67 } | 49 } |
| 68 | 50 |
| 69 /** | 51 /** |
| 70 * @override | 52 * @override |
| 71 * @param {!Workspace.UISourceCode} uiSourceCode | 53 * @param {!Workspace.UISourceCode} uiSourceCode |
| 72 * @param {number} lineNumber | 54 * @param {number} lineNumber |
| 73 * @return {boolean} | 55 * @return {boolean} |
| 74 */ | 56 */ |
| 75 uiLineHasMapping(uiSourceCode, lineNumber) { | 57 uiLineHasMapping(uiSourceCode, lineNumber) { |
| 76 return true; | 58 return true; |
| 77 } | 59 } |
| 78 }; | 60 }; |
| 79 | 61 |
| 80 /** | |
| 81 * @unrestricted | |
| 82 */ | |
| 83 Sources.FormatterScriptMapping.FormatData = class { | 62 Sources.FormatterScriptMapping.FormatData = class { |
| 84 /** | 63 /** |
| 85 * @param {string} projectId | 64 * @param {!Workspace.UISourceCode} originalSourceCode |
| 86 * @param {string} path | 65 * @param {!Workspace.UISourceCode} formattedSourceCode |
| 87 * @param {!Sources.FormatterSourceMapping} mapping | 66 * @param {!Sources.FormatterSourceMapping} mapping |
| 88 * @param {!Array.<!SDK.Script>} scripts | |
| 89 */ | 67 */ |
| 90 constructor(projectId, path, mapping, scripts) { | 68 constructor(originalSourceCode, formattedSourceCode, mapping) { |
| 91 this.projectId = projectId; | 69 this.originalSourceCode = originalSourceCode; |
| 92 this.path = path; | 70 this.formattedSourceCode = formattedSourceCode; |
| 93 this.mapping = mapping; | 71 this.mapping = mapping; |
| 94 this.scripts = scripts; | 72 } |
| 73 | |
| 74 originalPath() { | |
| 75 return this.originalSourceCode.project().id() + ':' + this.originalSourceCod e.url(); | |
| 95 } | 76 } |
| 96 }; | 77 }; |
| 97 | 78 |
| 98 /** | 79 /** |
| 99 * @implements {Sources.SourcesView.EditorAction} | 80 * @implements {Sources.SourcesView.EditorAction} |
| 100 * @implements {SDK.SDKModelObserver<!SDK.DebuggerModel>} | 81 * @implements {SDK.SDKModelObserver<!SDK.DebuggerModel>} |
| 101 * @unrestricted | 82 * @unrestricted |
| 102 */ | 83 */ |
| 103 Sources.ScriptFormatterEditorAction = class { | 84 Sources.ScriptFormatterEditorAction = class { |
| 104 constructor() { | 85 constructor() { |
| 105 this._projectId = 'formatter:'; | 86 this._projectId = 'formatter:'; |
| 106 this._project = new Bindings.ContentProviderBasedProject( | 87 this._project = new Bindings.ContentProviderBasedProject( |
| 107 Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter, 'formatter', | 88 Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter, 'formatter', |
| 108 true /* isServiceProject */); | 89 true /* isServiceProject */); |
| 109 | 90 |
| 110 /** @type {!Map.<!SDK.Script, !Workspace.UISourceCode>} */ | 91 /** @type {!Map<string, string>} */ |
| 111 this._uiSourceCodes = new Map(); | |
| 112 /** @type {!Map.<string, string>} */ | |
| 113 this._formattedPaths = new Map(); | 92 this._formattedPaths = new Map(); |
| 114 /** @type {!Map.<!Workspace.UISourceCode, !Sources.FormatterScriptMapping.Fo rmatData>} */ | 93 /** @type {!Set<string>} */ |
| 115 this._formatData = new Map(); | 94 this._pathsToFormatOnLoad = new Set(); |
| 95 this._scriptMapping = new Sources.FormatterScriptMapping(); | |
| 116 | 96 |
| 117 /** @type {!Set.<string>} */ | |
| 118 this._pathsToFormatOnLoad = new Set(); | |
| 119 | |
| 120 /** @type {!Map.<!SDK.DebuggerModel, !Sources.FormatterScriptMapping>} */ | |
| 121 this._scriptMappingByDebuggerModel = new Map(); | |
| 122 this._workspace = Workspace.workspace; | |
| 123 SDK.targetManager.observeModels(SDK.DebuggerModel, this); | 97 SDK.targetManager.observeModels(SDK.DebuggerModel, this); |
| 124 } | 98 } |
| 125 | 99 |
| 126 /** | 100 /** |
| 127 * @override | 101 * @override |
| 128 * @param {!SDK.DebuggerModel} debuggerModel | 102 * @param {!SDK.DebuggerModel} debuggerModel |
| 129 */ | 103 */ |
| 130 modelAdded(debuggerModel) { | 104 modelAdded(debuggerModel) { |
| 131 this._scriptMappingByDebuggerModel.set(debuggerModel, new Sources.FormatterS criptMapping(debuggerModel, this)); | |
| 132 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this); | 105 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this); |
| 133 } | 106 } |
| 134 | 107 |
| 135 /** | 108 /** |
| 136 * @override | 109 * @override |
| 137 * @param {!SDK.DebuggerModel} debuggerModel | 110 * @param {!SDK.DebuggerModel} debuggerModel |
| 138 */ | 111 */ |
| 139 modelRemoved(debuggerModel) { | 112 modelRemoved(debuggerModel) { |
| 140 this._scriptMappingByDebuggerModel.remove(debuggerModel); | |
| 141 this._cleanForModel(debuggerModel); | 113 this._cleanForModel(debuggerModel); |
| 142 debuggerModel.removeEventListener(SDK.DebuggerModel.Events.GlobalObjectClear ed, this._debuggerReset, this); | 114 debuggerModel.removeEventListener(SDK.DebuggerModel.Events.GlobalObjectClear ed, this._debuggerReset, this); |
| 143 } | 115 } |
| 144 | 116 |
| 145 /** | 117 /** |
| 146 * @param {!Common.Event} event | 118 * @param {!Common.Event} event |
| 147 */ | 119 */ |
| 148 _editorSelected(event) { | 120 _editorSelected(event) { |
| 149 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | 121 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| 150 this._updateButton(uiSourceCode); | 122 this._updateButton(uiSourceCode); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 start = mapping.originalToFormatted(selection.startLine, selection.startCo lumn); | 207 start = mapping.originalToFormatted(selection.startLine, selection.startCo lumn); |
| 236 } | 208 } |
| 237 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], start[ 1]); | 209 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], start[ 1]); |
| 238 this._updateButton(formattedUISourceCode); | 210 this._updateButton(formattedUISourceCode); |
| 239 } | 211 } |
| 240 | 212 |
| 241 /** | 213 /** |
| 242 * @param {!Workspace.UISourceCode} formattedUISourceCode | 214 * @param {!Workspace.UISourceCode} formattedUISourceCode |
| 243 */ | 215 */ |
| 244 _discardFormattedUISourceCodeScript(formattedUISourceCode) { | 216 _discardFormattedUISourceCodeScript(formattedUISourceCode) { |
| 245 var formatData = this._formatData.get(formattedUISourceCode); | 217 var formatData = formattedUISourceCode[Sources.ScriptFormatterEditorAction._ formatDataSymbol]; |
| 246 if (!formatData) | 218 if (!formatData) |
| 247 return; | 219 return; |
| 248 | 220 |
| 249 this._formatData.remove(formattedUISourceCode); | 221 var path = formatData.originalPath(); |
| 250 var path = formatData.projectId + ':' + formatData.path; | |
| 251 this._formattedPaths.remove(path); | 222 this._formattedPaths.remove(path); |
| 252 this._pathsToFormatOnLoad.delete(path); | 223 this._pathsToFormatOnLoad.delete(path); |
| 253 for (var i = 0; i < formatData.scripts.length; ++i) { | 224 var scripts = Sources.ScriptFormatterEditorAction._scriptsForUISourceCode(fo rmatData.originalSourceCode); |
| 254 this._uiSourceCodes.remove(formatData.scripts[i]); | 225 for (var script of scripts) { |
| 255 Bindings.debuggerWorkspaceBinding.popSourceMapping(formatData.scripts[i]); | 226 script[Sources.ScriptFormatterEditorAction._formatDataSymbol] = null; |
| 227 Bindings.debuggerWorkspaceBinding.popSourceMapping(script); | |
| 256 } | 228 } |
| 257 this._project.removeFile(formattedUISourceCode.url()); | 229 this._project.removeFile(formattedUISourceCode.url()); |
| 258 } | 230 } |
| 259 | 231 |
| 260 /** | 232 /** |
| 261 * @param {!SDK.DebuggerModel} debuggerModel | 233 * @param {!SDK.DebuggerModel} debuggerModel |
| 262 */ | 234 */ |
| 263 _cleanForModel(debuggerModel) { | 235 _cleanForModel(debuggerModel) { |
| 264 var uiSourceCodes = this._formatData.keysArray(); | 236 for (var script of Object.values(debuggerModel.scripts)) { |
| 265 for (var i = 0; i < uiSourceCodes.length; ++i) { | 237 var formatData = script[Sources.ScriptFormatterEditorAction._formatDataSym bol]; |
|
pfeldman
2017/04/06 00:46:26
cast
| |
| 266 Bindings.debuggerWorkspaceBinding.setSourceMapping(debuggerModel, uiSource Codes[i], null); | 238 if (!formatData) |
| 267 var formatData = this._formatData.get(uiSourceCodes[i]); | 239 continue; |
| 268 var scripts = []; | 240 delete script[Sources.ScriptFormatterEditorAction._formatDataSymbol]; |
| 269 for (var j = 0; j < formatData.scripts.length; ++j) { | 241 Bindings.debuggerWorkspaceBinding.setSourceMapping(debuggerModel, formatDa ta.formattedUISourceCode, null); |
| 270 if (formatData.scripts[j].debuggerModel === debuggerModel) | 242 this._formattedPaths.remove(formatData.originalPath()); |
| 271 this._uiSourceCodes.remove(formatData.scripts[j]); | 243 this._project.removeFile(formatData.formattedSourceCodes.url()); |
| 272 else | |
| 273 scripts.push(formatData.scripts[j]); | |
| 274 } | |
| 275 | |
| 276 if (scripts.length) { | |
| 277 formatData.scripts = scripts; | |
| 278 } else { | |
| 279 this._formattedPaths.remove(formatData.projectId + ':' + formatData.path ); | |
| 280 this._formatData.remove(uiSourceCodes[i]); | |
| 281 this._project.removeFile(uiSourceCodes[i].url()); | |
| 282 } | |
| 283 } | 244 } |
| 284 } | 245 } |
| 285 | 246 |
| 286 /** | 247 /** |
| 287 * @param {!Common.Event} event | 248 * @param {!Common.Event} event |
| 288 */ | 249 */ |
| 289 _debuggerReset(event) { | 250 _debuggerReset(event) { |
| 290 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); | 251 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); |
| 291 this._cleanForModel(debuggerModel); | 252 this._cleanForModel(debuggerModel); |
| 292 } | 253 } |
| 293 | 254 |
| 294 /** | 255 /** |
| 295 * @param {!Workspace.UISourceCode} uiSourceCode | 256 * @param {!Workspace.UISourceCode} uiSourceCode |
| 296 * @return {!Array.<!SDK.Script>} | 257 * @return {!Array<!SDK.Script>} |
| 297 */ | 258 */ |
| 298 _scriptsForUISourceCode(uiSourceCode) { | 259 static _scriptsForUISourceCode(uiSourceCode) { |
| 299 /** | |
| 300 * @param {!SDK.Script} script | |
| 301 * @return {boolean} | |
| 302 */ | |
| 303 function isInlineScript(script) { | |
| 304 return script.isInlineScript() && !script.hasSourceURL; | |
| 305 } | |
| 306 | |
| 307 if (uiSourceCode.contentType() === Common.resourceTypes.Document) { | 260 if (uiSourceCode.contentType() === Common.resourceTypes.Document) { |
| 308 var scripts = []; | 261 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| 309 var debuggerModels = SDK.targetManager.models(SDK.DebuggerModel); | 262 var debuggerModel = target && target.model(SDK.DebuggerModel); |
| 310 for (var i = 0; i < debuggerModels.length; ++i) | 263 if (debuggerModel) { |
| 311 scripts.pushAll(debuggerModels[i].scriptsForSourceURL(uiSourceCode.url() )); | 264 var scripts = debuggerModel.scriptsForSourceURL(uiSourceCode.url()) |
| 312 return scripts.filter(isInlineScript); | 265 .filter(script => script.isInlineScript() && !script.h asSourceURL); |
| 266 return scripts; | |
| 267 } | |
| 313 } | 268 } |
| 314 if (uiSourceCode.contentType().isScript()) { | 269 if (uiSourceCode.contentType().isScript()) { |
| 315 var rawLocation = Bindings.debuggerWorkspaceBinding.uiLocationToRawLocatio n(uiSourceCode, 0, 0); | 270 var rawLocation = Bindings.debuggerWorkspaceBinding.uiLocationToRawLocatio n(uiSourceCode, 0, 0); |
| 316 if (rawLocation) | 271 if (rawLocation) |
| 317 return [rawLocation.script()]; | 272 return [rawLocation.script()]; |
| 318 } | 273 } |
| 319 return []; | 274 return []; |
| 320 } | 275 } |
| 321 | 276 |
| 322 /** | 277 /** |
| 323 * @param {!Workspace.UISourceCode} uiSourceCode | 278 * @param {!Workspace.UISourceCode} uiSourceCode |
| 324 */ | 279 */ |
| 325 _formatUISourceCodeScript(uiSourceCode) { | 280 _formatUISourceCodeScript(uiSourceCode) { |
| 326 var formattedPath = this._formattedPaths.get(uiSourceCode.project().id() + ' :' + uiSourceCode.url()); | 281 var formattedPath = this._formattedPaths.get(uiSourceCode.project().id() + ' :' + uiSourceCode.url()); |
| 327 if (formattedPath) { | 282 if (formattedPath) { |
| 328 var uiSourceCodePath = formattedPath; | 283 var formattedUISourceCode = Workspace.workspace.uiSourceCode(this._project Id, formattedPath); |
| 329 var formattedUISourceCode = this._workspace.uiSourceCode(this._projectId, uiSourceCodePath); | 284 var formatData = |
| 330 var formatData = formattedUISourceCode ? this._formatData.get(formattedUIS ourceCode) : null; | 285 formattedUISourceCode && formattedUISourceCode[Sources.ScriptFormatter EditorAction._formatDataSymbol]; |
| 331 if (formatData) { | 286 if (formatData) { |
| 332 this._showIfNeeded( | 287 this._showIfNeeded( |
| 333 uiSourceCode, /** @type {!Workspace.UISourceCode} */ (formattedUISou rceCode), formatData.mapping); | 288 uiSourceCode, /** @type {!Workspace.UISourceCode} */ (formattedUISou rceCode), formatData.mapping); |
| 289 return; | |
| 334 } | 290 } |
| 335 return; | |
| 336 } | 291 } |
| 337 | 292 |
| 338 uiSourceCode.requestContent().then(contentLoaded.bind(this)); | 293 uiSourceCode.requestContent().then(contentLoaded.bind(this)); |
| 339 | 294 |
| 340 /** | 295 /** |
| 341 * @this {Sources.ScriptFormatterEditorAction} | 296 * @this {Sources.ScriptFormatterEditorAction} |
| 342 * @param {?string} content | 297 * @param {?string} content |
| 343 */ | 298 */ |
| 344 function contentLoaded(content) { | 299 function contentLoaded(content) { |
| 345 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourc eCode); | 300 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourc eCode); |
| 346 Sources.Formatter.format(uiSourceCode.contentType(), highlighterType, cont ent || '', innerCallback.bind(this)); | 301 Sources.Formatter.format(uiSourceCode.contentType(), highlighterType, cont ent || '', innerCallback.bind(this)); |
| 347 } | 302 } |
| 348 | 303 |
| 349 /** | 304 /** |
| 350 * @this {Sources.ScriptFormatterEditorAction} | 305 * @this {Sources.ScriptFormatterEditorAction} |
| 351 * @param {string} formattedContent | 306 * @param {string} formattedContent |
| 352 * @param {!Sources.FormatterSourceMapping} formatterMapping | 307 * @param {!Sources.FormatterSourceMapping} formatterMapping |
| 353 */ | 308 */ |
| 354 function innerCallback(formattedContent, formatterMapping) { | 309 function innerCallback(formattedContent, formatterMapping) { |
| 355 var scripts = this._scriptsForUISourceCode(uiSourceCode); | |
| 356 var formattedURL = uiSourceCode.url() + ':formatted'; | 310 var formattedURL = uiSourceCode.url() + ':formatted'; |
| 357 var contentProvider = | 311 var contentProvider = |
| 358 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con tentType(), formattedContent); | 312 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con tentType(), formattedContent); |
| 359 var formattedUISourceCode = this._project.addContentProvider(formattedURL, contentProvider); | 313 var formattedUISourceCode = this._project.addContentProvider(formattedURL, contentProvider); |
| 360 var formattedPath = formattedUISourceCode.url(); | 314 var formatData = |
| 361 var formatData = new Sources.FormatterScriptMapping.FormatData( | 315 new Sources.FormatterScriptMapping.FormatData(uiSourceCode, formattedU ISourceCode, formatterMapping); |
| 362 uiSourceCode.project().id(), uiSourceCode.url(), formatterMapping, scr ipts); | 316 formattedUISourceCode[Sources.ScriptFormatterEditorAction._formatDataSymbo l] = formatData; |
| 363 this._formatData.set(formattedUISourceCode, formatData); | 317 |
| 364 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); | 318 var path = formatData.originalPath(); |
| 365 this._formattedPaths.set(path, formattedPath); | 319 this._formattedPaths.set(path, formattedUISourceCode.url()); |
| 366 this._pathsToFormatOnLoad.add(path); | 320 this._pathsToFormatOnLoad.add(path); |
| 367 for (var i = 0; i < scripts.length; ++i) { | 321 |
| 368 this._uiSourceCodes.set(scripts[i], formattedUISourceCode); | 322 var scripts = Sources.ScriptFormatterEditorAction._scriptsForUISourceCode( uiSourceCode); |
| 369 var scriptMapping = | 323 if (!scripts) |
| 370 /** @type {!Sources.FormatterScriptMapping} */ ( | 324 return; |
| 371 this._scriptMappingByDebuggerModel.get(scripts[i].debuggerModel) ); | 325 for (var script of scripts) { |
| 372 Bindings.debuggerWorkspaceBinding.pushSourceMapping(scripts[i], scriptMa pping); | 326 script[Sources.ScriptFormatterEditorAction._formatDataSymbol] = formatDa ta; |
| 327 Bindings.debuggerWorkspaceBinding.pushSourceMapping(script, this._script Mapping); | |
| 373 } | 328 } |
| 374 | 329 |
| 375 var debuggerModels = SDK.targetManager.models(SDK.DebuggerModel); | 330 Bindings.debuggerWorkspaceBinding.setSourceMapping( |
| 376 for (var i = 0; i < debuggerModels.length; ++i) { | 331 scripts[0].debuggerModel, formattedUISourceCode, this._scriptMapping); |
| 377 var scriptMapping = | |
| 378 /** @type {!Sources.FormatterScriptMapping} */ (this._scriptMappingB yDebuggerModel.get(debuggerModels[i])); | |
| 379 Bindings.debuggerWorkspaceBinding.setSourceMapping(debuggerModels[i], fo rmattedUISourceCode, scriptMapping); | |
| 380 } | |
| 381 | 332 |
| 382 for (var decoration of uiSourceCode.allDecorations()) { | 333 for (var decoration of uiSourceCode.allDecorations()) { |
| 383 var range = decoration.range(); | 334 var range = decoration.range(); |
| 384 var startLocation = formatterMapping.originalToFormatted(range.startLine , range.startColumn); | 335 var startLocation = formatterMapping.originalToFormatted(range.startLine , range.startColumn); |
| 385 var endLocation = formatterMapping.originalToFormatted(range.endLine, ra nge.endColumn); | 336 var endLocation = formatterMapping.originalToFormatted(range.endLine, ra nge.endColumn); |
| 386 | 337 |
| 387 formattedUISourceCode.addDecoration( | 338 formattedUISourceCode.addDecoration( |
| 388 new TextUtils.TextRange(startLocation[0], startLocation[1], endLocat ion[0], endLocation[1]), | 339 new TextUtils.TextRange(startLocation[0], startLocation[1], endLocat ion[0], endLocation[1]), |
| 389 /** @type {string} */ (decoration.type()), decoration.data()); | 340 /** @type {string} */ (decoration.type()), decoration.data()); |
| 390 } | 341 } |
| 391 | 342 |
| 392 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMapping); | 343 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMapping); |
| 393 } | 344 } |
| 394 } | 345 } |
| 395 }; | 346 }; |
| 347 | |
| 348 Sources.ScriptFormatterEditorAction._formatDataSymbol = Symbol('formatData'); | |
| OLD | NEW |