Skip to content

Commit

Permalink
Prevent refactoring from sending commands before init
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Jul 7, 2024
1 parent 7417679 commit a518b6d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
14 changes: 12 additions & 2 deletions HostInjection/PoshToolsServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,12 @@ public string GetPowerShellProcessPath()

public IEnumerable<TreeView> GetTreeViews()
{
var json = ExecutePowerShellMainRunspace<string>("[PowerShellToolsPro.VSCode.TreeViewService]::Instance.GetTreeViews() | ConvertTo-Json -WarningAction SilentlyContinue").First();
var json = ExecutePowerShellMainRunspace<string>("[PowerShellToolsPro.VSCode.TreeViewService]::Instance.GetTreeViews() | ConvertTo-Json -WarningAction SilentlyContinue").FirstOrDefault();

if (json == null)
{
return Array.Empty<TreeView>();
}

if (json.StartsWith("["))
{
Expand Down Expand Up @@ -850,7 +855,12 @@ public IEnumerable<string> GetHistory()

public IEnumerable<PSJob> GetJobs()
{
var json = ExecutePowerShellMainRunspace<string>("Get-Job | ForEach-Object { [PowerShellToolsPro.Cmdlets.VSCode.PSJob]$_ } | ConvertTo-Json -WarningAction SilentlyContinue").First();
var json = ExecutePowerShellMainRunspace<string>("Get-Job | ForEach-Object { [PowerShellToolsPro.Cmdlets.VSCode.PSJob]$_ } | ConvertTo-Json -WarningAction SilentlyContinue").FirstOrDefault();

if (json == null)
{
return Array.Empty<PSJob>();
}

if (json.StartsWith("["))
{
Expand Down
3 changes: 1 addition & 2 deletions vscode/powershellprotools/src/commands/refactoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { Container } from '../container';
import { ICommand } from './command';
import { RefactorInfo, RefactoringProperty, RefactorProperty, RefactorRequest, RefactorTextEdit, RefactorType, TextEditorState, TextEditType } from '../types';

//https://github.com/microsoft/vscode-extension-samples/blob/master/code-actions-sample/src/extension.ts
export class RefactoringCommands implements ICommand, vscode.CodeActionProvider {
async provideCodeActions(document: vscode.TextDocument, range: vscode.Range | vscode.Selection, context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<(vscode.CodeAction | vscode.Command)[]> {
if (!Container.initialize) return;
if (!Container.IsInitialized(false)) return;

var request = this.getRefactorRequest();

Expand Down
4 changes: 2 additions & 2 deletions vscode/powershellprotools/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export class Container {
return load();
}

static IsInitialized() {
if (!this._initialized) {
static IsInitialized(showWaring: boolean = true) {
if (showWaring && !this._initialized) {
vscode.window.showWarningMessage("PowerShell Pro Tools is still starting.");
}

Expand Down
30 changes: 15 additions & 15 deletions vscode/powershellprotools/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ 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() });
vscode.window.createTreeView<vscode.TreeItem>('providerView', { treeDataProvider: new ProviderViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('quickScriptView', { treeDataProvider: new QuickScriptViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('variableView', { treeDataProvider: new VariableViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('infoView', { treeDataProvider: new InfoViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('reflectionView', { treeDataProvider: new ReflectionViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('customView', { treeDataProvider: new CustomTreeViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('historyView', { treeDataProvider: new HistoryTreeViewProvider() });
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("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() });
vscode.window.createTreeView<vscode.TreeItem>('providerView', { treeDataProvider: new ProviderViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('quickScriptView', { treeDataProvider: new QuickScriptViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('variableView', { treeDataProvider: new VariableViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('infoView', { treeDataProvider: new InfoViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('reflectionView', { treeDataProvider: new ReflectionViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('customView', { treeDataProvider: new CustomTreeViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('historyView', { treeDataProvider: new HistoryTreeViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('sessionsView', { treeDataProvider: new SessionTreeViewProvider() });
vscode.window.createTreeView<vscode.TreeItem>('jobView', { treeDataProvider: new JobTreeViewProvider() });

Container.Log("Starting code analysis.");

if (vscode.workspace.workspaceFolders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class PowerShellService {
});

client.on("error", (e) => {
Container.Log("Error sending data on named pipe. " + e);
Container.Log(`Invoke method: ${method} Error sending data on named pipe. ${e}`);
client.destroy();
setTimeout(async () => {
await this.Reconnect(() => this.invokeMethod(method, args).then(any => resolve(any)));
Expand Down

0 comments on commit a518b6d

Please sign in to comment.