From 8a60cb39630cac2d0cce560afcf7618ec4c7a00f Mon Sep 17 00:00:00 2001 From: Ilshat Aliyev Date: Thu, 6 Mar 2025 20:02:53 +0100 Subject: [PATCH] Trigger 'change cell language' command when clicking on "Select language" in the empty cell hint. --- .../browser/emptyTextEditorHint/emptyTextEditorHint.ts | 10 +++++++--- .../browser/contrib/editorHint/emptyCellEditorHint.ts | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.ts b/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.ts index 540a6deec5f7d..82ab14a857cce 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.ts @@ -51,6 +51,8 @@ export class EmptyTextEditorHintContribution implements IEditorContribution { protected toDispose: IDisposable[]; private textHintContentWidget: EmptyTextEditorHintContentWidget | undefined; + protected readonly changeLanguageCommandId: string = ChangeLanguageAction.ID; + constructor( protected readonly editor: ICodeEditor, @IEditorGroupsService private readonly editorGroupsService: IEditorGroupsService, @@ -149,7 +151,8 @@ export class EmptyTextEditorHintContribution implements IEditorContribution { this.chatAgentService, this.telemetryService, this.productService, - this.contextMenuService + this.contextMenuService, + this.changeLanguageCommandId ); } else if (!shouldRenderHint && this.textHintContentWidget) { this.textHintContentWidget.dispose(); @@ -184,6 +187,7 @@ class EmptyTextEditorHintContentWidget implements IContentWidget { private readonly telemetryService: ITelemetryService, private readonly productService: IProductService, private readonly contextMenuService: IContextMenuService, + private readonly changeLanguageCommandId: string, ) { this.toDispose = new DisposableStore(); this.toDispose.add(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { @@ -345,10 +349,10 @@ class EmptyTextEditorHintContentWidget implements IContentWidget { // Need to focus editor before so current editor becomes active and the command is properly executed this.editor.focus(); this.telemetryService.publicLog2('workbenchActionExecuted', { - id: ChangeLanguageAction.ID, + id: this.changeLanguageCommandId, from: 'hint' }); - await this.commandService.executeCommand(ChangeLanguageAction.ID); + await this.commandService.executeCommand(this.changeLanguageCommandId); this.editor.focus(); }; diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.ts b/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.ts index 7df058a690161..996d893ba7664 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.ts @@ -16,7 +16,7 @@ import { ITelemetryService } from '../../../../../../platform/telemetry/common/t import { IChatAgentService } from '../../../../chat/common/chatAgents.js'; import { EmptyTextEditorHintContribution, IEmptyTextEditorHintOptions } from '../../../../codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js'; import { IInlineChatSessionService } from '../../../../inlineChat/browser/inlineChatSessionService.js'; -import { getNotebookEditorFromEditorPane } from '../../notebookBrowser.js'; +import { getNotebookEditorFromEditorPane, CHANGE_CELL_LANGUAGE } from '../../notebookBrowser.js'; import { IEditorGroupsService } from '../../../../../services/editor/common/editorGroupsService.js'; import { IEditorService } from '../../../../../services/editor/common/editorService.js'; @@ -59,6 +59,8 @@ export class EmptyCellEditorHintContribution extends EmptyTextEditorHintContribu this.toDispose.push(activeEditor.onDidChangeActiveCell(() => this.update())); } + protected override readonly changeLanguageCommandId: string = CHANGE_CELL_LANGUAGE; + protected override _getOptions(): IEmptyTextEditorHintOptions { return { clickable: false }; }