教师端的协作编辑器只有高亮和括号匹配,没装 autocompletion —— 老师替学生 写代码时没有下拉补全,只能盲敲。而且语言写死 cpp(),学生写 Python 时老师 看到的是 C 的高亮。 - 求助协议带上语言:help_request 记到 HelpRequest,accept 时写进 Room, room_open 发给两端;认不出的语言一律当 C(老客户端不带这个字段,而它 以前就是写死 C 的) - 新增 help_language / room_language:学生在排队或协作期间切语言,只更新 语言,不动队列位置和房间;已开房就把新语言推给老师,弹框的高亮和补全 实时跟着换 - CollabModal 装上 autocompletion,和学生端用同一套 enhanceCompletion + completeAnyWord;语言→高亮扩展的映射抽到 shared/extensions/language.ts 两端共用,免得再分叉 - 学生端求助按钮合并状态提示:原来按钮旁边还挂一个 n-tag,一行工具栏在 1280 的机房屏上放不下,改成状态全进 label(已求助 · 待接入 / 已求助 · 前面 N 人 / xxx 老师帮你中) 扩展数组变了 vue-codemirror 会整体 reconfigure,但 CM6 对已存在的 compartment 取 `compartments.get() || ext.inner`,collabDoc 那个装 yCollab 的 compartment 内容会被沿用,切语言、切主题都不会把协作弄断 —— 实跑验证过 双向同步、补全下拉、协作中切语言三条路径。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015APGLsyaCUa7XFMYAaCho4
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
type CollabRequestItem,
|
||||
} from "shared/composables/websocket"
|
||||
import { useUserStore } from "shared/store/user"
|
||||
import type { LANGUAGE } from "utils/types"
|
||||
|
||||
export type HelpStatus = "idle" | "pending" | "active"
|
||||
|
||||
@@ -11,6 +12,8 @@ export interface RoomInfo {
|
||||
peerName: string
|
||||
peerRole: "student" | "teacher"
|
||||
problemId: string
|
||||
/** 学生编辑器的语言。教师端的弹框按它选高亮和补全 */
|
||||
language: LANGUAGE
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,8 +101,13 @@ export const useCollabStore = defineStore("collab", () => {
|
||||
peerName: String(data.peer?.name ?? ""),
|
||||
peerRole: data.peer?.role === "teacher" ? "teacher" : "student",
|
||||
problemId: String(data.problemId ?? ""),
|
||||
language: (data.language as LANGUAGE) ?? "C",
|
||||
}
|
||||
return
|
||||
case "room_language":
|
||||
// 学生在协作期间切了语言。只有教师端收得到这条
|
||||
if (room.value) room.value.language = (data.language as LANGUAGE) ?? "C"
|
||||
return
|
||||
case "room_closed":
|
||||
// 不管 reason 一律先归位到 idle:学生这一侧的 socket 发送失败时,
|
||||
// 服务端把它从请求表里摘掉却**发不出**任何纠正性的 help_status
|
||||
@@ -149,8 +157,17 @@ export const useCollabStore = defineStore("collab", () => {
|
||||
notice.value = ""
|
||||
}
|
||||
|
||||
function requestHelp(problemId: string) {
|
||||
ws.send({ type: "help_request", problemId })
|
||||
function requestHelp(problemId: string, language: LANGUAGE) {
|
||||
ws.send({ type: "help_request", problemId, language })
|
||||
}
|
||||
|
||||
/**
|
||||
* 求助期间换了语言。老师那边的高亮和补全按这个值选,不同步过去他就只能对着
|
||||
* 建房那一刻的语言给学生写代码。idle 时不发 —— 服务端压根没有这条求助记录。
|
||||
*/
|
||||
function updateLanguage(language: LANGUAGE) {
|
||||
if (helpStatus.value === "idle") return
|
||||
ws.send({ type: "help_language", language })
|
||||
}
|
||||
|
||||
function cancelHelp() {
|
||||
@@ -198,6 +215,7 @@ export const useCollabStore = defineStore("collab", () => {
|
||||
connect,
|
||||
disconnect,
|
||||
requestHelp,
|
||||
updateLanguage,
|
||||
cancelHelp,
|
||||
accept,
|
||||
reject,
|
||||
|
||||
Reference in New Issue
Block a user