Skip to content

Commit

Permalink
Version 3.4.0-185.0.dev
Browse files Browse the repository at this point in the history
Merge 8ae8ffd into dev
  • Loading branch information
Dart CI committed Feb 28, 2024
2 parents 1e6b559 + 8ae8ffd commit 44af846
Show file tree
Hide file tree
Showing 43 changed files with 889 additions and 915 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ vars = {
#
# For more details, see https://github.com/dart-lang/sdk/issues/30164.
"dart_style_rev": "a6ad7693555a9add6f98ad6fd94de80d35c89415", # disable rev_sdk_deps.dart
"dartdoc_rev": "7a9df65fbca600ecb3ada4b08002c8ab9ee4e987", # https://github.com/dart-lang/dartdoc/issues/3680
"dartdoc_rev": "40c470e050161964ce2c1b566bcdf9be40494eef",
"ecosystem_rev": "3e4f2866d49c2448e44f51112956a689a2e50cd6",
"file_rev": "3aa06490bf34bddf04c7ea964a50c177a4ca0de7",
"fixnum_rev": "570b28adcfbfdd5b8a7230ea1d6ec0f9587493f1",
Expand Down
28 changes: 0 additions & 28 deletions pkg/analysis_server/lib/src/lsp/test_macros.dart

This file was deleted.

18 changes: 0 additions & 18 deletions pkg/analysis_server/test/analysis_server_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,6 @@ class PubPackageAnalysisServerTest extends ContextResolutionTest
);
}

/// Adds support for macros to the `package_config.json` file and creates a
/// `macros.dart` file that defines the given [macros]. The macros should not
/// include imports, the imports for macros will be added automatically.
void addMacros(List<String> macros) {
writeTestPackageConfig(
macro: true,
);
newFile(
'$testPackageLibPath/macros.dart',
[
'''
// There is no public API exposed yet, the in-progress API lives here.
import 'package:_fe_analyzer_shared/src/macros/api.dart';
''',
...macros
].join('\n'));
}

// TODO(scheglov): rename
void addTestFile(String content) {
newFile(testFilePath, content);
Expand Down
26 changes: 8 additions & 18 deletions pkg/analysis_server/test/integration/lsp/notification_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import 'dart:async';

import 'package:analysis_server/src/lsp/test_macros.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'
as analyzer_plugin;
import 'package:analyzer_plugin/src/utilities/client_uri_converter.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../../analysis_server_base.dart';
import '../../test_macros.dart';
import 'abstract_lsp_over_legacy.dart';

void main() {
Expand Down Expand Up @@ -53,7 +53,8 @@ class LspOverLegacyNotificationTest extends AbstractLspOverLegacyTest
}

Future<void> test_macroModifiedContentEvent() async {
writeTestPackageConfig(macro: true);
addMacros([declareInTypeMacro()]);

// TODO(dantup): There are existing methods like
// `ResourceProviderMixin.newAnalysisOptionsYamlFile` that would be useful
// here, but we'd need to split it up to not be specific to
Expand All @@ -67,31 +68,20 @@ class LspOverLegacyNotificationTest extends AbstractLspOverLegacyTest
'name: test',
);

var macroImplementationFilePath =
pathContext.join(testPackageRootPath, 'lib', 'with_foo.dart');
writeFile(macroImplementationFilePath, withFooMethodMacro);

var content = '''
import 'with_foo.dart';
import 'macros.dart';
f() {
A().foo();
}
@WithFoo()
class A {
void bar() {}
}
@DeclareInType('void foo() {}')
class A {}
''';
writeFile(testFile, content);

await enableCustomUriSupport();
await standardAnalysisSetup();
await analysisFinished;

// Modify the macro and expect a change event.
writeFile(macroImplementationFilePath,
withFooMethodMacro.replaceAll('void foo() {', 'void foo2() {'));
// Modify the file and expect a change event.
writeFile(testFile, content.replaceAll('void foo() {', 'void foo2() {'));
await dartTextDocumentContentDidChangeNotifications
.firstWhere((notification) => notification.uri == testFileMacroUri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'dart:io';
import 'package:analysis_server/protocol/protocol_constants.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/services/pub/pub_command.dart';
import 'package:analyzer/file_system/file_system.dart' as analyzer_fs;
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer_plugin/protocol/protocol_common.dart';
Expand Down Expand Up @@ -154,24 +155,6 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest
@override
String get testPackageRootPath => sourceDirectory.path;

/// Adds support for macros to the `package_config.json` file and creates a
/// `macros.dart` file that defines the given [macros]. The macros should not
/// include imports, the imports for macros will be added automatically.
void addMacros(List<String> macros) {
writeTestPackageConfig(
macro: true,
);
writeFile(
'$testPackageRootPath/lib/macros.dart',
[
'''
// There is no public API exposed yet, the in-progress API lives here.
import 'package:_fe_analyzer_shared/src/macros/api.dart';
''',
...macros
].join('\n'));
}

/// Print out any messages exchanged with the server. If some messages have
/// already been exchanged with the server, they are printed out immediately.
void debugStdio() {
Expand All @@ -191,6 +174,13 @@ import 'package:_fe_analyzer_shared/src/macros/api.dart';
List<AnalysisError>? getErrors(String pathname) =>
currentAnalysisErrors[pathname];

/// A wrapper around [writeFile] with a matching signature as the in-memory
/// tests so that [macros.TestMacros] can be used by both.
@override
analyzer_fs.File newFile(String filePath, String content) {
return resourceProvider.getFile(writeFile(filePath, content));
}

/// Read a source file with the given absolute [pathname].
String readFile(String pathname) => File(pathname).readAsStringSync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/legacy_analysis_server.dart';
import 'package:analysis_server/src/lsp/test_macros.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer_plugin/src/utilities/client_uri_converter.dart';
import 'package:language_server_protocol/protocol_generated.dart';
import 'package:test/expect.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../test_macros.dart';
import '../tool/lsp_spec/matchers.dart';
import 'server_abstract.dart';

Expand Down Expand Up @@ -85,22 +85,13 @@ class DartTextDocumentContentProviderTest extends AbstractLspAnalysisServerTest
}

Future<void> test_valid_content() async {
writeTestPackageConfig(macro: true);

newFile(
join(projectFolderPath, 'lib', 'with_foo.dart'), withFooMethodMacro);
addMacros([declareInTypeMacro()]);

var content = '''
import 'with_foo.dart';
f() {
A().foo();
}
import 'macros.dart';
@WithFoo()
class A {
void bar() {}
}
@DeclareInType('void foo() {}')
class A {}
''';

await initialize();
Expand All @@ -124,23 +115,13 @@ class A {
}

Future<void> test_valid_eventAndModifiedContent() async {
writeTestPackageConfig(macro: true);

var macroImplementationFilePath =
join(projectFolderPath, 'lib', 'with_foo.dart');
newFile(macroImplementationFilePath, withFooMethodMacro);
addMacros([declareInTypeMacro()]);

var content = '''
import 'with_foo.dart';
f() {
A().foo();
}
import 'macros.dart';
@WithFoo()
class A {
void bar() {}
}
@DeclareInType('void foo() {}')
class A {}
''';

await initialize();
Expand All @@ -154,15 +135,15 @@ class A {
await getDartTextDocumentContent(mainFileMacroUri);
expect(macroGeneratedContent!.content, contains('void foo() {'));

// Modify the macro and expect a change event.
// Modify the file and expect a change event.
await Future.wait([
dartTextDocumentContentDidChangeNotifications
.firstWhere((notification) => notification.uri == mainFileMacroUri),
// Replace the macro implementation to produce a `foo2()` method instead
// of `foo()`.
openFile(
toUri(macroImplementationFilePath),
withFooMethodMacro.replaceAll('void foo() {', 'void foo2() {'),
// Replace the main file to produce a `foo2()` method instead of `foo()`.
replaceFile(
2,
mainFileUri,
content.replaceAll('void foo() {', 'void foo2() {'),
)
]);

Expand Down
26 changes: 9 additions & 17 deletions pkg/analysis_server/test/lsp/definition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import 'package:analysis_server/lsp_protocol/protocol.dart' as lsp;
import 'package:analysis_server/src/analysis_server.dart';
import 'package:analysis_server/src/legacy_analysis_server.dart';
import 'package:analysis_server/src/lsp/test_macros.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/test_utilities/test_code_format.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../test_macros.dart';
import '../utils/test_code_extensions.dart';
import 'server_abstract.dart';

Expand Down Expand Up @@ -425,21 +425,15 @@ foo(int m) {
}

Future<void> test_macro_macroGeneratedFileToUserFile() async {
writeTestPackageConfig(macro: true);
addMacros([declareInTypeMacro()]);

setLocationLinkSupport(); // To verify the full set of ranges.
setDartTextDocumentContentProviderSupport();
newFile(
join(projectFolderPath, 'lib', 'with_foo.dart'), withFooMethodMacro);

final code = TestCode.parse('''
import 'with_foo.dart';
import 'macros.dart';
f() {
A().foo();
}
@WithFoo()
@DeclareInType(' void foo() { bar(); }')
class A {
/*[0*/void /*[1*/bar/*1]*/() {}/*0]*/
}
Expand Down Expand Up @@ -475,24 +469,22 @@ class A {
}

Future<void> test_macro_userFileToMacroGeneratedFile() async {
writeTestPackageConfig(macro: true);
addMacros([declareInTypeMacro()]);

// TODO(dantup): Consider making LocationLink the default for tests (with
// some specific tests for Location) because it's what VS Code uses and
// has more fields to verify.
setLocationLinkSupport(); // To verify the full set of ranges.
setDartTextDocumentContentProviderSupport();
newFile(
join(projectFolderPath, 'lib', 'with_foo.dart'), withFooMethodMacro);

final code = TestCode.parse('''
import 'with_foo.dart';
import 'macros.dart';
f() {
A().[!foo^!]();
}
@WithFoo()
@DeclareInType('void foo() {}')
class A {}
''');

Expand All @@ -509,8 +501,8 @@ class A {}
// those substrings are as expected.
var macroResponse = await getDartTextDocumentContent(location.targetUri);
var macroContent = macroResponse!.content!;
expect(getTextForRange(macroContent, location.targetRange),
'void foo() {bar();}');
expect(
getTextForRange(macroContent, location.targetRange), 'void foo() {}');
expect(getTextForRange(macroContent, location.targetSelectionRange), 'foo');
}

Expand Down
Loading

0 comments on commit 44af846

Please sign in to comment.