Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/notebook/vscode-node/followActions.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
8
import { Event } from '../../../util/vs/base/common/event';
9
import { Disposable } from '../../../util/vs/base/common/lifecycle';
10
import { INotebookService } from '../../../platform/notebook/common/notebookService';
11
12
const NOTEBOOK_FOLLOW_IN_SESSION_KEY = 'github.copilot.notebookFollowInSessionEnabled';
13
14
export class NotebookFollowCommands extends Disposable {
15
16
private followSettingEnabled: boolean;
17
18
constructor(
19
@IConfigurationService private readonly _configurationService: IConfigurationService,
20
@INotebookService private readonly _notebookService: INotebookService
21
) {
22
super();
23
24
// get setting and set initial follower context state
25
this.followSettingEnabled = this._configurationService.getConfig(ConfigKey.NotebookFollowCellExecution);
26
this.updateFollowContext(this.followSettingEnabled);
27
28
// config listener to disable if the setting changes
29
this._register(Event.runAndSubscribe(this._configurationService.onDidChangeConfiguration, e => {
30
if (!e || e.affectsConfiguration(ConfigKey.NotebookFollowCellExecution.fullyQualifiedId)) {
31
this.followSettingEnabled = this._configurationService.getConfig(ConfigKey.NotebookFollowCellExecution);
32
this.updateFollowContext(this.followSettingEnabled);
33
}
34
}));
35
36
// commands to change context state
37
this._register(vscode.commands.registerCommand('github.copilot.chat.notebook.enableFollowCellExecution', () => {
38
this.updateFollowContext(true);
39
}));
40
41
this._register(vscode.commands.registerCommand('github.copilot.chat.notebook.disableFollowCellExecution', () => {
42
this.updateFollowContext(false);
43
}));
44
}
45
46
private updateFollowContext(value: boolean): void {
47
vscode.commands.executeCommand('setContext', NOTEBOOK_FOLLOW_IN_SESSION_KEY, value);
48
this._notebookService.setFollowState(value);
49
50
}
51
}
52
53