Skip to content

Make debugging options page nicer #159

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

Merged
merged 1 commit into from
Jun 28, 2015
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
120 changes: 120 additions & 0 deletions VisualRust.Project/EnvironmentPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VisualRust.Project
{
static class EnvironmentPath
{
public static string FindExePath(string name)
{
string extensionsVariable = Environment.GetEnvironmentVariable("PATHEXT") ?? ".COM;.EXE";
string[] extensions = extensionsVariable.Split(new [] {";"}, StringSplitOptions.RemoveEmptyEntries);
string[] fileNames = extensions.Where(s => s.StartsWith(".")).Select(e => name + e).ToArray();
foreach(string path in SplitPaths(Environment.GetEnvironmentVariable("PATH") ?? ""))
{
foreach(string file in fileNames)
{
string fullPath = Path.Combine(path, file);
if(File.Exists(fullPath))
return fullPath;
}
}
return null;
}

private static List<string> SplitPaths(string path)
{
int i = 0;
List<string> result = new List<string>();
while(i < path.Length)
{
int start = i;
int end;
if(path[start] == '"')
{
start++;
end = path.IndexOf('"', start);
if (end == -1)
{
end = path.Length;
i = path.Length;
}
else
{
int semi = path.IndexOf(';', end);
if(semi == -1)
i = path.Length;
else
i = semi + 1;
}
}
else
{
end = path.IndexOf(';', start);
if (end == -1)
{
end = path.Length;
i = path.Length;
}
else
{
i = end + 1;
}
}
result.Add(path.Substring(start, end - start));
}
return result;
}

#if TEST
[TestFixture]
private class Test
{
[Test]
public void SplitPathsPlain()
{
CollectionAssert.AreEquivalent(
new String[] { @"D:\dev\Rust\bin", @"D:\dev\LLVM\bin" },
SplitPaths(@"D:\dev\LLVM\bin;D:\dev\Rust\bin"));
}

[Test]
public void SplitPathsSingleChars()
{
CollectionAssert.AreEquivalent(
new String[] { "C", "D" },
SplitPaths("C;D"));
}

[Test]
public void SplitPathsExtraSemicolon()
{
CollectionAssert.AreEquivalent(
new String[] { @"D:\dev\Rust\bin", @"D:\dev\LLVM\bin" },
SplitPaths(@"D:\dev\LLVM\bin;D:\dev\Rust\bin;"));
}

[Test]
public void SplitPathsQuoted()
{
CollectionAssert.AreEquivalent(
new String[] { @"D:\dev\LLVM\bin", @"C:\main() {printf('%d', 42);}" },
SplitPaths(@"D:\dev\LLVM\bin;""C:\main() {printf('%d', 42);}"""));
}

[Test]
public void SplitPathsQuotedExtraSemicolon()
{
CollectionAssert.AreEquivalent(
new String[] { @"D:\dev\LLVM\bin", @"C:\main() {printf('%d', 42);}" },
SplitPaths(@"D:\dev\LLVM\bin;""C:\main() {printf('%d', 42);}"";"));
}
}
#endif
}
}
39 changes: 39 additions & 0 deletions VisualRust.Project/Feature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VisualRust.Project
{
public static class Feature
{
public static bool Gdb(IServiceProvider provider)
{
return IsVs14OrHigher(provider) && IsGdbEngineInstalled(provider);
}

private static bool IsVs14OrHigher(IServiceProvider provider)
{
var dte = provider.GetService(typeof(SDTE)) as EnvDTE.DTE;
if(dte == null)
return false;
Version ver;
if (!Version.TryParse(dte.Version, out ver))
return false;
return ver.Major >= 14;
}

private static bool IsGdbEngineInstalled(IServiceProvider provider)
{
var debugger = provider.GetService(typeof(SVsShellDebugger)) as IVsDebugger2;
if(debugger == null)
return false;
Guid gdbEngine = Constants.GdbEngine;
string _;
return debugger.GetEngineName(ref gdbEngine, out _) == VSConstants.S_OK;
}
}
}
2 changes: 2 additions & 0 deletions VisualRust.Project/VisualRust.Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
<DependentUpon>Build.tt</DependentUpon>
</Compile>
<Compile Include="DefaultRustLauncher.cs" />
<Compile Include="EnvironmentPath.cs" />
<Compile Include="Feature.cs" />
<Compile Include="FolderNode.cs" />
<Compile Include="Forms\BuildPropertyControl.cs">
<SubType>UserControl</SubType>
Expand Down
97 changes: 97 additions & 0 deletions VisualRust/Forms/DebuggingDisabledControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions VisualRust/Forms/DebuggingDisabledControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VisualRust.Forms
{
public partial class DebuggingDisabledControl : UserControl
{
public DebuggingDisabledControl()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
VS SDK Notes: This resx file contains the resources that will be consumed directly by your package.
For example, if you chose to create a tool window, there is a resource with ID 'CanNotCreateWindow'. This
is used in VsPkg.cs to determine the string to show the user if there is an error when attempting to create
the tool window.

Resources that are accessed directly from your package *by Visual Studio* are stored in the VSPackage.resx
file.
-->
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -126,4 +117,14 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAACiSURBVDhPrVPBDYMwEMsIfXSQ
jpANGaEjMFU/fOgC1XG+3AkrTZAgWDIgx7Y4SJKIDLFcCJ9nyspZKRWhZbft4AI1vCnQ4+T2gijAAgxL
fhkpYKz0vQQFKuC1zfD7rkYu6ehlHC+wmcMIhLmlecHMBSH+BTphY7MA5BKgFXY+7i/gMO78XJfwCMMf
cew3Aipc30gBLETggO2tHFDD+cN0nZI2dKMrgybRTIQAAAAASUVORK5CYII=
</value>
</data>
</root>
24 changes: 17 additions & 7 deletions VisualRust/Forms/DebuggingOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using VisualRust.Forms;
using VisualRust.Project;

namespace VisualRust.Options
{
[ComVisible(true)]
[Guid("93F42A39-0AF6-40EE-AE2C-1C44AB5F8B15")]
public partial class DebuggingOptionsPage : DialogPage
{
public bool UseCustomGdbPath { get; set; }
public string DebuggerLocation { get; set; }
public string ExtraArgs { get; set; }

private DebuggingOptionsPageControl _page;
private IWin32Window page;

protected override IWin32Window Window
{
get
{
_page = new DebuggingOptionsPageControl();
_page.LoadSettings(this);
return _page;
if(page != null)
return page;
if(Feature.Gdb(this.Site))
page = new DebuggingOptionsPageControl(this);
else
page = new DebuggingDisabledControl();
return page;
}
}

protected override void OnClosed(EventArgs e)
{
_page.LoadSettings(this);
var debugControl = page as DebuggingOptionsPageControl;
if(debugControl != null)
debugControl.LoadSettings(this);
base.OnClosed(e);
}

protected override void OnApply(PageApplyEventArgs e)
{
if (e.ApplyBehavior == ApplyKind.Apply)
_page.ApplySettings(this);
var debugControl = page as DebuggingOptionsPageControl;
if (e.ApplyBehavior == ApplyKind.Apply && debugControl != null)
debugControl.ApplySettings(this);
base.OnApply(e);
}
}
Expand Down
Loading