Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js

Issue 1768183003: DevTools: Support line markers in UISourceCode and Code Mirror (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wrap setGutterMarker's in an operation. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
(...skipping 19 matching lines...) Expand all
30 * @constructor 30 * @constructor
31 * @extends {WebInspector.SourceFrame} 31 * @extends {WebInspector.SourceFrame}
32 * @param {!WebInspector.UISourceCode} uiSourceCode 32 * @param {!WebInspector.UISourceCode} uiSourceCode
33 */ 33 */
34 WebInspector.UISourceCodeFrame = function(uiSourceCode) 34 WebInspector.UISourceCodeFrame = function(uiSourceCode)
35 { 35 {
36 this._uiSourceCode = uiSourceCode; 36 this._uiSourceCode = uiSourceCode;
37 WebInspector.SourceFrame.call(this, this._uiSourceCode); 37 WebInspector.SourceFrame.call(this, this._uiSourceCode);
38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteD elegate()); 38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteD elegate());
39 this._rowMessageBuckets = {}; 39 this._rowMessageBuckets = {};
40 /** @type {!Map<string, !Array<!WebInspector.UISourceCode.LineMarker>>} */
41 this._markersToDecorate = new Map();
40 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyChanged, this._onWorkingCopyChanged, this); 42 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyChanged, this._onWorkingCopyChanged, this);
41 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyCommitted, this._onWorkingCopyCommitted, this); 43 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyCommitted, this._onWorkingCopyCommitted, this);
42 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message Added, this._onMessageAdded, this); 44 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message Added, this._onMessageAdded, this);
43 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message Removed, this._onMessageRemoved, this); 45 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message Removed, this._onMessageRemoved, this);
46 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.LineMar kerAdded, this._onLineMarkerAdded, this);
47 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.LineMar kerRemoved, this._onLineMarkerRemoved, this);
44 this._updateStyle(); 48 this._updateStyle();
45 49
46 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this ._getErrorAnchor.bind(this), this._showErrorPopover.bind(this)); 50 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this ._getErrorAnchor.bind(this), this._showErrorPopover.bind(this));
47 this._errorPopoverHelper.setTimeout(100, 100); 51 this._errorPopoverHelper.setTimeout(100, 100);
48 } 52 }
49 53
50 WebInspector.UISourceCodeFrame.prototype = { 54 WebInspector.UISourceCodeFrame.prototype = {
51 /** 55 /**
52 * @return {!WebInspector.UISourceCode} 56 * @return {!WebInspector.UISourceCode}
53 */ 57 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 }, 115 },
112 116
113 /** 117 /**
114 * @override 118 * @override
115 */ 119 */
116 onTextEditorContentLoaded: function() 120 onTextEditorContentLoaded: function()
117 { 121 {
118 WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this); 122 WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this);
119 for (var message of this._uiSourceCode.messages()) 123 for (var message of this._uiSourceCode.messages())
120 this._addMessageToSource(message); 124 this._addMessageToSource(message);
125 this._decorateLineMarkers();
121 }, 126 },
122 127
123 /** 128 /**
124 * @override 129 * @override
125 * @param {!WebInspector.TextRange} oldRange 130 * @param {!WebInspector.TextRange} oldRange
126 * @param {!WebInspector.TextRange} newRange 131 * @param {!WebInspector.TextRange} newRange
127 */ 132 */
128 onTextChanged: function(oldRange, newRange) 133 onTextChanged: function(oldRange, newRange)
129 { 134 {
130 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, ne wRange); 135 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, ne wRange);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 }, 328 },
324 329
325 _updateBucketDecorations: function() 330 _updateBucketDecorations: function()
326 { 331 {
327 for (var line in this._rowMessageBuckets) { 332 for (var line in this._rowMessageBuckets) {
328 var bucket = this._rowMessageBuckets[line]; 333 var bucket = this._rowMessageBuckets[line];
329 bucket._updateDecoration(); 334 bucket._updateDecoration();
330 } 335 }
331 }, 336 },
332 337
338 /**
339 * @param {!WebInspector.Event} event
340 */
341 _onLineMarkerAdded: function(event)
342 {
343 var marker = /** @type {!WebInspector.UISourceCode.LineMarker} */ (event .data);
344 this._decorateLineMarker(marker);
pfeldman 2016/03/09 02:14:20 runtime.extensions(decorator, event.type).instance
alph 2016/03/09 22:42:18 Done.
345 },
346
347 /**
348 * @param {!WebInspector.Event} event
349 */
350 _onLineMarkerRemoved: function(event)
351 {
352 var marker = /** @type {!WebInspector.UISourceCode.LineMarker} */ (event .data);
pfeldman 2016/03/09 02:14:20 ditto
alph 2016/03/09 22:42:18 Done.
353 this._textEditor.setGutterMarker(marker.line(), marker.type(), null);
pfeldman 2016/03/09 02:14:20 How do you know what the decorator is doing? CodeM
alph 2016/03/09 22:42:18 Done.
354 },
355
356 _decorateLineMarkers: function()
357 {
358 for (var markers of this.uiSourceCode().lineMarkers().values())
359 markers.forEach(this._decorateLineMarker.bind(this));
360 },
361
362 /**
363 * @param {!WebInspector.UISourceCode.LineMarker} marker
364 */
365 _decorateLineMarker: function(marker)
366 {
367 var type = marker.type();
368 var markers = this._markersToDecorate.get(type);
369 if (markers) {
370 markers.push(marker);
371 return;
372 }
373 markers = [];
374 this._markersToDecorate.set(type, markers);
375 lineMarkerDecorator(marker.type()).then(decorateLineMarkers.bind(this, t ype, markers));
376
377 /**
378 * @param {string} type
379 * @param {!Array<!WebInspector.UISourceCode.LineMarker>} markers
380 * @param {!WebInspector.EditorLineMarkerDecorator} decorator
381 * @this {WebInspector.UISourceCodeFrame}
382 */
383 function decorateLineMarkers(type, markers, decorator)
384 {
385 for (var marker of markers)
386 this._textEditor.setGutterMarker(marker.line(), marker.type(), d ecorator.decorate(marker.data()));
387 this._markersToDecorate.delete(type);
388 }
389
390 /**
391 * @param {string} type
392 * @return {!Promise<!WebInspector.EditorLineMarkerDecorator>}
393 */
394 function lineMarkerDecorator(type)
395 {
396 var descriptor = self.runtime.extensions("@WebInspector.EditorLineMa rkerDecorator").find(extension => extension.descriptor().marker === type);
397 console.assert(descriptor, "Unknown decorator type.");
398 return descriptor.instancePromise();
399 }
400 },
401
333 __proto__: WebInspector.SourceFrame.prototype 402 __proto__: WebInspector.SourceFrame.prototype
334 } 403 }
335 404
336 WebInspector.UISourceCodeFrame._iconClassPerLevel = {}; 405 WebInspector.UISourceCodeFrame._iconClassPerLevel = {};
337 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "error-icon"; 406 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "error-icon";
338 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "warning-icon"; 407 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "warning-icon";
339 408
340 WebInspector.UISourceCodeFrame._lineClassPerLevel = {}; 409 WebInspector.UISourceCodeFrame._lineClassPerLevel = {};
341 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "text-editor-line-with-error"; 410 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "text-editor-line-with-error";
342 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "text-editor-line-with-warning"; 411 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "text-editor-line-with-warning";
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 616
548 /** 617 /**
549 * @param {!WebInspector.UISourceCode.Message} a 618 * @param {!WebInspector.UISourceCode.Message} a
550 * @param {!WebInspector.UISourceCode.Message} b 619 * @param {!WebInspector.UISourceCode.Message} b
551 * @return {number} 620 * @return {number}
552 */ 621 */
553 WebInspector.UISourceCode.Message.messageLevelComparator = function(a, b) 622 WebInspector.UISourceCode.Message.messageLevelComparator = function(a, b)
554 { 623 {
555 return WebInspector.UISourceCode.Message._messageLevelPriority[a.level()] - WebInspector.UISourceCode.Message._messageLevelPriority[b.level()]; 624 return WebInspector.UISourceCode.Message._messageLevelPriority[a.level()] - WebInspector.UISourceCode.Message._messageLevelPriority[b.level()];
556 } 625 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698