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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.DS_Store
index.scip
snapshots/input/staging-project/lib/**
snapshots/output/staging-project/lib/**
snapshots/output/staging-project/lib/**
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,11 @@ dart pub global activate scip_dart

The following command will output a `index.scip` file
```sh
dart pub global run scip_dart ./path/to/project/root
cd ./path/to/project/root
dart pub get
dart pub global run scip_dart ./
```

> 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
29 changes: 26 additions & 3 deletions bin/scip_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,36 @@ 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)
..addMultiOption('path', abbr: 'p', defaultsTo: ['./lib']))
..addFlag(
'performance',
aliases: ['perf'],
defaultsTo: false,
help: 'Whether or not to output performance metrics during indexing',
)
..addFlag(
'verbose',
abbr: 'v',
defaultsTo: false,
help: 'Whether or not to display debugging text during indexing',
)
..addMultiOption(
'path',
abbr: 'p',
help: 'DEPRECATED, has no effect on executed code',
))
.parse(args);


Flags.instance.init(result);

if ((result['path'] as List<String>?)?.isNotEmpty == true) {
print(
'The --path/-p flag is deprecated and no longer used. '
'All dart files in the provided directory are indexed by '
'default.',
);
}

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

Expand Down
4 changes: 0 additions & 4 deletions lib/src/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ 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
18 changes: 6 additions & 12 deletions lib/src/indexer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,22 @@ Future<Index> indexPackage(
.map((package) => p.normalize(package.packageUriRoot.toFilePath()))
.toList();

final indexedPaths = Flags.instance.paths.map(
(relPath) => p.normalize(p.join(dirPath, relPath)),
);

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

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

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 context = collection.contextFor(dirPath);
final resolvedUnitFutures = context.contextRoot
.analyzedFiles()
.where((file) => p.extension(file) == '.dart')
.map(context.currentSession.getResolvedUnit);

final resolvedUnits = await Future.wait(resolvedUnitFutures);

Expand Down
Loading