diff --git a/src/vs/base/node/encoding.ts b/src/vs/base/node/encoding.ts index 81e3b6946396acc89c59fa148c99448f1a7043a3..9fa464a16ef3c9d074d2e729e15ed245e5082f97 100644 --- a/src/vs/base/node/encoding.ts +++ b/src/vs/base/node/encoding.ts @@ -19,7 +19,6 @@ export const UTF16le = 'utf16le'; export interface IDecodeStreamOptions { guessEncoding?: boolean; - guessableEncodings?: string[]; minBytesRequiredForDetection?: number; overwriteEncoding?(detectedEncoding: string): string; } @@ -79,7 +78,7 @@ export function toDecodeStream(readable: Readable, options: IDecodeStreamOptions this._decodeStreamConstruction = TPromise.as(detectEncodingFromBuffer({ buffer: Buffer.concat(this._buffer), bytesRead: this._bytesBuffered - }, options.guessEncoding, options.guessableEncodings)).then(detected => { + }, options.guessEncoding)).then(detected => { detected.encoding = options.overwriteEncoding(detected.encoding); this._decodeStream = decodeStream(detected.encoding); for (const buffer of this._buffer) { @@ -273,8 +272,8 @@ export interface IDetectedEncodingResult { } export function detectEncodingFromBuffer(readResult: stream.ReadResult, autoGuessEncoding?: false): IDetectedEncodingResult; -export function detectEncodingFromBuffer(readResult: stream.ReadResult, autoGuessEncoding?: boolean, guessableEncodings?: string[]): TPromise; -export function detectEncodingFromBuffer({ buffer, bytesRead }: stream.ReadResult, autoGuessEncoding?: boolean, guessableEncodings?: string[]): TPromise | IDetectedEncodingResult { +export function detectEncodingFromBuffer(readResult: stream.ReadResult, autoGuessEncoding?: boolean): TPromise; +export function detectEncodingFromBuffer({ buffer, bytesRead }: stream.ReadResult, autoGuessEncoding?: boolean): TPromise | IDetectedEncodingResult { // Always first check for BOM to find out about encoding let encoding = detectEncodingByBOMFromBuffer(buffer, bytesRead); @@ -332,13 +331,6 @@ export function detectEncodingFromBuffer({ buffer, bytesRead }: stream.ReadResul // Auto guess encoding if configured if (autoGuessEncoding && !seemsBinary && !encoding) { return guessEncodingByBuffer(buffer.slice(0, bytesRead)).then(guessedEncoding => { - - // Ignore encoding if we have a list of encodings to use for guessing - if (guessedEncoding && guessableEncodings && guessableEncodings.length > 0 && guessableEncodings.indexOf(guessedEncoding) === -1) { - return { seemsBinary, encoding }; - } - - // Proceed with guessed encoding return { seemsBinary: false, encoding: guessedEncoding diff --git a/src/vs/base/test/node/encoding/encoding.test.ts b/src/vs/base/test/node/encoding/encoding.test.ts index 172b16037e50784797ddd1969b3bec79efdeb86a..99d05d437a0f3189a369b1d3ffcf249300ab52f7 100644 --- a/src/vs/base/test/node/encoding/encoding.test.ts +++ b/src/vs/base/test/node/encoding/encoding.test.ts @@ -153,42 +153,6 @@ suite('Encoding', () => { }); }); - test('autoGuessEncoding, guessableEncodings empty (ShiftJIS)', function () { - const file = getPathFromAmdModule(require, './fixtures/some.shiftjis.txt'); - return readExactlyByFile(file, 512 * 8).then(buffer => { - return encoding.detectEncodingFromBuffer(buffer, true, []).then(mimes => { - assert.equal(mimes.encoding, 'shiftjis'); - }); - }); - }); - - test('autoGuessEncoding, guessableEncodings (ShiftJIS)', function () { - const file = getPathFromAmdModule(require, './fixtures/some.shiftjis.txt'); - return readExactlyByFile(file, 512 * 8).then(buffer => { - return encoding.detectEncodingFromBuffer(buffer, true, ['windows1252']).then(mimes => { - assert.ok(!mimes.encoding); - }); - }); - }); - - test('autoGuessEncoding, guessableEncodings (ShiftJIS)', function () { - const file = getPathFromAmdModule(require, './fixtures/some.shiftjis.txt'); - return readExactlyByFile(file, 512 * 8).then(buffer => { - return encoding.detectEncodingFromBuffer(buffer, true, ['windows1252', 'shiftjis']).then(mimes => { - assert.equal(mimes.encoding, 'shiftjis'); - }); - }); - }); - - test('autoGuessEncoding, guessableEncodings (CP1252)', function () { - const file = getPathFromAmdModule(require, './fixtures/some.cp1252.txt'); - return readExactlyByFile(file, 512 * 8).then(buffer => { - return encoding.detectEncodingFromBuffer(buffer, true, ['windows1252']).then(mimes => { - assert.equal(mimes.encoding, 'windows1252'); - }); - }); - }); - async function readAndDecodeFromDisk(path, _encoding) { return new Promise((resolve, reject) => { fs.readFile(path, (err, data) => { diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index 77790c055ebb0bc322c0e659ebdce404de469fa7..abe84da07b4da9f6402b3a804631c2a09874bad2 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -552,12 +552,6 @@ export interface IResolveContentOptions { */ autoGuessEncoding?: boolean; - /** - * The optional list of encodings that can be used when guessing. If not provided, all encodings - * will be supported for guessing. - */ - guessableEncodings?: string[]; - /** * Is an integer specifying where to begin reading from in the file. If position is null, * data will be read from the current file position. @@ -667,7 +661,6 @@ export interface IFilesConfiguration { watcherExclude: { [filepattern: string]: boolean }; encoding: string; autoGuessEncoding: boolean; - guessableEncodings: string[]; defaultLanguage: string; trimTrailingWhitespace: boolean; autoSave: string; diff --git a/src/vs/platform/telemetry/common/telemetryUtils.ts b/src/vs/platform/telemetry/common/telemetryUtils.ts index 1a078e4ad12f42c3a890e2acebd8e893ebf2deaf..498b443cd446c87514735d667d356b4f5c2f4c9e 100644 --- a/src/vs/platform/telemetry/common/telemetryUtils.ts +++ b/src/vs/platform/telemetry/common/telemetryUtils.ts @@ -163,7 +163,6 @@ const configurationValueWhitelist = [ 'extensions.autoUpdate', 'files.associations', 'files.autoGuessEncoding', - 'files.guessableEncodings', 'files.autoSave', 'files.autoSaveDelay', 'files.encoding', diff --git a/src/vs/workbench/parts/files/electron-browser/files.contribution.ts b/src/vs/workbench/parts/files/electron-browser/files.contribution.ts index 7fbca0175a94794ebf7534fc9690b6992693e741..45e656cc1457e1e2c1e775d05354c6ca6da7e396 100644 --- a/src/vs/workbench/parts/files/electron-browser/files.contribution.ts +++ b/src/vs/workbench/parts/files/electron-browser/files.contribution.ts @@ -237,17 +237,6 @@ configurationRegistry.registerConfiguration({ 'description': nls.localize('autoGuessEncoding', "When enabled, the editor will attempt to guess the character set encoding when opening files. This setting can also be configured per language."), 'scope': ConfigurationScope.RESOURCE }, - 'files.guessableEncodings': { - 'type': 'array', - 'overridable': true, - 'default': [], - 'items': { - 'type': 'string', - 'enum': Object.keys(SUPPORTED_ENCODINGS) - }, - 'scope': ConfigurationScope.RESOURCE, - 'description': nls.localize('guessableEncodings', "If provided, will restrict the list of encodings that can be used when guessing. If the guessed file encoding is not in the list, the default encoding will be used.") - }, 'files.eol': { 'type': 'string', 'enum': [ diff --git a/src/vs/workbench/services/files/electron-browser/fileService.ts b/src/vs/workbench/services/files/electron-browser/fileService.ts index 3e3e932e320dca7b9f30c7f5cd3dc5498684354d..a64d6deef2f13f63a36a5f456dc797dbb5528125 100644 --- a/src/vs/workbench/services/files/electron-browser/fileService.ts +++ b/src/vs/workbench/services/files/electron-browser/fileService.ts @@ -531,8 +531,7 @@ export class FileService extends Disposable implements IFileService { // decoding stream which is then used to drive the string stream. TPromise.as(encoding.detectEncodingFromBuffer( { buffer: chunkBuffer, bytesRead }, - (options && options.autoGuessEncoding) || this.textResourceConfigurationService.getValue(resource, 'files.autoGuessEncoding'), - (options && options.guessableEncodings) || this.textResourceConfigurationService.getValue(resource, 'files.guessableEncodings') + (options && options.autoGuessEncoding) || this.textResourceConfigurationService.getValue(resource, 'files.autoGuessEncoding') )).then(detected => { if (options && options.acceptTextOnly && detected.seemsBinary) { diff --git a/src/vs/workbench/services/files/electron-browser/remoteFileService.ts b/src/vs/workbench/services/files/electron-browser/remoteFileService.ts index a54f8fe940902c0056a84850c073f573f28eaf97..99a00594348f7a42152577cbc10db6fd7adefbff 100644 --- a/src/vs/workbench/services/files/electron-browser/remoteFileService.ts +++ b/src/vs/workbench/services/files/electron-browser/remoteFileService.ts @@ -374,7 +374,6 @@ export class RemoteFileService extends FileService { const decodeStreamOpts: IDecodeStreamOptions = { guessEncoding: options.autoGuessEncoding, - guessableEncodings: options.guessableEncodings, overwriteEncoding: detected => { return this.encoding.getReadEncoding(resource, options, { encoding: detected, seemsBinary: false }); }