1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
22 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
23 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
24 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
25 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
26 | };
|
27 | var __metadata = (this && this.__metadata) || function (k, v) {
|
28 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
29 | };
|
30 | Object.defineProperty(exports, "__esModule", { value: true });
|
31 | exports.EncodingRegistry = void 0;
|
32 |
|
33 | const inversify_1 = require("inversify");
|
34 | const disposable_1 = require("../common/disposable");
|
35 | const core_preferences_1 = require("./core-preferences");
|
36 | const encoding_service_1 = require("../common/encoding-service");
|
37 | const encodings_1 = require("../common/encodings");
|
38 | let EncodingRegistry = class EncodingRegistry {
|
39 | constructor() {
|
40 | this.encodingOverrides = [];
|
41 | }
|
42 | registerOverride(override) {
|
43 | this.encodingOverrides.push(override);
|
44 | return disposable_1.Disposable.create(() => {
|
45 | const index = this.encodingOverrides.indexOf(override);
|
46 | if (index !== -1) {
|
47 | this.encodingOverrides.splice(index, 1);
|
48 | }
|
49 | });
|
50 | }
|
51 | getEncodingForResource(resource, preferredEncoding) {
|
52 | let fileEncoding;
|
53 | const override = this.getEncodingOverride(resource);
|
54 | if (override) {
|
55 | fileEncoding = override;
|
56 | }
|
57 | else if (preferredEncoding) {
|
58 | fileEncoding = preferredEncoding;
|
59 | }
|
60 | else {
|
61 | fileEncoding = this.preferences.get('files.encoding', undefined, resource.toString());
|
62 | }
|
63 | if (!fileEncoding || !this.encodingService.exists(fileEncoding)) {
|
64 | return encodings_1.UTF8;
|
65 | }
|
66 | return this.encodingService.toIconvEncoding(fileEncoding);
|
67 | }
|
68 | getEncodingOverride(resource) {
|
69 | if (this.encodingOverrides && this.encodingOverrides.length) {
|
70 | for (const override of this.encodingOverrides) {
|
71 | if (override.parent && resource.isEqualOrParent(override.parent)) {
|
72 | return override.encoding;
|
73 | }
|
74 | if (override.extension && resource.path.ext === `.${override.extension}`) {
|
75 | return override.encoding;
|
76 | }
|
77 | if (override.scheme && override.scheme === resource.scheme) {
|
78 | return override.encoding;
|
79 | }
|
80 | }
|
81 | }
|
82 | return undefined;
|
83 | }
|
84 | };
|
85 | __decorate([
|
86 | (0, inversify_1.inject)(core_preferences_1.CorePreferences),
|
87 | __metadata("design:type", Object)
|
88 | ], EncodingRegistry.prototype, "preferences", void 0);
|
89 | __decorate([
|
90 | (0, inversify_1.inject)(encoding_service_1.EncodingService),
|
91 | __metadata("design:type", encoding_service_1.EncodingService)
|
92 | ], EncodingRegistry.prototype, "encodingService", void 0);
|
93 | EncodingRegistry = __decorate([
|
94 | (0, inversify_1.injectable)()
|
95 | ], EncodingRegistry);
|
96 | exports.EncodingRegistry = EncodingRegistry;
|
97 |
|
\ | No newline at end of file |