-
Notifications
You must be signed in to change notification settings - Fork 2
FEA-2048: Ignore nested subpackages #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e3b7841
bf4ced6
8674b84
d5cf2a9
d84308d
3dbf476
3b4de43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include: package:workiva_analysis_options/v2.yaml | ||
|
||
analyzer: | ||
strong-mode: | ||
implicit-casts: false | ||
exclude: | ||
- snapshots/** |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:analyzer/dart/analysis/analysis_context_collection.dart'; | ||
import 'package:analyzer/dart/analysis/results.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
@@ -7,6 +9,7 @@ import 'package:scip_dart/src/flags.dart'; | |
|
||
import 'package:scip_dart/src/gen/scip.pb.dart'; | ||
import 'package:scip_dart/src/scip_visitor.dart'; | ||
import 'package:scip_dart/src/utils.dart'; | ||
|
||
Future<Index> indexPackage( | ||
String root, | ||
|
@@ -15,35 +18,55 @@ Future<Index> indexPackage( | |
) async { | ||
final dirPath = p.normalize(p.absolute(root)); | ||
|
||
final rootHasPubspecFile = await File( | ||
p.join(dirPath, 'pubspec.yaml'), | ||
).exists(); | ||
if (!rootHasPubspecFile) { | ||
stderr.writeln( | ||
'Provided path does not contain a pubspec.yaml file. ' | ||
'Unable to index', | ||
); | ||
exit(1); | ||
} | ||
|
||
final metadata = Metadata( | ||
projectRoot: 'file:/' + dirPath, | ||
textDocumentEncoding: TextEncoding.UTF8, | ||
toolInfo: ToolInfo( | ||
name: 'scip-dart', | ||
version: '0.0.1', | ||
arguments: [], | ||
)); | ||
projectRoot: 'file:/' + dirPath, | ||
textDocumentEncoding: TextEncoding.UTF8, | ||
toolInfo: ToolInfo( | ||
name: 'scip-dart', | ||
version: '0.0.1', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated but should this match the version of this library? Do we need to move this to a constant somewhere and configure the release event to bump it as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, ideally we do I didn't love the idea of relying on a release event (if for whatever reason scip-dart changed owners outside of workiva one day) and wanted the solution to be baked into the project I have an issue tracking this here and a spike pr for one of the solutions here: #45. Just haven't pushed on wrapping that up yet |
||
arguments: [], | ||
), | ||
); | ||
|
||
final allPackageRoots = packageConfig.packages | ||
.map((package) => p.normalize(package.packageUriRoot.toFilePath())) | ||
.toList(); | ||
|
||
final nestedPackages = (await pubspecPathsFor(root)) | ||
.map((path) => p.dirname(path)) | ||
.where((path) => path != root) | ||
.toList(); | ||
|
||
if (Flags.instance.verbose) print('Ignoring subdirectories: $nestedPackages'); | ||
|
||
final collection = AnalysisContextCollection( | ||
includedPaths: [ | ||
...allPackageRoots, | ||
dirPath, | ||
], | ||
); | ||
includedPaths: [ | ||
...allPackageRoots, | ||
dirPath, | ||
], | ||
// only index dart files of the current dart package, to index nested | ||
// packages, scip indexing can simply be re-run for that nested package | ||
excludedPaths: nestedPackages); | ||
|
||
if (Flags.instance.performance) print('Analyzing Source'); | ||
final st = Stopwatch()..start(); | ||
|
||
final context = collection.contextFor(dirPath); | ||
final resolvedUnitFutures = context.contextRoot | ||
.analyzedFiles() | ||
.where((file) => p.extension(file) == '.dart') | ||
.map(context.currentSession.getResolvedUnit); | ||
.analyzedFiles() | ||
.where((file) => p.extension(file) == '.dart') | ||
.map(context.currentSession.getResolvedUnit); | ||
|
||
final resolvedUnits = await Future.wait(resolvedUnitFutures); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w_module has a nested
pubspec.yaml
file in exampleAdd it as a consumer to verify this new functionality of not breaking on nested packages