Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/opener/browser/opener.contribution.ts
4780 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Disposable } from '../../../../base/common/lifecycle.js';
7
import { URI } from '../../../../base/common/uri.js';
8
import { ICommandService } from '../../../../platform/commands/common/commands.js';
9
import { IFileService } from '../../../../platform/files/common/files.js';
10
import { IOpener, IOpenerService, OpenExternalOptions, OpenInternalOptions } from '../../../../platform/opener/common/opener.js';
11
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
12
import { registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';
13
import { REVEAL_IN_EXPLORER_COMMAND_ID } from '../../files/browser/fileConstants.js';
14
15
class WorkbenchOpenerContribution extends Disposable implements IOpener {
16
public static readonly ID = 'workbench.contrib.opener';
17
18
constructor(
19
@IOpenerService openerService: IOpenerService,
20
@ICommandService private readonly commandService: ICommandService,
21
@IFileService private readonly fileService: IFileService,
22
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
23
) {
24
super();
25
26
this._register(openerService.registerOpener(this));
27
}
28
29
async open(link: URI | string, options?: OpenInternalOptions | OpenExternalOptions): Promise<boolean> {
30
try {
31
const uri = typeof link === 'string' ? URI.parse(link) : link;
32
if (this.workspaceContextService.isInsideWorkspace(uri)) {
33
if ((await this.fileService.stat(uri)).isDirectory) {
34
await this.commandService.executeCommand(REVEAL_IN_EXPLORER_COMMAND_ID, uri);
35
return true;
36
}
37
}
38
} catch {
39
// noop
40
}
41
42
return false;
43
}
44
}
45
46
47
registerWorkbenchContribution2(WorkbenchOpenerContribution.ID, WorkbenchOpenerContribution, WorkbenchPhase.Eventually);
48
49