Skip to content

Commit ba563bd

Browse files
authored
chat - tweak completions setting from status (microsoft#242189)
1 parent 8e99f3d commit ba563bd

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/vs/workbench/contrib/chat/browser/chatStatus.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import { KeyCode } from '../../../../base/common/keyCodes.js';
3636
import { Gesture, EventType as TouchEventType } from '../../../../base/browser/touch.js';
3737
import { IEditorService } from '../../../services/editor/common/editorService.js';
3838
import { IProductService } from '../../../../platform/product/common/productService.js';
39+
import { isObject } from '../../../../base/common/types.js';
40+
import { ILanguageService } from '../../../../editor/common/languages/language.js';
3941

4042
//#region --- colors
4143

@@ -109,7 +111,8 @@ export class ChatStatusBarEntry extends Disposable implements IWorkbenchContribu
109111
@ICommandService private readonly commandService: ICommandService,
110112
@IHoverService private readonly hoverService: IHoverService,
111113
@IEditorService private readonly editorService: IEditorService,
112-
@IProductService private readonly productService: IProductService
114+
@IProductService private readonly productService: IProductService,
115+
@ILanguageService private readonly languageService: ILanguageService
113116
) {
114117
super();
115118

@@ -370,27 +373,42 @@ export class ChatStatusBarEntry extends Disposable implements IWorkbenchContribu
370373
}
371374

372375
private createSettings(container: HTMLElement, disposables: DisposableStore): HTMLElement {
373-
const languageId = this.editorService.activeTextEditorLanguageId;
376+
const language = this.editorService.activeTextEditorLanguageId;
374377
const settings = container.appendChild($('div.settings'));
375378

376379
// --- Code Completions
377380
{
378-
const settingId = 'github.copilot.editor.enableAutoCompletions';
379381
const globalSetting = append(settings, $('div.setting'));
380-
this.createSetting(globalSetting, localize('settings.codeCompletions', "Code completions (all)"), { key: settingId, override: undefined }, disposables);
382+
this.createCodeCompletionsSetting(globalSetting, localize('settings.codeCompletions', "Code completions (all files)"), '*', disposables);
381383

382-
if (languageId) {
384+
if (language) {
383385
const languageSetting = append(settings, $('div.setting'));
384-
this.createSetting(languageSetting, localize('settings.codeCompletionsLanguage', "Code completions ({0})", languageId), { key: settingId, override: languageId }, disposables);
386+
this.createCodeCompletionsSetting(languageSetting, localize('settings.codeCompletionsLanguage', "Code completions ({0})", this.languageService.getLanguageName(language) ?? language), language, disposables);
385387
}
386388
}
387389

388390
return settings;
389391
}
390392

391-
private createSetting(container: HTMLElement, label: string, setting: { key: string; override: string | undefined }, disposables: DisposableStore): void {
392-
const readSetting = () => Boolean(this.configurationService.getValue<boolean>(setting.key, { overrideIdentifier: setting.override }));
393-
const writeSetting = (checkbox: Checkbox) => this.configurationService.updateValue(setting.key, checkbox.checked, { overrideIdentifier: setting.override });
393+
private createCodeCompletionsSetting(container: HTMLElement, label: string, language: string, disposables: DisposableStore): void {
394+
const settingId = 'github.copilot.enable';
395+
396+
const readSetting = () => {
397+
const result = this.configurationService.getValue<Record<string, boolean>>(settingId);
398+
if (!isObject(result)) {
399+
return false;
400+
}
401+
402+
return Boolean(result[language]);
403+
};
404+
const writeSetting = (checkbox: Checkbox) => {
405+
let result = this.configurationService.getValue<Record<string, boolean>>(settingId);
406+
if (!isObject(result)) {
407+
result = Object.create(null);
408+
}
409+
410+
return this.configurationService.updateValue(settingId, { ...result, [language]: checkbox.checked });
411+
};
394412

395413
const settingCheckbox = disposables.add(new Checkbox(label, readSetting(), defaultCheckboxStyles));
396414
container.appendChild(settingCheckbox.domNode);
@@ -414,7 +432,7 @@ export class ChatStatusBarEntry extends Disposable implements IWorkbenchContribu
414432
}));
415433

416434
disposables.add(this.configurationService.onDidChangeConfiguration(e => {
417-
if (e.affectsConfiguration(setting.key, { overrideIdentifier: setting.override })) {
435+
if (e.affectsConfiguration(settingId)) {
418436
settingCheckbox.checked = readSetting();
419437
}
420438
}));

0 commit comments

Comments
 (0)