Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding logging and setting for clear screen #55

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vscode/powershellprotools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions vscode/powershellprotools/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions vscode/powershellprotools/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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<vscode.TreeItem>('astView', { treeDataProvider: new AstTreeViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('hostProcessView', { treeDataProvider: new HostProcessViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('moduleView', { treeDataProvider: new ModuleViewProvider() });
Expand All @@ -110,7 +115,11 @@ async function finishActivation(context: vscode.ExtensionContext) {
vscode.window.createTreeView<vscode.TreeItem>('sessionsView', { treeDataProvider: new SessionTreeViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('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);
Expand Down
26 changes: 17 additions & 9 deletions vscode/powershellprotools/src/services/powershellservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class PowerShellService {

Reconnect(callback) {
if (this.status === SessionStatus.Initializing) {
Container.Log("Already trying to reconnect.");
return;
}

Expand All @@ -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;
}
Expand All @@ -111,6 +113,7 @@ export class PowerShellService {

Connect(callback) {
if (this.status === SessionStatus.Connected) {
Container.Log("Already connected to PowerShell process.");
callback();
return;
}
Expand All @@ -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`;
Expand Down Expand Up @@ -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)));
Expand Down
18 changes: 10 additions & 8 deletions vscode/powershellprotools/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>("universalDashboardPreviewPort", 10000),
Expand All @@ -36,6 +37,7 @@ export function load() : ISettings {
defaultPackagePsd1: configuration.get<string>("defaultPackagePsd1Path", ""),
signOnSave: configuration.get<boolean>("signOnSave", false),
signOnSaveCertificate: configuration.get<string>("signOnSaveCertificate", ""),
excludeAutomaticVariables: configuration.get<boolean>("excludeAutomaticVariables", false)
excludeAutomaticVariables: configuration.get<boolean>("excludeAutomaticVariables", false),
clearScreenAfterLoad: configuration.get<boolean>("clearScreenAfterLoad", true)
}
}
Loading