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

Side by Side Diff: dart/site/try/src/editor.dart

Issue 345143002: Handle incremental diagnostics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « dart/site/try/src/decoration.dart ('k') | dart/site/try/src/interaction_manager.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library trydart.editor; 5 library trydart.editor;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 8
9 import 'package:compiler/implementation/scanner/scannerlib.dart' show 9 import 'package:compiler/implementation/scanner/scannerlib.dart' show
10 EOF_TOKEN, 10 EOF_TOKEN,
11 ErrorToken, 11 ErrorToken,
12 StringScanner, 12 StringScanner,
13 Token; 13 Token;
14 14
15 import 'ui.dart' show 15 import 'ui.dart' show
16 currentTheme, 16 currentTheme,
17 hackDiv, 17 hackDiv,
18 interaction,
18 mainEditorPane, 19 mainEditorPane,
19 observer, 20 observer,
20 outputDiv; 21 outputDiv;
21 22
22 import 'decoration.dart' show 23 import 'decoration.dart' show
23 CodeCompletionDecoration, 24 CodeCompletionDecoration,
24 Decoration, 25 Decoration,
25 DiagnosticDecoration, 26 DiagnosticDecoration,
26 error, 27 error,
27 info, 28 info,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 CharacterData cdata = node; 146 CharacterData cdata = node;
146 // print('walking: ${node.data}'); 147 // print('walking: ${node.data}');
147 if (anchorNode == node) { 148 if (anchorNode == node) {
148 hasSelection = true; 149 hasSelection = true;
149 anchorOffset = selection.anchorOffset + offset; 150 anchorOffset = selection.anchorOffset + offset;
150 } 151 }
151 int newOffset = offset + cdata.length; 152 int newOffset = offset + cdata.length;
152 if (offset <= begin && begin < newOffset) { 153 if (offset <= begin && begin < newOffset) {
153 hasSelection = node == anchorNode; 154 hasSelection = node == anchorNode;
154 anchorOffset = selection.anchorOffset; 155 anchorOffset = selection.anchorOffset;
155 Node marker = new Text(""); 156 var alert;
156 node.replaceWith(marker);
157 // TODO(ahe): Don't highlight everything in the node. Find the
158 // relevant token (works for now as we create a node for each token,
159 // which is probably not great for performance).
160 if (kind == 'error') { 157 if (kind == 'error') {
161 marker.replaceWith(diagnostic(node, error(message))); 158 alert = error(message);
162 } else if (kind == 'warning') { 159 } else if (kind == 'warning') {
163 marker.replaceWith(diagnostic(node, warning(message))); 160 alert = warning(message);
164 } else { 161 } else {
165 marker.replaceWith(diagnostic(node, info(message))); 162 alert = info(message);
166 } 163 }
167 if (hasSelection) { 164 Element parent = node.parent;
168 selection.collapse(node, anchorOffset); 165 if (parent.classes.contains("diagnostic") &&
kasperl 2014/06/23 06:44:34 Consider factoring this code out in a method of it
ahe 2014/06/23 12:41:39 Yes. I hope to clean up this code when I fix the T
166 !interaction.oldDiagnostics.contains(parent)) {
167 Element other = parent.lastChild;
168 other.remove();
169 SpanElement wrapper = new SpanElement();
170 wrapper.style
171 ..fontWeight = 'normal';
172 var root = getShadowRoot(wrapper);
173 if (root is ShadowRoot) {
174 // When https://code.google.com/p/chromium/issues/detail?id=313458
175 // is fixed:
176 // var link = new LinkElement()
177 // ..rel = "stylesheet"
178 // ..type = "text/css"
179 // ..href = "dartlang-style.css";
180 // root.append(link);
181 root.append(
182 new StyleElement()..text = '@import url(dartlang-style.css)');
183 }
184 root
185 ..append(other)
186 ..append(alert);
187 other.style.display = 'block';
188 alert.style.display = 'block';
189 parent.append(wrapper);
190 } else {
191 if (interaction.oldDiagnostics.contains(parent)) {
192 node.remove();
193 parent.replaceWith(node);
194 }
195 Node marker = new Text("");
196 node.replaceWith(marker);
197 // TODO(ahe): Don't highlight everything in the node. Find the
198 // relevant token (works for now as we create a node for each token,
199 // which is probably not great for performance).
200 marker.replaceWith(diagnostic(node, alert));
201 if (hasSelection) {
202 selection.collapse(node, anchorOffset);
203 }
169 } 204 }
170 foundNode = true; 205 foundNode = true;
171 return; 206 return;
172 } 207 }
173 offset = newOffset; 208 offset = newOffset;
174 } else if (type == Node.ELEMENT_NODE) { 209 } else if (type == Node.ELEMENT_NODE) {
175 Element element = node; 210 Element element = node;
176 CssClassSet classes = element.classes; 211 CssClassSet classes = element.classes;
177 if (classes.contains('alert') || 212 if (classes.contains('alert') ||
178 classes.contains('dart-code-completion')) { 213 classes.contains('dart-code-completion')) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 270
236 diagnostic(text, tip) { 271 diagnostic(text, tip) {
237 if (text is String) { 272 if (text is String) {
238 text = new Text(text); 273 text = new Text(text);
239 } 274 }
240 return new AnchorElement() 275 return new AnchorElement()
241 ..classes.add('diagnostic') 276 ..classes.add('diagnostic')
242 ..append(text) 277 ..append(text)
243 ..append(tip); 278 ..append(tip);
244 } 279 }
OLDNEW
« no previous file with comments | « dart/site/try/src/decoration.dart ('k') | dart/site/try/src/interaction_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698