-
Notifications
You must be signed in to change notification settings - Fork 29.9k
/
openerService.ts
88 lines (76 loc) · 3.02 KB
/
openerService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import URI from 'vs/base/common/uri';
import { parse } from 'vs/base/common/marshalling';
import { Schemas } from 'vs/base/common/network';
import { TPromise } from 'vs/base/common/winjs.base';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { normalize } from 'vs/base/common/paths';
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
export class OpenerService implements IOpenerService {
_serviceBrand: any;
constructor(
@IEditorService private _editorService: IEditorService,
@ICommandService private _commandService: ICommandService,
@optional(ITelemetryService) private _telemetryService: ITelemetryService = NullTelemetryService
) {
//
}
open(resource: URI, options?: { openToSide?: boolean }): TPromise<any> {
/* __GDPR__
"openerService" : {
"scheme" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this._telemetryService.publicLog('openerService', { scheme: resource.scheme });
const { scheme, path, query, fragment } = resource;
let promise: TPromise<any>;
if (scheme === Schemas.http || scheme === Schemas.https) {
// open http
window.open(resource.toString(true));
} else if (scheme === 'command' && CommandsRegistry.getCommand(path)) {
// execute as command
let args: any = [];
try {
args = parse(query);
if (!Array.isArray(args)) {
args = [args];
}
} catch (e) {
//
}
promise = this._commandService.executeCommand(path, ...args);
} else {
let selection: {
startLineNumber: number;
startColumn: number;
};
const match = /^L?(\d+)(?:,(\d+))?/.exec(fragment);
if (match) {
// support file:///some/file.js#73,84
// support file:///some/file.js#L73
selection = {
startLineNumber: parseInt(match[1]),
startColumn: match[2] ? parseInt(match[2]) : 1
};
// remove fragment
resource = resource.with({ fragment: '' });
}
if (!resource.scheme) {
// we cannot handle those
return TPromise.as(undefined);
} else if (resource.scheme === Schemas.file) {
resource = resource.with({ path: normalize(resource.path) }); // workaround for non-normalized paths (https://github.com/Microsoft/vscode/issues/12954)
}
promise = this._editorService.openEditor({ resource, options: { selection, } }, options && options.openToSide);
}
return TPromise.as(promise);
}
}