dsh-remote-vs 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +50 -16
- package/README.md +40 -15
- package/THIRD-PARTY-NOTICES.md +188 -0
- package/lib/client.js +6512 -77887
- package/lib/index.js +1461 -1024
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +25 -0
- package/lib/types/client/EditorPane.d.ts +16 -5
- package/lib/types/client/FloatingPlaceholder.d.ts +16 -5
- package/lib/types/client/RemoteEditorView.d.ts +13 -10
- package/lib/types/client/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/RemoteRoot.d.ts +5 -5
- package/lib/types/client/TerminalSnippets.d.ts +36 -0
- package/lib/types/client/TerminalView.d.ts +1 -1
- package/lib/types/client/XTerm.d.ts +33 -0
- package/lib/types/client/api.d.ts +37 -2
- package/lib/types/client/changes/review-state.d.ts +19 -0
- package/lib/types/client/connection.d.ts +16 -0
- package/lib/types/client/editor-capability.d.ts +27 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/request-gate.d.ts +110 -0
- package/lib/types/client/scm/DiffView.d.ts +45 -7
- package/lib/types/client/scm/actions.d.ts +31 -3
- package/lib/types/client/store.d.ts +112 -4
- package/lib/types/client/terminal-input.d.ts +23 -0
- package/lib/types/client/terminal-snippets.d.ts +86 -0
- package/lib/types/client/vsc/FindWidget.d.ts +6 -0
- package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
- package/lib/types/client/vsc/change-marks.d.ts +16 -6
- package/lib/types/client/vsc/editor-caret.d.ts +32 -0
- package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
- package/lib/types/client/vsc/editor-langs.d.ts +9 -0
- package/lib/types/client/vsc/editor-settings.d.ts +55 -0
- package/lib/types/client/vsc/image-preview.d.ts +36 -0
- package/lib/types/client/vsc/kit.d.ts +13 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
- package/lib/types/client/vsc/terminal-clipboard.d.ts +15 -0
- package/lib/types/client/vsc/terminal-line.d.ts +25 -0
- package/lib/types/client/vsc/terminal-links.d.ts +62 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +48 -0
- package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
- package/lib/types/forward.d.ts +12 -0
- package/lib/types/fs-ops.d.ts +42 -0
- package/lib/types/http.d.ts +2 -0
- package/lib/types/keygen.d.ts +9 -0
- package/lib/types/monitor.d.ts +8 -0
- package/lib/types/notices.d.ts +16 -1
- package/lib/types/p2/helper-rpc.d.ts +45 -0
- package/lib/types/pool.d.ts +25 -0
- package/lib/types/routes.d.ts +2 -0
- package/lib/types/store.d.ts +7 -0
- package/lib/types/terminal.d.ts +33 -1
- package/lib/types/view-settings.d.ts +5 -0
- package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
- package/package.json +2 -1
- package/src/client/CodeEditor.tsx +205 -10
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +545 -118
- package/src/client/FloatingPlaceholder.tsx +34 -5
- package/src/client/HostsView.tsx +12 -3
- package/src/client/RemoteDirectoryPicker.tsx +12 -0
- package/src/client/RemoteEditorView.tsx +14 -11
- package/src/client/RemoteExplorer.tsx +929 -40
- package/src/client/RemoteRoot.tsx +167 -147
- package/src/client/SearchView.tsx +8 -0
- package/src/client/TerminalSnippets.tsx +432 -0
- package/src/client/TerminalView.tsx +50 -1
- package/src/client/XTerm.tsx +228 -58
- package/src/client/api.ts +106 -13
- package/src/client/auto-open-remote.ts +11 -9
- package/src/client/changes/ChangesDock.tsx +188 -6
- package/src/client/changes/changes.css +10 -3
- package/src/client/changes/review-state.ts +34 -0
- package/src/client/connection.ts +29 -0
- package/src/client/downloads.ts +49 -4
- package/src/client/editor-capability.ts +42 -0
- package/src/client/i18n.ts +228 -12
- package/src/client/index.tsx +22 -6
- package/src/client/request-gate.ts +221 -0
- package/src/client/scm/CommitPane.tsx +20 -2
- package/src/client/scm/DiffView.tsx +343 -117
- package/src/client/scm/HistoryPanel.tsx +23 -2
- package/src/client/scm/RepoPicker.tsx +1 -1
- package/src/client/scm/ScmPanel.tsx +391 -87
- package/src/client/scm/actions.ts +95 -12
- package/src/client/store.tsx +537 -22
- package/src/client/terminal-input.ts +44 -0
- package/src/client/terminal-snippets.ts +216 -0
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- package/src/client/vsc/breadcrumb.tsx +339 -0
- package/src/client/vsc/change-marks.ts +93 -44
- package/src/client/vsc/editor-caret.ts +30 -0
- package/src/client/vsc/editor-keymap.ts +59 -1
- package/src/client/vsc/editor-langs.ts +20 -0
- package/src/client/vsc/editor-settings.ts +146 -0
- package/src/client/vsc/editor-theme.ts +4 -5
- package/src/client/vsc/file-icons.tsx +17 -3
- package/src/client/vsc/image-preview.tsx +110 -0
- package/src/client/vsc/kit.tsx +46 -10
- package/src/client/vsc/save-shortcut.ts +47 -1
- package/src/client/vsc/terminal-clipboard.ts +19 -0
- package/src/client/vsc/terminal-line.ts +101 -0
- package/src/client/vsc/terminal-links.ts +166 -0
- package/src/client/vsc/terminal-theme.ts +97 -0
- package/src/client/vsc/terminal-writer.ts +112 -0
- package/src/client/vsc/vsc.css +1078 -181
- package/src/forward.ts +47 -9
- package/src/fs-ops.ts +124 -4
- package/src/git-ops.ts +20 -3
- package/src/http.ts +35 -4
- package/src/keygen.ts +55 -4
- package/src/monitor.ts +13 -0
- package/src/notices.ts +23 -1
- package/src/p2/helper-rpc.ts +113 -7
- package/src/p2/worlds.ts +14 -1
- package/src/pool.ts +99 -27
- package/src/routes.ts +212 -43
- package/src/sftp.ts +51 -14
- package/src/store.ts +10 -0
- package/src/terminal.ts +225 -24
- package/src/view-settings.ts +50 -10
- package/lib/types/client/Dialog.d.ts +0 -14
- package/src/client/Dialog.tsx +0 -76
package/src/client/store.tsx
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* Remote work stays lazy: a directory is listed once per expansion, a diff
|
|
13
13
|
* loads both revisions on demand, and git status is one NUL-separated call.
|
|
14
14
|
*/
|
|
15
|
-
import { useEffect, useSyncExternalStore } from 'react'
|
|
15
|
+
import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react'
|
|
16
16
|
import type { Context } from '@deepseek-ai/cordis'
|
|
17
17
|
import type {
|
|
18
18
|
DiffModel,
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
RemoteHostSummary,
|
|
21
21
|
RemoteRoutingStatus,
|
|
22
22
|
RemoteWorkspaceBinding,
|
|
23
|
+
RemoteFileEntry,
|
|
23
24
|
} from '../protocol.ts'
|
|
24
25
|
import { api, RemoteApiError, configureTimeouts, fileReadTimeoutMs, gitTimeoutMs } from './api.ts'
|
|
25
26
|
import { DEFAULT_GIT_TIMEOUT_MS, clientDeadlineFor } from '../timeouts.ts'
|
|
@@ -47,10 +48,18 @@ import {
|
|
|
47
48
|
import { detectLang, makeT, type Lang } from './i18n.ts'
|
|
48
49
|
import { effectiveEditorSurface, type EditorSurface } from './float-editor.ts'
|
|
49
50
|
import { captureLiveEditorPosition, captureLiveEditorText, isLiveEditorDirty, isLiveEditorFor, markLiveEditorSaved } from './live-editor.ts'
|
|
51
|
+
import { editorSeatCount } from './editor-capability.ts'
|
|
50
52
|
import { planWorkspaceFollow, selectionIsSessionBinding, type WorkspaceFollowDecision } from './remote-file-open-target.ts'
|
|
51
53
|
import { revealViewTab } from './reveal.ts'
|
|
52
|
-
import { connectionStateOf, isConnectionFailure } from './connection.ts'
|
|
54
|
+
import { applyConnectionStatuses, connectionStateOf, isConnectionFailure, markConnectionProbeOk } from './connection.ts'
|
|
55
|
+
import { isRequestAbort } from './request-gate.ts'
|
|
53
56
|
import { confirmDialog, isHtmlFile, isImageFile, isMarkdownFile, toast } from './vsc/kit.tsx'
|
|
57
|
+
import {
|
|
58
|
+
isWithinRoot,
|
|
59
|
+
normalizeRemotePath,
|
|
60
|
+
parentDirectoryOf,
|
|
61
|
+
resolutionCandidates,
|
|
62
|
+
} from './vsc/terminal-links.ts'
|
|
54
63
|
|
|
55
64
|
/** One editor tab (code file, preview or diff). */
|
|
56
65
|
export interface EditorTab {
|
|
@@ -632,6 +641,17 @@ export interface ExplorerValue {
|
|
|
632
641
|
openFloatingEditor: () => void
|
|
633
642
|
/** 停靠回主界面(底层的中心视图或侧栏表面)。 */
|
|
634
643
|
dockFloatingEditor: () => void
|
|
644
|
+
/**
|
|
645
|
+
* Show the SAME editor in the conversation-view tab (full width).
|
|
646
|
+
*
|
|
647
|
+
* The docked sidebar pane is the default seat; the centre tab is an optional
|
|
648
|
+
* second seat for the same buffer. Flipping the surface unmounts one mount and
|
|
649
|
+
* mounts the other, so the live buffer is captured first (see
|
|
650
|
+
* `captureLiveBuffer`).
|
|
651
|
+
*/
|
|
652
|
+
openEditorInCenter: () => void
|
|
653
|
+
/** Dock the editor back into the sidebar (the reverse of `openEditorInCenter`). */
|
|
654
|
+
dockEditorSidebar: () => void
|
|
635
655
|
openDiff: (rel: string, staged: boolean, untracked?: boolean) => void
|
|
636
656
|
openCommitFile: (hash: string, rel: string, origPath?: string) => void
|
|
637
657
|
activateTab: (id: string) => void
|
|
@@ -768,6 +788,8 @@ function build(): ExplorerValue {
|
|
|
768
788
|
openDiffInFloatEditor,
|
|
769
789
|
openFloatingEditor,
|
|
770
790
|
dockFloatingEditor,
|
|
791
|
+
openEditorInCenter,
|
|
792
|
+
dockEditorSidebar,
|
|
771
793
|
openDiff,
|
|
772
794
|
openCommitFile,
|
|
773
795
|
activateTab,
|
|
@@ -813,6 +835,128 @@ export function useExplorer(): ExplorerValue {
|
|
|
813
835
|
)
|
|
814
836
|
}
|
|
815
837
|
|
|
838
|
+
/**
|
|
839
|
+
* The store's subscription, extracted so `useExplorerSelector` passes React a
|
|
840
|
+
* STABLE function: a fresh arrow per render makes `useSyncExternalStore`
|
|
841
|
+
* unsubscribe/resubscribe on every paint.
|
|
842
|
+
*/
|
|
843
|
+
function subscribeStore(listener: () => void): () => void {
|
|
844
|
+
listeners.add(listener)
|
|
845
|
+
return () => {
|
|
846
|
+
listeners.delete(listener)
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Shallow equality for selector results — one level deep, `Object.is` per field.
|
|
852
|
+
*
|
|
853
|
+
* Selectors naturally build a fresh `{ repoRoot, head, … }` object out of the
|
|
854
|
+
* snapshot, and a plain `Object.is` would then see a new reference on every
|
|
855
|
+
* publish and repaint the panel anyway (defeating the whole point). Passing this
|
|
856
|
+
* as `equal` compares the FIELDS, so "the snapshot was rebuilt but none of the
|
|
857
|
+
* fields I read changed" answers `true` and the previous value (and render) is
|
|
858
|
+
* kept. Arrays are compared as objects, i.e. by index.
|
|
859
|
+
*
|
|
860
|
+
* Shallow is deliberate: every selected field is either a primitive or a
|
|
861
|
+
* REFERENCE the store already owns (`status`, `buckets`, `tabs`, `untrackedDirs`
|
|
862
|
+
* …). Comparing those by reference is a real value check — the store only
|
|
863
|
+
* replaces them when they actually change.
|
|
864
|
+
*/
|
|
865
|
+
export function shallowEqual(a: unknown, b: unknown): boolean {
|
|
866
|
+
if (Object.is(a, b)) return true
|
|
867
|
+
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false
|
|
868
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false
|
|
869
|
+
const left = a as Record<string, unknown>
|
|
870
|
+
const right = b as Record<string, unknown>
|
|
871
|
+
const keys = Object.keys(left)
|
|
872
|
+
if (keys.length !== Object.keys(right).length) return false
|
|
873
|
+
for (const key of keys) {
|
|
874
|
+
// `hasOwnProperty` first: `Object.is(undefined, undefined)` must still pass
|
|
875
|
+
// only for a field that EXISTS on both sides (a shorter object is a change).
|
|
876
|
+
if (!Object.prototype.hasOwnProperty.call(right, key)) return false
|
|
877
|
+
if (!Object.is(left[key], right[key])) return false
|
|
878
|
+
}
|
|
879
|
+
return true
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Subscribe to ONE slice of the explorer store.
|
|
884
|
+
*
|
|
885
|
+
* Why this exists: `useExplorer()` hands out the whole `ExplorerValue`, and
|
|
886
|
+
* every `publish()` builds a NEW snapshot object — so every subscriber repaints
|
|
887
|
+
* on every mutation, including mutations its panel does not read (a save bumps
|
|
888
|
+
* the tab array, a git refresh replaces `status`, a rail switch changes `view`).
|
|
889
|
+
* With the panels kept MOUNTED, one publish therefore repainted every panel,
|
|
890
|
+
* and the SCM panel's change list (up to 4000 rows) was rebuilt for a change in
|
|
891
|
+
* an unrelated field.
|
|
892
|
+
*
|
|
893
|
+
* This hook re-renders its component ONLY when the selected value changes:
|
|
894
|
+
* - `publish()` still notifies every listener (that is how the store stays a
|
|
895
|
+
* single source of truth), but React asks this hook for a fresh value and
|
|
896
|
+
* `Object.is`-compares it with the last rendered one; equal means no render;
|
|
897
|
+
* - the selector runs at most once per (snapshot, selector) pair, and its
|
|
898
|
+
* result is kept in a per-hook cache, so an equal result keeps the PREVIOUS
|
|
899
|
+
* reference (downstream `useMemo`s keyed on it stay valid).
|
|
900
|
+
*
|
|
901
|
+
* Constraints, all from `useSyncExternalStore`:
|
|
902
|
+
* - the value returned for an UNCHANGED snapshot must be stable. This hook
|
|
903
|
+
* guarantees it (cache keyed on the snapshot identity), which is also why a
|
|
904
|
+
* selector may safely return a fresh object — with `shallowEqual` it is
|
|
905
|
+
* compared and the old reference is kept, and without `equal` it is cached
|
|
906
|
+
* and only recomputed when the snapshot itself changes;
|
|
907
|
+
* - `selector` must be PURE and should read only the snapshot. It may be an
|
|
908
|
+
* inline arrow (the hook tracks its identity, so a selector that closes over
|
|
909
|
+
* props is recomputed when it changes), but a module-level selector is
|
|
910
|
+
* cheaper: its identity is stable, so between publishes the cache answers
|
|
911
|
+
* without running it at all;
|
|
912
|
+
* - `selector` must not mutate the snapshot.
|
|
913
|
+
*
|
|
914
|
+
* @param selector - pure read of the fields this component needs.
|
|
915
|
+
* @param equal - comparison used to decide whether the new selection is the
|
|
916
|
+
* same value; defaults to `Object.is`. Pass `shallowEqual` for object slices.
|
|
917
|
+
*/
|
|
918
|
+
export function useExplorerSelector<T>(
|
|
919
|
+
selector: (snapshot: ExplorerValue) => T,
|
|
920
|
+
equal: (a: T, b: T) => boolean = Object.is,
|
|
921
|
+
): T {
|
|
922
|
+
/**
|
|
923
|
+
* Last (snapshot, selector) → value. A `useRef`, not module state: two
|
|
924
|
+
* components selecting different fields must not evict each other.
|
|
925
|
+
*/
|
|
926
|
+
const cache = useRef<{ source: ExplorerValue; selector: (snapshot: ExplorerValue) => T; value: T } | undefined>(undefined)
|
|
927
|
+
/**
|
|
928
|
+
* Latest selector/equal, kept in refs so `getSelection` can stay stable
|
|
929
|
+
* (one `useCallback([])`) while still calling the CURRENT functions. A
|
|
930
|
+
* selector that closes over props changes identity every render; comparing it
|
|
931
|
+
* with the cached one is what makes such a selector recompute (and see the new
|
|
932
|
+
* props) instead of returning the previous, now stale, value.
|
|
933
|
+
*/
|
|
934
|
+
const selectorRef = useRef(selector)
|
|
935
|
+
selectorRef.current = selector
|
|
936
|
+
const equalRef = useRef(equal)
|
|
937
|
+
equalRef.current = equal
|
|
938
|
+
const getSelection = useCallback((): T => {
|
|
939
|
+
const source = snapshot
|
|
940
|
+
const current = cache.current
|
|
941
|
+
if (current !== undefined && current.source === source && current.selector === selectorRef.current) {
|
|
942
|
+
// Same snapshot, same selector: the cached value is the answer. This is
|
|
943
|
+
// what `useSyncExternalStore` requires (a changing value here would loop),
|
|
944
|
+
// and what keeps two consecutive reads of one snapshot identical.
|
|
945
|
+
return current.value
|
|
946
|
+
}
|
|
947
|
+
const next = selectorRef.current(source)
|
|
948
|
+
if (current !== undefined && equalRef.current(current.value, next)) {
|
|
949
|
+
// The snapshot moved but this slice did not: keep the OLD reference so
|
|
950
|
+
// React sees no change (no render) and downstream memo keys stay stable.
|
|
951
|
+
cache.current = { source, selector: selectorRef.current, value: current.value }
|
|
952
|
+
return current.value
|
|
953
|
+
}
|
|
954
|
+
cache.current = { source, selector: selectorRef.current, value: next }
|
|
955
|
+
return next
|
|
956
|
+
}, [])
|
|
957
|
+
return useSyncExternalStore(subscribeStore, getSelection)
|
|
958
|
+
}
|
|
959
|
+
|
|
816
960
|
/** The repo-relative path of an absolute remote path ('' when outside). */
|
|
817
961
|
export function repoRelative(repoRoot: string | undefined, fullPath: string): string {
|
|
818
962
|
if (repoRoot === undefined) return ''
|
|
@@ -866,6 +1010,23 @@ const gitReads = new ReadQueue(refreshGitBusy)
|
|
|
866
1010
|
const latestGitRead = new Map<string, number>()
|
|
867
1011
|
let gitReadTicket = 0
|
|
868
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* Cancellation handle for the git read in flight per binding.
|
|
1015
|
+
*
|
|
1016
|
+
* A workspace switch must take the OLD workspace's repository walk out of the
|
|
1017
|
+
* browser's connection pool. The browser gives one origin six connections and
|
|
1018
|
+
* the walk (probe + status + branch header) is the largest thing the plugin
|
|
1019
|
+
* sends; measured on the reported P710/Z700 trees, the walk took 8–9 s and a
|
|
1020
|
+
* purely in-memory `/status` route took 2.7–4.6 s during it — that is queueing,
|
|
1021
|
+
* not a slow host. Aborting the HTTP request frees the connection immediately;
|
|
1022
|
+
* the answer of an aborted read is dropped on purpose (a newer read of that
|
|
1023
|
+
* binding, or of the workspace now on screen, is the one that matters).
|
|
1024
|
+
*
|
|
1025
|
+
* One controller per binding, so a repo-picker move (same binding, another
|
|
1026
|
+
* directory) also retires the read it supersedes.
|
|
1027
|
+
*/
|
|
1028
|
+
const gitReadAborts = new Map<string, AbortController>()
|
|
1029
|
+
|
|
869
1030
|
/** True when `bindingId`'s read `ticket` may paint the on-screen slice. */
|
|
870
1031
|
function gitReadIsCurrent(bindingId: string, ticket: number): boolean {
|
|
871
1032
|
return latestGitRead.get(bindingId) === ticket && activeBinding().key === bindingId
|
|
@@ -1176,6 +1337,76 @@ export function revealInExplorer(dir: string): void {
|
|
|
1176
1337
|
setView('explorer')
|
|
1177
1338
|
}
|
|
1178
1339
|
|
|
1340
|
+
/** Outcome of one terminal path click (see `jumpToTerminalPath`). */
|
|
1341
|
+
export type TerminalPathJump = 'revealed' | 'missing' | 'outside' | 'blocked'
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Jump from a path printed in the TERMINAL to that folder in the directory tree
|
|
1345
|
+
* (Ctrl+Click in the terminal; the wiring lives in `XTerm`/`TerminalView`).
|
|
1346
|
+
*
|
|
1347
|
+
* The token is only text, so the absolute path is decided by a short candidate
|
|
1348
|
+
* chain (`vsc/terminal-links.ts`) and then CONFIRMED against the host: the first
|
|
1349
|
+
* candidate that exists wins, and its directory (the path itself for a folder,
|
|
1350
|
+
* its parent for a file) is revealed in the tree. A hit outside every binding on
|
|
1351
|
+
* that host is reported instead of silently jumping somewhere unrelated — the
|
|
1352
|
+
* tree can only show what a binding covers.
|
|
1353
|
+
*
|
|
1354
|
+
* @param alias - host the terminal TAB is connected to (not the panel's host
|
|
1355
|
+
* picker: a tab can outlive a picker change).
|
|
1356
|
+
* @param token - the path as printed in the terminal.
|
|
1357
|
+
* @param hints - shell cwd (OSC 7) and remote home, for relative/`~` tokens.
|
|
1358
|
+
*/
|
|
1359
|
+
export async function jumpToTerminalPath(
|
|
1360
|
+
alias: string,
|
|
1361
|
+
token: string,
|
|
1362
|
+
hints: { home?: string; cwd?: string } = {},
|
|
1363
|
+
): Promise<TerminalPathJump> {
|
|
1364
|
+
if (alias === '' || token === '') return 'missing'
|
|
1365
|
+
const bindings = state.workspaces.filter(item => item.alias === alias)
|
|
1366
|
+
const roots = bindings
|
|
1367
|
+
.map(item => item.remotePath)
|
|
1368
|
+
.sort((left, right) => right.length - left.length)
|
|
1369
|
+
const candidates = resolutionCandidates(token, {
|
|
1370
|
+
...(hints.home === undefined ? {} : { home: hints.home }),
|
|
1371
|
+
...(hints.cwd === undefined ? {} : { cwd: hints.cwd }),
|
|
1372
|
+
roots,
|
|
1373
|
+
})
|
|
1374
|
+
if (candidates.length === 0) {
|
|
1375
|
+
toast(t('term.pathOutside'), true)
|
|
1376
|
+
return 'outside'
|
|
1377
|
+
}
|
|
1378
|
+
for (const candidate of candidates) {
|
|
1379
|
+
let entry: RemoteFileEntry
|
|
1380
|
+
try {
|
|
1381
|
+
// Bounded: a dead link must not leave the click hanging with no answer.
|
|
1382
|
+
entry = await withDeadline(
|
|
1383
|
+
api.fileOp.stat(alias, candidate),
|
|
1384
|
+
clientDeadlineFor(fileReadTimeoutMs()),
|
|
1385
|
+
t('editor.readTimeout'),
|
|
1386
|
+
)
|
|
1387
|
+
} catch {
|
|
1388
|
+
// Not this candidate (or the link hiccuped): try the next one.
|
|
1389
|
+
continue
|
|
1390
|
+
}
|
|
1391
|
+
const dir = entry.isDir ? normalizeRemotePath(candidate) : parentDirectoryOf(candidate)
|
|
1392
|
+
const binding = bindings.find(item => isWithinRoot(dir, item.remotePath))
|
|
1393
|
+
if (binding === undefined) {
|
|
1394
|
+
// The path exists but no workspace covers it: the tree has nowhere to show
|
|
1395
|
+
// it, and moving the panel somewhere unrelated would be a lie.
|
|
1396
|
+
toast(t('term.pathOutside'), true)
|
|
1397
|
+
return 'outside'
|
|
1398
|
+
}
|
|
1399
|
+
if (state.workspaceId !== binding.id && !selectWorkspaceAuto(binding.id)) {
|
|
1400
|
+
toast(t('term.pathBlocked'), true)
|
|
1401
|
+
return 'blocked'
|
|
1402
|
+
}
|
|
1403
|
+
revealInExplorer(dir)
|
|
1404
|
+
return 'revealed'
|
|
1405
|
+
}
|
|
1406
|
+
toast(t('term.pathMissing'), true)
|
|
1407
|
+
return 'missing'
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1179
1410
|
/** Monotonic ticket for "open a terminal here" requests. */
|
|
1180
1411
|
let terminalSeq = 0
|
|
1181
1412
|
|
|
@@ -1309,10 +1540,77 @@ function confirmDiscardOnWorkspaceSwitch(dirty: readonly EditorTab[]): Promise<b
|
|
|
1309
1540
|
})
|
|
1310
1541
|
}
|
|
1311
1542
|
|
|
1543
|
+
/**
|
|
1544
|
+
* The in-flight switch probe, so a newer switch cancels an older dial.
|
|
1545
|
+
*
|
|
1546
|
+
* A test dial is a real SSH connection attempt: against a host that is down it
|
|
1547
|
+
* runs for the connection timeout (tens of seconds), and it is a FOREGROUND
|
|
1548
|
+
* request (the tree is waiting on its answer), so it would hold the background
|
|
1549
|
+
* git channel shut behind it. Switching again makes that dial pointless, hence
|
|
1550
|
+
* the abort.
|
|
1551
|
+
*/
|
|
1552
|
+
let switchProbe: { alias: string; controller: AbortController } | undefined
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Re-prove one alias' link when the user selects a workspace on it.
|
|
1556
|
+
*
|
|
1557
|
+
* The connection chip polls (and an explicit retry is exactly this pair of
|
|
1558
|
+
* calls), but the tree gates on the same evidence: `loadDir`/`prefetchDir`
|
|
1559
|
+
* refuse an alias known down. A switch made inside the poll interval therefore
|
|
1560
|
+
* used to leave the tree empty until the next tick — the user had to retry by
|
|
1561
|
+
* hand. One dial here answers the question the switch just raised; a failed
|
|
1562
|
+
* probe changes nothing (the chip owns the failure, and the alias stays down).
|
|
1563
|
+
*/
|
|
1564
|
+
function probeConnectionOnSwitch(alias: string): void {
|
|
1565
|
+
if (alias === '') return
|
|
1566
|
+
switchProbe?.controller.abort()
|
|
1567
|
+
const controller = new AbortController()
|
|
1568
|
+
switchProbe = { alias, controller }
|
|
1569
|
+
void (async () => {
|
|
1570
|
+
try {
|
|
1571
|
+
// Background on purpose: a dead host's dial runs for the connection
|
|
1572
|
+
// timeout (45 s + guard). As a FOREGROUND request it would hold the
|
|
1573
|
+
// foreground counter up for that whole window and starve every background
|
|
1574
|
+
// git read; as a background one it only contends with the git channel,
|
|
1575
|
+
// while the tree keeps showing its cached/empty state.
|
|
1576
|
+
const answer = await api.testHost(alias, { background: true, signal: controller.signal })
|
|
1577
|
+
if (controller.signal.aborted || !answer.ok) return
|
|
1578
|
+
// The same two steps as the chip's retry: record the success (so a stale
|
|
1579
|
+
// poll cannot paint it red again) and refresh the pooled status.
|
|
1580
|
+
markConnectionProbeOk(alias)
|
|
1581
|
+
const statuses = await api.connectionStatus()
|
|
1582
|
+
if (controller.signal.aborted) return
|
|
1583
|
+
applyConnectionStatuses(statuses)
|
|
1584
|
+
} catch {
|
|
1585
|
+
// A failed probe is not news: the alias keeps the state the chip shows.
|
|
1586
|
+
} finally {
|
|
1587
|
+
if (switchProbe?.controller === controller) switchProbe = undefined
|
|
1588
|
+
}
|
|
1589
|
+
})()
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1312
1592
|
/** Move the selection; `byUser` decides whether it is remembered as a choice. */
|
|
1313
1593
|
function applyWorkspaceSelection(id: string, byUser: boolean): void {
|
|
1314
1594
|
if (state.workspaceId === id) return
|
|
1315
1595
|
if (byUser) noteManualPick()
|
|
1596
|
+
const target = state.workspaces.find(item => item.id === id)
|
|
1597
|
+
// A connection probe started for the workspace being left is a real SSH dial
|
|
1598
|
+
// (up to the connection timeout on a dead host) and it is a FOREGROUND
|
|
1599
|
+
// request: left running, it would keep the background git channel of the NEW
|
|
1600
|
+
// workspace shut. Cancel it whether or not the new alias needs its own probe.
|
|
1601
|
+
if (switchProbe !== undefined && switchProbe.alias !== target?.alias) {
|
|
1602
|
+
switchProbe.controller.abort()
|
|
1603
|
+
switchProbe = undefined
|
|
1604
|
+
}
|
|
1605
|
+
// The workspace being left may have a full `git status` walk in flight. It is
|
|
1606
|
+
// no longer what the screen shows, and its connections are exactly what the
|
|
1607
|
+
// new workspace's directory list needs — cancel it here (the read drops its
|
|
1608
|
+
// answer; the cache it may already have written stays).
|
|
1609
|
+
for (const [readId, controller] of [...gitReadAborts]) {
|
|
1610
|
+
if (readId === id) continue
|
|
1611
|
+
controller.abort()
|
|
1612
|
+
gitReadAborts.delete(readId)
|
|
1613
|
+
}
|
|
1316
1614
|
// Local stage results are repository-relative: another binding's paths must
|
|
1317
1615
|
// never be re-applied to this one. The expanded untracked directories are
|
|
1318
1616
|
// repository-relative too.
|
|
@@ -1339,6 +1637,9 @@ function applyWorkspaceSelection(id: string, byUser: boolean): void {
|
|
|
1339
1637
|
// flag must reflect that before anything is published again.
|
|
1340
1638
|
refreshGitBusy()
|
|
1341
1639
|
if (stale) void refreshGit('join')
|
|
1640
|
+
// Selected onto an alias whose last known state was `error`: ask once, so the
|
|
1641
|
+
// tree is not gated offline by evidence from before the switch.
|
|
1642
|
+
if (target !== undefined && connectionStateOf(target.alias) === 'error') probeConnectionOnSwitch(target.alias)
|
|
1342
1643
|
}
|
|
1343
1644
|
|
|
1344
1645
|
let searchSeq = 0
|
|
@@ -1388,6 +1689,9 @@ let manualPickSession: string | undefined
|
|
|
1388
1689
|
*/
|
|
1389
1690
|
function noteManualPick(): void {
|
|
1390
1691
|
if (followSessionId !== undefined) manualPickSession = followSessionId
|
|
1692
|
+
// An explicit choice settles the follow for good: no fast retry may move the
|
|
1693
|
+
// selection out from under it afterwards.
|
|
1694
|
+
clearFollowRetry()
|
|
1391
1695
|
}
|
|
1392
1696
|
|
|
1393
1697
|
/**
|
|
@@ -1415,11 +1719,118 @@ export function setFollowSession(sessionId: string | undefined): void {
|
|
|
1415
1719
|
// A new seat re-follows: the previous session's manual pick was about that
|
|
1416
1720
|
// session's workspace, not this one's.
|
|
1417
1721
|
manualPickSession = undefined
|
|
1722
|
+
// …and its pending retry was about the previous session too.
|
|
1723
|
+
clearFollowRetry()
|
|
1724
|
+
// A different seat gets its own fast-retry budget.
|
|
1725
|
+
followFastRetrySpent = undefined
|
|
1418
1726
|
}
|
|
1419
1727
|
|
|
1420
1728
|
/** One resolution in flight, so the same session is never probed twice at once. */
|
|
1421
1729
|
let followFlight: { sessionId: string; promise: Promise<string | undefined> } | undefined
|
|
1422
1730
|
|
|
1731
|
+
/**
|
|
1732
|
+
* Fast retries for a session whose workspace has not resolved yet.
|
|
1733
|
+
*
|
|
1734
|
+
* Opening a conversation right after a page load (or before the change panel's
|
|
1735
|
+
* first scan) used to leave the selector on the previous workspace until the
|
|
1736
|
+
* panel's slow fallback came around: the workspace visibly switched by itself a
|
|
1737
|
+
* quarter of a minute later, which reads as a slow/glitchy app. Three quick
|
|
1738
|
+
* attempts cover that window; the SLOW fallback stays in the panel, so this is a
|
|
1739
|
+
* latency fix, not a second poll. Only an UNRESOLVED follow retries: an answer
|
|
1740
|
+
* that landed, a manual pick and a session change all stop the chain.
|
|
1741
|
+
*
|
|
1742
|
+
* Module-level state for the same reason the follow itself is: it must outlive
|
|
1743
|
+
* any one surface's render, and there is exactly one follow per page.
|
|
1744
|
+
*/
|
|
1745
|
+
const FOLLOW_FAST_RETRY_MS = [300, 1_000, 3_000] as const
|
|
1746
|
+
|
|
1747
|
+
/** The pending fast-retry chain (one session at a time). */
|
|
1748
|
+
let followRetry: { sessionId: string; attempt: number; timer: ReturnType<typeof setTimeout> } | undefined
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* Session whose fast-retry budget has been spent.
|
|
1752
|
+
*
|
|
1753
|
+
* The slow panel tick keeps calling the follow every 15 s; without this, each
|
|
1754
|
+
* unresolved answer would arm a NEW three-attempt chain and a session with no
|
|
1755
|
+
* resolvable workspace would cost four cwd probes per tick instead of one.
|
|
1756
|
+
* Cleared when the session changes (a new seat gets its own budget).
|
|
1757
|
+
*/
|
|
1758
|
+
let followFastRetrySpent: string | undefined
|
|
1759
|
+
|
|
1760
|
+
/** > 0 while a retry-driven `followSessionWorkspace` call is in flight. */
|
|
1761
|
+
let followRetryDrive = 0
|
|
1762
|
+
|
|
1763
|
+
/** Drop the pending retry (a resolution landed, the session changed, or the user picked). */
|
|
1764
|
+
function clearFollowRetry(): void {
|
|
1765
|
+
if (followRetry === undefined) return
|
|
1766
|
+
clearTimeout(followRetry.timer)
|
|
1767
|
+
followRetry = undefined
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
/** Is the retry chain still about the session on screen, and still wanted? */
|
|
1771
|
+
function followRetryWanted(sessionId: string): boolean {
|
|
1772
|
+
return followSessionId === sessionId
|
|
1773
|
+
&& followedSession !== sessionId
|
|
1774
|
+
&& manualPickSession !== sessionId
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Arm one attempt of the chain.
|
|
1779
|
+
*
|
|
1780
|
+
* The timer calls the follow again; a resolution that still has not landed
|
|
1781
|
+
* schedules the next attempt, and the chain stops after
|
|
1782
|
+
* {@link FOLLOW_FAST_RETRY_MS}'s last entry. "Still not landed" includes a cwd
|
|
1783
|
+
* probe that failed (resolved as "nothing resolved", not thrown); only a
|
|
1784
|
+
* rejection of the whole follow call — a bug, not a host answer — stops the
|
|
1785
|
+
* chain outright.
|
|
1786
|
+
*/
|
|
1787
|
+
function startFollowRetry(sessionId: string, attempt: number): void {
|
|
1788
|
+
clearFollowRetry()
|
|
1789
|
+
if (!followRetryWanted(sessionId)) return
|
|
1790
|
+
if (attempt >= FOLLOW_FAST_RETRY_MS.length) {
|
|
1791
|
+
followFastRetrySpent = sessionId
|
|
1792
|
+
return
|
|
1793
|
+
}
|
|
1794
|
+
const timer = setTimeout(() => {
|
|
1795
|
+
followRetry = undefined
|
|
1796
|
+
if (!followRetryWanted(sessionId)) return
|
|
1797
|
+
followRetryDrive += 1
|
|
1798
|
+
void followSessionWorkspace({}).then(
|
|
1799
|
+
(resolved) => {
|
|
1800
|
+
followRetryDrive -= 1
|
|
1801
|
+
if (resolved !== undefined || !followRetryWanted(sessionId)) {
|
|
1802
|
+
clearFollowRetry()
|
|
1803
|
+
return
|
|
1804
|
+
}
|
|
1805
|
+
startFollowRetry(sessionId, attempt + 1)
|
|
1806
|
+
},
|
|
1807
|
+
() => {
|
|
1808
|
+
followRetryDrive -= 1
|
|
1809
|
+
clearFollowRetry()
|
|
1810
|
+
},
|
|
1811
|
+
)
|
|
1812
|
+
}, FOLLOW_FAST_RETRY_MS[attempt] as number)
|
|
1813
|
+
// Never keep a Node gate (or a closing page) alive just for a retry.
|
|
1814
|
+
timer.unref?.()
|
|
1815
|
+
followRetry = { sessionId, attempt, timer }
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* Note that one resolution came back unresolved and arm the fast retry.
|
|
1820
|
+
*
|
|
1821
|
+
* A no-op while the chain already runs for this session (the chain owns its next
|
|
1822
|
+
* attempt — scheduling from here would restart the delays) and while a
|
|
1823
|
+
* retry-driven call is in flight. A chain belonging to ANOTHER session is stale
|
|
1824
|
+
* and is replaced.
|
|
1825
|
+
*/
|
|
1826
|
+
function noteFollowUnresolved(sessionId: string): void {
|
|
1827
|
+
// The fast budget is once per session: the slow tick must not refill it.
|
|
1828
|
+
if (followFastRetrySpent === sessionId) return
|
|
1829
|
+
if (followRetry !== undefined && followRetry.sessionId !== sessionId) clearFollowRetry()
|
|
1830
|
+
if (followRetryDrive > 0 || followRetry !== undefined) return
|
|
1831
|
+
startFollowRetry(sessionId, 0)
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1423
1834
|
/**
|
|
1424
1835
|
* Point the workspace selector (and with it the tree, the editor's dropdown and
|
|
1425
1836
|
* the git panel) at the binding the registered session works in.
|
|
@@ -1478,8 +1889,14 @@ export function followSessionWorkspace(options: {
|
|
|
1478
1889
|
// re-deciding what was already decided. A manual pick made BEFORE anything
|
|
1479
1890
|
// resolved (see `manualPickSession`) is the same promise, kept even though
|
|
1480
1891
|
// there is no follow to remember.
|
|
1481
|
-
if (followedSession === sessionId)
|
|
1482
|
-
|
|
1892
|
+
if (followedSession === sessionId) {
|
|
1893
|
+
clearFollowRetry()
|
|
1894
|
+
return Promise.resolve(followedBindingId)
|
|
1895
|
+
}
|
|
1896
|
+
if (manualPickSession === sessionId) {
|
|
1897
|
+
clearFollowRetry()
|
|
1898
|
+
return Promise.resolve(undefined)
|
|
1899
|
+
}
|
|
1483
1900
|
const inFlight = followFlight
|
|
1484
1901
|
if (inFlight !== undefined && inFlight.sessionId === sessionId) return inFlight.promise
|
|
1485
1902
|
const promise = resolveSessionWorkspace(sessionId, options).finally(() => {
|
|
@@ -1520,6 +1937,9 @@ async function resolveSessionWorkspace(
|
|
|
1520
1937
|
cwd = answer.cwd
|
|
1521
1938
|
} catch {
|
|
1522
1939
|
// A failed probe resolves nothing: the selection stands, nothing is sent.
|
|
1940
|
+
// Still unresolved, so the fast retry gets its chance (the panel's slow
|
|
1941
|
+
// fallback would otherwise be the only way out).
|
|
1942
|
+
noteFollowUnresolved(sessionId)
|
|
1523
1943
|
return undefined
|
|
1524
1944
|
}
|
|
1525
1945
|
// The session may have changed while the host was answering; its evidence
|
|
@@ -1527,12 +1947,23 @@ async function resolveSessionWorkspace(
|
|
|
1527
1947
|
if (followSessionId !== sessionId) return undefined
|
|
1528
1948
|
if (cwd !== undefined && cwd !== '') decision = plan(cwd)
|
|
1529
1949
|
}
|
|
1530
|
-
if (decision.action === 'keep')
|
|
1950
|
+
if (decision.action === 'keep') {
|
|
1951
|
+
// Nothing resolved (the host knows no usable cwd for this session, or the
|
|
1952
|
+
// evidence names no binding): arm the fast retry instead of waiting for the
|
|
1953
|
+
// panel's slow one.
|
|
1954
|
+
noteFollowUnresolved(sessionId)
|
|
1955
|
+
return undefined
|
|
1956
|
+
}
|
|
1531
1957
|
// The user may have chosen a workspace WHILE this resolution was in flight:
|
|
1532
1958
|
// a choice beats a late answer.
|
|
1533
|
-
if (followSessionId !== sessionId || manualPickSession === sessionId)
|
|
1959
|
+
if (followSessionId !== sessionId || manualPickSession === sessionId) {
|
|
1960
|
+
clearFollowRetry()
|
|
1961
|
+
return undefined
|
|
1962
|
+
}
|
|
1534
1963
|
followedSession = decision.followedSession
|
|
1535
1964
|
followedBindingId = decision.bindingId
|
|
1965
|
+
// An answer landed: the chain has nothing left to do.
|
|
1966
|
+
clearFollowRetry()
|
|
1536
1967
|
if (state.workspaceId !== decision.bindingId) selectWorkspaceAuto(decision.bindingId)
|
|
1537
1968
|
return decision.bindingId
|
|
1538
1969
|
}
|
|
@@ -1676,6 +2107,9 @@ export async function refreshGit(mode: 'join' | 'fresh' = 'fresh'): Promise<void
|
|
|
1676
2107
|
try {
|
|
1677
2108
|
await gitReads.run(cacheKey, () => readGit(key, subdir, cacheKey), mode, settleMs)
|
|
1678
2109
|
} catch (error) {
|
|
2110
|
+
// A cancelled read (a workspace switch retired it) is not a failure: the
|
|
2111
|
+
// selection moved on and there is nothing to report for the old key.
|
|
2112
|
+
if (isRequestAbort(error)) return
|
|
1679
2113
|
// Only the settle deadline (or a throw before the read's own try) lands
|
|
1680
2114
|
// here: `readGit` handles read failures itself. The failure belongs to the
|
|
1681
2115
|
// key this read STARTED with — the repo picker may have moved the panel to
|
|
@@ -1698,6 +2132,14 @@ async function readGit(bindingId: string, subdir: string, cacheKey: string): Pro
|
|
|
1698
2132
|
// The binding can disappear from the table while this read waits in the queue.
|
|
1699
2133
|
const workspace = state.workspaces.find(item => item.id === bindingId)
|
|
1700
2134
|
if (workspace === undefined) return
|
|
2135
|
+
// A read of the SAME binding is starting: the one already running describes a
|
|
2136
|
+
// slice that is about to be replaced (another repository directory, or a
|
|
2137
|
+
// refresh that started later), so it must release its connection instead of
|
|
2138
|
+
// walking the tree to an answer nobody will use.
|
|
2139
|
+
gitReadAborts.get(bindingId)?.abort()
|
|
2140
|
+
const controller = new AbortController()
|
|
2141
|
+
gitReadAborts.set(bindingId, controller)
|
|
2142
|
+
const signal = controller.signal
|
|
1701
2143
|
const ticket = ++gitReadTicket
|
|
1702
2144
|
latestGitRead.set(bindingId, ticket)
|
|
1703
2145
|
// A local stage/unstage that happens while this read is in flight cannot be in
|
|
@@ -1711,7 +2153,7 @@ async function readGit(bindingId: string, subdir: string, cacheKey: string): Pro
|
|
|
1711
2153
|
// hint, which is the very blank state the cache exists to prevent.
|
|
1712
2154
|
// `withDeadline` covers the host that never answers at all; the probe itself
|
|
1713
2155
|
// reports transport failures.
|
|
1714
|
-
const probe = await withDeadline(probeRepoRoot(workspace.alias, workdir), gitDeadlineMs(), t('editor.readTimeout'))
|
|
2156
|
+
const probe = await withDeadline(probeRepoRoot(workspace.alias, workdir, signal), gitDeadlineMs(), t('editor.readTimeout'))
|
|
1715
2157
|
if (probe.kind === 'failed') throw new Error(probe.error)
|
|
1716
2158
|
if (probe.kind === 'none') {
|
|
1717
2159
|
const snapshot: GitSnapshot = {
|
|
@@ -1729,9 +2171,12 @@ async function readGit(bindingId: string, subdir: string, cacheKey: string): Pro
|
|
|
1729
2171
|
}
|
|
1730
2172
|
const root = probe.root
|
|
1731
2173
|
const [detail, head] = await Promise.all([
|
|
1732
|
-
withDeadline(loadStatusDetail(workspace.alias, root), gitDeadlineMs(), t('editor.readTimeout')),
|
|
1733
|
-
withDeadline(loadHead(workspace.alias, root), gitDeadlineMs(), t('editor.readTimeout')),
|
|
2174
|
+
withDeadline(loadStatusDetail(workspace.alias, root, signal), gitDeadlineMs(), t('editor.readTimeout')),
|
|
2175
|
+
withDeadline(loadHead(workspace.alias, root, signal), gitDeadlineMs(), t('editor.readTimeout')),
|
|
1734
2176
|
])
|
|
2177
|
+
// One half may have been aborted while the other answered; a half-finished
|
|
2178
|
+
// pair must never be cached (an aborted HEAD once landed as "detached").
|
|
2179
|
+
if (signal.aborted) return
|
|
1735
2180
|
// A directory INSIDE a repository settles on that repository's root, so the
|
|
1736
2181
|
// stored choice is what git actually uses (and what the picker shows). Only
|
|
1737
2182
|
// the binding's LATEST read may rewrite that persisted choice: a read
|
|
@@ -1775,6 +2220,11 @@ async function readGit(bindingId: string, subdir: string, cacheKey: string): Pro
|
|
|
1775
2220
|
if (settled !== subdir) writeGitSnapshot(gitCacheKey(bindingId, settled), snapshot)
|
|
1776
2221
|
paintGit(bindingId, ticket, snapshot)
|
|
1777
2222
|
} catch (error) {
|
|
2223
|
+
// An ABORTED read is not a failure. The switch (or the newer read that
|
|
2224
|
+
// superseded this one) cancelled it on purpose, so there is nothing to
|
|
2225
|
+
// report: `gitError` would blame the user's new workspace for a walk they
|
|
2226
|
+
// left, and the cached slice they already have stays the truth.
|
|
2227
|
+
if (signal.aborted || isRequestAbort(error)) return
|
|
1778
2228
|
if (!gitReadIsCurrent(bindingId, ticket)) return
|
|
1779
2229
|
// A failed read discards nothing that was already known: the panel keeps the
|
|
1780
2230
|
// last good (or cached) slice and prints the message above it, so a transient
|
|
@@ -1784,6 +2234,10 @@ async function readGit(bindingId: string, subdir: string, cacheKey: string): Pro
|
|
|
1784
2234
|
gitError: error instanceof Error ? error.message : String(error),
|
|
1785
2235
|
gitCached: state.repoRoot !== undefined,
|
|
1786
2236
|
})
|
|
2237
|
+
} finally {
|
|
2238
|
+
// Only the read that still owns the slot may clear it: a newer read has
|
|
2239
|
+
// already replaced the map entry and must stay abortable.
|
|
2240
|
+
if (gitReadAborts.get(bindingId) === controller) gitReadAborts.delete(bindingId)
|
|
1787
2241
|
}
|
|
1788
2242
|
}
|
|
1789
2243
|
|
|
@@ -2002,16 +2456,27 @@ function upsertTab(tab: EditorTab): void {
|
|
|
2002
2456
|
let revealRetry: ReturnType<typeof setTimeout> | undefined
|
|
2003
2457
|
|
|
2004
2458
|
/**
|
|
2005
|
-
* Bring the editor into view.
|
|
2006
|
-
*
|
|
2007
|
-
*
|
|
2008
|
-
*
|
|
2009
|
-
*
|
|
2459
|
+
* Bring the editor into view.
|
|
2460
|
+
*
|
|
2461
|
+
* The docked surface (the default) is a FULL-COLUMN rail page, so opening a file
|
|
2462
|
+
* switches the column to the editor (the tree stays one click away on the rail)
|
|
2463
|
+
* — without this the click looks like a no-op. Closing its last file switches
|
|
2464
|
+
* back to the directory (see `closeTab`).
|
|
2465
|
+
*
|
|
2466
|
+
* On the 'center' surface the shell renders only the selected conversation
|
|
2467
|
+
* view, so a file opened from the sidebar must also select that tab. When the
|
|
2468
|
+
* tab cannot be found (another host build, or the shell's markup changed) the
|
|
2469
|
+
* user is told where the file opened instead of being left guessing.
|
|
2010
2470
|
*/
|
|
2011
2471
|
function revealEditor(): void {
|
|
2012
|
-
|
|
2013
|
-
//
|
|
2014
|
-
|
|
2472
|
+
const surface = effectiveEditorSurface(state.editorSurface, state.floatOpen)
|
|
2473
|
+
// While the editor floats, neither docked surface has an editor to reveal:
|
|
2474
|
+
// the file just went into the floating window (which is already on screen).
|
|
2475
|
+
if (surface === 'float') return
|
|
2476
|
+
if (surface === 'sidebar') {
|
|
2477
|
+
if (state.view !== 'editor') setView('editor')
|
|
2478
|
+
return
|
|
2479
|
+
}
|
|
2015
2480
|
const label = t('view.editor')
|
|
2016
2481
|
// A newer open supersedes the pending retry: arming a second one left the
|
|
2017
2482
|
// timers piling up one per opened file (each doing its own full-document tab
|
|
@@ -2267,13 +2732,18 @@ export function openRemoteFileInBinding(
|
|
|
2267
2732
|
* Whether the plugin's own rich editor is the place a remote file click should
|
|
2268
2733
|
* land (the click interceptor's gate, see `remote-file-open.ts`).
|
|
2269
2734
|
*
|
|
2270
|
-
*
|
|
2271
|
-
*
|
|
2272
|
-
* the
|
|
2273
|
-
*
|
|
2735
|
+
* True while at least one SEAT exists that can render our editor in this page
|
|
2736
|
+
* (see `editor-capability.ts`): the docked sidebar pane is the default seat and
|
|
2737
|
+
* the conversation-view tab is the optional second one. "Registered" rather than
|
|
2738
|
+
* "currently mounted" on purpose — the panels are lazy/keep-alive, so a fresh
|
|
2739
|
+
* page has no mounted pane until the rail visits it, and asking for a mount
|
|
2740
|
+
* would send the first click to the host's native preview, which cannot resolve
|
|
2741
|
+
* a remote path at all. A host where no seat registers falls back to that native
|
|
2742
|
+
* preview, which is the only thing it can do. Unknown bindings are still
|
|
2743
|
+
* answered by `openRemoteFileInBinding` returning false.
|
|
2274
2744
|
*/
|
|
2275
2745
|
export function isEditorTakeoverActive(): boolean {
|
|
2276
|
-
return
|
|
2746
|
+
return editorSeatCount() > 0
|
|
2277
2747
|
}
|
|
2278
2748
|
|
|
2279
2749
|
/** Open (or focus) a working-tree diff of one repository path. */
|
|
@@ -2410,6 +2880,16 @@ export function closeTab(id: string): void {
|
|
|
2410
2880
|
? (next[Math.min(index, next.length - 1)]?.id ?? next[next.length - 1]?.id)
|
|
2411
2881
|
: state.activeTabId
|
|
2412
2882
|
patch({ tabs: next, activeTabId })
|
|
2883
|
+
// Closing the LAST file returns to the directory: an empty editor page (or a
|
|
2884
|
+
// full-width tab with nothing in it) is where a reader has no next action.
|
|
2885
|
+
// Dirty tabs still go through the pane's confirmation before they get here.
|
|
2886
|
+
if (next.length === 0) {
|
|
2887
|
+
// The centre seat has nowhere to go once its last tab is gone: dock back and
|
|
2888
|
+
// show the directory. On the docked surface the editor IS the rail page, so
|
|
2889
|
+
// that page hands the column back to the explorer.
|
|
2890
|
+
if (state.editorSurface === 'center') setEditorSurface('sidebar')
|
|
2891
|
+
if (state.view === 'editor') setView('explorer')
|
|
2892
|
+
}
|
|
2413
2893
|
}
|
|
2414
2894
|
|
|
2415
2895
|
export function updateTab(id: string, next: Partial<EditorTab>): void {
|
|
@@ -2759,6 +3239,41 @@ export function setEditorSurface(surface: 'center' | 'sidebar'): void {
|
|
|
2759
3239
|
patch({ editorSurface: surface })
|
|
2760
3240
|
}
|
|
2761
3241
|
|
|
3242
|
+
/**
|
|
3243
|
+
* Move the editor into the conversation-view tab (full width).
|
|
3244
|
+
*
|
|
3245
|
+
* The live buffer is captured BEFORE the surface flips: the flip unmounts the
|
|
3246
|
+
* mount that owns it (see `captureLiveBuffer`'s header), and without that
|
|
3247
|
+
* handoff the edits typed since the load would disappear. The host tab is then
|
|
3248
|
+
* selected so the user actually sees where the editor went.
|
|
3249
|
+
*/
|
|
3250
|
+
export function openEditorInCenter(): void {
|
|
3251
|
+
if (state.editorSurface === 'center') {
|
|
3252
|
+
revealEditor()
|
|
3253
|
+
return
|
|
3254
|
+
}
|
|
3255
|
+
captureLiveBuffer()
|
|
3256
|
+
patch({ editorSurface: 'center' })
|
|
3257
|
+
revealEditor()
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
/**
|
|
3261
|
+
* Dock the editor back into the sidebar (the reverse of `openEditorInCenter`).
|
|
3262
|
+
*
|
|
3263
|
+
* The docked pane is the default seat and owns the whole sidebar column, so
|
|
3264
|
+
* `revealEditor` switches the rail to the editor page (from whatever view was
|
|
3265
|
+
* showing) and the tree stays one click away.
|
|
3266
|
+
*/
|
|
3267
|
+
export function dockEditorSidebar(): void {
|
|
3268
|
+
if (state.editorSurface === 'sidebar') {
|
|
3269
|
+
revealEditor()
|
|
3270
|
+
return
|
|
3271
|
+
}
|
|
3272
|
+
captureLiveBuffer()
|
|
3273
|
+
patch({ editorSurface: 'sidebar' })
|
|
3274
|
+
revealEditor()
|
|
3275
|
+
}
|
|
3276
|
+
|
|
2762
3277
|
/**
|
|
2763
3278
|
* Record that the host's frame-wide overlay slot actually rendered the
|
|
2764
3279
|
* floating window host (see `FloatingEditorWindow`).
|