Skip to content
Snippets Groups Projects
Commit 3dc879f1 authored by FMorschel's avatar FMorschel Committed by Commit Queue
Browse files

[DAS] Fix go to type definition for formal parameter

R=paulberry@google.com

Fixes https://github.com/dart-lang/sdk/issues/56844

Change-Id: Idb5c9420ecd9fda1d961c7211758721c4c4c7522
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388660


Reviewed-by: default avatarSamuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: default avatarKonstantin Shcheglov <scheglov@google.com>
parent 0bd1bffa
No related branches found
No related tags found
No related merge requests found
......@@ -77,7 +77,7 @@ class TypeDefinitionHandler extends SharedMessageHandler<TypeDefinitionParams,
return success(_emptyResult);
}
SyntacticEntity originEntity;
SyntacticEntity? originEntity;
DartType? type;
if (node is NamedType) {
originEntity = node.name2;
......@@ -94,7 +94,11 @@ class TypeDefinitionHandler extends SharedMessageHandler<TypeDefinitionParams,
} else if (node is Expression) {
originEntity = node;
type = _getType(node);
} else {
} else if (node is FormalParameter) {
originEntity = node.name;
type = node.declaredElement?.type;
}
if (originEntity == null) {
return success(_emptyResult);
}
......
......@@ -108,6 +108,19 @@ const a^ = 'test string';
_expectNameRange(result.range, 'String');
}
Future<void> test_namedParameter_closure() async {
var code = TestCode.parse('''
void bar(void Function(String, {required int? value}) f) {}
void foo() {
bar((str, {required [!val^ue!]}) {});
}
''');
var result = await _getResult(code);
expect(result.originSelectionRange, code.range.range);
_expectSdkCoreType(result, 'int');
}
Future<void> test_nonDartFile() async {
var code = TestCode.parse('''
const a = '^';
......@@ -120,6 +133,32 @@ const a = '^';
expect(results, isEmpty);
}
Future<void> test_optionalNamedParameter_closure() async {
var code = TestCode.parse('''
void bar(void Function() f) {}
void foo() {
bar(({String [!s^tr!] = ''}) {});
}
''');
var result = await _getResult(code);
expect(result.originSelectionRange, code.range.range);
_expectSdkCoreType(result, 'String');
}
Future<void> test_optionalPositionalParameter_closure() async {
var code = TestCode.parse('''
void bar(void Function() f) {}
void foo() {
bar(([String [!s^tr!] = '']) {});
}
''');
var result = await _getResult(code);
expect(result.originSelectionRange, code.range.range);
_expectSdkCoreType(result, 'String');
}
Future<void> test_otherFile() async {
var otherFilePath = join(projectFolderPath, 'lib', 'other.dart');
var otherFileUri = pathContext.toUri(otherFilePath);
......@@ -153,6 +192,32 @@ void f(String a) {
_expectSdkCoreType(result, 'String');
}
Future<void> test_parameter_closure() async {
var code = TestCode.parse('''
void bar(void Function(String) f) {}
void foo() {
bar(([!st^r!]) {});
}
''');
var result = await _getResult(code);
expect(result.originSelectionRange, code.range.range);
_expectSdkCoreType(result, 'String');
}
Future<void> test_parameter_named_closure() async {
var code = TestCode.parse('''
void bar({required void Function(String) f}) {}
void foo() {
bar(f: ([!st^r!]) {});
}
''');
var result = await _getResult(code);
expect(result.originSelectionRange, code.range.range);
_expectSdkCoreType(result, 'String');
}
Future<void> test_parameter_wildcard() async {
var code = TestCode.parse('''
void f(String _) {
......@@ -227,6 +292,19 @@ _ f() => [!^a!];
expect(result.targetRange, rangeOfString(code, 'class _ { }'));
}
Future<void> test_typedParameter_closure() async {
var code = TestCode.parse('''
void bar(void Function(String) f) {}
void foo() {
bar((String [!s^tr!]) {});
}
''');
var result = await _getResult(code);
expect(result.originSelectionRange, code.range.range);
_expectSdkCoreType(result, 'String');
}
Future<void> test_unopenedFile() async {
var code = TestCode.parse('''
const a = [!'^'!];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment