@@ -43,10 +43,11 @@ import 'package:analyzer/source/line_info.dart';
4343import 'package:analyzer/src/dart/analysis/driver.dart' as nd;
4444import 'package:analyzer/src/dart/analysis/status.dart' as nd;
4545import 'package:analyzer/src/generated/sdk.dart' ;
46+ import 'package:analyzer/src/util/file_paths.dart' as file_paths;
4647import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin;
4748import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
4849import 'package:analyzer_plugin/src/protocol/protocol_internal.dart' as plugin;
49- import 'package:path/path .dart' ;
50+ import 'package:http/http .dart' as http ;
5051import 'package:watcher/watcher.dart' ;
5152
5253/// Instances of the class [LspAnalysisServer] implement an LSP-based server
@@ -134,6 +135,7 @@ class LspAnalysisServer extends AbstractAnalysisServer {
134135 DartSdkManager sdkManager,
135136 CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder,
136137 InstrumentationService instrumentationService, {
138+ http.Client httpClient,
137139 DiagnosticServer diagnosticServer,
138140 }) : super (
139141 options,
@@ -142,6 +144,7 @@ class LspAnalysisServer extends AbstractAnalysisServer {
142144 crashReportingAttachmentsBuilder,
143145 baseResourceProvider,
144146 instrumentationService,
147+ httpClient,
145148 LspNotificationManager (channel, baseResourceProvider.pathContext),
146149 ) {
147150 notificationManager.server = this ;
@@ -185,8 +188,14 @@ class LspAnalysisServer extends AbstractAnalysisServer {
185188 RefactoringWorkspace get refactoringWorkspace => _refactoringWorkspace ?? =
186189 RefactoringWorkspace (driverMap.values, searchEngine);
187190
188- void addPriorityFile (String path) {
189- final didAdd = priorityFiles.add (path);
191+ void addPriorityFile (String filePath) {
192+ // When a pubspec is opened, trigger package name caching for completion.
193+ if (! pubPackageService.isRunning &&
194+ file_paths.isPubspecYaml (resourceProvider.pathContext, filePath)) {
195+ pubPackageService.beginPackageNamePreload ();
196+ }
197+
198+ final didAdd = priorityFiles.add (filePath);
190199 assert (didAdd);
191200 if (didAdd) {
192201 _updateDriversAndPluginsPriorityFiles ();
@@ -616,7 +625,10 @@ class LspAnalysisServer extends AbstractAnalysisServer {
616625 return MessageActionItem .fromJson (response.result);
617626 }
618627
628+ @override
619629 Future <void > shutdown () {
630+ super .shutdown ();
631+
620632 // Defer closing the channel so that the shutdown response can be sent and
621633 // logged.
622634 Future (() {
@@ -664,13 +676,15 @@ class LspAnalysisServer extends AbstractAnalysisServer {
664676 ..addAll (_temporaryAnalysisRoots.values);
665677
666678 final excludedPaths = clientConfiguration.analysisExcludedFolders
667- .expand ((excludePath) => isAbsolute (excludePath)
679+ .expand ((excludePath) => resourceProvider.pathContext
680+ .isAbsolute (excludePath)
668681 ? [excludePath]
669682 // Apply the relative path to each open workspace folder.
670683 // TODO(dantup): Consider supporting per-workspace config by
671684 // calling workspace/configuration whenever workspace folders change
672685 // and caching the config for each one.
673- : _explicitAnalysisRoots.map ((root) => join (root, excludePath)))
686+ : _explicitAnalysisRoots.map (
687+ (root) => resourceProvider.pathContext.join (root, excludePath)))
674688 .toSet ();
675689
676690 // If the roots didn't actually change from the last time they were set
0 commit comments