Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
add the 'code' and 'column' fields to analysis issues (#1093)
Browse files Browse the repository at this point in the history
* add the 'code' and 'column' fields to analysis issues

* update test expectations

* Update for `protoc_plugin` 21.0.0

---------

Co-authored-by: Brett Morgan <brettmorgan@google.com>
  • Loading branch information
devoncarew and domesticmouse authored Jun 17, 2023
1 parent 4eaa80b commit 92f2f89
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ to generate Dart code. To install, please run:
$ dart pub global activate protoc_plugin
```

## Initialise Flutter
## Initialize Flutter

The Flutter SDK needs to be downloaded and setup.

Expand Down
15 changes: 9 additions & 6 deletions lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,22 @@ abstract class AnalysisServerWrapper {
final issues = errors.map((error) {
final issue = proto.AnalysisIssue()
..kind = error.severity.toLowerCase()
..code = error.code.toLowerCase()
..line = error.location.startLine
..column = error.location.startColumn
..message = utils.normalizeFilePaths(error.message)
..sourceName = path.basename(error.location.file)
..hasFixes = error.hasFix ?? false
..charStart = error.location.offset
..charLength = error.location.length
..diagnosticMessages.addAll(
error.contextMessages?.map((m) => proto.DiagnosticMessage()
..message = utils.normalizeFilePaths(m.message)
..line = m.location.startLine
..charStart = m.location.offset
..charLength = m.location.length) ??
[]);
error.contextMessages?.map((m) => proto.DiagnosticMessage()
..message = utils.normalizeFilePaths(m.message)
..line = m.location.startLine
..charStart = m.location.offset
..charLength = m.location.length) ??
[],
);

if (error.url != null) {
issue.url = error.url!;
Expand Down
26 changes: 26 additions & 0 deletions lib/src/protos/dart_services.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ class AnalysisIssue extends $pb.GeneratedMessage {
9, _omitFieldNames ? '' : 'diagnosticMessages', $pb.PbFieldType.PM,
protoName: 'diagnosticMessages', subBuilder: DiagnosticMessage.create)
..aOS(10, _omitFieldNames ? '' : 'correction')
..a<$core.int>(11, _omitFieldNames ? '' : 'column', $pb.PbFieldType.O3)
..aOS(12, _omitFieldNames ? '' : 'code')
..hasRequiredFields = false;

@$core.Deprecated('Using this can add significant overhead to your binary. '
Expand Down Expand Up @@ -623,6 +625,30 @@ class AnalysisIssue extends $pb.GeneratedMessage {
$core.bool hasCorrection() => $_has(9);
@$pb.TagNumber(10)
void clearCorrection() => clearField(10);

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

@$pb.TagNumber(11)
$core.bool hasColumn() => $_has(10);
@$pb.TagNumber(11)
void clearColumn() => clearField(11);

@$pb.TagNumber(12)
$core.String get code => $_getSZ(11);
@$pb.TagNumber(12)
set code($core.String v) {
$_setString(11, v);
}

@$pb.TagNumber(12)
$core.bool hasCode() => $_has(11);
@$pb.TagNumber(12)
void clearCode() => clearField(12);
}

class DiagnosticMessage extends $pb.GeneratedMessage {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/protos/dart_services.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ const AnalysisIssue$json = {
'10': 'diagnosticMessages'
},
{'1': 'correction', '3': 10, '4': 1, '5': 9, '10': 'correction'},
{'1': 'column', '3': 11, '4': 1, '5': 5, '10': 'column'},
{'1': 'code', '3': 12, '4': 1, '5': 9, '10': 'code'},
],
};

Expand All @@ -217,7 +219,7 @@ final $typed_data.Uint8List analysisIssueDescriptor = $convert.base64Decode(
'N0YXJ0Eh4KCmNoYXJMZW5ndGgYByABKAVSCmNoYXJMZW5ndGgSEAoDdXJsGAggASgJUgN1cmwS'
'VAoSZGlhZ25vc3RpY01lc3NhZ2VzGAkgAygLMiQuZGFydF9zZXJ2aWNlcy5hcGkuRGlhZ25vc3'
'RpY01lc3NhZ2VSEmRpYWdub3N0aWNNZXNzYWdlcxIeCgpjb3JyZWN0aW9uGAogASgJUgpjb3Jy'
'ZWN0aW9u');
'ZWN0aW9uEhYKBmNvbHVtbhgLIAEoBVIGY29sdW1uEhIKBGNvZGUYDCABKAlSBGNvZGU=');

@$core.Deprecated('Use diagnosticMessageDescriptor instead')
const DiagnosticMessage$json = {
Expand Down
2 changes: 2 additions & 0 deletions protos/dart_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ message AnalysisIssue {
string url = 8;
repeated DiagnosticMessage diagnosticMessages = 9;
string correction = 10;
int32 column = 11;
string code = 12;
}

message DiagnosticMessage {
Expand Down
2 changes: 2 additions & 0 deletions test/analysis_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ void defineTests() {
expect(results.issues.length, 1);
final issue = results.issues[0];
expect(issue.line, 2);
expect(issue.column, 7);
expect(issue.kind, 'info');
expect(issue.message,
'An uninitialized variable should have an explicit type annotation.');
expect(issue.code, 'prefer_typing_uninitialized_variables');
});

test('repro #126 - completions polluted on second request', () async {
Expand Down
4 changes: 4 additions & 0 deletions test/common_server_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ void main() {
'hasFixes': true,
'charStart': 29,
'charLength': 1,
'column': 16,
'code': 'expected_token',
}
]
},
Expand Down Expand Up @@ -677,6 +679,8 @@ void main() {
'hasFixes': true,
'charStart': 29,
'charLength': 1,
'column': 16,
'code': 'expected_token',
}
]
},
Expand Down

0 comments on commit 92f2f89

Please sign in to comment.