[analysis_server] Don't suggest dev dependencies in app entry points

Fixes https://github.com/dart-lang/sdk/issues/54684

Change-Id: I51028464088a615f15144d28fa2687e38c250d94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349764
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Parker Lougheed 2024-02-08 19:36:27 +00:00 committed by Commit Queue
parent 5a70848899
commit 4fb4bdd24a
2 changed files with 107 additions and 10 deletions

View file

@ -734,6 +734,54 @@ suggestions
''');
}
Future<void> test_notImported_pub_dependencies_inBin() async {
writeTestPackagePubspecYamlFile(r'''
name: test
dependencies:
aaa: any
dev_dependencies:
bbb: any
''');
var aaaRoot = getFolder('$workspaceRootPath/packages/aaa');
newFile('${aaaRoot.path}/lib/f.dart', '''
class A01 {}
''');
var bbbRoot = getFolder('$workspaceRootPath/packages/bbb');
newFile('${bbbRoot.path}/lib/f.dart', '''
class A02 {}
''');
writeTestPackageConfig(
config: PackageConfigFileBuilder()
..add(name: 'aaa', rootPath: aaaRoot.path)
..add(name: 'bbb', rootPath: bbbRoot.path),
);
await _configureWithWorkspaceRoot();
var binPath = convertPath('$testPackageRootPath/bin/main.dart');
var response = await _getCodeSuggestions(
path: binPath,
content: '''
void f() {
A0^
}
''',
);
assertResponseText(response, r'''
replacement
left: 2
suggestions
A01
kind: class
isNotImported: true
libraryUri: package:aaa/f.dart
''');
}
Future<void> test_notImported_pub_dependencies_inLib() async {
writeTestPackagePubspecYamlFile(r'''
name: test
@ -842,6 +890,54 @@ suggestions
''');
}
Future<void> test_notImported_pub_dependencies_inWeb() async {
writeTestPackagePubspecYamlFile(r'''
name: test
dependencies:
aaa: any
dev_dependencies:
bbb: any
''');
var aaaRoot = getFolder('$workspaceRootPath/packages/aaa');
newFile('${aaaRoot.path}/lib/f.dart', '''
class A01 {}
''');
var bbbRoot = getFolder('$workspaceRootPath/packages/bbb');
newFile('${bbbRoot.path}/lib/f.dart', '''
class A02 {}
''');
writeTestPackageConfig(
config: PackageConfigFileBuilder()
..add(name: 'aaa', rootPath: aaaRoot.path)
..add(name: 'bbb', rootPath: bbbRoot.path),
);
await _configureWithWorkspaceRoot();
var webPath = convertPath('$testPackageRootPath/web/main.dart');
var response = await _getCodeSuggestions(
path: webPath,
content: '''
void f() {
A0^
}
''',
);
assertResponseText(response, r'''
replacement
left: 2
suggestions
A01
kind: class
isNotImported: true
libraryUri: package:aaa/f.dart
''');
}
Future<void> test_notImported_pub_this() async {
newFile('$testPackageLibPath/a.dart', '''
class A01 {}

View file

@ -60,20 +60,21 @@ class _PubFilter implements FileStateFilter {
final PubPackage targetPackage;
final String? targetPackageName;
final bool targetPackageIsAnalysisServer;
final bool targetInLib;
final bool targetInLibOrEntryPoint;
final Set<String> dependencies;
factory _PubFilter(PubPackage package, String path) {
var inLib = package.workspace.provider
.getFolder(package.root)
.getChildAssumingFolder('lib')
.contains(path);
var packageRootFolder = package.workspace.provider.getFolder(package.root);
var inLibOrEntryPoint =
packageRootFolder.getChildAssumingFolder('lib').contains(path) ||
packageRootFolder.getChildAssumingFolder('bin').contains(path) ||
packageRootFolder.getChildAssumingFolder('web').contains(path);
var dependencies = <String>{};
var pubspec = package.pubspec;
if (pubspec != null) {
dependencies.addAll(pubspec.dependencies.names);
if (!inLib) {
if (!inLibOrEntryPoint) {
dependencies.addAll(pubspec.devDependencies.names);
}
}
@ -84,7 +85,7 @@ class _PubFilter implements FileStateFilter {
targetPackage: package,
targetPackageName: packageName,
targetPackageIsAnalysisServer: packageName == 'analysis_server',
targetInLib: inLib,
targetInLibOrEntryPoint: inLibOrEntryPoint,
dependencies: dependencies,
);
}
@ -93,7 +94,7 @@ class _PubFilter implements FileStateFilter {
required this.targetPackage,
required this.targetPackageName,
required this.targetPackageIsAnalysisServer,
required this.targetInLib,
required this.targetInLibOrEntryPoint,
required this.dependencies,
});
@ -105,10 +106,10 @@ class _PubFilter implements FileStateFilter {
}
// Normally only package URIs are available.
// But outside of lib/ we allow any files of this package.
// But outside of lib/ and entry points we allow any files of this package.
var packageName = uri.packageName;
if (packageName == null) {
if (targetInLib) {
if (targetInLibOrEntryPoint) {
return false;
} else {
var filePackage = file.workspacePackage;