Fix #213206. Migrate off IInlineChatService (#213263)

* Fix #213206. Migrate off IInlineChatService

* fix tests
This commit is contained in:
Peng Lyu 2024-05-22 18:56:10 -07:00 committed by GitHub
parent 79d8e9809e
commit 17f711b9bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 12 deletions

View file

@ -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;

View file

@ -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>(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<IChatAgentService>() {
override getAgents(): IChatAgentData[] {
return [{
id: 'testEditorAgent',
...agentData
}];
}
override onDidChangeAgents: Event<IChatAgent | undefined> = Event.None;
};
instantiationService.stub(IChatAgentService, chatAgentService);
markerService = new class extends mock<ITestMarkerService>() {
override markers: ResourceMap<IMarkerData[]> = new ResourceMap();

View file

@ -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 {