Chromium Code Reviews| 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 Components.CoverageProfile = class { | 5 Components.CoverageProfile = class { |
| 6 constructor() { | 6 constructor() { |
| 7 /** @type {!Multimap<string, !Protocol.CSS.SourceRange>} */ | |
| 8 this._rangeDecorations = new Multimap(); | |
| 7 this._updateTimer = null; | 9 this._updateTimer = null; |
| 8 this.reset(); | 10 this.reset(); |
| 11 | |
| 12 Workspace.workspace.uiSourceCodes().forEach(uiSourceCode => uiSourceCode.add EventListener( | |
|
caseq
2016/11/14 23:33:18
When does this happen? What about those source cod
| |
| 13 Workspace.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCode WorkingCopyChanged.bind(this), this)); | |
| 14 | |
| 15 this._hasEventListenerSymbol = Symbol('coverageEventListener'); | |
|
caseq
2016/11/14 23:33:18
How is this used?
| |
| 9 } | 16 } |
| 10 | 17 |
| 11 /** | 18 /** |
| 12 * @return {!Components.CoverageProfile} | 19 * @return {!Components.CoverageProfile} |
| 13 */ | 20 */ |
| 14 static instance() { | 21 static instance() { |
| 15 if (!Components.CoverageProfile._instance) | 22 if (!Components.CoverageProfile._instance) |
| 16 Components.CoverageProfile._instance = new Components.CoverageProfile(); | 23 Components.CoverageProfile._instance = new Components.CoverageProfile(); |
| 17 | 24 |
| 18 return Components.CoverageProfile._instance; | 25 return Components.CoverageProfile._instance; |
| 19 } | 26 } |
| 20 | 27 |
| 21 /** | 28 /** |
| 22 * @param {string} url | 29 * @param {string} url |
| 23 * @param {!Protocol.CSS.SourceRange} range | 30 * @param {!Protocol.CSS.SourceRange} range |
| 24 */ | 31 */ |
| 25 appendUnusedRule(url, range) { | 32 appendUnusedRule(url, range) { |
| 26 if (!url) | 33 if (!url) |
| 27 return; | 34 return; |
| 28 | 35 |
| 29 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url); | 36 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url); |
| 30 if (!uiSourceCode) | 37 if (!uiSourceCode) |
| 31 return; | 38 return; |
| 32 | 39 |
| 33 for (var line = range.startLine; line <= range.endLine; ++line) | 40 if (range.startColumn) |
| 34 uiSourceCode.addLineDecoration(line, Components.CoverageProfile.LineDecora tor.type, range.startColumn); | 41 range.startColumn--; |
| 42 | |
| 43 this._rangeDecorations.set(url, range); | |
| 44 this._markRangeDecoration(uiSourceCode, range); | |
| 35 } | 45 } |
| 36 | 46 |
| 37 reset() { | 47 reset() { |
| 38 Workspace.workspace.uiSourceCodes().forEach( | 48 Workspace.workspace.uiSourceCodes().forEach( |
| 39 uiSourceCode => uiSourceCode.removeAllLineDecorations(Components.Coverag eProfile.LineDecorator.type)); | 49 uiSourceCode => uiSourceCode.removeAllLineDecorations(Components.Coverag eProfile.LineDecorator.type)); |
| 40 } | 50 } |
| 51 | |
| 52 /** | |
| 53 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 54 * @param {!Protocol.CSS.SourceRange} range | |
| 55 */ | |
| 56 _markRangeDecoration(uiSourceCode, range) { | |
| 57 for (var line = range.startLine; line <= range.endLine; ++line) | |
| 58 uiSourceCode.addLineDecoration(line, Components.CoverageProfile.LineDecora tor.type, null); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * @param {?} event | |
|
caseq
2016/11/14 23:33:18
please annotate with type.
| |
| 63 */ | |
| 64 _uiSourceCodeWorkingCopyChanged(event) { | |
| 65 if (!event.data || !event.data.sourceMapping) | |
| 66 return; | |
| 67 this.reset(); | |
| 68 | |
| 69 var sourceMapping = event.data.sourceMapping; | |
| 70 var uiSourceCode = event.target; | |
| 71 if (!uiSourceCode.url()) | |
| 72 return; | |
| 73 | |
| 74 for (var decoration of this._rangeDecorations.get(uiSourceCode.url())) { | |
| 75 var oldRange = /** {!Protocol.CSS.SourceRange} */ (decoration); | |
|
caseq
2016/11/14 23:33:18
Why do we need the cast here?
| |
| 76 [decoration.startLine, decoration.startColumn] = sourceMapping.originalT oFormatted( | |
| 77 oldRan ge.startLine, oldRange.startColumn); | |
| 78 | |
| 79 [decoration.endLine, decoration.endColumn] = sourceMapping.originalToFor matted( | |
| 80 oldRan ge.endLine, oldRange.endColumn); | |
| 81 | |
| 82 this._markRangeDecoration(uiSourceCode, decoration); | |
| 83 } | |
| 84 } | |
| 41 }; | 85 }; |
| 42 | 86 |
| 43 /** | 87 /** |
| 44 * @implements {Sources.UISourceCodeFrame.LineDecorator} | 88 * @implements {Sources.UISourceCodeFrame.LineDecorator} |
| 45 */ | 89 */ |
| 46 Components.CoverageProfile.LineDecorator = class { | 90 Components.CoverageProfile.LineDecorator = class { |
| 47 /** | 91 /** |
| 48 * @override | 92 * @override |
| 49 * @param {!Workspace.UISourceCode} uiSourceCode | 93 * @param {!Workspace.UISourceCode} uiSourceCode |
| 50 * @param {!TextEditor.CodeMirrorTextEditor} textEditor | 94 * @param {!TextEditor.CodeMirrorTextEditor} textEditor |
| 51 */ | 95 */ |
| 52 decorate(uiSourceCode, textEditor) { | 96 decorate(uiSourceCode, textEditor) { |
| 53 var gutterType = 'CodeMirror-gutter-coverage'; | 97 var gutterType = 'CodeMirror-gutter-coverage'; |
| 54 | 98 |
| 55 var decorations = uiSourceCode.lineDecorations(Components.CoverageProfile.Li neDecorator.type); | 99 var decorations = uiSourceCode.lineDecorations(Components.CoverageProfile.Li neDecorator.type); |
| 56 textEditor.uninstallGutter(gutterType); | 100 textEditor.uninstallGutter(gutterType); |
| 57 if (!decorations) | 101 if (!decorations || !decorations.size) |
| 58 return; | 102 return; |
| 59 | 103 |
| 60 textEditor.installGutter(gutterType, false); | 104 textEditor.installGutter(gutterType, false); |
| 61 | 105 |
| 62 for (var decoration of decorations.values()) { | 106 for (var decoration of decorations.values()) { |
| 63 var element = createElementWithClass('div', 'text-editor-line-marker-cover age'); | 107 var element = createElementWithClass('div', 'text-editor-line-marker-cover age'); |
| 64 textEditor.setGutterDecoration(decoration.line(), gutterType, element); | 108 textEditor.setGutterDecoration(decoration.line(), gutterType, element); |
| 65 } | 109 } |
| 66 } | 110 } |
| 67 }; | 111 }; |
| 68 | 112 |
| 69 Components.CoverageProfile.LineDecorator.type = 'coverage'; | 113 Components.CoverageProfile.LineDecorator.type = 'coverage'; |
| OLD | NEW |