Skip to content

Commit 9e75379

Browse files
DanTupCommit Queue
authored and
Commit Queue
committed
[analsysis_server] Fix missing types on record fields in LSP completion detail
Fixes Dart-Code/Dart-Code#4788 Change-Id: Iaa57a5e486dac6c1978b8576b4855f8c3e8955f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330107 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent ae78a3d commit 9e75379

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pkg/analysis_server/lib/src/lsp/mapping.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ CompletionDetail getCompletionDetail(
398398
}) {
399399
final element = suggestion.element;
400400
var parameters = element?.parameters;
401-
var returnType = element?.returnType;
401+
// Prefer the element return type (because it's available for things like
402+
// overrides) but fall back to the suggestion if there isn't one (to handle
403+
// records).
404+
var returnType = element?.returnType ?? suggestion.returnType;
402405

403406
// Extract the type from setters to be shown in the place a return type
404407
// would usually be shown.

pkg/analysis_server/test/lsp/completion_dart_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,36 @@ bool a = ^
598598
detail: null,
599599
);
600600
}
601+
602+
Future<void> test_record() async {
603+
final content = r'''
604+
void f((int, int) record) {
605+
record.$^
606+
}
607+
''';
608+
609+
await expectLabels(content,
610+
label: r'$1',
611+
labelDetail: ' int',
612+
labelDescription: null,
613+
filterText: null,
614+
detail: 'int');
615+
}
616+
617+
Future<void> test_variable() async {
618+
final content = r'''
619+
void f(int variable) {
620+
varia^
621+
}
622+
''';
623+
624+
await expectLabels(content,
625+
label: 'variable',
626+
labelDetail: ' int',
627+
labelDescription: null,
628+
filterText: null,
629+
detail: 'int');
630+
}
601631
}
602632

603633
@reflectiveTest

0 commit comments

Comments
 (0)