mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:51:29 +00:00
[analysis_server] Sort fields in generated LSP types consistently
This simplifies an upcoming change switching from parsing LSP TypeScript definitions to using a new JSON definition (where items are not all in the same order). Change-Id: I33672d645a8a96702dbfcbf1c090dfc8f5254960 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244404 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
cd71694342
commit
b4ed709482
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -130,6 +130,9 @@ class AssistsCodeActionsTest extends AbstractCodeActionsTest {
|
|||
"textDocument": {
|
||||
"uri": "${mainFileUri.toString()}"
|
||||
},
|
||||
"context": {
|
||||
"diagnostics": []
|
||||
},
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
|
|
|
@ -23,7 +23,7 @@ void main() {
|
|||
method: Method.shutdown,
|
||||
jsonrpc: 'test');
|
||||
final output = json.encode(message.toJson());
|
||||
expect(output, equals('{"id":1,"method":"shutdown","jsonrpc":"test"}'));
|
||||
expect(output, equals('{"id":1,"jsonrpc":"test","method":"shutdown"}'));
|
||||
});
|
||||
|
||||
test('returns correct output for union types containing interface types',
|
||||
|
@ -34,7 +34,7 @@ void main() {
|
|||
expect(
|
||||
output,
|
||||
equals(
|
||||
'{"uri":"!uri","languageId":"!language","version":1,"text":"!text"}'));
|
||||
'{"languageId":"!language","text":"!text","uri":"!uri","version":1}'));
|
||||
});
|
||||
|
||||
test('returns correct output for types with lists', () {
|
||||
|
@ -54,26 +54,26 @@ void main() {
|
|||
);
|
||||
final output = json.encode(codeAction.toJson());
|
||||
final expected = '''{
|
||||
"range":{
|
||||
"start":{"line":1,"character":1},
|
||||
"end":{"line":2,"character":2}
|
||||
},
|
||||
"severity":1,
|
||||
"code":"test_err",
|
||||
"source":"/tmp/source.dart",
|
||||
"message":"err!!",
|
||||
"range":{
|
||||
"end":{"character":2,"line":2},
|
||||
"start":{"character":1,"line":1}
|
||||
},
|
||||
"relatedInformation":[
|
||||
{
|
||||
"location":{
|
||||
"uri":"y-uri",
|
||||
"range":{
|
||||
"start":{"line":1,"character":1},
|
||||
"end":{"line":2,"character":2}
|
||||
}
|
||||
"end":{"character":2,"line":2},
|
||||
"start":{"character":1,"line":1}
|
||||
},
|
||||
"uri":"y-uri"
|
||||
},
|
||||
"message":"message"
|
||||
}
|
||||
]
|
||||
],
|
||||
"severity":1,
|
||||
"source":"/tmp/source.dart"
|
||||
}'''
|
||||
.replaceAll(RegExp('[ \n]'), '');
|
||||
expect(output, equals(expected));
|
||||
|
@ -101,11 +101,11 @@ void main() {
|
|||
kind: FoldingRangeKind.Comment);
|
||||
final output = json.encode(foldingRange.toJson());
|
||||
final expected = '''{
|
||||
"startLine":1,
|
||||
"startCharacter":2,
|
||||
"endLine":3,
|
||||
"endCharacter":4,
|
||||
"kind":"comment"
|
||||
"endLine":3,
|
||||
"kind":"comment",
|
||||
"startCharacter":2,
|
||||
"startLine":1
|
||||
}'''
|
||||
.replaceAll(RegExp('[ \n]'), '');
|
||||
expect(output, equals(expected));
|
||||
|
@ -253,9 +253,12 @@ void main() {
|
|||
test('canParse records nested undefined fields', () {
|
||||
final reporter = LspJsonReporter('params');
|
||||
expect(
|
||||
CompletionParams.canParse(
|
||||
{'textDocument': <String, dynamic>{}}, reporter),
|
||||
isFalse);
|
||||
CompletionParams.canParse({
|
||||
'position': {'line': 1, 'character': 1},
|
||||
'textDocument': <String, dynamic>{},
|
||||
}, reporter),
|
||||
isFalse,
|
||||
);
|
||||
expect(reporter.errors, hasLength(greaterThanOrEqualTo(1)));
|
||||
expect(reporter.errors.first,
|
||||
equals('params.textDocument.uri must not be undefined'));
|
||||
|
@ -264,10 +267,12 @@ void main() {
|
|||
test('canParse records nested null fields', () {
|
||||
final reporter = LspJsonReporter('params');
|
||||
expect(
|
||||
CompletionParams.canParse({
|
||||
'textDocument': {'uri': null}
|
||||
}, reporter),
|
||||
isFalse);
|
||||
CompletionParams.canParse({
|
||||
'position': {'line': 1, 'character': 1},
|
||||
'textDocument': {'uri': null},
|
||||
}, reporter),
|
||||
isFalse,
|
||||
);
|
||||
expect(reporter.errors, hasLength(greaterThanOrEqualTo(1)));
|
||||
expect(reporter.errors.first,
|
||||
equals('params.textDocument.uri must not be null'));
|
||||
|
@ -276,10 +281,12 @@ void main() {
|
|||
test('canParse records nested fields of the wrong type', () {
|
||||
final reporter = LspJsonReporter('params');
|
||||
expect(
|
||||
CompletionParams.canParse({
|
||||
'textDocument': {'uri': 1}
|
||||
}, reporter),
|
||||
isFalse);
|
||||
CompletionParams.canParse({
|
||||
'position': {'line': 1, 'character': 1},
|
||||
'textDocument': {'uri': 1},
|
||||
}, reporter),
|
||||
isFalse,
|
||||
);
|
||||
expect(reporter.errors, hasLength(greaterThanOrEqualTo(1)));
|
||||
expect(reporter.errors.first,
|
||||
equals('params.textDocument.uri must be of type String'));
|
||||
|
@ -290,10 +297,11 @@ void main() {
|
|||
() {
|
||||
final reporter = LspJsonReporter('params');
|
||||
expect(
|
||||
WorkspaceEdit.canParse({
|
||||
'documentChanges': {'uri': 1}
|
||||
}, reporter),
|
||||
isFalse);
|
||||
WorkspaceEdit.canParse({
|
||||
'documentChanges': {'uri': 1}
|
||||
}, reporter),
|
||||
isFalse,
|
||||
);
|
||||
expect(reporter.errors, hasLength(greaterThanOrEqualTo(1)));
|
||||
expect(
|
||||
reporter.errors.first,
|
||||
|
|
|
@ -101,13 +101,16 @@ List<Field> _getAllFields(Interface? interface) {
|
|||
if (interface == null) {
|
||||
return [];
|
||||
}
|
||||
return interface.members
|
||||
|
||||
final allFields = interface.members
|
||||
.whereType<Field>()
|
||||
.followedBy(interface.baseTypes
|
||||
// This cast is safe because base types are always real types.
|
||||
.map((type) => _getAllFields(_interfaces[(type as Type).name]))
|
||||
.expand((ts) => ts))
|
||||
.toList();
|
||||
|
||||
return _getSortedUnique(allFields);
|
||||
}
|
||||
|
||||
/// Returns a copy of the list sorted by name with duplicates (by name+type) removed.
|
||||
|
|
Loading…
Reference in a new issue