From d12a9992630666dd658b38b93e1fc1538a4b6ac7 Mon Sep 17 00:00:00 2001 From: wuxinyi Date: Wed, 27 Aug 2025 17:54:50 +0800 Subject: [PATCH 1/2] feat(code-editor): add locale setting to language server --- spx-gui/src/components/editor/code-editor/code-editor.ts | 9 +++++++++ spx-gui/src/components/editor/code-editor/lsp/index.ts | 7 +++++++ .../components/editor/code-editor/ui/CodeEditorUI.vue | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/spx-gui/src/components/editor/code-editor/code-editor.ts b/spx-gui/src/components/editor/code-editor/code-editor.ts index 6cdfbee00..c5f83d22f 100644 --- a/spx-gui/src/components/editor/code-editor/code-editor.ts +++ b/spx-gui/src/components/editor/code-editor/code-editor.ts @@ -728,6 +728,15 @@ export class CodeEditor extends Disposable { this.hoverProvider = new HoverProvider(this.lspClient, this.documentBase) } + async setLocale(locale: string) { + await this.lspClient.initialize({ signal: new AbortController().signal }, { + processId: null, + rootUri: null, + capabilities: {}, + locale + }) + } + private registerMCPTools(): void { // Register tools for code editor this.registry.registerTools( diff --git a/spx-gui/src/components/editor/code-editor/lsp/index.ts b/spx-gui/src/components/editor/code-editor/lsp/index.ts index f32f06474..221637e6a 100644 --- a/spx-gui/src/components/editor/code-editor/lsp/index.ts +++ b/spx-gui/src/components/editor/code-editor/lsp/index.ts @@ -232,6 +232,13 @@ export class SpxLSPClient extends Disposable { }) } + async initialize( + ctx: RequestContext, + params: lsp.InitializeParams + ): Promise { + return this.request(ctx, lsp.InitializeRequest.method, params) + } + async workspaceExecuteCommandSpxGetDefinitions( ctx: RequestContext, ...params: spxGetDefinitions.Arguments diff --git a/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue b/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue index 3ee82c3d3..317d11799 100644 --- a/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue +++ b/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue @@ -214,10 +214,19 @@ watch( signal.addEventListener('abort', () => { codeEditorCtx.mustEditor().detachUI(ui) }) + + await codeEditorCtx.mustEditor().setLocale(i18n.lang.value) }, { immediate: true } ) +watch( + () => i18n.lang.value, + async (newLang) => { + await codeEditorCtx.mustEditor().setLocale(newLang) + } +) + const codeEditorUICtx = computedShallowReactive(() => ({ ui: uiRef.value })) From 0b484d09caf90cc794ab07668ae49ca57f842679 Mon Sep 17 00:00:00 2001 From: wuxinyi Date: Wed, 27 Aug 2025 17:56:14 +0800 Subject: [PATCH 2/2] refactor(code-editor): simplify initialization method formatting --- .../components/editor/code-editor/code-editor.ts | 15 +++++++++------ .../components/editor/code-editor/lsp/index.ts | 5 +---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spx-gui/src/components/editor/code-editor/code-editor.ts b/spx-gui/src/components/editor/code-editor/code-editor.ts index c5f83d22f..a36642f9e 100644 --- a/spx-gui/src/components/editor/code-editor/code-editor.ts +++ b/spx-gui/src/components/editor/code-editor/code-editor.ts @@ -729,12 +729,15 @@ export class CodeEditor extends Disposable { } async setLocale(locale: string) { - await this.lspClient.initialize({ signal: new AbortController().signal }, { - processId: null, - rootUri: null, - capabilities: {}, - locale - }) + await this.lspClient.initialize( + { signal: new AbortController().signal }, + { + processId: null, + rootUri: null, + capabilities: {}, + locale + } + ) } private registerMCPTools(): void { diff --git a/spx-gui/src/components/editor/code-editor/lsp/index.ts b/spx-gui/src/components/editor/code-editor/lsp/index.ts index 221637e6a..22e4ee1a7 100644 --- a/spx-gui/src/components/editor/code-editor/lsp/index.ts +++ b/spx-gui/src/components/editor/code-editor/lsp/index.ts @@ -232,10 +232,7 @@ export class SpxLSPClient extends Disposable { }) } - async initialize( - ctx: RequestContext, - params: lsp.InitializeParams - ): Promise { + async initialize(ctx: RequestContext, params: lsp.InitializeParams): Promise { return this.request(ctx, lsp.InitializeRequest.method, params) }