Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ on:
pull_request:

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: 2.18.7
- run: dart pub get
- run: dart run dart_dev analyze

format:
runs-on: ubuntu-latest
steps:
Expand All @@ -12,7 +22,7 @@ jobs:
with:
sdk: 2.18.7
- run: dart pub get
- run: dart run dart_dev format
- run: dart run dart_dev format --check

dependency-validator:
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ jobs:

strategy:
matrix:
repo: ["Workiva/over_react", "rrousselGit/provider", "dart-lang/args"]
repo: [
"Workiva/over_react",
"Workiva/w_module",
Copy link
Contributor Author

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 example

Add it as a consumer to verify this new functionality of not breaking on nested packages

"rrousselGit/provider",
"dart-lang/args",
]

steps:
# Setup scip-dart
Expand Down
7 changes: 7 additions & 0 deletions analysis_options.yaml
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/**
3 changes: 1 addition & 2 deletions bin/scip_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Future<void> main(List<String> args) async {
))
.parse(args);


Flags.instance.init(result);

if ((result['path'] as List<String>?)?.isNotEmpty == true) {
Expand All @@ -40,7 +39,7 @@ Future<void> main(List<String> args) async {
}

final packageRoot =
result.rest.length > 0 ? result.rest.first : Directory.current.path;
result.rest.isNotEmpty ? result.rest.first : Directory.current.path;

final packageConfig = await findPackageConfig(Directory(packageRoot));
if (packageConfig == null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Flags {
bool _performance = false;

void init(ArgResults results) {
_verbose = results['verbose'] ?? false;
_performance = results['performance'] ?? false;
_verbose = results['verbose'] as bool? ?? false;
_performance = results['performance'] as bool? ?? false;
}

static Flags get instance => _instance;
Expand Down
53 changes: 38 additions & 15 deletions lib/src/indexer.dart
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;
Expand All @@ -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,
Expand All @@ -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',

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);

Expand Down
1 change: 0 additions & 1 deletion lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ScipVisitor extends GeneralizingAstVisitor {
Pubspec pubspec,
) : _symbolGenerator = SymbolGenerator(
packageConfig,
_projectRoot,
pubspec,
) {
final fileSymbol = _symbolGenerator.fileSymbolFor(_relativePath);
Expand Down
2 changes: 0 additions & 2 deletions lib/src/symbol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:scip_dart/src/utils.dart';
/// Each sourcefile should use its own instance of `SymbolGenerator`
class SymbolGenerator {
final PackageConfig _packageConfig;
final String _projectRoot;
final Pubspec _pubspec;

int _localElementIndex = 0;
Expand All @@ -23,7 +22,6 @@ class SymbolGenerator {

SymbolGenerator(
this._packageConfig,
this._projectRoot,
this._pubspec,
);

Expand Down
12 changes: 12 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import 'dart:io';

import 'package:analyzer/source/line_info.dart';
import 'package:path/path.dart' as p;

import 'package:scip_dart/src/flags.dart';

/// Returns a list of all the pubspec.yaml paths under a directory.
/// Will recurse into child folders, will not follow links.
Future<List<String>> pubspecPathsFor(String rootDirectory) async {
return Directory(rootDirectory)
.list(recursive: true, followLinks: false)
.where((file) => p.basename(file.path) == 'pubspec.yaml')
.map((file) => file.path)
.toList();
}

enum DisplayLevel {
info,
warn,
Expand Down
Loading