Skip to content

Commit 57cd03d

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Immediately return null for getEditableArgs of non-Dart files
See flutter/devtools#9048 Change-Id: I5edb446cbda6f9a4222f2aca8dfd72ccbf334287 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416780 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Elliott Brooks <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent fbb00e5 commit 57cd03d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

pkg/analysis_server/lib/src/lsp/handlers/custom/editable_arguments/handler_editable_arguments.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class EditableArgumentsHandler
4242
MessageInfo message,
4343
CancellationToken token,
4444
) async {
45+
if (!isDartDocument(params.textDocument)) {
46+
return success(null);
47+
}
48+
4549
var textDocument = params.textDocument;
4650
var position = params.position;
4751

pkg/analysis_server/test/shared/shared_editable_arguments_tests.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:analysis_server/lsp_protocol/protocol.dart';
66
import 'package:analyzer/src/test_utilities/test_code_format.dart';
77
import 'package:test/test.dart';
88

9+
import '../../tool/codebase/failing_tests.dart';
910
import '../lsp/request_helpers_mixin.dart';
1011
import '../utils/test_code_extensions.dart';
1112
import 'shared_test_interface.dart';
@@ -765,6 +766,23 @@ class MyWidget extends StatelessWidget {
765766
expect(result, isNull);
766767
}
767768

769+
Future<void> test_location_bad_nonDart() async {
770+
var textFilePath = pathContext.join(projectFolderPath, 'lib', 'test.txt');
771+
var textFileUri = Uri.file(textFilePath);
772+
773+
var content = 'my text';
774+
createFile(textFilePath, content);
775+
await initializeServer();
776+
await openFile(textFileUri, content);
777+
await currentAnalysis;
778+
var result = await getEditableArguments(
779+
textFileUri,
780+
Position(line: 0, character: 0),
781+
);
782+
783+
expect(result, isNull);
784+
}
785+
768786
Future<void> test_location_bad_unnamedConstructor_notWidget() async {
769787
var result = await getEditableArgumentsFor('''
770788
class MyWidget {

pkg/analysis_server/test/shared/shared_test_interface.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ abstract interface class SharedTestInterface {
2424
/// be overridden for tests that are deliberately testing invalid code.
2525
set failTestOnErrorDiagnostic(bool value);
2626

27+
/// Gets the full normalized path of the test project folder.
28+
String get projectFolderPath;
29+
2730
/// Gets the full normalized file path of a file named "test.dart" in the test
2831
/// project.
2932
String get testFilePath;

0 commit comments

Comments
 (0)