Repository navigation
Conversation
|
🔍 OpenCodeReview found 8 issue(s) in this PR.
|
| const root = await git.getRepositoryRoot(); | ||
| if (!root) return; |
There was a problem hiding this comment.
Silent early return leaves partially-mutated state. When getRepositoryRoot() returns null, the method returns after already mutating this.git, this.comments, and this.reviewContext (lines 56-58), but before creating any threads or calling emitSync(). This leaves the CommentProvider in an inconsistent state — comments are stored but invisible, and sync listeners are never notified.
Although the caller (SidebarProvider.startReview) currently guards against a missing repo root before invoking show, this silent return is fragile: if future refactoring changes the caller's guard or adds new call sites, the inconsistency would surface as a hard-to-debug UI bug.
Consider either throwing an error (so the caller's try/catch logs a warning) or calling emitSync() before returning to ensure listeners see a consistent empty state.
| try { | ||
| const cwd = await git.getRepositoryRoot(); | ||
| if (!cwd) { | ||
| this.post({ type: 'stateChange', state: 'failed', error: t(resolveLocale(vscode.env.language), 'ext.noRepository') }); |
There was a problem hiding this comment.
Minor: Redundant locale resolution. resolveLocale(vscode.env.language) is called inline three times within this method (lines 72, 79, 118). Consider resolving it once at the top of handle() (or caching it as a class field) and reusing the value, consistent with how the ready handler already assigns it to a local variable.
| onDone: (result) => { | ||
| completion = (async () => { | ||
| try { | ||
| if (result.comments.length) { | ||
| await this.comments.show(result.comments, { | ||
| mode: msg.options.mode, | ||
| from: msg.options.from, | ||
| to: msg.options.to, | ||
| commit: msg.options.commit, | ||
| }, git); | ||
| } | ||
| } catch (e) { | ||
| this.post({ | ||
| type: 'logLine', | ||
| line: { level: 'warn', text: `[ocr] Unable to display inline comments: ${e instanceof Error ? e.message : String(e)}` }, | ||
| }); | ||
| } | ||
| this.post({ type: 'reviewDone', result }); | ||
| })(); |
There was a problem hiding this comment.
Race condition / inconsistency: The onDone, onState, and onLog callbacks do not check git === this.git before posting messages, unlike every other async handler in this method (ready, getGitState, getModeFiles). While the reviewRunning guard currently prevents workspace switching during a review, this is a defense-in-depth concern. If any future code path mutates this.git without checking reviewRunning, stale review results would be posted to the webview and applied to the wrong workspace's comment provider.
Recommend adding a git === this.git guard inside onDone (and ideally onState/onLog) for consistency and safety:
Suggestion:
| onDone: (result) => { | |
| completion = (async () => { | |
| try { | |
| if (result.comments.length) { | |
| await this.comments.show(result.comments, { | |
| mode: msg.options.mode, | |
| from: msg.options.from, | |
| to: msg.options.to, | |
| commit: msg.options.commit, | |
| }, git); | |
| } | |
| } catch (e) { | |
| this.post({ | |
| type: 'logLine', | |
| line: { level: 'warn', text: `[ocr] Unable to display inline comments: ${e instanceof Error ? e.message : String(e)}` }, | |
| }); | |
| } | |
| this.post({ type: 'reviewDone', result }); | |
| })(); | |
| onDone: (result) => { | |
| completion = (async () => { | |
| if (git !== this.git) return; | |
| try { | |
| if (result.comments.length) { | |
| await this.comments.show(result.comments, { | |
| mode: msg.options.mode, | |
| from: msg.options.from, | |
| to: msg.options.to, | |
| commit: msg.options.commit, | |
| }, git); | |
| } | |
| } catch (e) { | |
| this.post({ | |
| type: 'logLine', | |
| line: { level: 'warn', text: `[ocr] Unable to display inline comments: ${e instanceof Error ? e.message : String(e)}` }, | |
| }); | |
| } | |
| this.post({ type: 'reviewDone', result }); | |
| })(); |
| const root = await this.getRepositoryRoot(); | ||
| const apiRoot = await realpath(repo.rootUri.fsPath).catch(() => null); |
There was a problem hiding this comment.
Symlink resolution asymmetry: apiRoot is resolved through realpath() (which resolves symlinks), but root from getRepositoryRoot() (git rev-parse --show-toplevel) is not. If the workspace path involves symlinks, these two values may differ even for the same repository, causing a valid repo to be incorrectly rejected. Consider applying realpath() to both sides (or neither) for consistent comparison.
| // An ancestor may be discovered before the selected nested repository. | ||
| if (!root || !apiRoot || relative(apiRoot, root) !== '') repo = null; |
There was a problem hiding this comment.
The comment says "An ancestor may be discovered before the selected nested repository", but the check actually verifies that the API-reported repo root matches the git rev-parse root exactly. If the intent is to detect when VS Code's Git extension selects an ancestor repo instead of the correct nested one, consider adding a more descriptive log message when this mismatch occurs so users can diagnose why their repo is being rejected. Currently it falls through to getState: no repo which doesn't explain the root cause.
| const root = await this.getRepositoryRoot(); | ||
| const apiRoot = await realpath(repo.rootUri.fsPath).catch(() => null); | ||
| // An ancestor may be discovered before the selected nested repository. | ||
| if (!root || !apiRoot || relative(apiRoot, root) !== '') repo = null; |
There was a problem hiding this comment.
Potential false negative on case-insensitive filesystems (macOS, Windows). path.relative performs string-based comparison, so if apiRoot and root differ only in casing (e.g., /Users/Foo/repo vs /users/foo/repo), relative() will return a non-empty path and the valid repo will be incorrectly rejected.
Consider normalizing both paths to the same case before comparison, or using a direct equality check with case-insensitive comparison on platforms that need it:
const normalize = process.platform === 'win32' || process.platform === 'darwin'
? (p: string) => p.toLowerCase()
: (p: string) => p;
if (!root || !apiRoot || normalize(apiRoot) !== normalize(root)) repo = null;Alternatively, since you already use realpath for apiRoot, you could also apply realpath to root to ensure both are fully resolved and comparable.
| this.cache.branches = []; | ||
| this.cache.currentBranch = ''; | ||
| this.cache.recentCommits = []; |
There was a problem hiding this comment.
Behavioral regression: The old code returned a fresh empty object with workspaceFiles: [] when no repo was found. Now snapshot() spreads this.cache, which may contain stale workspaceFiles from a prior Workspace-mode call. While consumers currently only read workspaceFiles in Workspace mode, returning stale data violates the contract and could cause subtle bugs if any caller inspects workspaceFiles regardless of mode. Consider also clearing this.cache.workspaceFiles = [] here to match the previous behavior.
Suggestion:
| this.cache.branches = []; | |
| this.cache.currentBranch = ''; | |
| this.cache.recentCommits = []; | |
| this.cache.branches = []; | |
| this.cache.currentBranch = ''; | |
| this.cache.recentCommits = []; | |
| this.cache.workspaceFiles = []; |
| case 'workspaceChanged': | ||
| return { | ||
| ...initialState, | ||
| config: state.config, | ||
| locale: state.locale, | ||
| gitState: msg.gitState, | ||
| filesLoading: false, | ||
| }; |
There was a problem hiding this comment.
Minor: Spreading initialState sets filesLoading: true (from initialState), only to immediately override it to false on the next line. While functionally correct, this is slightly misleading to readers. Consider either omitting filesLoading from the override (since you want false, not the initial true) or restructuring for clarity.
Also note that this resets reviewMode to ReviewMode.Workspace (via initialState). If the user was on Branch/Commit mode before switching workspaces, they'll be silently reset to Workspace mode. Make sure this is the intended behavior.
|
Heads up — #1031 just landed on main and moved the VS Code webview and shared types into a new |
a099757 to
c7c331e
Compare
|
The multi-root workspace selection addresses a real pain point from #1350, and the test coverage for stale responses and review-time switching looks solid. Two things before this can land: 1. Rebase needed — currently CONFLICTING with main. 2. Path comparison rejects valid repos on case-insensitive filesystems (
Before: user selects a nested repo in a multi-root workspace on macOS, sees branches and commits. Please apply Optional follow-up, not blocking: AI assistance disclosure: This review was drafted with the help of Hermes Agent (Kimi, developed by Moonshot AI), which analyzed the PR diff, the linked issue #1350, and the existing OCR bot comments via the GitHub API. I personally reviewed the analysis and the final wording before posting; the judgments and requests in this comment are my own. |
Description
In a multi-root VS Code workspace, reviews always use the first folder. Add a Project button that opens the native workspace-folder picker and use the selected folder's Git repository for changed files, branch/commit metadata, CLI reviews, diff navigation, and inline comments.
Switching projects clears old results and branch/commit selections, reattaches the Git watcher, and ignores stale responses. Selection stays fixed until the review and comment mounting finish. Results remain available if inline comments cannot mount; if the repository disappears, unavailable comment jump links stay disabled. Workspace subdirectories resolve to their Git root, and non-Git folders cannot silently review another repository.
Rebased onto
e5d7ce0after #1031. Shared UI, types, messages, and tests now live underextensions/frontend/; the VS Code host uses the new@shared/imports. The shared UI shows the Project button only when the host supplies workspace metadata. IDEA does not expose this VS Code-only feature; its message-contract tests explicitly account for the two host-specific messages.This addresses project selection in #1350. Result copying/exporting remains outside this PR.
Type of Change
How Has This Been Tested?
npm test -- --runInBand: 103 tests across 12 suites pass.npm test -- --runInBand: 18 tests pass. Total remains 121 after splitting the packages.npm run typecheck, bothOCR_TARGET=vscode npm run buildandOCR_TARGET=idea npm run build, and VS Codenpm run build:extension: pass.npm run lint, repositorymake check, andgit diff --check: pass.make test: all 23 Go packages pass on the rebased tree, with race detection enabled.selectWorkspace, the returned project updates the UI, selection is disabled during review, and the IDEA bundle omits the unsupported selector. These tests make no CLI/LLM calls.Earlier OCR CLI self-reviews used DeepSeek
deepseek-v4-pro. No additional OCR/LLM API review was run for this migration; the validation above was rerun locally. Root-resolution subprocess overhead remains a possible performance follow-up.Checklist
go fmt,go vet)AI assistance: OpenAI Codex (GPT-6) was used for investigation, implementation, tests, migration, and drafting this description. OpenCodeReview CLI with DeepSeek
deepseek-v4-prowas used for the earlier self-reviews. The contributor personally reviewed the submission before it was marked ready for review. Substantive answers to maintainer questions will come from the contributor, with AI limited to translation or wording assistance.Related Issues
Refs #1350 (project selection only). Adapts to the frontend extraction in #1031.