[analysis_server] Replace URI fields in tests with getters to avoid having to set all paths twice
This is a minor refactoring to swap some fields for URIs to getters so that any tests that modify them don't have to set both a path and URI (or risk them being out-of-sync).
Change-Id: Ic3776d250f4cfd9b0f16a7fc578ab5e7f19e52a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384762
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/benchmark/perf/memory_tests.dart b/pkg/analysis_server/benchmark/perf/memory_tests.dart
index ecfbb91..4fb1ae9 100644
--- a/pkg/analysis_server/benchmark/perf/memory_tests.dart
+++ b/pkg/analysis_server/benchmark/perf/memory_tests.dart
@@ -183,7 +183,6 @@
_test.instrumentationService = InstrumentationLogAdapter(_logger);
await _test.setUp();
_test.projectFolderPath = roots.single;
- _test.projectFolderUri = Uri.file(_test.projectFolderPath);
await _test.initialize();
}
diff --git a/pkg/analysis_server/test/integration/lsp_server/integration_tests.dart b/pkg/analysis_server/test/integration/lsp_server/integration_tests.dart
index 8d4ace2..0dc4d68 100644
--- a/pkg/analysis_server/test/integration/lsp_server/integration_tests.dart
+++ b/pkg/analysis_server/test/integration/lsp_server/integration_tests.dart
@@ -125,11 +125,8 @@
.resolveSymbolicLinksSync();
newFolder(projectFolderPath);
newFolder(join(projectFolderPath, 'lib'));
- projectFolderUri = Uri.file(projectFolderPath);
mainFilePath = join(projectFolderPath, 'lib', 'main.dart');
- mainFileUri = Uri.file(mainFilePath);
analysisOptionsPath = join(projectFolderPath, 'analysis_options.yaml');
- analysisOptionsUri = Uri.file(analysisOptionsPath);
var client = LspServerClient(instrumentationService);
this.client = client;
diff --git a/pkg/analysis_server/test/lsp/completion_dart_test.dart b/pkg/analysis_server/test/lsp/completion_dart_test.dart
index 6a597ef..fe0452f 100644
--- a/pkg/analysis_server/test/lsp/completion_dart_test.dart
+++ b/pkg/analysis_server/test/lsp/completion_dart_test.dart
@@ -4472,7 +4472,6 @@
Future<void> test_snippets_testBlock() async {
mainFilePath = join(projectFolderPath, 'test', 'foo_test.dart');
- mainFileUri = pathContext.toUri(mainFilePath);
var content = '''
void f() {
test^
@@ -4497,7 +4496,6 @@
Future<void> test_snippets_testGroupBlock() async {
mainFilePath = join(projectFolderPath, 'test', 'foo_test.dart');
- mainFileUri = pathContext.toUri(mainFilePath);
var content = '''
void f() {
group^
diff --git a/pkg/analysis_server/test/lsp/server_abstract.dart b/pkg/analysis_server/test/lsp/server_abstract.dart
index 195284a..9570f46 100644
--- a/pkg/analysis_server/test/lsp/server_abstract.dart
+++ b/pkg/analysis_server/test/lsp/server_abstract.dart
@@ -293,18 +293,14 @@
server.pluginManager = pluginManager;
projectFolderPath = convertPath('/home/my_project');
- projectFolderUri = toUri(projectFolderPath);
newFolder(projectFolderPath);
newFolder(join(projectFolderPath, 'lib'));
// Create a folder and file to aid testing that includes imports/completion.
newFolder(join(projectFolderPath, 'lib', 'folder'));
newFile(join(projectFolderPath, 'lib', 'file.dart'), '');
mainFilePath = join(projectFolderPath, 'lib', 'main.dart');
- mainFileUri = toUri(mainFilePath);
nonExistentFilePath = join(projectFolderPath, 'lib', 'not_existing.dart');
- nonExistentFileUri = toUri(nonExistentFilePath);
pubspecFilePath = join(projectFolderPath, file_paths.pubspecYaml);
- pubspecFileUri = toUri(pubspecFilePath);
analysisOptionsPath = join(projectFolderPath, 'analysis_options.yaml');
newFile(analysisOptionsPath, '''
analyzer:
@@ -313,7 +309,6 @@
- wildcard-variables
''');
- analysisOptionsUri = pathContext.toUri(analysisOptionsPath);
writeTestPackageConfig();
}
@@ -804,11 +799,7 @@
nonExistentFilePath,
pubspecFilePath,
analysisOptionsPath;
- late Uri projectFolderUri,
- mainFileUri,
- nonExistentFileUri,
- pubspecFileUri,
- analysisOptionsUri;
+
final String simplePubspecContent = 'name: my_project';
/// The client capabilities sent to the server during initialization.
@@ -845,6 +836,9 @@
/// server.
bool failTestOnErrorDiagnostic = true;
+ /// [analysisOptionsPath] as a 'file:///' [Uri].
+ Uri get analysisOptionsUri => pathContext.toUri(analysisOptionsPath);
+
/// A stream of [NotificationMessage]s from the server that may be errors.
Stream<NotificationMessage> get errorNotificationsFromServer {
return notificationsFromServer.where(_isErrorNotification);
@@ -867,6 +861,12 @@
/// The URI for the macro-generated contents for [mainFileUri].
Uri get mainFileMacroUri => mainFileUri.replace(scheme: macroClientUriScheme);
+ /// [mainFilePath] as a 'file:///' [Uri].
+ Uri get mainFileUri => pathContext.toUri(mainFilePath);
+
+ /// [nonExistentFilePath] as a 'file:///' [Uri].
+ Uri get nonExistentFileUri => pathContext.toUri(nonExistentFilePath);
+
/// A stream of [NotificationMessage]s from the server.
@override
Stream<NotificationMessage> get notificationsFromServer {
@@ -883,6 +883,9 @@
path.Context get pathContext;
+ /// [projectFolderPath] as a 'file:///' [Uri].
+ Uri get projectFolderUri => pathContext.toUri(projectFolderPath);
+
/// A stream of diagnostic notifications from the server.
Stream<PublishDiagnosticsParams> get publishedDiagnostics {
return notificationsFromServer
@@ -892,6 +895,9 @@
notification.params as Map<String, Object?>));
}
+ /// [pubspecFilePath] as a 'file:///' [Uri].
+ Uri get pubspecFileUri => pathContext.toUri(pubspecFilePath);
+
/// A stream of [RequestMessage]s from the server.
Stream<RequestMessage> get requestsFromServer {
return serverToClient
diff --git a/pkg/analysis_server/test/src/services/refactoring/move_top_level_to_file_test.dart b/pkg/analysis_server/test/src/services/refactoring/move_top_level_to_file_test.dart
index 3c1f1ea..bda1e6c 100644
--- a/pkg/analysis_server/test/src/services/refactoring/move_top_level_to_file_test.dart
+++ b/pkg/analysis_server/test/src/services/refactoring/move_top_level_to_file_test.dart
@@ -316,9 +316,6 @@
// Put the file in tool/ so we can use a package: import for the file
// above but get a relative import back to src.
mainFilePath = join(projectFolderPath, 'tool', 'main.dart');
- // TODO(dantup): Make these URIs getters to avoid setting these twice in
- // each test.
- mainFileUri = pathContext.toUri(mainFilePath);
newFile(libFilePath, 'mixin PackageMixin {};');
var originalSource = '''