Skip to content

Commit 4488ed1

Browse files
author
Paul van Brenk
committed
PR Feedback
1 parent 56e5265 commit 4488ed1

File tree

3 files changed

+28
-46
lines changed

3 files changed

+28
-46
lines changed

Nodejs/Product/Nodejs/SharedProject/OutputWindowWrapper.cs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,41 @@ public sealed class OutputPaneWrapper
1717

1818
// This is the package manager pane that ships with VS2015, and we should print there if available.
1919
private static readonly Guid VSPackageManagerPaneGuid = new Guid("C7E31C31-1451-4E05-B6BE-D11B6829E8BB");
20-
2120
private static readonly Guid TscPaneGuid = new Guid("7CCFA622-001E-4459-9D8B-5B60BE0A18C2");
2221

2322
[Import]
2423
private SVsServiceProvider ServiceProvider { get; set; }
2524

2625
private Dictionary<OutputWindowTarget, IVsOutputWindowPane> lazyOutputPaneCollection = new Dictionary<OutputWindowTarget, IVsOutputWindowPane>();
2726

28-
public OutputPaneWrapper()
29-
{
30-
//...
31-
}
32-
33-
private void InitializeOutputPane(OutputWindowTarget target)
27+
private IVsOutputWindowPane InitializeOutputPane(string title, Guid paneId)
3428
{
3529
ThreadHelper.ThrowIfNotOnUIThread();
36-
var (title, guid) = GetPaneInfo(target);
3730
var outputWindow = (IVsOutputWindow)this.ServiceProvider.GetService(typeof(SVsOutputWindow));
3831

3932
// Try to get the workspace pane if it has already been registered
40-
var hr = outputWindow.GetPane(guid, out var lazyOutputPane);
33+
var hr = outputWindow.GetPane(paneId, out var lazyOutputPane);
4134

4235
// If the workspace pane has not been registered before, create it
4336
if (lazyOutputPane == null || ErrorHandler.Failed(hr))
4437
{
4538

46-
if (ErrorHandler.Failed(outputWindow.CreatePane(guid, title, fInitVisible: 1, fClearWithSolution: 1)) ||
47-
ErrorHandler.Failed(outputWindow.GetPane(guid, out lazyOutputPane)))
39+
if (ErrorHandler.Failed(outputWindow.CreatePane(paneId, title, fInitVisible: 1, fClearWithSolution: 1)) ||
40+
ErrorHandler.Failed(outputWindow.GetPane(paneId, out lazyOutputPane)))
4841
{
49-
return;
42+
return null;
5043
}
5144

5245
// Must activate the workspace pane for it to show up in the output window
5346
lazyOutputPane.Activate();
5447
}
5548

56-
this.lazyOutputPaneCollection.Add(target, lazyOutputPane);
57-
58-
(string title, Guid guid) GetPaneInfo(OutputWindowTarget pane)
59-
{
60-
switch (pane)
61-
{
62-
case OutputWindowTarget.Npm:
63-
return ("Npm", VSPackageManagerPaneGuid);
64-
case OutputWindowTarget.Tsc:
65-
return ("Tsc", TscPaneGuid); /* no need to localize since name of exe */
66-
default:
67-
throw new ArgumentOutOfRangeException(nameof(pane));
68-
}
69-
}
49+
return lazyOutputPane;
7050
}
7151

7252
public void WriteLine(string message, OutputWindowTarget target = OutputWindowTarget.Npm)
7353
{
74-
if (!this.lazyOutputPaneCollection.TryGetValue(target, out var lazyOutputPane))
54+
if (!this.lazyOutputPaneCollection.TryGetValue(target, out var lazyOutputPane) || lazyOutputPane == null)
7555
{
7656
throw new InvalidOperationException("You need to initialize the output panes before using them.");
7757
}
@@ -84,8 +64,10 @@ public void InitializeOutputPanes()
8464
{
8565
ThreadHelper.ThrowIfNotOnUIThread();
8666

87-
InitializeOutputPane(OutputWindowTarget.Npm);
88-
InitializeOutputPane(OutputWindowTarget.Tsc);
67+
var npmPane = InitializeOutputPane("Npm", VSPackageManagerPaneGuid);
68+
this.lazyOutputPaneCollection.Add(OutputWindowTarget.Npm, npmPane);
69+
var tscPane = InitializeOutputPane("Tsc", TscPaneGuid);
70+
this.lazyOutputPaneCollection.Add(OutputWindowTarget.Tsc, tscPane);
8971
}
9072
}
9173

Nodejs/Product/Nodejs/Workspace/ContextMenuProvider.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
using Microsoft.NodejsTools.NpmUI;
1212
using Microsoft.VisualStudio;
1313
using Microsoft.VisualStudio.OLE.Interop;
14-
using Microsoft.VisualStudio.Shell;
1514
using Microsoft.VisualStudio.Workspace;
1615
using Microsoft.VisualStudio.Workspace.Debug;
1716
using Microsoft.VisualStudio.Workspace.VSIntegration.UI;
1817
using Microsoft.VisualStudioTools.Project;
19-
using ShellInterop = Microsoft.VisualStudio.Shell.Interop;
2018

2119
namespace Microsoft.NodejsTools.Workspace
2220
{
@@ -80,24 +78,26 @@ public int Exec(List<WorkspaceVisualNodeBase> selection, Guid pguidCmdGroup, uin
8078
{
8179
this.outputPane.InitializeOutputPanes();
8280

81+
var fileNode = ((IFileNode)node).FullPath;
82+
8383
switch (nCmdID)
8484
{
8585
case PkgCmdId.cmdidWorkSpaceNpmInstallMissing:
86-
ExecNpmInstallMissing((IFileNode)node);
86+
ExecNpmInstallMissing(fileNode);
8787
return VSConstants.S_OK;
8888

8989
case PkgCmdId.cmdidWorkSpaceNpmInstallNew:
90-
ExecNpmInstallNew((IFileNode)node);
90+
ExecNpmInstallNew(fileNode);
9191
return VSConstants.S_OK;
9292

9393
case PkgCmdId.cmdidWorkSpaceNpmUpdate:
94-
ExecNpmUpdate((IFileNode)node);
94+
ExecNpmUpdate(fileNode);
9595
return VSConstants.S_OK;
9696
}
9797

9898
if (nCmdID >= PkgCmdId.cmdidWorkSpaceNpmDynamicScript && nCmdID < PkgCmdId.cmdidWorkSpaceNpmDynamicScriptMax)
9999
{
100-
ExecDynamic((IFileNode)node, nCmdID);
100+
ExecDynamic(fileNode, nCmdID);
101101
return VSConstants.S_OK;
102102
}
103103
}
@@ -119,40 +119,39 @@ public int Exec(List<WorkspaceVisualNodeBase> selection, Guid pguidCmdGroup, uin
119119
// Note: all the Exec commands are async, this allows us to call them in a fire and forget
120120
// pattern, without blocking the UI or losing any logging
121121

122-
private async void ExecNpmInstallMissing(IFileNode node)
122+
private async void ExecNpmInstallMissing(string filePath)
123123
{
124-
using (var npmController = this.CreateController(node.FullPath))
124+
using (var npmController = this.CreateController(filePath))
125125
using (var commander = npmController.CreateNpmCommander())
126126
{
127127
await commander.Install();
128128
}
129129
}
130130

131-
private void ExecNpmInstallNew(IFileNode node)
131+
private void ExecNpmInstallNew(string filePath)
132132
{
133-
using (var npmController = this.CreateController(node.FullPath))
133+
using (var npmController = this.CreateController(filePath))
134134
using (var npmWorker = new NpmWorker(npmController))
135135
using (var manager = new NpmPackageInstallWindow(npmController, npmWorker))
136136
{
137137
manager.ShowModal();
138138
}
139139
}
140140

141-
private async void ExecNpmUpdate(IFileNode node)
141+
private async void ExecNpmUpdate(string filePath)
142142
{
143-
using (var npmController = this.CreateController(node.FullPath))
143+
using (var npmController = this.CreateController(filePath))
144144
using (var commander = npmController.CreateNpmCommander())
145145
{
146146
await commander.UpdatePackagesAsync();
147147
}
148148
}
149149

150-
private async void ExecDynamic(IFileNode node, uint nCmdID)
150+
private async void ExecDynamic(string filePath, uint nCmdID)
151151
{
152152
// Unfortunately the NpmController (and NpmCommander), used for the install and update commands
153153
// doesn't support running arbitrary scripts. And changing that is outside
154154
// the scope of these changes.
155-
var filePath = node.FullPath;
156155
if (TryGetCommand(nCmdID, filePath, out var commandName))
157156
{
158157
using (var npmController = this.CreateController(filePath))
@@ -174,7 +173,7 @@ private async void ExecDebugAsync(WorkspaceVisualNodeBase node)
174173
}
175174

176175
//invoke debuglaunchtargetprovider on this file
177-
var fileContextActions = await node.Workspace.GetFileContextActionsAsync(packageJson.Main, new[] { DebugLaunchActionContext.ContextTypeGuid });
176+
var fileContextActions = await workspace.GetFileContextActionsAsync(packageJson.Main, new[] { DebugLaunchActionContext.ContextTypeGuid });
178177
if (fileContextActions.Any())
179178
{
180179
// we requested a single context, so there should be a single grouping. Use the First action, since they're ordered by priority.
@@ -274,7 +273,8 @@ private static bool TryGetCommand(uint nCmdID, string filePath, out string comma
274273

275274
private INpmController CreateController(string packageJsonPath)
276275
{
277-
Debug.Assert(Path.IsPathRooted(packageJsonPath) && PackageJsonFactory.IsPackageJsonFile(packageJsonPath));
276+
Debug.Assert(Path.IsPathRooted(packageJsonPath));
277+
Debug.Assert(PackageJsonFactory.IsPackageJsonFile(packageJsonPath));
278278

279279
var projectHome = Path.GetDirectoryName(packageJsonPath);
280280

Nodejs/Product/Npm/SPI/NpmCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ await NpmHelpers.ExecuteNpmCommandAsync(
106106
cancelled = true;
107107
}
108108
OnCommandCompleted(this.Arguments, redirector?.HasErrors ?? false, cancelled);
109-
return redirector == null || !redirector.HasErrors; // return true when the command completed without errors, or redirector is null (which means we can't track)
109+
return redirector?.HasErrors != true; // return true when the command completed without errors, or redirector is null (which means we can't track)
110110
}
111111

112112
private sealed class NpmCommandRedirector : Redirector

0 commit comments

Comments
 (0)