Skip to content

Commit 7836c14

Browse files
author
Paul van Brenk
committed
Don't crash when there is no main script
1 parent f0a4177 commit 7836c14

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Nodejs/Product/Nodejs/Workspace/ContextMenuProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
using Microsoft.NodejsTools.NpmUI;
1212
using Microsoft.VisualStudio;
1313
using Microsoft.VisualStudio.OLE.Interop;
14+
using Microsoft.VisualStudio.Shell;
1415
using Microsoft.VisualStudio.Workspace;
1516
using Microsoft.VisualStudio.Workspace.Debug;
1617
using Microsoft.VisualStudio.Workspace.VSIntegration.UI;
1718
using Microsoft.VisualStudioTools.Project;
19+
using ShellInterop = Microsoft.VisualStudio.Shell.Interop;
1820

1921
namespace Microsoft.NodejsTools.Workspace
2022
{
@@ -166,6 +168,11 @@ private async void ExecDebugAsync(WorkspaceVisualNodeBase node)
166168
var workspace = node.Workspace;
167169
var packageJson = PackageJsonFactory.Create(((IFileNode)node).FullPath);
168170

171+
if (string.IsNullOrEmpty(packageJson.Main))
172+
{
173+
return;
174+
}
175+
169176
//invoke debuglaunchtargetprovider on this file
170177
var fileContextActions = await node.Workspace.GetFileContextActionsAsync(packageJson.Main, new[] { DebugLaunchActionContext.ContextTypeGuid });
171178
if (fileContextActions.Any())

Nodejs/Product/Nodejs/Workspace/PackageJsonScannerFactory.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ protected override Task<List<FileReferenceInfo>> ComputeFileReferencesAsync(stri
4343

4444
var packageJson = PackageJsonFactory.Create(filePath);
4545
var main = packageJson.Main;
46-
var fileReferences = new List<FileReferenceInfo>
46+
47+
var fileReferences = new List<FileReferenceInfo>();
48+
49+
if (!string.IsNullOrEmpty(main))
4750
{
48-
new FileReferenceInfo(main,
49-
context: "Debug",
50-
target: main,
51-
referenceType: (int)FileReferenceInfoType.Output)
52-
};
51+
fileReferences.Add(new FileReferenceInfo(main,
52+
context: "Debug",
53+
target: main,
54+
referenceType: (int)FileReferenceInfoType.Output));
55+
}
5356

5457
return Task.FromResult(fileReferences);
5558
}

0 commit comments

Comments
 (0)