forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactiveResource.ts
More file actions
27 lines (23 loc) · 1007 Bytes
/
activeResource.ts
File metadata and controls
27 lines (23 loc) · 1007 Bytes
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { Resource } from '../types';
import { IActiveResourceService, IDocumentManager, IWorkspaceService } from './types';
@injectable()
export class ActiveResourceService implements IActiveResourceService {
constructor(
@inject(IDocumentManager) private readonly documentManager: IDocumentManager,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
) {}
public getActiveResource(): Resource {
const editor = this.documentManager.activeTextEditor;
if (editor && !editor.document.isUntitled) {
return editor.document.uri;
}
return Array.isArray(this.workspaceService.workspaceFolders) &&
this.workspaceService.workspaceFolders.length > 0
? this.workspaceService.workspaceFolders[0].uri
: undefined;
}
}