From a4abdc36a1da6c6aa90128bb2d1fec8da7868343 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 16 Apr 2025 10:57:38 -0600 Subject: [PATCH 1/5] gracefully handle missing pubspec version --- lib/src/pubspec_indexer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/pubspec_indexer.dart b/lib/src/pubspec_indexer.dart index 493a0f3..7279de9 100644 --- a/lib/src/pubspec_indexer.dart +++ b/lib/src/pubspec_indexer.dart @@ -28,7 +28,7 @@ Document indexPubspec({ 'scip-dart', 'pub', pubspec.name, - pubspec.version!, + pubspec.version ?? '*', '`pubspec.yaml`/', ].join(' '); From 4bba7cb9531e9c230f8da9eb5820b4a93eebfb71 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 17 Apr 2025 08:18:36 -0600 Subject: [PATCH 2/5] omit file symbol for non-published pubspecs --- lib/src/pubspec_indexer.dart | 93 +++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/lib/src/pubspec_indexer.dart b/lib/src/pubspec_indexer.dart index 7279de9..b12e58b 100644 --- a/lib/src/pubspec_indexer.dart +++ b/lib/src/pubspec_indexer.dart @@ -24,30 +24,18 @@ Document indexPubspec({ }) { final pubspecLineInfo = LineInfo.fromContent(pubspecStr); - final fileSymbol = [ - 'scip-dart', - 'pub', - pubspec.name, - pubspec.version ?? '*', - '`pubspec.yaml`/', - ].join(' '); + final symbols = []; + final occurrences = []; - final symbols = [ - 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( - symbol: fileSymbol, - range: [0, 0, 0], - ) - ]; + // 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, range: [0, 0, 0],)); + } final deps = { DependencyKind.regular: pubspec.dependencies, @@ -73,6 +61,29 @@ 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) { @@ -80,23 +91,27 @@ SymbolInformation _buildSymbol(String depName, PubspecLock lock) { '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 { From 4fd8fe8c0279763d99d2f12be6923e33e16b5913 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 17 Apr 2025 08:26:29 -0600 Subject: [PATCH 3/5] fmt --- lib/src/pubspec_indexer.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/pubspec_indexer.dart b/lib/src/pubspec_indexer.dart index b12e58b..9228e1d 100644 --- a/lib/src/pubspec_indexer.dart +++ b/lib/src/pubspec_indexer.dart @@ -34,7 +34,10 @@ Document indexPubspec({ if (pubspec.publishTo != 'none') { final info = _buildFileSymbol(pubspec); symbols.add(info); - occurrences.add(Occurrence(symbol: info.symbol, range: [0, 0, 0],)); + occurrences.add(Occurrence( + symbol: info.symbol, + range: [0, 0, 0], + )); } final deps = { From 2fa7436e0a1149f6d14b2d9f8c01d4569e78b721 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 17 Apr 2025 08:33:29 -0600 Subject: [PATCH 4/5] correctly declare file symbol as a definition --- lib/src/pubspec_indexer.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/pubspec_indexer.dart b/lib/src/pubspec_indexer.dart index 9228e1d..f2502ca 100644 --- a/lib/src/pubspec_indexer.dart +++ b/lib/src/pubspec_indexer.dart @@ -36,6 +36,7 @@ Document indexPubspec({ symbols.add(info); occurrences.add(Occurrence( symbol: info.symbol, + symbolRoles: SymbolRole.Definition.value, range: [0, 0, 0], )); } From df94043d54dccab0c2a3e5299fc4e83d532d00ed Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 17 Apr 2025 08:42:55 -0600 Subject: [PATCH 5/5] snaps --- snapshots/output/basic-project/pubspec.yaml | 2 +- snapshots/output/diagnostics/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/snapshots/output/basic-project/pubspec.yaml b/snapshots/output/basic-project/pubspec.yaml index ea4b27a..a38e70e 100755 --- a/snapshots/output/basic-project/pubspec.yaml +++ b/snapshots/output/basic-project/pubspec.yaml @@ -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: diff --git a/snapshots/output/diagnostics/pubspec.yaml b/snapshots/output/diagnostics/pubspec.yaml index 91cf323..f96b652 100755 --- a/snapshots/output/diagnostics/pubspec.yaml +++ b/snapshots/output/diagnostics/pubspec.yaml @@ -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: