From 8ea25f7536de87327a234a0a1a9f271eb037c87e Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Wed, 22 May 2024 14:22:10 -0700 Subject: [PATCH 1/2] Fix #213206. Migrate off IInlineChatService --- .../cellDiagnostics/cellDiagnosticEditorContrib.ts | 10 +++++----- .../notebook/test/browser/testNotebookEditor.ts | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.ts b/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.ts index a04c894f93124..79608fb88b4db 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.ts @@ -7,7 +7,6 @@ import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle' import { IMarkerData, IMarkerService } from 'vs/platform/markers/common/markers'; import { IRange } from 'vs/editor/common/core/range'; import { ICellExecutionError, ICellExecutionStateChangedEvent, IExecutionStateChangedEvent, INotebookExecutionStateService, NotebookExecutionType } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; -import { IInlineChatService } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { CellKind, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { INotebookEditor, INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; @@ -16,6 +15,7 @@ import { Iterable } from 'vs/base/common/iterator'; import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel'; import { URI } from 'vs/base/common/uri'; import { Event } from 'vs/base/common/event'; +import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; type CellDiagnostic = { cellUri: URI; @@ -35,14 +35,14 @@ export class CellDiagnostics extends Disposable implements INotebookEditorContri private readonly notebookEditor: INotebookEditor, @INotebookExecutionStateService private readonly notebookExecutionStateService: INotebookExecutionStateService, @IMarkerService private readonly markerService: IMarkerService, - @IInlineChatService private readonly inlineChatService: IInlineChatService, + @IChatAgentService private readonly chatAgentService: IChatAgentService, @IConfigurationService private readonly configurationService: IConfigurationService ) { super(); this.updateEnabled(); - this._register(inlineChatService.onDidChangeProviders(() => this.updateEnabled())); + this._register(chatAgentService.onDidChangeAgents(() => this.updateEnabled())); this._register(configurationService.onDidChangeConfiguration((e) => { if (e.affectsConfiguration(NotebookSetting.cellFailureDiagnostics)) { this.updateEnabled(); @@ -52,10 +52,10 @@ export class CellDiagnostics extends Disposable implements INotebookEditorContri private updateEnabled() { const settingEnabled = this.configurationService.getValue(NotebookSetting.cellFailureDiagnostics); - if (this.enabled && (!settingEnabled || Iterable.isEmpty(this.inlineChatService.getAllProvider()))) { + if (this.enabled && (!settingEnabled || Iterable.isEmpty(this.chatAgentService.getAgents()))) { this.enabled = false; this.clearAll(); - } else if (!this.enabled && settingEnabled && !Iterable.isEmpty(this.inlineChatService.getAllProvider())) { + } else if (!this.enabled && settingEnabled && !Iterable.isEmpty(this.chatAgentService.getAgents())) { this.enabled = true; if (!this.listening) { this.listening = true; diff --git a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts index 677afcd4ab8db..6db24ac2b1092 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts @@ -65,8 +65,6 @@ import { EditorFontLigatures, EditorFontVariations } from 'vs/editor/common/conf import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { mainWindow } from 'vs/base/browser/window'; import { TestCodeEditorService } from 'vs/editor/test/browser/editorTestServices'; -import { IInlineChatService } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; -import { InlineChatServiceImpl } from 'vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl'; import { INotebookCellOutlineProviderFactory, NotebookCellOutlineProviderFactory } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProviderFactory'; import { ILanguageDetectionService } from 'vs/workbench/services/languageDetection/common/languageDetectionWorkerService'; @@ -201,7 +199,6 @@ export function setupInstantiationService(disposables: DisposableStore) { instantiationService.stub(IKeybindingService, new MockKeybindingService()); instantiationService.stub(INotebookCellStatusBarService, disposables.add(new NotebookCellStatusBarService())); instantiationService.stub(ICodeEditorService, disposables.add(new TestCodeEditorService(testThemeService))); - instantiationService.stub(IInlineChatService, instantiationService.createInstance(InlineChatServiceImpl)); instantiationService.stub(INotebookCellOutlineProviderFactory, instantiationService.createInstance(NotebookCellOutlineProviderFactory)); instantiationService.stub(ILanguageDetectionService, new class MockLanguageDetectionService implements ILanguageDetectionService { From 2f2a0166def621807171ca51f388755e12d5a9f1 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Wed, 22 May 2024 15:40:44 -0700 Subject: [PATCH 2/2] fix tests --- .../contrib/notebookCellDiagnostics.test.ts | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/test/browser/contrib/notebookCellDiagnostics.test.ts b/src/vs/workbench/contrib/notebook/test/browser/contrib/notebookCellDiagnostics.test.ts index 677f7f5b850b1..ef1c965adb22f 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/contrib/notebookCellDiagnostics.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/contrib/notebookCellDiagnostics.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { Emitter } from 'vs/base/common/event'; +import { Emitter, Event } from 'vs/base/common/event'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { ResourceMap } from 'vs/base/common/map'; import { waitForState } from 'vs/base/common/observable'; @@ -15,12 +15,13 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { IMarkerData, IMarkerService } from 'vs/platform/markers/common/markers'; -import { IInlineChatService, IInlineChatSessionProvider } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; +import { ChatAgentLocation, IChatAgent, IChatAgentData, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; import { CellDiagnostics } from 'vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib'; import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel'; import { CellKind, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { ICellExecutionStateChangedEvent, IExecutionStateChangedEvent, INotebookCellExecution, INotebookExecutionStateService, NotebookExecutionType } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { setupInstantiationService, TestNotebookExecutionStateService, withTestNotebook } from 'vs/workbench/contrib/notebook/test/browser/testNotebookEditor'; +import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions'; suite('notebookCellDiagnostics', () => { @@ -64,8 +65,26 @@ suite('notebookCellDiagnostics', () => { testExecutionService = new TestExecutionService(); instantiationService.stub(INotebookExecutionStateService, testExecutionService); - const chatProviders = instantiationService.get(IInlineChatService); - disposables.add(chatProviders.addProvider({} as IInlineChatSessionProvider)); + const agentData = { + extensionId: nullExtensionDescription.identifier, + extensionDisplayName: '', + extensionPublisherId: '', + name: 'testEditorAgent', + isDefault: true, + locations: [ChatAgentLocation.Editor], + metadata: {}, + slashCommands: [] + }; + const chatAgentService = new class extends mock() { + override getAgents(): IChatAgentData[] { + return [{ + id: 'testEditorAgent', + ...agentData + }]; + } + override onDidChangeAgents: Event = Event.None; + }; + instantiationService.stub(IChatAgentService, chatAgentService); markerService = new class extends mock() { override markers: ResourceMap = new ResourceMap();