diff --git a/src/client/common/vscodeApis/workspaceApis.ts b/src/client/common/vscodeApis/workspaceApis.ts index d41c877e5aa8..137382dc71a0 100644 --- a/src/client/common/vscodeApis/workspaceApis.ts +++ b/src/client/common/vscodeApis/workspaceApis.ts @@ -36,11 +36,11 @@ export function findFiles( return vscode.workspace.findFiles(include, exclude, maxResults, token); } -export function onDidCloseTextDocument(handler: (e: vscode.TextDocument) => unknown): vscode.Disposable { +export function onDidCloseTextDocument(handler: (e: vscode.TextDocument) => void): vscode.Disposable { return vscode.workspace.onDidCloseTextDocument(handler); } -export function onDidSaveTextDocument(handler: (e: vscode.TextDocument) => unknown): vscode.Disposable { +export function onDidSaveTextDocument(handler: (e: vscode.TextDocument) => void): vscode.Disposable { return vscode.workspace.onDidSaveTextDocument(handler); } @@ -48,15 +48,15 @@ export function getOpenTextDocuments(): readonly vscode.TextDocument[] { return vscode.workspace.textDocuments; } -export function onDidOpenTextDocument(handler: (doc: vscode.TextDocument) => unknown): vscode.Disposable { +export function onDidOpenTextDocument(handler: (doc: vscode.TextDocument) => void): vscode.Disposable { return vscode.workspace.onDidOpenTextDocument(handler); } -export function onDidChangeTextDocument(handler: (e: vscode.TextDocumentChangeEvent) => unknown): vscode.Disposable { +export function onDidChangeTextDocument(handler: (e: vscode.TextDocumentChangeEvent) => void): vscode.Disposable { return vscode.workspace.onDidChangeTextDocument(handler); } -export function onDidChangeConfiguration(handler: (e: vscode.ConfigurationChangeEvent) => unknown): vscode.Disposable { +export function onDidChangeConfiguration(handler: (e: vscode.ConfigurationChangeEvent) => void): vscode.Disposable { return vscode.workspace.onDidChangeConfiguration(handler); } @@ -75,7 +75,21 @@ export function createFileSystemWatcher( } export function onDidChangeWorkspaceFolders( - handler: (e: vscode.WorkspaceFoldersChangeEvent) => unknown, + handler: (e: vscode.WorkspaceFoldersChangeEvent) => void, ): vscode.Disposable { return vscode.workspace.onDidChangeWorkspaceFolders(handler); } + +export function isVirtualWorkspace(): boolean { + const isVirtualWorkspace = + vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.every((f) => f.uri.scheme !== 'file'); + return !!isVirtualWorkspace; +} + +export function isTrusted(): boolean { + return vscode.workspace.isTrusted; +} + +export function onDidGrantWorkspaceTrust(handler: () => void): vscode.Disposable { + return vscode.workspace.onDidGrantWorkspaceTrust(handler); +} diff --git a/src/client/extensionInit.ts b/src/client/extensionInit.ts index 38b402b3c9de..1332dc6bd070 100644 --- a/src/client/extensionInit.ts +++ b/src/client/extensionInit.ts @@ -4,7 +4,7 @@ 'use strict'; import { Container } from 'inversify'; -import { Disposable, Memento, window } from 'vscode'; +import { Disposable, l10n, Memento, window } from 'vscode'; import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry'; import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry'; import { registerTypes as commonRegisterTypes } from './common/serviceRegistry'; @@ -28,6 +28,7 @@ import * as pythonEnvironments from './pythonEnvironments'; import { IDiscoveryAPI } from './pythonEnvironments/base/locator'; import { registerLogger } from './logging'; import { OutputChannelLogger } from './logging/outputChannelLogger'; +import { isTrusted, isVirtualWorkspace } from './common/vscodeApis/workspaceApis'; // The code in this module should do nothing more complex than register // objects to DI and simple init (e.g. no side effects). That implies @@ -57,6 +58,9 @@ export function initializeGlobals( const unitTestOutChannel = window.createOutputChannel(OutputChannelNames.pythonTest); disposables.push(unitTestOutChannel); + if (isVirtualWorkspace() || !isTrusted()) { + unitTestOutChannel.appendLine(l10n.t('Unit tests are not supported in this environment.')); + } serviceManager.addSingletonInstance(ILogOutputChannel, standardOutputChannel); serviceManager.addSingletonInstance(ITestOutputChannel, unitTestOutChannel);