Skip to content

Commit c1d3bf8

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 36890. Ignore the name that contains the caret during completion.
The previous implementation worked fine in tests, when we asked for completion where the user does, but that's not what happens during actual completion. Actually the 'offset' is at the start of the identifier. R=brianwilkerson@google.com Bug: #36890 Change-Id: I5ceaff055580a18fe34d2c17ccacef8f4c7663b3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108282 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent a6afc5a commit c1d3bf8

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

pkg/analyzer_plugin/lib/src/utilities/change_builder/dart/syntactic_scope.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class SyntacticScopeNamesCollector extends RecursiveAstVisitor<void> {
300300

301301
void _addName(SimpleIdentifier node) {
302302
if (node == null) return;
303-
if (node.end == offset) return;
303+
if (node.offset <= offset && offset <= node.end) return;
304304

305305
names.add(node.name);
306306
}

pkg/analyzer_plugin/test/src/utilities/change_builder/dart/import_library_element_test.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,34 @@ class C {
205205
);
206206
}
207207

208-
test_formalParameter() async {
209-
newFile('/home/test/lib/a.dart', content: 'class A {}');
210-
newFile('/home/test/lib/b.dart', content: r'''
211-
export 'a.dart';
212-
''');
208+
test_formalParameter_end() async {
209+
newFile('/home/test/lib/a.dart', content: 'class AAA {}');
213210
await _assertImportLibraryElement(
214211
initialCode: r'''
215-
f(A^) {}
212+
f(AAA^) {}
216213
''',
217214
uriStr: 'package:test/a.dart',
218-
name: 'A',
215+
name: 'AAA',
216+
expectedCode: r'''
217+
import 'package:test/a.dart';
218+
219+
f(AAA) {}
220+
''',
221+
);
222+
}
223+
224+
test_formalParameter_start() async {
225+
newFile('/home/test/lib/a.dart', content: 'class AAA {}');
226+
await _assertImportLibraryElement(
227+
initialCode: r'''
228+
f(^AAA) {}
229+
''',
230+
uriStr: 'package:test/a.dart',
231+
name: 'AAA',
219232
expectedCode: r'''
220233
import 'package:test/a.dart';
221234
222-
f(A) {}
235+
f(AAA) {}
223236
''',
224237
);
225238
}

pkg/analyzer_plugin/test/src/utilities/change_builder/dart/syntactic_scope_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ N1 N2(N3 N4(N5 N6 ^1, N7), N8 ^2) {
352352
''');
353353
}
354354

355+
test_FormalParameter_nameOnly() {
356+
_assertScopeNames(code: r'''
357+
N1 N2(^1N3^2) {
358+
^3
359+
}
360+
''', expected: r'''
361+
1: {}
362+
2: {}
363+
3: N3
364+
''');
365+
}
366+
355367
test_ForStatement2_ForEachPartsWithDeclaration() {
356368
_enableExperiments();
357369
_assertScopeNames(code: r'''

0 commit comments

Comments
 (0)