[svn] r6724: vs-plugin/trunk: Nemerle.Compiler.Utils/AstBrowserForm.n Nemerle.Compiler.Utils/Const.n Nemer...

IT svnadmin at nemerle.org
Wed Sep 27 06:06:45 CEST 2006


Log:
Regions for namespaces and types.

Author: IT
Date: Wed Sep 27 06:06:32 2006
New Revision: 6724

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/AstBrowserForm.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Const.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Debug.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Decl.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj
   vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/AstBrowserForm.n
==============================================================================

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Const.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Const.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Const.n	Wed Sep 27 06:06:32 2006
@@ -1,4 +1,5 @@
 using System;
+
 namespace Nemerle.Completion2
 {
 	public module Const

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	Wed Sep 27 06:06:32 2006
@@ -119,6 +119,9 @@
     <Compile Include="Nemerle.Completion2\CodeModel\Project.Debug.n" />
     <Compile Include="Nemerle.Completion2\CompiledUnitAstBrowser.n" />
   </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Nemerle.Completion2\ISourceTextManager.n" />
+  </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

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

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n	Wed Sep 27 06:06:32 2006
@@ -11,8 +11,14 @@
 {
 	public partial class Project
 	{
-    CompleteInNamespace(_ns : Decl.Namespace, _fileIndex : int, _line : int, _col : int,
-      _getText : GetText) : array[CompletionElem]
+    CompleteInNamespace(
+      _ns        : Decl.Namespace,
+      _fileIndex : int,
+      _line      : int,
+      _col       : int,
+      _source    : ISourceTextManager
+    )
+      : array[CompletionElem]
     {
       _topKeywords
     }

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	Wed Sep 27 06:06:32 2006
@@ -21,7 +21,7 @@
       fileIndex : int,
       line      : int,
       col       : int, 
-      getText   : GetText
+      source    : ISourceTextManager
     )
       : array[CompletionElem]
     {
@@ -37,8 +37,8 @@
           
           if (loc.Contains(line, col)) // completion in method body
           {
-            def bodyCode       = getText(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
-            def completionCode = getText(loc.Line, loc.Column, line, col);
+            def bodyCode       = source.GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
+            def completionCode = source.GetRegion(loc.Line, loc.Column, line, col);
             def result         = _engine.RunCompletionEngine(method, bodyCode, completionCode.Length);
 
             if (result == null)
@@ -76,7 +76,7 @@
       fileIndex : int,
       line      : int,
       col       : int,
-      getText   : GetText
+      source    : ISourceTextManager
     )
       : Location * object
     {
@@ -91,7 +91,7 @@
 
         if (loc.Contains(line, col)) // in method body
         {
-          def bodyCode = getText(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
+          def bodyCode = source.GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
 
           def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, loc);
 
@@ -154,11 +154,11 @@
       fileIndex : int,
       line      : int,
       col       : int,
-      getText   : GetText
+      source    : ISourceTextManager
     )
       : QuickTipInfo
     {
-      def (loc, obj) = FindObject(typeDecl, fileIndex, line, col, getText);
+      def (loc, obj) = FindObject(typeDecl, fileIndex, line, col, source);
 
       match (obj)
       {
@@ -178,11 +178,11 @@
       fileIndex : int,
       line      : int,
       col       : int,
-      getText   : GetText
+      source    : ISourceTextManager
     )
       : GotoInfo
     {
-      def (_, obj) = FindObject(typeDecl, fileIndex, line, col, getText);
+      def (_, obj) = FindObject(typeDecl, fileIndex, line, col, source);
 
       match (obj)
       {
@@ -202,7 +202,7 @@
       fileIndex : int,
       line      : int,
       col       : int, 
-      getText   : GetText
+      source    : ISourceTextManager
     )
       : MethodTipInfo
     {
@@ -217,7 +217,7 @@
           
           if (loc.Contains(line, col)) // completion in method body
           {
-            def bodyCode = getText(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
+            def bodyCode = source.GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
             def groups   = _engine.PreParse(bodyCode, loc);
             def tokens   = ExprFinder().Find(groups, line, col);
 
@@ -225,7 +225,7 @@
             {
             | Some(group) =>
 
-              def completionCode = getText(loc.Line, loc.Column, group.Location.Line, group.Location.Column);
+              def completionCode = source.GetRegion(loc.Line, loc.Column, group.Location.Line, group.Location.Column);
               def code           = completionCode.TrimEnd(' ', '\t', '\r', '\n');
               def result         = _engine.RunCompletionEngine(method, bodyCode, code.Length);
 

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n	Wed Sep 27 06:06:32 2006
@@ -16,8 +16,14 @@
     static UsingLen          : int = 5;
 
     /// Complete word inside the using directive.
-    CompleteInUsing(us : Decl.Using, fileIndex : int, line : int, col : int,
-      getText : GetText) : array[CompletionElem]
+    CompleteInUsing(
+      us        : Decl.Using,
+      fileIndex : int,
+      line      : int,
+      col       : int,
+      source    : ISourceTextManager
+    )
+      : array[CompletionElem]
     {
       def loc = us.Location;
 
@@ -38,7 +44,7 @@
         // If the previous character is '.', the user is trying to get 
         // the list of all internal elements (types and namespaces).
         // Otherwise consider him trying to complete the last element.
-        def text = getText(last.Line, last.Column, last.EndLine, last.EndColumn);
+        def text = source.GetRegion(last.Line, last.Column, last.EndLine, last.EndColumn);
         def completeLastName = text != ".";
 
         // Completion befor namespace name

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	Wed Sep 27 06:06:32 2006
@@ -14,7 +14,6 @@
 
 namespace Nemerle.Completion2
 {
-  public delegate GetText        (line : int, col : int, lineEnd : int, colEnd : int) : string;
   public delegate AddHiddenRegion(location : Location, isExpanded : bool) : void;
   public delegate AddError       (compilerMessage : CompilerMessage) : void;
 
@@ -29,7 +28,7 @@
       [NotNull] filePath : string, 
                 line     : int,
                 col      : int,
-      [NotNull] getText  : GetText
+      [NotNull] source   : ISourceTextManager
     )
       : array[CompletionElem]
     {
@@ -40,9 +39,9 @@
       match (decl)
       {
         | GlobalAttribute => array(0)
-        | Using as us     => CompleteInUsing(us, fileIndex, line, col, getText);
-        | Namespace as ns => CompleteInNamespace(ns, fileIndex, line, col, getText);
-        | Type as ty      => CompleteInType(ty, fileIndex, line, col, getText);
+        | Using as us     => CompleteInUsing    (us, fileIndex, line, col, source);
+        | Namespace as ns => CompleteInNamespace(ns, fileIndex, line, col, source);
+        | Type as ty      => CompleteInType     (ty, fileIndex, line, col, source);
         | None            => throw System.Exception(); //array(0)
       }
     }
@@ -51,7 +50,8 @@
       strs      : SCG.IEnumerable[string],
       glyphType : int,
       info      : string
-      )         : array[CompletionElem]
+    )
+      : array[CompletionElem]
     {
       def ary = SCG.List();
 
@@ -79,7 +79,8 @@
       fileIndex : int, 
       line : int,
       col : int
-      ) : Decl
+    )
+      : Decl
     {
       def find_decl(decl : Decl)
       {
@@ -109,16 +110,18 @@
 
     /// Finds the innermost top level construction (namespace, class,
     /// using, attribute) located at filePath, line, and col.
-    public GetActiveDecl(
-      [NotNull] filePath : string,
-      line               : int,
-      col                : int)
-    : Decl
+    public GetActiveDecl([NotNull] filePath : string, line : int, col : int) : Decl
     {
       GetActiveDecl(_compileUnits.GetFileIndex(filePath), line, col)
     }
 
-    public GetQuickTipInfo(/*[NotNull]*/ filePath : string, line : int, col : int, getText : GetText) : QuickTipInfo
+    public GetQuickTipInfo(
+      [NotNull] filePath : string,
+                line     : int,
+                col      : int,
+      [NotNull] source   : ISourceTextManager
+    )
+      : QuickTipInfo
     {
       def fileIndex = _compileUnits.GetFileIndex(filePath);
       def decl      = GetActiveDecl(fileIndex, line, col);
@@ -126,20 +129,26 @@
       match (decl)
       {
       | Using as us => GetUsingQuickTip(us, fileIndex, line, col)
-      | Type  as tp => GetTypeQuickTip (tp, fileIndex, line, col, getText);
+      | Type  as tp => GetTypeQuickTip (tp, fileIndex, line, col, source);
       | None        => throw System.Exception()
       | _ => null
       }
     }
 
-    public GetGotoInfo([NotNull] filePath : string, line : int, col : int, getText : GetText) : GotoInfo
+    public GetGotoInfo(
+      [NotNull] filePath : string,
+                line     : int,
+                col      : int,
+      [NotNull] source   : ISourceTextManager
+    )
+      : GotoInfo
     {
       def fileIndex = _compileUnits.GetFileIndex(filePath);
       def decl      = GetActiveDecl(fileIndex, line, col);
 
       match (decl)
       {
-      | Type as tp => GetTypeGoto(tp, fileIndex, line, col, getText);
+      | Type as tp => GetTypeGoto(tp, fileIndex, line, col, source);
       | None       => throw System.Exception()
       | _ => null
       }
@@ -147,9 +156,9 @@
 
     public Check(
       /*[NotNull]*/ fileName        : string,
+      /*[NotNull]*/ source          : ISourceTextManager,
       /*[NotNull]*/ addHiddenRegion : AddHiddenRegion,
-      /*[NotNull]*/ addError        : AddError,
-      /*[NotNull]*/ getText         : GetText
+      /*[NotNull]*/ addError        : AddError
     )
       : void
     {
@@ -158,34 +167,48 @@
 
       def fileIndex = _compileUnits.GetFileIndex(fileName);
 
-      foreach (decl in _compileUnits[fileIndex].Decls)
+      def isNext(line, col, ch)
       {
-      | Type(builder) as tp =>
+        def str = source.GetLine(line);
+        col > 0 && str.Length >= col && str[col - 1] == ch
+      }
+
+      def processDecl(decl)
+      {
+      | Decl.Type(builder) as tp /*when decl.FileIndex == fileIndex*/ =>
+
+        def _start = Environment.TickCount;
 
         foreach (member in builder.GetMembers())
         {
         | method is MethodBuilder =>
 
+#if !DEBUG
+          when (_start > Environment.TickCount - 2000)
+          {
+#endif
           // Get errors.
           //
           def location = method.BodyLocation;
-          def bodyCode = getText(location.Line, location.Column, location.EndLine, location.EndColumn);
+            def bodyCode = source.GetRegion(location.Line, location.Column, location.EndLine, location.EndColumn);
 
           _ = _engine.CompileMethod(method, bodyCode, location);
 
           foreach (cm in _engine.CompilerMessages)
             addError(cm);
+#if !DEBUG
+          }
+#endif
 
           // Get region location.
           //
           def loc      = method.Location.TrimStart(method.fun_header.Location, false);
-          def bodyCode = getText(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
 
-          when (!loc.IsEmptyLocation())
+          when (!loc.IsEmpty())
           {
             addHiddenRegion(
-              if (bodyCode.Length > 0 && bodyCode[0] == ' ')
-                Location(loc.FileIndex, loc.Line, loc.Column + 1, loc.EndLine, loc.EndColumn)
+              if (isNext(loc.Line, loc.Column, ' '))
+                Location(fileIndex, loc.Line, loc.Column + 1, loc.EndLine, loc.EndColumn)
               else
                 loc,
               true);
@@ -194,20 +217,60 @@
         | _ => ()
         }
 
-        addHiddenRegion(tp.Location, true);
+        // Region for the type itself.
+        //
+        mutable lineStart = tp.Location.Line;
+        mutable colStart  = tp.Location.Column;
+        mutable lineEnd   = tp.Location.EndLine;
+        mutable colEnd    = tp.Location.EndColumn;
+
+        // Should be temporary solution until we get location for the type name.
+        //
+        colStart = source.GetLine(lineStart).Length + 1;
+
+        addHiddenRegion(Location(fileIndex, lineStart, colStart, lineEnd, colEnd), true);
+
+      | Namespace(decls, _, locations, _, _, nsloc) =>
+
+        decls.Iter(processDecl);
+
+        match (locations.Find(l => l.FileIndex == fileIndex))
+        {
+        | Some(loc) =>
+
+          mutable lineStart = loc.EndLine;
+          mutable colStart  = loc.EndColumn;
+          mutable lineEnd   = nsloc.EndLine;
+          mutable colEnd    = nsloc.EndColumn;
+
+          when (isNext(lineStart, colStart, ' ')) colStart++;
+          when (isNext(lineEnd,   colEnd,   '}')) colEnd++;
+
+          addHiddenRegion(Location(fileIndex, lineStart, colStart, lineEnd, colEnd), true);
 
+        | None => ()
+        }
       | _ => ()
       }
+
+      foreach (decl in _compileUnits[fileIndex].Decls)
+        processDecl(decl);
     }
 
-    public GetMethodTip([NotNull] filePath : string, line : int, col : int, getText : GetText) : MethodTipInfo
+    public GetMethodTip(
+      [NotNull] filePath : string,
+                line     : int,
+                col      : int,
+      [NotNull] source   : ISourceTextManager
+    )
+      : MethodTipInfo
     {
       def fileIndex = _compileUnits.GetFileIndex(filePath);
       def decl      = GetActiveDecl(fileIndex, line, col);
       
       match (decl)
       {
-      | Type as tp => GetMethodTip(tp, fileIndex, line, col, getText);
+      | Type as tp => GetMethodTip(tp, fileIndex, line, col, source);
       | None       => throw System.Exception()
       | _ => null
       }

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

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n	Wed Sep 27 06:06:32 2006
@@ -0,0 +1,12 @@
+using System;
+
+namespace Nemerle.Completion2
+{
+  public interface ISourceTextManager
+  {
+    GetRegion         (lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string;
+    GetLine           (line : int) : string;
+    GetNearestPosition(line : int, col : int) : int;
+    GetLineAndColumn  (pos  : int) : int * int;
+  }
+}

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	Wed Sep 27 06:06:32 2006
@@ -1,10 +1,13 @@
+using System;
 using System.Console;
 using System.IO;
 using System.Reflection;
 using System.Text;
+
 using Nemerle.Compiler;
 using Nemerle.Imperative;
 using Nemerle.Text;
+
 using NUnit.Framework;
 
 using Nemerle.Completion2;
@@ -67,27 +70,6 @@
       }
     }
 
-    GetTextFromFile(filePath : string, line : int, col : int, lineEnd : int, colEnd : int) : string
-    {
-      def line = line - 1; def col = col - 1; def lineEnd = lineEnd - 1; def colEnd = colEnd - 1;
-      def lines = File.ReadAllLines(filePath);
-      def builder = StringBuilder();
-
-      if (line == lineEnd)
-        ignore(builder.Append(lines[line].Substring(col, colEnd - col)));
-      else
-      {
-        ignore(builder.AppendLine(lines[line].Substring(col)));
-
-        for (mutable i = line + 1; i < lineEnd; i++)
-          ignore(builder.AppendLine(lines[i]));
-
-        ignore(builder.Append(lines[lineEnd].Substring(0, colEnd)));
-      }
-
-      builder.ToString();
-    }
-
     /// Íŕőîäčň ňĺă č âîçâđŕůŕĺň ĺăî ęîîđäčíŕňű (ńňđîęŕ, ęîëîíęŕ).
     /// ôîđěŕň ňĺăŕ /*Ňĺăŕ*/ čëč /*Ňĺăŕ:+ńäâčă*/ čëč /*Ňĺăŕ:-ńäâčă*/
     /// Ńäâčă ďîçâîë˙ĺň çŕäŕňü ęîëîíęó ń îňíîńčňĺëüíűě ńäâčăîě.
@@ -123,5 +105,51 @@
 
       throw System.Exception("Tag not found.");
     }
+
+    private class TestSourceTextManager : ISourceTextManager
+    {
+      public this(filePath : string)
+      {
+        _filePath = filePath;
+      }
+
+      _filePath : string;
+
+      public GetRegion(line : int, col : int, lineEnd : int, colEnd : int) : string
+      {
+        def line = line - 1; def col = col - 1; def lineEnd = lineEnd - 1; def colEnd = colEnd - 1;
+        def lines = File.ReadAllLines(_filePath);
+        def builder = StringBuilder();
+
+        if (line == lineEnd)
+          ignore(builder.Append(lines[line].Substring(col, colEnd - col)));
+        else
+        {
+          ignore(builder.AppendLine(lines[line].Substring(col)));
+
+          for (mutable i = line + 1; i < lineEnd; i++)
+            ignore(builder.AppendLine(lines[i]));
+
+          ignore(builder.Append(lines[lineEnd].Substring(0, colEnd)));
+        }
+
+        builder.ToString();
+      }
+
+      public GetLine(_line : int) : string
+      {
+        throw NotImplementedException();
+      }
+
+      public GetNearestPosition(_line : int, _col : int) : int
+      {
+        throw NotImplementedException();
+      }
+
+      public GetLineAndColumn(_pos : int) : int * int
+      {
+        throw NotImplementedException();
+      }
+    }
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n	Wed Sep 27 06:06:32 2006
@@ -18,7 +18,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete glabal ns");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.AreEqual(2, result.Length, "Expected 2 elements.");
     }
@@ -35,7 +35,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Hint in body of implicit match");
-      def result = _project.GetQuickTipInfo(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.GetQuickTipInfo(file, line, col, TestSourceTextManager(file));
 
       Assert.IsNotNull(result, "result is null");
       //WriteLine(result.Text);
@@ -50,7 +50,7 @@
 
       def Test()
       {
-        def result = _project.GetQuickTipInfo(file, line, col, GetTextFromFile(file, _, _, _, _));
+        def result = _project.GetQuickTipInfo(file, line, col, TestSourceTextManager(file));
 
         Assert.IsNotNull(result, "result is null");
         WriteLine(result.Text);
@@ -71,7 +71,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete generic type cast");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.Greater(result.Length, 0);
     }
 
@@ -80,7 +80,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete type cast");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.Greater(result.Length, 0);
     }
 
@@ -89,7 +89,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete namespace");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
     }
@@ -99,7 +99,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete vars with same name");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.AreEqual(2, result.Length, "Expected 2 elements.");
     }
@@ -109,7 +109,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete in match variant 3");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
     }
@@ -119,7 +119,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete in match variant 2");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
     }
@@ -129,7 +129,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete in match variant 1");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
     }
@@ -139,7 +139,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete type escalation 3");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
     }
@@ -149,7 +149,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete type escalation 2");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
     }
@@ -159,7 +159,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete type escalation");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.AreEqual(18, result.Length, "Expected 1 elements.");
     }
@@ -169,7 +169,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete qualidend");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.AreEqual(2, result.Length, "Expected 1 elements.");
     }
@@ -179,7 +179,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Main() 2");
-      def decl = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def decl = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(decl, "decl is null");
     }
 
@@ -188,7 +188,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "using");
-      def decl = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def decl = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(decl, "decl is null");
     }
 
@@ -209,7 +209,7 @@
     {
       def file = FilePath1;
       def (line, col) = ReadLocation(file, "Complete aliased type");
-      def result = _project.CompleteWord(file, line, col, GetTextFromFile(file, _, _, _, _));
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.Greater(result.Length, 0);
       //FixMe
@@ -287,7 +287,7 @@
 
       def Test()
       {
-        def result = _project.GetQuickTipInfo(file, line, col, GetTextFromFile(file, _, _, _, _));
+        def result = _project.GetQuickTipInfo(file, line, col, TestSourceTextManager(file));
 
         Assert.IsNotNull(result, "result is null");
         WriteLine(result.Text);

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n	Wed Sep 27 06:06:32 2006
@@ -36,16 +36,16 @@
 		[Obsolete("Callers should not use the ICodeGenerator interface.")]
 		public override CreateGenerator():  ICodeGenerator
 		{
-// Obsolete
+      // Obsolete
 #pragma warning disable 618
 			provider.CreateGenerator();
-#pragma warning restore 618
+  #pragma warning restore 618
 		}
 
 		[Obsolete("Callers should not use the ICodeCompiler interface.")]
 		public override CreateCompiler():  ICodeCompiler
 		{
-// Obsolete
+      // Obsolete
 #pragma warning disable 618
 			provider.CreateCompiler();
 #pragma warning restore 618

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n	Wed Sep 27 06:06:32 2006
@@ -448,7 +448,7 @@
       l1.Column == l2.Column && l1.EndColumn == l2.EndColumn
     }
 
-    public IsEmptyLocation(this loc : Location) : bool
+    public IsEmpty(this loc : Location) : bool
     {
       loc.EndLine == 0 || loc.EndLine < loc.Line || (loc.EndLine == loc.Line && loc.EndColumn <= loc.Column)
     }

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	Wed Sep 27 06:06:32 2006
@@ -23,11 +23,11 @@
 			_overloadPossibility = overloadPossibility;
 		}
 
-		public NemerleAuthoringScope(ProjectInfo project, AuthoringSink sink, string filePath, GetText getText)
+		public NemerleAuthoringScope(ProjectInfo project, AuthoringSink sink, string filePath, ISourceTextManager source)
 			: this(project, sink)
 		{
 			_filePath = filePath;
-			_getText  = getText;
+			_sourceText = source;
 		}
 
 		public NemerleAuthoringScope(ProjectInfo project, AuthoringSink sink, Methods methods)
@@ -51,7 +51,7 @@
 		private Methods          _methods;
 		private ProjectInfo      _project;
 		private string           _filePath;
-		private GetText          _getText;
+		private ISourceTextManager _sourceText;
 
 		#endregion
 
@@ -61,7 +61,7 @@
 		{
 			span = new TextSpan();
 
-			QuickTipInfo info = _project.GetQuickTip(_filePath, line, col, _getText);
+			QuickTipInfo info = _project.GetQuickTip(_filePath, line, col, _sourceText);
 
 			if (info == null)
 				return null;
@@ -83,7 +83,7 @@
 		{
 			span = new TextSpan();
 
-			GotoInfo info = _project.GetGoto(_filePath, line, col, _getText);
+			GotoInfo info = _project.GetGoto(_filePath, line, col, _sourceText);
 
 			if (info == null || !info.HasLocation)
 				return null;
@@ -99,7 +99,7 @@
 		public override Declarations GetDeclarations(
 			IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 		{
-			return new NemerleDeclarations(_overloadPossibility);
+			return new NemerleDeclarations(_overloadPossibility ?? new CompletionElem[0]);
 		}
 
 		public override Methods GetMethods(int line, int col, string name)

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	Wed Sep 27 06:06:32 2006
@@ -205,6 +205,7 @@
 
 				projectInfo.Project.Check(
 					request.FileName,
+					new SourceTextManager(this, request.View),
 					delegate(Location location, bool isExpanded)
 					{
 						NewHiddenRegion r = new NewHiddenRegion();
@@ -230,10 +231,6 @@
 							cm.MessageKind == MessageKind.Error   ? Severity.Error :
 							cm.MessageKind == MessageKind.Warning ? Severity.Warning :
 							                                        Severity.Hint);
-					},
-					delegate(int line, int col, int lineEnd, int colEnd)
-					{
-						return GetCodeRegion(request, line, col, lineEnd, colEnd);
 					});
 			}
 			finally
@@ -260,11 +257,7 @@
 				return null;
 
 			return new NemerleAuthoringScope(
-				projectInfo, request.Sink, request.FileName,
-				delegate(int line, int col, int lineEnd, int colEnd)
-				{
-					return GetCodeRegion(request, line, col, lineEnd, colEnd);
-				});
+				projectInfo, request.Sink, request.FileName, new SourceTextManager(this, request.View));
 		}
 
 		private AuthoringScope GetCompleteWord(ParseRequest request)
@@ -277,11 +270,7 @@
 					return null;
 
 				CompletionElem[] overloads = projectInfo.CompleteWord(
-					request.FileName, request.Line, request.Col,
-					delegate(int line, int col, int lineEnd, int colEnd)
-					{
-						return GetCodeRegion(request, line, col, lineEnd, colEnd);
-					});
+					request.FileName, request.Line, request.Col, new SourceTextManager(this, request.View));
 
 				if (overloads.Length > 0)
 					return new NemerleAuthoringScope(projectInfo, request.Sink, overloads);
@@ -303,11 +292,7 @@
 				return null;
 
 			NemerleMethods methods = projectInfo.GetMethodTip(
-				request.FileName, request.Line, request.Col,
-				delegate(int line, int col, int lineEnd, int colEnd)
-				{
-					return GetCodeRegion(request, line, col, lineEnd, colEnd);
-				});
+				request.FileName, request.Line, request.Col, new SourceTextManager(this, request.View));
 
 			if (methods != null)
 			{

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 Sep 27 06:06:32 2006
@@ -1,5 +1,9 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.Runtime.InteropServices;
 
 using Microsoft.VisualStudio;
 using Microsoft.VisualStudio.Package;
@@ -18,6 +22,7 @@
 		public NemerleSource(NemerleLanguageService service, IVsTextLines textLines, Colorizer colorizer)
 			: base(service, textLines, colorizer)
 		{
+			//BeginParse();
 		}
 
 		public override CommentInfo GetCommentFormat()
@@ -77,5 +82,166 @@
 			int maxErrors = LanguageService.Preferences.MaxErrorMessages;
 			return new NemerleAuthoringSink(this, reason, line, col, maxErrors);
 		}
+
+		public override void ProcessHiddenRegions(ArrayList hiddenRegions)
+		{
+			IVsEnumHiddenRegions ppenum = null;
+
+			try
+			{
+				// Compare the existing regions with the new regions and 
+				// remove any that do not match the new regions.
+				//
+				IVsHiddenTextSession session = GetHiddenTextSession();
+				TextSpan[]           aspan   = new TextSpan[1];
+
+				aspan[0] = GetDocumentSpan();
+
+				NativeMethods.ThrowOnFailure(session.EnumHiddenRegions(
+					(uint)FIND_HIDDEN_REGION_FLAGS.FHR_BY_CLIENT_DATA,
+					0,//25,
+					aspan,
+					out ppenum));
+
+				IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
+
+				uint fetched;
+				int  matched = 0;
+				int  removed = 0;
+				int  added   = 0;
+				int  pos     = 0;
+
+				// Create a list of IVsHiddenRegion objects, sorted in the same order that the
+				// authoring sink sorts.  This is necessary because VS core editor does NOT return
+				// the regions in the same order that we add them.
+				//
+				ArrayList regions = new ArrayList();
+				ArrayList spans   = new ArrayList();
+
+				uint nr;
+				int ret = ppenum.GetCount(out nr);
+
+				while ((ret=ppenum.Next(1, aregion, out fetched)) == NativeMethods.S_OK && fetched == 1)
+				{
+					NativeMethods.ThrowOnFailure(aregion[0].GetSpan(aspan));
+
+					TextSpan s = aspan[0];
+
+					int i;
+					for (i = spans.Count - 1; i >= 0; i--)
+					{
+						TextSpan s2 = (TextSpan)spans[i];
+
+						if (TextSpanHelper.StartsAfterStartOf(s, s2))
+							break;
+					}
+
+					spans.  Insert(i + 1, s);
+					regions.Insert(i + 1, aregion[0]);
+				}
+
+				// Now merge the list found with the list in the AuthoringSink to figure out
+				// what matches, what needs to be removed, and what needs to be inserted.
+				//
+				NewHiddenRegion r = pos < hiddenRegions.Count ?
+					(NewHiddenRegion)hiddenRegions[pos] :
+					new NewHiddenRegion();
+
+				for (int i = 0, n = regions.Count; i < n; i++)
+				{
+					IVsHiddenRegion region = (IVsHiddenRegion)regions[i];
+					TextSpan        span   = (TextSpan)spans[i];
+
+					// In case we're inserting a new region, scan ahead to matching start line
+					//
+					while (r.tsHiddenText.iStartLine < span.iStartLine)
+					{
+						pos++;
+
+						if (pos >= hiddenRegions.Count)
+						{
+							r = new NewHiddenRegion();
+							break;
+						}
+						else
+						{
+							r = (NewHiddenRegion)hiddenRegions[pos];
+						}
+					}
+
+					if (TextSpanHelper.IsSameSpan(r.tsHiddenText, span))
+					{
+						// This region is already there.
+						//
+						matched++;
+						hiddenRegions.RemoveAt(pos);
+						r = (pos < hiddenRegions.Count) ? (NewHiddenRegion)hiddenRegions[pos] : new NewHiddenRegion();
+					}
+					else
+					{
+						removed++;
+						NativeMethods.ThrowOnFailure(region.Invalidate((int)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable));
+					}
+				}
+
+				int start = Environment.TickCount;
+
+				if (hiddenRegions.Count > 0)
+				{
+					int count = hiddenRegions.Count;
+
+					// For very large documents this can take a while, so add them in chunks of 
+					// 1000 and stop after 5 seconds.
+					//
+					int               maxTime   = this.LanguageService.Preferences.MaxRegionTime;
+					int               chunkSize = 1000;
+					NewHiddenRegion[] chunk     = new NewHiddenRegion[chunkSize];
+					int               now       = Environment.TickCount;
+					int               i         = 0;
+
+					while (i < count 
+#if DEBUG
+						&& start > now - maxTime
+#endif
+					)
+					{
+						int j = 0;
+
+						while (i < count && j < chunkSize)
+						{
+							r = (NewHiddenRegion)hiddenRegions[i];
+
+							if (!TextSpanHelper.ValidSpan(this, r.tsHiddenText))
+							{
+								Debug.Assert(false, "Invalid span " + r.tsHiddenText.iStartLine + "," + r.tsHiddenText.iStartIndex + "," + r.tsHiddenText.iEndLine + "," + r.tsHiddenText.iEndIndex);
+								break;
+							}
+							else
+							{
+								chunk[j] = r;
+								added++;
+							}
+
+							i++;
+							j++;
+						}
+
+						int hr = session.AddHiddenRegions((int)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable, j, chunk, null);
+
+						if (NativeMethods.Failed(hr))
+							break; // stop adding if we start getting errors.
+
+						now = Environment.TickCount;
+					}
+				}
+
+				int diff = Environment.TickCount - start;
+				Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Hidden Regions: Matched={0}, Removed={1}, Addded={2}/{3} in {4} ms", matched, removed, added, hiddenRegions.Count, diff));
+			}
+			finally
+			{
+				Marshal.ReleaseComObject(ppenum);
+			}
+		}
 	}
 }

Added: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs	Wed Sep 27 06:06:32 2006
@@ -0,0 +1,76 @@
+using System;
+
+using Microsoft.VisualStudio;
+using Microsoft.VisualStudio.TextManager.Interop;
+
+using Nemerle.Builtins;
+
+using Nemerle.Completion2;
+
+namespace Nemerle.VisualStudio.LanguageService
+{
+	class SourceTextManager : ISourceTextManager
+	{
+		public SourceTextManager(NemerleLanguageService service, IVsTextView view)
+		{
+			_view    = view;
+			_service = service;
+		}
+
+		IVsTextView            _view;
+		NemerleLanguageService _service;
+
+		private IVsTextLines _textLines;
+		public  IVsTextLines  TextLines
+		{
+			get
+			{
+				if (_textLines == null)
+					_view.GetBuffer(out _textLines);
+
+				return _textLines;
+			}
+		}
+
+		private NemerleSource _source;
+		public  NemerleSource  Source
+		{
+			get
+			{
+				if (_source == null)
+					_source = (NemerleSource)_service.GetSource(TextLines);
+				return _source;
+			}
+		}
+
+		public string GetRegion(int lineStart, int colStart, int lineEnd, int colEnd)
+		{
+			string region;
+
+			if (_view.GetTextStream(lineStart - 1, colStart- 1, lineEnd - 1, colEnd - 1, out region) == VSConstants.S_OK)
+				return region;
+
+			return "";
+		}
+
+		public string GetLine(int line)
+		{
+			return Source.GetLine(line - 1);
+		}
+
+		public int GetNearestPosition(int line, int col)
+		{
+			int pos, spaces;
+			return _view.GetNearestPosition(line - 1, col - 1, out pos, out spaces) == VSConstants.S_OK? pos: -1;
+		}
+
+		public Tuple<int, int> GetLineAndColumn(int pos)
+		{
+			int line, col;
+
+			_view.GetLineAndColumn(pos, out line, out col);
+
+			return new Tuple<int,int>(line + 1, col + 1);
+		}
+	}
+}

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	Wed Sep 27 06:06:32 2006
@@ -126,6 +126,7 @@
     <Compile Include="LanguageService\NemerleLanguageService.cs" />
     <Compile Include="LanguageService\NemerleScanner.cs" />
     <Compile Include="LanguageService\NemerleSource.cs" />
+    <Compile Include="LanguageService\SourceTextManager.cs" />
     <Compile Include="NemerlePackage.cs" />
     <Compile Include="Project\NemerleOAFileItem.cs" />
     <Compile Include="Project\HierarchyEventArgs.cs" />

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs	Wed Sep 27 06:06:32 2006
@@ -323,14 +323,14 @@
 			get { return Engine.Project; }
 		}
 
-		public CompletionElem[] CompleteWord(string filePath, int line, int col, GetText getText)
+		public CompletionElem[] CompleteWord(string filePath, int line, int col, ISourceTextManager source)
 		{
-			return Project.CompleteWord(filePath, line + 1, col + 1, getText);
+			return Project.CompleteWord(filePath, line + 1, col + 1, source);
 		}
 
-		public QuickTipInfo GetQuickTip(string filePath, int line, int col, GetText getText)
+		public QuickTipInfo GetQuickTip(string filePath, int line, int col, ISourceTextManager source)
 		{
-			QuickTipInfo info = Project.GetQuickTipInfo(filePath, line + 1, col + 1, getText);
+			QuickTipInfo info = Project.GetQuickTipInfo(filePath, line + 1, col + 1, source);
 
 			if (info != null)
 				info.Text = info.Text.Replace(_projectLocation, "");
@@ -338,14 +338,14 @@
 			return info;
 		}
 
-		public GotoInfo GetGoto(string filePath, int line, int col, GetText getText)
+		public GotoInfo GetGoto(string filePath, int line, int col, ISourceTextManager source)
 		{
-			return Project.GetGotoInfo(filePath, line + 1, col + 1, getText);
+			return Project.GetGotoInfo(filePath, line + 1, col + 1, source);
 		}
 
-		public NemerleMethods GetMethodTip(string filePath, int line, int col, GetText getText)
+		public NemerleMethods GetMethodTip(string filePath, int line, int col, ISourceTextManager source)
 		{
-			MethodTipInfo info = Project.GetMethodTip(filePath, line + 1, col + 1, getText);
+			MethodTipInfo info = Project.GetMethodTip(filePath, line + 1, col + 1, source);
 			return info != null? new NemerleMethods(info): null;
 		}
 	}



More information about the svn mailing list