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

on:
pull_request:

jobs:
format:
runs-on: workiva-runner-dev
steps:
- uses: actions/checkout@v3

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

- run: dart pub get
- uses: Workiva/gha-dart/dart-format@master

dependency-validator:
runs-on: workiva-runner-dev
steps:
- uses: actions/checkout@v3

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

- run: dart pub get

# TODO: convert to Workiva/gha-dart/dart-dependency-validator@master once
# https://github.com/Workiva/gha-dart/pull/4 merges
- run: dart run dependency_validator
shell: bash


2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM scratch
FROM drydock-prod.workiva.net/workiva/dart_build_image:3 as build
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ snap:
lint:
scip lint ./index.scip

gen-proto:
protoc --dart_out=. ./lib/src/gen/scip.proto

print:
scip print ./index.scip
11 changes: 6 additions & 5 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ 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);
..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 packageRoot =
result.rest.length > 0 ? result.rest.first : Directory.current.path;

final packageConfig = await findPackageConfig(Directory(packageRoot));
if (packageConfig == null) {
Expand All @@ -33,4 +34,4 @@ Future<void> main(List<String> args) async {
final index = await indexPackage(packageRoot, packageConfig, pubspec);

File('index.scip').writeAsBytesSync(index.writeToBuffer());
}
}
2 changes: 1 addition & 1 deletion lib/scip-dart.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'src/indexer.dart' show indexPackage;
export 'src/indexer.dart' show indexPackage;
2 changes: 1 addition & 1 deletion lib/src/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class Flags {
static Flags get instance => _instance;
static final Flags _instance = Flags._();
Flags._();
}
}
2 changes: 1 addition & 1 deletion lib/src/gen/scip.pb.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/gen/scip.pbenum.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/gen/scip.pbjson.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/gen/scip.pbserver.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 30 additions & 33 deletions lib/src/indexer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ Future<Index> indexPackage(
final dirPath = p.normalize(p.absolute(root));

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',
arguments: [],
));

final allPackageRoots = packageConfig.packages
.map((package) => p.normalize(package.packageUriRoot.toFilePath()))
Expand All @@ -36,40 +35,38 @@ Future<Index> indexPackage(

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

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

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

final documents = resolvedUnits
.whereType<ResolvedUnitResult>()
.map((resUnit) {

final relativePath = p.relative(resUnit.path, from: dirPath);
final documents =
resolvedUnits.whereType<ResolvedUnitResult>().map((resUnit) {
final relativePath = p.relative(resUnit.path, from: dirPath);

final visitor = ScipVisitor(
relativePath,
dirPath,
resUnit.lineInfo,
packageConfig,
pubspec,
);
resUnit.unit.accept(visitor);
final visitor = ScipVisitor(
relativePath,
dirPath,
resUnit.lineInfo,
packageConfig,
pubspec,
);
resUnit.unit.accept(visitor);

return Document(
language: Language.Dart.name,
relativePath: relativePath,
occurrences: visitor.occurrences,
symbols: visitor.symbols,
);
})
.toList();
return Document(
language: Language.Dart.name,
relativePath: relativePath,
occurrences: visitor.occurrences,
symbols: visitor.symbols,
);
}).toList();

if (Flags.instance.performance) {
print('Parsing Ast took: ${st.elapsedMilliseconds}ms');
Expand All @@ -80,4 +77,4 @@ Future<Index> indexPackage(
documents: documents,
externalSymbols: globalExternalSymbols,
);
}
}
12 changes: 5 additions & 7 deletions lib/src/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import 'package:analyzer/dart/element/element.dart';

/// Refers to any additional metadata attached to a `SymbolInformation`
/// struct on the protobuf spec.
///
/// Use [getSymbolMetadata] to retrieve [SymbolMetadata] for a provided
///
/// Use [getSymbolMetadata] to retrieve [SymbolMetadata] for a provided
/// [Element] type.
class SymbolMetadata {
List<String> documentation;

SymbolMetadata({
required this.documentation
});
SymbolMetadata({required this.documentation});
}

/// Returns a [SymbolMetadata] object for a provided [Element] type.
///
///
/// This information is used to embellish `SymbolInformation` struct's
/// within the protobuf schema for scip
SymbolMetadata getSymbolMetadata(Element element) {
Expand All @@ -29,7 +27,7 @@ SymbolMetadata getSymbolMetadata(Element element) {
);

return SymbolMetadata(
documentation:[
documentation: [
'```dart\n$displayString\n```',
if (docComment != null) docComment
],
Expand Down
18 changes: 9 additions & 9 deletions lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class ScipVisitor extends GeneralizingAstVisitor {
PackageConfig packageConfig,
Pubspec pubspec,
) : _symbolGenerator = SymbolGenerator(
packageConfig,
_projectRoot,
pubspec,
) {
packageConfig,
_projectRoot,
pubspec,
) {
final fileSymbol = _symbolGenerator.fileSymbolFor(_relativePath);
occurrences.add(Occurrence(
symbol: fileSymbol,
Expand All @@ -44,7 +44,6 @@ class ScipVisitor extends GeneralizingAstVisitor {

@override
void visitNode(AstNode node) {

if (node is Comment) {
// For now, don't parse anything within comments (this was broken for
// local references). Later update to support this
Expand All @@ -53,7 +52,7 @@ class ScipVisitor extends GeneralizingAstVisitor {

// [visitDeclaration] on the [GeneralizingAstVisitor] does not match parameters
// even though the parameter node extends [Declaration]. This is a workaround
// to correctly parse all [Declaration] ast nodes.
// to correctly parse all [Declaration] ast nodes.
if (node is Declaration) {
_visitDeclaration(node);
} else if (node is SimpleFormalParameter) {
Expand Down Expand Up @@ -105,7 +104,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
final element = node.staticElement;

// element is null if there's nothing really to do for this node. Example: `void`
// TODO: One weird issue found: named parameters of external symbols were element.source
// TODO: One weird issue found: named parameters of external symbols were element.source
// EX: `color(path, front: Styles.YELLOW);` where `color` comes from the chalk-dart package
if (element == null || element.source == null) return;

Expand All @@ -117,7 +116,8 @@ class ScipVisitor extends GeneralizingAstVisitor {
));

if (!element.source!.fullName.startsWith(_projectRoot)) {
if (globalExternalSymbols.every((symbolInfo) => symbolInfo.symbol != symbol)) {
if (globalExternalSymbols
.every((symbolInfo) => symbolInfo.symbol != symbol)) {
final meta = getSymbolMetadata(element);
globalExternalSymbols.add(SymbolInformation(
symbol: symbol,
Expand All @@ -135,4 +135,4 @@ class ScipVisitor extends GeneralizingAstVisitor {
documentation: meta.documentation,
));
}
}
}
Loading