UNPKG

4.05 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-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.ResourceContextKey = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const context_key_service_1 = require("./context-key-service");
22const language_service_1 = require("./language-service");
23let ResourceContextKey = class ResourceContextKey {
24 init() {
25 this.resource = this.contextKeyService.createKey('resource', undefined);
26 this.resourceSchemeKey = this.contextKeyService.createKey('resourceScheme', undefined);
27 this.resourceFileName = this.contextKeyService.createKey('resourceFilename', undefined);
28 this.resourceExtname = this.contextKeyService.createKey('resourceExtname', undefined);
29 this.resourceLangId = this.contextKeyService.createKey('resourceLangId', undefined);
30 this.resourceDirName = this.contextKeyService.createKey('resourceDirName', undefined);
31 this.resourcePath = this.contextKeyService.createKey('resourcePath', undefined);
32 this.resourceSet = this.contextKeyService.createKey('resourceSet', false);
33 }
34 get() {
35 return this.resource.get();
36 }
37 set(resourceUri) {
38 this.resource.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.toString());
39 this.resourceSchemeKey.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.scheme);
40 this.resourceFileName.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.base);
41 this.resourceExtname.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.ext);
42 this.resourceLangId.set(resourceUri && this.getLanguageId(resourceUri));
43 this.resourceDirName.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.dir.fsPath());
44 this.resourcePath.set(resourceUri === null || resourceUri === void 0 ? void 0 : resourceUri.path.fsPath());
45 this.resourceSet.set(Boolean(resourceUri));
46 }
47 getLanguageId(uri) {
48 if (uri) {
49 for (const language of this.languages.languages) {
50 if (language.extensions.has(uri.path.ext)) {
51 return language.id;
52 }
53 }
54 }
55 return undefined;
56 }
57};
58(0, tslib_1.__decorate)([
59 (0, inversify_1.inject)(language_service_1.LanguageService),
60 (0, tslib_1.__metadata)("design:type", language_service_1.LanguageService)
61], ResourceContextKey.prototype, "languages", void 0);
62(0, tslib_1.__decorate)([
63 (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
64 (0, tslib_1.__metadata)("design:type", Object)
65], ResourceContextKey.prototype, "contextKeyService", void 0);
66(0, tslib_1.__decorate)([
67 (0, inversify_1.postConstruct)(),
68 (0, tslib_1.__metadata)("design:type", Function),
69 (0, tslib_1.__metadata)("design:paramtypes", []),
70 (0, tslib_1.__metadata)("design:returntype", void 0)
71], ResourceContextKey.prototype, "init", null);
72ResourceContextKey = (0, tslib_1.__decorate)([
73 (0, inversify_1.injectable)()
74], ResourceContextKey);
75exports.ResourceContextKey = ResourceContextKey;
76//# sourceMappingURL=resource-context-key.js.map
\No newline at end of file