change setting to workbench.editor.untitled.experimentalLanguageDetection

This commit is contained in:
Tyler Leonhardt 2021-07-23 14:07:18 -07:00
parent 6dca117625
commit 64cf4ed3fe
No known key found for this signature in database
GPG key ID: 1BC2B6244363E77E
2 changed files with 7 additions and 3 deletions

View file

@ -93,7 +93,7 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
'default': 'text',
'markdownDescription': localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'untitledHint' }, "Controls if the untitled hint should be inline text in the editor or a floating button or hidden.")
},
'workbench.editor.untitled.languageDetection': {
'workbench.editor.untitled.experimentalLanguageDetection': {
type: 'boolean',
default: false,
description: localize('workbench.editor.untitled.languageDetection', "Experimental. Controls whether the language in an untitled text editor is automatically detected unless the language has been explicitly set by the language picker. This can also be scoped by language so you can control which languages you want to trigger language detection on."),

View file

@ -21,6 +21,7 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle
export class LanguageDetectionService extends Disposable implements ILanguageDetectionService {
private static readonly expectedRelativeConfidence = 0.2;
static readonly enablementSettingKey = 'workbench.editor.untitled.experimentalLanguageDetection';
private _loadFailed = false;
private _modelOperations: ModelOperations | undefined;
@ -37,8 +38,7 @@ export class LanguageDetectionService extends Disposable implements ILanguageDet
}
private async handleChangeEvent(e: IUntitledTextEditorModel) {
const settingValue = this._configurationService.getValue<boolean>('workbench.editor.untitled.languageDetection', { overrideIdentifier: e.getMode() });
if (!settingValue || e.hasModeSetExplicitly) {
if (!this.isEnabledForMode(e.getMode()) || e.hasModeSetExplicitly) {
return;
}
@ -80,6 +80,10 @@ export class LanguageDetectionService extends Disposable implements ILanguageDet
return this._register(this._modelOperations);
}
private isEnabledForMode(modeId: string | undefined): boolean {
return !!modeId && this._configurationService.getValue<boolean>(LanguageDetectionService.enablementSettingKey, { overrideIdentifier: modeId });
}
async detectLanguage(contentOrResource: string | URI): Promise<string | undefined> {
let content: string | undefined = URI.isUri(contentOrResource) ? this._untitledTextEditorService.getValue(contentOrResource) : contentOrResource;