[svn] r6823: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n Nemerle....

pbludov svnadmin at nemerle.org
Fri Nov 3 09:11:39 CET 2006


Log:
Changes in Goto

Author: pbludov
Date: Fri Nov  3 09:11:34 2006
New Revision: 6823

Added:
   vs-plugin/trunk/Nemerle.VsIntegration/GUI/AutoSizeListView.cs
   vs-plugin/trunk/Nemerle.VsIntegration/GUI/NativeMethods.cs
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.Designer.cs
   vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	Fri Nov  3 09:11:34 2006
@@ -189,6 +189,18 @@
     {
       def (_, _, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
 
+      def getMembers (ti : TypeInfo) {
+        def members = ti.GetMembers(BindingFlags.Static 
+          %| BindingFlags.Instance %| BindingFlags.Public 
+          %| BindingFlags.NonPublic %| BindingFlags.DeclaredOnly)
+          .Filter(fun(m) {
+             System.Attribute.GetCustomAttribute(m.GetHandle(),
+              typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)) == null;
+           });
+
+        List.Map(members, GotoInfo);
+      }
+
       match (tObj)
       {
       | me is TExpr.MacroEnvelope  => [(GotoInfo(me))]
@@ -198,13 +210,11 @@
         {
           | MType.Class(tycon is TypeBuilder, _) =>
             List.Map(tycon.PartsLocation, GotoInfo);
-          | MType.Class(tycon, _) =>
-            List.Map(tycon.GetMembers(BindingFlags.Static 
-              %| BindingFlags.Instance %| BindingFlags.Public 
-              %| BindingFlags.NonPublic %| BindingFlags.DeclaredOnly), GotoInfo);
+          | MType.Class(tycon, _) => getMembers(tycon);
           | _ => []
         }
       | tb is TypeBuilder          => List.Map(tb.PartsLocation, GotoInfo);
+      | ti is TypeInfo             => getMembers(ti);
       | fh is Typedtree.Fun_header => [(GotoInfo(fh))]
       | fb is FieldBuilder         => [(GotoInfo(fb))]
       | pb is PropertyBuilder      => [(GotoInfo(pb))]

Added: vs-plugin/trunk/Nemerle.VsIntegration/GUI/AutoSizeListView.cs
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.VsIntegration/GUI/AutoSizeListView.cs	Fri Nov  3 09:11:34 2006
@@ -0,0 +1,41 @@
+ďťżusing System;
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+
+namespace Nemerle.VisualStudio.GUI
+{
+	public class AutoSizeListView : ListView
+	{
+		public Rectangle HeaderRect
+		{
+			get
+			{
+				NativeMethods.RECT r = new NativeMethods.RECT();
+				Message            m = Message.Create(Handle,
+					NativeMethods.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
+
+				DefWndProc(ref m);
+				if (NativeMethods.GetWindowRect(new HandleRef(this, m.Result), ref r))
+					return r;
+
+				return Rectangle.Empty;
+			}
+		}
+
+		// This method is not imlemented by winforms for no good reason.
+		//
+		public override Size GetPreferredSize(Size _)
+		{	
+			int width = SystemInformation.VerticalScrollBarWidth + SystemInformation.Border3DSize.Width;
+			foreach (ColumnHeader hdr in Columns)
+				width += hdr.Width;
+			
+			int height = View == View.Details? HeaderRect.Height: 0;
+			if (Items.Count > 0)
+				height += Items.Count * GetItemRect(0).Height;
+
+			return new Size(width, height);
+		}
+	}
+}

Modified: vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.Designer.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.Designer.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.Designer.cs	Fri Nov  3 09:11:34 2006
@@ -28,7 +28,7 @@
     /// </summary>
     private void InitializeComponent()
     {
-      this._listView = new System.Windows.Forms.ListView();
+      this._listView = new AutoSizeListView();
       this.colFile = new System.Windows.Forms.ColumnHeader();
       this.colLine = new System.Windows.Forms.ColumnHeader();
       this.colPath = new System.Windows.Forms.ColumnHeader();
@@ -78,18 +78,14 @@
       this.KeyPreview = true;
       this.Name = "GoToTypeForm";
       this.ShowInTaskbar = false;
-      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
       this.Text = "Select file:";
-      this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.GoToTypeForm_KeyPress);
-      this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GoToTypeForm_FormClosing);
-      this.Load += new System.EventHandler(this.GoToTypeForm_Load);
       this.ResumeLayout(false);
 
     }
 
     #endregion
 
-    private System.Windows.Forms.ListView _listView;
+    private AutoSizeListView _listView;
     private System.Windows.Forms.ColumnHeader colFile;
     private System.Windows.Forms.ColumnHeader colLine;
     private System.Windows.Forms.ColumnHeader colPath;

Modified: vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/GUI/GoToTypeForm.cs	Fri Nov  3 09:11:34 2006
@@ -1,10 +1,7 @@
-// TODO: Âű÷čńëčňü őîň˙ áű HWND TextEditor'ŕ čëč őîň˙ áű ăëŕâíîăî îęíŕ ńňóäčč.
 using System;
 using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
 using System.Drawing;
-using System.Text;
+using System.Runtime.InteropServices;
 using System.Windows.Forms;
 using Nemerle.Completion2;
 using System.IO;
@@ -15,7 +12,7 @@
   {
     public GotoInfo Result;
 
-    public GoToTypeForm(GotoInfo[] gotoInfos)
+		public GoToTypeForm(IList<GotoInfo> gotoInfos)
     {
       InitializeComponent();
 
@@ -32,35 +29,32 @@
       }
     }
 
-    private void GoToTypeForm_Load(object sender, EventArgs e)
+		protected override void OnLoad(EventArgs e)
     {
-      // Resize columns by content.
-      foreach (ColumnHeader hdr in _listView.Columns)
-        hdr.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
+			base.OnLoad(e);
 
-      // Resize window.
+			// Adjust size
+			//
+			_listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
+			ClientSize = _listView.PreferredSize;
 
-      // Calc width
-      int width = SystemInformation.SmallIconSize.Width + 2;
-      foreach (ColumnHeader hdr in _listView.Columns)
-        width += hdr.Width;
-      ClientSize = new System.Drawing.Size(width, ClientSize.Height);
+			// Adjust position
+			//
+			Rectangle parentRect = Screen.FromControl(this).WorkingArea;
 
-      Left = (Screen.FromControl(this).WorkingArea.Width - Width) / 2;
+			Left = parentRect.Left + (parentRect.Width  - Width)  / 2;
+			Top  = parentRect.Top  + (parentRect.Height - Height) / 2;
 
-      // Calc height
+			// Select first item by default
+			//
       if (_listView.Items.Count > 0)
-      {
-        int height = _listView.Items.Count * _listView.GetItemRect(0).Height;
-        ClientSize = new Size(ClientSize.Width,
-          height + 30); //TODO: Try get header height.
-      }
-
-      Top = (Screen.FromControl(this).WorkingArea.Height - Height) / 2;
+				_listView.SelectedIndices.Add(0);
     }
 
-    private void GoToTypeForm_KeyPress(object sender, KeyPressEventArgs e)
+		protected override void OnKeyPress(KeyPressEventArgs e)
     {
+			base.OnKeyPress(e);
+
       if (e.KeyChar == (char)Keys.Escape)
         DialogResult = DialogResult.Cancel;
       else if (e.KeyChar == '\r' || e.KeyChar == ' ')
@@ -71,23 +65,25 @@
       Close();
     }
 
-    private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
+		protected override void OnFormClosing(FormClosingEventArgs e)
     {
-      DialogResult = DialogResult.OK;
-      Close();
-    }
+			base.OnClosing(e);
 
-    private void GoToTypeForm_FormClosing(object sender, FormClosingEventArgs e)
-    {
       if (DialogResult == DialogResult.OK)
         if (_listView.FocusedItem.Tag == null)
         {
           e.Cancel = true;
-          MessageBox.Show(this, "You must select item.", "Goto tyoe",
+					MessageBox.Show(this, "You must select item.", "Goto",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
           Result = (GotoInfo)_listView.FocusedItem.Tag;
     }
+
+		private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
+		{
+			DialogResult = DialogResult.OK;
+			Close();
+		}
   }
 }
\ No newline at end of file

Added: vs-plugin/trunk/Nemerle.VsIntegration/GUI/NativeMethods.cs
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.VsIntegration/GUI/NativeMethods.cs	Fri Nov  3 09:11:34 2006
@@ -0,0 +1,76 @@
+using System;
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace Nemerle.VisualStudio.GUI
+{
+	[SuppressUnmanagedCodeSecurity]
+	internal static class NativeMethods
+	{
+		public const int LVM_GETHEADER = 0x1000 + 0x1F;
+
+		#region RECT
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct RECT
+		{
+			public int left;
+			public int top;
+			public int right;
+			public int bottom;
+
+			public RECT(int left, int top, int right, int bottom)
+			{
+				this.left = left;
+				this.top = top;
+				this.right = right;
+				this.bottom = bottom;
+			}
+
+			public RECT(Rectangle r)
+			{
+				left = r.Left;
+				top = r.Top;
+				right = r.Right;
+				bottom = r.Bottom;
+			}
+
+			public static RECT FromXYWH(int x, int y, int width, int height)
+			{
+				return new RECT(x, y, x + width, y + height);
+			}
+
+			public int Width
+			{
+				get { return right - left; }
+			}
+
+			public int Height
+			{
+				get { return bottom - top; }
+			}
+
+			public Size Size
+			{
+				get { return new Size(Width, Height); }
+			}
+
+			public static implicit operator Rectangle(RECT r)
+			{
+				return new Rectangle(r.left, r.top, r.Width, r.Height);
+			}
+
+			public static implicit operator RECT(Rectangle r)
+			{
+				return new RECT(r.Left, r.Top, r.Right, r.Bottom);
+			}
+		}
+
+		#endregion
+
+		[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
+		public static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);
+	}
+}
+

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs	Fri Nov  3 09:11:34 2006
@@ -1,6 +1,5 @@
 using System;
-using System.Diagnostics;
-using System.IO;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Diagnostics.SymbolStore;
 using System.Windows.Forms;
@@ -103,6 +102,7 @@
 			int[]             columns    = null;
 			int[]             endLines   = null;
 			int[]             endColumns = null;
+			int[]             offsets    = null;
 
 			try
 			{
@@ -129,19 +129,27 @@
 							columns    = new int[1];
 							endLines   = new int[1];
 							endColumns = new int[1];
+							offsets    = new int[1];
 						}
 					}
 
+					try
+					{
 					SymbolToken    token  = new SymbolToken(gotoInfo.Member.MetadataToken);
 					ISymbolReader  reader = binder.GetReader(mdiPtr, gotoInfo.FilePath, null);
 					ISymbolMethod  method = reader.GetMethod(token);
 
 					if (method.SequencePointCount > 0)
 					{
-						method.GetSequencePoints(new int[1], documents, lines, columns, endLines, endColumns);
+							method.GetSequencePoints(offsets, documents, lines, columns, endLines, endColumns);
 						gotoInfo.SetLocation(documents[0].URL, lines[0], columns[0], endLines[0], endColumns[0]);
 					}
 				}
+					catch (COMException)
+					{
+						// Abstract method or something. Eat exception and continue.
+					}
+				}
 			}
 			catch (COMException)
 			{
@@ -167,18 +175,32 @@
 			}
 			else
 			{
-        GotoInfo[] gotoInfos = Array.FindAll(info, delegate(GotoInfo inf)
-          { return inf.HasLocation; });
+				List<GotoInfo> gotoInfos = new List<GotoInfo>(info.Length);
+
+				// Remove duplicates and members which location still is not known.
+				//
+				for (int i = 0; i < info.Length; ++i)
+				{
+					if (info[i].HasLocation && gotoInfos.FindIndex(
+							delegate (GotoInfo item)
+							{
+								return item.FilePath == info[i].FilePath
+									&& item.LineStart == info[i].LineStart;
+							}) < 0)
+						gotoInfos.Add(info[i]);
+				}
 
-        if (gotoInfos.Length <= 0)
+				if (gotoInfos.Count <= 0)
           return null;
-        else if (gotoInfos.Length == 1)
+				else if (gotoInfos.Count == 1)
           return SetTextSpan(ref span, gotoInfos[0]);
         else
         {
-          GoToTypeForm popup = new GoToTypeForm(gotoInfos);
+					NativeWindow textEditorWnd = 
+						NativeWindow.FromHandle(textView.GetWindowHandle());
 
-          if (popup.ShowDialog() == DialogResult.OK)
+					using (GoToTypeForm popup = new GoToTypeForm(gotoInfos))
+						if (popup.ShowDialog(textEditorWnd) == DialogResult.OK)
             return SetTextSpan(ref span, popup.Result);
         }
 			}

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj	Fri Nov  3 09:11:34 2006
@@ -122,12 +122,16 @@
     <Compile Include="$(VisualStudioIntegration)\Common\Source\CSharp\RegistrationAttributes\WebSiteProjectRelatedFilesAttribute.cs">
       <Link>RegistrationAttributes\WebSiteProjectRelatedFilesAttribute.cs</Link>
     </Compile>
+    <Compile Include="GUI\AutoSizeListView.cs">
+      <SubType>Component</SubType>
+    </Compile>
     <Compile Include="GUI\GoToTypeForm.cs">
       <SubType>Form</SubType>
     </Compile>
     <Compile Include="GUI\GoToTypeForm.Designer.cs">
       <DependentUpon>GoToTypeForm.cs</DependentUpon>
     </Compile>
+    <Compile Include="GUI\NativeMethods.cs" />
     <Compile Include="LanguageService\NemerleAuthoringScope.cs" />
     <Compile Include="LanguageService\NemerleAuthoringSink.cs" />
     <Compile Include="LanguageService\NemerleColorableItem.cs" />



More information about the svn mailing list