Skip to content

feat: implement version lens#99

Open
9romise wants to merge 11 commits intomainfrom
version-lens
Open

feat: implement version lens#99
9romise wants to merge 11 commits intomainfrom
version-lens

Conversation

@9romise
Copy link
Copy Markdown
Member

@9romise 9romise commented Apr 3, 2026

close #2, close #32

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54a236a1-d1f6-473b-a6a3-8711c0b0f3a7

📥 Commits

Reviewing files that changed from the base of the PR and between 63508f1 and e665200.

📒 Files selected for processing (2)
  • packages/language-service/src/plugins/version-lens.ts
  • packages/language-service/src/utils/version.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/language-service/src/plugins/version-lens.ts

📝 Walkthrough

Walkthrough

Adds a "version lens" CodeLens feature and supporting plumbing. Two new VS Code configuration keys (npmx.versionLens.enabled, npmx.versionLens.hideWhenLatest) were added. A new language-service plugin npmx-version-lens generates CodeLenses for npm dependency spec ranges and consults resolved workspace state; it honours the new settings and can hide lenses when a dependency is already at the latest. A new replaceText command and REPLACE_TEXT_COMMAND constant were introduced and wired into the extension command registration. Utilities now include resolveUpgradeTiers plus related types and tests for computing patch/minor/major upgrade targets.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description references the two linked issues (#2 and #32) that define the version lens feature objectives.
Linked Issues check ✅ Passed The PR fully implements version lens functionality with CodeLens UI, upgrade tier resolution, and one-click upgrade commands as required by #2 and #32.
Out of Scope Changes check ✅ Passed All changes directly support version lens implementation; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch version-lens

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
packages/language-service/src/utils/version.ts (1)

59-71: Consider handling invalid semver input gracefully.

new SemVer(resolvedVersion) on line 60 will throw a TypeError if resolvedVersion is not a valid semver string. Whilst the caller should ideally provide valid input, defensive handling would prevent runtime crashes when encountering malformed version specs.

♻️ Suggested defensive handling
 export function resolveUpgradeTiers(pkg: PackageInfo, resolvedVersion: string): UpgradeTier[] {
+  let current: SemVer
+  try {
+    current = new SemVer(resolvedVersion)
+  }
+  catch {
+    return []
+  }
-  const current = new SemVer(resolvedVersion)
   const currentMajor = current.major
   const currentMinor = current.minor
packages/language-service/src/utils/version.test.ts (1)

28-33: Test helper uses as cast; consider a type-safe alternative.

The as PackageInfo cast on line 32 bypasses type checking. Whilst acceptable in test helpers, a more type-safe approach would use satisfies or provide complete mock data.

♻️ Type-safe alternative using Partial
-function createPkg(versions: string[]): PackageInfo {
+function createPkg(versions: string[]): Partial<PackageInfo> & Pick<PackageInfo, 'versionsMeta' | 'distTags'> {
   const versionsMeta: Record<string, object> = {}
   for (const v of versions)
     versionsMeta[v] = {}
-  return { versionsMeta, distTags: { latest: versions.at(-1)! } } as PackageInfo
+  return { versionsMeta, distTags: { latest: versions.at(-1)! } }
 }

As per coding guidelines: "Avoid as type casts—validate instead in TypeScript".

extensions/vscode/src/commands/replace-text.ts (1)

4-15: Consider handling applyEdit failure.

workspace.applyEdit() returns Promise<boolean> indicating whether the edit was applied successfully. Silently ignoring failures could lead to confusing user experiences when edits don't apply (e.g., file changed externally, read-only file).

♻️ Suggested error handling
 export async function replaceText(uri: string, range: LspRange, newText: string) {
   const edit = new WorkspaceEdit()
   edit.replace(
     Uri.parse(uri),
     new Range(
       new Position(range.start.line, range.start.character),
       new Position(range.end.line, range.end.character),
     ),
     newText,
   )
-  await workspace.applyEdit(edit)
+  const success = await workspace.applyEdit(edit)
+  if (!success) {
+    throw new Error(`Failed to apply edit to ${uri}`)
+  }
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1cf001e9-a8a6-4365-a514-09e85dd1d164

📥 Commits

Reviewing files that changed from the base of the PR and between 0aafc62 and a918671.

📒 Files selected for processing (9)
  • extensions/vscode/README.md
  • extensions/vscode/package.json
  • extensions/vscode/src/commands/replace-text.ts
  • extensions/vscode/src/index.ts
  • packages/language-service/src/index.ts
  • packages/language-service/src/plugins/version-lens.ts
  • packages/language-service/src/utils/version.test.ts
  • packages/language-service/src/utils/version.ts
  • packages/shared/src/commands.ts

Comment thread packages/language-service/src/plugins/version-lens.ts Outdated
Comment thread packages/language-service/src/plugins/version-lens.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to latest

1 participant