dsh-ris-ide 1.8.3 → 1.8.5

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/lib/client.js CHANGED
@@ -125,15 +125,19 @@ window.__ModuleLoader__.load({
125
125
  /**
126
126
  * Tell the user that the IDE code changed under the open page.
127
127
  *
128
- * Neither page shape reloads itself: the standalone window owns an editor that
129
- * can hold unsaved buffers, and a DSH page would drop the conversation view. The
130
- * bar carries the refresh button and is idempotent — later hellos/focus polls
128
+ * Only the standalone IDE window shows this: refreshing it costs nothing, while a
129
+ * DSH page reload throws the conversation away — there the IDE panel simply keeps
130
+ * running the bundle it booted until the user reloads on their own terms (m06203).
131
+ * The bar carries the refresh button and is idempotent — later hellos/focus polls
131
132
  * reuse the same node instead of stacking bars.
132
133
  * @param {string} build - the build id the hint is for.
133
134
  */
134
135
  function showStaleBuildNotice(build) {
135
136
  staleNoticeBuild = typeof build === 'string' ? build : null
136
137
  if (typeof document === 'undefined') return
138
+ // The DSH page hosts the IDE in its right sidebar; do not nag it with a banner
139
+ // whose only action is a full-page reload (m06203: dsh端取消).
140
+ if (!inStandaloneIdeWindow()) return
137
141
  var existing = document.getElementById('dsh-ris-ide-build-stale')
138
142
  if (existing !== null) { existing.hidden = false; return }
139
143
  var bar = document.createElement('div')
@@ -269,10 +273,17 @@ window.__ModuleLoader__.load({
269
273
  * `sessionId` can go stale and the host then answers every route with 400.
270
274
  * The host accepts an absolute `cwd` from the client, which is enough to keep
271
275
  * the panel working across a session switch or a `dsh web` restart.
276
+ *
277
+ * ONLY the DSH page writes this slot. The standalone window and the IDE inside
278
+ * the risd-ui tab are separate surfaces with their own workspace in the URL:
279
+ * letting them overwrite the slot made the DSH console open the workspace the
280
+ * embedded IDE happened to switch to (m00173-3). They keep using their own
281
+ * (session, cwd) scope and the per-session keys.
272
282
  * @param {string} value - absolute workspace path.
273
283
  */
274
284
  function rememberWorkspaceCwd(value) {
275
285
  if (typeof value !== 'string' || value === '' || value[0] !== '/') return
286
+ if (typeof window !== 'undefined' && window.__dshRisIdeWindow === true) return
276
287
  try { window.localStorage.setItem(WORKSPACE_CWD_KEY, value) } catch { /* private mode */ }
277
288
  }
278
289
 
@@ -486,16 +497,27 @@ window.__ModuleLoader__.load({
486
497
  * event (same origin, fires in every other window) carries the selected log
487
498
  * path, so starting a program from the console also moves the IDE window's log
488
499
  * pane immediately instead of only when the debug session attaches ~40s later.
500
+ *
501
+ * The broadcast is SCOPED by (sessionId, cwd): two views of two different
502
+ * workspaces must stay independent — a start made in workspace B never moves
503
+ * the console that is showing workspace A (m00173-3).
489
504
  */
490
505
  var LOG_FOCUS_KEY = 'dsh-ris-ide:log-focus'
491
506
 
492
507
  /**
493
508
  * @param {string} logPath - the log the user should now be watching.
509
+ * @param {string} [sessionId] - the session the log belongs to.
510
+ * @param {string} [cwd] - the workspace the log belongs to.
494
511
  */
495
- function broadcastLogFocus(logPath) {
512
+ function broadcastLogFocus(logPath, sessionId, cwd) {
496
513
  if (typeof logPath !== 'string' || logPath === '') return
497
514
  try {
498
- window.localStorage.setItem(LOG_FOCUS_KEY, JSON.stringify({ path: logPath, at: Date.now() }))
515
+ window.localStorage.setItem(LOG_FOCUS_KEY, JSON.stringify({
516
+ path: logPath,
517
+ sessionId: typeof sessionId === 'string' ? sessionId : '',
518
+ cwd: typeof cwd === 'string' ? cwd : '',
519
+ at: Date.now(),
520
+ }))
499
521
  } catch { /* private mode / quota: the broadcast is best-effort */ }
500
522
  }
501
523
 
@@ -558,6 +580,48 @@ window.__ModuleLoader__.load({
558
580
  return true
559
581
  }
560
582
 
583
+ /** Normalised workspace path, for comparing two panels' scopes. */
584
+ function risScopeCwd(value) {
585
+ if (typeof value !== 'string' || value === '') return ''
586
+ return value.replace(/[\\/]+$/, '').replace(/\\/g, '/').toLowerCase()
587
+ }
588
+
589
+ /**
590
+ * Does this subscriber belong to the (Session, workspace) the socket carries?
591
+ *
592
+ * ONE socket has ONE scope, but DSH keeps a `keepMounted` panel body alive
593
+ * across Session switches, so the subscriber set can hold panels from several
594
+ * workspaces at once. The scope used to be picked from whichever panel
595
+ * subscribed first, and every frame was then handed to every subscriber of the
596
+ * topic: the console of workspace A painted B's rows (and after a few switches
597
+ * "内容窜"), because `programs` frames carry a `root` that the handler stored
598
+ * unexamined. Frames for another scope are NOT delivered here — that panel
599
+ * falls back to polling its own scope.
600
+ *
601
+ * A subscriber that names neither a session nor a workspace (the `opens` /
602
+ * `debugs` watchers) is connection-wide and matches every socket.
603
+ *
604
+ * @param {object} sub - the subscription.
605
+ * @param {string} sessionId - session the socket was opened for.
606
+ * @param {string} cwd - workspace the socket was opened for.
607
+ * @returns {boolean} whether the sub may receive this socket's frames.
608
+ */
609
+ function risScopeMatches(sub, sessionId, cwd) {
610
+ var subSession = typeof sub.sessionId === 'string' ? sub.sessionId : ''
611
+ var subCwd = risScopeCwd(sub.cwd)
612
+ var socketSession = typeof sessionId === 'string' ? sessionId : ''
613
+ var socketCwd = risScopeCwd(cwd)
614
+ if (subSession !== '' && socketSession !== '' && subSession !== socketSession) return false
615
+ if (subCwd !== '' && socketCwd !== '' && subCwd !== socketCwd) return false
616
+ return true
617
+ }
618
+
619
+ /** The session the right sidebar is showing RIGHT NOW (document-wide, visible marker only). */
620
+ function liveSidebarSessionOfDocument() {
621
+ var live = liveSidebarSessionId()
622
+ return typeof live === 'string' && live !== '' ? live : ''
623
+ }
624
+
561
625
  /** Subscribe an object `{topics, sessionId?, cwd?, handlers, onOpen?}` to the hub. */
562
626
  function risStreamHub() {
563
627
  if (RIS_STREAM_HUB !== null) return RIS_STREAM_HUB
@@ -566,6 +630,9 @@ window.__ModuleLoader__.load({
566
630
  var signature = ''
567
631
  /** The tail path the CURRENT connection carries ('' when none). */
568
632
  var servedTail = ''
633
+ /** The scope the CURRENT connection carries ('' = unknown / connection-wide). */
634
+ var servedSession = ''
635
+ var servedCwd = ''
569
636
  var rebuildTimer = null
570
637
  var retryTimer = null
571
638
  var retryDelay = 3000
@@ -611,20 +678,33 @@ window.__ModuleLoader__.load({
611
678
  return
612
679
  }
613
680
  var topics = []
614
- var sessionId
615
- var cwd
616
681
  var tail
617
682
  var tailBytes
618
683
  var debugPath
684
+ var firstSession
685
+ var firstCwd
686
+ var activeSession
687
+ var activeCwd
619
688
  subscribers.forEach(function (sub) {
620
689
  ;(sub.topics || []).forEach(function (topic) { if (topics.indexOf(topic) === -1) topics.push(topic) })
621
- if (sessionId === undefined && typeof sub.sessionId === 'string' && sub.sessionId !== '') sessionId = sub.sessionId
622
- if (cwd === undefined && typeof sub.cwd === 'string' && sub.cwd !== '') cwd = sub.cwd
623
- if (cwd === undefined) cwd = knownWorkspaceCwd()
690
+ var subSession = typeof sub.sessionId === 'string' ? sub.sessionId : ''
691
+ var subCwd = typeof sub.cwd === 'string' ? sub.cwd : ''
692
+ if (firstSession === undefined && subSession !== '') firstSession = subSession
693
+ if (firstCwd === undefined && subCwd !== '') firstCwd = subCwd
694
+ // The panel the user is looking at owns the socket. A kept-mounted panel
695
+ // from a previous Session just holds its subscription and polls instead
696
+ // of dragging the connection (and every other panel) to its own scope.
697
+ if (sub.active === true) {
698
+ if (activeSession === undefined && subSession !== '') activeSession = subSession
699
+ if (activeCwd === undefined && subCwd !== '') activeCwd = subCwd
700
+ }
624
701
  if (tail === undefined && typeof sub.tail === 'string' && sub.tail !== '') tail = sub.tail
625
702
  if (tailBytes === undefined && typeof sub.tailBytes === 'number' && sub.tailBytes > 0) tailBytes = sub.tailBytes
626
703
  if (debugPath === undefined && typeof sub.debugPath === 'string' && sub.debugPath !== '') debugPath = sub.debugPath
627
704
  })
705
+ var sessionId = activeSession !== undefined ? activeSession : firstSession
706
+ var cwd = activeCwd !== undefined ? activeCwd : firstCwd
707
+ if (cwd === undefined) cwd = knownWorkspaceCwd()
628
708
  topics.sort()
629
709
  var next = topics.join(',') + '|' + [sessionId || '', cwd || '', tail || '', tailBytes || '', debugPath || ''].join('|')
630
710
  if (source !== null && next === signature) {
@@ -638,6 +718,8 @@ window.__ModuleLoader__.load({
638
718
  closeSource()
639
719
  signature = next
640
720
  servedTail = tail || ''
721
+ servedSession = typeof sessionId === 'string' ? sessionId : ''
722
+ servedCwd = typeof cwd === 'string' ? cwd : ''
641
723
  var url = routeUrl('dsh-ris-ide/stream')
642
724
  url.searchParams.set('topics', topics.join(','))
643
725
  if (sessionId !== undefined) url.searchParams.set('sessionId', sessionId)
@@ -690,6 +772,11 @@ window.__ModuleLoader__.load({
690
772
  var payload
691
773
  try { payload = JSON.parse(event.data) } catch { return }
692
774
  subscribers.forEach(function (sub) {
775
+ // Frames belong to the socket's ONE scope. `stream-error` is a
776
+ // connection-wide report, everything else must match the subscriber's
777
+ // own (session, workspace) — a kept-mounted panel from another Session
778
+ // polls its scope instead of painting this one's rows.
779
+ if (topic !== 'stream-error' && !risScopeMatches(sub, servedSession, servedCwd)) return
693
780
  // A frame does not always belong to its own topic (tail bytes arrive
694
781
  // as `append`): risFrameWanted owns that mapping.
695
782
  if (!risFrameWanted(sub.topics, topic, sub.tail, servedTail)) return
@@ -699,10 +786,17 @@ window.__ModuleLoader__.load({
699
786
  })
700
787
  })
701
788
  }
702
- /** Tell subscribers the connection is up, and WHICH tail it carries. */
789
+ /** Tell subscribers the connection is up, WHICH tail it carries and WHICH scope. */
703
790
  function notifyOpen() {
704
791
  subscribers.forEach(function (sub) {
705
- if (typeof sub.onOpen === 'function') sub.onOpen({ tail: servedTail })
792
+ if (typeof sub.onOpen !== 'function') return
793
+ sub.onOpen({
794
+ tail: servedTail,
795
+ sessionId: servedSession,
796
+ cwd: servedCwd,
797
+ // This panel's scope is not the one on the wire: it must poll, not wait.
798
+ scopeMismatch: !risScopeMatches(sub, servedSession, servedCwd),
799
+ })
706
800
  })
707
801
  }
708
802
  function scheduleRetry() {
@@ -1964,6 +2058,7 @@ window.__ModuleLoader__.load({
1964
2058
  /** Every open file stays mounted; inactive panes only collapse. */
1965
2059
  filePanes: { flex: '1 1 0', minHeight: 0, display: 'flex', flexDirection: 'column', position: 'relative' },
1966
2060
  filePane: { flex: '1 1 0', minHeight: 0, display: 'flex', flexDirection: 'column' },
2061
+ sourceUpgradeBar: { display: 'flex', alignItems: 'center', gap: 6, padding: '4px 8px', background: '#eef4ff', borderBottom: '1px solid #cfe0ff', fontSize: 12, color: '#1f4d99', flex: '0 0 auto' },
1967
2062
  filePaneHidden: { display: 'none' },
1968
2063
  /** Read-only preview of a file above the whole-read limit (windowed). */
1969
2064
  largeText: { flex: '1 1 0', minHeight: 0, display: 'flex', flexDirection: 'column', overflow: 'hidden' },
@@ -2441,11 +2536,14 @@ window.__ModuleLoader__.load({
2441
2536
  onOpen: function (info) {
2442
2537
  failures = 0
2443
2538
  // The panel shares ONE streaming socket and that socket carries ONE
2444
- // tail path. When the host bound it to another file (another log viewer
2445
- // mounted first), this pane would never see its own file on the stream
2446
- // — poll `/tail` for it instead of waiting forever.
2539
+ // tail path AND one (Session, workspace). When the host bound it to
2540
+ // another file or another workspace (another pane mounted first, or a
2541
+ // kept panel from an older Session still holds the connection), this
2542
+ // pane would never see its own file on the stream — poll `/tail` for it
2543
+ // instead of waiting forever.
2447
2544
  var served = info !== null && info !== undefined && typeof info.tail === 'string' ? info.tail : ''
2448
- setStreamOk(served === '' || served === path)
2545
+ var mismatch = info !== null && info !== undefined && info.scopeMismatch === true
2546
+ setStreamOk(mismatch !== true && (served === '' || served === path))
2449
2547
  },
2450
2548
  onError: function (readyState) {
2451
2549
  failures += 1
@@ -7243,6 +7341,19 @@ window.__ModuleLoader__.load({
7243
7341
  }
7244
7342
 
7245
7343
  /** Mounts the CodeMirror chunk and pushes prop changes into the handle. */
7344
+ /**
7345
+ * Ctrl/Cmd symbol navigation only makes sense for Java: `.java` sources (which
7346
+ * includes the decompiled cache files), `.class` and the `javap` dump. Other
7347
+ * tabs — Markdown, JSON, logs — keep a plain editor (m05797 follow-up).
7348
+ * @param {string} path - document path shown in the tab.
7349
+ * @returns {boolean} whether hover-underline and click-to-declaration are on.
7350
+ */
7351
+ function symbolNavigationPath(path) {
7352
+ var value = typeof path === 'string' ? path : ''
7353
+ if (value === '') return false
7354
+ return /\.java$|\.class$|\.javap\.txt$/i.test(value)
7355
+ }
7356
+
7246
7357
  function IdeCodeMirror(props) {
7247
7358
  var S = stylesFor(props && typeof props.fontRatio === 'number' ? props.fontRatio : 1)
7248
7359
  var hostRef = useRef(null)
@@ -7255,6 +7366,7 @@ window.__ModuleLoader__.load({
7255
7366
  onSave: props.onSave,
7256
7367
  onToggleBreakpoint: props.onToggleBreakpoint,
7257
7368
  onToolbarState: props.onToolbarState,
7369
+ onSymbolJump: props.onSymbolJump,
7258
7370
  }
7259
7371
  useEffect(function () {
7260
7372
  var host = hostRef.current
@@ -7262,6 +7374,7 @@ window.__ModuleLoader__.load({
7262
7374
  var handle = props.chunk.mount(host, {
7263
7375
  doc: typeof props.text === 'string' ? props.text : '',
7264
7376
  path: typeof props.path === 'string' ? props.path : '',
7377
+ symbolNavigation: symbolNavigationPath(typeof props.path === 'string' ? props.path : ''),
7265
7378
  onContextMenu: function (payload) {
7266
7379
  if (typeof props.onEditorMenu === 'function') props.onEditorMenu(payload)
7267
7380
  },
@@ -7291,6 +7404,10 @@ window.__ModuleLoader__.load({
7291
7404
  var callbacks = callbacksRef.current
7292
7405
  if (typeof callbacks.onToggleBreakpoint === 'function') callbacks.onToggleBreakpoint(line)
7293
7406
  },
7407
+ onSymbolJump: function (payload) {
7408
+ var callbacks = callbacksRef.current
7409
+ if (typeof callbacks.onSymbolJump === 'function') callbacks.onSymbolJump(payload)
7410
+ },
7294
7411
  })
7295
7412
  handleRef.current = handle
7296
7413
  // Expose the handle so the workspace content search can drive the find
@@ -7582,6 +7699,14 @@ window.__ModuleLoader__.load({
7582
7699
  var openProgram = props !== null && props !== undefined && props.openProgram !== null && typeof props.openProgram === 'object' ? props.openProgram : null
7583
7700
  var openLogPath = openProgram !== null && typeof openProgram.logPath === 'string' ? openProgram.logPath : ''
7584
7701
  var visible = props ? props.visible !== false : true
7702
+ /**
7703
+ * The console's 🌐 button. The URL/token work lives in the OWNING panel
7704
+ * (`ProgramsPanel.openSite`) because this component never scans: it only
7705
+ * knows the `programs` array it is handed (m04354/m03945).
7706
+ */
7707
+ var onOpenSite = typeof props.onOpenSite === 'function' ? props.onOpenSite : null
7708
+ var siteBusyId = typeof props.siteBusyId === 'string' ? props.siteBusyId : undefined
7709
+ var ydsProject = props.ydsProject === true
7585
7710
  /** The workspace search box (Ctrl+Alt+F / F3 target outside the editor). */
7586
7711
  var searchInputRef = useRef(null)
7587
7712
  /** The panel root: the boundary of "inside the IDE" for the shortcut shield. */
@@ -7801,6 +7926,76 @@ var [ui, setUi] = useState(function () {
7801
7926
  var debugOpeningRef = useRef(false)
7802
7927
  /** className → absolute source path (a step storm must not re-search). */
7803
7928
  var sourcePathRef = useRef({})
7929
+ /**
7930
+ * className → timestamp of a miss. A miss is NOT permanent: `mvn` may still be
7931
+ * downloading the sources jar, so after a minute the lookup runs again
7932
+ * (m06100). Step storms inside that window stay cheap.
7933
+ */
7934
+ var sourceMissRef = useRef({})
7935
+ var SOURCE_MISS_TTL_MS = 60 * 1000
7936
+ /** type name → resolved Java file (or null when nothing matched). */
7937
+ var javaTypePathRef = useRef({})
7938
+
7939
+ /**
7940
+ * Poll `/debug/source-status` while Maven fetches a missing sources jar.
7941
+ * When the real sources land, the tab keeps the decompiled text and a
7942
+ * banner offers to switch; nothing blocks the editor meanwhile.
7943
+ */
7944
+ function pollDependencySources(displayName, fqn, logPath, decompiledPath) {
7945
+ var attempt = 0
7946
+ function tick() {
7947
+ attempt += 1
7948
+ if (attempt > 48) return
7949
+ var url = routeUrl('dsh-ris-ide/debug/source-status')
7950
+ url.searchParams.set('sessionId', scopeRef.current.sessionId)
7951
+ var pollCwd = scopeCwd(scopeRef.current)
7952
+ if (pollCwd !== undefined) url.searchParams.set('cwd', pollCwd)
7953
+ url.searchParams.set('className', fqn)
7954
+ url.searchParams.set('path', logPath)
7955
+ fetch(url.href, { headers: { accept: 'application/json' } }).then(function (response) {
7956
+ return response.json().catch(function () { return null })
7957
+ }).then(function (body) {
7958
+ // Closed while downloading? Then nobody wants the sources any more; stop
7959
+ // quietly instead of popping a banner for a tab that is gone (m05607).
7960
+ if (docsRef.current[decompiledPath] === undefined) return
7961
+ if (body === null || body.ok !== true) { setTimeout(tick, 2500); return }
7962
+ if (body.ready === true && typeof body.path === 'string' && body.path !== '' && body.path !== decompiledPath) {
7963
+ var upgrade = { name: displayName, decompiledPath: decompiledPath, sourcePath: body.path }
7964
+ // Still looking at the decompiled fallback? Move straight to the real
7965
+ // sources (the fallback tab is closed) instead of asking; the banner is
7966
+ // only for when the user is reading some other tab meanwhile.
7967
+ if (activePathRef.current === decompiledPath) { switchToDependencySource(upgrade); return }
7968
+ setSourceUpgrade(upgrade)
7969
+ return
7970
+ }
7971
+ if (body.status === 'failed') {
7972
+ statusNote('源码下载失败:' + (typeof body.message === 'string' && body.message !== '' ? body.message : 'mvn 没有拿到源码'), 8000)
7973
+ return
7974
+ }
7975
+ setTimeout(tick, 2500)
7976
+ }).catch(function () { setTimeout(tick, 2500) })
7977
+ }
7978
+ setTimeout(tick, 1200)
7979
+ }
7980
+
7981
+ /**
7982
+ * Switch to the real sources and drop the decompiled fallback tab: once the
7983
+ * sources jar is on disk the decompiled view is only a stale duplicate, and
7984
+ * leaving it around makes every later click look like it "did not switch".
7985
+ */
7986
+ function switchToDependencySource(upgrade) {
7987
+ if (upgrade === null || upgrade === undefined) return
7988
+ var existing = docsRef.current[upgrade.sourcePath]
7989
+ if (existing !== undefined && existing !== null) reloadPath(upgrade.sourcePath)
7990
+ openPath(upgrade.sourcePath)
7991
+ setSourceUpgrade(null)
7992
+ if (typeof upgrade.decompiledPath === 'string' && upgrade.decompiledPath !== ''
7993
+ && upgrade.decompiledPath !== upgrade.sourcePath
7994
+ && docsRef.current[upgrade.decompiledPath] !== undefined) {
7995
+ closePath(upgrade.decompiledPath)
7996
+ }
7997
+ }
7998
+
7804
7999
 
7805
8000
  /**
7806
8001
  * The on-disk source path of a class reported by the debugger.
@@ -7815,7 +8010,9 @@ var [ui, setUi] = useState(function () {
7815
8010
  var cleaned = String(className === undefined || className === null ? '' : className).replace(/\$.*$/, '').trim()
7816
8011
  if (cleaned === '') return undefined
7817
8012
  var remembered = sourcePathRef.current[cleaned]
7818
- if (remembered !== undefined) return remembered === null ? undefined : remembered
8013
+ if (remembered !== undefined) return remembered
8014
+ var missedAt = sourceMissRef.current[cleaned]
8015
+ if (typeof missedAt === 'number' && Date.now() - missedAt < SOURCE_MISS_TTL_MS) return undefined
7819
8016
  var relativeSuffix = sourceRelativeSuffix(cleaned)
7820
8017
  var fileEnding = '/' + cleaned.split('.').pop() + '.java'
7821
8018
  try {
@@ -7824,16 +8021,28 @@ var [ui, setUi] = useState(function () {
7824
8021
  var found = candidates.find(function (item) { return item.endsWith('/' + relativeSuffix) })
7825
8022
  if (found === undefined) found = candidates.find(function (item) { return item.endsWith(fileEnding) })
7826
8023
  if (found === undefined) {
7827
- // Not in the workspace: it is a dependency class. Ask the host to pull
7828
- // it out of a `-sources.jar`, decompile it, or at least javap it (the
7829
- // files land in `.dsh-ris-ide/cache` and open in the editor).
8024
+ // Not in the workspace: it is a dependency class. Same host pipeline as
8025
+ // Ctrl/Cmd+click (m06100): sources.jar → decompiler → javap, and when
8026
+ // only compiled text is ready the real sources keep downloading in the
8027
+ // background while the editor shows the same switch banner.
7830
8028
  statusNote('正在获取依赖源码:' + cleaned + '…', 0)
7831
- found = await fsDependencySource(scopeRef.current, cleaned, activePathRef === undefined ? activePath : activePathRef.current)
8029
+ var debugLogPath = activePathRef === undefined ? activePath : activePathRef.current
8030
+ var resolved = await fsDependencySource(scopeRef.current, cleaned, debugLogPath)
7832
8031
  setStatusText('')
8032
+ if (resolved !== undefined && typeof resolved.path === 'string' && resolved.path !== '') {
8033
+ found = resolved.path
8034
+ if (resolved.sourcePending === true) {
8035
+ pollDependencySources(cleaned.split('.').pop(), cleaned, debugLogPath, found)
8036
+ }
8037
+ }
8038
+ }
8039
+ if (found === undefined) {
8040
+ // Not permanent: the background Maven fetch may still produce sources.
8041
+ sourceMissRef.current[cleaned] = Date.now()
8042
+ return undefined
7833
8043
  }
7834
- // Cache a MISS as well: stepping through a JDK/dependency class would
7835
- // otherwise re-scan the workspace (`fsSearch`) on every single frame.
7836
- sourcePathRef.current[cleaned] = found === undefined ? null : found
8044
+ sourcePathRef.current[cleaned] = found
8045
+ delete sourceMissRef.current[cleaned]
7837
8046
  return found
7838
8047
  } catch (error) {
7839
8048
  return undefined
@@ -7930,6 +8139,9 @@ var [ui, setUi] = useState(function () {
7930
8139
  var [previewOpen, setPreviewOpen] = useState(function () { return {} })
7931
8140
  /** path -> {kind:'text',text,saved} | {kind:'image'|'pdf'|'binary'|'too-large'} | {kind:'error',error} */
7932
8141
  var [docs, setDocs] = useState(function () { return {} })
8142
+ // A decompiled dependency opened while Maven was still fetching the real
8143
+ // sources: `{name, decompiledPath, sourcePath}` once they arrive.
8144
+ var [sourceUpgrade, setSourceUpgrade] = useState(null)
7933
8145
  /** Latest docs map for async loaders (state is closure-stale otherwise). */
7934
8146
  var docsRef = useRef(docs)
7935
8147
  docsRef.current = docs
@@ -7989,6 +8201,14 @@ var [ui, setUi] = useState(function () {
7989
8201
  if (event.key !== LOG_FOCUS_KEY || typeof event.newValue !== 'string' || event.newValue === '') return
7990
8202
  var parsed
7991
8203
  try { parsed = JSON.parse(event.newValue) } catch (error) { return }
8204
+ // The broadcast is scoped: a start made in another workspace must not
8205
+ // move THIS window's log pane (two surfaces, two Sessions — m00173-3).
8206
+ var mineSession = typeof sessionId === 'string' ? sessionId : ''
8207
+ var mineCwd = risScopeCwd(typeof cwd === 'string' ? cwd : '')
8208
+ var theirSession = parsed !== null && typeof parsed.sessionId === 'string' ? parsed.sessionId : ''
8209
+ var theirCwd = risScopeCwd(parsed !== null && typeof parsed.cwd === 'string' ? parsed.cwd : '')
8210
+ if (mineSession !== '' && theirSession !== '' && mineSession !== theirSession) return
8211
+ if (mineCwd !== '' && theirCwd !== '' && mineCwd !== theirCwd) return
7992
8212
  var path = parsed !== null && typeof parsed.path === 'string' ? parsed.path : ''
7993
8213
  if (path === '') return
7994
8214
  var found
@@ -8583,6 +8803,306 @@ var [ui, setUi] = useState(function () {
8583
8803
  })
8584
8804
  }
8585
8805
 
8806
+ /**
8807
+ * Ctrl/Cmd+click on a type that is NOT declared in the current file: resolve
8808
+ * `package`/`import` to candidate files, open the first one that reads (a
8809
+ * missing file lands in `docs` as `error`) and ask its editor to reveal the
8810
+ * declaration. Tier 0 of the no-index plan (see docs/dsh-ris-ide/known-issues.md).
8811
+ * @param {{name?: string, path?: string}} payload - from the editor chunk.
8812
+ */
8813
+ function jumpToSymbolInProject(payload) {
8814
+ if (payload === null || payload === undefined) return
8815
+ var name = typeof payload.name === 'string' ? payload.name : ''
8816
+ // Annotation attribute (`@Schema(description = "…")` → `description`): the
8817
+ // target is the annotation type, the selected range is the attribute method.
8818
+ var member = typeof payload.member === 'string' ? payload.member : ''
8819
+ var label = member === '' ? name : name + '.' + member
8820
+ var fromPath = typeof payload.path === 'string' ? payload.path : ''
8821
+ if (name === '') return
8822
+ var fromDoc = docsRef.current[fromPath]
8823
+ var text = fromDoc !== undefined && fromDoc !== null && fromDoc.kind === 'text' ? fromDoc.text : ''
8824
+ // `Receiver.Member` click: the receiver is a class (`SqlMethod.INSERT_ONE`,
8825
+ // `SqlHelper.retBool(...)`), `this`/`super` (field/constant/method of this
8826
+ // type or a parent) or a variable whose declared type we can read (m06015).
8827
+ var receiver = typeof payload.receiver === 'string' ? payload.receiver : ''
8828
+ if (receiver !== '' && member !== '') {
8829
+ jumpToMemberInProject(receiver, member, fromPath, text)
8830
+ return
8831
+ }
8832
+ var remembered = javaTypePathRef.current[name]
8833
+ if (remembered !== undefined) {
8834
+ if (remembered === null) {
8835
+ statusNote('找不到 ' + name + ' 的声明', 8000)
8836
+ return
8837
+ }
8838
+ // A dependency source lives in the host cache and is regenerated when the
8839
+ // jar (or the decompiler) changes; never trust the remembered path for it —
8840
+ // re-resolve so an upgraded jar shows the new source instead of stale text.
8841
+ if (remembered.indexOf('/.dsh-ris-ide/cache/') !== -1) {
8842
+ openDependencySource()
8843
+ return
8844
+ }
8845
+ openPath(remembered)
8846
+ waitAndReveal(remembered, 0)
8847
+ return
8848
+ }
8849
+ var candidates = javaTypeCandidates(cwd, fromPath, text, name)
8850
+ function remember(target) {
8851
+ javaTypePathRef.current[name] = typeof target === 'string' ? target : null
8852
+ }
8853
+ function revealIn(target, attempt, onMissing) {
8854
+ var controls = viewerControlsRef.current[target]
8855
+ if (controls !== undefined && controls !== null && typeof controls.revealSymbol === 'function') {
8856
+ if (controls.revealSymbol(name, member === '' ? undefined : member) === true) { remember(target); return }
8857
+ onMissing()
8858
+ return
8859
+ }
8860
+ if (attempt >= 40) {
8861
+ statusNote('已打开 ' + fileBaseName(target) + ',但编辑器未就绪,无法定位 ' + label, 8000)
8862
+ return
8863
+ }
8864
+ setTimeout(function () { revealIn(target, attempt + 1, onMissing) }, 50)
8865
+ }
8866
+ /** Open `target` first, then reveal `name`; used by both fallbacks. */
8867
+ function waitAndReveal(target, attempt) {
8868
+ var doc = docsRef.current[target]
8869
+ if (doc !== undefined && doc !== null) {
8870
+ if (doc.kind === 'text') {
8871
+ remember(target)
8872
+ revealIn(target, 0, function () {
8873
+ statusNote('已打开 ' + fileBaseName(target) + ',但没找到 ' + label + ' 的声明', 8000)
8874
+ })
8875
+ return
8876
+ }
8877
+ if (doc.kind === 'error' || doc.kind === 'binary') {
8878
+ statusNote('打开 ' + fileBaseName(target) + ' 失败', 8000)
8879
+ return
8880
+ }
8881
+ }
8882
+ if (attempt >= 40) {
8883
+ statusNote('打开 ' + fileBaseName(target) + ' 超时', 8000)
8884
+ return
8885
+ }
8886
+ setTimeout(function () { waitAndReveal(target, attempt + 1) }, 50)
8887
+ }
8888
+ /** A log of a program whose directory contains `path` — the dependency route needs one. */
8889
+ function dependencyLogPath(path) {
8890
+ var list = Array.isArray(props.programs) ? props.programs : []
8891
+ var normalized = typeof path === 'string' ? path.replace(/\\/g, '/') : ''
8892
+ for (var index = 0; index < list.length; index += 1) {
8893
+ var row = list[index]
8894
+ if (row === null || row === undefined) continue
8895
+ var dir = typeof row.dir === 'string' ? row.dir.replace(/\\/g, '/').replace(/\/+$/, '') : ''
8896
+ if (dir === '' || normalized.indexOf(dir + '/') !== 0) continue
8897
+ if (typeof row.logPath === 'string' && row.logPath !== '') return row.logPath
8898
+ }
8899
+ return ''
8900
+ }
8901
+ /** Human label for a member declaration (m06015). */
8902
+ function describeMember(decl) {
8903
+ if (decl.kind === 'method') return decl.static ? '静态方法' : '方法'
8904
+ if (decl.kind === 'constant') return '枚举常量'
8905
+ if (decl.static) return decl.constant ? '静态常量' : '静态字段'
8906
+ return '字段'
8907
+ }
8908
+ /** Read a file's text: the already-opened doc first, then `fs/read`. */
8909
+ function readTextOf(target, onText) {
8910
+ var doc = docsRef.current[target]
8911
+ if (doc !== undefined && doc !== null) { onText(doc.kind === 'text' ? doc.text : ''); return }
8912
+ fsRead(scopeRef.current, target).then(function (body) {
8913
+ onText(body !== null && body !== undefined && body.kind === 'text' ? (body.text || '') : '')
8914
+ }).catch(function () { onText('') })
8915
+ }
8916
+ /** Reveal a member declaration once `target`'s editor is mounted. */
8917
+ function revealMemberAt(target, decl, where) {
8918
+ openPath(target)
8919
+ waitForLine(target, decl, where, 0)
8920
+ }
8921
+ function waitForLine(target, decl, where, attempt) {
8922
+ var controls = viewerControlsRef.current[target]
8923
+ if (controls !== undefined && controls !== null && typeof controls.revealLine === 'function') {
8924
+ if (controls.revealLine(decl.line, decl.column) === true) {
8925
+ statusNote(label + ' · ' + describeMember(decl) + (where === '' ? '' : '(' + where + ')'), 6000)
8926
+ return
8927
+ }
8928
+ statusNote('已打开 ' + fileBaseName(target) + ',但没找到 ' + label + ' 的声明', 8000)
8929
+ return
8930
+ }
8931
+ if (attempt >= 40) { statusNote('打开 ' + fileBaseName(target) + ' 超时', 8000); return }
8932
+ setTimeout(function () { waitForLine(target, decl, where, attempt + 1) }, 50)
8933
+ }
8934
+ function memberNotFound() {
8935
+ statusNote('没有找到 ' + label + ' 的声明(本类、父类与依赖源码里都没有)', 8000)
8936
+ }
8937
+ /** Resolve a simple type name to a file: candidates → workspace search → dependency jar. */
8938
+ function resolveTypePath(typeName, fromPath2, fromText, onPath) {
8939
+ var candidates = javaTypeCandidates(cwd, fromPath2, fromText, typeName)
8940
+ var fileEnding = '/' + typeName + '.java'
8941
+ function next(index) {
8942
+ if (index >= candidates.length) { viaSearch(); return }
8943
+ var target = candidates[index]
8944
+ fsRead(scopeRef.current, target).then(function (body) {
8945
+ if (body !== null && body !== undefined && body.kind === 'text') onPath(target, body.text || '')
8946
+ else next(index + 1)
8947
+ }).catch(function () { next(index + 1) })
8948
+ }
8949
+ function viaSearch() {
8950
+ fsSearch(scopeRef.current, typeName + '.java').then(function (result) {
8951
+ var list = result !== null && result !== undefined && Array.isArray(result.matches)
8952
+ ? result.matches.map(function (item) { return absolutePath(cwd, item) })
8953
+ : []
8954
+ var pick = list.find(function (item) { return item.slice(-fileEnding.length) === fileEnding })
8955
+ if (pick === undefined) { viaDependency(); return }
8956
+ readTextOf(pick, function (text2) { if (text2 !== '') onPath(pick, text2); else viaDependency() })
8957
+ }).catch(viaDependency)
8958
+ }
8959
+ function viaDependency() {
8960
+ var fqn = javaTypeFqn(fromText, typeName)
8961
+ fsDependencySource(scopeRef.current, fqn, dependencyLogPath(fromPath2)).then(function (resolved) {
8962
+ if (resolved === null || resolved === undefined || typeof resolved.path !== 'string' || resolved.path === '') { onPath('', ''); return }
8963
+ readTextOf(resolved.path, function (text2) { onPath(resolved.path, text2) })
8964
+ }).catch(function () { onPath('', '') })
8965
+ }
8966
+ next(0)
8967
+ }
8968
+ /** `this.x` fallback: walk the `extends` chain (≤8 levels) for the declaration. */
8969
+ function walkSuper(source, depth) {
8970
+ var parent = javaSuperClass(source)
8971
+ if (parent === '') { memberNotFound(); return }
8972
+ resolveTypePath(parent, fromPath, source, function (parentPath, parentText) {
8973
+ if (parentPath === '') { memberNotFound(); return }
8974
+ var decl = memberDeclarationIn(parentText, member)
8975
+ if (decl !== null) { revealMemberAt(parentPath, decl, '父类 ' + parent); return }
8976
+ if (depth >= 8) { memberNotFound(); return }
8977
+ walkSuper(parentText, depth + 1)
8978
+ })
8979
+ }
8980
+ /**
8981
+ * Ctrl/Cmd+click on `Receiver.Member`: same-file member first (`this.`),
8982
+ * then the parent chain, then the receiver's class (a class name, or a
8983
+ * variable's declared type) resolved like any cross-file type (m06015).
8984
+ */
8985
+ function jumpToMemberInProject(receiver, memberName, fromPath2, fromText) {
8986
+ if (receiver === 'this' || receiver === 'super') {
8987
+ if (receiver === 'this') {
8988
+ var own = memberDeclarationIn(fromText, memberName)
8989
+ if (own !== null) { revealMemberAt(fromPath2, own, '本类'); return }
8990
+ }
8991
+ walkSuper(fromText, 0)
8992
+ return
8993
+ }
8994
+ var typeName = javaVariableType(fromText, receiver)
8995
+ if (typeName === '') typeName = /^[A-Z]/.test(receiver) ? receiver : ''
8996
+ if (typeName === '') { statusNote('无法判断 ' + receiver + ' 的类型', 8000); return }
8997
+ resolveTypePath(typeName, fromPath2, fromText, function (target, targetText) {
8998
+ if (target === '') { memberNotFound(); return }
8999
+ var decl = memberDeclarationIn(targetText, memberName)
9000
+ if (decl === null) { memberNotFound(); return }
9001
+ revealMemberAt(target, decl, typeName)
9002
+ })
9003
+ }
9004
+
9005
+ /**
9006
+ * Tier 0, fallback 1: locate the file by its LAST name segment anywhere in
9007
+ * the workspace (`Name.java`) and use the `package` path only to break ties
9008
+ * between same-named classes in different modules. This is what makes
9009
+ * cross-project imports work without scanning `pom.xml` (the project's
9010
+ * groupId never appears in the Java source).
9011
+ */
9012
+ function searchWorkspace() {
9013
+ var fileEnding = '/' + name + '.java'
9014
+ var packagePath = javaPackagePath(text)
9015
+ statusNote('正在工作区搜索 ' + name + '.java…')
9016
+ fsSearch(scopeRef.current, name + '.java').then(function (result) {
9017
+ var matches = (result !== null && result !== undefined && Array.isArray(result.matches)) ? result.matches : []
9018
+ var list = matches.map(function (item) { return absolutePath(cwd, item) })
9019
+ var found
9020
+ if (packagePath !== '') {
9021
+ var wanted = '/' + packagePath + fileEnding
9022
+ found = list.find(function (item) { return item.slice(-wanted.length) === wanted })
9023
+ }
9024
+ if (found === undefined) found = list.find(function (item) { return item.slice(-fileEnding.length) === fileEnding })
9025
+ if (found !== undefined) {
9026
+ openPath(found)
9027
+ waitAndReveal(found, 0)
9028
+ return
9029
+ }
9030
+ openDependencySource()
9031
+ }).catch(function () { openDependencySource() })
9032
+ }
9033
+ /**
9034
+ * Tier 0, fallback 2: the class is not in the workspace, so it comes from a
9035
+ * dependency jar. Reuse the debugger's pipeline (sources.jar → the user's
9036
+ * decompiler → javap) through `/dsh-ris-ide/debug/source`; the host caches
9037
+ * the result under `.dsh-ris-ide/cache`, which opens in this editor.
9038
+ */
9039
+ function openDependencySource() {
9040
+ // The clicked file may live in a module that was never started through the
9041
+ // IDE, so there is no program log to name. The host still locates the jar
9042
+ // through any workspace `target/cp.txt` and falls back to the JDK sources
9043
+ // (or `javap`) for platform classes, so an empty log path is fine (m05797).
9044
+ var logPath = dependencyLogPath(fromPath)
9045
+ var fqn = javaTypeFqn(text, name)
9046
+ statusNote('正在解析 ' + fqn + ' 的源码…')
9047
+ fsDependencySource(scopeRef.current, fqn, logPath).then(function (resolved) {
9048
+ if (resolved === undefined || resolved === null || typeof resolved.path !== 'string' || resolved.path === '') {
9049
+ statusNote('找不到 ' + name + ' 的源码(工作区、依赖源码、反编译与 javap 都没有结果)', 8000)
9050
+ return
9051
+ }
9052
+ var dependencyPath = resolved.path
9053
+ // 依赖源码是宿主按 jar/条目指纹重新生成的缓存文件;jar 换版本后路径不变、
9054
+ // 内容会变,已打开的页签必须强制重读,否则一直显示旧版本的源码。
9055
+ var knownDependencyDoc = docsRef.current[dependencyPath]
9056
+ if (knownDependencyDoc !== undefined && knownDependencyDoc !== null) reloadPath(dependencyPath)
9057
+ openPath(dependencyPath)
9058
+ waitAndReveal(dependencyPath, 0)
9059
+ // 已用反编译/javap 兜底:宿主的 `mvn dependency:sources` 仍在后台跑,
9060
+ // 真源码到位后在编辑器顶部提示,可一键切过去。
9061
+ if (resolved.sourcePending === true) pollDependencySources(name, fqn, logPath, dependencyPath)
9062
+ }).catch(function (error) {
9063
+ statusNote('依赖源码解析失败:' + messageOf(error), 8000)
9064
+ })
9065
+ }
9066
+ function waitFor(target, attempt, index) {
9067
+ var doc = docsRef.current[target]
9068
+ if (doc !== undefined && doc !== null) {
9069
+ if (doc.kind === 'text') {
9070
+ revealIn(target, 0, function () { tryCandidate(index + 1) })
9071
+ return
9072
+ }
9073
+ if (doc.kind === 'error' || doc.kind === 'binary') { tryCandidate(index + 1); return }
9074
+ }
9075
+ if (attempt >= 40) {
9076
+ statusNote('打开失败:' + fileBaseName(target), 8000)
9077
+ tryCandidate(index + 1)
9078
+ return
9079
+ }
9080
+ setTimeout(function () { waitFor(target, attempt + 1, index) }, 50)
9081
+ }
9082
+ function tryCandidate(index) {
9083
+ if (index >= candidates.length) {
9084
+ searchWorkspace()
9085
+ return
9086
+ }
9087
+ var target = candidates[index]
9088
+ var known = docsRef.current[target]
9089
+ if (known !== undefined && known !== null) {
9090
+ if (known.kind === 'text') {
9091
+ openPath(target)
9092
+ revealIn(target, 0, function () { tryCandidate(index + 1) })
9093
+ return
9094
+ }
9095
+ if (known.kind === 'error' || known.kind === 'binary') { tryCandidate(index + 1); return }
9096
+ }
9097
+ fsRead(scopeRef.current, target).then(function (doc) {
9098
+ if (doc === null || doc === undefined || doc.kind !== 'text') { tryCandidate(index + 1); return }
9099
+ openPath(target)
9100
+ revealIn(target, 0, function () { tryCandidate(index + 1) })
9101
+ }).catch(function () { tryCandidate(index + 1) })
9102
+ }
9103
+ tryCandidate(0)
9104
+ }
9105
+
8586
9106
  function openPath(target) {
8587
9107
  var path = absolutePath(cwd, target)
8588
9108
  if (debugOpeningRef.current !== true && debugOpenedRef.current.indexOf(path) !== -1) {
@@ -8628,6 +9148,9 @@ var [ui, setUi] = useState(function () {
8628
9148
  note('已在编辑器打开 ' + fileBaseName(request.path) + '(改完保存即生效)')
8629
9149
  }, [configOpenNonce])
8630
9150
  function closePath(path) {
9151
+ // The user closed the decompiled fallback while Maven was still fetching the
9152
+ // sources: dropping the tab means the prompt is no longer wanted (m05607).
9153
+ if (sourceUpgrade !== null && sourceUpgrade !== undefined && sourceUpgrade.decompiledPath === path) setSourceUpgrade(null)
8631
9154
  debugOpenedRef.current = debugOpenedRef.current.filter(function (item) { return item !== path })
8632
9155
  var index = openFiles.indexOf(path)
8633
9156
  if (index === -1) { forgetDoc(path); return }
@@ -8831,7 +9354,7 @@ var [ui, setUi] = useState(function () {
8831
9354
  // Watch this program's log while it starts: mvn compile is quiet, so the
8832
9355
  // view has to switch at click time, not after the spawn settles.
8833
9356
  selectProgram(program)
8834
- broadcastLogFocus(program.logPath)
9357
+ broadcastLogFocus(program.logPath, sessionId, cwd)
8835
9358
  var logPath = typeof program.logPath === 'string' ? program.logPath : ''
8836
9359
  // Same first-output watch as the debug path. Without it the pane can sit on
8837
9360
  // the wrapper's marker/command line forever: a start's output arrives as
@@ -8874,7 +9397,7 @@ var [ui, setUi] = useState(function () {
8874
9397
  /** Restart one program: the host stops it (pidfile released) then starts it. */
8875
9398
  async function consoleRestart(program) {
8876
9399
  selectProgram(program)
8877
- broadcastLogFocus(program.logPath)
9400
+ broadcastLogFocus(program.logPath, sessionId, cwd)
8878
9401
  var logPath = typeof program.logPath === 'string' ? program.logPath : ''
8879
9402
  var baseline = logPath === '' ? undefined : await logSizeOf(logPath)
8880
9403
  statusNote('正在重启 ' + program.name + '…', 0)
@@ -8928,7 +9451,7 @@ var [ui, setUi] = useState(function () {
8928
9451
  setConsoleBusyKind(kind)
8929
9452
  if (kind === 'start') {
8930
9453
  selectProgram(targets[index])
8931
- broadcastLogFocus(targets[index].logPath)
9454
+ broadcastLogFocus(targets[index].logPath, sessionId, cwd)
8932
9455
  }
8933
9456
  try {
8934
9457
  var result = kind === 'start'
@@ -8952,7 +9475,7 @@ var [ui, setUi] = useState(function () {
8952
9475
  }
8953
9476
  async function consoleDebug(program) {
8954
9477
  selectProgram(program)
8955
- broadcastLogFocus(program.logPath)
9478
+ broadcastLogFocus(program.logPath, sessionId, cwd)
8956
9479
  sourcePathRef.current = {}
8957
9480
  setDbg(function () { return { attached: false, port: null, suspended: false, suspendedThreads: [], currentThreadId: null, seq: 0, events: [], breakpoints: globalBreakpointsSnapshot(), threads: [], frames: [], variables: [], missingSource: null, lastError: null } })
8958
9481
  setUi(function (prev) { return Object.assign({}, prev, { busy: true, note: '正在以调试模式重启 ' + program.name + '(Spring 约 40–55s)…' }) })
@@ -9230,7 +9753,7 @@ var [ui, setUi] = useState(function () {
9230
9753
  setActivePath(logPath)
9231
9754
  activePathRef.current = logPath
9232
9755
  }
9233
- broadcastLogFocus(logPath)
9756
+ broadcastLogFocus(logPath, sessionId, cwd)
9234
9757
  }
9235
9758
  var baseline = logPath === '' ? undefined : await logSizeOf(logPath)
9236
9759
  setUi(function (prev) { return Object.assign({}, prev, { busy: true, note: '正在以调试模式重启(Spring 约 40–55s)…' }) })
@@ -10313,6 +10836,7 @@ var [ui, setUi] = useState(function () {
10313
10836
  })
10314
10837
  },
10315
10838
  onSave: function () { void savePath(path) },
10839
+ onSymbolJump: jumpToSymbolInProject,
10316
10840
  onReload: function () { setReloadTick(function (value) { return value + 1 }) },
10317
10841
  onToolbarState: function (state) {
10318
10842
  setViewerStates(function (prev) {
@@ -10338,7 +10862,19 @@ var [ui, setUi] = useState(function () {
10338
10862
  },
10339
10863
  })
10340
10864
  }
10341
- return h('div', { key: path, style: active && previewOpen[path] !== true ? S.filePane : S.filePaneHidden, 'data-file-mounted': path, 'data-file-active': active ? '1' : '0' }, body)
10865
+ var upgrade = sourceUpgrade !== null && sourceUpgrade !== undefined && sourceUpgrade.decompiledPath === path ? sourceUpgrade : null
10866
+ var banner = upgrade === null ? null : h('div', { style: S.sourceUpgradeBar, role: 'status', 'data-source-upgrade': '1' },
10867
+ h('span', { style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
10868
+ '已找到 ' + upgrade.name + ' 的源码(反编译视图可切换)'),
10869
+ h('button', {
10870
+ type: 'button', style: S.button, 'data-source-upgrade-switch': '1',
10871
+ onClick: function () { switchToDependencySource(upgrade) },
10872
+ }, '切换到源码'),
10873
+ h('button', {
10874
+ type: 'button', style: Object.assign({}, S.buttonOff, { padding: '0 4px' }), title: '关闭提示',
10875
+ onClick: function () { setSourceUpgrade(null) },
10876
+ }, '×'))
10877
+ return h('div', { key: path, style: active && previewOpen[path] !== true ? S.filePane : S.filePaneHidden, 'data-file-mounted': path, 'data-file-active': active ? '1' : '0' }, banner, body)
10342
10878
  }
10343
10879
 
10344
10880
  /**
@@ -10741,6 +11277,19 @@ var [ui, setUi] = useState(function () {
10741
11277
  alive ? button(stopGlyph(11), function (event) { event.stopPropagation(); void consoleStop(program) }, { icon: true, width: 25, stop: true, action: 'console-stop', title: '停止 ' + program.name }) : null,
10742
11278
  // ⟳ shares ▶'s green: both (re)start the program, only ■ is red.
10743
11279
  startable ? button('⟳', function (event) { event.stopPropagation(); void consoleRestart(program) }, { icon: true, width: 25, start: true, action: 'console-restart', title: '重启 ' + program.name }) : null,
11280
+ // The IDE console has the same 🌐 as the sidebar console (m03945):
11281
+ // only a frontend serves a page, and only the owning panel can ask
11282
+ // the host where that page is (m04354).
11283
+ program.kind === 'frontend'
11284
+ ? button(siteBusyId === program.id ? '…' : '🌐', function (event) {
11285
+ event.stopPropagation()
11286
+ if (onOpenSite !== null) onOpenSite(program)
11287
+ }, {
11288
+ icon: true, width: 25, off: true, disabled: siteBusyId === program.id, action: 'console-open-site',
11289
+ title: '在系统浏览器打开 ' + program.name + ' 的页面'
11290
+ + (ydsProject ? '(yds 项目:请求自动带上登录 token,免登录)' : ''),
11291
+ })
11292
+ : null,
10744
11293
  program.kind === 'spring' ? button(ideBadgeIcon('bug', 'play', 13), function (event) { event.stopPropagation(); void consoleDebug(program) }, { icon: true, width: 25, debug: true, off: ui.busy, action: 'console-debug', title: '调试 ' + program.name }) : null,
10745
11294
  busy
10746
11295
  ? h('div', {
@@ -11505,13 +12054,16 @@ var [ui, setUi] = useState(function () {
11505
12054
  h('span', null, ' · 断点 ' + (dbg.breakpoints ? dbg.breakpoints.length : 0)),
11506
12055
  h('span', null, ' · 项目 ' + programs.length),
11507
12056
  h('span', null, ' · 文件 ' + openFiles.length + '/' + FILE_LIMIT + (openFiles.filter(isDirty).length > 0 ? '(' + openFiles.filter(isDirty).length + ' 未保存)' : '')),
11508
- h('span', { style: S.spacer }),
11509
- // Transient progress/status: the static key hints moved into the ? help panel.
12057
+ // Transient status area right after the file counter: symbol-navigation
12058
+ // messages ("正在解析依赖源码…", search misses) land here instead of
12059
+ // popping toasts. The newest replaces the previous one; statusNote()
12060
+ // owns the timer, so it fades after a few seconds (m05950).
11510
12061
  h('span', {
11511
- style: Object.assign({}, S.status, { maxWidth: '58%', overflow: 'hidden', textOverflow: 'ellipsis', opacity: 0.8 }),
12062
+ style: Object.assign({}, S.status, { maxWidth: '44%', overflow: 'hidden', textOverflow: 'ellipsis', opacity: 0.85, marginLeft: 6 }),
11512
12063
  'data-ide-status-text': statusText === '' ? '0' : '1',
11513
12064
  title: statusText,
11514
12065
  }, statusText),
12066
+ h('span', { style: S.spacer }),
11515
12067
  // Bottom-RIGHT corner: help, then the session message log.
11516
12068
  h('button', {
11517
12069
  type: 'button', style: S.messageButton, 'data-action': 'help',
@@ -13413,7 +13965,12 @@ var [ui, setUi] = useState(function () {
13413
13965
  * @param {object} scope - owning session.
13414
13966
  * @param {string} className - class name of the frame.
13415
13967
  * @param {string} logPath - the debugged program's log (identifies the program).
13416
- * @returns {Promise<string|undefined>} absolute path of the cached file.
13968
+ */
13969
+ /**
13970
+ * Ask the host for a dependency class's source.
13971
+ * @returns {Promise<{path: string, kind: string, jar: string, sourcePending: boolean}|undefined>}
13972
+ * `sourcePending` means the host answered with decompiled/javap text while
13973
+ * Maven downloads the real sources in the background.
13417
13974
  */
13418
13975
  async function fsDependencySource(scope, className, logPath) {
13419
13976
  var url = routeUrl('dsh-ris-ide/debug/source')
@@ -13422,10 +13979,28 @@ var [ui, setUi] = useState(function () {
13422
13979
  if (routeCwd !== undefined) url.searchParams.set('cwd', routeCwd)
13423
13980
  url.searchParams.set('className', className)
13424
13981
  if (typeof logPath === 'string' && logPath !== '') url.searchParams.set('path', logPath)
13425
- var response = await fetch(url.href, { headers: { accept: 'application/json' } })
13426
- var parsed = await response.json().catch(function () { return null })
13427
- if (!response.ok || parsed === null || parsed.ok !== true) return undefined
13428
- return typeof parsed.path === 'string' && parsed.path !== '' ? parsed.path : undefined
13982
+ // A decompiler jar that wedges used to leave this fetch pending forever (the
13983
+ // editor spinner never stopped). The host now kills the child process; this
13984
+ // is the client-side backstop for a host that is stuck for another reason.
13985
+ var controller = new AbortController()
13986
+ var timer = setTimeout(function () { controller.abort() }, 20000)
13987
+ try {
13988
+ var response = await fetch(url.href, { headers: { accept: 'application/json' }, signal: controller.signal })
13989
+ var parsed = await response.json().catch(function () { return null })
13990
+ if (!response.ok || parsed === null || parsed.ok !== true) return undefined
13991
+ if (typeof parsed.path !== 'string' || parsed.path === '') return undefined
13992
+ return {
13993
+ path: parsed.path,
13994
+ kind: typeof parsed.kind === 'string' ? parsed.kind : '',
13995
+ jar: typeof parsed.jar === 'string' ? parsed.jar : '',
13996
+ sourcePending: parsed.sourcePending === true,
13997
+ }
13998
+ } catch (error) {
13999
+ void error
14000
+ return undefined
14001
+ } finally {
14002
+ clearTimeout(timer)
14003
+ }
13429
14004
  }
13430
14005
 
13431
14006
  /**
@@ -13512,6 +14087,192 @@ var [ui, setUi] = useState(function () {
13512
14087
  * @param {string} path - absolute or cwd-relative path.
13513
14088
  * @returns {string} an absolute, slash-normalized path.
13514
14089
  */
14090
+ /**
14091
+ * `package a.b.c;` → `a/b/c`, or `''` when the file has no package statement.
14092
+ * Tier 0 needs it for BOTH the candidate paths and the by-filename fallback
14093
+ * (`Imported.Name` is located by its LAST segment: the host's gitignore-aware
14094
+ * filename search finds `<Name>.java`, and the package path is only used to
14095
+ * pick the right one when several modules carry the same class name).
14096
+ */
14097
+ function javaPackagePath(text) {
14098
+ var match = /(?:^|\n)\s*package\s+([A-Za-z_$][\w.]*)\s*;/m.exec(typeof text === 'string' ? text : '')
14099
+ return match === null ? '' : match[1].replace(/\./g, '/')
14100
+ }
14101
+
14102
+ /**
14103
+ * Candidate files for a Java type, tier 0: the CURRENT file's `package` and
14104
+ * `import` statements plus the same-directory sibling. No repository index.
14105
+ * Used by the editor's Ctrl/Cmd+click "go to declaration" for types that are
14106
+ * not declared in the file being edited.
14107
+ *
14108
+ * Source roots are derived from the current file's own path (`.../src/main/java/`,
14109
+ * `.../src/test/java/`, plain `.../src/`) and tried BEFORE the workspace root:
14110
+ * Maven/Gradle modules keep sources under `<module>/src/main/java`, so a package
14111
+ * like `cn.com.x.config` does not live at `<workspace>/cn/com/x/config`.
14112
+ */
14113
+ function javaTypeCandidates(cwd, fromPath, text, name) {
14114
+ var root = typeof cwd === 'string' ? cwd.replace(/\\/g, '/').replace(/\/+$/, '') : ''
14115
+ var bases = []
14116
+ function addBase(base) {
14117
+ if (typeof base !== 'string') return
14118
+ var value = base.replace(/\\/g, '/').replace(/\/+$/, '')
14119
+ if (value === '' || bases.indexOf(value) !== -1) return
14120
+ bases.push(value)
14121
+ }
14122
+ var fromNormalized = typeof fromPath === 'string' ? fromPath.replace(/\\/g, '/') : ''
14123
+ // Most specific marker first; the plain `/src/` fallback only applies when the
14124
+ // path carries no Maven/Gradle layout marker (otherwise it just adds noise).
14125
+ var specificRoot = false
14126
+ ;['/src/main/java/', '/src/test/java/'].forEach(function (marker) {
14127
+ var at = fromNormalized.indexOf(marker)
14128
+ if (at === -1) return
14129
+ specificRoot = true
14130
+ addBase(fromNormalized.slice(0, at + marker.length - 1))
14131
+ })
14132
+ if (!specificRoot) {
14133
+ var plainSrc = fromNormalized.indexOf('/src/')
14134
+ if (plainSrc !== -1) addBase(fromNormalized.slice(0, plainSrc + '/src'.length))
14135
+ }
14136
+ addBase(root)
14137
+ if (bases.length === 0) return []
14138
+ var source = typeof text === 'string' ? text : ''
14139
+ var packages = []
14140
+ var wildcards = []
14141
+ var exact = []
14142
+ var pkgMatch = /(?:^|\n)\s*package\s+([A-Za-z_$][\w.]*)\s*;/m.exec(source)
14143
+ if (pkgMatch !== null) packages.push(pkgMatch[1])
14144
+ var importPattern = /(?:^|\n)\s*import\s+(?:static\s+)?([A-Za-z_$][\w.]*\.(?:\*|[A-Za-z_$][\w$]*))\s*;/g
14145
+ var match = importPattern.exec(source)
14146
+ while (match !== null) {
14147
+ var fqn = match[1]
14148
+ if (fqn.slice(-2) === '.*') wildcards.push(fqn.slice(0, -2))
14149
+ else if (fqn.slice(-(name.length + 1)) === '.' + name) exact.push(fqn)
14150
+ match = importPattern.exec(source)
14151
+ }
14152
+ var relatives = []
14153
+ exact.forEach(function (fqn) { relatives.push(fqn) })
14154
+ wildcards.forEach(function (prefix) { relatives.push(prefix + '.' + name) })
14155
+ packages.forEach(function (prefix) { relatives.push(prefix + '.' + name) })
14156
+ var paths = []
14157
+ bases.forEach(function (base) {
14158
+ relatives.forEach(function (relative) {
14159
+ if (typeof relative !== 'string' || relative === '') return
14160
+ var path = base + '/' + relative.replace(/\./g, '/') + '.java'
14161
+ if (paths.indexOf(path) === -1) paths.push(path)
14162
+ })
14163
+ })
14164
+ var slash = typeof fromPath === 'string' ? fromPath.lastIndexOf('/') : -1
14165
+ if (slash > 0) {
14166
+ var sibling = fromPath.slice(0, slash + 1) + name + '.java'
14167
+ if (paths.indexOf(sibling) === -1) paths.push(sibling)
14168
+ }
14169
+ return paths
14170
+ }
14171
+
14172
+ /**
14173
+ * Best fully-qualified name for the class named `name`, derived from the
14174
+ * CURRENT file's imports and package. The debug-source route looks a class
14175
+ * up inside the dependency jars by its FQN path (`a/b/C.class`), so a bare
14176
+ * `Name` never matches — the import list is what turns `R` or `BeanUtils`
14177
+ * into `cn.com...R` / `org.springframework.beans.BeanUtils` (m04476).
14178
+ * @param {string} text - the file being edited.
14179
+ * @param {string} name - simple type name from the click.
14180
+ * @returns {string} dotted FQN, or `name` when no import matches.
14181
+ */
14182
+ function javaTypeFqn(text, name) {
14183
+ var source = typeof text === 'string' ? text : ''
14184
+ var pattern = /(?:^|\n)\s*import\s+(?:static\s+)?([A-Za-z_$][\w.]*\.(?:\*|[A-Za-z_$][\w$]*))\s*;/g
14185
+ var wildcards = []
14186
+ var match = pattern.exec(source)
14187
+ while (match !== null) {
14188
+ var fqn = match[1]
14189
+ if (fqn.slice(-2) === '.*') wildcards.push(fqn.slice(0, -2))
14190
+ else if (fqn.slice(-(name.length + 1)) === '.' + name) return fqn
14191
+ match = pattern.exec(source)
14192
+ }
14193
+ if (wildcards.length > 0) return wildcards[0] + '.' + name
14194
+ var pkg = /(?:^|\n)\s*package\s+([A-Za-z_$][\w.]*)\s*;/m.exec(source)
14195
+ return pkg === null ? name : pkg[1] + '.' + name
14196
+ }
14197
+
14198
+ /**
14199
+ * First declaration of `member` inside a Java type body: a field, an enum
14200
+ * constant or a method. Tier 0 only reads the declaration line — it tells a
14201
+ * constant/field/method apart and whether it is `static` (m06015).
14202
+ * @param {string} source - Java source text.
14203
+ * @param {string} member - member name.
14204
+ * @returns {{line: number, column: number, kind: string, static: boolean, constant: boolean}|null} declaration.
14205
+ */
14206
+ function memberDeclarationIn(source, member) {
14207
+ if (typeof source !== 'string' || source === '' || member === '') return null
14208
+ var lines = source.split('\n')
14209
+ for (var index = 0; index < lines.length; index += 1) {
14210
+ var line = lines[index]
14211
+ var at = line.indexOf(member)
14212
+ if (at < 0) continue
14213
+ var before = line.slice(0, at)
14214
+ var after = line.slice(at + member.length)
14215
+ var head = before
14216
+ .replace(/\b(?:public|private|protected|static|final|abstract|synchronized|native|default|strictfp|volatile|transient)\b/g, '')
14217
+ .replace(/\s+/g, ' ')
14218
+ .trim()
14219
+ if (head !== '' && !/^[A-Za-z_$@][\w$.<>\[\], ?]*$/.test(head)) continue
14220
+ if (/^\s*[\w$.<>\[\],]*\s+\*?$/.test(before) && after.charAt(0) === '.') continue // qualified call `x.member(`
14221
+ var kind = ''
14222
+ if (/^\s*\(/.test(after)) kind = 'method'
14223
+ else if (/^\s*(?:=|;)/.test(after) && head !== '') kind = 'field'
14224
+ else if (/^\s*[,(;]/.test(after) && head === '') kind = 'constant'
14225
+ if (kind === '') continue
14226
+ var isStatic = /\bstatic\b/.test(before)
14227
+ var isFinal = /\bfinal\b/.test(before)
14228
+ return {
14229
+ line: index + 1,
14230
+ column: at + 1,
14231
+ kind: kind,
14232
+ static: isStatic,
14233
+ constant: kind === 'field' && isFinal && /^[A-Z][A-Z0-9_]*$/.test(member),
14234
+ }
14235
+ }
14236
+ return null
14237
+ }
14238
+
14239
+ /**
14240
+ * Declared type of a variable/field/parameter named `name` in THIS file.
14241
+ * @param {string} source - Java source text.
14242
+ * @param {string} name - variable name.
14243
+ * @returns {string} simple type name, or '' when unknown.
14244
+ */
14245
+ function javaVariableType(source, name) {
14246
+ if (typeof source !== 'string' || name === '') return ''
14247
+ var escaped = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
14248
+ var pattern = new RegExp('(?:^|[^\\w$.])((?:[A-Za-z_$][\\w$.]*\\s*(?:<[^;{}()]*>)?\\s*(?:\\[\\s*\\])?\\s+)+)' + escaped + '\\s*(?:=|;|,|\\))', 'm')
14249
+ var match = pattern.exec(source)
14250
+ if (match === null) return ''
14251
+ var typeText = match[1]
14252
+ .replace(/\b(?:public|private|protected|static|final|volatile|transient)\b/g, '')
14253
+ .replace(/<[^>]*>/g, '')
14254
+ .replace(/\[\s*\]/g, '')
14255
+ .replace(/\s+/g, ' ')
14256
+ .trim()
14257
+ if (typeText === '') return ''
14258
+ var simple = typeText.slice(typeText.lastIndexOf(' ') + 1)
14259
+ var dot = simple.lastIndexOf('.')
14260
+ return dot === -1 ? simple : simple.slice(dot + 1)
14261
+ }
14262
+
14263
+ /**
14264
+ * Parent class named in `class X extends Parent`: `{name, path}` in the current
14265
+ * file (best effort, tier 0 — no index).
14266
+ * @param {string} source - Java source text.
14267
+ * @returns {string} parent simple name, or ''.
14268
+ */
14269
+ function javaSuperClass(source) {
14270
+ if (typeof source !== 'string') return ''
14271
+ var match = /\bclass\s+[A-Za-z_$][\w$]*[^{]*?\bextends\s+([A-Za-z_$][\w$.]*)/.exec(source)
14272
+ if (match === null) return ''
14273
+ return match[1].slice(match[1].lastIndexOf('.') + 1)
14274
+ }
14275
+
13515
14276
  function absolutePath(cwd, path) {
13516
14277
  var value = String(path === undefined || path === null ? '' : path).replace(/\\/g, '/')
13517
14278
  if (value === '') return value
@@ -14141,21 +14902,12 @@ var [ui, setUi] = useState(function () {
14141
14902
  return { loading: true, programs: [], root: undefined, dir: undefined, config: undefined, error: undefined, note: prev.note }
14142
14903
  })
14143
14904
  }, [sessionIdentity, cwd])
14144
- // A workspace switch opens a blank DSH session, and a sidebar layout is stored
14145
- // per session — so the blank one has no IDE tab and the panel would sit on an
14146
- // empty pane. Put the tab back on the new session. Capability-checked: hosts
14147
- // without the right-Sidebar service keep working (nothing happens).
14148
- useEffect(function () {
14149
- if (sessionIdentity === '' || props.compact !== true) return
14150
- var sidebar = props.clientCtx !== null && props.clientCtx !== undefined ? props.clientCtx.sidebarRight : undefined
14151
- if (sidebar === undefined || sidebar === null || typeof sidebar.openTab !== 'function') return
14152
- try {
14153
- sidebar.openTab(IDE_TAB_KIND)
14154
- } catch (error) {
14155
- // A host that refuses the tab kind must not break the switch itself.
14156
- void error
14157
- }
14158
- }, [sessionIdentity])
14905
+ // NOTE: this panel must NOT open its own sidebar tab. `openTab()` expands the
14906
+ // sidebar column (a session starts collapsed and empty by design), so doing
14907
+ // it on every session change is what made the console pop open by itself at
14908
+ // the start of a session. The tab is opened by user actions only
14909
+ // (`openIdeTab` from the header/⧉/log routes); a session with no layout yet
14910
+ // simply keeps the panel closed until the user asks for it.
14159
14911
  /** Warm the compact ⧉'s address; a fresh cache makes the click synchronous. */
14160
14912
  function warmCompactRisd() {
14161
14913
  if (typeof sessionId !== 'string' || sessionId === '') return
@@ -14324,9 +15076,17 @@ var [ui, setUi] = useState(function () {
14324
15076
  topics: ['programs'],
14325
15077
  sessionId: sessionId,
14326
15078
  cwd: typeof cwd === 'string' ? cwd : undefined,
14327
- onOpen: function () {
15079
+ // The shared socket serves ONE scope: the console the user is looking at.
15080
+ // A kept-mounted body of another Session stays subscribed but must not
15081
+ // pull the connection (and every panel) to its own workspace.
15082
+ active: typeof sessionId === 'string' && sessionId !== '' && sessionId === liveSidebarSessionOfDocument(),
15083
+ onOpen: function (info) {
14328
15084
  failures = 0
14329
- setStreamOk(true)
15085
+ // The socket carries another panel's scope: poll our own instead of
15086
+ // sitting on rows that will never arrive.
15087
+ var mismatch = info !== null && info !== undefined && info.scopeMismatch === true
15088
+ setStreamOk(mismatch !== true)
15089
+ if (mismatch === true) void refresh(false)
14330
15090
  },
14331
15091
  onError: function (readyState) {
14332
15092
  failures += 1
@@ -14334,6 +15094,15 @@ var [ui, setUi] = useState(function () {
14334
15094
  },
14335
15095
  handlers: {
14336
15096
  programs: function (payload) {
15097
+ // Defence in depth: a frame naming another workspace must never paint
15098
+ // this session's console (the hub already filters by scope, but this
15099
+ // handler is where the rows and the tree root are stored).
15100
+ if (cwdKnown === true && typeof cwd === 'string' && cwd !== '' &&
15101
+ payload !== null && payload !== undefined && typeof payload.root === 'string' && payload.root !== '' &&
15102
+ risScopeCwd(payload.root) !== risScopeCwd(cwd)) {
15103
+ void refresh(false)
15104
+ return
15105
+ }
14337
15106
  setState(function (prev) {
14338
15107
  return {
14339
15108
  loading: false,
@@ -14401,7 +15170,7 @@ var [ui, setUi] = useState(function () {
14401
15170
  setBusyKind(kind)
14402
15171
  if (kind === 'start') {
14403
15172
  setActive(targets[index])
14404
- broadcastLogFocus(targets[index].logPath)
15173
+ broadcastLogFocus(targets[index].logPath, sessionId, cwd)
14405
15174
  }
14406
15175
  var scopeArg = { sessionId: sessionId, cwd: cwd }
14407
15176
  var result
@@ -14438,7 +15207,7 @@ var [ui, setUi] = useState(function () {
14438
15207
  // Show this program's log from the first moment: the start call waits for
14439
15208
  // a pidfile (up to START_WAIT_MS), and Maven compile is silent. The same
14440
15209
  // event moves the standalone IDE window's log pane right away.
14441
- if (boots) { setActive(program); broadcastLogFocus(program.logPath); setCompactLogNonce(function (value) { return value + 1 }) }
15210
+ if (boots) { setActive(program); broadcastLogFocus(program.logPath, sessionId, cwd); setCompactLogNonce(function (value) { return value + 1 }) }
14442
15211
  var scopeArg = { sessionId: sessionId, cwd: cwd }
14443
15212
  var task = kind === 'stop'
14444
15213
  ? requestStop(program.logPath, scopeArg)
@@ -15067,6 +15836,12 @@ var [ui, setUi] = useState(function () {
15067
15836
  // The row the window was opened on (sidebar 🐞): seeds the log pane and
15068
15837
  // turns on auto-debug. `null` = plain workspace window.
15069
15838
  openProgram: active !== null && active !== undefined && typeof active === 'object' ? active : null,
15839
+ // The IDE console renders the same 🌐 as the sidebar rows: the URL/token
15840
+ // resolution and the "one tab at a time" guard stay HERE (this panel owns
15841
+ // the fetch and the note bar), the workbench only draws the button.
15842
+ onOpenSite: openSite,
15843
+ siteBusyId: busySiteId,
15844
+ ydsProject: ydsProject,
15070
15845
  tab: {
15071
15846
  id: PROGRAM_TAB_ID,
15072
15847
  type: PROGRAM_TAB_ID,