Skip to content

Commit 1e64108

Browse files
DanTupCommit Queue
authored and
Commit Queue
committed
[analysis_server] Fix == overrides being truncated in LSP
The LSP completion mapping currently does some manipulation of values to fit better into the different fields LSP supports (to improve formatting and filtering). The code that splits the label on `=>` was also matching `==` in overrides but should not. This is a simple fix to the regex to solve the issue, although longer-term (or at least if we see other issues as a result of this manipulation) this logic should be pushed up to the source so we have reliable fields and don't need to split things this way. Fixes #56336 Change-Id: I056489df5aba417cab9162e027eb97579f71756b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378200 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 94e1824 commit 1e64108

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ final sortTextMaxValue = int.parse('9' * maximumRelevance.toString().length);
5959

6060
/// A regex used for splitting the display text in a completion so that
6161
/// filterText only includes the symbol name and not any additional text (such
62-
/// as parens, ` => `).
63-
final _completionFilterTextSplitPattern = RegExp(r'[=\(]');
62+
/// as parens, ` => `). Match `=>` but not `==` (which may appear in overrides).
63+
final _completionFilterTextSplitPattern = RegExp(r'=>|[\(]');
6464

6565
/// A regex to extract the type name from the parameter string of a setter
6666
/// completion item.
@@ -1018,6 +1018,9 @@ lsp.CompletionItem toCompletionItem(
10181018
// Only do this if label doesn't start with the pattern, because if it does
10191019
// (for example for a closure `(a, b) {}`) we'll end up with an empty string
10201020
// but we should instead use the whole label.
1021+
1022+
// TODO(dantup): Consider including more of these raw fields in the original
1023+
// suggestion to avoid needing to manipulate them in this way here.
10211024
var filterText = !label.startsWith(_completionFilterTextSplitPattern)
10221025
? label.split(_completionFilterTextSplitPattern).first.trim()
10231026
: label;

pkg/analysis_server/test/lsp/completion_dart_test.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,24 @@ void f() {
517517
detail: 'String');
518518
}
519519

520-
Future<void> test_local_override_annotation() async {
520+
Future<void> test_local_override_annotation_equals() async {
521+
var content = '''
522+
class Base {
523+
}
524+
525+
class Derived extends Base {
526+
@over^
527+
}
528+
''';
529+
await expectLabels(content,
530+
label: 'override ==',
531+
labelDetail: '(…) → bool',
532+
labelDescription: null,
533+
filterText: null,
534+
detail: '(Object other) → bool');
535+
}
536+
537+
Future<void> test_local_override_annotation_method() async {
521538
var content = '''
522539
class Base {
523540
String aa(String a) => '';
@@ -1901,7 +1918,7 @@ void f() {
19011918
/// the correct narrowed type in the `detail` field.
19021919
///
19031920
/// https://github.com/Dart-Code/Dart-Code/issues/4499
1904-
Future<void> test_getter_barrowedBySubclass() async {
1921+
Future<void> test_getter_narrowedBySubclass() async {
19051922
var content = '''
19061923
void f(MyItem item) {
19071924
item.na^

0 commit comments

Comments
 (0)