dsh-remote-vs 0.26.0 → 0.27.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 +4 -11
- package/README.md +4 -8
- package/THIRD-PARTY-NOTICES.md +7 -2
- package/lib/client.js +6622 -5821
- package/lib/index.js +275 -1
- package/lib/types/client/CodeEditor.d.ts +14 -0
- package/lib/types/client/OutlinePanel.d.ts +22 -0
- package/lib/types/client/ProcessesSection.d.ts +19 -0
- package/lib/types/client/api.d.ts +5 -1
- package/lib/types/client/blame-model.d.ts +77 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/outline-model.d.ts +59 -0
- package/lib/types/client/scm/actions.d.ts +12 -1
- package/lib/types/client/store.d.ts +18 -0
- package/lib/types/client/vsc/blame.d.ts +19 -0
- package/lib/types/client/vsc/kit.d.ts +0 -2
- package/lib/types/client/vsc/preview-document.d.ts +46 -0
- package/lib/types/client/vsc/preview-model.d.ts +31 -0
- package/lib/types/client/vsc/preview-services.d.ts +24 -0
- package/lib/types/git-ops.d.ts +18 -0
- package/lib/types/processes.d.ts +43 -0
- package/lib/types/protocol.d.ts +34 -0
- package/package.json +2 -1
- package/src/client/CodeEditor.tsx +43 -1
- package/src/client/EditorPane.tsx +520 -37
- package/src/client/MonitorView.tsx +16 -5
- package/src/client/OutlinePanel.tsx +287 -0
- package/src/client/ProcessesSection.tsx +292 -0
- package/src/client/api.ts +8 -0
- package/src/client/blame-model.ts +242 -0
- package/src/client/i18n.ts +194 -0
- package/src/client/index.tsx +4 -0
- package/src/client/outline-model.ts +775 -0
- package/src/client/scm/HistoryPanel.tsx +38 -1
- package/src/client/scm/actions.ts +55 -2
- package/src/client/store.tsx +54 -5
- package/src/client/vsc/blame.ts +147 -0
- package/src/client/vsc/kit.tsx +3 -11
- package/src/client/vsc/preview-document.tsx +323 -0
- package/src/client/vsc/preview-model.ts +216 -0
- package/src/client/vsc/preview-services.ts +118 -0
- package/src/client/vsc/vsc.css +6509 -5716
- package/src/git-ops.ts +34 -0
- package/src/processes.ts +177 -0
- package/src/protocol.ts +37 -0
- package/src/routes.ts +118 -0
|
@@ -26,7 +26,7 @@ import type { GitCommit, GitCommitFile } from '../../protocol.ts'
|
|
|
26
26
|
import { GIT_LOG_MAX } from '../../git-format.ts'
|
|
27
27
|
import { api } from '../api.ts'
|
|
28
28
|
import { gitReadSettleMs, shallowEqual, useExplorerSelector, type ExplorerValue } from '../store.tsx'
|
|
29
|
-
import { checkoutCommit, joinRemote, loadCommitFiles, loadCommitMessage, loadCommitPatch } from './actions.ts'
|
|
29
|
+
import { checkoutCommit, joinRemote, loadCommit, loadCommitFiles, loadCommitMessage, loadCommitPatch } from './actions.ts'
|
|
30
30
|
import { CommitPane } from './CommitPane.tsx'
|
|
31
31
|
import { isHistoryTab, needsPatchLoad, refBadgeClass, refBadgeLabel, type HistoryTab } from './commit-model.ts'
|
|
32
32
|
import { ReadQueue } from './read-queue.ts'
|
|
@@ -44,6 +44,16 @@ import {
|
|
|
44
44
|
} from '../vsc/kit.tsx'
|
|
45
45
|
|
|
46
46
|
const ROW_H = 22
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Last `commitFocus` request consumed by ANY mounted panel instance.
|
|
50
|
+
*
|
|
51
|
+
* The request lives in the store until overwritten, and the panel re-renders
|
|
52
|
+
* whenever the log refreshes; without this module-level watermark a click on
|
|
53
|
+
* blame would be replayed over the user's later manual selection (and across
|
|
54
|
+
* repository switches). Same rule as `revealRequest`/`terminalRequest`.
|
|
55
|
+
*/
|
|
56
|
+
let consumedCommitFocusId = 0
|
|
47
57
|
const LANE_W = 13
|
|
48
58
|
const PAD_X = 9
|
|
49
59
|
const LANE_COLORS = ['#e2b714', '#4ec9b0', '#58a6ff', '#d2a8ff', '#ff7b72', '#79c0ff', '#7ee787', '#ffa657']
|
|
@@ -226,6 +236,7 @@ const selectHistoryStore = (snapshot: ExplorerValue) => ({
|
|
|
226
236
|
openCommitFile: snapshot.openCommitFile,
|
|
227
237
|
revealInExplorer: snapshot.revealInExplorer,
|
|
228
238
|
openTerminalAt: snapshot.openTerminalAt,
|
|
239
|
+
commitFocus: snapshot.commitFocus,
|
|
229
240
|
})
|
|
230
241
|
|
|
231
242
|
export function HistoryPanel(): ReactNode {
|
|
@@ -349,6 +360,32 @@ export function HistoryPanel(): ReactNode {
|
|
|
349
360
|
setFocusPath(undefined)
|
|
350
361
|
}, [repoKey])
|
|
351
362
|
|
|
363
|
+
// Blame / file-history entries only know a hash: the editor asks the store to
|
|
364
|
+
// show it here, and the log above owns the row object the detail pane needs.
|
|
365
|
+
// Declared AFTER the repository-switch reset so a first mount cannot clear the
|
|
366
|
+
// selection that this request just set.
|
|
367
|
+
useEffect(() => {
|
|
368
|
+
const request = store.commitFocus
|
|
369
|
+
if (request === undefined) return
|
|
370
|
+
if (request.id === consumedCommitFocusId) return
|
|
371
|
+
consumedCommitFocusId = request.id
|
|
372
|
+
setSelectedHash(request.hash)
|
|
373
|
+
setFocusPath(undefined)
|
|
374
|
+
// Blame can point at a commit older than the loaded graph window; fetch its
|
|
375
|
+
// header so the detail pane still opens instead of selecting nothing.
|
|
376
|
+
const live = rows.some(commit => commit.hash === request.hash)
|
|
377
|
+
if (live || selectedSnapshot?.hash === request.hash || alias === '' || repoRoot === undefined) return
|
|
378
|
+
let cancelled = false
|
|
379
|
+
void loadCommit(alias, repoRoot, request.hash)
|
|
380
|
+
.then((commit) => {
|
|
381
|
+
if (!cancelled && commit !== undefined) setSelectedSnapshot(commit)
|
|
382
|
+
})
|
|
383
|
+
.catch(() => {
|
|
384
|
+
// A stale/invalid hash is not worth a toast: the rail is still usable.
|
|
385
|
+
})
|
|
386
|
+
return () => { cancelled = true }
|
|
387
|
+
}, [store.commitFocus?.id, rows, selectedSnapshot?.hash, alias, repoRoot])
|
|
388
|
+
|
|
352
389
|
// Message + file list: what 提交详情 and 内容 need. The patch is NOT read here
|
|
353
390
|
// (see the lazy effect below), so clicking through commits stays cheap.
|
|
354
391
|
useEffect(() => {
|
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
* messages a user can act on (missing identity, no upstream, conflicts, ...).
|
|
9
9
|
*/
|
|
10
10
|
import { REMOTE_API } from '../../protocol.ts'
|
|
11
|
-
import type { GitBranch, GitCommitFile, GitRemote, GitStash, GitStatusDetail, RemoteExecResult, RemoteRead } from '../../protocol.ts'
|
|
12
|
-
import { assertRef, messageCommand, parseMessage, shQuote } from '../../git-format.ts'
|
|
11
|
+
import type { GitBranch, GitCommit, GitCommitFile, GitRemote, GitStash, GitStatusDetail, RemoteExecResult, RemoteRead } from '../../protocol.ts'
|
|
12
|
+
import { assertRef, messageCommand, parseLog, parseMessage, shQuote } from '../../git-format.ts'
|
|
13
13
|
import {
|
|
14
14
|
addRemoteCommand,
|
|
15
15
|
allBranchesCommand,
|
|
16
16
|
applyPatchCommand,
|
|
17
|
+
blameCommand,
|
|
17
18
|
branchHeaderCommand,
|
|
18
19
|
checkoutCommand,
|
|
19
20
|
cleanUntrackedCommand,
|
|
20
21
|
commitCommand,
|
|
22
|
+
commitMetaCommand,
|
|
21
23
|
commitFileDiffCommand,
|
|
22
24
|
commitFilesCommand,
|
|
23
25
|
commitPatchCommand,
|
|
@@ -25,6 +27,7 @@ import {
|
|
|
25
27
|
deleteBranchCommand,
|
|
26
28
|
diffCommand,
|
|
27
29
|
fetchCommand,
|
|
30
|
+
fileHistoryCommand,
|
|
28
31
|
fileAtRevCommand,
|
|
29
32
|
gitErrorHint,
|
|
30
33
|
GIT_CAP,
|
|
@@ -62,6 +65,7 @@ import {
|
|
|
62
65
|
statusPathsCommand,
|
|
63
66
|
unstageCommand,
|
|
64
67
|
} from '../../git-ops.ts'
|
|
68
|
+
import { parseBlamePorcelain, parseFileHistory, type BlameLine, type FileHistoryCommit } from '../blame-model.ts'
|
|
65
69
|
import { api, gitTimeoutMs, type RequestOptions } from '../api.ts'
|
|
66
70
|
import { isRequestAbort } from '../request-gate.ts'
|
|
67
71
|
import { appendExecOutput, networkBudgetMs, networkCommands, type PushTarget } from '../exec-output.ts'
|
|
@@ -425,6 +429,55 @@ export async function loadCommitPatch(alias: string, root: string, hash: string)
|
|
|
425
429
|
return { text: out.stdout, truncated: bytes >= GIT_CAP }
|
|
426
430
|
}
|
|
427
431
|
|
|
432
|
+
/** One viewport window of `git blame` for a repo-relative path. */
|
|
433
|
+
export async function loadBlame(
|
|
434
|
+
alias: string,
|
|
435
|
+
root: string,
|
|
436
|
+
path: string,
|
|
437
|
+
from: number,
|
|
438
|
+
to: number,
|
|
439
|
+
options: RunOptions = {},
|
|
440
|
+
): Promise<BlameLine[]> {
|
|
441
|
+
const result = await run(alias, blameCommand(root, path, from, to), 60_000, options)
|
|
442
|
+
const rows = parseBlamePorcelain(result.stdout)
|
|
443
|
+
// `capped()` pipes through `head`, so git's non-zero exit is hidden; a
|
|
444
|
+
// `no such path` / `has only 0 lines` diagnosis still arrives on stderr and
|
|
445
|
+
// must not be rendered as "this window has no blame data".
|
|
446
|
+
if (rows.length === 0 && result.stderr.trim() !== '') {
|
|
447
|
+
throw new GitOpError(gitErrorHint(result.stderr) ?? result.stderr.trim())
|
|
448
|
+
}
|
|
449
|
+
return rows
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Commits that touched one path. `--follow` makes renames visible as history
|
|
454
|
+
* of the CURRENT name, which is exactly what the editor's file-history menu
|
|
455
|
+
* promises; the rows use the same shape as the repository log.
|
|
456
|
+
*/
|
|
457
|
+
export async function loadFileHistory(
|
|
458
|
+
alias: string,
|
|
459
|
+
root: string,
|
|
460
|
+
path: string,
|
|
461
|
+
max = 100,
|
|
462
|
+
): Promise<FileHistoryCommit[]> {
|
|
463
|
+
const result = await run(alias, fileHistoryCommand(root, path, max), 60_000)
|
|
464
|
+
const rows = parseFileHistory(result.stdout, path)
|
|
465
|
+
if (rows.length === 0 && result.stderr.trim() !== '') {
|
|
466
|
+
throw new GitOpError(gitErrorHint(result.stderr) ?? result.stderr.trim())
|
|
467
|
+
}
|
|
468
|
+
return rows
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** One commit header when the hash is older than the loaded log window. */
|
|
472
|
+
export async function loadCommit(alias: string, root: string, hash: string): Promise<GitCommit | undefined> {
|
|
473
|
+
const result = await run(alias, commitMetaCommand(root, hash), 60_000)
|
|
474
|
+
const commit = parseLog(result.stdout)[0]
|
|
475
|
+
if (commit === undefined && result.stderr.trim() !== '') {
|
|
476
|
+
throw new GitOpError(gitErrorHint(result.stderr) ?? result.stderr.trim())
|
|
477
|
+
}
|
|
478
|
+
return commit
|
|
479
|
+
}
|
|
480
|
+
|
|
428
481
|
/** Local + remote-tracking branches. */
|
|
429
482
|
export async function loadBranches(alias: string, root: string, current: string): Promise<GitBranch[]> {
|
|
430
483
|
const out = await run(alias, allBranchesCommand(root), 60_000)
|
package/src/client/store.tsx
CHANGED
|
@@ -53,7 +53,8 @@ import { planWorkspaceFollow, selectionIsSessionBinding, type WorkspaceFollowDec
|
|
|
53
53
|
import { revealViewTab } from './reveal.ts'
|
|
54
54
|
import { applyConnectionStatuses, connectionStateOf, isConnectionFailure, markConnectionProbeOk } from './connection.ts'
|
|
55
55
|
import { isRequestAbort } from './request-gate.ts'
|
|
56
|
-
import { confirmDialog,
|
|
56
|
+
import { confirmDialog, isImageFile, toast } from './vsc/kit.tsx'
|
|
57
|
+
import { hasTextSource, isBytePreview, previewKindOf } from './vsc/preview-model.ts'
|
|
57
58
|
import {
|
|
58
59
|
isWithinRoot,
|
|
59
60
|
normalizeRemotePath,
|
|
@@ -219,6 +220,8 @@ interface State {
|
|
|
219
220
|
revealRequest: RevealRequest | undefined
|
|
220
221
|
/** A pending "open a terminal in this folder" request (search-result menu). */
|
|
221
222
|
terminalRequest: TerminalRequest | undefined
|
|
223
|
+
/** A pending "select this commit in the history rail" request. */
|
|
224
|
+
commitFocus: CommitFocusRequest | undefined
|
|
222
225
|
/**
|
|
223
226
|
* Expanded untracked DIRECTORY rows (`-u normal` collapses a directory into
|
|
224
227
|
* one row, so the panel asks for its contents on demand — see
|
|
@@ -268,6 +271,13 @@ export interface TerminalRequest {
|
|
|
268
271
|
dir: string
|
|
269
272
|
}
|
|
270
273
|
|
|
274
|
+
/** One "show this commit in the history rail" request. */
|
|
275
|
+
export interface CommitFocusRequest {
|
|
276
|
+
/** Monotonic id so selecting the same commit twice still re-triggers. */
|
|
277
|
+
id: number
|
|
278
|
+
hash: string
|
|
279
|
+
}
|
|
280
|
+
|
|
271
281
|
const WS_KEY = 'dsh-remote-vs.files.ws'
|
|
272
282
|
const VIEW_KEY = 'dsh-remote-vs.view'
|
|
273
283
|
/** Per-workspace repository sub-directory, keyed by workspace id. */
|
|
@@ -526,6 +536,7 @@ const state: State = {
|
|
|
526
536
|
searchRequest: undefined,
|
|
527
537
|
revealRequest: undefined,
|
|
528
538
|
terminalRequest: undefined,
|
|
539
|
+
commitFocus: undefined,
|
|
529
540
|
untrackedDirs: new Map(),
|
|
530
541
|
}
|
|
531
542
|
|
|
@@ -577,6 +588,8 @@ export interface ExplorerValue {
|
|
|
577
588
|
revealRequest: RevealRequest | undefined
|
|
578
589
|
/** Pending "open a terminal here" request (consumed by the terminal panel). */
|
|
579
590
|
terminalRequest: TerminalRequest | undefined
|
|
591
|
+
/** Pending "select this commit in the history rail" request. */
|
|
592
|
+
commitFocus: CommitFocusRequest | undefined
|
|
580
593
|
setView: (view: RailView) => void
|
|
581
594
|
/** Switch to the search panel (optionally scoped to a folder) — the tree's
|
|
582
595
|
"find in folder" entry point. */
|
|
@@ -592,6 +605,8 @@ export interface ExplorerValue {
|
|
|
592
605
|
* search results' "open in terminal" entry.
|
|
593
606
|
*/
|
|
594
607
|
openTerminalAt: (dir: string) => void
|
|
608
|
+
/** Open the history rail with this commit selected (blame / file history). */
|
|
609
|
+
focusCommit: (hash: string) => void
|
|
595
610
|
/**
|
|
596
611
|
* The USER's pick — the workspace dropdowns and the wizard's "open files".
|
|
597
612
|
*
|
|
@@ -770,10 +785,12 @@ function build(): ExplorerValue {
|
|
|
770
785
|
searchRequest: state.searchRequest,
|
|
771
786
|
revealRequest: state.revealRequest,
|
|
772
787
|
terminalRequest: state.terminalRequest,
|
|
788
|
+
commitFocus: state.commitFocus,
|
|
773
789
|
setView,
|
|
774
790
|
requestSearch,
|
|
775
791
|
revealInExplorer,
|
|
776
792
|
openTerminalAt,
|
|
793
|
+
focusCommit,
|
|
777
794
|
selectWorkspace,
|
|
778
795
|
setRepoSubdir,
|
|
779
796
|
discoverRepos,
|
|
@@ -1430,6 +1447,23 @@ export function openTerminalAt(dir: string): void {
|
|
|
1430
1447
|
setView('terminal')
|
|
1431
1448
|
}
|
|
1432
1449
|
|
|
1450
|
+
/** Monotonic ticket for "show this commit" requests from the editor. */
|
|
1451
|
+
let commitFocusSeq = 0
|
|
1452
|
+
|
|
1453
|
+
/**
|
|
1454
|
+
* Open the history rail and select one commit.
|
|
1455
|
+
*
|
|
1456
|
+
* Blame cells and the file-history menu only know a hash; the history panel owns
|
|
1457
|
+
* the list and the detail pane, so the selection travels as a request (the same
|
|
1458
|
+
* pattern as `revealInExplorer` / `openTerminalAt`).
|
|
1459
|
+
*/
|
|
1460
|
+
export function focusCommit(hash: string): void {
|
|
1461
|
+
if (hash === '' || /^0+$/.test(hash)) return
|
|
1462
|
+
commitFocusSeq += 1
|
|
1463
|
+
patch({ commitFocus: { id: commitFocusSeq, hash } })
|
|
1464
|
+
setView('history')
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1433
1467
|
/**
|
|
1434
1468
|
* Select the binding every view works against — the USER's choice.
|
|
1435
1469
|
*
|
|
@@ -2620,6 +2654,7 @@ export function openFile(fullPath: string, options: { line?: number } = {}): voi
|
|
|
2620
2654
|
const workspace = currentWorkspace()
|
|
2621
2655
|
if (workspace === undefined || fullPath === '') return
|
|
2622
2656
|
const id = `file:${workspace.alias}:${fullPath}`
|
|
2657
|
+
const previewKind = previewKindOf(fullPath)
|
|
2623
2658
|
// Re-opening a tab that is already up only re-addresses the reveal line, so
|
|
2624
2659
|
// a second search hit in the same file moves the cursor instead of reloading.
|
|
2625
2660
|
// The nonce also re-triggers a jump to the SAME line (value alone would not).
|
|
@@ -2647,10 +2682,10 @@ export function openFile(fullPath: string, options: { line?: number } = {}): voi
|
|
|
2647
2682
|
saving: false,
|
|
2648
2683
|
binary: false,
|
|
2649
2684
|
truncated: false,
|
|
2650
|
-
image:
|
|
2651
|
-
markdown:
|
|
2652
|
-
html:
|
|
2653
|
-
preview:
|
|
2685
|
+
image: previewKind === 'image',
|
|
2686
|
+
markdown: previewKind === 'markdown',
|
|
2687
|
+
html: previewKind === 'html',
|
|
2688
|
+
preview: hasTextSource(previewKind),
|
|
2654
2689
|
staged: false,
|
|
2655
2690
|
untracked: false,
|
|
2656
2691
|
...(options.line === undefined ? {} : { line: options.line, lineNonce: 1 }),
|
|
@@ -2658,6 +2693,13 @@ export function openFile(fullPath: string, options: { line?: number } = {}): voi
|
|
|
2658
2693
|
model: undefined,
|
|
2659
2694
|
view: 'split',
|
|
2660
2695
|
})
|
|
2696
|
+
// PDF/Office/media have no editable text: reading them through fs.read would
|
|
2697
|
+
// only fetch a capped base64 window and land on the binary notice. The
|
|
2698
|
+
// preview component reads their bytes from the download route instead.
|
|
2699
|
+
if (isBytePreview(previewKind)) {
|
|
2700
|
+
patchTab(id, { loading: false })
|
|
2701
|
+
return
|
|
2702
|
+
}
|
|
2661
2703
|
void (async () => {
|
|
2662
2704
|
try {
|
|
2663
2705
|
const read = await withDeadline(api.fileOp.read(workspace.alias, fullPath), fileReadDeadlineMs(), t('editor.readTimeout'))
|
|
@@ -3186,6 +3228,13 @@ export async function reloadTab(id: string): Promise<void> {
|
|
|
3186
3228
|
const tab = state.tabs.find(item => item.id === id)
|
|
3187
3229
|
if (workspace === undefined || tab === undefined) return
|
|
3188
3230
|
if (tab.kind === 'file') {
|
|
3231
|
+
// Byte previews have no text buffer: fs.read would fetch a capped base64
|
|
3232
|
+
// window and turn the tab into "binary", hiding the preview. A revision
|
|
3233
|
+
// bump is the whole reload for them.
|
|
3234
|
+
if (isBytePreview(previewKindOf(tab.fullPath))) {
|
|
3235
|
+
patchTab(id, { loading: false, error: undefined, reloadNonce: (tab.reloadNonce ?? 0) + 1 })
|
|
3236
|
+
return
|
|
3237
|
+
}
|
|
3189
3238
|
try {
|
|
3190
3239
|
const read = await withDeadline(api.fileOp.read(workspace.alias, tab.fullPath), fileReadDeadlineMs(), t('editor.readTimeout'))
|
|
3191
3240
|
patchTab(id, {
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline blame gutter for the CodeMirror editor.
|
|
3
|
+
*
|
|
4
|
+
* The data is fetched by the editor pane (one `-L` window at a time) and handed
|
|
5
|
+
* in as a line→commit map; this module only paints it. Keeping the fetch out of
|
|
6
|
+
* here is deliberate: the same model is used by the gate without CodeMirror,
|
|
7
|
+
* and a scroll must not be able to start a request from inside a gutter
|
|
8
|
+
* callback.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
RangeSetBuilder,
|
|
12
|
+
type Extension,
|
|
13
|
+
type RangeSet,
|
|
14
|
+
} from '@codemirror/state'
|
|
15
|
+
import {
|
|
16
|
+
EditorView,
|
|
17
|
+
GutterMarker,
|
|
18
|
+
ViewPlugin,
|
|
19
|
+
gutter,
|
|
20
|
+
type ViewUpdate,
|
|
21
|
+
} from '@codemirror/view'
|
|
22
|
+
import { blameLabel, blameRuns, blameTitle, isCommittedBlame, type BlameLine } from '../blame-model.ts'
|
|
23
|
+
|
|
24
|
+
/** One gutter cell's label; `null` text means "same commit as the line above". */
|
|
25
|
+
class BlameMarker extends GutterMarker {
|
|
26
|
+
constructor(
|
|
27
|
+
private readonly text: string,
|
|
28
|
+
private readonly title: string,
|
|
29
|
+
private readonly committed: boolean,
|
|
30
|
+
) {
|
|
31
|
+
super()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override toDOM(): HTMLElement {
|
|
35
|
+
const node = document.createElement('span')
|
|
36
|
+
node.className = this.text === ''
|
|
37
|
+
? 'rvs-blame-cont'
|
|
38
|
+
: `rvs-blame-chip${this.committed ? '' : ' rvs-blame-uncommitted'}`
|
|
39
|
+
node.textContent = this.text
|
|
40
|
+
if (this.title !== '') node.title = this.title
|
|
41
|
+
return node
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override eq(other: GutterMarker): boolean {
|
|
45
|
+
return other instanceof BlameMarker && other.text === this.text && other.title === this.title
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const EMPTY = new RangeSetBuilder<GutterMarker>().finish()
|
|
50
|
+
|
|
51
|
+
/** Fixed spacer: keeps the gutter from jumping between files. */
|
|
52
|
+
class SpacerMarker extends GutterMarker {
|
|
53
|
+
override toDOM(): HTMLElement {
|
|
54
|
+
const node = document.createElement('span')
|
|
55
|
+
node.className = 'rvs-blame-spacer'
|
|
56
|
+
node.textContent = 'author · 00y'
|
|
57
|
+
return node
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const SPACER = new SpacerMarker()
|
|
62
|
+
|
|
63
|
+
/** Viewport-only markers; the gutter itself only renders visible lines. */
|
|
64
|
+
function viewportMarkers(
|
|
65
|
+
view: EditorView,
|
|
66
|
+
entries: ReadonlyMap<number, BlameLine>,
|
|
67
|
+
nowSeconds: number,
|
|
68
|
+
): RangeSet<GutterMarker> {
|
|
69
|
+
const doc = view.state.doc
|
|
70
|
+
const first = Math.max(1, doc.lineAt(view.viewport.from).number)
|
|
71
|
+
const last = Math.min(doc.lines, doc.lineAt(view.viewport.to).number)
|
|
72
|
+
if (entries.size === 0 || last < first) return EMPTY
|
|
73
|
+
const runStarts = new Set(
|
|
74
|
+
blameRuns([...entries.values()].sort((left, right) => left.line - right.line)).map(run => run.from),
|
|
75
|
+
)
|
|
76
|
+
const builder = new RangeSetBuilder<GutterMarker>()
|
|
77
|
+
for (let number = first; number <= last; number += 1) {
|
|
78
|
+
const entry = entries.get(number)
|
|
79
|
+
if (entry === undefined) continue
|
|
80
|
+
const sameAsAbove = !runStarts.has(number)
|
|
81
|
+
const marker = sameAsAbove
|
|
82
|
+
? new BlameMarker('', '', true)
|
|
83
|
+
: new BlameMarker(blameLabel(entry, nowSeconds), blameTitle(entry), isCommittedBlame(entry.hash))
|
|
84
|
+
const line = doc.line(number)
|
|
85
|
+
builder.add(line.from, line.to, marker)
|
|
86
|
+
}
|
|
87
|
+
return builder.finish()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Fire `report` when the viewport (or the document) changes. */
|
|
91
|
+
function viewportReporter(report: (first: number, last: number) => void): Extension {
|
|
92
|
+
const emit = (view: EditorView): void => {
|
|
93
|
+
const doc = view.state.doc
|
|
94
|
+
report(doc.lineAt(view.viewport.from).number, doc.lineAt(view.viewport.to).number)
|
|
95
|
+
}
|
|
96
|
+
return ViewPlugin.fromClass(class {
|
|
97
|
+
constructor(view: EditorView) {
|
|
98
|
+
// A freshly mounted editor gets no update event: report the first
|
|
99
|
+
// viewport here, or the pane would never fetch any blame until scroll.
|
|
100
|
+
emit(view)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
update(update: ViewUpdate): void {
|
|
104
|
+
if (!update.viewportChanged && !update.docChanged) return
|
|
105
|
+
emit(update.view)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Build the gutter extension. Rebuilt by the editor's compartment whenever a
|
|
112
|
+
* blame window lands; `nowSeconds` is pinned so every cell in one render has
|
|
113
|
+
* the same clock.
|
|
114
|
+
*/
|
|
115
|
+
export function blameExtension(
|
|
116
|
+
entries: ReadonlyMap<number, BlameLine>,
|
|
117
|
+
onOpen?: (entry: BlameLine) => void,
|
|
118
|
+
): Extension {
|
|
119
|
+
const nowSeconds = Math.floor(Date.now() / 1000)
|
|
120
|
+
const activate = (view: EditorView, line: { from: number }, event: Event): boolean => {
|
|
121
|
+
const number = view.state.doc.lineAt(line.from).number
|
|
122
|
+
const entry = entries.get(number)
|
|
123
|
+
if (entry === undefined || !isCommittedBlame(entry.hash)) return false
|
|
124
|
+
event.preventDefault()
|
|
125
|
+
onOpen?.(entry)
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
return [
|
|
129
|
+
gutter({
|
|
130
|
+
class: 'rvs-blame-gutter',
|
|
131
|
+
markers: view => viewportMarkers(view, entries, nowSeconds),
|
|
132
|
+
initialSpacer: () => SPACER,
|
|
133
|
+
domEventHandlers: onOpen === undefined
|
|
134
|
+
? {}
|
|
135
|
+
: {
|
|
136
|
+
mousedown(view, line, event) {
|
|
137
|
+
return activate(view, line, event)
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Internal export for the editor to forward viewport changes. */
|
|
145
|
+
export function blameViewportReporter(report: (first: number, last: number) => void): Extension {
|
|
146
|
+
return viewportReporter(report)
|
|
147
|
+
}
|
package/src/client/vsc/kit.tsx
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
type CSSProperties,
|
|
31
31
|
type ReactNode,
|
|
32
32
|
} from 'react'
|
|
33
|
+
import { isBytePreview, previewKindOf } from './preview-model.ts'
|
|
33
34
|
import { createPortal } from 'react-dom'
|
|
34
35
|
import { detectLang, makeT } from '../i18n.ts'
|
|
35
36
|
import { FileTypeIcon, FolderGlyph } from './file-icons.tsx'
|
|
@@ -405,23 +406,14 @@ export function isImageFile(path: string): boolean {
|
|
|
405
406
|
return IMAGE_EXTS.has(extOf(path))
|
|
406
407
|
}
|
|
407
408
|
|
|
408
|
-
export function isMarkdownFile(path: string): boolean {
|
|
409
|
-
const ext = extOf(path)
|
|
410
|
-
return ext === 'md' || ext === 'markdown'
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
export function isHtmlFile(path: string): boolean {
|
|
414
|
-
const ext = extOf(path)
|
|
415
|
-
return ext === 'html' || ext === 'htm'
|
|
416
|
-
}
|
|
417
|
-
|
|
418
409
|
export function mimeFor(path: string): string {
|
|
419
410
|
return MIME[extOf(path)] ?? 'application/octet-stream'
|
|
420
411
|
}
|
|
421
412
|
|
|
422
413
|
/** True for a file that always opens as a preview, never as a diff. */
|
|
423
414
|
export function isPreviewOnlyFile(path: string): boolean {
|
|
424
|
-
|
|
415
|
+
const kind = previewKindOf(path)
|
|
416
|
+
return kind === 'image' || isBytePreview(kind)
|
|
425
417
|
}
|
|
426
418
|
|
|
427
419
|
/**
|