Skip to content

Decouple code editor runtime dependencies#3088

Merged
nighca merged 1 commit into
goplus:devfrom
nighca:issue-3085
Apr 29, 2026
Merged

Decouple code editor runtime dependencies#3088
nighca merged 1 commit into
goplus:devfrom
nighca:issue-3085

Conversation

@nighca
Copy link
Copy Markdown
Collaborator

@nighca nighca commented Apr 28, 2026

Closes #3084
Closes #3085

Summary

  • Define the code editor's own Copilot capability interface so the generic XGo editor no longer depends on the Copilot module directly.
  • Inject History into the generic CodeEditor instance so XGo code editor UI no longer depends on SPX EditorContextProvider.
  • Relocate the generic XGo code editor to src/components/xgo-code-editor and update consumers to import it through @/components/xgo-code-editor.
  • Relocate the SPX code editor to src/components/editor/spx-code-editor and update editor consumers to use the new module path.
  • Update lint/prettier ignore paths and fix the SPX LSP declaration symlink after the directory move.

Tests

  • npm run type-check
  • npm run test -- --run src/components/xgo-code-editor/common.test.ts src/components/editor/spx-code-editor/common.test.ts
  • npm run lint

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread spx-gui/src/components/editor/code-editor/xgo-code-editor/ui/code-editor-ui.ts Outdated
@nighca nighca marked this pull request as ready for review April 28, 2026 03:33
Copilot AI review requested due to automatic review settings April 28, 2026 03:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in xgo-code-editor/ui/copilot.ts to avoid importing Copilot module types.
  • Threads an optional copilot capability prop into xgo-code-editor’s CodeEditorUI.vue and registers Copilot commands only when provided.
  • Updates the spx-code-editor wrapper 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.

Comment thread spx-gui/src/components/editor/code-editor/xgo-code-editor/index.ts Outdated
Copy link
Copy Markdown
Contributor

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread spx-gui/src/components/editor/code-editor/xgo-code-editor/ui/CodeEditorUI.vue Outdated
Comment thread spx-gui/src/components/editor/code-editor/xgo-code-editor/ui/copilot.ts Outdated
Comment thread spx-gui/src/components/xgo-code-editor/copilot.ts
Comment thread spx-gui/src/components/editor/code-editor/xgo-code-editor/index.ts Outdated
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'
Copy link
Copy Markdown
Collaborator Author

@nighca nighca Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这次还调整了 xgo-code-editor/spx-code-editor/ 的位置,新位置是:

  • src/components/xgo-code-editor:为了突出 xgo-code-editor 不再是 (spx) editor 的一部分,默认也不应该再去依赖后者对应的 editor context
  • src/components/editor/spx-code-editorxgo-code-editor 挪走后干掉了不必要的 code-editor/ 这一层级

constructor(
private mainTextDocumentId: TextDocumentIdentifier,
public project: IXGoProject,
private codeEditor: CodeEditor,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeEditorUIController 的多个外部依赖合并为了对 CodeEditor 实例的依赖


export type CodeEditorParams = {
project: IXGoProject
history: History
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

historycopilot 走 class CodeEditor 的构造函数参数传进来,避免由 xgo-code-editor 内部逻辑自己去硬编码依赖

Copy link
Copy Markdown
Collaborator

@cn0809 cn0809 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nighca nighca merged commit 408b30d into goplus:dev Apr 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants