mirror of
https://github.com/Microsoft/vscode
synced 2024-08-25 03:56:03 +00:00
change setting to workbench.editor.untitled.experimentalLanguageDetection
This commit is contained in:
parent
6dca117625
commit
64cf4ed3fe
|
@ -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."),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue