Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import '../../../shared/utils/utils.dart';
import 'property_editor_types.dart';

typedef EditableWidgetData =
({List<EditableProperty> properties, String? name, String? documentation});
({
List<EditableProperty> properties,
String? name,
String? documentation,
String? fileUri,
});

typedef EditArgumentFunction =
Future<EditArgumentResponse?> Function<T>({
Expand Down Expand Up @@ -84,6 +89,15 @@ class PropertyEditorController extends DisposableController
cursorPosition == _currentCursorPosition) {
return;
}
if (!textDocument.uriAsString.endsWith('.dart')) {
_editableWidgetData.value = (
properties: [],
name: null,
documentation: null,
fileUri: textDocument.uriAsString,
);
return;
}
_editableArgsDebouncer.run(
() => _updateWithEditableArgs(
textDocument: textDocument,
Expand Down Expand Up @@ -148,6 +162,7 @@ class PropertyEditorController extends DisposableController
properties: properties,
name: name,
documentation: result?.documentation,
fileUri: _currentDocument?.uriAsString,
);
filterData(activeFilter.value);
// Register impression.
Expand Down Expand Up @@ -180,6 +195,7 @@ class PropertyEditorController extends DisposableController
editableArgsResult.args.map(argToProperty).nonNulls.toList(),
name: editableArgsResult.name,
documentation: editableArgsResult.documentation,
fileUri: document?.uriAsString,
);
}
if (document != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ class PropertyEditorView extends StatelessWidget {
);
}

final (:properties, :name, :documentation, :fileUri) =
editableWidgetData;
if (fileUri != null && !fileUri.endsWith('.dart')) {
return const CenteredMessage(
message: 'No Dart code found at the current cursor location.',
);
}

final filteredProperties = values.fourth as List<EditableProperty>;
final (:properties, :name, :documentation) = editableWidgetData;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void main() {

group('on cursor location change', () {
void Function()? listener;
Completer? getEditableArgsCalled;

Future<List<EditableArgument>> waitForEditableArgs() {
final argsCompleter = Completer<List<EditableArgument>>();
Expand Down Expand Up @@ -87,6 +88,7 @@ void main() {
}

setUp(() {
getEditableArgsCalled = Completer<void>();
for (final MapEntry(key: location, value: result)
in locationToArgsResult.entries) {
when(
Expand All @@ -95,7 +97,11 @@ void main() {
textDocument: location.document,
position: location.position,
),
).thenAnswer((realInvocation) => Future.value(result));
).thenAnswer((realInvocation) {
getEditableArgsCalled?.complete();
getEditableArgsCalled = Completer<void>();
return Future.value(result);
});
}
});

Expand Down Expand Up @@ -175,6 +181,38 @@ void main() {
expect(titleValue, equals('Hello world!'));
});
});

testWidgets('verify does not fetch editable arguments for non-Dart files', (
tester,
) async {
return await tester.runAsync(() async {
// Load the property editor.
await tester.pumpWidget(wrap(propertyEditor));
final getEditableArgsCalledFuture = getEditableArgsCalled!.future;

// Send an active location changed event.
eventController.add(activeLocationChangedEventNotDart);

// Verify it doesn't trigger a request to getEditableArgs.
try {
await getEditableArgsCalledFuture.timeout(
const Duration(milliseconds: 100),
);
fail('getEditableArgs was unexpectedly called.');
} on TimeoutException catch (e) {
expect(e, isA<TimeoutException>());
}

// Verify "No Dart code" message is shown.
await tester.pumpAndSettle();
expect(
find.textContaining(
'No Dart code found at the current cursor location.',
),
findsOneWidget,
);
});
});
});

group('inputs for editable arguments', () {
Expand Down Expand Up @@ -1020,6 +1058,15 @@ final activeLocationChangedEvent4 = ActiveLocationChangedEvent(
textDocument: textDocument1,
);

final notADartDocument = TextDocument(
uriAsString: '/my/fake/other.js',
version: 1,
);
final activeLocationChangedEventNotDart = ActiveLocationChangedEvent(
selections: [editorSelection1],
textDocument: notADartDocument,
);

// Widget name and documentation
const widgetName = 'MyFlutterWidget';

Expand Down