|
1 | | -import { type ExtensionContext, window, workspace, commands } from 'vscode' |
2 | | - |
3 | | -import { PesterTestController } from './pesterTestController' |
| 1 | +import { type ExtensionContext, window, workspace, Disposable, WorkspaceConfiguration, Extension } from 'vscode' |
4 | 2 | import { |
5 | | - getPowerShellExtension, |
6 | | - PowerShellExtensionClient |
| 3 | + waitForPowerShellExtension, |
| 4 | + PowerShellExtensionClient, |
| 5 | + IPowerShellExtensionClient |
7 | 6 | } from './powershellExtensionClient' |
| 7 | +import { watchWorkspace } from './workspaceWatcher' |
| 8 | +import log, { VSCodeLogOutputChannelTransport } from './log' |
8 | 9 |
|
9 | 10 | export async function activate(context: ExtensionContext) { |
10 | | - // PowerShell extension is a prerequisite, but we allow either preview or normal, which is why we do this instead of |
11 | | - // leverage package.json dependencies |
12 | | - const powershellExtension = getPowerShellExtension(context) |
13 | | - |
14 | | - // Short circuit this activate call if we didn't find a PowerShell Extension. Another activate will be triggered once |
15 | | - // the powershell extension is available |
16 | | - if (powershellExtension === undefined) { |
17 | | - return |
| 11 | + |
| 12 | + log.attachTransport(new VSCodeLogOutputChannelTransport('Pester').transport) |
| 13 | + |
| 14 | + subscriptions = context.subscriptions |
| 15 | + |
| 16 | + // PowerShell extension is a prerequisite |
| 17 | + const powershellExtension = await waitForPowerShellExtension() |
| 18 | + |
| 19 | + pesterExtensionContext = { |
| 20 | + extensionContext: context, |
| 21 | + powerShellExtension: powershellExtension, |
| 22 | + powershellExtensionPesterConfig: PowerShellExtensionClient.GetPesterSettings() |
18 | 23 | } |
19 | 24 |
|
| 25 | + promptForPSLegacyCodeLensDisable() |
| 26 | + |
| 27 | + await watchWorkspace() |
| 28 | + |
| 29 | + // TODO: Rig this up for multiple workspaces |
| 30 | + // const stopPowerShellCommand = commands.registerCommand('pester.stopPowershell', () => { |
| 31 | + // if (controller.stopPowerShell()) { |
| 32 | + // void window.showInformationMessage('PowerShell background process stopped.') |
| 33 | + // } else { |
| 34 | + // void window.showWarningMessage('No PowerShell background process was running !') |
| 35 | + // } |
| 36 | + // }) |
| 37 | + |
| 38 | + // context.subscriptions.push( |
| 39 | + // controller, |
| 40 | + // stopPowerShellCommand, |
| 41 | + // ) |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +/** Register a Disposable with the extension so that it can be cleaned up if the extension is disabled */ |
| 46 | +export function registerDisposable(disposable: Disposable) { |
| 47 | + if (subscriptions == undefined) { |
| 48 | + throw new Error('registerDisposable called before activate. This should never happen and is a bug.') |
| 49 | + } |
| 50 | + subscriptions.push(disposable) |
| 51 | +} |
| 52 | + |
| 53 | +export function registerDisposables(disposables: Disposable[]) { |
| 54 | + subscriptions.push(Disposable.from(...disposables)) |
| 55 | +} |
| 56 | + |
| 57 | +let subscriptions: Disposable[] |
| 58 | + |
| 59 | +type PesterExtensionContext = { |
| 60 | + extensionContext: ExtensionContext |
| 61 | + powerShellExtension: Extension<IPowerShellExtensionClient> |
| 62 | + powershellExtensionPesterConfig: WorkspaceConfiguration |
| 63 | +} |
| 64 | + |
| 65 | +/** Get the activated extension context */ |
| 66 | +export function getPesterExtensionContext() { |
| 67 | + if (pesterExtensionContext == undefined) { |
| 68 | + throw new Error('Pester Extension Context attempted to be fetched before activation. This should never happen and is a bug') |
| 69 | + } |
| 70 | + |
| 71 | + return pesterExtensionContext |
| 72 | +} |
| 73 | +let pesterExtensionContext: PesterExtensionContext |
| 74 | + |
| 75 | +function promptForPSLegacyCodeLensDisable() { |
20 | 76 | // Disable PowerShell codelens setting if present |
21 | 77 | const config = PowerShellExtensionClient.GetPesterSettings() |
| 78 | + |
22 | 79 | const psExtensionCodeLensSetting: boolean = config.codeLens |
23 | 80 |
|
24 | 81 | const suppressCodeLensNotice = workspace.getConfiguration('pester').get<boolean>('suppressCodeLensNotice') ?? false |
@@ -50,18 +107,4 @@ export async function activate(context: ExtensionContext) { |
50 | 107 | } |
51 | 108 | }) |
52 | 109 | } |
53 | | - |
54 | | - const controller = new PesterTestController(powershellExtension, context) |
55 | | - const stopPowerShellCommand = commands.registerCommand('pester.stopPowershell', () => { |
56 | | - if (controller.stopPowerShell()) { |
57 | | - void window.showInformationMessage('PowerShell background process stopped.') |
58 | | - } else { |
59 | | - void window.showWarningMessage('No PowerShell background process was running !') |
60 | | - } |
61 | | - }) |
62 | | - |
63 | | - context.subscriptions.push( |
64 | | - controller, |
65 | | - stopPowerShellCommand, |
66 | | - ) |
67 | 110 | } |
0 commit comments