Skip to content

Commit 3159d61

Browse files
author
Jackson Kearl
authored
Default to only show language detection hints in text editors (microsoft#148663)
* Default to only show language detection hints in text editors Fixes microsoft#148220 * Update to object-based config * Clarify type of untitled editor
1 parent 7295846 commit 3159d61

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/vs/workbench/browser/workbench.contribution.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,21 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
112112
description: localize('workbench.editor.preferBasedLanguageDetection', "When enabled, a language detection model that takes into account editor history will be given higher precedence."),
113113
},
114114
'workbench.editor.languageDetectionHints': {
115-
type: 'string',
116-
default: 'always',
115+
type: 'object',
116+
default: { 'untitledEditors': true, 'notebookEditors': false },
117117
tags: ['experimental'],
118-
enum: ['always', 'notebookEditors', 'textEditors', 'never'],
119118
description: localize('workbench.editor.showLanguageDetectionHints', "When enabled, shows a status bar quick fix when the editor language doesn't match detected content language."),
120-
enumDescriptions: [
121-
localize('workbench.editor.showLanguageDetectionHints.always', "Show show language detection quick fixes in both notebooks and untitled editors"),
122-
localize('workbench.editor.showLanguageDetectionHints.notebook', "Only show language detection quick fixes in notebooks"),
123-
localize('workbench.editor.showLanguageDetectionHints.editors', "Only show language detection quick fixes in untitled editors"),
124-
localize('workbench.editor.showLanguageDetectionHints.never', "Never show language quick fixes"),
125-
]
119+
additionalProperties: false,
120+
properties: {
121+
untitledEditors: {
122+
type: 'boolean',
123+
description: localize('workbench.editor.showLanguageDetectionHints.editors', "Show in untitled text editors"),
124+
},
125+
notebookEditors: {
126+
type: 'boolean',
127+
description: localize('workbench.editor.showLanguageDetectionHints.notebook', "Show in notebook editors"),
128+
}
129+
}
126130
},
127131
'workbench.editor.tabCloseButton': {
128132
'type': 'string',

src/vs/workbench/contrib/languageDetection/browser/languageDetection.contribution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWo
1111
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1212
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
1313
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';
14-
import { ILanguageDetectionService } from 'vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
14+
import { ILanguageDetectionService, LanguageDetectionHintConfig } from 'vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
1515
import { ThrottledDelayer } from 'vs/base/common/async';
1616
import { ILanguageService } from 'vs/editor/common/languages/language';
1717
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
@@ -75,8 +75,8 @@ class LanguageDetectionStatusContribution implements IWorkbenchContribution {
7575
const editorModel = editor?.getModel();
7676
const editorUri = editorModel?.uri;
7777
const existingId = editorModel?.getLanguageId();
78-
const enablementConfig = this._configurationService.getValue('workbench.editor.languageDetectionHints');
79-
const enabled = enablementConfig === 'always' || enablementConfig === 'textEditors';
78+
const enablementConfig = this._configurationService.getValue<LanguageDetectionHintConfig>('workbench.editor.languageDetectionHints');
79+
const enabled = typeof enablementConfig === 'object' && enablementConfig?.untitledEditors;
8080
const disableLightbulb = !enabled || editorUri?.scheme !== Schemas.untitled || !existingId;
8181

8282
if (disableLightbulb || !editorUri) {

src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/com
1919
import { CellKind, CellStatusbarAlignment, INotebookCellStatusBarItem, INotebookCellStatusBarItemList, INotebookCellStatusBarItemProvider } from 'vs/workbench/contrib/notebook/common/notebookCommon';
2020
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
2121
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
22-
import { ILanguageDetectionService } from 'vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
22+
import { ILanguageDetectionService, LanguageDetectionHintConfig } from 'vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
2323
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
2424

2525
class CellStatusBarLanguagePickerProvider implements INotebookCellStatusBarItemProvider {
@@ -79,8 +79,8 @@ class CellStatusBarLanguageDetectionProvider implements INotebookCellStatusBarIt
7979
const cell = doc?.cells[index];
8080
if (!cell) { return; }
8181

82-
const enablementConfig = this._configurationService.getValue('workbench.editor.languageDetectionHints');
83-
const enabled = enablementConfig === 'always' || enablementConfig === 'notebookEditors';
82+
const enablementConfig = this._configurationService.getValue<LanguageDetectionHintConfig>('workbench.editor.languageDetectionHints');
83+
const enabled = typeof enablementConfig === 'object' && enablementConfig?.notebookEditors;
8484
if (!enabled) {
8585
return;
8686
}

src/vs/workbench/services/languageDetection/common/languageDetectionWorkerService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface ILanguageDetectionService {
2525
detectLanguage(resource: URI, supportedLangs?: string[]): Promise<string | undefined>;
2626
}
2727

28+
export type LanguageDetectionHintConfig = {
29+
untitledEditors: boolean;
30+
notebookEditors: boolean;
31+
};
32+
2833
//#region Telemetry events
2934

3035
export const AutomaticLanguageDetectionLikelyWrongId = 'automaticlanguagedetection.likelywrong';

0 commit comments

Comments
 (0)