Skip to content

Commit 94fe610

Browse files
committed
encoding - always resolve encoding when language changes independent of overrides
1 parent e4af7dc commit 94fe610

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/vs/workbench/services/textfile/common/textFileEditorModel.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import { extUri } from 'vs/base/common/resources';
3131
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
3232
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
3333
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
34-
import { IModelLanguageChangedEvent } from 'vs/editor/common/textModelEvents';
35-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3634

3735
interface IBackupMetaData extends IWorkingCopyBackupMeta {
3836
mtime: number;
@@ -121,8 +119,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
121119
@ILanguageDetectionService languageDetectionService: ILanguageDetectionService,
122120
@IAccessibilityService accessibilityService: IAccessibilityService,
123121
@IPathService private readonly pathService: IPathService,
124-
@IExtensionService private readonly extensionService: IExtensionService,
125-
@IConfigurationService private readonly configurationService: IConfigurationService
122+
@IExtensionService private readonly extensionService: IExtensionService
126123
) {
127124
super(modelService, languageService, languageDetectionService, accessibilityService);
128125

@@ -567,7 +564,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
567564

568565
// Listen to text model events
569566
this._register(model.onDidChangeContent(e => this.onModelContentChanged(model, e.isUndoing || e.isRedoing)));
570-
this._register(model.onDidChangeLanguage(e => this.onMaybeDidChangeEncoding(e))); // detect possible encoding change via language specific settings
567+
this._register(model.onDidChangeLanguage(e => this.onMaybeDidChangeEncoding())); // detect possible encoding change via language specific settings
571568
}
572569

573570
private onModelContentChanged(model: ITextModel, isUndoingOrRedoing: boolean): void {
@@ -1003,7 +1000,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
10031000

10041001
//#region Encoding
10051002

1006-
private async onMaybeDidChangeEncoding(e: IModelLanguageChangedEvent): Promise<void> {
1003+
private async onMaybeDidChangeEncoding(): Promise<void> {
10071004

10081005
// This is a bit of a hack but there is a narrow case where
10091006
// per-language configured encodings are not working:
@@ -1017,14 +1014,10 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
10171014
// To mitigate this issue, when we detect the model language
10181015
// changes, we see if there is a specific encoding configured
10191016
// for the new language and apply it, only if the model is
1020-
// not dirty and has finished resolving.
1017+
// not dirty.
10211018
//
10221019
// (see https://github.com/microsoft/vscode/issues/127936)
10231020

1024-
if (!this.configurationService.inspect('files.encoding').overrideIdentifiers?.includes(e.newLanguage)) {
1025-
return; // only when there is a language specific override for the new language
1026-
}
1027-
10281021
const { encoding } = await this.textFileService.encoding.getPreferredReadEncoding(this.resource);
10291022
if (typeof encoding !== 'string' || !this.isNewEncoding(encoding)) {
10301023
return; // return early if encoding is invalid or did not change

0 commit comments

Comments
 (0)