[svn] r6787: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n Nemerle.Com...

IT svnadmin at nemerle.org
Thu Oct 26 04:44:00 CEST 2006


Log:
Added the background color of the space to the right of the last character for verbatim string and quotations.

Author: IT
Date: Thu Oct 26 04:43:53 2006
New Revision: 6787

Added:
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorizer.cs
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj

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	Thu Oct 26 04:43:53 2006
@@ -382,6 +382,8 @@
     {
       _keepDollar = false;
 
+      try
+      {
       def tok = base.GetToken();
 
       def (tp, color, trigger) = match (tok)
@@ -458,10 +460,16 @@
 
       (tok, tp, color, trigger)
     }
+      catch
+      {
+      | _ => (Token.Identifier(""), TP.Unknown, C.Text, TR.None)
+      }
+    }
 
     public GetToken(prevState : ScanState) : ScanTokenInfo
     {
       _tokenInfo.State = prevState;
+      _tokenInfo.ColorizeEnd = false;
 
       _last_line  = line;
       _last_col   = col;
@@ -471,12 +479,26 @@
         =
       if (eol())
       {
-        when (_tokenInfo.IsString && !_tokenInfo.IsMultiLineString)
-          _tokenInfo.State &= ~ScanState.String;
-
         _tokenInfo.IsEndOfLine = eol();
 
-        (Token.EndOfFile(), TP.Unknown, C.Text, TR.None)
+        def color = if (_tokenInfo.IsMultiLineString)
+        {
+          _tokenInfo.ColorizeEnd = true;
+          C.VerbatimString
+        }
+        else if (_tokenInfo.IsQuotation)
+        {
+          _tokenInfo.ColorizeEnd = true;
+          C.Quotation
+        }
+        else
+        {
+          when (_tokenInfo.IsString)
+            _tokenInfo.State &= ~ScanState.String;
+          C.Text
+        }
+
+        (Token.EndOfFile(), TP.Unknown, color, TR.None)
       }
       else if (_onPreprocessor)
       {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n	Thu Oct 26 04:43:53 2006
@@ -13,6 +13,7 @@
     public mutable Triggers    : ScanTokenTriggers;
     public mutable Type        : ScanTokenType;
     public mutable IsEndOfLine : bool;
+    public mutable ColorizeEnd : bool;
 
     public BracketCount : int
     {

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs	Thu Oct 26 04:43:53 2006
@@ -12,7 +12,7 @@
 		static readonly Color[] QuotationBackColor = new Color[] {
 			Color.FromArgb(230, 237, 228), // Quotation
 			Color.FromArgb(240, 230, 220), // Quotation Verbatim String
-			Color.FromArgb(255, 210, 220)  // Verbatim String
+			Color.FromArgb(250, 232, 232)  // Verbatim String
 		};
 
 		public NemerleColorableItem(string displayName)

Added: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorizer.cs
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorizer.cs	Thu Oct 26 04:43:53 2006
@@ -0,0 +1,38 @@
+using System;
+
+using Microsoft.VisualStudio.Package;
+using Microsoft.VisualStudio.TextManager.Interop;
+
+namespace Nemerle.VisualStudio.LanguageService
+{
+	class NemerleColorizer : Colorizer
+	{
+		public NemerleColorizer(NemerleLanguageService ls, IVsTextLines buffer, NemerleScanner scaner) 
+			: base(ls, buffer, scaner)
+		{
+		}
+
+		public override int ColorizeLine(int line, int length, IntPtr ptr, int state, uint[] attrs)
+		{
+			NemerleScanner scanner = (NemerleScanner)Scanner;
+
+			scanner._currentLine = line;
+
+			int ret;
+
+			try
+			{
+				ret = base.ColorizeLine(line, length, ptr, state, attrs);
+
+				if (attrs != null && scanner._colorizeEnd)
+					attrs[length] = (uint)scanner._lastColor;
+			}
+			finally
+			{
+				scanner._currentLine = -1;
+			}
+
+			return ret;
+		}
+	}
+}

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	Thu Oct 26 04:43:53 2006
@@ -118,6 +118,11 @@
 
 				_specialSources.Clear();
 
+				foreach (NemerleColorizer colorizer in _colorizers.Values)
+					colorizer.Dispose();
+
+				_colorizers.Clear();
+
 				if (_preferences != null)
 				{
 					_preferences.Dispose();
@@ -400,6 +405,26 @@
 
 		#endregion
 
+		#region Colorizer
+
+		Dictionary<IVsTextLines, NemerleColorizer> _colorizers = new Dictionary<IVsTextLines,NemerleColorizer>();
+
+		public override Colorizer GetColorizer(IVsTextLines buffer)
+		{
+			NemerleColorizer colorizer;
+
+			if (!_colorizers.TryGetValue(buffer, out colorizer))
+			{
+				colorizer = new NemerleColorizer(this, buffer, (NemerleScanner)GetScanner(buffer));
+
+				_colorizers.Add(buffer, colorizer);
+			}
+
+			return colorizer;
+		}
+
+		#endregion
+
 		public override ImageList GetImageList()
 		{
 			return base.GetImageList();

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	Thu Oct 26 04:43:53 2006
@@ -20,6 +20,9 @@
 
 		private NemerleLanguageService _languageService;
 		private IVsTextLines           _buffer;
+		internal int                    _currentLine = -1;
+		internal TokenColor             _lastColor;
+		internal bool                   _colorizeEnd;
 
 		private ScanLexer _lexer;
 		private ScanLexer GetLexer()
@@ -41,7 +44,6 @@
 
 			return _lexer;
 		}
-			//System.Diagnostics.Debug.WriteLine(source);
 
 		// Its calling depends on IVsColorizer.GetStateMaintenanceFlag, which defaults to true.
 		//
@@ -54,8 +56,11 @@
 
 			state = (int)info.State;
 
+			_lastColor   = (TokenColor)info.Color;
+			_colorizeEnd = info.ColorizeEnd;
+
+			tokenInfo.Color      = _lastColor;
 			tokenInfo.Type       = (TokenType)    info.Type;
-			tokenInfo.Color      = (TokenColor)   info.Color;
 			tokenInfo.Trigger    = (TokenTriggers)info.Triggers;
 			tokenInfo.StartIndex = info.Token.Location.Column    - 1;
 			tokenInfo.EndIndex   = info.Token.Location.EndColumn - 2;

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	Thu Oct 26 04:43:53 2006
@@ -125,6 +125,7 @@
     <Compile Include="LanguageService\NemerleAuthoringScope.cs" />
     <Compile Include="LanguageService\NemerleAuthoringSink.cs" />
     <Compile Include="LanguageService\NemerleColorableItem.cs" />
+    <Compile Include="LanguageService\NemerleColorizer.cs" />
     <Compile Include="LanguageService\NemerleLanguageService.cs" />
     <Compile Include="LanguageService\NemerleScanner.cs" />
     <Compile Include="LanguageService\NemerleSource.cs" />



More information about the svn mailing list