Skip to content

Commit c550de7

Browse files
srawlinsCommit Queue
authored andcommitted
analysis server: simplify LegacyAnalysisServer
This class had a few methods which only pertain to the resource provider and can just be extensions on ResourceProvider. They also have the exact same impl! So one can redirect to the other. Change-Id: I3a0433304adba1b71f69d0a4afc8a44515a23d10 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405600 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent e2477ad commit c550de7

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

pkg/analysis_server/lib/src/handler/legacy/analysis_set_analysis_roots.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:async';
77
import 'package:analysis_server/protocol/protocol.dart';
88
import 'package:analysis_server/protocol/protocol_generated.dart';
99
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
10+
import 'package:analysis_server/src/utilities/extensions/resource_provider.dart';
1011

1112
/// The handler for the `analysis.setAnalysisRoots` request.
1213
class AnalysisSetAnalysisRootsHandler extends LegacyHandler {
@@ -32,13 +33,13 @@ class AnalysisSetAnalysisRootsHandler extends LegacyHandler {
3233

3334
// validate
3435
for (var path in includedPathList) {
35-
if (!server.isValidFilePath(path)) {
36+
if (!server.resourceProvider.isValidFilePath(path)) {
3637
sendResponse(Response.invalidFilePathFormat(request, path));
3738
return;
3839
}
3940
}
4041
for (var path in excludedPathList) {
41-
if (!server.isValidFilePath(path)) {
42+
if (!server.resourceProvider.isValidFilePath(path)) {
4243
sendResponse(Response.invalidFilePathFormat(request, path));
4344
return;
4445
}

pkg/analysis_server/lib/src/handler/legacy/analysis_set_priority_files.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart';
99
import 'package:analysis_server/src/analysis_server.dart';
1010
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
1111
import 'package:analysis_server/src/plugin/request_converter.dart';
12+
import 'package:analysis_server/src/utilities/extensions/resource_provider.dart';
1213

1314
/// The handler for the `analysis.setPriorityFiles` request.
1415
class AnalysisSetPriorityFilesHandler extends LegacyHandler {
@@ -31,7 +32,7 @@ class AnalysisSetPriorityFilesHandler extends LegacyHandler {
3132
server.analyticsManager.startedSetPriorityFiles(params);
3233

3334
for (var file in params.files) {
34-
if (!server.isAbsoluteAndNormalized(file)) {
35+
if (!server.resourceProvider.isAbsoluteAndNormalized(file)) {
3536
sendResponse(Response.invalidFilePathFormat(request, file));
3637
return;
3738
}

pkg/analysis_server/lib/src/handler/legacy/analysis_set_subscriptions.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analysis_server/src/analysis_server.dart';
1010
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
1111
import 'package:analysis_server/src/plugin/request_converter.dart';
1212
import 'package:analysis_server/src/protocol/protocol_internal.dart';
13+
import 'package:analysis_server/src/utilities/extensions/resource_provider.dart';
1314

1415
/// The handler for the `analysis.setSubscriptions` request.
1516
class AnalysisSetSubscriptionsHandler extends LegacyHandler {
@@ -31,7 +32,7 @@ class AnalysisSetSubscriptionsHandler extends LegacyHandler {
3132

3233
for (var fileList in params.subscriptions.values) {
3334
for (var file in fileList) {
34-
if (!server.isAbsoluteAndNormalized(file)) {
35+
if (!server.resourceProvider.isAbsoluteAndNormalized(file)) {
3536
sendResponse(Response.invalidFilePathFormat(request, file));
3637
}
3738
}

pkg/analysis_server/lib/src/handler/legacy/analysis_update_content.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analysis_server/protocol/protocol.dart';
88
import 'package:analysis_server/protocol/protocol_generated.dart';
99
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
1010
import 'package:analysis_server/src/plugin/request_converter.dart';
11+
import 'package:analysis_server/src/utilities/extensions/resource_provider.dart';
1112

1213
/// The handler for the `analysis.updateContent` request.
1314
class AnalysisUpdateContentHandler extends LegacyHandler {
@@ -28,7 +29,7 @@ class AnalysisUpdateContentHandler extends LegacyHandler {
2829
);
2930

3031
for (var file in params.files.keys) {
31-
if (!server.isAbsoluteAndNormalized(file)) {
32+
if (!server.resourceProvider.isAbsoluteAndNormalized(file)) {
3233
sendResponse(Response.invalidFilePathFormat(request, file));
3334
return;
3435
}

pkg/analysis_server/lib/src/legacy_analysis_server.dart

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import 'package:analysis_server/src/services/completion/completion_state.dart';
9494
import 'package:analysis_server/src/services/execution/execution_context.dart';
9595
import 'package:analysis_server/src/services/flutter/widget_descriptions.dart';
9696
import 'package:analysis_server/src/services/refactoring/legacy/refactoring_manager.dart';
97+
import 'package:analysis_server/src/utilities/extensions/resource_provider.dart';
9798
import 'package:analysis_server/src/utilities/process.dart';
9899
import 'package:analyzer/dart/analysis/results.dart';
99100
import 'package:analyzer/dart/analysis/session.dart';
@@ -468,7 +469,7 @@ class LegacyAnalysisServer extends AnalysisServer {
468469

469470
/// The [Future] that completes when analysis is complete.
470471
Future<void> get onAnalysisComplete {
471-
if (isAnalysisComplete()) {
472+
if (_isAnalysisComplete) {
472473
return Future.value();
473474
}
474475
var completer = _onAnalysisCompleteCompleter ??= Completer<void>();
@@ -525,6 +526,8 @@ class LegacyAnalysisServer extends AnalysisServer {
525526
bool get supportsShowMessageRequest =>
526527
clientCapabilities.requests.contains('showMessageRequest');
527528

529+
bool get _isAnalysisComplete => !analysisDriverScheduler.isWorking;
530+
528531
void cancelRequest(String id) {
529532
cancellationTokens[id]?.cancel();
530533
}
@@ -679,25 +682,6 @@ class LegacyAnalysisServer extends AnalysisServer {
679682
sendLspNotifications = true;
680683
}
681684

682-
/// Return `true` if the [path] is both absolute and normalized.
683-
bool isAbsoluteAndNormalized(String path) {
684-
var pathContext = resourceProvider.pathContext;
685-
return pathContext.isAbsolute(path) && pathContext.normalize(path) == path;
686-
}
687-
688-
/// Return `true` if analysis is complete.
689-
bool isAnalysisComplete() {
690-
return !analysisDriverScheduler.isWorking;
691-
}
692-
693-
/// Return `true` if the given path is a valid `FilePath`.
694-
///
695-
/// This means that it is absolute and normalized.
696-
bool isValidFilePath(String path) {
697-
return resourceProvider.pathContext.isAbsolute(path) &&
698-
resourceProvider.pathContext.normalize(path) == path;
699-
}
700-
701685
@override
702686
void notifyFlutterWidgetDescriptions(String path) {
703687
flutterWidgetDescriptions.flush();
@@ -786,7 +770,7 @@ class LegacyAnalysisServer extends AnalysisServer {
786770
/// If the [path] is not a valid file path, that is absolute and normalized,
787771
/// send an error response, and return `true`. If OK then return `false`.
788772
bool sendResponseErrorIfInvalidFilePath(Request request, String path) {
789-
if (!isAbsoluteAndNormalized(path)) {
773+
if (!resourceProvider.isAbsoluteAndNormalized(path)) {
790774
sendResponse(Response.invalidFilePathFormat(request, path));
791775
return true;
792776
}
@@ -926,16 +910,18 @@ class LegacyAnalysisServer extends AnalysisServer {
926910
List<GeneralAnalysisService> subscriptions,
927911
) {
928912
var newServices = subscriptions.toSet();
929-
if (newServices.contains(GeneralAnalysisService.ANALYZED_FILES) &&
930-
!generalAnalysisServices.contains(
931-
GeneralAnalysisService.ANALYZED_FILES,
932-
) &&
933-
isAnalysisComplete()) {
913+
var newServicesContainsAnalyzedFiles = newServices.contains(
914+
GeneralAnalysisService.ANALYZED_FILES,
915+
);
916+
var generalServicesContainsAnalyzedFiles = generalAnalysisServices.contains(
917+
GeneralAnalysisService.ANALYZED_FILES,
918+
);
919+
if (newServicesContainsAnalyzedFiles &&
920+
!generalServicesContainsAnalyzedFiles &&
921+
_isAnalysisComplete) {
934922
sendAnalysisNotificationAnalyzedFiles(this);
935-
} else if (!newServices.contains(GeneralAnalysisService.ANALYZED_FILES) &&
936-
generalAnalysisServices.contains(
937-
GeneralAnalysisService.ANALYZED_FILES,
938-
)) {
923+
} else if (!newServicesContainsAnalyzedFiles &&
924+
generalServicesContainsAnalyzedFiles) {
939925
prevAnalyzedFiles = null;
940926
}
941927
generalAnalysisServices = newServices;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/file_system/file_system.dart';
6+
7+
extension ResourceProviderExtension on ResourceProvider {
8+
/// Whether [path] is both absolute and normalized.
9+
bool isAbsoluteAndNormalized(String path) =>
10+
pathContext.isAbsolute(path) && pathContext.normalize(path) == path;
11+
12+
/// Whether [path] is a valid `FilePath`.
13+
///
14+
/// This means that it is absolute and normalized.
15+
bool isValidFilePath(String path) => isAbsoluteAndNormalized(path);
16+
}

0 commit comments

Comments
 (0)