[analysis_server] Fix duplicate reporting of some LSP type parsing errors

Parse errors for spec types were being reported twice - once by the containing object (in canParse()), and once by the nested canParse() call for the nested type.

This skips reporting the error for nested calls to a canParse() method, which will always report the error itself.

Change-Id: I03e4a9638fd6a3fc77eac918f6fd16def93327d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404105
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny
2025-01-14 08:56:41 -08:00
committed by Commit Queue
parent c36dac8fc9
commit 9b71817072
4 changed files with 24 additions and 215 deletions
@@ -288,7 +288,7 @@ void main() {
expect(reporter.errors.first, equals('params.kind must not be null'));
});
test('canParse records fields of the wrong type', () {
test('canParse records fields of the wrong type (non-spec types)', () {
var reporter = LspJsonReporter('params');
expect(RenameFileOptions.canParse({'overwrite': 1}, reporter), isFalse);
expect(reporter.errors, hasLength(1));
@@ -298,6 +298,20 @@ void main() {
);
});
test('canParse records fields of the wrong type (spec types)', () {
var reporter = LspJsonReporter('params');
expect(
ClientCapabilities.canParse({'textDocument': 1}, reporter),
isFalse,
);
expect(
reporter.errors.single,
equals(
'params.textDocument must be of type TextDocumentClientCapabilities',
),
);
});
test('canParse records nested undefined fields', () {
var reporter = LspJsonReporter('params');
expect(
@@ -514,8 +514,15 @@ void _writeCanParseType(
buffer
..write(') {')
..indent()
..writeIndentedln('reporter.reportError($quote$failureMessage$quote);')
..indent();
if (!_isSpecType(type)) {
// Only report an error for non-spec types, as spec types will have reported
// their own error in the nested canParse() call.
buffer.writeIndentedln(
'reporter.reportError($quote$failureMessage$quote);',
);
}
buffer
..writeIndentedln('return false;')
..outdent()
..writeIndentedln('}')
@@ -52,7 +52,6 @@ bool _canParseArgumentEdit(
}
if ((!nullCheck || value != null) &&
!ArgumentEdit.canParse(value, reporter)) {
reporter.reportError('must be of type ArgumentEdit');
return false;
}
} finally {
@@ -102,7 +101,6 @@ bool _canParseElement(
return false;
}
if ((!nullCheck || value != null) && !Element.canParse(value, reporter)) {
reporter.reportError('must be of type Element');
return false;
}
} finally {
@@ -128,7 +126,6 @@ bool _canParseErrorCodes(
}
if ((!nullCheck || value != null) &&
!ErrorCodes.canParse(value, reporter)) {
reporter.reportError('must be of type ErrorCodes');
return false;
}
} finally {
@@ -154,7 +151,6 @@ bool _canParseFlutterOutline(
}
if ((!nullCheck || value != null) &&
!FlutterOutline.canParse(value, reporter)) {
reporter.reportError('must be of type FlutterOutline');
return false;
}
} finally {
@@ -180,7 +176,6 @@ bool _canParseInsertTextFormat(
}
if ((!nullCheck || value != null) &&
!InsertTextFormat.canParse(value, reporter)) {
reporter.reportError('must be of type InsertTextFormat');
return false;
}
} finally {
@@ -501,7 +496,6 @@ bool _canParseMethod(
return false;
}
if ((!nullCheck || value != null) && !Method.canParse(value, reporter)) {
reporter.reportError('must be of type Method');
return false;
}
} finally {
@@ -526,7 +520,6 @@ bool _canParseOutline(
return false;
}
if ((!nullCheck || value != null) && !Outline.canParse(value, reporter)) {
reporter.reportError('must be of type Outline');
return false;
}
} finally {
@@ -551,7 +544,6 @@ bool _canParsePosition(
return false;
}
if ((!nullCheck || value != null) && !Position.canParse(value, reporter)) {
reporter.reportError('must be of type Position');
return false;
}
} finally {
@@ -576,7 +568,6 @@ bool _canParseRange(
return false;
}
if ((!nullCheck || value != null) && !Range.canParse(value, reporter)) {
reporter.reportError('must be of type Range');
return false;
}
} finally {
@@ -602,7 +593,6 @@ bool _canParseResponseError(
}
if ((!nullCheck || value != null) &&
!ResponseError.canParse(value, reporter)) {
reporter.reportError('must be of type ResponseError');
return false;
}
} finally {
@@ -653,7 +643,6 @@ bool _canParseTextDocumentIdentifier(
}
if ((!nullCheck || value != null) &&
!TextDocumentIdentifier.canParse(value, reporter)) {
reporter.reportError('must be of type TextDocumentIdentifier');
return false;
}
} finally {
@@ -679,7 +668,6 @@ bool _canParseTypeHierarchyAnchor(
}
if ((!nullCheck || value != null) &&
!TypeHierarchyAnchor.canParse(value, reporter)) {
reporter.reportError('must be of type TypeHierarchyAnchor');
return false;
}
} finally {
File diff suppressed because it is too large Load Diff