[analysis_server] remove ignore of no_leading_underscores_for_local_identifiers in generated file

Part of #49059

Change-Id: I9d8771e71ca505d61442bc04b9f71fd02f1c7d5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245380
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Danny Tuppeny <danny@tuppeny.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Ahmed Ashour
2022-05-20 15:54:53 +00:00
committed by Commit Bot
parent 2b4939ad73
commit 77da5016fe
9 changed files with 1852 additions and 1842 deletions
@@ -19,8 +19,7 @@ class CompletionRequestOperation extends RequestOperation {
late Stopwatch stopwatch;
bool firstNotification = true;
CompletionRequestOperation(
super.converter, super.json);
CompletionRequestOperation(super.converter, super.json);
@override
Future<void>? perform(Driver driver) {
@@ -7,7 +7,6 @@
// "pkg/analysis_server/tool/lsp_spec/generate_all.dart".
// ignore_for_file: annotate_overrides
// ignore_for_file: no_leading_underscores_for_local_identifiers
// ignore_for_file: prefer_is_not_operator
// ignore_for_file: unnecessary_parenthesis
@@ -41,9 +40,9 @@ class AnalyzerStatusParams implements ToJsonable {
final bool isAnalyzing;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['isAnalyzing'] = isAnalyzing;
return __result;
var result = <String, Object?>{};
result['isAnalyzing'] = isAnalyzing;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -114,10 +113,10 @@ class ClosingLabel implements ToJsonable {
final Range range;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['label'] = label;
__result['range'] = range.toJson();
return __result;
var result = <String, Object?>{};
result['label'] = label;
result['range'] = range.toJson();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -202,8 +201,8 @@ class CompletionItemResolutionInfo implements ToJsonable {
}
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
return __result;
var result = <String, Object?>{};
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -251,9 +250,9 @@ class DartDiagnosticServer implements ToJsonable {
final int port;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['port'] = port;
return __result;
var result = <String, Object?>{};
result['port'] = port;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -351,15 +350,15 @@ class DartSuggestionSetCompletionItemResolutionInfo
final int rOffset;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['displayUri'] = displayUri;
__result['file'] = file;
__result['iLength'] = iLength;
__result['libId'] = libId;
__result['offset'] = offset;
__result['rLength'] = rLength;
__result['rOffset'] = rOffset;
return __result;
var result = <String, Object?>{};
result['displayUri'] = displayUri;
result['file'] = file;
result['iLength'] = iLength;
result['libId'] = libId;
result['offset'] = offset;
result['rLength'] = rLength;
result['rOffset'] = rOffset;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -576,22 +575,22 @@ class Element implements ToJsonable {
final String? typeParameters;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['kind'] = kind;
__result['name'] = name;
var result = <String, Object?>{};
result['kind'] = kind;
result['name'] = name;
if (parameters != null) {
__result['parameters'] = parameters;
result['parameters'] = parameters;
}
if (range != null) {
__result['range'] = range?.toJson();
result['range'] = range?.toJson();
}
if (returnType != null) {
__result['returnType'] = returnType;
result['returnType'] = returnType;
}
if (typeParameters != null) {
__result['typeParameters'] = typeParameters;
result['typeParameters'] = typeParameters;
}
return __result;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -774,30 +773,29 @@ class FlutterOutline implements ToJsonable {
final String? variableName;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (attributes != null) {
__result['attributes'] =
attributes?.map((item) => item.toJson()).toList();
result['attributes'] = attributes?.map((item) => item.toJson()).toList();
}
if (children != null) {
__result['children'] = children?.map((item) => item.toJson()).toList();
result['children'] = children?.map((item) => item.toJson()).toList();
}
if (className != null) {
__result['className'] = className;
result['className'] = className;
}
__result['codeRange'] = codeRange.toJson();
result['codeRange'] = codeRange.toJson();
if (dartElement != null) {
__result['dartElement'] = dartElement?.toJson();
result['dartElement'] = dartElement?.toJson();
}
__result['kind'] = kind;
result['kind'] = kind;
if (label != null) {
__result['label'] = label;
result['label'] = label;
}
__result['range'] = range.toJson();
result['range'] = range.toJson();
if (variableName != null) {
__result['variableName'] = variableName;
result['variableName'] = variableName;
}
return __result;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1000,13 +998,13 @@ class FlutterOutlineAttribute implements ToJsonable {
final Range? valueRange;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['label'] = label;
__result['name'] = name;
var result = <String, Object?>{};
result['label'] = label;
result['name'] = name;
if (valueRange != null) {
__result['valueRange'] = valueRange?.toJson();
result['valueRange'] = valueRange?.toJson();
}
return __result;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1128,16 +1126,16 @@ class IncomingMessage implements Message, ToJsonable {
final Object? params;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (clientRequestTime != null) {
__result['clientRequestTime'] = clientRequestTime;
result['clientRequestTime'] = clientRequestTime;
}
__result['jsonrpc'] = jsonrpc;
__result['method'] = method.toJson();
result['jsonrpc'] = jsonrpc;
result['method'] = method.toJson();
if (params != null) {
__result['params'] = params;
result['params'] = params;
}
return __result;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1250,12 +1248,12 @@ class Message implements ToJsonable {
final String jsonrpc;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (clientRequestTime != null) {
__result['clientRequestTime'] = clientRequestTime;
result['clientRequestTime'] = clientRequestTime;
}
__result['jsonrpc'] = jsonrpc;
return __result;
result['jsonrpc'] = jsonrpc;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1350,16 +1348,16 @@ class NotificationMessage implements IncomingMessage, ToJsonable {
final Object? params;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (clientRequestTime != null) {
__result['clientRequestTime'] = clientRequestTime;
result['clientRequestTime'] = clientRequestTime;
}
__result['jsonrpc'] = jsonrpc;
__result['method'] = method.toJson();
result['jsonrpc'] = jsonrpc;
result['method'] = method.toJson();
if (params != null) {
__result['params'] = params;
result['params'] = params;
}
return __result;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1479,14 +1477,14 @@ class Outline implements ToJsonable {
final Range range;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (children != null) {
__result['children'] = children?.map((item) => item.toJson()).toList();
result['children'] = children?.map((item) => item.toJson()).toList();
}
__result['codeRange'] = codeRange.toJson();
__result['element'] = element.toJson();
__result['range'] = range.toJson();
return __result;
result['codeRange'] = codeRange.toJson();
result['element'] = element.toJson();
result['range'] = range.toJson();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1612,9 +1610,9 @@ class PubPackageCompletionItemResolutionInfo
final String packageName;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['packageName'] = packageName;
return __result;
var result = <String, Object?>{};
result['packageName'] = packageName;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1688,10 +1686,10 @@ class PublishClosingLabelsParams implements ToJsonable {
final String uri;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['labels'] = labels.map((item) => item.toJson()).toList();
__result['uri'] = uri;
return __result;
var result = <String, Object?>{};
result['labels'] = labels.map((item) => item.toJson()).toList();
result['uri'] = uri;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1788,10 +1786,10 @@ class PublishFlutterOutlineParams implements ToJsonable {
final String uri;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['outline'] = outline.toJson();
__result['uri'] = uri;
return __result;
var result = <String, Object?>{};
result['outline'] = outline.toJson();
result['uri'] = uri;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1883,10 +1881,10 @@ class PublishOutlineParams implements ToJsonable {
final String uri;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['outline'] = outline.toJson();
__result['uri'] = uri;
return __result;
var result = <String, Object?>{};
result['outline'] = outline.toJson();
result['uri'] = uri;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -1997,17 +1995,17 @@ class RequestMessage implements IncomingMessage, ToJsonable {
final Object? params;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (clientRequestTime != null) {
__result['clientRequestTime'] = clientRequestTime;
result['clientRequestTime'] = clientRequestTime;
}
__result['id'] = id;
__result['jsonrpc'] = jsonrpc;
__result['method'] = method.toJson();
result['id'] = id;
result['jsonrpc'] = jsonrpc;
result['method'] = method.toJson();
if (params != null) {
__result['params'] = params;
result['params'] = params;
}
return __result;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -2142,13 +2140,13 @@ class ResponseError implements ToJsonable {
final String message;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['code'] = code.toJson();
var result = <String, Object?>{};
result['code'] = code.toJson();
if (data != null) {
__result['data'] = data;
result['data'] = data;
}
__result['message'] = message;
return __result;
result['message'] = message;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -2276,20 +2274,20 @@ class ResponseMessage implements Message, ToJsonable {
final Object? result;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var map = <String, Object?>{};
if (clientRequestTime != null) {
__result['clientRequestTime'] = clientRequestTime;
map['clientRequestTime'] = clientRequestTime;
}
__result['id'] = id;
__result['jsonrpc'] = jsonrpc;
map['id'] = id;
map['jsonrpc'] = jsonrpc;
if (error != null && result != null) {
throw 'result and error cannot both be set';
} else if (error != null) {
__result['error'] = error;
map['error'] = error;
} else {
__result['result'] = result;
map['result'] = result;
}
return __result;
return map;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -2415,11 +2413,11 @@ class SnippetTextEdit implements TextEdit, ToJsonable {
final Range range;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
__result['insertTextFormat'] = insertTextFormat.toJson();
__result['newText'] = newText;
__result['range'] = range.toJson();
return __result;
var result = <String, Object?>{};
result['insertTextFormat'] = insertTextFormat.toJson();
result['newText'] = newText;
result['range'] = range.toJson();
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
@@ -2532,12 +2530,12 @@ class ValidateRefactorResult implements ToJsonable {
final bool valid;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
var result = <String, Object?>{};
if (message != null) {
__result['message'] = message;
result['message'] = message;
}
__result['valid'] = valid;
return __result;
result['valid'] = valid;
return result;
}
static bool canParse(Object? obj, LspJsonReporter reporter) {
File diff suppressed because it is too large Load Diff
@@ -232,8 +232,8 @@ abstract class ServerStateMessageHandler {
try {
final result = await handler.handleMessage(message, messageInfo, token);
// Do a final check before returning the result, because if the request was
// cancelled we can save the overhead of serialising everything to JSON
// and the client to deserialising the same in order to read the ID to see
// cancelled we can save the overhead of serializing everything to JSON
// and the client to deserializing the same in order to read the ID to see
// that it was a request it didn't need (in the case of completions this
// can be quite large).
await Future.delayed(Duration.zero);
+1 -1
View File
@@ -813,7 +813,7 @@ lsp.Diagnostic pluginToDiagnostic(
tags: getDiagnosticTags(supportedTags, error),
relatedInformation: relatedInformation,
// Only include codeDescription if the client explicitly supports it
// (a minor optimization to avoid unnecessary payload/(de)serialisation).
// (a minor optimization to avoid unnecessary payload/(de)serialization).
codeDescription: clientSupportsCodeDescription && documentationUrl != null
? CodeDescription(href: documentationUrl)
: null,
@@ -217,7 +217,7 @@ class DocumentSymbolsTest extends AbstractLspAnalysisServerTest {
await initialize();
final result = await getDocumentSymbols(pubspecFileUri);
// Since the list is empty, it will deserialise into whatever the first
// Since the list is empty, it will deserialize into whatever the first
// type is, so just accept both types.
final symbols = result.map(
(docsymbols) => docsymbols,
@@ -92,7 +92,7 @@ void main() {
);
});
test('serialises enums to their underlying values', () {
test('serializes enums to their underlying values', () {
final foldingRange = FoldingRange(
startLine: 1,
startCharacter: 2,
@@ -374,9 +374,9 @@ void main() {
expect(message.params, isNull);
});
test('deserialises subtypes into the correct class', () {
// Create some JSON that includes a VersionedTextDocumentIdenfitier but
// where the class definition only references a TextDocumentIdemntifier.
test('deserializes subtypes into the correct class', () {
// Create some JSON that includes a VersionedTextDocumentIdentifier but
// where the class definition only references a TextDocumentIdentifier.
final input = jsonEncode(TextDocumentPositionParams(
textDocument: VersionedTextDocumentIdentifier(
version: 111, uri: 'file:///foo/bar.dart'),
@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:collection/collection.dart';
import 'package:dart_style/dart_style.dart';
import 'typescript_parser.dart';
@@ -18,7 +19,7 @@ Map<String, TypeAlias> _typeAliases = {};
/// from canParse() for the correct type). This is to allow us to have some
/// type safety for these values but without restricting which values are allowed.
/// This is to support things like custom error codes and also future changes
/// in the spec (it's important the server doesn't crash on deserialising
/// in the spec (it's important the server doesn't crash on deserializing
/// newer values).
bool enumClassAllowsAnyValue(String name) {
// The types listed here are the ones that have a guaranteed restricted type
@@ -53,7 +54,7 @@ void recordTypes(List<AstNode> types) {
types.whereType<Interface>().forEach((interface) {
_interfaces[interface.name] = interface;
// Keep track of our base classes so they can look up their super classes
// later in their fromJson() to deserialise into the most specific type.
// later in their fromJson() to deserialize into the most specific type.
for (var base in interface.baseTypes) {
final subTypes = _subtypes[base.dartType] ??= <String>[];
subTypes.add(interface.name);
@@ -136,6 +137,22 @@ TypeBase resolveTypeAlias(TypeBase type, {bool resolveEnumClasses = false}) {
return type;
}
String _determineVariableName(
Interface interface, Iterable<String> suggestions) {
var fieldNames = _getAllFields(interface).map((f) => f.name).toList();
var suggestion = suggestions.firstWhereOrNull((s) => !fieldNames.contains(s));
if (suggestion != null) {
return suggestion;
}
var first = suggestions.firstOrNull ?? 'var';
for (var i = 1; true; i++) {
var suggestion = '$first$i';
if (!fieldNames.contains(suggestion)) {
return suggestion;
}
}
}
String _formatCode(String code) {
try {
code = formatter.format(code);
@@ -711,7 +728,7 @@ void _writeFromJsonConstructor(
..writeIndentedln('static ${interface.nameWithTypeArgs} '
'fromJson${interface.typeArgsString}(Map<String, Object?> json) {')
..indent();
// First check whether any of our subclasses can deserialise this.
// First check whether any of our subclasses can deserialize this.
for (final subclassName in _subtypes[interface.name] ?? const <String>[]) {
final subclass = _interfaces[subclassName]!;
buffer
@@ -874,9 +891,7 @@ void _writeToJsonCode(IndentableStringBuffer buffer, TypeBase type,
}
void _writeToJsonFieldsForResponseMessage(
IndentableStringBuffer buffer, Interface interface) {
const mapName = '__result';
IndentableStringBuffer buffer, Interface interface, String mapName) {
final allFields = _getAllFields(interface);
final standardFields =
allFields.where((f) => f.name != 'error' && f.name != 'result');
@@ -903,24 +918,25 @@ void _writeToJsonFieldsForResponseMessage(
}
void _writeToJsonMethod(IndentableStringBuffer buffer, Interface interface) {
// It's important the name we use for the map here isn't in use in the object
// already. 'result' was, so we prefix it with some underscores.
final mapName = _determineVariableName(interface,
['result', 'map', 'json', 'toReturn', 'results', 'value', 'values']);
buffer
..writeIndentedln('Map<String, Object?> toJson() {')
..indent()
..writeIndentedln('var __result = <String, Object?>{};');
..writeIndentedln('var $mapName = <String, Object?>{};');
// ResponseMessage must confirm to JSON-RPC which says only one of
// result/error can be included. Since this isn't encoded in the types we
// need to special-case it's toJson generation.
if (interface.name == 'ResponseMessage') {
_writeToJsonFieldsForResponseMessage(buffer, interface);
_writeToJsonFieldsForResponseMessage(buffer, interface, mapName);
} else {
for (var field in _getAllFields(interface)) {
_writeJsonMapAssignment(buffer, field, '__result');
_writeJsonMapAssignment(buffer, field, mapName);
}
}
buffer
..writeIndentedln('return __result;')
..writeIndentedln('return $mapName;')
..outdent()
..writeIndentedln('}');
}
@@ -167,7 +167,6 @@ String generatedFileHeader(int year, {bool importCustom = false}) => '''
// "pkg/analysis_server/tool/lsp_spec/generate_all.dart".
// ignore_for_file: annotate_overrides
// ignore_for_file: no_leading_underscores_for_local_identifiers
// ignore_for_file: prefer_is_not_operator
// ignore_for_file: unnecessary_parenthesis
@@ -276,7 +275,7 @@ List<AstNode> getCustomClasses() {
[
field('code', type: 'ErrorCodes'),
field('message', type: 'string'),
// This is Object? normally, but since this class can be serialised
// This is Object? normally, but since this class can be serialized
// we will crash if it data is set to something that can't be converted to
// JSON (for ex. Uri) so this forces anyone setting this to convert to a
// String.