Permalink
Browse files

Improved formatting for code completion tooltips

  • Loading branch information...
1 parent f8b9478 commit 4da559c53e91925a49e1e8ff69be0ea789108682 @jgranick committed Jul 19, 2012
View
8 HaxeBinding/HaxeBinding.addin.xml
@@ -5,15 +5,15 @@
copyright = "MIT X11"
description = "Haxe Language Binding"
category = "Language bindings"
- version = "0.3.1" >
+ version = "0.3.2" >
<!-- Dependencies -->
<Dependencies>
- <Addin id="Core" version="3.0" />
- <Addin id="Ide" version="3.0" />
- <Addin id="SourceEditor2" version="3.0" />
+ <Addin id="::MonoDevelop.Core" version="3.0" />
+ <Addin id="::MonoDevelop.Ide" version="3.0" />
+ <Addin id="::MonoDevelop.SourceEditor2" version="3.0" />
</Dependencies>
View
27 HaxeBinding/HaxeBinding.csproj
@@ -33,36 +33,27 @@
<Reference Include="System" />
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
<Private>False</Private>
- <Package>gtk-sharp-2.0</Package>
- </Reference>
- <Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
- <Package>gtk-sharp-2.0</Package>
- </Reference>
- <Reference Include="MonoDevelop.Core, Version=2.6.0.0, Culture=neutral">
- <Private>False</Private>
- <Package>monodevelop</Package>
- </Reference>
- <Reference Include="MonoDevelop.Ide, Version=2.6.0.0, Culture=neutral">
- <Private>False</Private>
- <Package>monodevelop</Package>
</Reference>
+ <Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="System.Xml" />
<Reference Include="Mono.TextEditor, Version=1.0.0.0, Culture=neutral">
<Private>False</Private>
- <Package>monodevelop</Package>
</Reference>
<Reference Include="MonoDevelop.DesignerSupport, Version=2.6.0.0, Culture=neutral">
<Private>False</Private>
- <Package>monodevelop-core-addins</Package>
</Reference>
<Reference Include="MonoDevelop.Refactoring, Version=2.6.0.0, Culture=neutral">
<Private>False</Private>
- <Package>monodevelop-core-addins</Package>
</Reference>
<Reference Include="Mono.Posix" />
- <Reference Include="ICSharpCode.NRefactory, Version=0.0.0.0, Culture=neutral, PublicKeyToken=efe927acf176eea2">
- <Private>False</Private>
- <Package>monodevelop</Package>
+ <Reference Include="MonoDevelop.Core">
+ <HintPath>..\..\..\..\..\..\Applications\MonoDevelop.app\Contents\MacOS\lib\monodevelop\bin\MonoDevelop.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="MonoDevelop.Ide">
+ <HintPath>..\..\..\..\..\..\Applications\MonoDevelop.app\Contents\MacOS\lib\monodevelop\bin\MonoDevelop.Ide.dll</HintPath>
+ </Reference>
+ <Reference Include="ICSharpCode.NRefactory">
+ <HintPath>..\..\..\..\..\..\Applications\MonoDevelop.app\Contents\MacOS\lib\monodevelop\bin\ICSharpCode.NRefactory.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
View
47 HaxeBinding/Languages/Gui/HaxeParameterDataProvider.cs
@@ -137,6 +137,47 @@ public void Update (CodeCompletionContext completionContext, XmlDocument data)
return offset;
}
}
+
+
+ private string FormatShortType (string type)
+ {
+ string[] keywords = type.Split (' ');
+ type = "";
+
+ for (int i = 0; i < keywords.Length; i++) {
+
+ if (keywords[i].IndexOf (".") > -1) {
+
+ string[] segments = keywords[i].Split ('.');
+
+ if (keywords[0].IndexOf ("<") > -1) {
+
+ type += keywords[0].Substring (0, keywords[0].IndexOf ("<") + 1);
+
+ } else if (keywords[0].StartsWith (":")) {
+
+ type += ":";
+
+ }
+
+ type += segments[segments.Length - 1];
+
+ } else {
+
+ type += keywords[i];
+
+ }
+
+ if (i < keywords.Length - 1) {
+
+ type += " ";
+
+ }
+
+ }
+
+ return type;
+ }
public string GetHeading (int overload, string[] parameterDescription, int currentParameter)
@@ -171,11 +212,11 @@ public string GetHeading (int overload, string[] parameterDescription, int curre
{
if (i == currentParameter)
{
- display += "<span foreground=\"#a0a0f7\"><b>" + param.Substring (0, index) + "</b>" + param.Substring (index) + "</span>";
+ display += "<span foreground=\"#a0a0f7\"><b>" + param.Substring (0, index) + "</b>" + FormatShortType (param.Substring (index)) + "</span>";
}
else
{
- display += "<b>" + param.Substring (0, index) + "</b>" + param.Substring (index);
+ display += "<b>" + param.Substring (0, index) + "</b>" + FormatShortType (param.Substring (index));
}
if (i < parameters.Length - 2)
@@ -185,7 +226,7 @@ public string GetHeading (int overload, string[] parameterDescription, int curre
}
}
- display += "):" + parameters [parameters.Length - 1];
+ display += ") : " + FormatShortType (parameters [parameters.Length - 1]) + " ...";
return display;
}
View
157 HaxeBinding/Languages/Gui/HaxeTextEditorCompletion.cs
@@ -95,7 +95,9 @@ private void FetchCompletionData (CodeCompletionContext completionContext)
File.WriteAllText (mTempFileName, Document.Editor.Text);
string data = HaxeCompilerManager.GetCompletionData (Document.Project, mTempBaseDirectory, mTempFileName, mCacheTriggerOffset);
-
+
+ //MonoDevelop.Ide.MessageService.ShowMessage (data);
+
try
{
var xml = new XmlDocument ();
@@ -141,6 +143,129 @@ private void FetchCompletionData (CodeCompletionContext completionContext)
}
}
}
+
+
+ private string FormatDocumentation (string documentation)
+ {
+ string[] lines = documentation.Split ('\n');
+
+ documentation = "";
+ bool newline = true;
+
+ for (int i = 0; i < lines.Length; i++) {
+
+ string line = "\n" + lines[i].Trim ();
+ line = line.Replace ("\n* ", " ");
+ line = line.Replace ("\n*", " ");
+ line = line.Replace ("<p>", "");
+ line = line.Replace ("</p>", "");
+ line = line.Replace ("<code>", "");
+ line = line.Replace ("</code>", "");
+ line = line.Replace ("<b>", "");
+ line = line.Replace ("</b>", "");
+
+ if (newline) {
+
+ line = line.TrimStart ();
+ newline = false;
+
+ }
+
+ if (line.Trim () == "") {
+
+ line = "\n\n";
+ newline = true;
+
+ }
+
+ if (line.IndexOf ("@param") > -1 || line.IndexOf ("@throws") > -1 || line.IndexOf ("@return") > -1) {
+
+ break;
+
+ }
+
+ documentation += line;
+
+ }
+
+ return "\n" + documentation;
+ }
+
+
+ private string FormatShortType (string type)
+ {
+ string[] keywords = type.Split (' ');
+ type = "";
+
+ for (int i = 0; i < keywords.Length; i++) {
+
+ if (keywords[i].IndexOf (".") > -1) {
+
+ string[] segments = keywords[i].Split ('.');
+
+ if (keywords[0].IndexOf ("<") > -1) {
+
+ type += keywords[0].Substring (0, keywords[0].IndexOf ("<") + 1);
+
+ }
+
+ type += segments[segments.Length - 1];
+
+ } else {
+
+ type += keywords[i];
+
+ }
+
+ if (i < keywords.Length - 1) {
+
+ type += " ";
+
+ }
+
+ }
+
+ return type;
+ }
+
+
+ private string FormatType (string name, string type)
+ {
+ if (type.IndexOf (":") > -1) {
+
+ type = type.Replace (" ", "");
+
+ string[] parameters = type.Split (new string[] { "->" }, StringSplitOptions.None);
+
+ string display = "function " + name + " (";
+
+ for (int i = 0; i < parameters.Length - 1; i++) {
+ string param = parameters [i];
+ int index = param.IndexOf (":");
+
+ if (index > -1) {
+ display += param.Substring (0, index + 1) + FormatShortType (param.Substring (index + 1));
+
+ if (i < parameters.Length - 2) {
+ display += ", ";
+ }
+ }
+ }
+
+ display += ") : " + FormatShortType (parameters [parameters.Length - 1]) + " ...";
+
+ type = display;
+
+ } else {
+
+ type = "var " + name + " : " + FormatShortType (type) + " ...";
+
+ }
+
+ //type = type.Replace (" : ", ":");
+
+ return type;
+ }
private CompletionDataList GetCompletionList (CodeCompletionContext completionContext)
@@ -156,6 +281,8 @@ private CompletionDataList GetCompletionList (CodeCompletionContext completionCo
if (xml.HasChildNodes && xml.FirstChild.HasChildNodes)
{
+ string documentation;
+ string[] lines;
string name;
string type;
string icon;
@@ -167,18 +294,38 @@ private CompletionDataList GetCompletionList (CodeCompletionContext completionCo
foreach (XmlElement node in xml.FirstChild.ChildNodes)
{
name = node.GetAttribute ("n");
- type = node.InnerText;
icon = "md-property";
+
+ lines = node.InnerText.Replace("\r","").Split('\n');
+
+ type = "";
+ documentation = "";
+
+ for (var i = 0; i < lines.Length; i++) {
+
+ if (i == 0) {
+
+ type = lines[0];
+
+ } else {
+
+ documentation += "\n" + lines[i];
+
+ }
+
+ }
+
+ //MonoDevelop.Ide.MessageService.ShowMessage (documentation);
- if (type.IndexOf ("->") > -1)
+ if (type.IndexOf (":") > -1)
{
icon = "md-method";
//md-literal
}
- if (type.IndexOf ("@private") == -1)
+ if (documentation.IndexOf ("@private") == -1)
{
- list.Add (new CompletionData (name, icon, type));
+ list.Add (new CompletionData (name, icon, FormatType (name, type) + FormatDocumentation (documentation)));
}
}
View
2 HaxeBinding/Projects/NMEProject.cs
@@ -42,7 +42,7 @@ public class NMEProject : Project
public NMEProject () : base()
{
-
+
}
View
2 HaxeBinding/Tools/HaxeCompilerManager.cs
@@ -54,7 +54,7 @@ public static BuildResult Compile (HaxeProject project, HaxeProjectConfiguration
{
hxmlPath = Path.Combine (project.BaseDirectory, project.TargetHXMLFile);
}
-
+
string hxml = File.ReadAllText (hxmlPath);
hxml = hxml.Replace (Environment.NewLine, " ");
string[] hxmlArgs = hxml.Split (' ');
View
BIN HaxeBinding/bin/Debug/MonoDevelop.HaxeBinding.dll
Binary file not shown.
View
BIN HaxeBinding/bin/Debug/MonoDevelop.HaxeBinding.dll.mdb
Binary file not shown.
View
6 HaxeBinding/gtk-gui/MonoDevelop.HaxeBinding.Projects.Gui.HaxeProjectOptionsWidget.cs
@@ -68,11 +68,7 @@ protected virtual void Build ()
w3.Spacing = 2;
// Container child GtkHBox.Gtk.Container+ContainerChild
global::Gtk.Image w4 = new global::Gtk.Image ();
- w4.Pixbuf = global::Stetic.IconLoader.LoadIcon (
- this,
- "gtk-file",
- global::Gtk.IconSize.Menu
- );
+ w4.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-file", global::Gtk.IconSize.Menu);
w3.Add (w4);
// Container child GtkHBox.Gtk.Container+ContainerChild
global::Gtk.Label w6 = new global::Gtk.Label ();
View
6 HaxeBinding/gtk-gui/MonoDevelop.HaxeBinding.Projects.Gui.NMEProjectOptionsWidget.cs
@@ -68,11 +68,7 @@ protected virtual void Build ()
w3.Spacing = 2;
// Container child GtkHBox.Gtk.Container+ContainerChild
global::Gtk.Image w4 = new global::Gtk.Image ();
- w4.Pixbuf = global::Stetic.IconLoader.LoadIcon (
- this,
- "gtk-file",
- global::Gtk.IconSize.Menu
- );
+ w4.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-file", global::Gtk.IconSize.Menu);
w3.Add (w4);
// Container child GtkHBox.Gtk.Container+ContainerChild
global::Gtk.Label w6 = new global::Gtk.Label ();
View
23 HaxeBinding/gtk-gui/generated.cs
@@ -89,27 +89,10 @@ public static Gdk.Pixbuf LoadIcon (Gtk.Widget widget, string name, Gtk.IconSize
pmap.DrawRectangle (gc, true, 0, 0, sz, sz);
gc.RgbFgColor = new Gdk.Color (0, 0, 0);
pmap.DrawRectangle (gc, false, 0, 0, (sz - 1), (sz - 1));
- gc.SetLineAttributes (
- 3,
- Gdk.LineStyle.Solid,
- Gdk.CapStyle.Round,
- Gdk.JoinStyle.Round
- );
+ gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
gc.RgbFgColor = new Gdk.Color (255, 0, 0);
- pmap.DrawLine (
- gc,
- (sz / 4),
- (sz / 4),
- ((sz - 1) - (sz / 4)),
- ((sz - 1) - (sz / 4))
- );
- pmap.DrawLine (
- gc,
- ((sz - 1) - (sz / 4)),
- (sz / 4),
- (sz / 4),
- ((sz - 1) - (sz / 4))
- );
+ pmap.DrawLine (gc, (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)), ((sz - 1) - (sz / 4)));
+ pmap.DrawLine (gc, ((sz - 1) - (sz / 4)), (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)));
return Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz);
}
}
View
7 HaxeBinding/gtk-gui/gui.stetic
@@ -5,11 +5,8 @@
<target-gtk-version>2.12</target-gtk-version>
</configuration>
<import>
- <widget-library name="MonoDevelop.Ide, Version=2.6.0.0, Culture=neutral" />
- <widget-library name="Mono.TextEditor, Version=1.0.0.0, Culture=neutral" />
- <widget-library name="MonoDevelop.DesignerSupport, Version=2.6.0.0, Culture=neutral" />
- <widget-library name="MonoDevelop.Refactoring, Version=2.6.0.0, Culture=neutral" />
- <widget-library name="../bin/Debug/MonoDevelop.HaxeBinding.dll" internal="true" />
+ <widget-library name="../../../../../../../Applications/MonoDevelop.app/Contents/MacOS/lib/monodevelop/bin/MonoDevelop.Ide.dll" />
+ <widget-library name="../bin/Release/MonoDevelop.HaxeBinding.dll" internal="true" />
</import>
<widget class="Gtk.Bin" id="MonoDevelop.HaxeBinding.Projects.Gui.NMEOutputOptionsWidget" design-size="467 300">
<property name="MemberName" />

0 comments on commit 4da559c

Please sign in to comment.