diff --git a/vscode/powershellprotools/package.json b/vscode/powershellprotools/package.json index fe93534..8467ad2 100644 --- a/vscode/powershellprotools/package.json +++ b/vscode/powershellprotools/package.json @@ -516,6 +516,11 @@ "type": "boolean", "default": false, "markdownDescription": "Whether to exclude automatic variables from the variables window." + }, + "poshProTools.clearScreenAfterLoad": { + "type": "boolean", + "default": true, + "markdownDescription": "Whether to clear the terminal after loading PowerShell Pro Tools. Set to false to see any errors loading the module." } } }, diff --git a/vscode/powershellprotools/src/container.ts b/vscode/powershellprotools/src/container.ts index 27ef539..197370d 100644 --- a/vscode/powershellprotools/src/container.ts +++ b/vscode/powershellprotools/src/container.ts @@ -57,6 +57,8 @@ export class Container { // context.subscriptions.push(codeLensProviderDisposable) this.outputChannel = vscode.window.createOutputChannel("PowerShell Pro Tools"); + + this.Log("Starting PowerShell Pro Tools..."); } static FinishInitialize() { diff --git a/vscode/powershellprotools/src/extension.ts b/vscode/powershellprotools/src/extension.ts index 4281b28..676902d 100644 --- a/vscode/powershellprotools/src/extension.ts +++ b/vscode/powershellprotools/src/extension.ts @@ -85,6 +85,9 @@ export async function activate(context: vscode.ExtensionContext) { } async function finishActivation(context: vscode.ExtensionContext) { + + Container.Log("Finishing extension activation."); + let terminal = null; do { terminal = vscode.window.terminals.find(x => x.name.startsWith("PowerShell Extension")); @@ -97,6 +100,8 @@ async function finishActivation(context: vscode.ExtensionContext) { const powershellProTools = vscode.extensions.getExtension("ironmansoftware.powershellprotools")!; const currentVersion = powershellProTools.packageJSON.version; + Container.Log("Creating tree views."); + vscode.window.createTreeView('astView', { treeDataProvider: new AstTreeViewProvider() }); vscode.window.createTreeView('hostProcessView', { treeDataProvider: new HostProcessViewProvider() }); vscode.window.createTreeView('moduleView', { treeDataProvider: new ModuleViewProvider() }); @@ -110,7 +115,11 @@ async function finishActivation(context: vscode.ExtensionContext) { vscode.window.createTreeView('sessionsView', { treeDataProvider: new SessionTreeViewProvider() }); vscode.window.createTreeView('jobView', { treeDataProvider: new JobTreeViewProvider() }); + Container.Log("Connecting to PowerShell Editor Services."); + powerShellService.Connect(() => { + Container.Log("Starting code analysis."); + if (vscode.workspace.workspaceFolders) { for (let wsf of vscode.workspace.workspaceFolders) { Container.PowerShellService.AddWorkspaceFolder(wsf.uri.fsPath); diff --git a/vscode/powershellprotools/src/services/powershellservice.ts b/vscode/powershellprotools/src/services/powershellservice.ts index af73b09..9af7889 100644 --- a/vscode/powershellprotools/src/services/powershellservice.ts +++ b/vscode/powershellprotools/src/services/powershellservice.ts @@ -83,6 +83,7 @@ export class PowerShellService { Reconnect(callback) { if (this.status === SessionStatus.Initializing) { + Container.Log("Already trying to reconnect."); return; } @@ -91,6 +92,7 @@ export class PowerShellService { this.logger?.destroy(); if (this.reconnectDepth > 5) { + Container.Log("Reconnect depth exceeded. Connection failed."); this.setSessionStatus(SessionStatus.Failed); return; } @@ -111,6 +113,7 @@ export class PowerShellService { Connect(callback) { if (this.status === SessionStatus.Connected) { + Container.Log("Already connected to PowerShell process."); callback(); return; } @@ -124,23 +127,27 @@ export class PowerShellService { poshToolsModulePath = path.join(vscode.extensions.getExtension("ironmansoftware.powershellprotools").extensionPath, "src", "Modules", "PowerShellProTools", "PowerShellProTools.psd1"); } - var terminal = vscode.window.terminals.find(x => x.name.startsWith("PowerShell Extension")); - if (terminal == null) { - this.setSessionStatus(SessionStatus.Failed); - throw ("PowerShell Extension not found."); - } - var terminal = vscode.window.terminals.find(x => x.name.startsWith("PowerShell Extension")); if (terminal != null) { - // todo: logging + Container.Log("Importing module in PowerShell and starting server."); terminal.sendText(`Import-Module '${cmdletPath}'`, true); terminal.sendText(`Import-Module '${poshToolsModulePath}'`, true); terminal.sendText(`Start-PoshToolsServer -PipeName '${this.pipeName}'`, true); - terminal.sendText('Clear-Host', true); + + const settings = load(); + + if (settings.clearScreenAfterLoad) { + terminal.sendText('Clear-Host', true); + } + + } else { + Container.Log("PowerShell Extension not found."); + this.setSessionStatus(SessionStatus.Failed); + throw ("PowerShell Extension not found."); } setTimeout(() => { - // todo: logging + Container.Log("Connecting named pipe to PoshTools server."); var pipePath = path.join(os.tmpdir(), `CoreFxPipe_${this.pipeName}_log`); if (process.platform === "win32") { pipePath = `\\\\.\\pipe\\${this.pipeName}_log`; @@ -207,6 +214,7 @@ export class PowerShellService { }); client.on("error", (e) => { + Container.Log("Error sending data on named pipe. " + e); client.destroy(); setTimeout(async () => { await this.Reconnect(() => this.invokeMethod(method, args).then(any => resolve(any))); diff --git a/vscode/powershellprotools/src/settings.ts b/vscode/powershellprotools/src/settings.ts index fba0b1c..8375e8d 100644 --- a/vscode/powershellprotools/src/settings.ts +++ b/vscode/powershellprotools/src/settings.ts @@ -6,20 +6,21 @@ export interface ISettings { showUpgradeNotification: boolean; debugModuleLoad: boolean; ignoredModules: string; - ignoredAssemblies : string; - ignoredTypes : string; - ignoredCommands : string; - ignoredVariables : string; - ignoredPaths : string; + ignoredAssemblies: string; + ignoredTypes: string; + ignoredCommands: string; + ignoredVariables: string; + ignoredPaths: string; checkForModuleUpdates: boolean; license: string; defaultPackagePsd1: string; - signOnSave: boolean; + signOnSave: boolean; signOnSaveCertificate: string; excludeAutomaticVariables: boolean; + clearScreenAfterLoad: boolean; } -export function load() : ISettings { +export function load(): ISettings { const configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(PowerShellLanguageId); return { universalDashboardPreviewPort: configuration.get("universalDashboardPreviewPort", 10000), @@ -36,6 +37,7 @@ export function load() : ISettings { defaultPackagePsd1: configuration.get("defaultPackagePsd1Path", ""), signOnSave: configuration.get("signOnSave", false), signOnSaveCertificate: configuration.get("signOnSaveCertificate", ""), - excludeAutomaticVariables: configuration.get("excludeAutomaticVariables", false) + excludeAutomaticVariables: configuration.get("excludeAutomaticVariables", false), + clearScreenAfterLoad: configuration.get("clearScreenAfterLoad", true) } }