Skip to content

Commit

Permalink
[stable] [analysis_server] Fix missing closure completions in LSP
Browse files Browse the repository at this point in the history
Closure completions disappeared in eb73dba because we ended up wiping our the filterText/label when trying to clean them up for functions.

Fixes Dart-Code/Dart-Code#4837

Bug: Dart-Code/Dart-Code#4837
Change-Id: I536ce38624ee3f6047229ac58c3fe173d162079a
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/335822
Cherry-pick-request: #54112
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337341
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
DanTup authored and Commit Queue committed Nov 28, 2023
1 parent b6227bf commit 2c61450
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ This is a patch release that:
- Adjusts the nullablity computations in the implementation of the
upper bound algorithm in the CFE (issue [#53999][]).

- Fixes missing closure code completion entries for function parameters
(issue [#54112][]) for LSP-based editors like VS Code.

[#53999]: https://github.com/dart-lang/sdk/issues/53999
[#54112]: https://github.com/dart-lang/sdk/issues/54112

## 3.2.1 - 2023-11-22

Expand Down
8 changes: 7 additions & 1 deletion pkg/analysis_server/lib/src/lsp/mapping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,13 @@ lsp.CompletionItem toCompletionItem(
// Displayed labels may have additional info appended (for example '(...)' on
// callables and ` => ` on getters) that should not be included in filterText,
// so strip anything from the first paren/space.
final filterText = label.split(_completionFilterTextSplitPattern).first;
//
// Only do this if label doesn't start with the pattern, because if it does
// (for example for a closure `(a, b) {}`) we'll end up with an empty string
// but we should instead use the whole label.
final filterText = !label.startsWith(_completionFilterTextSplitPattern)
? label.split(_completionFilterTextSplitPattern).first
: label;

// If we're using label details, we also don't want the label to include any
// additional symbols as noted above, because they will appear in the extra
Expand Down
26 changes: 26 additions & 0 deletions pkg/analysis_server/test/lsp/completion_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,32 @@ class B {
expect(labels, contains('Deprecated(…)'));
}

Future<void> test_closure() async {
final content = '''
void f({void Function(int a, String b) closure}) {}
void g() {
f(closure: ^);
}
''';

final expectedContent = '''
void f({void Function(int a, String b) closure}) {}
void g() {
f(closure: (a, b) => ^,);
}
''';

await verifyCompletions(
mainFileUri,
content,
expectCompletions: ['(a, b) {}', '(a, b) =>'],
applyEditsFor: '(a, b) =>',
expectedContent: expectedContent,
);
}

Future<void> test_comment() async {
final content = '''
// foo ^
Expand Down

0 comments on commit 2c61450

Please sign in to comment.