-
-
Couldn't load subscription status.
- Fork 126
feat: support save markdown preview file #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jiashengguo
commented
Sep 26, 2025
- telemetry tracking for VSCode extension
📝 WalkthroughWalkthroughAdds a VS Code telemetry module, instruments extension activation and sign-in flows, updates ZModel preview to cache and save generated markdown with a fixed temp filename and context-key toggling, and adds a build step to copy preview resources and replace a telemetry token. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant VSCode as VS Code
participant Ext as Extension
participant Tele as Telemetry
participant Auth as Auth Provider
participant IdP as Identity Provider
VSCode->>Ext: activate()
Ext->>Tele: track("extension:activate")
Ext->>VSCode: requireAuth() prompts
Ext->>Tele: track("extension:signin:show")
VSCode->>Ext: user clicks "Sign in"
Ext->>Tele: track("extension:signin:start")
Ext->>Auth: start auth flow
Auth->>IdP: open auth URL
IdP-->>Auth: callback with token
Auth->>Auth: decode claims (email)
Auth->>Tele: identify(email)
Auth-->>Ext: success
Ext->>Tele: track("extension:signin:complete")
Note over Ext,Tele: On error: track("extension:signin:error", payload)
sequenceDiagram
autonumber
participant User
participant ZPrev as ZModelPreview
participant Tele as Telemetry
participant FS as File System
participant VSCode as VS Code UI
User->>ZPrev: Preview ZModel
ZPrev->>Tele: track("extension:zmodel-preview")
ZPrev->>ZPrev: generate markdown & cache lastGeneratedMarkdown
ZPrev->>FS: write temp preview.md (fixed name)
ZPrev->>VSCode: open markdown preview
Note over VSCode,ZPrev: Tab change updates context key
User->>ZPrev: Save documentation (command)
ZPrev->>ZPrev: ensure lastGeneratedMarkdown exists
ZPrev->>VSCode: show save dialog (.md)
VSCode-->>ZPrev: selected path
ZPrev->>FS: write saved file
ZPrev->>VSCode: open & close saved doc (refresh preview)
ZPrev->>Tele: track("extension:zmodel-save")
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code graph analysis (1)packages/schema/src/vscode/vscode-telemetry.ts (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (1)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Nitpick comments (4)
packages/schema/src/vscode-telemetry.ts (1)
29-35: Telemetry enablement fallback (optional)env.isTelemetryEnabled may not exist in older VS Code. Optionally, fall back to telemetry.telemetryLevel !== 'off'.
- if (vscode.env.isTelemetryEnabled) { + const isEnabled = + (vscode.env as any).isTelemetryEnabled ?? + vscode.workspace.getConfiguration('telemetry').get('telemetryLevel') !== 'off'; + if (isEnabled) {packages/schema/src/extension.ts (1)
23-35: Sanitize error telemetry payloadsSending raw error messages can include URLs, tokens, or PII. Prefer minimal fields (name/code) and truncate length.
- telemetry.track('extension:signin:error', { error: e instanceof Error ? e.message : String(e) }); + const err = e instanceof Error ? { name: e.name, message: String(e.message).slice(0, 200) } : { message: String(e).slice(0, 200) }; + telemetry.track('extension:signin:error', err);packages/schema/src/zmodel-preview.ts (2)
290-334: Refine Save UX and robustness
- Opening then immediately closing the saved file is jarring and doesn’t refresh the preview (which points to the temp file).
- Consider notifying the user and offering to open the saved file.
- // Open and close the saved file to refresh the shown markdown preview - await vscode.commands.executeCommand('vscode.open', saveUri); - await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); + // Notify user and optionally open the saved file + const action = await vscode.window.showInformationMessage( + `Documentation saved: ${saveUri.fsPath}`, + 'Open File' + ); + if (action === 'Open File') { + await vscode.commands.executeCommand('vscode.open', saveUri); + }
268-271: Optional: include source filename in default save nameIf feasible, derive defaultFilePath from the active ZModel (e.g., -doc.md). You’d need to persist the originating document name when generating.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/schema/package.jsonis excluded by!**/*.json
📒 Files selected for processing (5)
packages/schema/src/extension.ts(3 hunks)packages/schema/src/res/zmodel-preview-release-notes.html(1 hunks)packages/schema/src/vscode-telemetry.ts(1 hunks)packages/schema/src/zenstack-auth-provider.ts(2 hunks)packages/schema/src/zmodel-preview.ts(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/schema/src/vscode-telemetry.ts (3)
packages/schema/bin/post-install.js (3)
Mixpanel(6-6)os(8-8)payload(16-28)packages/schema/src/global.d.ts (1)
TELEMETRY_TRACKING_TOKEN(2-2)packages/schema/src/utils/machine-id-utils.ts (1)
getMachineId(63-74)
packages/schema/src/extension.ts (1)
packages/schema/src/zenstack-auth-provider.ts (1)
AUTH_PROVIDER_ID(11-11)
packages/schema/src/zmodel-preview.ts (1)
packages/schema/src/documentation-cache.ts (1)
DocumentationCache(15-152)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
🔇 Additional comments (6)
packages/schema/src/zenstack-auth-provider.ts (1)
2-2: LGTM: central telemetry importImporting the shared telemetry singleton here aligns usage across the extension.
packages/schema/src/extension.ts (1)
45-45: LGTM: activation telemetryActivation event is tracked once on startup and gated by telemetry settings.
packages/schema/src/zmodel-preview.ts (4)
18-21: Preview file naming approach is soundZero-width space avoids collisions; consistent with the tab detection logic.
96-96: LGTM: preview event telemetryEvent is emitted at start of preview generation.
128-133: Good: cache last generated content for SaveThis enables Save without re-calling the API.
268-284: Temp preview creation is fineUsing os.tmpdir and markdown.showPreviewToSide is appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/schema/src/zmodel-preview.ts (1)
301-309: Offer contextual default Save name (optional improvement).Right now every save dialog defaults to
zmodel-doc.md, which makes it easy to overwrite the wrong file when you’re documenting several models. We already know the source.zmodelthat producedlastGeneratedMarkdown, so we could capture its stem during preview and reuse it here to prefill something like<model>-documentation.md.- let defaultFilePath = `zmodel-doc.md`; + const defaultFileName = `${this.lastPreviewedDocumentName ?? 'zmodel-doc'}.md`; + let defaultFilePath = defaultFileName; @@ - defaultFilePath = path.join(workspacePath, defaultFilePath); + defaultFilePath = path.join(workspacePath, defaultFileName);// near other fields private lastPreviewedDocumentName: string | null = null; // in previewZModelFile() when generation succeeds this.lastPreviewedDocumentName = path.parse(document.fileName).name;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/schema/package.jsonis excluded by!**/*.json
📒 Files selected for processing (2)
packages/schema/src/vscode-telemetry.ts(1 hunks)packages/schema/src/zmodel-preview.ts(7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/schema/src/vscode-telemetry.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/schema/src/zmodel-preview.ts (1)
packages/schema/src/documentation-cache.ts (1)
DocumentationCache(15-152)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: OSSAR-Scan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/schema/tsconfig.jsonis excluded by!**/*.json
📒 Files selected for processing (6)
packages/schema/build/bundle.js(1 hunks)packages/schema/src/extension.ts(3 hunks)packages/schema/src/vscode/res/zmodel-preview-release-notes.html(1 hunks)packages/schema/src/vscode/vscode-telemetry.ts(1 hunks)packages/schema/src/vscode/zenstack-auth-provider.ts(2 hunks)packages/schema/src/vscode/zmodel-preview.ts(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/schema/src/vscode/zmodel-preview.ts (1)
packages/schema/src/vscode/documentation-cache.ts (1)
DocumentationCache(15-152)
packages/schema/src/extension.ts (1)
packages/schema/src/vscode/zenstack-auth-provider.ts (1)
AUTH_PROVIDER_ID(11-11)
packages/schema/src/vscode/vscode-telemetry.ts (3)
packages/schema/bin/post-install.js (3)
Mixpanel(6-6)os(8-8)payload(16-28)packages/schema/src/global.d.ts (1)
TELEMETRY_TRACKING_TOKEN(2-2)packages/schema/src/utils/machine-id-utils.ts (1)
getMachineId(63-74)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: build-test (20.x)
- GitHub Check: OSSAR-Scan
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/schema/build/bundle.js(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: dependency-review
- GitHub Check: OSSAR-Scan
- GitHub Check: build-test (20.x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/schema/build/bundle.js(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
- GitHub Check: OSSAR-Scan
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)