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

Side by Side Diff: pkg/analysis_server/lib/src/protocol_server.dart

Issue 1517723002: Server custom error severity support (#24452). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: lib_renames Created 5 years 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 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 protocol.server; 5 library protocol.server;
6 6
7 import 'package:analysis_server/plugin/protocol/protocol.dart'; 7 import 'package:analysis_server/plugin/protocol/protocol.dart';
8 import 'package:analysis_server/plugin/protocol/protocol_dart.dart'; 8 import 'package:analysis_server/plugin/protocol/protocol_dart.dart';
9 import 'package:analysis_server/src/services/correction/fix.dart'; 9 import 'package:analysis_server/src/services/correction/fix.dart';
10 import 'package:analysis_server/src/services/search/search_engine.dart' 10 import 'package:analysis_server/src/services/search/search_engine.dart'
11 as engine; 11 as engine;
12 import 'package:analyzer/source/error_processor.dart';
12 import 'package:analyzer/src/generated/ast.dart' as engine; 13 import 'package:analyzer/src/generated/ast.dart' as engine;
13 import 'package:analyzer/src/generated/element.dart' as engine; 14 import 'package:analyzer/src/generated/element.dart' as engine;
14 import 'package:analyzer/src/generated/engine.dart' as engine; 15 import 'package:analyzer/src/generated/engine.dart' as engine;
15 import 'package:analyzer/src/generated/error.dart' as engine; 16 import 'package:analyzer/src/generated/error.dart' as engine;
16 import 'package:analyzer/src/generated/source.dart' as engine; 17 import 'package:analyzer/src/generated/source.dart' as engine;
17 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; 18 import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
18 19
19 export 'package:analysis_server/plugin/protocol/protocol.dart'; 20 export 'package:analysis_server/plugin/protocol/protocol.dart';
20 export 'package:analysis_server/plugin/protocol/protocol_dart.dart'; 21 export 'package:analysis_server/plugin/protocol/protocol_dart.dart';
21 22
22 /** 23 /**
23 * Returns a list of AnalysisErrors correponding to the given list of Engine 24 * Returns a list of AnalysisErrors corresponding to the given list of Engine
24 * errors. 25 * errors.
25 */ 26 */
26 List<AnalysisError> doAnalysisError_listFromEngine( 27 List<AnalysisError> doAnalysisError_listFromEngine(
27 engine.LineInfo lineInfo, List<engine.AnalysisError> errors) { 28 engine.AnalysisContext context,
28 return errors.map((engine.AnalysisError error) { 29 engine.LineInfo lineInfo,
29 return newAnalysisError_fromEngine(lineInfo, error); 30 List<engine.AnalysisError> errors) {
30 }).toList(); 31 List<AnalysisError> serverErrors = <AnalysisError>[];
32 for (engine.AnalysisError error in errors) {
33 ErrorProcessor processor = ErrorProcessor.getProcessor(context, error);
34 if (processor != null) {
35 engine.ErrorSeverity severity = processor.severity;
36 // Errors with null severity are filtered out.
37 if (severity != null) {
38 // Specified severities override.
39 serverErrors
40 .add(newAnalysisError_fromEngine(lineInfo, error, severity));
41 }
42 } else {
43 serverErrors.add(newAnalysisError_fromEngine(lineInfo, error));
44 }
45 }
46 return serverErrors;
31 } 47 }
32 48
33 /** 49 /**
34 * Adds [edit] to the [FileEdit] for the given [element]. 50 * Adds [edit] to the [FileEdit] for the given [element].
35 */ 51 */
36 void doSourceChange_addElementEdit( 52 void doSourceChange_addElementEdit(
37 SourceChange change, engine.Element element, SourceEdit edit) { 53 SourceChange change, engine.Element element, SourceEdit edit) {
38 engine.AnalysisContext context = element.context; 54 engine.AnalysisContext context = element.context;
39 engine.Source source = element.source; 55 engine.Source source = element.source;
40 doSourceChange_addSourceEdit(change, context, source, edit); 56 doSourceChange_addSourceEdit(change, context, source, edit);
(...skipping 21 matching lines...) Expand all
62 return type != null ? type.displayName : 'dynamic'; 78 return type != null ? type.displayName : 'dynamic';
63 } else if (element is engine.FunctionTypeAliasElement) { 79 } else if (element is engine.FunctionTypeAliasElement) {
64 return element.returnType.toString(); 80 return element.returnType.toString();
65 } else { 81 } else {
66 return null; 82 return null;
67 } 83 }
68 } 84 }
69 85
70 /** 86 /**
71 * Construct based on error information from the analyzer engine. 87 * Construct based on error information from the analyzer engine.
88 *
89 * If an [errorSeverity] is specified, it will override the one in [error].
72 */ 90 */
73 AnalysisError newAnalysisError_fromEngine( 91 AnalysisError newAnalysisError_fromEngine(
74 engine.LineInfo lineInfo, engine.AnalysisError error) { 92 engine.LineInfo lineInfo, engine.AnalysisError error,
93 [engine.ErrorSeverity errorSeverity]) {
75 engine.ErrorCode errorCode = error.errorCode; 94 engine.ErrorCode errorCode = error.errorCode;
76 // prepare location 95 // prepare location
77 Location location; 96 Location location;
78 { 97 {
79 String file = error.source.fullName; 98 String file = error.source.fullName;
80 int offset = error.offset; 99 int offset = error.offset;
81 int length = error.length; 100 int length = error.length;
82 int startLine = -1; 101 int startLine = -1;
83 int startColumn = -1; 102 int startColumn = -1;
84 if (lineInfo != null) { 103 if (lineInfo != null) {
85 engine.LineInfo_Location lineLocation = lineInfo.getLocation(offset); 104 engine.LineInfo_Location lineLocation = lineInfo.getLocation(offset);
86 if (lineLocation != null) { 105 if (lineLocation != null) {
87 startLine = lineLocation.lineNumber; 106 startLine = lineLocation.lineNumber;
88 startColumn = lineLocation.columnNumber; 107 startColumn = lineLocation.columnNumber;
89 } 108 }
90 } 109 }
91 location = new Location(file, offset, length, startLine, startColumn); 110 location = new Location(file, offset, length, startLine, startColumn);
92 } 111 }
112
113 // Deafult to the error's severity if none is specified.
114 errorSeverity ??= errorCode.errorSeverity;
115
93 // done 116 // done
94 var severity = new AnalysisErrorSeverity(errorCode.errorSeverity.name); 117 var severity = new AnalysisErrorSeverity(errorSeverity.name);
95 var type = new AnalysisErrorType(errorCode.type.name); 118 var type = new AnalysisErrorType(errorCode.type.name);
96 String message = error.message; 119 String message = error.message;
97 String correction = error.correction; 120 String correction = error.correction;
98 bool fix = hasFix(error.errorCode); 121 bool fix = hasFix(error.errorCode);
99 return new AnalysisError(severity, type, location, message, 122 return new AnalysisError(severity, type, location, message,
100 correction: correction, hasFix: fix); 123 correction: correction, hasFix: fix);
101 } 124 }
102 125
103 /** 126 /**
104 * Create a Location based on an [engine.Element]. 127 * Create a Location based on an [engine.Element].
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (lineInfo != null) { 255 if (lineInfo != null) {
233 engine.LineInfo_Location offsetLocation = 256 engine.LineInfo_Location offsetLocation =
234 lineInfo.getLocation(range.offset); 257 lineInfo.getLocation(range.offset);
235 startLine = offsetLocation.lineNumber; 258 startLine = offsetLocation.lineNumber;
236 startColumn = offsetLocation.columnNumber; 259 startColumn = offsetLocation.columnNumber;
237 } 260 }
238 } 261 }
239 return new Location( 262 return new Location(
240 source.fullName, range.offset, range.length, startLine, startColumn); 263 source.fullName, range.offset, range.length, startLine, startColumn);
241 } 264 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_analysis.dart ('k') | pkg/analysis_server/lib/src/status/get_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698