OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @unrestricted | 5 * @unrestricted |
6 */ | 6 */ |
7 Common.FormatterWorkerPool = class { | 7 Common.FormatterWorkerPool = class { |
8 constructor() { | 8 constructor() { |
9 this._taskQueue = []; | 9 this._taskQueue = []; |
10 /** @type {!Map<!Common.Worker, ?Common.FormatterWorkerPool.Task>} */ | 10 /** @type {!Map<!Common.Worker, ?Common.FormatterWorkerPool.Task>} */ |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 /** | 176 /** |
177 * @param {boolean} isLastChunk | 177 * @param {boolean} isLastChunk |
178 * @param {*} data | 178 * @param {*} data |
179 */ | 179 */ |
180 function onDataChunk(isLastChunk, data) { | 180 function onDataChunk(isLastChunk, data) { |
181 var items = /** @type {!Array.<!Common.FormatterWorkerPool.JSOutlineItem>}
*/ (data || []); | 181 var items = /** @type {!Array.<!Common.FormatterWorkerPool.JSOutlineItem>}
*/ (data || []); |
182 callback(isLastChunk, items); | 182 callback(isLastChunk, items); |
183 } | 183 } |
184 } | 184 } |
| 185 |
| 186 /** |
| 187 * @param {string} content |
| 188 * @param {string} mimeType |
| 189 * @param {function(boolean, !Array<!Common.FormatterWorkerPool.OutlineItem>)}
callback |
| 190 * @return {boolean} |
| 191 */ |
| 192 outlineForMimetype(content, mimeType, callback) { |
| 193 switch (mimeType) { |
| 194 case 'text/html': |
| 195 case 'text/javascript': |
| 196 this.javaScriptOutline(content, javaScriptCallback); |
| 197 return true; |
| 198 case 'text/css': |
| 199 this.parseCSS(content, cssCallback); |
| 200 return true; |
| 201 } |
| 202 return false; |
| 203 |
| 204 /** |
| 205 * @param {boolean} isLastChunk |
| 206 * @param {!Array<!Common.FormatterWorkerPool.JSOutlineItem>} items |
| 207 */ |
| 208 function javaScriptCallback(isLastChunk, items) { |
| 209 callback( |
| 210 isLastChunk, |
| 211 items.map(item => ({line: item.line, column: item.column, title: item.
name, subtitle: item.arguments}))); |
| 212 } |
| 213 |
| 214 /** |
| 215 * @param {boolean} isLastChunk |
| 216 * @param {!Array<!Common.FormatterWorkerPool.CSSRule>} rules |
| 217 */ |
| 218 function cssCallback(isLastChunk, rules) { |
| 219 callback( |
| 220 isLastChunk, |
| 221 rules.map( |
| 222 rule => ({line: rule.lineNumber, column: rule.columnNumber, title:
rule.selectorText || rule.atRule}))); |
| 223 } |
| 224 } |
185 }; | 225 }; |
186 | 226 |
187 Common.FormatterWorkerPool.MaxWorkers = 2; | 227 Common.FormatterWorkerPool.MaxWorkers = 2; |
188 | 228 |
189 /** | 229 /** |
190 * @unrestricted | 230 * @unrestricted |
191 */ | 231 */ |
192 Common.FormatterWorkerPool.Task = class { | 232 Common.FormatterWorkerPool.Task = class { |
193 /** | 233 /** |
194 * @param {string} method | 234 * @param {string} method |
(...skipping 14 matching lines...) Expand all Loading... |
209 /** @type {string} */ | 249 /** @type {string} */ |
210 this.content; | 250 this.content; |
211 /** @type {!Common.FormatterWorkerPool.FormatMapping} */ | 251 /** @type {!Common.FormatterWorkerPool.FormatMapping} */ |
212 this.mapping; | 252 this.mapping; |
213 } | 253 } |
214 }; | 254 }; |
215 | 255 |
216 /** @typedef {{original: !Array<number>, formatted: !Array<number>}} */ | 256 /** @typedef {{original: !Array<number>, formatted: !Array<number>}} */ |
217 Common.FormatterWorkerPool.FormatMapping; | 257 Common.FormatterWorkerPool.FormatMapping; |
218 | 258 |
| 259 /** @typedef {{line: number, column: number, title: string, subtitle: (string|un
defined) }} */ |
| 260 Common.FormatterWorkerPool.OutlineItem; |
| 261 |
219 Common.FormatterWorkerPool.JSOutlineItem = class { | 262 Common.FormatterWorkerPool.JSOutlineItem = class { |
220 constructor() { | 263 constructor() { |
221 /** @type {string} */ | 264 /** @type {string} */ |
222 this.name; | 265 this.name; |
223 /** @type {(string|undefined)} */ | 266 /** @type {(string|undefined)} */ |
224 this.arguments; | 267 this.arguments; |
225 /** @type {number} */ | 268 /** @type {number} */ |
226 this.line; | 269 this.line; |
227 /** @type {number} */ | 270 /** @type {number} */ |
228 this.column; | 271 this.column; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 this.selectors; | 338 this.selectors; |
296 /** @type {!Array<!Common.FormatterWorkerPool.SCSSProperty>} */ | 339 /** @type {!Array<!Common.FormatterWorkerPool.SCSSProperty>} */ |
297 this.properties; | 340 this.properties; |
298 /** @type {!Common.FormatterWorkerPool.TextRange} */ | 341 /** @type {!Common.FormatterWorkerPool.TextRange} */ |
299 this.styleRange; | 342 this.styleRange; |
300 } | 343 } |
301 }; | 344 }; |
302 | 345 |
303 /** @type {!Common.FormatterWorkerPool} */ | 346 /** @type {!Common.FormatterWorkerPool} */ |
304 Common.formatterWorkerPool; | 347 Common.formatterWorkerPool; |
OLD | NEW |