Skip to content

Commit

Permalink
Better messaging for tests output in virtual or untrusted scenario (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Sep 6, 2024
1 parent e3a7c7a commit 223eca9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/client/common/vscodeApis/workspaceApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ 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);
}

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);
}

Expand All @@ -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);
}
6 changes: 5 additions & 1 deletion src/client/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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>(ILogOutputChannel, standardOutputChannel);
serviceManager.addSingletonInstance<ITestOutputChannel>(ITestOutputChannel, unitTestOutChannel);
Expand Down

0 comments on commit 223eca9

Please sign in to comment.