UNPKG

2.22 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.CommandOpenHandler = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const command_1 = require("../common/command");
22let CommandOpenHandler = class CommandOpenHandler {
23 constructor() {
24 this.id = 'command';
25 }
26 canHandle(uri) {
27 return uri.scheme === 'command' ? 500 : -1;
28 }
29 async open(uri) {
30 // eslint-disable-next-line @typescript-eslint/no-explicit-any
31 let args = [];
32 try {
33 args = JSON.parse(decodeURIComponent(uri.query));
34 }
35 catch {
36 // ignore and retry
37 try {
38 args = JSON.parse(uri.query);
39 }
40 catch {
41 args = uri.query;
42 }
43 }
44 if (!Array.isArray(args)) {
45 args = [args];
46 }
47 await this.commands.executeCommand(uri.path.toString(), ...args);
48 return true;
49 }
50};
51(0, tslib_1.__decorate)([
52 (0, inversify_1.inject)(command_1.CommandService),
53 (0, tslib_1.__metadata)("design:type", Object)
54], CommandOpenHandler.prototype, "commands", void 0);
55CommandOpenHandler = (0, tslib_1.__decorate)([
56 (0, inversify_1.injectable)()
57], CommandOpenHandler);
58exports.CommandOpenHandler = CommandOpenHandler;
59//# sourceMappingURL=command-open-handler.js.map
\No newline at end of file