mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Update the lsp generator to generate return types for all methods
Change-Id: Id1a90d770aa772327011ee8ccc7a13f0ca6f8de4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133961 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
58a9c22f80
commit
5d7f3093fd
2 changed files with 64 additions and 64 deletions
|
@ -713,7 +713,7 @@ class CodeActionKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is CodeActionKind && o._value == _value;
|
||||
}
|
||||
|
@ -2561,7 +2561,7 @@ class CompletionItemKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is CompletionItemKind && o._value == _value;
|
||||
}
|
||||
|
@ -3074,7 +3074,7 @@ class CompletionTriggerKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) =>
|
||||
o is CompletionTriggerKind && o._value == _value;
|
||||
|
@ -3941,7 +3941,7 @@ class DiagnosticSeverity {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is DiagnosticSeverity && o._value == _value;
|
||||
}
|
||||
|
@ -4910,7 +4910,7 @@ class DocumentHighlightKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) =>
|
||||
o is DocumentHighlightKind && o._value == _value;
|
||||
|
@ -6090,7 +6090,7 @@ class ErrorCodes {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is ErrorCodes && o._value == _value;
|
||||
}
|
||||
|
@ -6378,7 +6378,7 @@ class FailureHandlingKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is FailureHandlingKind && o._value == _value;
|
||||
}
|
||||
|
@ -6409,7 +6409,7 @@ class FileChangeType {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is FileChangeType && o._value == _value;
|
||||
}
|
||||
|
@ -6796,7 +6796,7 @@ class FoldingRangeKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is FoldingRangeKind && o._value == _value;
|
||||
}
|
||||
|
@ -7463,7 +7463,7 @@ class InsertTextFormat {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is InsertTextFormat && o._value == _value;
|
||||
}
|
||||
|
@ -7965,7 +7965,7 @@ class MarkupKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is MarkupKind && o._value == _value;
|
||||
}
|
||||
|
@ -8142,7 +8142,7 @@ class MessageType {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is MessageType && o._value == _value;
|
||||
}
|
||||
|
@ -8320,7 +8320,7 @@ class Method {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is Method && o._value == _value;
|
||||
}
|
||||
|
@ -10006,7 +10006,7 @@ class ResourceOperationKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) =>
|
||||
o is ResourceOperationKind && o._value == _value;
|
||||
|
@ -12010,7 +12010,7 @@ class SymbolKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is SymbolKind && o._value == _value;
|
||||
}
|
||||
|
@ -15752,7 +15752,7 @@ class TextDocumentSaveReason {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) =>
|
||||
o is TextDocumentSaveReason && o._value == _value;
|
||||
|
@ -15876,7 +15876,7 @@ class TextDocumentSyncKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is TextDocumentSyncKind && o._value == _value;
|
||||
}
|
||||
|
@ -16415,7 +16415,7 @@ class WatchKind {
|
|||
String toString() => _value.toString();
|
||||
|
||||
@override
|
||||
get hashCode => _value.hashCode;
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
bool operator ==(Object o) => o is WatchKind && o._value == _value;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import 'typescript_parser.dart';
|
|||
|
||||
final formatter = DartFormatter();
|
||||
Map<String, Interface> _interfaces = {};
|
||||
Map<String, List<String>> _subtypes = {};
|
||||
// TODO(dantup): Rename namespaces -> enums since they're always that now.
|
||||
Map<String, Namespace> _namespaces = {};
|
||||
// TODO(dantup): Rename namespaces -> enums since they're always that now.
|
||||
Map<String, List<String>> _subtypes = {};
|
||||
Map<String, TypeAlias> _typeAliases = {};
|
||||
|
||||
/// Whether our enum class allows any value (eg. should always return true
|
||||
|
@ -34,6 +34,13 @@ bool enumClassAllowsAnyValue(String name) {
|
|||
name != 'ResourceOperationKind';
|
||||
}
|
||||
|
||||
String generateDartForTypes(List<AstNode> types) {
|
||||
final buffer = IndentableStringBuffer();
|
||||
_getSorted(types).forEach((t) => _writeType(buffer, t));
|
||||
final formattedCode = _formatCode(buffer.toString());
|
||||
return formattedCode.trim() + '\n'; // Ensure a single trailing newline.
|
||||
}
|
||||
|
||||
void recordTypes(List<AstNode> types) {
|
||||
types
|
||||
.whereType<TypeAlias>()
|
||||
|
@ -52,13 +59,6 @@ void recordTypes(List<AstNode> types) {
|
|||
.forEach((namespace) => _namespaces[namespace.name] = namespace);
|
||||
}
|
||||
|
||||
String generateDartForTypes(List<AstNode> types) {
|
||||
final buffer = IndentableStringBuffer();
|
||||
_getSorted(types).forEach((t) => _writeType(buffer, t));
|
||||
final formattedCode = _formatCode(buffer.toString());
|
||||
return formattedCode.trim() + '\n'; // Ensure a single trailing newline.
|
||||
}
|
||||
|
||||
TypeBase resolveTypeAlias(TypeBase type, {resolveEnumClasses = false}) {
|
||||
if (type is Type && _typeAliases.containsKey(type.name)) {
|
||||
final alias = _typeAliases[type.name];
|
||||
|
@ -179,7 +179,7 @@ void _writeCanParseMethod(IndentableStringBuffer buffer, Interface interface) {
|
|||
buffer
|
||||
..writeIndentedln("if (!obj.containsKey('${field.name}')) {")
|
||||
..indent()
|
||||
..writeIndentedln('reporter.reportError("must not be undefined");')
|
||||
..writeIndentedln("reporter.reportError('must not be undefined');")
|
||||
..writeIndentedln('return false;')
|
||||
..outdent()
|
||||
..writeIndentedln('}');
|
||||
|
@ -188,7 +188,7 @@ void _writeCanParseMethod(IndentableStringBuffer buffer, Interface interface) {
|
|||
buffer
|
||||
..writeIndentedln("if (obj['${field.name}'] == null) {")
|
||||
..indent()
|
||||
..writeIndentedln('reporter.reportError("must not be null");')
|
||||
..writeIndentedln("reporter.reportError('must not be null');")
|
||||
..writeIndentedln('return false;')
|
||||
..outdent()
|
||||
..writeIndentedln('}');
|
||||
|
@ -204,7 +204,7 @@ void _writeCanParseMethod(IndentableStringBuffer buffer, Interface interface) {
|
|||
..write(')) {')
|
||||
..indent()
|
||||
..writeIndentedln(
|
||||
'reporter.reportError("must be of type ${field.type.dartTypeWithTypeArgs}");')
|
||||
"reporter.reportError('must be of type ${field.type.dartTypeWithTypeArgs}');")
|
||||
..writeIndentedln('return false;')
|
||||
..outdent()
|
||||
..writeIndentedln('}')
|
||||
|
@ -221,7 +221,7 @@ void _writeCanParseMethod(IndentableStringBuffer buffer, Interface interface) {
|
|||
..writeIndentedln('} else {')
|
||||
..indent()
|
||||
..writeIndentedln(
|
||||
'reporter.reportError("must be of type ${interface.nameWithTypeArgs}");')
|
||||
"reporter.reportError('must be of type ${interface.nameWithTypeArgs}');")
|
||||
..writeIndentedln('return false;')
|
||||
..outdent()
|
||||
..writeIndentedln('}')
|
||||
|
@ -266,15 +266,6 @@ void _writeConstructor(IndentableStringBuffer buffer, Interface interface) {
|
|||
}
|
||||
}
|
||||
|
||||
void _writeJsonHandler(IndentableStringBuffer buffer, Interface interface) {
|
||||
buffer
|
||||
..writeIndented('static const jsonHandler = ')
|
||||
..write('LspJsonHandler(')
|
||||
..write('${interface.name}.canParse, ${interface.name}.fromJson')
|
||||
..writeln(');')
|
||||
..writeln();
|
||||
}
|
||||
|
||||
void _writeDocCommentsAndAnnotations(
|
||||
IndentableStringBuffer buffer, AstNode node) {
|
||||
var comment = node.commentText?.trim();
|
||||
|
@ -343,7 +334,7 @@ void _writeEnumClass(IndentableStringBuffer buffer, Namespace namespace) {
|
|||
..writeln()
|
||||
..writeIndentedln('@override String toString() => _value.toString();')
|
||||
..writeln()
|
||||
..writeIndentedln('@override get hashCode => _value.hashCode;')
|
||||
..writeIndentedln('@override int get hashCode => _value.hashCode;')
|
||||
..writeln()
|
||||
..writeIndentedln(
|
||||
'bool operator ==(Object o) => o is ${namespace.name} && o._value == _value;')
|
||||
|
@ -558,6 +549,15 @@ void _writeInterface(IndentableStringBuffer buffer, Interface interface) {
|
|||
..writeln();
|
||||
}
|
||||
|
||||
void _writeJsonHandler(IndentableStringBuffer buffer, Interface interface) {
|
||||
buffer
|
||||
..writeIndented('static const jsonHandler = ')
|
||||
..write('LspJsonHandler(')
|
||||
..write('${interface.name}.canParse, ${interface.name}.fromJson')
|
||||
..writeln(');')
|
||||
..writeln();
|
||||
}
|
||||
|
||||
void _writeJsonMapAssignment(
|
||||
IndentableStringBuffer buffer, Field field, String mapName) {
|
||||
// If we are allowed to be undefined, we'll only add the value if set.
|
||||
|
@ -593,29 +593,6 @@ void _writeMembers(IndentableStringBuffer buffer, List<Member> members) {
|
|||
_getSorted(members).forEach((m) => _writeMember(buffer, m));
|
||||
}
|
||||
|
||||
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.
|
||||
buffer
|
||||
..writeIndentedln('Map<String, dynamic> toJson() {')
|
||||
..indent()
|
||||
..writeIndentedln('Map<String, dynamic> __result = {};');
|
||||
// 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);
|
||||
} else {
|
||||
for (var field in _getAllFields(interface)) {
|
||||
_writeJsonMapAssignment(buffer, field, '__result');
|
||||
}
|
||||
}
|
||||
buffer
|
||||
..writeIndentedln('return __result;')
|
||||
..outdent()
|
||||
..writeIndentedln('}');
|
||||
}
|
||||
|
||||
void _writeToJsonFieldsForResponseMessage(
|
||||
IndentableStringBuffer buffer, Interface interface) {
|
||||
const mapName = '__result';
|
||||
|
@ -645,6 +622,29 @@ void _writeToJsonFieldsForResponseMessage(
|
|||
..writeIndentedln('}');
|
||||
}
|
||||
|
||||
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.
|
||||
buffer
|
||||
..writeIndentedln('Map<String, dynamic> toJson() {')
|
||||
..indent()
|
||||
..writeIndentedln('Map<String, dynamic> __result = {};');
|
||||
// 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);
|
||||
} else {
|
||||
for (var field in _getAllFields(interface)) {
|
||||
_writeJsonMapAssignment(buffer, field, '__result');
|
||||
}
|
||||
}
|
||||
buffer
|
||||
..writeIndentedln('return __result;')
|
||||
..outdent()
|
||||
..writeIndentedln('}');
|
||||
}
|
||||
|
||||
void _writeToString(IndentableStringBuffer buffer, Interface interface) {
|
||||
buffer
|
||||
..writeIndentedln('@override')
|
||||
|
|
Loading…
Reference in a new issue