@@ -18,6 +18,7 @@ internal sealed partial class OpenVisualStudioCodeCommand : InvokableCommand, IH
1818{
1919 private readonly VisualStudioCodePage page ;
2020 private readonly bool _elevated ;
21+ private readonly bool _isFromVisualStudioSolution ;
2122
2223 public VisualStudioCodeWorkspace Workspace { get ; set ; }
2324
@@ -26,13 +27,16 @@ internal sealed partial class OpenVisualStudioCodeCommand : InvokableCommand, IH
2627 /// </summary>
2728 /// <param name="workspace">The Visual Studio Code workspace to open.</param>
2829 /// <param name="page">The Visual Studio Code page instance.</param>
29- public OpenVisualStudioCodeCommand ( VisualStudioCodeWorkspace workspace , VisualStudioCodePage page , bool elevated = false )
30+ /// <param name="elevated">Whether to run as administrator.</param>
31+ /// <param name="isFromVisualStudioSolution">Whether this command is opening a Visual Studio solution.</param>
32+ public OpenVisualStudioCodeCommand ( VisualStudioCodeWorkspace workspace , VisualStudioCodePage page , bool elevated = false , bool isFromVisualStudioSolution = false )
3033 {
3134 try
3235 {
3336 Workspace = workspace ;
3437 this . page = page ;
3538 _elevated = elevated ;
39+ _isFromVisualStudioSolution = isFromVisualStudioSolution ;
3640 this . Icon = Classes . Icon . VisualStudioCode ;
3741
3842 if ( elevated )
@@ -42,7 +46,14 @@ public OpenVisualStudioCodeCommand(VisualStudioCodeWorkspace workspace, VisualSt
4246 }
4347 else
4448 {
45- Name = $ "Open";
49+ if ( isFromVisualStudioSolution )
50+ {
51+ Name = "Open in Visual Studio Code" ;
52+ }
53+ else
54+ {
55+ Name = "Open" ;
56+ }
4657 }
4758 }
4859 catch ( Exception ex )
@@ -60,7 +71,7 @@ public override CommandResult Invoke()
6071 {
6172 try
6273 {
63- if ( Workspace . WorkspaceType == WorkspaceType . Solution || Workspace . WorkspaceType == WorkspaceType . Solution2026 )
74+ if ( ! _isFromVisualStudioSolution && ( Workspace . WorkspaceType == WorkspaceType . Solution || Workspace . WorkspaceType == WorkspaceType . Solution2026 ) )
6475 {
6576 return CommandResult . Confirm ( new ConfirmationArgs { Title = "Error" , Description = "Cannot open a solution with this command." } ) ;
6677 }
@@ -88,7 +99,22 @@ public override CommandResult Invoke()
8899 }
89100 else
90101 {
91- arguments = $ "--folder-uri \" { Workspace . Path } \" ";
102+ var path = Workspace . Path ;
103+ if ( _isFromVisualStudioSolution )
104+ {
105+ if ( File . Exists ( path ) && ! Directory . Exists ( path ) )
106+ {
107+ path = Path . GetDirectoryName ( path ) ;
108+ }
109+
110+ if ( path != null )
111+ {
112+ var uri = new Uri ( path ) ;
113+ path = uri . AbsoluteUri ;
114+ }
115+ }
116+
117+ arguments = $ "--folder-uri \" { path } \" ";
92118 }
93119
94120 if ( page . SettingsManager . UseHelperLauncher )
0 commit comments