forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpartialModeStatus.ts
More file actions
58 lines (53 loc) · 2.36 KB
/
partialModeStatus.ts
File metadata and controls
58 lines (53 loc) · 2.36 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// IMPORTANT: Do not import any node fs related modules here, as they do not work in browser.
import { inject, injectable } from 'inversify';
import type * as vscodeTypes from 'vscode';
import { IWorkspaceService } from '../common/application/types';
import { IDisposableRegistry } from '../common/types';
import { Common, LanguageService } from '../common/utils/localize';
import { IExtensionSingleActivationService } from './types';
/**
* Only partial features are available when running in untrusted or a
* virtual workspace, this creates a UI element to indicate that.
*/
@injectable()
export class PartialModeStatusItem implements IExtensionSingleActivationService {
public readonly supportedWorkspaceTypes = { untrustedWorkspace: true, virtualWorkspace: true };
constructor(
@inject(IWorkspaceService) private readonly workspace: IWorkspaceService,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
) {}
public async activate(): Promise<void> {
const { isTrusted, isVirtualWorkspace } = this.workspace;
if (isTrusted && !isVirtualWorkspace) {
return;
}
const statusItem = this.createStatusItem();
if (statusItem) {
this.disposables.push(statusItem);
}
}
private createStatusItem() {
// eslint-disable-next-line global-require
const vscode = require('vscode') as typeof vscodeTypes;
if ('createLanguageStatusItem' in vscode.languages) {
const statusItem = vscode.languages.createLanguageStatusItem('python.projectStatus', {
language: 'python',
});
statusItem.name = LanguageService.statusItem.name;
statusItem.severity = vscode.LanguageStatusSeverity.Warning;
statusItem.text = LanguageService.statusItem.text;
statusItem.detail = !this.workspace.isTrusted
? LanguageService.statusItem.detail
: LanguageService.virtualWorkspaceStatusItem.detail;
statusItem.command = {
title: Common.learnMore,
command: 'vscode.open',
arguments: [vscode.Uri.parse('https://aka.ms/AAdzyh4')],
};
return statusItem;
}
return undefined;
}
}