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
78 changes: 78 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Tests

on:
push:
branches:
- master
pull_request:


jobs:
snapshots:
runs-on: workiva-runner-dev
name: Snapshots

steps:
- uses: actions/checkout@v3
- name: Install scip cli
run: |
bash -c 'curl -L "https://github.com/sourcegraph/scip/releases/download/v0.2.3/scip-linux-amd64.tar.gz"' | tar xzf - scip
./scip --version

- uses: dart-lang/setup-dart@v1
with:
sdk: 2.18.7

# run `pub get` for the scip-dart package
- name: Pub get cli
uses: Workiva/gha-dart/pub-get@master

# run `pub get` for `snapshots`
- name: Pub get snapshots dir
uses: Workiva/gha-dart/pub-get@master
with:
package-path: ./snapshots/input/basic-project

- name: Snapshots Diff Check
run: |
dart ./bin/main.dart ./snapshots/input/basic-project
./scip snapshot --to ./snapshots/output/basic-project

if [[ -z "$(git status --porcelain ./snapshots/output)" ]];
then
echo "No changes to snapshot files"
else
echo
echo "Snapshot diff detected differences, run 'make run snap' to re-generate snapshots"
git status --short ./snapshots/output
echo
exit 1
fi

consumer:
runs-on: workiva-runner-dev
name: Consumer

strategy:
matrix:
repo: ["Workiva/wdesk_sdk", "Workiva/syncdeps_dart"]

steps:
# Setup scip-dart
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: 2.18.7
- uses: Workiva/gha-dart/pub-get@master

# Setup wdesk_sdk
- uses: actions/checkout@v3
with:
repo: ${{ matrix.repo }}
path: ${{ matrix.repo }}
- uses: Workiva/gha-dart/pub-get@master
with:
package-path: ${{ matrix.repo }}

- run: |
dart ./bin/main.dart ./${{ matrix.repo }} || exit 1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dart_tool
.DS_Store
index.scip
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM scratch
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
run:
dart bin/main.dart ./snapshots/input/basic-project --verbose

snap:
scip snapshot --to ./snapshots/output/basic-project

lint:
scip lint ./index.scip

print:
scip print ./index.scip
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# scip-dart
# scip-dart

Experimental spike on a [scip](https://github.com/sourcegraph/scip) indexer for [dart](https://github.com/dart-lang)

Designed to be a replacement for [lsif_indexer](https://github.com/Workiva/lsif_indexer), with better coverage and reliability

## Usage

The following command will output a `index.scip` file
```sh
dart scip-dart/bin/main.dart ./path/to/project/root
```

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

```sh
scip print ./index.scip
scip snapshot
```

Analysis can be uploaded to sourcegraph using the [src cli](https://docs.sourcegraph.com/cli)

```sh
src code-intl upload -file=index.scip -github-token="<your gh token>"
```

## Design Philosophy

Scip is a fairly simple file format. Much of it boils down to finding every declaration in a source file, and creating a unique, but consistent string for it. This is called a `symbol`. Then the idea is to search the source code for every reference, and generate that same `symbol` we created before, for the references declaration. After this is done, we should have a large mapping of every reference, and declaration which allows external tools to preform code navigation on the entities within the codebase.

While this is simple in concept, in practice, parsing ast, and generating these symbols is edge case hell. Instead of expecting full coverage on everything, in its spike state, `scip-dart` will fail silently on unknown cases (this silent failing can be turned off with the `--verbose/-v` flag). The reason for this is that an incomplete scip index is still helpful, but a completely failed indexing is not.

Failures in running `scip-dart` will be treated with higher priority than full coverage of symbols.
6 changes: 6 additions & 0 deletions aviary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 1

exclude:
# generated protobuf files have encoded base64 files that
# aviary thinks are secrets. They are not, so tell aviary to ignore these files
- ^lib/src/gen
36 changes: 36 additions & 0 deletions bin/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:scip_dart/scip-dart.dart';
import 'package:package_config/package_config.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:path/path.dart' as p;
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)
).parse(args);

Flags.instance.init(result);

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

final packageConfig = await findPackageConfig(Directory(packageRoot));
if (packageConfig == null) {
stderr.writeln('ERROR: Unable to locate packageConfig');
exit(1);
}

final pubspecFile = File(p.join(packageRoot, 'pubspec.yaml'));
if (!pubspecFile.existsSync()) {
stderr.writeln('ERROR: Unable to locate pubspec.yaml');
exit(1);
}
final pubspec = Pubspec.parse(pubspecFile.readAsStringSync());

final index = await indexPackage(packageRoot, packageConfig, pubspec);

File('index.scip').writeAsBytesSync(index.writeToBuffer());
}
1 change: 1 addition & 0 deletions lib/scip-dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/indexer.dart' show indexPackage;
18 changes: 18 additions & 0 deletions lib/src/flags.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:args/args.dart';

class Flags {
bool get verbose => _verbose;
bool _verbose = false;

bool get performance => _performance;
bool _performance = false;

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

static Flags get instance => _instance;
static final Flags _instance = Flags._();
Flags._();
}
Loading