Skip to content

Commit 27ba8fc

Browse files
DanTupCommit Queue
authored and
Commit Queue
committed
[analysis_server] Include type arguments in Type Hierarchy
Fixes Dart-Code/Dart-Code#4217. Change-Id: I8b8dec4ad25a9eb4a4f80dd036e8a9b61bb012d2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264981 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 9629401 commit 27ba8fc

File tree

8 files changed

+545
-107
lines changed

8 files changed

+545
-107
lines changed

pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart

+193
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,147 @@ class SnippetTextEdit implements TextEdit, ToJsonable {
18581858
String toString() => jsonEncoder.convert(toJson());
18591859
}
18601860

1861+
class TypeHierarchyAnchor implements ToJsonable {
1862+
static const jsonHandler = LspJsonHandler(
1863+
TypeHierarchyAnchor.canParse,
1864+
TypeHierarchyAnchor.fromJson,
1865+
);
1866+
1867+
TypeHierarchyAnchor({
1868+
required this.path,
1869+
required this.ref,
1870+
});
1871+
static TypeHierarchyAnchor fromJson(Map<String, Object?> json) {
1872+
final pathJson = json['path'];
1873+
final path =
1874+
(pathJson as List<Object?>).map((item) => item as int).toList();
1875+
final refJson = json['ref'];
1876+
final ref = refJson as String;
1877+
return TypeHierarchyAnchor(
1878+
path: path,
1879+
ref: ref,
1880+
);
1881+
}
1882+
1883+
/// Indices used to navigate from this anchor to the element.
1884+
final List<int> path;
1885+
1886+
/// The ElementLocation for this anchor element.
1887+
final String ref;
1888+
1889+
@override
1890+
Map<String, Object?> toJson() {
1891+
var result = <String, Object?>{};
1892+
result['path'] = path;
1893+
result['ref'] = ref;
1894+
return result;
1895+
}
1896+
1897+
static bool canParse(Object? obj, LspJsonReporter reporter) {
1898+
if (obj is Map<String, Object?>) {
1899+
if (!_canParseListInt(obj, reporter, 'path',
1900+
allowsUndefined: false, allowsNull: false)) {
1901+
return false;
1902+
}
1903+
return _canParseString(obj, reporter, 'ref',
1904+
allowsUndefined: false, allowsNull: false);
1905+
} else {
1906+
reporter.reportError('must be of type TypeHierarchyAnchor');
1907+
return false;
1908+
}
1909+
}
1910+
1911+
@override
1912+
bool operator ==(Object other) {
1913+
return other is TypeHierarchyAnchor &&
1914+
other.runtimeType == TypeHierarchyAnchor &&
1915+
listEqual(path, other.path, (int a, int b) => a == b) &&
1916+
ref == other.ref;
1917+
}
1918+
1919+
@override
1920+
int get hashCode => Object.hash(
1921+
lspHashCode(path),
1922+
ref,
1923+
);
1924+
1925+
@override
1926+
String toString() => jsonEncoder.convert(toJson());
1927+
}
1928+
1929+
class TypeHierarchyItemInfo implements ToJsonable {
1930+
static const jsonHandler = LspJsonHandler(
1931+
TypeHierarchyItemInfo.canParse,
1932+
TypeHierarchyItemInfo.fromJson,
1933+
);
1934+
1935+
TypeHierarchyItemInfo({
1936+
this.anchor,
1937+
required this.ref,
1938+
});
1939+
static TypeHierarchyItemInfo fromJson(Map<String, Object?> json) {
1940+
final anchorJson = json['anchor'];
1941+
final anchor = anchorJson != null
1942+
? TypeHierarchyAnchor.fromJson(anchorJson as Map<String, Object?>)
1943+
: null;
1944+
final refJson = json['ref'];
1945+
final ref = refJson as String;
1946+
return TypeHierarchyItemInfo(
1947+
anchor: anchor,
1948+
ref: ref,
1949+
);
1950+
}
1951+
1952+
/// An anchor element that can be used to navigate to this element preserving
1953+
/// type arguments.
1954+
final TypeHierarchyAnchor? anchor;
1955+
1956+
/// The ElementLocation for this element, used to re-locate the element when
1957+
/// subtypes/supertypes are fetched later.
1958+
final String ref;
1959+
1960+
@override
1961+
Map<String, Object?> toJson() {
1962+
var result = <String, Object?>{};
1963+
if (anchor != null) {
1964+
result['anchor'] = anchor?.toJson();
1965+
}
1966+
result['ref'] = ref;
1967+
return result;
1968+
}
1969+
1970+
static bool canParse(Object? obj, LspJsonReporter reporter) {
1971+
if (obj is Map<String, Object?>) {
1972+
if (!_canParseTypeHierarchyAnchor(obj, reporter, 'anchor',
1973+
allowsUndefined: true, allowsNull: false)) {
1974+
return false;
1975+
}
1976+
return _canParseString(obj, reporter, 'ref',
1977+
allowsUndefined: false, allowsNull: false);
1978+
} else {
1979+
reporter.reportError('must be of type TypeHierarchyItemInfo');
1980+
return false;
1981+
}
1982+
}
1983+
1984+
@override
1985+
bool operator ==(Object other) {
1986+
return other is TypeHierarchyItemInfo &&
1987+
other.runtimeType == TypeHierarchyItemInfo &&
1988+
anchor == other.anchor &&
1989+
ref == other.ref;
1990+
}
1991+
1992+
@override
1993+
int get hashCode => Object.hash(
1994+
anchor,
1995+
ref,
1996+
);
1997+
1998+
@override
1999+
String toString() => jsonEncoder.convert(toJson());
2000+
}
2001+
18612002
class ValidateRefactorResult implements ToJsonable {
18622003
static const jsonHandler = LspJsonHandler(
18632004
ValidateRefactorResult.canParse,
@@ -2184,6 +2325,32 @@ bool _canParseListFlutterOutlineAttribute(
21842325
return true;
21852326
}
21862327

2328+
bool _canParseListInt(
2329+
Map<String, Object?> map, LspJsonReporter reporter, String fieldName,
2330+
{required bool allowsUndefined, required bool allowsNull}) {
2331+
reporter.push(fieldName);
2332+
try {
2333+
if (!allowsUndefined && !map.containsKey(fieldName)) {
2334+
reporter.reportError('must not be undefined');
2335+
return false;
2336+
}
2337+
final value = map[fieldName];
2338+
final nullCheck = allowsNull || allowsUndefined;
2339+
if (!nullCheck && value == null) {
2340+
reporter.reportError('must not be null');
2341+
return false;
2342+
}
2343+
if ((!nullCheck || value != null) &&
2344+
(value is! List<Object?> || value.any((item) => item is! int))) {
2345+
reporter.reportError('must be of type List<int>');
2346+
return false;
2347+
}
2348+
} finally {
2349+
reporter.pop();
2350+
}
2351+
return true;
2352+
}
2353+
21872354
bool _canParseListOutline(
21882355
Map<String, Object?> map, LspJsonReporter reporter, String fieldName,
21892356
{required bool allowsUndefined, required bool allowsNull}) {
@@ -2395,6 +2562,32 @@ bool _canParseString(
23952562
return true;
23962563
}
23972564

2565+
bool _canParseTypeHierarchyAnchor(
2566+
Map<String, Object?> map, LspJsonReporter reporter, String fieldName,
2567+
{required bool allowsUndefined, required bool allowsNull}) {
2568+
reporter.push(fieldName);
2569+
try {
2570+
if (!allowsUndefined && !map.containsKey(fieldName)) {
2571+
reporter.reportError('must not be undefined');
2572+
return false;
2573+
}
2574+
final value = map[fieldName];
2575+
final nullCheck = allowsNull || allowsUndefined;
2576+
if (!nullCheck && value == null) {
2577+
reporter.reportError('must not be null');
2578+
return false;
2579+
}
2580+
if ((!nullCheck || value != null) &&
2581+
!TypeHierarchyAnchor.canParse(value, reporter)) {
2582+
reporter.reportError('must be of type TypeHierarchyAnchor');
2583+
return false;
2584+
}
2585+
} finally {
2586+
reporter.pop();
2587+
}
2588+
return true;
2589+
}
2590+
23982591
bool _canParseUri(
23992592
Map<String, Object?> map, LspJsonReporter reporter, String fieldName,
24002593
{required bool allowsUndefined, required bool allowsNull}) {

pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart

+35-3
Original file line numberDiff line numberDiff line change
@@ -31448,7 +31448,9 @@ class TypeHierarchyItem implements ToJsonable {
3144831448
});
3144931449
static TypeHierarchyItem fromJson(Map<String, Object?> json) {
3145031450
final dataJson = json['data'];
31451-
final data = dataJson;
31451+
final data = dataJson != null
31452+
? TypeHierarchyItemInfo.fromJson(dataJson as Map<String, Object?>)
31453+
: null;
3145231454
final detailJson = json['detail'];
3145331455
final detail = detailJson as String?;
3145431456
final kindJson = json['kind'];
@@ -31482,7 +31484,7 @@ class TypeHierarchyItem implements ToJsonable {
3148231484
/// supertypes or subtypes requests. It could also be used to identify the
3148331485
/// type hierarchy in the server, helping improve the performance on resolving
3148431486
/// supertypes and subtypes.
31485-
final LSPAny data;
31487+
final TypeHierarchyItemInfo? data;
3148631488

3148731489
/// More detail for this item, e.g. the signature of a function.
3148831490
final String? detail;
@@ -31511,7 +31513,7 @@ class TypeHierarchyItem implements ToJsonable {
3151131513
Map<String, Object?> toJson() {
3151231514
var result = <String, Object?>{};
3151331515
if (data != null) {
31514-
result['data'] = data;
31516+
result['data'] = data?.toJson();
3151531517
}
3151631518
if (detail != null) {
3151731519
result['detail'] = detail;
@@ -31529,6 +31531,10 @@ class TypeHierarchyItem implements ToJsonable {
3152931531

3153031532
static bool canParse(Object? obj, LspJsonReporter reporter) {
3153131533
if (obj is Map<String, Object?>) {
31534+
if (!_canParseTypeHierarchyItemInfo(obj, reporter, 'data',
31535+
allowsUndefined: true, allowsNull: false)) {
31536+
return false;
31537+
}
3153231538
if (!_canParseString(obj, reporter, 'detail',
3153331539
allowsUndefined: true, allowsNull: false)) {
3153431540
return false;
@@ -41981,6 +41987,32 @@ bool _canParseTypeHierarchyItem(
4198141987
return true;
4198241988
}
4198341989

41990+
bool _canParseTypeHierarchyItemInfo(
41991+
Map<String, Object?> map, LspJsonReporter reporter, String fieldName,
41992+
{required bool allowsUndefined, required bool allowsNull}) {
41993+
reporter.push(fieldName);
41994+
try {
41995+
if (!allowsUndefined && !map.containsKey(fieldName)) {
41996+
reporter.reportError('must not be undefined');
41997+
return false;
41998+
}
41999+
final value = map[fieldName];
42000+
final nullCheck = allowsNull || allowsUndefined;
42001+
if (!nullCheck && value == null) {
42002+
reporter.reportError('must not be null');
42003+
return false;
42004+
}
42005+
if ((!nullCheck || value != null) &&
42006+
!TypeHierarchyItemInfo.canParse(value, reporter)) {
42007+
reporter.reportError('must be of type TypeHierarchyItemInfo');
42008+
return false;
42009+
}
42010+
} finally {
42011+
reporter.pop();
42012+
}
42013+
return true;
42014+
}
42015+
4198442016
bool _canParseUniquenessLevel(
4198542017
Map<String, Object?> map, LspJsonReporter reporter, String fieldName,
4198642018
{required bool allowsUndefined, required bool allowsNull}) {

0 commit comments

Comments
 (0)