Decouple code editor runtime dependencies#3088
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Copilot integration by introducing a new ICodeEditorCopilot interface and decoupling the CodeEditorUIController from the concrete Copilot implementation. The copilot instance is now passed as an optional prop to CodeEditorUI.vue and handled as a nullable dependency within the controller. A potential issue was identified in code-editor-ui.ts where the copilot parameter in registerCopilotCommands shadows the class property, which could lead to confusion during maintenance.
There was a problem hiding this comment.
Pull request overview
Decouples the generic xgo-code-editor UI layer from the Copilot runtime by introducing an editor-owned Copilot capability interface and making Copilot command registration conditional, enabling the editor to run in environments where the Copilot module is absent (e.g. external widgets).
Changes:
- Introduces
ICodeEditorCopilot+ minimal topic shape inxgo-code-editor/ui/copilot.tsto avoid importing Copilot module types. - Threads an optional
copilotcapability prop intoxgo-code-editor’sCodeEditorUI.vueand registers Copilot commands only when provided. - Updates the
spx-code-editorwrapper to pass the injected Copilot instance into the generic editor UI.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spx-gui/src/components/editor/code-editor/xgo-code-editor/ui/copilot.ts | Adds editor-defined Copilot capability and topic shape (no Copilot module import). |
| spx-gui/src/components/editor/code-editor/xgo-code-editor/ui/code-editor-ui.ts | Switches Copilot dependency to optional capability; conditional command registration. |
| spx-gui/src/components/editor/code-editor/xgo-code-editor/ui/CodeEditorUI.vue | Adds optional copilot prop and passes it to controller. |
| spx-gui/src/components/editor/code-editor/xgo-code-editor/index.ts | Re-exports Copilot-related editor types from the xgo-code-editor public entry. |
| spx-gui/src/components/editor/code-editor/spx-code-editor/ui/CodeEditorUI.vue | Supplies the Copilot instance from SPX context to the generic editor UI. |
| spx-gui/src/components/copilot/context.ts | Minor null-check style change when validating injected Copilot. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Clean decoupling: the XGo code editor no longer imports from the Copilot module, and Copilot capability is wired in as an optional prop. The structural inversion is sound, the null-guard pattern is consistent with project conventions, and the minimal interface captures exactly what the editor calls. A few points worth addressing below.
4be441e to
5447589
Compare
Co-authored-by: Copilot <copilot@github.com>
| import SoundRecorderModal from '../editor/stage/sound/SoundRecorderModal.vue' | ||
| import { useEditorCtx } from '../editor/EditorContextProvider.vue' | ||
| import { useCodeEditor, useRenameWarning, getResourceIdentifier } from '../editor/code-editor/spx-code-editor' | ||
| import { useCodeEditor, useRenameWarning, getResourceIdentifier } from '../editor/spx-code-editor' |
There was a problem hiding this comment.
这次还调整了 xgo-code-editor/ 和 spx-code-editor/ 的位置,新位置是:
src/components/xgo-code-editor:为了突出xgo-code-editor不再是 (spx) editor 的一部分,默认也不应该再去依赖后者对应的 editor contextsrc/components/editor/spx-code-editor:xgo-code-editor挪走后干掉了不必要的code-editor/这一层级
| constructor( | ||
| private mainTextDocumentId: TextDocumentIdentifier, | ||
| public project: IXGoProject, | ||
| private codeEditor: CodeEditor, |
There was a problem hiding this comment.
把 CodeEditorUIController 的多个外部依赖合并为了对 CodeEditor 实例的依赖
|
|
||
| export type CodeEditorParams = { | ||
| project: IXGoProject | ||
| history: History |
There was a problem hiding this comment.
history 和 copilot 走 class CodeEditor 的构造函数参数传进来,避免由 xgo-code-editor 内部逻辑自己去硬编码依赖
Closes #3084
Closes #3085
Summary
src/components/xgo-code-editorand update consumers to import it through@/components/xgo-code-editor.src/components/editor/spx-code-editorand update editor consumers to use the new module path.Tests
npm run type-checknpm run test -- --run src/components/xgo-code-editor/common.test.ts src/components/editor/spx-code-editor/common.test.tsnpm run lint