提交 d41edee8 编写于 作者: B Benjamin Pasero

Workspace file: encoding should always be UTF-8 (fixes #46935)

上级 f3b860d4
......@@ -25,6 +25,7 @@ import { isMacintosh, isWindows } from 'vs/base/common/platform';
import product from 'vs/platform/node/product';
import { Schemas } from 'vs/base/common/network';
import { Severity, INotificationService, PromptOption } from 'vs/platform/notification/common/notification';
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
export class FileService implements IFileService {
......@@ -159,9 +160,16 @@ export class FileService implements IFileService {
private getEncodingOverrides(): IEncodingOverride[] {
const encodingOverride: IEncodingOverride[] = [];
encodingOverride.push({ resource: uri.file(this.environmentService.appSettingsHome), encoding: encoding.UTF8 });
// Global settings
encodingOverride.push({ parent: uri.file(this.environmentService.appSettingsHome), encoding: encoding.UTF8 });
// Workspace files
encodingOverride.push({ extension: WORKSPACE_EXTENSION, encoding: encoding.UTF8 });
// Folder Settings
this.contextService.getWorkspace().folders.forEach(folder => {
encodingOverride.push({ resource: uri.file(paths.join(folder.uri.fsPath, '.vscode')), encoding: encoding.UTF8 });
encodingOverride.push({ parent: uri.file(paths.join(folder.uri.fsPath, '.vscode')), encoding: encoding.UTF8 });
});
return encodingOverride;
......
......@@ -42,7 +42,8 @@ import { Readable } from 'stream';
import { Schemas } from 'vs/base/common/network';
export interface IEncodingOverride {
resource: uri;
parent?: uri;
extension?: string;
encoding: string;
}
......@@ -974,9 +975,13 @@ export class FileService implements IFileService {
for (let i = 0; i < this.options.encodingOverride.length; i++) {
const override = this.options.encodingOverride[i];
// check if the resource is a child of the resource with override and use
// the provided encoding in that case
if (isParent(resource.fsPath, override.resource.fsPath, !isLinux /* ignorecase */)) {
// check if the resource is child of encoding override path
if (override.parent && isParent(resource.fsPath, override.parent.fsPath, !isLinux /* ignorecase */)) {
return override.encoding;
}
// check if the resource extension is equal to encoding override
if (override.extension && paths.extname(resource.fsPath) === `.${override.extension}`) {
return override.encoding;
}
}
......
......@@ -912,7 +912,7 @@ suite('FileService', () => {
}, 100);
});
test('options - encoding', function () {
test('options - encoding override (parent)', function () {
// setup
const _id = uuid.generateUuid();
......@@ -922,7 +922,44 @@ suite('FileService', () => {
return pfs.copy(_sourceDir, _testDir).then(() => {
const encodingOverride: IEncodingOverride[] = [];
encodingOverride.push({
resource: uri.file(path.join(testDir, 'deep')),
parent: uri.file(path.join(testDir, 'deep')),
encoding: 'utf16le'
});
const configurationService = new TestConfigurationService();
configurationService.setUserConfiguration('files', { encoding: 'windows1252' });
const textResourceConfigurationService = new TestTextResourceConfigurationService(configurationService);
const _service = new FileService(new TestContextService(new Workspace(_testDir, _testDir, toWorkspaceFolders([{ path: _testDir }]))), TestEnvironmentService, textResourceConfigurationService, configurationService, new TestLifecycleService(), {
encodingOverride,
disableWatcher: true
});
return _service.resolveContent(uri.file(path.join(testDir, 'index.html'))).then(c => {
assert.equal(c.encoding, 'windows1252');
return _service.resolveContent(uri.file(path.join(testDir, 'deep', 'conway.js'))).then(c => {
assert.equal(c.encoding, 'utf16le');
// teardown
_service.dispose();
});
});
});
});
test('options - encoding override (extension)', function () {
// setup
const _id = uuid.generateUuid();
const _testDir = path.join(parentDir, _id);
const _sourceDir = require.toUrl('./fixtures/service');
return pfs.copy(_sourceDir, _testDir).then(() => {
const encodingOverride: IEncodingOverride[] = [];
encodingOverride.push({
extension: 'js',
encoding: 'utf16le'
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册