Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/renderer/src/components/right-sidebar/FileExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ function FileExplorerFiles(): React.JSX.Element {
}, [])
const { handleClick, handleDoubleClick, handleWheelCapture } = useFileExplorerHandlers({
activeWorktreeId,
runtimeEnvironmentId: activeRuntimeEnvironmentId,
openFile,
makePreviewFilePermanent,
toggleDir: hasNameFilter ? handleToggleNameFilterDir : toggleDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ let capturedHandlers: ReturnType<typeof useFileExplorerHandlers> | null = null
function HandlersProbe({ scrollRef }: { scrollRef: React.RefObject<HTMLDivElement | null> }): null {
capturedHandlers = useFileExplorerHandlers({
activeWorktreeId: 'wt-1',
runtimeEnvironmentId: null,
openFile: vi.fn(),
makePreviewFilePermanent: vi.fn(),
toggleDir: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('activateFileExplorerNode', () => {
await activateFileExplorerNode({
node: symlinkNode,
activeWorktreeId: 'wt-1',
runtimeEnvironmentId: 'runtime-env-1',
openFile,
toggleDir: vi.fn(),
loadDir: vi.fn(),
Expand All @@ -85,10 +86,42 @@ describe('activateFileExplorerNode', () => {
filePath: '/repo/linked-docs',
relativePath: 'linked-docs',
worktreeId: 'wt-1',
runtimeEnvironmentId: 'runtime-env-1',
language: expect.any(String),
mode: 'edit'
},
{ preview: true }
{ preview: true, suppressActiveRuntimeFallback: false }
)
})

it('opens local files without runtime fallback when no runtime owner is set', async () => {
const fileNode: TreeNode = {
name: 'README.md',
path: '/repo/README.md',
relativePath: 'README.md',
isDirectory: false,
depth: 0
}
const openFile = vi.fn()

await activateFileExplorerNode({
node: fileNode,
activeWorktreeId: 'wt-1',
runtimeEnvironmentId: null,
openFile,
toggleDir: vi.fn(),
loadDir: vi.fn(),
statPath: vi.fn(),
markPathAsDirectory: vi.fn(),
setSelectedPath: vi.fn()
})

expect(openFile).toHaveBeenCalledWith(
expect.objectContaining({
filePath: '/repo/README.md',
runtimeEnvironmentId: undefined
}),
{ preview: true, suppressActiveRuntimeFallback: true }
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import { translate } from '@/i18n/i18n'

type UseFileExplorerHandlersParams = {
activeWorktreeId: string | null
runtimeEnvironmentId?: string | null
openFile: (
params: {
filePath: string
relativePath: string
worktreeId: string
language: string
mode: 'edit'
runtimeEnvironmentId?: string | null
},
options?: { preview?: boolean }
options?: { preview?: boolean; suppressActiveRuntimeFallback?: boolean }
) => void
makePreviewFilePermanent: (filePath: string) => void
toggleDir: (worktreeId: string, dirPath: string) => void
Expand Down Expand Up @@ -45,6 +47,7 @@ type OpenFileOptions = Parameters<UseFileExplorerHandlersParams['openFile']>[1]
export async function activateFileExplorerNode(args: {
node: TreeNode
activeWorktreeId: string | null
runtimeEnvironmentId?: string | null
openFile: (params: OpenFileParams, options?: OpenFileOptions) => void
toggleDir: (worktreeId: string, dirPath: string) => void
canToggleDirectories?: boolean
Expand All @@ -56,6 +59,7 @@ export async function activateFileExplorerNode(args: {
const {
node,
activeWorktreeId,
runtimeEnvironmentId,
openFile,
toggleDir,
canToggleDirectories = true,
Expand Down Expand Up @@ -116,15 +120,22 @@ export async function activateFileExplorerNode(args: {
filePath: node.path,
relativePath: node.relativePath,
worktreeId: activeWorktreeId,
runtimeEnvironmentId: runtimeEnvironmentId ?? undefined,
language: detectLanguage(node.name),
mode: 'edit'
},
{ preview: true }
{
preview: true,
// Why: explicit local opens must not inherit the active runtime, so we
// encode "no runtime owner" via the fallback-suppression option.
suppressActiveRuntimeFallback: runtimeEnvironmentId === null
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
)
}

export function useFileExplorerHandlers({
activeWorktreeId,
runtimeEnvironmentId,
openFile,
makePreviewFilePermanent,
toggleDir,
Expand All @@ -140,6 +151,7 @@ export function useFileExplorerHandlers({
void activateFileExplorerNode({
node,
activeWorktreeId,
runtimeEnvironmentId,
openFile,
toggleDir,
canToggleDirectories,
Expand All @@ -151,6 +163,7 @@ export function useFileExplorerHandlers({
},
[
activeWorktreeId,
runtimeEnvironmentId,
canToggleDirectories,
loadDir,
markPathAsDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ export function useFileExplorerInlineInput({
}
await refreshDir(inlineInput.parentPath)
if (inlineInput.type === 'file') {
openFile({
filePath: fullPath,
relativePath: worktreePath ? fullPath.slice(worktreePath.length + 1) : name,
worktreeId: activeWorktreeId,
language: detectLanguage(name),
mode: 'edit'
})
const runtimeEnvironmentId =
fileContext.settings.activeRuntimeEnvironmentId?.trim() || null
openFile(
{
filePath: fullPath,
relativePath: worktreePath ? fullPath.slice(worktreePath.length + 1) : name,
worktreeId: activeWorktreeId,
runtimeEnvironmentId: runtimeEnvironmentId ?? undefined,
language: detectLanguage(name),
mode: 'edit'
},
{ suppressActiveRuntimeFallback: runtimeEnvironmentId === null }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
)
}
} catch (err) {
// Refresh the directory even on failure so the tree stays consistent
Expand Down