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/README.md +1 -1
- package/lib/client-codemirror.js +516 -11
- package/lib/client.js +832 -57
- package/lib/index.js +533 -48
- package/lib/risd/server.js +12 -3
- package/lib/standalone/window.html +10 -0
- package/package.json +2 -2
- package/test/client-build.test.mjs +3 -0
- package/test/client-viewer.test.mjs +227 -7
- package/test/dsh-window-refresh.test.mjs +45 -5
- package/test/helpers/cmd.mjs +2 -0
- package/test/host-tail.test.mjs +18 -1
- package/test/risd-api.test.mjs +22 -0
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ DSH(DeepSeek Harness)Web GUI 右侧栏里的 **RIS-IDE 本地开发面板**
|
|
|
29
29
|
- **日志**:走一条共享 SSE 实时增量;ANSI/级别着色,默认**只看本次启动**(更早内容向上滚动仍可加载);标题栏 `级 → W+ → E+` 级别过滤、换行开关(真正的 `pre-wrap`/`pre`)、`A−/A+` 字号、跟随/暂停、`Ctrl+F` 查找条、内容溢出时**滚动条常驻可见**;标题栏显示 `运行中 (pid N)` 并可一键**停止服务**(pidfile + `/proc` 校验后才发信号)。
|
|
30
30
|
- **文件树**:git 口径(`.gitignore` 过滤,标题栏眼睛可临时关闭;没有 git 也能用);新建/新建包名/重命名/复制/移动/删除/从系统导入(复制/剪切同时把文件列表写进**系统剪贴板**,可直接粘贴到资源管理器/桌面:WSL 走 PowerShell,Linux 走 xclip/wl-copy,macOS 走 JXA);**Ctrl+点击多选**、`Ctrl+A` 全选、批量复制/剪切/粘贴/拖动/删除(重名自动「 副本」「 副本(n)」,成功提示带「撤销」,一条批量操作只占一次撤销);点文件夹行 = 展开/折叠,换根走右键菜单「**进入**」(行首出现 `↑ 上级` 逐级返回);「新建文件 ▸」hover 在右侧弹出类型面板;新建/重命名/粘贴为/删除确认等弹窗**锚定在鼠标旁**;工作区变更经同一条 SSE **静默**自动刷新,只有标题栏 ⟳ 点击才提示结果。
|
|
31
31
|
- **检索**:同一个框搜**文件名 + 文件内容**(内容走宿主 `git grep -n`、无索引、上限 200 条);两类结果排在一起,首屏 40 行、滚到近底再追加 60 行(末尾提示剩余行数),`↑/↓` + `Enter` 打开;默认指向文件名完全匹配的那行、否则第一行;选中后检索词与结果**保留**,快捷键聚焦时**全选**框内文字;内容命中会把检索词带进编辑器查找框并定位到命中行。
|
|
32
|
-
- **编辑器**:按需加载的 CodeMirror(Java 等语法高亮)、多页签(切换时页签自动滚入可视区)、保存/脏标记、`Ctrl+D` 删行、自绘**两行式查找/替换面板**(查找一行、替换一行,等宽输入框 + 图标按钮 + 匹配计数 + `Aa`/`.*`/`ab` + `↑/↓`/替换/全部替换);**点选区或搜索命中块当次就把光标放进去**;失焦不残留全选色;有未保存页签时关闭页签/刷新页面先确认;`±`
|
|
32
|
+
- **编辑器**:按需加载的 CodeMirror(Java 等语法高亮)、多页签(切换时页签自动滚入可视区)、保存/脏标记、`Ctrl+D` 删行、自绘**两行式查找/替换面板**(查找一行、替换一行,等宽输入框 + 图标按钮 + 匹配计数 + `Aa`/`.*`/`ab` + `↑/↓`/替换/全部替换);**点选区或搜索命中块当次就把光标放进去**;失焦不残留全选色;有未保存页签时关闭页签/刷新页面先确认;`±` 打开与磁盘版本的逐行对比(仅在有未保存修改时可用);按住 Ctrl/Cmd 悬停把同名标识符加下划线,Ctrl/Cmd+点击跳声明(当前文件内变量/类型;跨文件先按 `package`/`import` 与源码根推断、再按类名末级在工作区里找,jar 依赖按「工作区源码 → 本地 `.m2` 同版本 sources.jar → `mvn dependency:sources` 后台拉取 → 反编译 → javap」找源码(`/debug/source` 先返回反编译文本、源码到位后在编辑器顶部提示切换),全链路带超时,无索引);`src/test/java/**/*Test.java` 标题栏出现 **▶ 运行测试**(`mvn -pl <module> test -Dtest=<类>`,输出保留开头 4K + 省略 + 结尾 400K,状态 通过/失败/超时,可重跑)。
|
|
33
33
|
- **预览**:`.md/.markdown/.html/.htm` 编辑/预览切换按钮**悬浮在编辑区右上角**(不占代码行高,预览含未保存修改);超过整读上限的大文本以**只读分页预览**打开(滚到近底取下一页、内存超限释放前文、滚动位置按文件记住),标题栏「编辑」可强制全量加载进编辑(上限 32MB)。
|
|
34
34
|
- **JDWP 调试(仅 Java)**:点行号加断点、双击红点删除(空行/注释行忽略);断点/线程/调用栈/变量/单步/继续;对象与数组懒加载展开、继承字段与空值也列出;依赖 jar 自动取 `-sources.jar`,没有则 `javap` 反汇编,也可在调试面板 ⚙ 填反编译 jar(如 CFR),缓存按 jar 指纹失效并有 64MB/30 天上限回收;命中后自动切「参数」页签、打开源码并高亮当前行;前端程序只能启停/看日志。
|
|
35
35
|
- **独立窗口**:聊天页右上角 **⧉ RIS-IDE**(或控制台标题栏 ⧉)打开,**填满屏幕**、**不加载 DSH 界面/不带会话历史**,与侧栏同一套 `/dsh-ris-ide/*` 路由与 cookie,没有新端口;窗口按**工作空间**单例,从程序目录调试也不会开出第二个。
|
package/lib/client-codemirror.js
CHANGED
|
@@ -29927,6 +29927,464 @@ globalThis.__dshRisIdeChunks__.codemirror = (require) => {
|
|
|
29927
29927
|
}
|
|
29928
29928
|
};
|
|
29929
29929
|
}
|
|
29930
|
+
const SYMBOL_KEYWORDS = /* @__PURE__ */ new Set([
|
|
29931
|
+
"abstract",
|
|
29932
|
+
"assert",
|
|
29933
|
+
"boolean",
|
|
29934
|
+
"break",
|
|
29935
|
+
"byte",
|
|
29936
|
+
"case",
|
|
29937
|
+
"catch",
|
|
29938
|
+
"char",
|
|
29939
|
+
"class",
|
|
29940
|
+
"const",
|
|
29941
|
+
"continue",
|
|
29942
|
+
"default",
|
|
29943
|
+
"do",
|
|
29944
|
+
"double",
|
|
29945
|
+
"else",
|
|
29946
|
+
"enum",
|
|
29947
|
+
"extends",
|
|
29948
|
+
"final",
|
|
29949
|
+
"finally",
|
|
29950
|
+
"float",
|
|
29951
|
+
"for",
|
|
29952
|
+
"goto",
|
|
29953
|
+
"if",
|
|
29954
|
+
"implements",
|
|
29955
|
+
"import",
|
|
29956
|
+
"instanceof",
|
|
29957
|
+
"int",
|
|
29958
|
+
"interface",
|
|
29959
|
+
"long",
|
|
29960
|
+
"native",
|
|
29961
|
+
"new",
|
|
29962
|
+
"package",
|
|
29963
|
+
"private",
|
|
29964
|
+
"protected",
|
|
29965
|
+
"public",
|
|
29966
|
+
"record",
|
|
29967
|
+
"return",
|
|
29968
|
+
"sealed",
|
|
29969
|
+
"short",
|
|
29970
|
+
"static",
|
|
29971
|
+
"strictfp",
|
|
29972
|
+
"super",
|
|
29973
|
+
"switch",
|
|
29974
|
+
"synchronized",
|
|
29975
|
+
"this",
|
|
29976
|
+
"throw",
|
|
29977
|
+
"throws",
|
|
29978
|
+
"transient",
|
|
29979
|
+
"try",
|
|
29980
|
+
"var",
|
|
29981
|
+
"void",
|
|
29982
|
+
"volatile",
|
|
29983
|
+
"while",
|
|
29984
|
+
"true",
|
|
29985
|
+
"false",
|
|
29986
|
+
"null",
|
|
29987
|
+
"yield"
|
|
29988
|
+
]);
|
|
29989
|
+
const SYMBOL_WORD_CHAR = /[A-Za-z0-9_$]/;
|
|
29990
|
+
const SYMBOL_MAX_RANGES = 3e3;
|
|
29991
|
+
const symbolHighlightEffect = StateEffect.define();
|
|
29992
|
+
const symbolHitMark = Decoration.mark({ class: "cm-symbol-hit" });
|
|
29993
|
+
const symbolHighlightField = StateField.define({
|
|
29994
|
+
create: () => Decoration.none,
|
|
29995
|
+
update(decorations, transaction) {
|
|
29996
|
+
for (const effect of transaction.effects) {
|
|
29997
|
+
if (!effect.is(symbolHighlightEffect)) continue;
|
|
29998
|
+
const ranges = Array.isArray(effect.value) ? effect.value : [];
|
|
29999
|
+
if (ranges.length === 0) return Decoration.none;
|
|
30000
|
+
const builder = new RangeSetBuilder();
|
|
30001
|
+
for (const range of ranges) builder.add(range.from, range.to, symbolHitMark);
|
|
30002
|
+
return builder.finish();
|
|
30003
|
+
}
|
|
30004
|
+
return decorations.map(transaction.changes);
|
|
30005
|
+
},
|
|
30006
|
+
provide: (field) => EditorView.decorations.from(field)
|
|
30007
|
+
});
|
|
30008
|
+
const symbolTheme = EditorView.theme({ ".cm-symbol-hit": {
|
|
30009
|
+
textDecoration: "underline",
|
|
30010
|
+
textDecorationThickness: "1px",
|
|
30011
|
+
textUnderlineOffset: "2px",
|
|
30012
|
+
textDecorationColor: "var(--ris-symbol-hit, #2f6feb)"
|
|
30013
|
+
} });
|
|
30014
|
+
/** @param {KeyboardEvent|MouseEvent} event - modifier state source. */
|
|
30015
|
+
function symbolModifierHeld(event) {
|
|
30016
|
+
return event.ctrlKey === true || event.metaKey === true;
|
|
30017
|
+
}
|
|
30018
|
+
/**
|
|
30019
|
+
* The identifier under a document position.
|
|
30020
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30021
|
+
* @param {number|null|undefined} pos - document offset.
|
|
30022
|
+
* @returns {string} the word, or '' for blanks/keywords/numbers.
|
|
30023
|
+
*/
|
|
30024
|
+
function identifierAt(view, pos) {
|
|
30025
|
+
if (pos === null || pos === void 0) return "";
|
|
30026
|
+
const doc = view.state.doc;
|
|
30027
|
+
if (pos < 0 || pos > doc.length) return "";
|
|
30028
|
+
const line = doc.lineAt(pos);
|
|
30029
|
+
const text = line.text;
|
|
30030
|
+
let start = pos - line.from;
|
|
30031
|
+
let end = start;
|
|
30032
|
+
while (start > 0 && SYMBOL_WORD_CHAR.test(text.charAt(start - 1))) start -= 1;
|
|
30033
|
+
while (end < text.length && SYMBOL_WORD_CHAR.test(text.charAt(end))) end += 1;
|
|
30034
|
+
const word = text.slice(start, end);
|
|
30035
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(word)) return "";
|
|
30036
|
+
if (SYMBOL_KEYWORDS.has(word)) return "";
|
|
30037
|
+
return word;
|
|
30038
|
+
}
|
|
30039
|
+
/**
|
|
30040
|
+
* The identifier a Ctrl/Cmd gesture may act on, with Java's declaration lines
|
|
30041
|
+
* taken into account (m05797):
|
|
30042
|
+
* - a `package` line is not a symbol at all (`io.swagger.v3.oas.annotations.tags`
|
|
30043
|
+
* is a name, nothing to jump to);
|
|
30044
|
+
* - in an `import` line only the LAST segment is drillable — `java.lang.annotation`
|
|
30045
|
+
* must not highlight, only `Inherited` in
|
|
30046
|
+
* `import java.lang.annotation.Inherited;` may.
|
|
30047
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30048
|
+
* @param {number|null|undefined} pos - document offset.
|
|
30049
|
+
* @returns {string} the drillable word, or ''.
|
|
30050
|
+
*/
|
|
30051
|
+
function symbolDrillWord(view, pos) {
|
|
30052
|
+
const word = identifierAt(view, pos);
|
|
30053
|
+
if (word === "") return "";
|
|
30054
|
+
if (pos === null || pos === void 0) return "";
|
|
30055
|
+
const doc = view.state.doc;
|
|
30056
|
+
if (pos < 0 || pos > doc.length) return "";
|
|
30057
|
+
const line = doc.lineAt(pos);
|
|
30058
|
+
const text = line.text;
|
|
30059
|
+
const trimmed = text.trim();
|
|
30060
|
+
if (trimmed.startsWith("package")) return "";
|
|
30061
|
+
if (trimmed.startsWith("import")) {
|
|
30062
|
+
let end = pos - line.from;
|
|
30063
|
+
while (end < text.length && SYMBOL_WORD_CHAR.test(text.charAt(end))) end += 1;
|
|
30064
|
+
const rest = text.slice(end).trim();
|
|
30065
|
+
if (rest !== "" && rest !== ";") return "";
|
|
30066
|
+
}
|
|
30067
|
+
return word;
|
|
30068
|
+
}
|
|
30069
|
+
/**
|
|
30070
|
+
* Every occurrence of `word` in the document, as decoration ranges.
|
|
30071
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30072
|
+
* @param {string} word - identifier.
|
|
30073
|
+
* @returns {Array<{from: number, to: number}>} ranges, in document order.
|
|
30074
|
+
*/
|
|
30075
|
+
function symbolRanges(view, word) {
|
|
30076
|
+
if (word === "") return [];
|
|
30077
|
+
const doc = view.state.doc;
|
|
30078
|
+
const pattern = new RegExp("(?<![A-Za-z0-9_$])" + symbolQuote(word) + "(?![A-Za-z0-9_$])", "g");
|
|
30079
|
+
const ranges = [];
|
|
30080
|
+
for (let index = 1; index <= doc.lines && ranges.length < SYMBOL_MAX_RANGES; index += 1) {
|
|
30081
|
+
const line = doc.line(index);
|
|
30082
|
+
let match = pattern.exec(line.text);
|
|
30083
|
+
while (match !== null) {
|
|
30084
|
+
ranges.push({
|
|
30085
|
+
from: line.from + match.index,
|
|
30086
|
+
to: line.from + match.index + word.length
|
|
30087
|
+
});
|
|
30088
|
+
if (ranges.length >= SYMBOL_MAX_RANGES) break;
|
|
30089
|
+
match = pattern.exec(line.text);
|
|
30090
|
+
}
|
|
30091
|
+
pattern.lastIndex = 0;
|
|
30092
|
+
}
|
|
30093
|
+
return ranges;
|
|
30094
|
+
}
|
|
30095
|
+
/** @param {string} text - literal to escape for a RegExp. */
|
|
30096
|
+
function symbolQuote(text) {
|
|
30097
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
30098
|
+
}
|
|
30099
|
+
/**
|
|
30100
|
+
* First declaration of `word` in the document: a type declaration wins over a
|
|
30101
|
+
* variable/parameter declaration (a class name never resolves to a variable).
|
|
30102
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30103
|
+
* @param {string} word - identifier.
|
|
30104
|
+
* @returns {{from: number, to: number}|null} the declaration's range.
|
|
30105
|
+
*/
|
|
30106
|
+
function findSymbolDeclaration(view, word) {
|
|
30107
|
+
if (word === "") return null;
|
|
30108
|
+
const doc = view.state.doc;
|
|
30109
|
+
const name = symbolQuote(word);
|
|
30110
|
+
const modifiers = "(?:(?:public|private|protected|static|final|abstract|sealed|non-sealed|strictfp|transient|volatile|native|synchronized)\\s+)*";
|
|
30111
|
+
const typePattern = new RegExp("^\\s*" + modifiers + "(?:class|interface|enum|record|@interface)\\s+(?:[\\w$]+\\.)*" + name + "\\b");
|
|
30112
|
+
const fieldPattern = new RegExp("^\\s*" + modifiers + "[A-Za-z_$][\\w$.<>\\[\\], ]*\\s+" + name + "\\s*(?:=|;|,|\\))");
|
|
30113
|
+
const localPattern = new RegExp("(?:^|[;{}(,]\\s*)(?:final\\s+)?[A-Za-z_$][\\w$.<>\\[\\], ]*\\s+" + name + "\\s*(?:=|;|,|\\))");
|
|
30114
|
+
const parameterPattern = new RegExp("[(,]\\s*(?:final\\s+)*[A-Za-z_$][\\w$.<>\\[\\], ]*\\s+" + name + "\\s*[,)]");
|
|
30115
|
+
const forEachPattern = new RegExp("for\\s*\\(\\s*[A-Za-z_$][\\w$.<>\\[\\]]*\\s+" + name + "\\s*:");
|
|
30116
|
+
let variableHit = null;
|
|
30117
|
+
for (let index = 1; index <= doc.lines; index += 1) {
|
|
30118
|
+
const line = doc.line(index);
|
|
30119
|
+
const typeMatch = typePattern.exec(line.text);
|
|
30120
|
+
if (typeMatch !== null) {
|
|
30121
|
+
const at = line.from + typeMatch[0].lastIndexOf(word);
|
|
30122
|
+
return {
|
|
30123
|
+
from: at,
|
|
30124
|
+
to: at + word.length
|
|
30125
|
+
};
|
|
30126
|
+
}
|
|
30127
|
+
if (variableHit !== null) continue;
|
|
30128
|
+
const patterns = [
|
|
30129
|
+
fieldPattern,
|
|
30130
|
+
localPattern,
|
|
30131
|
+
parameterPattern,
|
|
30132
|
+
forEachPattern
|
|
30133
|
+
];
|
|
30134
|
+
for (const pattern of patterns) {
|
|
30135
|
+
const match = pattern.exec(line.text);
|
|
30136
|
+
if (match === null) continue;
|
|
30137
|
+
const at = line.from + match[0].lastIndexOf(word);
|
|
30138
|
+
variableHit = {
|
|
30139
|
+
from: at,
|
|
30140
|
+
to: at + word.length
|
|
30141
|
+
};
|
|
30142
|
+
break;
|
|
30143
|
+
}
|
|
30144
|
+
}
|
|
30145
|
+
return variableHit;
|
|
30146
|
+
}
|
|
30147
|
+
/** Select a range and scroll it into the middle of the viewport. */
|
|
30148
|
+
function revealRange(view, from, to) {
|
|
30149
|
+
const docLength = view.state.doc.length;
|
|
30150
|
+
const anchor = Math.max(0, Math.min(docLength, from));
|
|
30151
|
+
const head = Math.max(anchor, Math.min(docLength, to));
|
|
30152
|
+
view.dispatch({
|
|
30153
|
+
selection: {
|
|
30154
|
+
anchor,
|
|
30155
|
+
head
|
|
30156
|
+
},
|
|
30157
|
+
effects: EditorView.scrollIntoView(anchor, { y: "center" })
|
|
30158
|
+
});
|
|
30159
|
+
view.focus();
|
|
30160
|
+
}
|
|
30161
|
+
/**
|
|
30162
|
+
* Is the identifier under the pointer part of an annotation? Two shapes matter:
|
|
30163
|
+
* `@NotBlank` (the annotation type itself) and `@Schema(description = "…")` (one
|
|
30164
|
+
* of the annotation's attributes). The JLS only allows `name = value` inside the
|
|
30165
|
+
* parentheses, so an identifier directly followed by `=` whose innermost `(` is
|
|
30166
|
+
* preceded by `@Type` is an attribute of that annotation.
|
|
30167
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30168
|
+
* @param {number} pos - document offset of the identifier start.
|
|
30169
|
+
* @param {string} word - the identifier under the pointer.
|
|
30170
|
+
* @returns {{name: string, member: string}|null} annotation type (+attribute), or null.
|
|
30171
|
+
*/
|
|
30172
|
+
function annotationContextAt(view, pos, word) {
|
|
30173
|
+
if (word === "") return null;
|
|
30174
|
+
const text = view.state.doc.toString();
|
|
30175
|
+
const start = pos;
|
|
30176
|
+
const end = pos + word.length;
|
|
30177
|
+
if (start > 0 && text.charAt(start - 1) === "@") return {
|
|
30178
|
+
name: word,
|
|
30179
|
+
member: ""
|
|
30180
|
+
};
|
|
30181
|
+
let after = end;
|
|
30182
|
+
while (after < text.length && /\s/.test(text.charAt(after))) after += 1;
|
|
30183
|
+
if (text.charAt(after) !== "=") return null;
|
|
30184
|
+
let depth = 0;
|
|
30185
|
+
let index = start - 1;
|
|
30186
|
+
while (index >= 0) {
|
|
30187
|
+
const ch = text.charAt(index);
|
|
30188
|
+
if (ch === ")") depth += 1;
|
|
30189
|
+
else if (ch === "(") {
|
|
30190
|
+
if (depth === 0) break;
|
|
30191
|
+
depth -= 1;
|
|
30192
|
+
}
|
|
30193
|
+
index -= 1;
|
|
30194
|
+
}
|
|
30195
|
+
if (index < 0) return null;
|
|
30196
|
+
let nameEnd = index - 1;
|
|
30197
|
+
while (nameEnd >= 0 && /\s/.test(text.charAt(nameEnd))) nameEnd -= 1;
|
|
30198
|
+
let nameStart = nameEnd;
|
|
30199
|
+
while (nameStart >= 0 && /[\w$.]/.test(text.charAt(nameStart))) nameStart -= 1;
|
|
30200
|
+
if (text.charAt(nameStart) !== "@") return null;
|
|
30201
|
+
const annotation = text.slice(nameStart + 1, nameEnd + 1);
|
|
30202
|
+
if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(annotation)) return null;
|
|
30203
|
+
return {
|
|
30204
|
+
name: annotation,
|
|
30205
|
+
member: word
|
|
30206
|
+
};
|
|
30207
|
+
}
|
|
30208
|
+
/**
|
|
30209
|
+
* `Receiver.Member` under the pointer: the token before the dot plus the member
|
|
30210
|
+
* after it. `this.entityClass` / `SqlMethod.INSERT_ONE` / `SqlHelper.retBool`
|
|
30211
|
+
* classify differently, so the core needs both halves (m06015).
|
|
30212
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30213
|
+
* @param {number} pos - document position of the pointer.
|
|
30214
|
+
* @returns {{receiver: string, member: string, from: number, to: number}|null} access, if any.
|
|
30215
|
+
*/
|
|
30216
|
+
function memberAccessAt(view, pos) {
|
|
30217
|
+
if (typeof pos !== "number" || pos < 0) return null;
|
|
30218
|
+
const doc = view.state.doc;
|
|
30219
|
+
if (pos >= doc.length) return null;
|
|
30220
|
+
const word = identifierAt(view, pos);
|
|
30221
|
+
if (word === "") return null;
|
|
30222
|
+
let start = pos;
|
|
30223
|
+
while (start > 0 && SYMBOL_WORD_CHAR.test(doc.sliceString(start - 1, start))) start -= 1;
|
|
30224
|
+
if (start === 0 || doc.sliceString(start - 1, start) !== ".") return null;
|
|
30225
|
+
const member = doc.sliceString(start, start + word.length);
|
|
30226
|
+
if (member !== word) return null;
|
|
30227
|
+
let receiverEnd = start - 1;
|
|
30228
|
+
let receiverStart = receiverEnd;
|
|
30229
|
+
while (receiverStart > 0 && SYMBOL_WORD_CHAR.test(doc.sliceString(receiverStart - 1, receiverStart))) receiverStart -= 1;
|
|
30230
|
+
const receiver = doc.sliceString(receiverStart, receiverEnd);
|
|
30231
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(receiver)) return null;
|
|
30232
|
+
return {
|
|
30233
|
+
receiver,
|
|
30234
|
+
member,
|
|
30235
|
+
from: receiverStart,
|
|
30236
|
+
to: start + member.length
|
|
30237
|
+
};
|
|
30238
|
+
}
|
|
30239
|
+
/**
|
|
30240
|
+
* Ctrl/Cmd+click on `Receiver.Member`: a member that lives in this file is
|
|
30241
|
+
* revealed directly; anything else goes to the core, which resolves the receiver
|
|
30242
|
+
* (class name, `this`/`super` chain, or a variable's declared type).
|
|
30243
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30244
|
+
* @param {{receiver: string, member: string}} access - parsed access.
|
|
30245
|
+
* @param {object} options - mount options.
|
|
30246
|
+
* @returns {boolean} true when the click was consumed.
|
|
30247
|
+
*/
|
|
30248
|
+
function jumpToMember(view, access, options) {
|
|
30249
|
+
if (typeof options.onSymbolJump !== "function") return false;
|
|
30250
|
+
options.onSymbolJump({
|
|
30251
|
+
receiver: access.receiver,
|
|
30252
|
+
member: access.member,
|
|
30253
|
+
name: access.receiver,
|
|
30254
|
+
path: typeof options.path === "string" ? options.path : ""
|
|
30255
|
+
});
|
|
30256
|
+
return true;
|
|
30257
|
+
}
|
|
30258
|
+
/**
|
|
30259
|
+
* Declaration of an annotation attribute inside its `@interface` body, e.g.
|
|
30260
|
+
* `String description() default "";`. Used after the annotation type is opened.
|
|
30261
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30262
|
+
* @param {string} member - attribute name.
|
|
30263
|
+
* @returns {{from: number, to: number}|null} the attribute name's range.
|
|
30264
|
+
*/
|
|
30265
|
+
function findAnnotationMemberDeclaration(view, member) {
|
|
30266
|
+
if (member === "") return null;
|
|
30267
|
+
const doc = view.state.doc;
|
|
30268
|
+
const pattern = new RegExp("(?:^|[\\s;{}])(?:[A-Za-z_$][\\w$.<>\\[\\], ]*?)\\s+" + symbolQuote(member) + "\\s*\\(");
|
|
30269
|
+
for (let index = 1; index <= doc.lines; index += 1) {
|
|
30270
|
+
const line = doc.line(index);
|
|
30271
|
+
const match = pattern.exec(line.text);
|
|
30272
|
+
if (match === null) continue;
|
|
30273
|
+
const at = line.from + match[0].lastIndexOf(member);
|
|
30274
|
+
return {
|
|
30275
|
+
from: at,
|
|
30276
|
+
to: at + member.length
|
|
30277
|
+
};
|
|
30278
|
+
}
|
|
30279
|
+
return null;
|
|
30280
|
+
}
|
|
30281
|
+
/**
|
|
30282
|
+
* Chinese-IDE behaviour: Ctrl/Cmd+click a symbol → declaration in this file; a
|
|
30283
|
+
* type that lives elsewhere is handed to `options.onSymbolJump` (`{name, path}`).
|
|
30284
|
+
* @param {import('@codemirror/view').EditorView} view - editor.
|
|
30285
|
+
* @param {string} word - identifier.
|
|
30286
|
+
* @param {object} options - mount options.
|
|
30287
|
+
* @returns {boolean} true when the click was consumed.
|
|
30288
|
+
*/
|
|
30289
|
+
function jumpToSymbol(view, word, options, pos) {
|
|
30290
|
+
const annotation = annotationContextAt(view, typeof pos === "number" ? pos : Math.max(0, view.state.selection.main.head - word.length), word);
|
|
30291
|
+
if (annotation !== null && annotation.member !== "" && typeof options.onSymbolJump === "function") {
|
|
30292
|
+
options.onSymbolJump({
|
|
30293
|
+
name: annotation.name,
|
|
30294
|
+
member: annotation.member,
|
|
30295
|
+
path: typeof options.path === "string" ? options.path : ""
|
|
30296
|
+
});
|
|
30297
|
+
return true;
|
|
30298
|
+
}
|
|
30299
|
+
const found = findSymbolDeclaration(view, word);
|
|
30300
|
+
if (found !== null) {
|
|
30301
|
+
revealRange(view, found.from, found.to);
|
|
30302
|
+
return true;
|
|
30303
|
+
}
|
|
30304
|
+
if (typeof options.onSymbolJump === "function") {
|
|
30305
|
+
options.onSymbolJump({
|
|
30306
|
+
name: word,
|
|
30307
|
+
path: typeof options.path === "string" ? options.path : ""
|
|
30308
|
+
});
|
|
30309
|
+
return true;
|
|
30310
|
+
}
|
|
30311
|
+
return false;
|
|
30312
|
+
}
|
|
30313
|
+
/** Ctrl/Cmd-hover: underline every occurrence of the identifier under the pointer. */
|
|
30314
|
+
const symbolHoverPlugin = ViewPlugin.fromClass(class {
|
|
30315
|
+
constructor(view) {
|
|
30316
|
+
this.view = view;
|
|
30317
|
+
this.modifier = false;
|
|
30318
|
+
this.point = null;
|
|
30319
|
+
this.word = "";
|
|
30320
|
+
this.highlighted = false;
|
|
30321
|
+
this.onMouseMove = this.onMouseMove.bind(this);
|
|
30322
|
+
this.onMouseLeave = this.onMouseLeave.bind(this);
|
|
30323
|
+
this.onKeyDown = this.onKeyDown.bind(this);
|
|
30324
|
+
this.onKeyUp = this.onKeyUp.bind(this);
|
|
30325
|
+
this.onBlur = this.onBlur.bind(this);
|
|
30326
|
+
view.dom.addEventListener("mousemove", this.onMouseMove);
|
|
30327
|
+
view.dom.addEventListener("mouseleave", this.onMouseLeave);
|
|
30328
|
+
window.addEventListener("keydown", this.onKeyDown, true);
|
|
30329
|
+
window.addEventListener("keyup", this.onKeyUp, true);
|
|
30330
|
+
window.addEventListener("blur", this.onBlur);
|
|
30331
|
+
}
|
|
30332
|
+
destroy() {
|
|
30333
|
+
this.view.dom.removeEventListener("mousemove", this.onMouseMove);
|
|
30334
|
+
this.view.dom.removeEventListener("mouseleave", this.onMouseLeave);
|
|
30335
|
+
window.removeEventListener("keydown", this.onKeyDown, true);
|
|
30336
|
+
window.removeEventListener("keyup", this.onKeyUp, true);
|
|
30337
|
+
window.removeEventListener("blur", this.onBlur);
|
|
30338
|
+
this.clear();
|
|
30339
|
+
}
|
|
30340
|
+
onMouseMove(event) {
|
|
30341
|
+
this.point = {
|
|
30342
|
+
x: event.clientX,
|
|
30343
|
+
y: event.clientY
|
|
30344
|
+
};
|
|
30345
|
+
if (this.modifier) this.refresh();
|
|
30346
|
+
else if (this.highlighted) this.clear();
|
|
30347
|
+
}
|
|
30348
|
+
onMouseLeave() {
|
|
30349
|
+
this.point = null;
|
|
30350
|
+
if (this.highlighted) this.clear();
|
|
30351
|
+
}
|
|
30352
|
+
onKeyDown(event) {
|
|
30353
|
+
if (event.key !== "Control" && event.key !== "Meta") return;
|
|
30354
|
+
this.modifier = true;
|
|
30355
|
+
this.refresh();
|
|
30356
|
+
}
|
|
30357
|
+
onKeyUp(event) {
|
|
30358
|
+
if (event.key !== "Control" && event.key !== "Meta") return;
|
|
30359
|
+
this.modifier = false;
|
|
30360
|
+
if (this.highlighted) this.clear();
|
|
30361
|
+
}
|
|
30362
|
+
onBlur() {
|
|
30363
|
+
this.modifier = false;
|
|
30364
|
+
this.point = null;
|
|
30365
|
+
if (this.highlighted) this.clear();
|
|
30366
|
+
}
|
|
30367
|
+
refresh() {
|
|
30368
|
+
if (this.modifier !== true || this.point === null) return;
|
|
30369
|
+
const view = this.view;
|
|
30370
|
+
const word = symbolDrillWord(view, view.posAtCoords(this.point));
|
|
30371
|
+
if (word === this.word && this.highlighted) return;
|
|
30372
|
+
this.word = word;
|
|
30373
|
+
const ranges = symbolRanges(view, word);
|
|
30374
|
+
if (ranges.length === 0) {
|
|
30375
|
+
this.clear();
|
|
30376
|
+
return;
|
|
30377
|
+
}
|
|
30378
|
+
this.highlighted = true;
|
|
30379
|
+
view.dispatch({ effects: symbolHighlightEffect.of(ranges) });
|
|
30380
|
+
}
|
|
30381
|
+
clear() {
|
|
30382
|
+
this.word = "";
|
|
30383
|
+
if (!this.highlighted) return;
|
|
30384
|
+
this.highlighted = false;
|
|
30385
|
+
this.view.dispatch({ effects: symbolHighlightEffect.of([]) });
|
|
30386
|
+
}
|
|
30387
|
+
});
|
|
29930
30388
|
/**
|
|
29931
30389
|
* Mount CodeMirror into one element.
|
|
29932
30390
|
* @param {HTMLElement} parent - the host element (the React component owns it).
|
|
@@ -29986,6 +30444,11 @@ globalThis.__dshRisIdeChunks__.codemirror = (require) => {
|
|
|
29986
30444
|
createPanel: ideFindPanel
|
|
29987
30445
|
}),
|
|
29988
30446
|
highlightSelectionMatches(),
|
|
30447
|
+
...options.symbolNavigation === false ? [] : [
|
|
30448
|
+
symbolHighlightField,
|
|
30449
|
+
symbolTheme,
|
|
30450
|
+
symbolHoverPlugin
|
|
30451
|
+
],
|
|
29989
30452
|
keymap.of([
|
|
29990
30453
|
{
|
|
29991
30454
|
key: "Mod-s",
|
|
@@ -30057,17 +30520,33 @@ globalThis.__dshRisIdeChunks__.codemirror = (require) => {
|
|
|
30057
30520
|
debugLineField,
|
|
30058
30521
|
readOnlyCompartment.of(EditorState.readOnly.of(options.readOnly === true)),
|
|
30059
30522
|
themeCompartment.of(surfaceTheme(Number(options.fontSize) || 12.5)),
|
|
30060
|
-
EditorView.domEventHandlers({
|
|
30061
|
-
|
|
30062
|
-
|
|
30063
|
-
|
|
30064
|
-
|
|
30065
|
-
|
|
30066
|
-
|
|
30067
|
-
|
|
30068
|
-
|
|
30069
|
-
|
|
30070
|
-
|
|
30523
|
+
EditorView.domEventHandlers({
|
|
30524
|
+
mousedown(event, instance) {
|
|
30525
|
+
if (options.symbolNavigation === false) return false;
|
|
30526
|
+
if (event.button !== 0 || !symbolModifierHeld(event)) return false;
|
|
30527
|
+
const pos = instance.posAtCoords({
|
|
30528
|
+
x: event.clientX,
|
|
30529
|
+
y: event.clientY
|
|
30530
|
+
});
|
|
30531
|
+
const word = symbolDrillWord(instance, pos);
|
|
30532
|
+
if (word === "") return false;
|
|
30533
|
+
event.preventDefault();
|
|
30534
|
+
const access = memberAccessAt(instance, pos);
|
|
30535
|
+
if (access !== null) return jumpToMember(instance, access, options);
|
|
30536
|
+
return jumpToSymbol(instance, word, options, pos);
|
|
30537
|
+
},
|
|
30538
|
+
contextmenu(event, instance) {
|
|
30539
|
+
if (typeof options.onContextMenu !== "function") return false;
|
|
30540
|
+
event.preventDefault();
|
|
30541
|
+
event.stopPropagation();
|
|
30542
|
+
options.onContextMenu({
|
|
30543
|
+
x: event.clientX,
|
|
30544
|
+
y: event.clientY,
|
|
30545
|
+
items: editorMenuItems(instance, options)
|
|
30546
|
+
});
|
|
30547
|
+
return true;
|
|
30548
|
+
}
|
|
30549
|
+
}),
|
|
30071
30550
|
EditorView.updateListener.of((update) => {
|
|
30072
30551
|
if (!update.docChanged) return;
|
|
30073
30552
|
if (typeof options.onChange === "function") options.onChange(update.state.doc.toString());
|
|
@@ -30105,6 +30584,32 @@ globalThis.__dshRisIdeChunks__.codemirror = (require) => {
|
|
|
30105
30584
|
getValue() {
|
|
30106
30585
|
return view.state.doc.toString();
|
|
30107
30586
|
},
|
|
30587
|
+
/**
|
|
30588
|
+
* Reveal and select the declaration of `name` in this document — the second
|
|
30589
|
+
* half of a cross-file Ctrl/Cmd-click (the core opens the file, then calls
|
|
30590
|
+
* this once the editor for it exists).
|
|
30591
|
+
* @param {string} name - identifier.
|
|
30592
|
+
* @returns {boolean} true when a declaration was found.
|
|
30593
|
+
*/
|
|
30594
|
+
revealSymbol(name, member) {
|
|
30595
|
+
const attribute = typeof member === "string" && member !== "" ? findAnnotationMemberDeclaration(view, member) : null;
|
|
30596
|
+
const found = attribute !== null ? attribute : findSymbolDeclaration(view, typeof name === "string" ? name : "");
|
|
30597
|
+
if (found === null) return false;
|
|
30598
|
+
revealRange(view, found.from, found.to);
|
|
30599
|
+
return true;
|
|
30600
|
+
},
|
|
30601
|
+
/**
|
|
30602
|
+
* Reveal a line (1-based) and put the caret on `column` (1-based).
|
|
30603
|
+
* @param {number} line - 1-based line.
|
|
30604
|
+
* @param {number} [column] - 1-based column.
|
|
30605
|
+
*/
|
|
30606
|
+
revealLine(line, column) {
|
|
30607
|
+
const total = view.state.doc.lines;
|
|
30608
|
+
const target = Math.max(1, Math.min(total, Math.floor(Number(line) || 1)));
|
|
30609
|
+
const row = view.state.doc.line(target);
|
|
30610
|
+
const offset = Math.max(0, Math.min(row.text.length, Math.floor(Number(column) || 1) - 1));
|
|
30611
|
+
revealRange(view, row.from + offset, row.from + offset);
|
|
30612
|
+
},
|
|
30108
30613
|
/** Replace the whole document without reporting it as a user edit. */
|
|
30109
30614
|
setDoc(text) {
|
|
30110
30615
|
view.dispatch({ changes: {
|