76dc2c4cfa
Originally we didn't use the LSP Request/Response classes, and just exposed the handlers through the legacy request/response. However there were some mismatches (such as legacy protocol always returns Map<String, Object?> but some LSP requests return Lists, LSP using int|String IDs, and LSP having numeric error codes that don't match legacy string error codes). This change uses LSP's request and Response by wrapping them inside a standard (legacy) handler. The LSP-over-Legacy handler has become a standard handler, and the params contain an "lspMessage" field that holds an LSP message, and the result contains an "lspResponse" field that contains an LSP response. If an LSP handler returns an error, it will be returned as an error inside the LSP response, which will be in a _successful_ legacy request (since that's how we can return an LSP response - as the result). Change-Id: I67973590ab32f3543d1a6e1b7279974e5e8832bc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315201 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
51 lines
1.7 KiB
Dart
51 lines
1.7 KiB
Dart
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
// 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 'api.dart';
|
|
|
|
/// Visitor specialized for generating Dart code.
|
|
class DartCodegenVisitor extends HierarchicalApiVisitor {
|
|
/// Type references in the spec that are named something else in Dart.
|
|
static const Map<String, String> _typeRenames = {
|
|
'long': 'int',
|
|
'object': 'Object',
|
|
};
|
|
|
|
DartCodegenVisitor(super.api);
|
|
|
|
/// Convert the given [TypeDecl] to a Dart type.
|
|
String dartType(TypeDecl type) {
|
|
if (type is TypeReference) {
|
|
var typeName = type.typeName;
|
|
var referencedDefinition = api.types[typeName];
|
|
var typeRename = _typeRenames[typeName];
|
|
if (typeRename != null) {
|
|
return typeRename;
|
|
}
|
|
if (referencedDefinition == null) {
|
|
return typeName;
|
|
}
|
|
var referencedType = referencedDefinition.type;
|
|
if (referencedType is TypeObject || referencedType is TypeEnum) {
|
|
return typeName;
|
|
}
|
|
return dartType(referencedType);
|
|
} else if (type is TypeList) {
|
|
return 'List<${dartType(type.itemType)}>';
|
|
} else if (type is TypeMap) {
|
|
return 'Map<${dartType(type.keyType)}, ${dartType(type.valueType)}>';
|
|
} else if (type is TypeUnion) {
|
|
return 'Object';
|
|
} else {
|
|
throw Exception("Can't convert to a dart type");
|
|
}
|
|
}
|
|
|
|
/// Return the Dart type for [field], nullable if the field is optional.
|
|
String fieldDartType(TypeObjectField field) {
|
|
var typeStr = dartType(field.type);
|
|
return field.optional ? '$typeStr?' : typeStr;
|
|
}
|
|
}
|