Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the json protocol to include context messages, locations #2715

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/dart_services/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ analyzer:
errors:
lines_longer_than_80_chars: ignore
unreachable_from_main: ignore
# Remove this once we remove the AnalysisIssue.sourceName field.
deprecated_member_use_from_same_package: ignore

linter:
rules:
Expand Down
1 change: 1 addition & 0 deletions pkgs/dart_services/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ abstract class AnalysisServerWrapper {
error.contextMessages?.map((m) => proto.DiagnosticMessage()
..message = utils.normalizeFilePaths(m.message)
..line = m.location.startLine
..column = m.location.startColumn
..charStart = m.location.offset
..charLength = m.location.length) ??
[],
Expand Down
22 changes: 18 additions & 4 deletions pkgs/dart_services/lib/src/common_server_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'protos/dart_services.pb.dart' as proto;
import 'pub.dart';
import 'scheduler.dart';
import 'shared/model.dart' as api;
import 'shared/services.dart';
import 'shelf_cors.dart' as shelf_cors;

export 'common_server_impl.dart' show log;
Expand Down Expand Up @@ -62,12 +63,25 @@ class CommonServerApi {
return api.AnalysisIssue(
kind: issue.kind,
message: issue.message,
location: api.Location(
charStart: issue.charStart,
charLength: issue.charLength,
line: issue.line,
column: issue.column,
),
correction: issue.hasCorrection() ? issue.correction : null,
url: issue.hasUrl() ? issue.url : null,
charStart: issue.charStart,
charLength: issue.charLength,
line: issue.line,
column: issue.column,
contextMessages: issue.diagnosticMessages.map((diagnostic) {
return api.DiagnosticMessage(
message: diagnostic.message,
location: Location(
charStart: diagnostic.charStart,
charLength: diagnostic.charLength,
line: diagnostic.line,
column: diagnostic.column,
),
);
}).toList(),
);
}).toList(),
packageImports: result.packageImports,
Expand Down
17 changes: 17 additions & 0 deletions pkgs/dart_services/lib/src/protos/dart_services.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ class DiagnosticMessage extends $pb.GeneratedMessage {
$core.int? line,
$core.int? charStart,
$core.int? charLength,
$core.int? column,
}) {
final $result = create();
if (message != null) {
Expand All @@ -902,6 +903,9 @@ class DiagnosticMessage extends $pb.GeneratedMessage {
if (charLength != null) {
$result.charLength = charLength;
}
if (column != null) {
$result.column = column;
}
return $result;
}
DiagnosticMessage._() : super();
Expand All @@ -923,6 +927,7 @@ class DiagnosticMessage extends $pb.GeneratedMessage {
protoName: 'charStart')
..a<$core.int>(4, _omitFieldNames ? '' : 'charLength', $pb.PbFieldType.O3,
protoName: 'charLength')
..a<$core.int>(5, _omitFieldNames ? '' : 'column', $pb.PbFieldType.O3)
..hasRequiredFields = false;

@$core.Deprecated('Using this can add significant overhead to your binary. '
Expand Down Expand Up @@ -995,6 +1000,18 @@ class DiagnosticMessage extends $pb.GeneratedMessage {
$core.bool hasCharLength() => $_has(3);
@$pb.TagNumber(4)
void clearCharLength() => clearField(4);

@$pb.TagNumber(5)
$core.int get column => $_getIZ(4);
@$pb.TagNumber(5)
set column($core.int v) {
$_setSignedInt32(4, v);
}

@$pb.TagNumber(5)
$core.bool hasColumn() => $_has(4);
@$pb.TagNumber(5)
void clearColumn() => clearField(5);
}

class VersionRequest extends $pb.GeneratedMessage {
Expand Down
3 changes: 2 additions & 1 deletion pkgs/dart_services/lib/src/protos/dart_services.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ const DiagnosticMessage$json = {
{'1': 'line', '3': 2, '4': 1, '5': 5, '10': 'line'},
{'1': 'charStart', '3': 3, '4': 1, '5': 5, '10': 'charStart'},
{'1': 'charLength', '3': 4, '4': 1, '5': 5, '10': 'charLength'},
{'1': 'column', '3': 5, '4': 1, '5': 5, '10': 'column'},
],
};

/// Descriptor for `DiagnosticMessage`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List diagnosticMessageDescriptor = $convert.base64Decode(
'ChFEaWFnbm9zdGljTWVzc2FnZRIYCgdtZXNzYWdlGAEgASgJUgdtZXNzYWdlEhIKBGxpbmUYAi'
'ABKAVSBGxpbmUSHAoJY2hhclN0YXJ0GAMgASgFUgljaGFyU3RhcnQSHgoKY2hhckxlbmd0aBgE'
'IAEoBVIKY2hhckxlbmd0aA==');
'IAEoBVIKY2hhckxlbmd0aBIWCgZjb2x1bW4YBSABKAVSBmNvbHVtbg==');

@$core.Deprecated('Use versionRequestDescriptor instead')
const VersionRequest$json = {
Expand Down
51 changes: 43 additions & 8 deletions pkgs/dart_services/lib/src/shared/model.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 30 additions & 4 deletions pkgs/dart_services/lib/src/shared/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkgs/dart_services/protos/dart_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ message DiagnosticMessage {
int32 line = 2;
int32 charStart = 3;
int32 charLength = 4;
int32 column = 5;
}

message VersionRequest {}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_services/test/server_v3_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void main() {
issue.message,
contains(
"A value of type 'String' can't be assigned to a variable of type 'int'"));
expect(issue.line, 2);
expect(issue.location.line, 2);
});

test('complete', () async {
Expand Down
3 changes: 3 additions & 0 deletions pkgs/dartpad_shared/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ analyzer:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
# Remove this once we remove the AnalysisIssue.sourceName field.
deprecated_member_use_from_same_package: ignore

linter:
rules:
Expand Down
51 changes: 43 additions & 8 deletions pkgs/dartpad_shared/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,21 @@ class AnalysisResponse {
class AnalysisIssue {
final String kind;
final String message;
final Location location;
final String? correction;
final String? url;
final int charStart;
final int charLength;
final int line;
final int column;
final List<DiagnosticMessage>? contextMessages;
@Deprecated('Remove this once no longer referenced')
final String sourceName;

AnalysisIssue({
required this.kind,
required this.message,
required this.location,
this.correction,
this.url,
this.charStart = -1,
this.charLength = 0,
this.line = -1,
this.column = -1,
this.contextMessages,
this.sourceName = 'main.dart',
});

factory AnalysisIssue.fromJson(Map<String, dynamic> json) =>
Expand All @@ -69,6 +68,42 @@ class AnalysisIssue {
String toString() => '[$kind] $message';
}

@JsonSerializable()
class Location {
final int charStart;
final int charLength;
final int line;
final int column;

Location({
this.charStart = -1,
this.charLength = 0,
this.line = -1,
this.column = -1,
});

factory Location.fromJson(Map<String, dynamic> json) =>
_$LocationFromJson(json);

Map<String, dynamic> toJson() => _$LocationToJson(this);
}

@JsonSerializable()
class DiagnosticMessage {
final String message;
final Location location;

DiagnosticMessage({
required this.message,
required this.location,
});

factory DiagnosticMessage.fromJson(Map<String, dynamic> json) =>
_$DiagnosticMessageFromJson(json);

Map<String, dynamic> toJson() => _$DiagnosticMessageToJson(this);
}

@JsonSerializable()
class CompileRequest {
final String source;
Expand Down
Loading
Loading