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
95 changes: 57 additions & 38 deletions lib/src/pubspec_indexer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,22 @@ Document indexPubspec({
}) {
final pubspecLineInfo = LineInfo.fromContent(pubspecStr);

final fileSymbol = [
'scip-dart',
'pub',
pubspec.name,
pubspec.version!,
'`pubspec.yaml`/',
].join(' ');
final symbols = <SymbolInformation>[];
final occurrences = <Occurrence>[];

final symbols = <SymbolInformation>[
SymbolInformation(
symbol: fileSymbol,
kind: SymbolInformation_Kind
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency
signatureDocumentation: Document(
language: Language.YAML.name,
text: ['name: ${pubspec.name}', 'version: ${pubspec.version}']
.join('\n')))
];
final occurrences = <Occurrence>[
Occurrence(
symbol: fileSymbol,
// a 'none' publishTo implies that the pubspec.yaml file (and project) are not
// actually published to a pub server, and only used for testing. We still want
// to index the dependencies in this case, but avoid creating the file symbol
// to reduce duplicate packages names
if (pubspec.publishTo != 'none') {
final info = _buildFileSymbol(pubspec);
symbols.add(info);
occurrences.add(Occurrence(
symbol: info.symbol,
symbolRoles: SymbolRole.Definition.value,
range: [0, 0, 0],
)
];
));
}

final deps = {
DependencyKind.regular: pubspec.dependencies,
Expand All @@ -73,30 +65,57 @@ Document indexPubspec({
);
}

SymbolInformation _buildFileSymbol(Pubspec pubspec) {
final symbol = [
'scip-dart',
'pub',
pubspec.name,
pubspec.version ?? '*',
'`pubspec.yaml`/',
].join(' ');

return SymbolInformation(
symbol: symbol,
kind: SymbolInformation_Kind
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency
signatureDocumentation: Document(
language: Language.YAML.name,
text: [
'name: ${pubspec.name}',
'version: ${pubspec.version}',
].join('\n'),
),
);
}

SymbolInformation _buildSymbol(String depName, PubspecLock lock) {
final depVersion = lock.packages[depName]?.version.toString();
if (depVersion == null) {
throw Exception(
'Unable to find ${depName} in pubspec.lock. Have you ran pub get?');
}

final symbol = [
'scip-dart',
'pub',
depName,
depVersion,
'`pubspec.yaml`/',
].join(' ');

return SymbolInformation(
displayName: depName,
symbol: [
'scip-dart',
'pub',
depName,
depVersion,
'`pubspec.yaml`/',
].join(' '),
kind: SymbolInformation_Kind
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency and SymbolInformation_Kind.DevDependency
signatureDocumentation: Document(
language: Language.YAML.name,
text: [
'name: $depName',
'version: $depVersion',
].join('\n')));
displayName: depName,
symbol: symbol,
kind: SymbolInformation_Kind
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency and SymbolInformation_Kind.DevDependency
signatureDocumentation: Document(
language: Language.YAML.name,
text: [
'name: $depName',
'version: $depVersion',
].join('\n'),
),
);
}

enum DependencyKind {
Expand Down
2 changes: 1 addition & 1 deletion snapshots/output/basic-project/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart_test
// reference scip-dart pub dart_test 1.0.0 `pubspec.yaml`/
// definition scip-dart pub dart_test 1.0.0 `pubspec.yaml`/
version: 1.0.0

environment:
Expand Down
2 changes: 1 addition & 1 deletion snapshots/output/diagnostics/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart_test_diagnostics
// reference scip-dart pub dart_test_diagnostics 1.0.0 `pubspec.yaml`/
// definition scip-dart pub dart_test_diagnostics 1.0.0 `pubspec.yaml`/
version: 1.0.0

environment:
Expand Down