dsh-ris-ide 1.8.4 → 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')
@@ -2054,6 +2058,7 @@ window.__ModuleLoader__.load({
2054
2058
  /** Every open file stays mounted; inactive panes only collapse. */
2055
2059
  filePanes: { flex: '1 1 0', minHeight: 0, display: 'flex', flexDirection: 'column', position: 'relative' },
2056
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' },
2057
2062
  filePaneHidden: { display: 'none' },
2058
2063
  /** Read-only preview of a file above the whole-read limit (windowed). */
2059
2064
  largeText: { flex: '1 1 0', minHeight: 0, display: 'flex', flexDirection: 'column', overflow: 'hidden' },
@@ -7336,6 +7341,19 @@ window.__ModuleLoader__.load({
7336
7341
  }
7337
7342
 
7338
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
+
7339
7357
  function IdeCodeMirror(props) {
7340
7358
  var S = stylesFor(props && typeof props.fontRatio === 'number' ? props.fontRatio : 1)
7341
7359
  var hostRef = useRef(null)
@@ -7348,6 +7366,7 @@ window.__ModuleLoader__.load({
7348
7366
  onSave: props.onSave,
7349
7367
  onToggleBreakpoint: props.onToggleBreakpoint,
7350
7368
  onToolbarState: props.onToolbarState,
7369
+ onSymbolJump: props.onSymbolJump,
7351
7370
  }
7352
7371
  useEffect(function () {
7353
7372
  var host = hostRef.current
@@ -7355,6 +7374,7 @@ window.__ModuleLoader__.load({
7355
7374
  var handle = props.chunk.mount(host, {
7356
7375
  doc: typeof props.text === 'string' ? props.text : '',
7357
7376
  path: typeof props.path === 'string' ? props.path : '',
7377
+ symbolNavigation: symbolNavigationPath(typeof props.path === 'string' ? props.path : ''),
7358
7378
  onContextMenu: function (payload) {
7359
7379
  if (typeof props.onEditorMenu === 'function') props.onEditorMenu(payload)
7360
7380
  },
@@ -7384,6 +7404,10 @@ window.__ModuleLoader__.load({
7384
7404
  var callbacks = callbacksRef.current
7385
7405
  if (typeof callbacks.onToggleBreakpoint === 'function') callbacks.onToggleBreakpoint(line)
7386
7406
  },
7407
+ onSymbolJump: function (payload) {
7408
+ var callbacks = callbacksRef.current
7409
+ if (typeof callbacks.onSymbolJump === 'function') callbacks.onSymbolJump(payload)
7410
+ },
7387
7411
  })
7388
7412
  handleRef.current = handle
7389
7413
  // Expose the handle so the workspace content search can drive the find
@@ -7902,6 +7926,76 @@ var [ui, setUi] = useState(function () {
7902
7926
  var debugOpeningRef = useRef(false)
7903
7927
  /** className → absolute source path (a step storm must not re-search). */
7904
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
+
7905
7999
 
7906
8000
  /**
7907
8001
  * The on-disk source path of a class reported by the debugger.
@@ -7916,7 +8010,9 @@ var [ui, setUi] = useState(function () {
7916
8010
  var cleaned = String(className === undefined || className === null ? '' : className).replace(/\$.*$/, '').trim()
7917
8011
  if (cleaned === '') return undefined
7918
8012
  var remembered = sourcePathRef.current[cleaned]
7919
- 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
7920
8016
  var relativeSuffix = sourceRelativeSuffix(cleaned)
7921
8017
  var fileEnding = '/' + cleaned.split('.').pop() + '.java'
7922
8018
  try {
@@ -7925,16 +8021,28 @@ var [ui, setUi] = useState(function () {
7925
8021
  var found = candidates.find(function (item) { return item.endsWith('/' + relativeSuffix) })
7926
8022
  if (found === undefined) found = candidates.find(function (item) { return item.endsWith(fileEnding) })
7927
8023
  if (found === undefined) {
7928
- // Not in the workspace: it is a dependency class. Ask the host to pull
7929
- // it out of a `-sources.jar`, decompile it, or at least javap it (the
7930
- // 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.
7931
8028
  statusNote('正在获取依赖源码:' + cleaned + '…', 0)
7932
- 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)
7933
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
7934
8043
  }
7935
- // Cache a MISS as well: stepping through a JDK/dependency class would
7936
- // otherwise re-scan the workspace (`fsSearch`) on every single frame.
7937
- sourcePathRef.current[cleaned] = found === undefined ? null : found
8044
+ sourcePathRef.current[cleaned] = found
8045
+ delete sourceMissRef.current[cleaned]
7938
8046
  return found
7939
8047
  } catch (error) {
7940
8048
  return undefined
@@ -8031,6 +8139,9 @@ var [ui, setUi] = useState(function () {
8031
8139
  var [previewOpen, setPreviewOpen] = useState(function () { return {} })
8032
8140
  /** path -> {kind:'text',text,saved} | {kind:'image'|'pdf'|'binary'|'too-large'} | {kind:'error',error} */
8033
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)
8034
8145
  /** Latest docs map for async loaders (state is closure-stale otherwise). */
8035
8146
  var docsRef = useRef(docs)
8036
8147
  docsRef.current = docs
@@ -8692,6 +8803,306 @@ var [ui, setUi] = useState(function () {
8692
8803
  })
8693
8804
  }
8694
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
+
8695
9106
  function openPath(target) {
8696
9107
  var path = absolutePath(cwd, target)
8697
9108
  if (debugOpeningRef.current !== true && debugOpenedRef.current.indexOf(path) !== -1) {
@@ -8737,6 +9148,9 @@ var [ui, setUi] = useState(function () {
8737
9148
  note('已在编辑器打开 ' + fileBaseName(request.path) + '(改完保存即生效)')
8738
9149
  }, [configOpenNonce])
8739
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)
8740
9154
  debugOpenedRef.current = debugOpenedRef.current.filter(function (item) { return item !== path })
8741
9155
  var index = openFiles.indexOf(path)
8742
9156
  if (index === -1) { forgetDoc(path); return }
@@ -10422,6 +10836,7 @@ var [ui, setUi] = useState(function () {
10422
10836
  })
10423
10837
  },
10424
10838
  onSave: function () { void savePath(path) },
10839
+ onSymbolJump: jumpToSymbolInProject,
10425
10840
  onReload: function () { setReloadTick(function (value) { return value + 1 }) },
10426
10841
  onToolbarState: function (state) {
10427
10842
  setViewerStates(function (prev) {
@@ -10447,7 +10862,19 @@ var [ui, setUi] = useState(function () {
10447
10862
  },
10448
10863
  })
10449
10864
  }
10450
- 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)
10451
10878
  }
10452
10879
 
10453
10880
  /**
@@ -11627,13 +12054,16 @@ var [ui, setUi] = useState(function () {
11627
12054
  h('span', null, ' · 断点 ' + (dbg.breakpoints ? dbg.breakpoints.length : 0)),
11628
12055
  h('span', null, ' · 项目 ' + programs.length),
11629
12056
  h('span', null, ' · 文件 ' + openFiles.length + '/' + FILE_LIMIT + (openFiles.filter(isDirty).length > 0 ? '(' + openFiles.filter(isDirty).length + ' 未保存)' : '')),
11630
- h('span', { style: S.spacer }),
11631
- // 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).
11632
12061
  h('span', {
11633
- 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 }),
11634
12063
  'data-ide-status-text': statusText === '' ? '0' : '1',
11635
12064
  title: statusText,
11636
12065
  }, statusText),
12066
+ h('span', { style: S.spacer }),
11637
12067
  // Bottom-RIGHT corner: help, then the session message log.
11638
12068
  h('button', {
11639
12069
  type: 'button', style: S.messageButton, 'data-action': 'help',
@@ -13535,7 +13965,12 @@ var [ui, setUi] = useState(function () {
13535
13965
  * @param {object} scope - owning session.
13536
13966
  * @param {string} className - class name of the frame.
13537
13967
  * @param {string} logPath - the debugged program's log (identifies the program).
13538
- * @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.
13539
13974
  */
13540
13975
  async function fsDependencySource(scope, className, logPath) {
13541
13976
  var url = routeUrl('dsh-ris-ide/debug/source')
@@ -13544,10 +13979,28 @@ var [ui, setUi] = useState(function () {
13544
13979
  if (routeCwd !== undefined) url.searchParams.set('cwd', routeCwd)
13545
13980
  url.searchParams.set('className', className)
13546
13981
  if (typeof logPath === 'string' && logPath !== '') url.searchParams.set('path', logPath)
13547
- var response = await fetch(url.href, { headers: { accept: 'application/json' } })
13548
- var parsed = await response.json().catch(function () { return null })
13549
- if (!response.ok || parsed === null || parsed.ok !== true) return undefined
13550
- 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
+ }
13551
14004
  }
13552
14005
 
13553
14006
  /**
@@ -13634,6 +14087,192 @@ var [ui, setUi] = useState(function () {
13634
14087
  * @param {string} path - absolute or cwd-relative path.
13635
14088
  * @returns {string} an absolute, slash-normalized path.
13636
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
+
13637
14276
  function absolutePath(cwd, path) {
13638
14277
  var value = String(path === undefined || path === null ? '' : path).replace(/\\/g, '/')
13639
14278
  if (value === '') return value