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: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ The following command will output a `index.scip` file
dart pub global run scip_dart ./path/to/project/root
```

> Note: by default, only `./lib` is indexed. This can be extended to include other paths using `--path/-p`
>
> ```bash
> dart pub global run scip_dart \
> -p ./lib \ # path relative to project root
> -p ./test \
> ./path/to/project/root
>```
>
> Indexing test directories will impact performance of the indexer


This file can be analyzed / displayed using the [scip cli](https://github.com/sourcegraph/scip)

```sh
Expand Down
3 changes: 2 additions & 1 deletion bin/scip_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'package:scip_dart/src/flags.dart';
Future<void> main(List<String> args) async {
final result = (ArgParser()
..addFlag('performance', aliases: ['perf'], defaultsTo: false)
..addFlag('verbose', abbr: 'v', defaultsTo: false))
..addFlag('verbose', abbr: 'v', defaultsTo: false)
..addMultiOption('path', abbr: 'p', defaultsTo: ['./lib']))
.parse(args);

Flags.instance.init(result);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ class Flags {
bool get performance => _performance;
bool _performance = false;

List<String> get paths => _paths;
List<String> _paths = [];

void init(ArgResults results) {
_verbose = results['verbose'] ?? false;
_performance = results['performance'] ?? false;
_paths = (results['path'] as Iterable<String>?)?.toList() ?? [];
}

static Flags get instance => _instance;
Expand Down
26 changes: 19 additions & 7 deletions lib/src/indexer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,30 @@ Future<Index> indexPackage(
.map((package) => p.normalize(package.packageUriRoot.toFilePath()))
.toList();

final collection = AnalysisContextCollection(includedPaths: allPackageRoots);
final indexedPaths = Flags.instance.paths.map(
(relPath) => p.normalize(p.join(dirPath, relPath)),
);

final collection = AnalysisContextCollection(
includedPaths: [
...allPackageRoots,
...indexedPaths,
],
);

if (Flags.instance.performance) print('Analyzing Source');
final st = Stopwatch()..start();

final context = collection.contextFor(p.join(dirPath, 'lib'));
final files = context.contextRoot
.analyzedFiles()
.where((file) => p.extension(file) == '.dart');
final resolvedUnitFutures = indexedPaths.map((path) {
final context = collection.contextFor(path);
final files = context.contextRoot
.analyzedFiles()
.where((file) => p.extension(file) == '.dart');

return files.map(context.currentSession.getResolvedUnit);
}).expand((resUnits) => resUnits);

final resolvedUnits =
await Future.wait(files.map(context.currentSession.getResolvedUnit));
final resolvedUnits = await Future.wait(resolvedUnitFutures);

if (Flags.instance.performance) {
print('Analyzing Source took: ${st.elapsedMilliseconds}ms');
Expand Down