feat(language-service): add installed package definitions#138
Conversation
📝 WalkthroughWalkthroughChangesThis change adds package-name path-safety helpers and a new Related PRs: None indicated. Suggested labels: enhancement, language-service, language-core Suggested reviewers: None indicated. 🐰 A rabbit hops through node_modules deep, 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
packages/language-service/src/utils/document.ts (1)
23-35: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor duplication between the two offset helpers.
getResolvedDependencyNameAtOffsetandgetResolvedDependencySpecAtOffsetare identical apart from the range field used. Could be reduced to a single parametrized helper, but the duplication is small and keeping them separate/explicit aids readability given each is a public API. Optional.packages/language-service/src/plugins/catalog.ts (1)
8-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueInconsistent catalog-detection signal vs. document-link.ts.
This helper detects catalog dependencies via
rawSpec.startsWith('catalog:'), whereasprovidePackageDocumentLinksindocument-link.tsusesdep.protocol === 'catalog'for the same purpose. Both work today, but relying on two different signals for the same classification is fragile if they ever diverge. Consider standardising ondep.protocol === 'catalog'here as well.packages/language-service/src/plugins/document-link.ts (1)
27-33: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winImplicit handling of the
'latest'link mode.
targetVersionis only set for'declared'/'resolved'; the'latest'case is handled implicitly by falling through both branches. This currently produces the intended result, but it's not exhaustively checked — a future addition toEnabledPackageLinkModewithout an explicit branch here would silently fall through the same way. Consider making the'latest'case explicit for clarity and safety.♻️ Proposed explicit handling
let targetVersion: string | undefined if (linkMode === 'declared') { targetVersion = resolvedSpec } else if (linkMode === 'resolved') { targetVersion = await dep.resolvedVersion() ?? resolvedSpec + } else if (linkMode === 'latest') { + targetVersion = undefined }packages/language-core/src/workspace.ts (1)
200-216: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated directory-walk logic between the two manifest lookups.
findNearestPackageManifestPath(Lines 200-216) andfindInstalledPackageManifestPath(Lines 218-250) share the same upward directory-walk skeleton (loop condition, root-break, parent-advance-break), differing only in what candidate path is tested per directory. Extracting the shared walk into a helper that accepts a per-directory candidate-path callback would remove the duplication and reduce the risk of the two loops drifting apart on future fixes.♻️ Possible refactor sketch
+ async `#walkUpToRoot`( + startDir: string, + getCandidate: (dir: string) => string | undefined, + ): Promise<string | undefined> { + let dir = startDir + while (isPathInsideOrEqual(dir, this.rootPath)) { + const candidate = getCandidate(dir) + if (candidate && await this.adapter.fileExists(candidate)) + return candidate + + if (dir === this.rootPath) + break + + const parent = dirname(dir) + if (parent === dir) + break + dir = parent + } + }Also applies to: 218-250
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e9d63ad0-d37f-4b8d-881b-722ae84eba02
📒 Files selected for processing (16)
extensions/vscode/README.mdextensions/vscode/package.jsonpackages/language-core/src/constants.tspackages/language-core/src/workspace.test.tspackages/language-core/src/workspace.tspackages/language-server/src/workspace.tspackages/language-service/src/index.tspackages/language-service/src/plugins/catalog.test.tspackages/language-service/src/plugins/catalog.tspackages/language-service/src/plugins/document-link.test.tspackages/language-service/src/plugins/document-link.tspackages/language-service/src/plugins/installed-package-definition.test.tspackages/language-service/src/plugins/installed-package-definition.tspackages/language-service/src/test-utils/dependency.tspackages/language-service/src/utils/document.test.tspackages/language-service/src/utils/document.ts
Summary
CleanShot.2026-07-03.at.22.45.04.mp4
Validation