diff --git a/.gitignore b/.gitignore index 79e5818c..15617b6a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ .DS_Store index.scip snapshots/input/staging-project/lib/** -snapshots/output/staging-project/lib/** +snapshots/output/staging-project/lib/** \ No newline at end of file diff --git a/README.md b/README.md index 903148e2..79302b47 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/scip_dart.dart b/bin/scip_dart.dart index 67a3cceb..e394dcb6 100644 --- a/bin/scip_dart.dart +++ b/bin/scip_dart.dart @@ -9,13 +9,36 @@ import 'package:scip_dart/src/flags.dart'; Future main(List 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?)?.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; diff --git a/lib/src/flags.dart b/lib/src/flags.dart index 509e01f1..15988584 100644 --- a/lib/src/flags.dart +++ b/lib/src/flags.dart @@ -7,13 +7,9 @@ class Flags { bool get performance => _performance; bool _performance = false; - List get paths => _paths; - List _paths = []; - void init(ArgResults results) { _verbose = results['verbose'] ?? false; _performance = results['performance'] ?? false; - _paths = (results['path'] as Iterable?)?.toList() ?? []; } static Flags get instance => _instance; diff --git a/lib/src/indexer.dart b/lib/src/indexer.dart index bcf98842..1030ab83 100644 --- a/lib/src/indexer.dart +++ b/lib/src/indexer.dart @@ -28,28 +28,22 @@ Future 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); diff --git a/snapshots/input/basic-project/pubspec.lock b/snapshots/input/basic-project/pubspec.lock index 89b205e1..81043360 100644 --- a/snapshots/input/basic-project/pubspec.lock +++ b/snapshots/input/basic-project/pubspec.lock @@ -1,5 +1,320 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile -packages: {} +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "54.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "5.6.0" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.1" + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.17.2" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.3" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.5" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.16" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.1" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + node_preamble: + dependency: transitive + description: + name: node_preamble + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.3" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.12" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test: + dependency: "direct main" + description: + name: test + url: "https://pub.dartlang.org" + source: hosted + version: "1.24.3" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.0" + test_core: + dependency: transitive + description: + name: test_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.3" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.2" + vm_service: + dependency: transitive + description: + name: vm_service + url: "https://pub.dartlang.org" + source: hosted + version: "11.2.0" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" sdks: dart: ">=2.18.0 <3.0.0" diff --git a/snapshots/input/basic-project/pubspec.yaml b/snapshots/input/basic-project/pubspec.yaml index 01372323..5b2fdcb4 100644 --- a/snapshots/input/basic-project/pubspec.yaml +++ b/snapshots/input/basic-project/pubspec.yaml @@ -3,3 +3,6 @@ version: 1.0.0 environment: sdk: ">=2.18.0 <3.0.0" + +dependencies: + test: ^1.24.3 \ No newline at end of file diff --git a/snapshots/input/basic-project/test/basic_test.dart b/snapshots/input/basic-project/test/basic_test.dart new file mode 100644 index 00000000..35ddd9ba --- /dev/null +++ b/snapshots/input/basic-project/test/basic_test.dart @@ -0,0 +1,9 @@ +import 'package:test/test.dart'; + +void main() { + group('some test', () { + test('equality', () { + expect(1, 1); + }); + }); +} \ No newline at end of file diff --git a/snapshots/output/basic-project/test/basic_test.dart b/snapshots/output/basic-project/test/basic_test.dart new file mode 100755 index 00000000..a7506aae --- /dev/null +++ b/snapshots/output/basic-project/test/basic_test.dart @@ -0,0 +1,15 @@ + import 'package:test/test.dart'; +// definition scip-dart pub dart_test 1.0.0 test/basic_test.dart/ + + void main() { +// ^^^^ definition scip-dart pub dart_test 1.0.0 test/basic_test.dart/main(). +// documentation ```dart + group('some test', () { +// ^^^^^ reference scip-dart pub test_core 0.5.3 lib/scaffolding.dart/group(). + test('equality', () { +// ^^^^ reference scip-dart pub test_core 0.5.3 lib/scaffolding.dart/test(). + expect(1, 1); +// ^^^^^^ reference scip-dart pub matcher 0.12.16 lib/src/expect/expect.dart/expect(). + }); + }); + }