UNPKG

4.64 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 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;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.ResourceContextKey = void 0;
28const inversify_1 = require("inversify");
29const context_key_service_1 = require("./context-key-service");
30const language_service_1 = require("./language-service");
31let ResourceContextKey = class ResourceContextKey {
32 init() {
33 this.resource = this.contextKeyService.createKey('resource', undefined);
34 this.resourceSchemeKey = this.contextKeyService.createKey('resourceScheme', undefined);
35 this.resourceFileName = this.contextKeyService.createKey('resourceFilename', undefined);
36 this.resourceExtname = this.contextKeyService.createKey('resourceExtname', undefined);
37 this.resourceLangId = this.contextKeyService.createKey('resourceLangId', undefined);
38 this.resourceDirName = this.contextKeyService.createKey('resourceDirName', undefined);
39 this.resourcePath = this.contextKeyService.createKey('resourcePath', undefined);
40 this.resourceSet = this.contextKeyService.createKey('resourceSet', false);
41 }
42 get() {
43 return this.resource.get();
44 }
45 set(resourceUri) {
46 this.resource.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.toString());
47 this.resourceSchemeKey.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.scheme);
48 this.resourceFileName.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.base);
49 this.resourceExtname.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.ext);
50 this.resourceLangId.set(resourceUri && this.getLanguageId(resourceUri));
51 this.resourceDirName.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.dir.fsPath());
52 this.resourcePath.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.fsPath());
53 this.resourceSet.set(Boolean(resourceUri));
54 }
55 getLanguageId(uri) {
56 if (uri) {
57 for (const language of this.languages.languages) {
58 if (language.extensions.has(uri.path.ext)) {
59 return language.id;
60 }
61 }
62 }
63 return undefined;
64 }
65};
66__decorate([
67 (0, inversify_1.inject)(language_service_1.LanguageService),
68 __metadata("design:type", language_service_1.LanguageService)
69], ResourceContextKey.prototype, "languages", void 0);
70__decorate([
71 (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
72 __metadata("design:type", Object)
73], ResourceContextKey.prototype, "contextKeyService", void 0);
74__decorate([
75 (0, inversify_1.postConstruct)(),
76 __metadata("design:type", Function),
77 __metadata("design:paramtypes", []),
78 __metadata("design:returntype", void 0)
79], ResourceContextKey.prototype, "init", null);
80ResourceContextKey = __decorate([
81 (0, inversify_1.injectable)()
82], ResourceContextKey);
83exports.ResourceContextKey = ResourceContextKey;
84//# sourceMappingURL=resource-context-key.js.map
\No newline at end of file