diff --git a/src/vs/base/node/encoding.ts b/src/vs/base/node/encoding.ts index 5ff845143de41..4d88057801311 100644 --- a/src/vs/base/node/encoding.ts +++ b/src/vs/base/node/encoding.ts @@ -92,4 +92,39 @@ export function detectEncodingByBOMFromBuffer(buffer: NodeBuffer, bytesRead: num */ export function detectEncodingByBOM(file: string): TPromise { return stream.readExactlyByFile(file, 3).then(({buffer, bytesRead}) => detectEncodingByBOMFromBuffer(buffer, bytesRead)); +} + +/** + * The encodings that are allowed in a settings file don't match the canonical encoding labels specified by WHATWG. + * See https://encoding.spec.whatwg.org/#names-and-labels + * Iconv-lite strips all non-alphanumeric characters, but ripgrep doesn't. For backcompat, allow these labels. + */ +export function toCanonicalName(enc: string): string { + switch (enc) { + case 'shiftjis': + return 'shift-jis'; + case 'utf16le': + return 'utf-16le'; + case 'utf16be': + return 'utf-16be'; + case 'big5hkcs': + return 'big5-hkcs'; + case 'eucjp': + return 'euc-jp'; + case 'euckr': + return 'euc-kr'; + case 'koi8r': + return 'koi8-r'; + case 'koi8u': + return 'koi8-u'; + case 'macroman': + return 'x-mac-roman'; + default: + const m = enc.match(/windows(\d+)/); + if (m) { + return 'windows-' + m[1]; + } + + return enc; + } } \ No newline at end of file diff --git a/src/vs/workbench/services/search/node/ripgrepTextSearch.ts b/src/vs/workbench/services/search/node/ripgrepTextSearch.ts index 42e72e86cad07..452349eb5c580 100644 --- a/src/vs/workbench/services/search/node/ripgrepTextSearch.ts +++ b/src/vs/workbench/services/search/node/ripgrepTextSearch.ts @@ -10,6 +10,7 @@ import * as path from 'path'; import * as cp from 'child_process'; import { rgPath } from 'vscode-ripgrep'; +import * as encoding from 'vs/base/node/encoding'; import * as strings from 'vs/base/common/strings'; import * as glob from 'vs/base/common/glob'; import { ILineMatch, IProgress } from 'vs/platform/search/common/search'; @@ -325,6 +326,11 @@ function getRgArgs(config: IRawSearch): { args: string[], siblingClauses: glob.S // Follow symlinks args.push('--follow'); + // Set default encoding + if (config.fileEncoding) { + args.push('--encoding', encoding.toCanonicalName(config.fileEncoding)); + } + if (config.contentPattern.isRegExp) { if (config.contentPattern.isWordMatch) { args.push('--word-regexp');