Skip to content

Commit 27d3084

Browse files
Merge pull request #175 from Workiva/gracefully_handle_missing_pubspec_version
FEDX-2979: Pubspec Indexing followups
2 parents d7e9ca4 + df94043 commit 27d3084

File tree

3 files changed

+59
-40
lines changed

3 files changed

+59
-40
lines changed

lib/src/pubspec_indexer.dart

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,22 @@ Document indexPubspec({
2424
}) {
2525
final pubspecLineInfo = LineInfo.fromContent(pubspecStr);
2626

27-
final fileSymbol = [
28-
'scip-dart',
29-
'pub',
30-
pubspec.name,
31-
pubspec.version!,
32-
'`pubspec.yaml`/',
33-
].join(' ');
27+
final symbols = <SymbolInformation>[];
28+
final occurrences = <Occurrence>[];
3429

35-
final symbols = <SymbolInformation>[
36-
SymbolInformation(
37-
symbol: fileSymbol,
38-
kind: SymbolInformation_Kind
39-
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency
40-
signatureDocumentation: Document(
41-
language: Language.YAML.name,
42-
text: ['name: ${pubspec.name}', 'version: ${pubspec.version}']
43-
.join('\n')))
44-
];
45-
final occurrences = <Occurrence>[
46-
Occurrence(
47-
symbol: fileSymbol,
30+
// a 'none' publishTo implies that the pubspec.yaml file (and project) are not
31+
// actually published to a pub server, and only used for testing. We still want
32+
// to index the dependencies in this case, but avoid creating the file symbol
33+
// to reduce duplicate packages names
34+
if (pubspec.publishTo != 'none') {
35+
final info = _buildFileSymbol(pubspec);
36+
symbols.add(info);
37+
occurrences.add(Occurrence(
38+
symbol: info.symbol,
39+
symbolRoles: SymbolRole.Definition.value,
4840
range: [0, 0, 0],
49-
)
50-
];
41+
));
42+
}
5143

5244
final deps = {
5345
DependencyKind.regular: pubspec.dependencies,
@@ -73,30 +65,57 @@ Document indexPubspec({
7365
);
7466
}
7567

68+
SymbolInformation _buildFileSymbol(Pubspec pubspec) {
69+
final symbol = [
70+
'scip-dart',
71+
'pub',
72+
pubspec.name,
73+
pubspec.version ?? '*',
74+
'`pubspec.yaml`/',
75+
].join(' ');
76+
77+
return SymbolInformation(
78+
symbol: symbol,
79+
kind: SymbolInformation_Kind
80+
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency
81+
signatureDocumentation: Document(
82+
language: Language.YAML.name,
83+
text: [
84+
'name: ${pubspec.name}',
85+
'version: ${pubspec.version}',
86+
].join('\n'),
87+
),
88+
);
89+
}
90+
7691
SymbolInformation _buildSymbol(String depName, PubspecLock lock) {
7792
final depVersion = lock.packages[depName]?.version.toString();
7893
if (depVersion == null) {
7994
throw Exception(
8095
'Unable to find ${depName} in pubspec.lock. Have you ran pub get?');
8196
}
8297

98+
final symbol = [
99+
'scip-dart',
100+
'pub',
101+
depName,
102+
depVersion,
103+
'`pubspec.yaml`/',
104+
].join(' ');
105+
83106
return SymbolInformation(
84-
displayName: depName,
85-
symbol: [
86-
'scip-dart',
87-
'pub',
88-
depName,
89-
depVersion,
90-
'`pubspec.yaml`/',
91-
].join(' '),
92-
kind: SymbolInformation_Kind
93-
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency and SymbolInformation_Kind.DevDependency
94-
signatureDocumentation: Document(
95-
language: Language.YAML.name,
96-
text: [
97-
'name: $depName',
98-
'version: $depVersion',
99-
].join('\n')));
107+
displayName: depName,
108+
symbol: symbol,
109+
kind: SymbolInformation_Kind
110+
.UnspecifiedKind, // TODO: Add SymbolInformation_Kind.Dependency and SymbolInformation_Kind.DevDependency
111+
signatureDocumentation: Document(
112+
language: Language.YAML.name,
113+
text: [
114+
'name: $depName',
115+
'version: $depVersion',
116+
].join('\n'),
117+
),
118+
);
100119
}
101120

102121
enum DependencyKind {

snapshots/output/basic-project/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dart_test
2-
// reference scip-dart pub dart_test 1.0.0 `pubspec.yaml`/
2+
// definition scip-dart pub dart_test 1.0.0 `pubspec.yaml`/
33
version: 1.0.0
44

55
environment:

snapshots/output/diagnostics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dart_test_diagnostics
2-
// reference scip-dart pub dart_test_diagnostics 1.0.0 `pubspec.yaml`/
2+
// definition scip-dart pub dart_test_diagnostics 1.0.0 `pubspec.yaml`/
33
version: 1.0.0
44

55
environment:

0 commit comments

Comments
 (0)