Skip to content

Commit 9820487

Browse files
DanTupCommit Queue
authored andcommitted
[analyzer] Support enclosingFragments that are local variables
Fixes at least some of Dart-Code/Dart-Code#5369. Change-Id: I367969335573e4659fc0932a5751d547b0942836 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401100 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent dbf6008 commit 9820487

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkg/analysis_server/test/lsp/document_highlights_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,44 @@ void f() {
2626
var _ = 2;
2727
print(/*[1*/_/*1]*/);
2828
}
29+
''');
30+
31+
Future<void> test_dartCode_issue5369_field() => _testMarkedContent('''
32+
class A {
33+
var /*[0*/^a/*0]*/ = [''].where((_) => true).toList();
34+
List<String> f() {
35+
return /*[1*/a/*1]*/;
36+
}
37+
}
38+
39+
var a; // Not a reference
40+
''');
41+
42+
Future<void> test_dartCode_issue5369_functionType() => _testMarkedContent('''
43+
class A {
44+
String m({ required String Function(String input) /*[0*/^f/*0]*/ }) {
45+
return /*[1*/f/*1]*/('');
46+
}
47+
}
48+
49+
var f; // Not a reference
50+
''');
51+
52+
Future<void> test_dartCode_issue5369_localVariable() => _testMarkedContent('''
53+
class A {
54+
List<String> f() {
55+
var /*[0*/^a/*0]*/ = [''].where((_) => true).toList();
56+
return /*[1*/a/*1]*/;
57+
}
58+
}
59+
60+
var a; // Not a reference
61+
''');
62+
63+
Future<void> test_dartCode_issue5369_topLevelVariable() =>
64+
_testMarkedContent('''
65+
var /*[0*/^a/*0]*/ = [''].where((_) => true).toList();
66+
var b = /*[1*/a/*1]*/;
2967
''');
3068

3169
Future<void> test_forInLoop() => _testMarkedContent('''

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5085,6 +5085,12 @@ class FunctionElementImpl extends ExecutableElementImpl
50855085
return libraryFragment;
50865086
case ExecutableFragment executableFragment:
50875087
return executableFragment;
5088+
case LocalVariableFragment variableFragment:
5089+
return variableFragment;
5090+
case TopLevelVariableFragment variableFragment:
5091+
return variableFragment;
5092+
case FieldFragment fieldFragment:
5093+
return fieldFragment;
50885094
}
50895095
// Local functions cannot be augmented.
50905096
throw UnsupportedError('This is not a fragment');

0 commit comments

Comments
 (0)