Repository navigation
Refactor terminal component #839
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { Button } from "@superset/ui/button"; | ||
| import { Card } from "@superset/ui/card"; | ||
| import { HiExclamationTriangle } from "react-icons/hi2"; | ||
| import { LuPower, LuTerminal } from "react-icons/lu"; | ||
|
|
||
| interface OverlayContainerProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| /** | ||
| * Common overlay container with centered positioning and backdrop. | ||
| */ | ||
| function OverlayContainer({ children }: OverlayContainerProps) { | ||
| return ( | ||
| <div className="absolute inset-0 z-10 flex items-center justify-center bg-black/50"> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| interface KilledOverlayProps { | ||
| onRestart: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Overlay shown when terminal session was killed by user. | ||
| */ | ||
| export function KilledOverlay({ onRestart }: KilledOverlayProps) { | ||
| return ( | ||
| <OverlayContainer> | ||
| <Card className="gap-3 py-4 px-2"> | ||
| <div className="flex flex-col items-center text-center gap-1.5 px-4"> | ||
| <LuPower className="size-5 text-muted-foreground" /> | ||
| <div className="space-y-0.5"> | ||
| <p className="text-sm font-medium">Session killed</p> | ||
| <p className="text-xs text-muted-foreground"> | ||
| You terminated this shell session | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <div className="px-4"> | ||
| <Button size="sm" className="w-full" onClick={onRestart}> | ||
| Restart | ||
| </Button> | ||
| </div> | ||
| </Card> | ||
| </OverlayContainer> | ||
| ); | ||
| } | ||
|
|
||
| interface ConnectionErrorOverlayProps { | ||
| onRetry: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Overlay shown when connection to terminal daemon is lost. | ||
| */ | ||
| export function ConnectionErrorOverlay({ | ||
| onRetry, | ||
| }: ConnectionErrorOverlayProps) { | ||
| return ( | ||
| <OverlayContainer> | ||
| <Card className="gap-3 py-4 px-2 max-w-xs"> | ||
| <div className="flex flex-col items-center text-center gap-1.5 px-4"> | ||
| <HiExclamationTriangle className="size-5 text-destructive" /> | ||
| <div className="space-y-0.5"> | ||
| <p className="text-sm font-medium">Connection error</p> | ||
| <p className="text-xs text-muted-foreground"> | ||
| Lost connection to terminal daemon | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <div className="px-4"> | ||
| <Button size="sm" className="w-full" onClick={onRetry}> | ||
| Retry | ||
| </Button> | ||
| </div> | ||
| </Card> | ||
| </OverlayContainer> | ||
| ); | ||
| } | ||
|
|
||
| interface RestoredOverlayProps { | ||
| onStartShell: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Overlay shown after cold restore (reboot recovery). | ||
| * Previous scrollback is preserved and displayed read-only until user starts new shell. | ||
| */ | ||
| export function RestoredOverlay({ onStartShell }: RestoredOverlayProps) { | ||
| return ( | ||
| <OverlayContainer> | ||
| <Card className="gap-3 py-4 px-2"> | ||
| <div className="flex flex-col items-center text-center gap-1.5 px-4"> | ||
| <LuTerminal className="size-5 text-primary" /> | ||
| <div className="space-y-0.5"> | ||
| <p className="text-sm font-medium">Session restored</p> | ||
| <p className="text-xs text-muted-foreground"> | ||
| Previous scrollback preserved after restart | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <div className="px-4"> | ||
| <Button size="sm" className="w-full" onClick={onStartShell}> | ||
| Start Shell | ||
| </Button> | ||
| </div> | ||
| </Card> | ||
| </OverlayContainer> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export { | ||
| ConnectionErrorOverlay, | ||
| KilledOverlay, | ||
| RestoredOverlay, | ||
| } from "./TerminalOverlays"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,28 @@ | ||
| export type { UseTerminalConnectionOptions } from "./useTerminalConnection"; | ||
| export { useTerminalConnection } from "./useTerminalConnection"; | ||
| export type { | ||
| UseTerminalCwdOptions, | ||
| UseTerminalCwdResult, | ||
| } from "./useTerminalCwd"; | ||
| export { useTerminalCwd } from "./useTerminalCwd"; | ||
| export type { | ||
| UseTerminalFileLinksOptions, | ||
| UseTerminalFileLinksResult, | ||
| } from "./useTerminalFileLinks"; | ||
| export { useTerminalFileLinks } from "./useTerminalFileLinks"; | ||
| export type { | ||
| UseTerminalInputOptions, | ||
| UseTerminalInputResult, | ||
| } from "./useTerminalInput"; | ||
| export { useTerminalInput } from "./useTerminalInput"; | ||
| export type { | ||
| CreateOrAttachResult, | ||
| UseTerminalSessionOptions, | ||
| UseTerminalSessionRefs, | ||
| UseTerminalSessionResult, | ||
| } from "./useTerminalSession"; | ||
| export { | ||
| coldRestoreState, | ||
| pendingDetaches, | ||
| useTerminalSession, | ||
| } from "./useTerminalSession"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import debounce from "lodash/debounce"; | ||
| import { useCallback, useEffect, useRef, useState } from "react"; | ||
| import { useTabsStore } from "renderer/stores/tabs/store"; | ||
| import { parseCwd } from "../parseCwd"; | ||
|
|
||
| export interface UseTerminalCwdOptions { | ||
| paneId: string; | ||
| /** Initial CWD from pane data (e.g., initialCwd) */ | ||
| initialCwd?: string | null; | ||
| /** Workspace CWD as fallback seed */ | ||
| workspaceCwd?: string | null; | ||
| } | ||
|
|
||
| export interface UseTerminalCwdResult { | ||
| /** Current terminal CWD */ | ||
| terminalCwd: string | null; | ||
| /** Whether CWD has been confirmed by OSC-7 (vs seeded from initialCwd) */ | ||
| cwdConfirmed: boolean; | ||
| /** Update CWD from terminal output data (parses OSC-7 sequences) */ | ||
| updateCwdFromData: (data: string) => void; | ||
| /** Ref to updateCwdFromData for use inside effects */ | ||
| updateCwdRef: React.RefObject<(data: string) => void>; | ||
| /** Set CWD directly (e.g., from restore data) */ | ||
| setTerminalCwd: (cwd: string | null) => void; | ||
| } | ||
|
|
||
| /** | ||
| * Hook to manage terminal current working directory. | ||
| * | ||
| * Encapsulates: | ||
| * - OSC-7 parsing to extract CWD from terminal output | ||
| * - CWD seeding from initialCwd or workspaceCwd | ||
| * - Debounced store updates to reduce store churn | ||
| * - CWD confirmation tracking (seeded vs OSC-7 confirmed) | ||
| */ | ||
| export function useTerminalCwd({ | ||
| paneId, | ||
| initialCwd, | ||
| workspaceCwd, | ||
| }: UseTerminalCwdOptions): UseTerminalCwdResult { | ||
| const [terminalCwd, setTerminalCwd] = useState<string | null>(null); | ||
| const [cwdConfirmed, setCwdConfirmed] = useState(false); | ||
|
|
||
| const updatePaneCwd = useTabsStore((s) => s.updatePaneCwd); | ||
|
|
||
| // Debounced CWD update to reduce store updates during rapid directory changes | ||
| const debouncedUpdatePaneCwdRef = useRef( | ||
| debounce((id: string, cwd: string | null, confirmed: boolean) => { | ||
| updatePaneCwd(id, cwd, confirmed); | ||
| }, 150), | ||
| ); | ||
|
|
||
| // Parse terminal data for cwd (OSC 7 sequences) | ||
| const updateCwdFromData = useCallback((data: string) => { | ||
| const cwd = parseCwd(data); | ||
| if (cwd !== null) { | ||
| setTerminalCwd(cwd); | ||
| setCwdConfirmed(true); // Confirmed by OSC-7 | ||
| } | ||
| }, []); | ||
|
|
||
| // Ref for use inside effects | ||
| const updateCwdRef = useRef(updateCwdFromData); | ||
| updateCwdRef.current = updateCwdFromData; | ||
|
|
||
| // Seed cwd from initialCwd or workspace path (shell spawns there) | ||
| // OSC-7 will override if/when the shell reports directory changes | ||
| useEffect(() => { | ||
| if (terminalCwd) return; // Already have a cwd, don't override | ||
| const seedCwd = initialCwd || workspaceCwd; | ||
| if (seedCwd) { | ||
| setTerminalCwd(seedCwd); | ||
| setCwdConfirmed(false); // Seeded, not confirmed by OSC-7 | ||
| } | ||
| }, [initialCwd, workspaceCwd, terminalCwd]); | ||
|
|
||
| // Sync terminal cwd to store for DirectoryNavigator (debounced) | ||
| useEffect(() => { | ||
| debouncedUpdatePaneCwdRef.current(paneId, terminalCwd, cwdConfirmed); | ||
| }, [terminalCwd, cwdConfirmed, paneId]); | ||
|
|
||
| // Cleanup debounced function on unmount | ||
| useEffect(() => { | ||
| const debouncedFn = debouncedUpdatePaneCwdRef.current; | ||
| return () => { | ||
| debouncedFn.cancel(); | ||
| }; | ||
| }, []); | ||
|
|
||
| return { | ||
| terminalCwd, | ||
| cwdConfirmed, | ||
| updateCwdFromData, | ||
| updateCwdRef, | ||
| setTerminalCwd, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { toast } from "@superset/ui/sonner"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useCallback, useRef } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { electronTrpc } from "renderer/lib/electron-trpc"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { electronTrpcClient as trpcClient } from "renderer/lib/trpc-client"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useTabsStore } from "renderer/stores/tabs/store"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { normalizeFilePath } from "../normalizeFilePath"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface UseTerminalFileLinksOptions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceId: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Ref to workspace CWD (use ref to avoid terminal recreation) */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceCwdRef: React.RefObject<string | null | undefined>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface UseTerminalFileLinksResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Handler for file link clicks in terminal */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFileLinkClick: (path: string, line?: number, column?: number) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Ref to handleFileLinkClick for use in terminal instance creation */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFileLinkClickRef: React.RefObject< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (path: string, line?: number, column?: number) => void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| >; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's read the file to understand the current implementation
cat -n apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.tsRepository: superset-sh/superset Length of output: 184 🏁 Script executed: # Search for all usages of handleFileLinkClick in the codebase
rg "handleFileLinkClick" --type ts --type tsx -A 2 -B 2Repository: superset-sh/superset Length of output: 91 🏁 Script executed: # Also search for any console logging in this file to check the logging prefix
rg "console\.(error|warn|log)" apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts -A 1 -B 1Repository: superset-sh/superset Length of output: 285 🏁 Script executed: # Read the file directly with cat
cat -n "apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts"Repository: superset-sh/superset Length of output: 4203 🏁 Script executed: # Search for handleFileLinkClick usage more broadly (all file types)
rg "handleFileLinkClick" -A 3 -B 1Repository: superset-sh/superset Length of output: 4853 🏁 Script executed: # Find all files in the Terminal hooks directory
fd . "apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal"Repository: superset-sh/superset Length of output: 5265 Switch file-link handlers to a params object. The callback currently takes positional parameters (path, line, column). Per coding guidelines, functions with 2+ parameters should accept a single params object with named properties. Refactor the interface definitions and implementation, then update the call site in Terminal.tsx. ♻️ Proposed refactor+export interface TerminalFileLinkClickParams {
+ path: string;
+ line?: number;
+ column?: number;
+}
+
export interface UseTerminalFileLinksResult {
/** Handler for file link clicks in terminal */
- handleFileLinkClick: (path: string, line?: number, column?: number) => void;
+ handleFileLinkClick: (params: TerminalFileLinkClickParams) => void;
/** Ref to handleFileLinkClick for use in terminal instance creation */
handleFileLinkClickRef: React.RefObject<
- (path: string, line?: number, column?: number) => void
+ (params: TerminalFileLinkClickParams) => void
>;
}
const handleFileLinkClick = useCallback(
- (path: string, line?: number, column?: number) => {
+ ({ path, line, column }: TerminalFileLinkClickParams) => {Then in Terminal.tsx, update the call site from: -onFileLinkClick: (path, line, column) =>
- handleFileLinkClickRef.current(path, line, column),
+onFileLinkClick: (path, line, column) =>
+ handleFileLinkClickRef.current({ path, line, column }),🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Hook to manage terminal file link handling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Encapsulates: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - Terminal link behavior setting query | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - File path normalization for file viewer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - External editor fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - Toast notifications for errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function useTerminalFileLinks({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceCwdRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: UseTerminalFileLinksOptions): UseTerminalFileLinksResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const addFileViewerPane = useTabsStore((s) => s.addFileViewerPane); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Query terminal link behavior setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data: terminalLinkBehavior } = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| electronTrpc.settings.getTerminalLinkBehavior.useQuery(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleFileLinkClick = useCallback( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (path: string, line?: number, column?: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const behavior = terminalLinkBehavior ?? "external-editor"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const workspaceCwd = workspaceCwdRef.current; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Helper to open in external editor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const openInExternalEditor = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trpcClient.external.openFileInEditor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .mutate({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: workspaceCwd ?? undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "[Terminal] Failed to open file in editor:", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorMessage = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error instanceof Error ? error.message : String(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error("Failed to open file in editor", { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: errorMessage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (behavior === "file-viewer") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If workspaceCwd is not loaded yet, fall back to external editor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!workspaceCwd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "[Terminal] workspaceCwd not loaded, falling back to external editor", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+57
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align console prefixes with The current log prefixes don’t include an operation identifier. Please adjust to the required format. As per coding guidelines, ... 💡 Suggested tweak- console.error(
- "[Terminal] Failed to open file in editor:",
+ console.error(
+ "[terminal/open-file] Failed to open file in editor:",
path,
error,
);
@@
- console.warn(
- "[Terminal] workspaceCwd not loaded, falling back to external editor",
- );
+ console.warn(
+ "[terminal/file-link] workspaceCwd not loaded, falling back to external editor",
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openInExternalEditor(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Normalize path for file viewer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalized = normalizeFilePath(path, workspaceCwd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (normalized.type === "absolute-outside-workspace") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.warning("File is outside the workspace", { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Switch to 'External editor' in Settings to open this file", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filePath = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalized.type === "workspace-root" ? "." : normalized.path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addFileViewerPane(workspaceId, { filePath, line, column }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openInExternalEditor(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [terminalLinkBehavior, workspaceId, workspaceCwdRef, addFileViewerPane], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ref to avoid terminal recreation when callback changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleFileLinkClickRef = useRef(handleFileLinkClick); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFileLinkClickRef.current = handleFileLinkClick; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFileLinkClick, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFileLinkClickRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 91
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 91
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 1030
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 8507
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 596
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 234
🏁 Script executed:
# Check the index.ts file to see how components are exported cat apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/TerminalOverlays/index.tsRepository: superset-sh/superset
Length of output: 160
Split into one component per file.
This file defines three exported components (
KilledOverlay,ConnectionErrorOverlay,RestoredOverlay) in a single.tsxfile, violating the one-component-per-file rule. Each overlay should be in its own file. The internalOverlayContainerhelper can be extracted to a shared utility file or colocated with one of the overlays if used by only that component.Example structure:
🤖 Prompt for AI Agents