OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 Sources.SourceFormatData = class { | 5 Sources.SourceFormatData = class { |
6 /** | 6 /** |
7 * @param {!Workspace.UISourceCode} originalSourceCode | 7 * @param {!Workspace.UISourceCode} originalSourceCode |
8 * @param {!Workspace.UISourceCode} formattedSourceCode | 8 * @param {!Workspace.UISourceCode} formattedSourceCode |
9 * @param {!Sources.FormatterSourceMapping} mapping | 9 * @param {!Sources.FormatterSourceMapping} mapping |
10 */ | 10 */ |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 /** | 82 /** |
83 * @param {!Workspace.UISourceCode} uiSourceCode | 83 * @param {!Workspace.UISourceCode} uiSourceCode |
84 * @return {!Promise<!Sources.SourceFormatData>} | 84 * @return {!Promise<!Sources.SourceFormatData>} |
85 */ | 85 */ |
86 async format(uiSourceCode) { | 86 async format(uiSourceCode) { |
87 var formattedUISourceCode = this._formattedPaths.get(uiSourceCode.project().
id() + ':' + uiSourceCode.url()); | 87 var formattedUISourceCode = this._formattedPaths.get(uiSourceCode.project().
id() + ':' + uiSourceCode.url()); |
88 if (formattedUISourceCode) | 88 if (formattedUISourceCode) |
89 return Sources.SourceFormatData._for(formattedUISourceCode); | 89 return Sources.SourceFormatData._for(formattedUISourceCode); |
90 | 90 |
91 var content = await uiSourceCode.requestContent(); | 91 var content = await uiSourceCode.requestContent(); |
92 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourceC
ode); | |
93 var fulfillFormatPromise; | 92 var fulfillFormatPromise; |
94 var resultPromise = new Promise(fulfill => { | 93 var resultPromise = new Promise(fulfill => { |
95 fulfillFormatPromise = fulfill; | 94 fulfillFormatPromise = fulfill; |
96 }); | 95 }); |
97 Sources.Formatter.format(uiSourceCode.contentType(), highlighterType, conten
t || '', innerCallback.bind(this)); | 96 Sources.Formatter.format( |
| 97 uiSourceCode.contentType(), uiSourceCode.mimeType(), content || '', inne
rCallback.bind(this)); |
98 return resultPromise; | 98 return resultPromise; |
99 | 99 |
100 /** | 100 /** |
101 * @this Sources.SourceFormatter | 101 * @this Sources.SourceFormatter |
102 * @param {string} formattedContent | 102 * @param {string} formattedContent |
103 * @param {!Sources.FormatterSourceMapping} formatterMapping | 103 * @param {!Sources.FormatterSourceMapping} formatterMapping |
104 */ | 104 */ |
105 function innerCallback(formattedContent, formatterMapping) { | 105 function innerCallback(formattedContent, formatterMapping) { |
106 var formattedURL = uiSourceCode.url() + ':formatted'; | 106 var formattedURL = uiSourceCode.url() + ':formatted'; |
107 var contentProvider = | 107 var contentProvider = |
108 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con
tentType(), formattedContent); | 108 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con
tentType(), formattedContent); |
109 var formattedUISourceCode = this._project.addContentProvider(formattedURL,
contentProvider); | 109 var formattedUISourceCode = |
| 110 this._project.addContentProvider(formattedURL, contentProvider, uiSour
ceCode.mimeType()); |
110 var formatData = new Sources.SourceFormatData(uiSourceCode, formattedUISou
rceCode, formatterMapping); | 111 var formatData = new Sources.SourceFormatData(uiSourceCode, formattedUISou
rceCode, formatterMapping); |
111 formattedUISourceCode[Sources.SourceFormatData._formatDataSymbol] = format
Data; | 112 formattedUISourceCode[Sources.SourceFormatData._formatDataSymbol] = format
Data; |
112 this._scriptMapping._setSourceMappingEnabled(formatData, true); | 113 this._scriptMapping._setSourceMappingEnabled(formatData, true); |
113 this._styleMapping._setSourceMappingEnabled(formatData, true); | 114 this._styleMapping._setSourceMappingEnabled(formatData, true); |
114 | 115 |
115 var path = formatData.originalPath(); | 116 var path = formatData.originalPath(); |
116 this._formattedPaths.set(path, formattedUISourceCode); | 117 this._formattedPaths.set(path, formattedUISourceCode); |
117 | 118 |
118 for (var decoration of uiSourceCode.allDecorations()) { | 119 for (var decoration of uiSourceCode.allDecorations()) { |
119 var range = decoration.range(); | 120 var range = decoration.range(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return; | 284 return; |
284 if (enable) | 285 if (enable) |
285 styleHeader[Sources.SourceFormatData._formatDataSymbol] = formatData; | 286 styleHeader[Sources.SourceFormatData._formatDataSymbol] = formatData; |
286 else | 287 else |
287 delete styleHeader[Sources.SourceFormatData._formatDataSymbol]; | 288 delete styleHeader[Sources.SourceFormatData._formatDataSymbol]; |
288 Bindings.cssWorkspaceBinding.updateLocations(styleHeader); | 289 Bindings.cssWorkspaceBinding.updateLocations(styleHeader); |
289 } | 290 } |
290 }; | 291 }; |
291 | 292 |
292 Sources.sourceFormatter = new Sources.SourceFormatter(); | 293 Sources.sourceFormatter = new Sources.SourceFormatter(); |
OLD | NEW |