Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sources/SourceFormatter.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sources/SourceFormatter.js b/third_party/WebKit/Source/devtools/front_end/sources/SourceFormatter.js |
| index 4ce4d5e5c47727ed9d7f1414dee25273f9b841d0..a6d00a8a9b5ef90b1e5f99c510a7efc9a8cf3356 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sources/SourceFormatter.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sources/SourceFormatter.js |
| @@ -36,7 +36,7 @@ Sources.SourceFormatter = class { |
| Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter, 'formatter', |
| true /* isServiceProject */); |
| - /** @type {!Map<string, !Workspace.UISourceCode>} */ |
| + /** @type {!Map<string, !Promise<!Sources.SourceFormatData>>} */ |
| this._formattedPaths = new Map(); |
| this._scriptMapping = new Sources.SourceFormatter.ScriptMapping(); |
| this._styleMapping = new Sources.SourceFormatter.StyleMapping(); |
| @@ -49,9 +49,9 @@ Sources.SourceFormatter = class { |
| */ |
| _onUISourceCodeRemoved(event) { |
| var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| - var formattedUISourceCode = this._formattedPaths.get(uiSourceCode.project().id() + ':' + uiSourceCode.url()); |
| - if (formattedUISourceCode) |
| - this.discardFormattedUISourceCode(formattedUISourceCode); |
| + var formatDataPromise = this._formattedPaths.get(uiSourceCode.project().id() + ':' + uiSourceCode.url()); |
| + if (formatDataPromise) |
| + formatDataPromise.then(formatData => this.discardFormattedUISourceCode(formatData.formattedSourceCode)); |
|
lushnikov
2017/05/17 23:39:08
Since you're caching per projectId + uiSourceCodeU
lushnikov
2017/05/17 23:57:32
this._formattedPath.delete(path);
|
| } |
| /** |
| @@ -67,8 +67,9 @@ Sources.SourceFormatter = class { |
| this._scriptMapping._setSourceMappingEnabled(formatData, false); |
| this._styleMapping._setSourceMappingEnabled(formatData, false); |
| this._project.removeFile(formattedUISourceCode.url()); |
| - this._formattedPaths.remove(formatData.originalPath()); |
| - return formatData.originalSourceCode; |
| + var originalSourceCode = formatData.originalSourceCode; |
| + this._formattedPaths.remove(originalSourceCode.project().id() + ':' + originalSourceCode.url()); |
| + return originalSourceCode; |
| } |
| /** |
| @@ -84,16 +85,18 @@ Sources.SourceFormatter = class { |
| * @return {!Promise<!Sources.SourceFormatData>} |
| */ |
| async format(uiSourceCode) { |
| - var formattedUISourceCode = this._formattedPaths.get(uiSourceCode.project().id() + ':' + uiSourceCode.url()); |
| - if (formattedUISourceCode) |
| - return Sources.SourceFormatData._for(formattedUISourceCode); |
| + var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); |
| + var resultPromise = this._formattedPaths.get(path); |
| + if (resultPromise) |
| + return resultPromise; |
| - var content = await uiSourceCode.requestContent(); |
| - var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourceCode); |
| var fulfillFormatPromise; |
| - var resultPromise = new Promise(fulfill => { |
| + resultPromise = new Promise(fulfill => { |
| fulfillFormatPromise = fulfill; |
| }); |
| + this._formattedPaths.set(path, resultPromise); |
| + var content = await uiSourceCode.requestContent(); |
| + var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourceCode); |
| Sources.Formatter.format(uiSourceCode.contentType(), highlighterType, content || '', innerCallback.bind(this)); |
| return resultPromise; |
| @@ -112,9 +115,6 @@ Sources.SourceFormatter = class { |
| this._scriptMapping._setSourceMappingEnabled(formatData, true); |
| this._styleMapping._setSourceMappingEnabled(formatData, true); |
| - var path = formatData.originalPath(); |
| - this._formattedPaths.set(path, formattedUISourceCode); |
| - |
| for (var decoration of uiSourceCode.allDecorations()) { |
| var range = decoration.range(); |
| var startLocation = formatterMapping.originalToFormatted(range.startLine, range.startColumn); |