Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #213525. Move nb chat variable to service #213835

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,38 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from 'vs/workbench/common/contributions';
import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables';
import 'vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions';
import { NotebookChatController } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService';

class NotebookChatVariables extends Disposable implements IWorkbenchContribution {

static readonly ID = 'workbench.contrib.notebookChatVariables';

constructor(
@IChatVariablesService private readonly _chatVariableService: IChatVariablesService,
@INotebookEditorService private readonly _notebookEditorService: INotebookEditorService
) {
super();

this._register(this._chatVariableService.registerVariable(
{ id: '_notebookChatInput', name: '_notebookChatInput', description: '', hidden: true },
async (_message, _arg, model) => {
const editors = this._notebookEditorService.listNotebookEditors();
for (const editor of editors) {
const chatController = editor.getContribution(NotebookChatController.id) as NotebookChatController | undefined;
if (chatController?.hasSession(model)) {
return chatController.getSessionInputUri();
}
}

return undefined;
}
));
}
}

registerWorkbenchContribution2(NotebookChatVariables.ID, NotebookChatVariables, WorkbenchPhase.BlockRestore);
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
import { ChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
import { ChatModel, IChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables';
import { countWords } from 'vs/workbench/contrib/chat/common/chatWordCounter';
import { ProgressingEditsOptions } from 'vs/workbench/contrib/inlineChat/browser/inlineChatStrategies';
import { InlineChatWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget';
Expand Down Expand Up @@ -279,8 +278,7 @@ export class NotebookChatController extends Disposable implements INotebookEdito
@ILanguageService private readonly _languageService: ILanguageService,
@INotebookExecutionStateService private _executionStateService: INotebookExecutionStateService,
@IStorageService private readonly _storageService: IStorageService,
@IChatService private readonly _chatService: IChatService,
@IChatVariablesService private readonly _chatVariableService: IChatVariablesService,
@IChatService private readonly _chatService: IChatService
) {
super();
this._ctxHasActiveRequest = CTX_NOTEBOOK_CHAT_HAS_ACTIVE_REQUEST.bindTo(this._contextKeyService);
Expand All @@ -301,13 +299,6 @@ export class NotebookChatController extends Disposable implements INotebookEdito
this._historyCandidate = '';
this._storageService.store(NotebookChatController._storageKey, JSON.stringify(NotebookChatController._promptHistory), StorageScope.PROFILE, StorageTarget.USER);
};

this._register(this._chatVariableService.registerVariable(
{ id: '_notebookChatInput', name: '_notebookChatInput', description: '', hidden: true },
async (_message, _arg, model) => {
return this._widget?.parentEditor.getModel()?.uri;
}
));
}

private _registerFocusTracker() {
Expand Down Expand Up @@ -541,6 +532,14 @@ export class NotebookChatController extends Disposable implements INotebookEdito
this._widget.updateNotebookEditorFocusNSelections();
}

hasSession(chatModel: IChatModel) {
return this._model.value === chatModel;
}

getSessionInputUri() {
return this._widget?.parentEditor.getModel()?.uri;
}

async acceptInput() {
assertType(this._widget);
await this._sessionCtor;
Expand Down
Loading