[svn] r7241: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService: NemerleDropDownMember.cs NemerleSource...

IT svnadmin at nemerle.org
Wed Jan 10 23:20:43 CET 2007


Log:
Fixed some bugs related to navigation combobox. 

Author: IT
Date: Wed Jan 10 23:20:41 2007
New Revision: 7241

Modified:
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleDropDownMember.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleDropDownMember.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleDropDownMember.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleDropDownMember.cs	Wed Jan 10 23:20:41 2007
@@ -32,7 +32,7 @@
 				label += s + '.';
 
 			if (!string.IsNullOrEmpty(parentName))
-				label += parentName + '.';
+				label += parentName;
 
 			label += decl.Name;
 
@@ -76,9 +76,11 @@
 				Has(attrs, NemerleAttributes.Internal)?  GlyphSubtype.Internal:
 				Has(attrs, NemerleAttributes.Protected)? GlyphSubtype.Protected:
 				Has(attrs, NemerleAttributes.Public)?    GlyphSubtype.Public:
+				Has(attrs, NemerleAttributes.Private)?   GlyphSubtype.Private:
+				decl is TopDeclaration.VariantOption?    GlyphSubtype.Public:
 				                                         GlyphSubtype.Private;
 
-			return (int)kind | (int)modifier;
+			return (int)kind + (int)modifier;
 		}
 
 		public static DROPDOWNFONTATTR GetAttr(TopDeclaration decl)
@@ -98,7 +100,7 @@
 					_members = new List<DropDownMember>();
 
 					foreach (ClassMember m in AstUtils.GetMembers(_decl))
-						_members.Add(CreateMember(m));
+						_members.Add(CreateMember(_decl, m));
 
 					_members.Sort(delegate(DropDownMember m1, DropDownMember m2)
 					{
@@ -116,7 +118,7 @@
 			}
 		}
 
-		private static DropDownMember CreateMember(ClassMember member)
+		private static DropDownMember CreateMember(TopDeclaration decl, ClassMember member)
 		{
 			string           label    = AstUtils.GetMemberLabel(member);
 			DROPDOWNFONTATTR attr     = DROPDOWNFONTATTR.FONTATTR_PLAIN;
@@ -135,6 +137,7 @@
 				Has(attrs, NemerleAttributes.Internal)?  1:
 				Has(attrs, NemerleAttributes.Protected)? 3:
 				Has(attrs, NemerleAttributes.Public)?    0:
+				decl is TopDeclaration.VariantOption?    0:
 				                                         4;
 
 			return new DropDownMember(label, span, kind * 6 + modifier, attr);

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs	Wed Jan 10 23:20:41 2007
@@ -2,9 +2,12 @@
 using System.Collections;
 using System.Collections.Generic;
 
+using Microsoft.VisualStudio;
 using Microsoft.VisualStudio.Package;
 using Microsoft.VisualStudio.TextManager.Interop;
 
+using VsCommands2K = Microsoft.VisualStudio.VSConstants.VSStd2KCmdID;
+
 using Nemerle.Completion2;
 
 using Nemerle.VisualStudio.Project;
@@ -22,6 +25,7 @@
 		{
 			string path = GetFilePath();
 
+			_service     = service;
 			_projectInfo = ProjectInfo.FindProject(path);
 
 			if (_projectInfo != null)
@@ -51,6 +55,12 @@
 
 		#region Properties
 
+		private NemerleLanguageService _service;
+		public  NemerleLanguageService  Service
+		{
+			get { return _service; }
+		}
+
 		private NemerleScanner _scanner;
 		public  NemerleScanner  Scanner
 		{
@@ -179,6 +189,68 @@
 			//base.ReformatSpan(mgr, span);
 		}
 
+		MethodData _methodData;
+
+		public override MethodData CreateMethodData()
+		{
+			return _methodData = base.CreateMethodData();
+		}
+
+		public override void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
+		{
+			if (textView == null || _service == null || !_service.Preferences.EnableCodeSense)
+				return;
+
+			bool backward = (command == VsCommands2K.BACKSPACE || command == VsCommands2K.BACKTAB ||
+				command == VsCommands2K.LEFT || command == VsCommands2K.LEFT_EXT);
+
+			int line, idx;
+
+			textView.GetCaretPos(out line, out idx);
+
+			TokenInfo info = GetTokenInfo(line, idx);
+			TokenTriggers triggerClass = info.Trigger;
+
+			if ((triggerClass & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR))
+			{
+				ParseReason reason = ((triggerClass & TokenTriggers.MatchBraces) == TokenTriggers.MatchBraces) ? ParseReason.MemberSelectAndHighlightBraces : ParseReason.MemberSelect;
+				this.Completion(textView, info, reason);
+			}
+			else if ((triggerClass & TokenTriggers.MatchBraces) != 0 && _service.Preferences.EnableMatchBraces)
+			{
+				if ((command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || _service.Preferences.EnableMatchBracesAtCaret))
+				{
+					this.MatchBraces(textView, line, idx, info);
+				}
+			}
+			//displayed & a trigger found
+			// todo: This means the method tip disappears if you type "ENTER" 
+			// while entering method arguments, which is bad.
+			if ((triggerClass & TokenTriggers.MethodTip) != 0 && _methodData.IsDisplayed)
+			{
+				if ((triggerClass & TokenTriggers.MethodTip) == TokenTriggers.ParameterNext)
+				{
+					//this is an optimization
+					_methodData.AdjustCurrentParameter((backward && idx > 0) ? -1 : +1);
+				}
+				else
+				{
+					//this is the general case
+					this.MethodTip(textView, line, (backward && idx > 0) ? idx - 1 : idx, info);
+				}
+			}
+			else if ((triggerClass & TokenTriggers.MethodTip) != 0 && (command == VsCommands2K.TYPECHAR) && _service.Preferences.ParameterInformation)
+			{
+				//not displayed & trigger found & character typed & method info enabled
+				this.MethodTip(textView, line, idx, info);
+			}
+			else if (_methodData.IsDisplayed)
+			{
+				//displayed & complex command
+				this.MethodTip(textView, line, idx, info);
+			}
+		}
+
 		#endregion
 	}
 }

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs	Wed Jan 10 23:20:41 2007
@@ -1,7 +1,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
-using System.Diagnostics;
+
 using Microsoft.VisualStudio.Package;
 using Microsoft.VisualStudio.TextManager.Interop;
 
@@ -55,6 +55,7 @@
 #pragma warning restore 618
 
 				foreach (Tuple<string,TopDeclaration> decl in decls)
+					if (decl.field1.name.GetName().context != null)
 					list.Add(new NemerleDropDownMember(decl.field0, decl.field1));
 
 				list.Sort(delegate(NemerleDropDownMember m1, NemerleDropDownMember m2)
@@ -71,9 +72,9 @@
 				_lastSelectedType = -2;
 			}
 
-			selectedType = GetSelectedType(dropDownTypes, line, col);
+			int selType = GetSelectedType(dropDownTypes, line, col);
 
-			if (_lastSelectedType != selectedType)
+			if (_lastSelectedType != selType)
 			{
 				ret = true;
 
@@ -82,34 +83,46 @@
 					foreach (DropDownMember m in dropDownTypes)
 						m.FontAttr &= ~DROPDOWNFONTATTR.FONTATTR_GRAY;
 				}
-				else if (selectedType == -1)
+				else if (selType == -1)
 				{
 					foreach (DropDownMember m in dropDownTypes)
 						m.FontAttr |= DROPDOWNFONTATTR.FONTATTR_GRAY;
 				}
 
-				_lastSelectedType   = selectedType;
+				_lastSelectedType   = selType;
 				_lastSelectedMember = -2;
 
+				if (selType >= 0)
+				{
+					selectedType = selType;
+
+					if (dropDownMembers.Count > 0)
 				dropDownMembers.Clear();
 
-				if (selectedType >= 0)
 					dropDownMembers.AddRange(((NemerleDropDownMember)dropDownTypes[selectedType]).Members);
 			}
+				else if (selectedType < 0)
+				{
+					selectedType = 0;
 
-			if (selectedType < 0)
+					if (dropDownTypes.Count > 0)
 			{
-				selectedMember = -1;
-				return ret;
+						if (dropDownMembers.Count > 0)
+							dropDownMembers.Clear();
+
+						dropDownMembers.AddRange(((NemerleDropDownMember)dropDownTypes[selectedType]).Members);
+					}
+				}
 			}
 
-			Debug.Assert(dropDownTypes.Count != 0);
+			if (dropDownTypes.Count == 0)
+				return ret;
 
 			List<DropDownMember> members = ((NemerleDropDownMember)dropDownTypes[selectedType]).Members;
 
-			selectedMember= GetSelectedMember(members, line, col);
+			int selMember = selType < 0? -1: GetSelectedMember(members, line, col);
 
-			if (_lastSelectedMember != selectedMember)
+			if (_lastSelectedMember != selMember)
 			{
 				ret = true;
 
@@ -122,19 +135,24 @@
 					foreach (DropDownMember m in members)
 						m.FontAttr &= ~DROPDOWNFONTATTR.FONTATTR_GRAY;
 				}
-				else if (selectedMember == -1)
+				else if (selMember == -1)
 				{
 					foreach (DropDownMember m in members)
 						m.FontAttr |= DROPDOWNFONTATTR.FONTATTR_GRAY;
 				}
 
-				_lastSelectedMember = selectedMember;
+				_lastSelectedMember = selMember;
+
+				if (selMember >= 0)
+					selectedMember = selMember;
+				else if (selectedMember < 0)
+					selectedMember = 0;
 			}
 
 			return ret;
 		}
 
-		private static int GetSelectedMember(List<DropDownMember> members, int line, int col)
+		private int GetSelectedMember(List<DropDownMember> members, int line, int col)
 		{
 			int idx = -1;
 
@@ -149,7 +167,7 @@
 			return idx;
 		}
 
-		private static int GetSelectedType(ArrayList types, int line, int col)
+		static int GetSelectedType(ArrayList types, int line, int col)
 		{
 			int idx = -1;
 
@@ -164,7 +182,7 @@
 			return idx;
 		}
 
-		private static bool IsIn(TextSpan span, int line, int col)
+		static bool IsIn(TextSpan span, int line, int col)
 		{
 			return
 				(line > span.iStartLine || line == span.iStartLine && col >= span.iStartIndex) &&
@@ -172,3 +190,4 @@
 		}
 	}
 }
+



More information about the svn mailing list