[svn] r7001: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n Nemerle.Compi...

IT svnadmin at nemerle.org
Sun Nov 26 04:01:03 CET 2006


Log:
User type colorizing.

Author: IT
Date: Sun Nov 26 04:00:58 2006
New Revision: 7001

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/XmlDocReader.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n	Sun Nov 26 04:00:58 2006
@@ -357,7 +357,7 @@
       }
     }
 
-    ProcessDecls(decls : list[Decl]) : void
+    ProcessRegions(decls : list[Decl]) : void
     {
       //TODO: Ðåãèîíû ïîêà íå ðåëîêåéòÿòñÿ. Òàê ÷òî ïðè çìåíåíèè èñõîäíèêîâ îíè äîëæíû âðàòü.
       def regions = _project.CompileUnits.GetRegions(_fileIndex);
@@ -390,7 +390,7 @@
 
       | Namespace(decls, _, locations, _, _, nsloc) => 
 
-        ProcessDecls(decls);
+        ProcessRegions(decls);
 
         match (locations.Find(l => l.FileIndex == _fileIndex))
         {
@@ -467,7 +467,7 @@
         when (!_addError(cm))
           break;
 
-      ProcessDecls(_project.CompileUnits[_fileIndex].Decls);
+      ProcessRegions(_project.CompileUnits[_fileIndex].Decls);
     }
 
     _debug(obj : object) : void

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n	Sun Nov 26 04:00:58 2006
@@ -109,53 +109,96 @@
       find_decl(_compileUnits[fileIndex])
     }
 
-    public GetActiveEnv(fileIndex : int, line : int) : GlobalEnv * int * int
+    public GetActiveEnv(fileIndex : int, line : int) : GlobalEnv * TypeBuilder * int * int
     {
       mutable env;
+      mutable typeBuilder;
       mutable start = 0;
       mutable end   = int.MaxValue;
 
-      def loop(decl : Decl)
+      def check(loc, doFind)
       {
-      | Namespace as ns => 
-
-        if (line >= ns.Location.Line)
+        if (line >= loc.Line)
         {
-          if (line <= ns.Location.EndLine)
+          if (line <= loc.EndLine)
           {
-            start = ns.Location.Line;
-            end   = ns.Location.EndLine;
-            env   = ns.InsideEnv;
+            start = loc.Line;
+            end   = loc.EndLine;
 
-            foreach (d in ns.Decls)
-              loop(d);
+            doFind();
+
+            true;
           }
           else
           {
-            start = ns.Location.EndLine + 1;
+            start = loc.EndLine + 1;
+            false;
           }
         }
         else
         {
-          end = ns.Location.Line - 1;
+          end = loc.Line - 1;
+          false;
+        }
+      }
+
+      def loop(decl : Decl)
+      {
+      | Namespace as ns => 
+
+        check(ns.Location, () =>
+        {
+          env = ns.InsideEnv;
+
+          foreach (d in ns.Decls)
+            when (loop(d))
+              break;
+        });
+
+      | Type(builder) => 
+
+        def checkBuilder(builder)
+        {
+          _debug(builder);
+          mutable found = false;
+
+          foreach (loc
+            when !found && loc.FileIndex == fileIndex && builder.Location.Line < builder.Location.EndLine
+            in builder.PartsLocation)
+          {
+            found = check(loc, () =>
+            {
+              typeBuilder = builder;
+
+              foreach (b in builder.DeclaredNestedTypes)
+                when (checkBuilder(b))
+                  break;
+            });
         }
 
+          found
+        }
+
+        checkBuilder(builder);
+
       | Using as us =>
 
-        when (line >= us.NameLocations.Head.Line)
+        when (us.NameLocations.Length > 0 && line >= us.NameLocations.Head.Line)
         {
           start = us.Location.Line;
           env   = us.AfterEnv;
         }
 
-      | _ => ()
+        false;
+
+      | _ => false
       }
 
       def decl = _compileUnits[fileIndex];
 
-      loop(decl);
+      _ = loop(decl);
 
-      (env, start, end)
+      (env, typeBuilder, start, end)
     }
 
     /// Finds the innermost top level construction (namespace, class,
@@ -313,5 +356,11 @@
       | _          => null
       }
     }
+
+    _debug(obj : object) : void
+    {
+      when (obj != null)
+        _ = obj.ToString();
+    }
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n	Sun Nov 26 04:00:58 2006
@@ -19,7 +19,13 @@
       Keywords = manager.CoreEnv.Keywords;
     }
 
-    public SetLine(line : string, offset : int, env : GlobalEnv) : void
+    public SetLine(
+      line        : string,
+      offset      : int,
+      env         : GlobalEnv,
+      typeBuilder : TypeBuilder
+    )
+      : void
     {
       base.reader          = line;
       base.pos             = offset;
@@ -30,6 +36,8 @@
       base.eating_stack    = Stack();
       base.eating_now      = 0;
 
+      _env             = if (env != null) env else Manager.CoreEnv;
+      _typeBuilder     = typeBuilder;
       _onPreprocessor  = false;
       _tokenInfo.Token = null;
       _bracketCount    = -1;
@@ -37,15 +45,21 @@
 
       _tokenInfo.IsEndOfLine = eol();
 
-      Keywords = (if (env != null) env else Manager.CoreEnv).Keywords;
+      when (_identifiers.Length != 0)
+        _identifiers = [];
+
+      Keywords = _env.Keywords;
     }
 
+    mutable _env            : GlobalEnv;
+    mutable _typeBuilder    : TypeBuilder;
     mutable _last_line      : int;
     mutable _last_col       : int;
     mutable _onPreprocessor : bool;
     mutable _keepDollar     : bool;
     mutable _bracketCount   : int;
     mutable _quotationCount : int;
+    mutable _identifiers    : list[string] = [];
 
     _tokenInfo : ScanTokenInfo = ScanTokenInfo();
 
@@ -380,6 +394,50 @@
       Token.Keyword(CurrentValue);
     }
 
+    GetIdentifierColor(name : string) : ScanTokenColor
+    {
+      def getColor()
+      {
+        def lookup()
+        {
+          def ids = if (_identifiers.Length > 1) _identifiers.Rev() else _identifiers;
+
+          match (_env.LookupType(ids, _typeBuilder, -1))
+          {
+          | Some(ti) =>
+
+            if      (ti.IsEnum)      C.UserTypeEnum
+            else if (ti.IsDelegate)  C.UserTypeDelegate
+            else if (ti.IsValueType) C.UserTypeValueType
+            else                     C.UserType
+
+          | None => C.Identifier
+          }
+        }
+
+        if (_typeBuilder != null && _typeBuilder.IsEnum && _last_col > 1)
+        {
+          def line = reader.Substring(0, _last_col - 1).TrimEnd(' ', '\t');
+
+          _debug(line);
+
+          if (line.Length > 0 && line[line.Length-1] == '|')
+            C.Identifier
+          else
+            lookup();
+        }
+        else
+          lookup();
+      }
+
+      match (_tokenInfo.Token)
+      {
+      | Operator(".") when _identifiers.Length == 0 => C.Identifier
+      | Operator(".") => _identifiers ::= name;     getColor();
+      | _             => _identifiers = name :: []; getColor();
+      }
+    }
+
     _Debug[T](o : T) : void
     {
       _ = o.ToString();
@@ -410,7 +468,7 @@
             (TP.Keyword,    C.Keyword,    TR.None)
           }
           else
-            (TP.Identifier, C.Identifier, TR.None)
+            (TP.Identifier, GetIdentifierColor(name), TR.None)
 
         | IdentifierToComplete      => (TP.Identifier, C.Identifier, TR.None)
         | Comma                     => (TP.Operator,   C.Operator,   TR.ParameterNext)
@@ -427,9 +485,18 @@
 
           match (nm)
           {
+          | "."                              => 
+
+            match (_tokenInfo.Token)
+            {
+            | Identifier => ()
+            | _          => when (_identifiers.Length > 0) _identifiers = [];
+            }
+
+            (TP.Delimiter, C.Operator, TR.MemberSelect)
+
           | ".." when _tokenInfo.IsQuotation
           | "$"  when _tokenInfo.IsQuotation => (TP.Operator,  C.Keyword,  TR.None)
-          | "."                              => (TP.Delimiter, C.Operator, TR.MemberSelect)
           | _                                => (TP.Operator,  C.Operator, TR.None)
           }
 
@@ -668,6 +735,11 @@
         | StringEx         => ScanTokenColor.QuotationStringEx
         | VerbatimString   => ScanTokenColor.QuotationVerbatimString
         | VerbatimStringEx => ScanTokenColor.QuotationVerbatimStringEx
+        | QuotationUserType          => ScanTokenColor.QuotationUserType
+        | QuotationUserTypeDelegate  => ScanTokenColor.QuotationUserTypeDelegate
+        | QuotationUserTypeEnum      => ScanTokenColor.QuotationUserTypeEnum
+        | QuotationUserTypeInterface => ScanTokenColor.QuotationUserTypeInterface
+        | QuotationUserTypeValueType => ScanTokenColor.QuotationUserTypeValueType
         | _                => _tokenInfo.Color
         }
       }
@@ -675,5 +747,11 @@
       _tokenInfo.Token.Location = Location(file_idx, _last_line, _last_col, line, col);
       _tokenInfo
     }
+
+    _debug(obj : object) : void
+    {
+      when (obj != null)
+        _ = obj.ToString();
+    }
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n	Sun Nov 26 04:00:58 2006
@@ -18,6 +18,12 @@
   | VerbatimString
   | VerbatimStringEx
 
+  | UserType
+  | UserTypeDelegate
+  | UserTypeEnum
+  | UserTypeInterface
+  | UserTypeValueType
+
   | Quotation
   | QuotationText
   | QuotationKeyword
@@ -30,5 +36,10 @@
   | QuotationVerbatimString
   | QuotationVerbatimStringEx
 
+  | QuotationUserType
+  | QuotationUserTypeDelegate
+  | QuotationUserTypeEnum
+  | QuotationUserTypeInterface
+  | QuotationUserTypeValueType
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/XmlDocReader.n
==============================================================================

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	Sun Nov 26 04:00:58 2006
@@ -10,6 +10,7 @@
 
 using Microsoft.VisualStudio;
 using Microsoft.VisualStudio.Package;
+using Microsoft.VisualStudio.Shell.Interop;
 using Microsoft.VisualStudio.TextManager.Interop;
 
 using Nemerle.Completion2;
@@ -112,6 +113,37 @@
 			int                      col,
 			out TextSpan             span)
 		{
+
+
+			IVsUIShell shell = _project.ProjectNode.Package.GetService<IVsUIShell, SVsUIShell>();
+
+			Guid           guid = new Guid(ToolWindowGuids.ObjectSearchResultsWindow);
+			IVsWindowFrame frame;
+
+			shell.FindToolWindow(
+				(uint)__VSFINDTOOLWIN.FTW_fForceCreate,
+				ref guid,
+				out frame);
+
+			if (frame != null)
+			{
+				guid = typeof(IVsLiteTreeList).GUID;
+				IntPtr ptr;
+
+				frame.QueryViewInterface(ref guid, out ptr);
+
+				IVsLiteTreeList obj = frame as IVsLiteTreeList;
+
+				if (obj != null)
+				{
+				}
+
+				frame.Show();
+			}
+
+
+
+
 			span = new TextSpan();
 
 			GotoInfo[] info;
@@ -155,6 +187,7 @@
 				return SetTextSpan(ref span, info[0]);
 			else if (info.Length > 0)
 			{
+
 				NativeWindow textEditorWnd = 
 					NativeWindow.FromHandle(textView.GetWindowHandle());
 
@@ -232,7 +265,7 @@
 				return null;
 
 			object            unkMetaDataImport;
-			IntPtr            ptrMetaDataImport;
+			IntPtr            ptrMetaDataImport = IntPtr.Zero;
 			ISymbolBinder1    binder;
 			ISymbolReader     reader;
 			ISymbolDocument[] documents;
@@ -241,11 +274,13 @@
 			int[]             endLines;
 			int[]             endColumns;
 			int[]             offsets;
-			int               hr;
 			List<GotoInfo>    infos      = new List<GotoInfo>();
 			List<MethodBase>  methods    = new List<MethodBase>();
 
-			hr = _project.SmartOpenScope.OpenScope(info.FilePath, 0, ref IID_MetaDataImport, out unkMetaDataImport);
+			try
+			{
+				int hr = _project.SmartOpenScope.OpenScope(info.FilePath, 0, ref IID_MetaDataImport, out unkMetaDataImport);
+
 			if (hr == VSConstants.S_OK)
 			{
 				ptrMetaDataImport = Marshal.GetIUnknownForObject(unkMetaDataImport);
@@ -265,8 +300,6 @@
 				return null;
 			}
 
-			try
-			{
 				switch (info.Member.MemberType)
 				{
 					case MemberTypes.Constructor:
@@ -347,7 +380,7 @@
 			}
 			finally
 			{
-				if (IntPtr.Zero != ptrMetaDataImport)
+				if (ptrMetaDataImport != IntPtr.Zero)
 					Marshal.Release(ptrMetaDataImport);
 			}
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs	Sun Nov 26 04:00:58 2006
@@ -80,7 +80,7 @@
 		// this language.
 		private static NemerleColorableItem[] _colorableItems = 
 		{
-			// The first 6 items in this list MUST be these default items.
+			// The sequential order of these items should be consistent with the ScanTokenColor enum.
 			//
 			new NemerleColorableItem("Keyword",                  COLORINDEX.CI_BLUE),
 			new NemerleColorableItem("Comment",                  COLORINDEX.CI_DARKGREEN),
@@ -95,6 +95,12 @@
 			new NemerleColorableItem("String (@ Verbatim)",   2, COLORINDEX.CI_MAROON, Color.FromArgb(170,  0,   0)),
 			new NemerleColorableItem("StringEx (@ Verbatim)", 2, COLORINDEX.CI_MAROON, Color.FromArgb(143, 44, 182)),
 
+			new NemerleColorableItem("User Types",               COLORINDEX.CI_CYAN,   Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("User Types (Delegates)",   COLORINDEX.CI_CYAN,   Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("User Types (Enums)",       COLORINDEX.CI_CYAN,   Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("User Types (Interfaces)",  COLORINDEX.CI_CYAN,   Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("User Types (Value types)", COLORINDEX.CI_CYAN,   Color.FromArgb(43, 145, 175)),
+
 			new NemerleColorableItem("Quotation",             0, COLORINDEX.CI_BROWN),
 
 			new NemerleColorableItem("<[ Text ]>",            0),
@@ -107,6 +113,12 @@
 			new NemerleColorableItem("<[ StringEx ]>",        0, COLORINDEX.CI_MAROON, Color.FromArgb(143, 44, 182)),
 			new NemerleColorableItem("<[ String (@) ]>",      1, COLORINDEX.CI_MAROON, Color.FromArgb(170,  0,   0)),
 			new NemerleColorableItem("<[ StringEx (@) ]>",    1, COLORINDEX.CI_MAROON, Color.FromArgb(143, 44, 182)),
+
+			new NemerleColorableItem("<[ User Types ]>",               0, COLORINDEX.CI_CYAN, Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("<[ User Types (Delegates) ]>",   0, COLORINDEX.CI_CYAN, Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("<[ User Types (Enums) ]>",       0, COLORINDEX.CI_CYAN, Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("<[ User Types (Interfaces) ]>",  0, COLORINDEX.CI_CYAN, Color.FromArgb(43, 145, 175)),
+			new NemerleColorableItem("<[ User Types (Value types) ]>", 0, COLORINDEX.CI_CYAN, Color.FromArgb(43, 145, 175)),
 		};
 
 		public override void Dispose()

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs	Sun Nov 26 04:00:58 2006
@@ -81,6 +81,7 @@
 
 		Nemerle.Completion2.Project _prevProject;
 		GlobalEnv                   _env;
+		TypeBuilder                 _type;
 		int                         _envStartLine;
 		int                         _envEndLine = -1;
 
@@ -110,17 +111,18 @@
 
 						if (_currentLine < _envStartLine || _currentLine > _envEndLine)
 						{
-							Tuple<GlobalEnv, int, int> ret =
+							Tuple<GlobalEnv, TypeBuilder, int, int> ret =
 								project.GetActiveEnv(_source.FileIndex, _currentLine + 1);
 
 							_env          = ret.field0;
-							_envStartLine = ret.field1 - 1;
-							_envEndLine   = ret.field2 - 1;
+							_type         = ret.field1;
+							_envStartLine = ret.field2 - 1;
+							_envEndLine   = ret.field3 - 1;
 						}
 					}
 				}
 
-				lexer.SetLine(source, offset, _env);
+				lexer.SetLine(source, offset, _env, _type);
 			}
 		}
 	}



More information about the svn mailing list