[svn] r7121: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj Nemerle.Compiler.Utils/...

phantom svnadmin at nemerle.org
Tue Dec 19 18:52:23 CET 2006


Log:
Refactoring & ExtendSelection command.

Author: phantom
Date: Tue Dec 19 18:52:20 2006
New Revision: 7121

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
   vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/Guids.h
   vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmd.ctc
   vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmdID.h
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs
   vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleEditorFactory.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleMenus.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Utils.cs

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	Tue Dec 19 18:52:20 2006
@@ -167,6 +167,9 @@
   <ItemGroup>
     <Compile Include="Nemerle.Completion2\Engine\Engine.Completion.n" />
   </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Nemerle.Completion2\CodeModel\Project.Refactoring.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.

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n	Tue Dec 19 18:52:20 2006
@@ -0,0 +1,291 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+using Nemerle.Assertions;
+using Nemerle.Collections;
+using Nemerle.Compiler;
+using Nemerle.Compiler.Utils;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Compiler.Typedtree;
+using Nemerle.Utility;
+
+using SCG = System.Collections.Generic;
+
+namespace Nemerle.Completion2
+{
+  public partial class Project
+  {
+    public GetUsages([NotNull] filePath : string, line : int, col : int) : array [GotoInfo]
+    {
+      def fileIndex = _compileUnits.GetFileIndex(filePath);
+      def decl      = GetActiveDecl(fileIndex, line, col);
+
+      match (decl)
+      {
+      | Type as ty => FindUsages(ty, fileIndex, line, col).ToArray();
+      | _          => null
+      }
+    }
+
+    public HandleIdleTime([NotNull] lexer : ScanLexer, [NotNull] filePath : string, line : int, col : int) : void
+    {
+      def fileIndex = _compileUnits.GetFileIndex(filePath);
+      def decl      = GetActiveDecl(fileIndex, line, col);
+      
+      match (decl)
+      {
+      | Type as ty =>
+        def highlights = FindUsages(ty, fileIndex, line, col, true).Map(goto =>
+        {
+          match(goto.UsageType)
+          {
+            | UsageType.Usage => (goto.Location, 0)
+            | _ => (goto.Location, 1)
+          }
+        });
+        lexer.SetHighlights(highlights);
+      | _          => ()
+      }
+    }
+
+    // TODO: implement get usages behaviour, this is a stub yet
+    // Ïðèìåðíîå îïèñàíèå àëãîðèòìà ïîèñêà ÷ëåíà êëàññà:
+    // 1. Íàõîäèì âñå ññûëêè íà äàííûé ÷ëåí â äåðåâå òèïîâ.
+    //    Ýòî ìîæíî ñäåëàòü ïðîñêàíèðîâàâ TypeBuilder-û.
+    //    Ïîëó÷èòü âñå TypeBuilder-û ïðîåêòà ìîæíî ñ ïîìîùüþ
+    //    ìåòîäà NamespaceTree.GetTypeBuilders().
+
+    // 1. Find all entry in type tree. It will be done by scan TypeBuilders.
+    //    Get all TypeBuilders you may by NamespaceTree.GetTypeBuilders().
+
+    // 2. Äàëåå ñêàíèðóåì ôàéëû ïûòàÿñü íàéòè âîçìîæíûå âõîæäåíèÿ èìåíè 
+    //    èñêîìîãî ÷ëåíà (òóïî èùåì ïîäñòðîêè â èñõîäíèêàõ).
+    //    Òî êàê ýòî äåëàòü ÿ èçîáðàçèë â findPossibleUsages().
+    //    Ýòîò øàã äîëæåí ñôîðìèðîâàòü ñïèñîê ëîêåøîíîâ ñãðóïèðîàííûé
+    //    ïî èíäåêñàì ôàéëîâ (äëÿ ýòîãî òóïî ïîëó÷àåì ïëîñêèé ñïèñîê è
+    //    ïîòîì ðàññîâûâàåì ëîêåøîíû ïî ãðóïïàì ñ èñïîëçîâàíèåì õýø-òàáëèöû).
+
+    // 2. Scan files for find possible usages (simple text entries).
+    //    It stem must make locations lists grouped by file index.
+
+    // 3. Ñêàíèðóåì ìåòîäû â ôàéëàõ èíäåêñû êîòîðûõ ïîëó÷åíû íà ïðåäûäóùåì øåãå,
+    //    è èùåì òå ìåòîäû êîòîðûå ïåðåñåêàþòñÿ ñ íàéäåííûìè ëîêåøîíàìè.
+    //    Åñëè åñòü ëîêåøíîû â ýòîì ìåòîäå, òî èùåì âõîæäåíèÿ â ýòîì ìåòîäå.
+    //    Êîä ïîèñêà âõîæäåíèÿ äîëæåí ñîâïàäàòü ñ êîäîì ïîèñêà ëîêàëüíîé 
+    //    ïåðåìåííîé. Òàê ÷òî èìååò ñìûñë ïîïðîáîâàòü óíèôèöèðîâàòü ýòè ìåòîäû.
+
+    // 3. Scan methods in files which contains entries (files from file 
+    //    indecis list which you make in step 2).
+    //    (It may be done by GetAllMetodsDefinedInFile(fileIndex : int) : SCG.List[MethodBuilder])
+    //    If lacations from step 2 intersect with method try find entries
+    //    in it method.
+    private FindUsages(inType : Decl.Type, fileIndex : int, line : int, column : int, onlyThisFile : bool = false) : list [GotoInfo]
+    {
+      def (declarationLocation, _, declarationObject) = FindObject(inType, fileIndex, line, column);
+      // TODO: test project 2, test case 3: incorrect location found if starting from line 98 - see why ExprFinder returns incorrect location
+      Debug.WriteLine($"Found declaration: $declarationLocation");
+
+      // TODO: for rename refactoring, we should know all usages, including generated
+      // however, this implementation neglects generated usages
+      def findPossibleUsages(name, onlyThisFile)
+      {
+        mutable entries = [];
+        def sources = _engine.ProjectSources;
+        def filesToSearchThrough =
+          if (onlyThisFile)
+            array[fileIndex]
+          else
+            _engine.Sources.GetFileIndices();
+        foreach (fileIndex in filesToSearchThrough)
+        {
+          def source = sources.GetSource(fileIndex);
+          def code = source.GetText();
+          def findEntry(startPos)
+          {
+            def position = code.OrdinalIndexOf(name, startPos);
+            unless (position < 0)
+            {
+              def (line, column) = source.GetLineIndexOfPosition(position);
+              def location = Location(fileIndex, line, column, line, column + name.Length);
+              entries ::= location;
+              findEntry(position + name.Length);
+            }
+          }
+          findEntry(0);
+        }
+        entries.Reverse()
+      }
+
+      def debug(method)
+      {
+          ignore(method);
+          #if phantom
+          Debug.WriteLine("parsed tree:");
+          when (method.BodyLocation.FileIndex > 0)
+            Debug.WriteLine(PrettyPrint.SprintExpr(None(), method.BodyParsed));
+          Debug.WriteLine("typed tree:");
+          Debug.WriteLine(PrettyPrint.SprintTyExpr(method.BodyTyped));
+          #endif
+      }
+      
+      def findInMethod(localValueDeclaration)
+      {
+        def member = inType.Builder.GetActiveMember(fileIndex, line, column);
+        Debug.WriteLine($"searching for $localValueDeclaration");
+        Debug.WriteLine($"enclosing member:\n $member");
+        match (member)
+        {
+          | method is MethodBuilder =>
+            debug(method);
+            ExprFinder().FindLocalValueEntries(method.BodyTyped, localValueDeclaration);
+          | _ => []
+        }
+      }
+
+      def makeUsage(location, declarationLocation)
+      {
+        if (location == declarationLocation)
+          GotoInfo(location, UsageType.Definition)
+        else
+          GotoInfo(location, UsageType.Usage)
+      }
+      
+      def usageIsReal(mustBeMember : IMember, usage)
+      {
+        if (usage.UsageType == UsageType.Definition)
+          true
+        else
+        {
+          Debug.WriteLine($"checking usage $usage for consistency");
+          Debug.WriteLine($"must be member:\n $mustBeMember");
+          // phantom: strange, why it doesn't catch exeption on christianity.n, any interface member?
+          try
+          {
+            match (GetActiveDecl(usage.FileIndex, usage.Line, usage.Column))
+            {
+              | ty is Decl.Type => //VladD2: don't use identifier with quote ('). It prevent match braces
+                match (ty.Builder.GetActiveMember(usage.FileIndex, usage.Line, usage.Column))
+                {
+                  | method is MethodBuilder =>
+                    debug(method);
+                    def (_, _, usageTypedExpression) = ExprFinder().Find(method.BodyParsed, method.BodyTyped, usage.Line, usage.Column);
+                    Debug.WriteLine($"Expression Finder found such an expression of a usage: $usageTypedExpression");
+                    match (usageTypedExpression)
+                    {
+                      | member is IMember => mustBeMember.GetFullName() == member.GetFullName()
+                      | _ => Debug.WriteLine("Not known IMember type! Perhaps, should be added to isReal function"); false
+                    }
+                  | _ => false
+                }
+              | _ =>  false
+            }
+          }
+          catch
+          {
+            | _ => false  // somewhere tree is not consistent
+          }
+        }
+      }
+
+      match (declarationObject)
+      {
+        | localValue is LocalValue => findInMethod(localValue)
+        | member is MemberBuilder =>
+          def declarationLocation = member.Ast.name.Location;
+          findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage(_, declarationLocation)).Filter(usageIsReal(member, _))
+        //| member is IMember =>
+          //findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage).Filter(usageIsReal(member, _));
+        | _ => [] //TODO: May be it wrong!
+      }
+    }
+  
+    private GetChainOfEnclosingExpressions(fileIndex : int, line : int, column : int) : list[Location]
+    {
+      def source = _engine.ProjectSources.GetSource(fileIndex);
+      def (lastLine, lastColumn) = source.GetLineIndexOfPosition(source.GetText().Length);
+      def wholeFile = Location(fileIndex, 1, 1, lastLine, lastColumn);
+      
+      def lineLocation =
+        if (line < wholeFile.EndLine)
+          Location(fileIndex, line, 1, line + 1, 1);
+        else
+          Location(fileIndex, wholeFile.EndLine, 1, wholeFile.EndLine, wholeFile.EndColumn);
+      def withLineLocation(chain, accumulator = [], added = false)
+      {
+        match (chain)
+        {
+          | head :: tail =>
+            if (head.Contains(lineLocation))
+              withLineLocation(tail, head :: accumulator, false)
+            else
+              withLineLocation(tail, head :: lineLocation :: accumulator, true)
+          | [] =>
+            if (added)
+              accumulator.Reverse()
+            else
+              withLineLocation([], lineLocation :: accumulator, true);
+        }
+      }
+
+      def chainInside(topDeclaration : Decl)
+      {
+        | GlobalAttribute => []
+        | Using as Using => chainInsideUsing(Using)
+        | Namespace => []
+        | Type(builder) => chainInsideType(builder)
+        | _ => []
+      }
+      and chainInsideUsing(Using)
+      {
+        match (Using.NameLocations.Find(_.Contains(line, column)))
+        {
+          | Some(location) => [location]  // TODO: token instead of this (or in addition)
+          | None => []
+        }
+      }
+      and chainInsideType(typeBuilder)
+      {
+        def members = typeBuilder.GetActiveMembers(fileIndex, line, column);
+        members.Map(_.Location);
+      }
+
+      def topDeclaration = GetActiveDecl(fileIndex, line, column);
+      withLineLocation(wholeFile :: topDeclaration.Location :: chainInside(topDeclaration))
+    }
+    
+    public GetEnclosingExpressionLocation(location : Location) : Location
+    {
+      def leftChain = GetChainOfEnclosingExpressions(location.FileIndex, location.Line, location.Column);
+      def rightChain = GetChainOfEnclosingExpressions(location.FileIndex, location.EndLine, location.EndColumn);
+
+      def purify(one, two)
+      {
+        def n = Math.Min(one.Length, two.Length);
+        (one.FirstN(n).RemoveDuplicates(), two.FirstN(n).RemoveDuplicates())
+      }
+      def (leftChain, rightChain) = purify(leftChain, rightChain);
+
+      def chain = List.Map2(leftChain, rightChain, (one, two) => if (one == two) one else Location.Default);
+      mutable result = chain.Head;
+      _ = chain.Find(current =>
+      {
+        if (current.StrictlyContains(location))
+        {
+          result = current;
+          false
+        }
+        else
+          true
+      });
+      if (result == Location.Default)
+        location
+      else
+        result
+    }
+  
+  }
+}
\ No newline at end of file

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	Tue Dec 19 18:52:20 2006
@@ -347,157 +347,6 @@
       }
     }
 
-    // TODO: implement get usages behaviour, this is a stub yet
-    // Ïðèìåðíîå îïèñàíèå àëãîðèòìà ïîèñêà ÷ëåíà êëàññà:
-    // 1. Íàõîäèì âñå ññûëêè íà äàííûé ÷ëåí â äåðåâå òèïîâ.
-    //    Ýòî ìîæíî ñäåëàòü ïðîñêàíèðîâàâ TypeBuilder-û.
-    //    Ïîëó÷èòü âñå TypeBuilder-û ïðîåêòà ìîæíî ñ ïîìîùüþ
-    //    ìåòîäà NamespaceTree.GetTypeBuilders().
-
-    // 1. Find all entry in type tree. It will be done by scan TypeBuilders.
-    //    Get all TypeBuilders you may by NamespaceTree.GetTypeBuilders().
-
-    // 2. Äàëåå ñêàíèðóåì ôàéëû ïûòàÿñü íàéòè âîçìîæíûå âõîæäåíèÿ èìåíè 
-    //    èñêîìîãî ÷ëåíà (òóïî èùåì ïîäñòðîêè â èñõîäíèêàõ).
-    //    Òî êàê ýòî äåëàòü ÿ èçîáðàçèë â findPossibleUsages().
-    //    Ýòîò øàã äîëæåí ñôîðìèðîâàòü ñïèñîê ëîêåøîíîâ ñãðóïèðîàííûé
-    //    ïî èíäåêñàì ôàéëîâ (äëÿ ýòîãî òóïî ïîëó÷àåì ïëîñêèé ñïèñîê è
-    //    ïîòîì ðàññîâûâàåì ëîêåøîíû ïî ãðóïïàì ñ èñïîëçîâàíèåì õýø-òàáëèöû).
-
-    // 2. Scan files for find possible usages (simple text entries).
-    //    It stem must make locations lists grouped by file index.
-
-    // 3. Ñêàíèðóåì ìåòîäû â ôàéëàõ èíäåêñû êîòîðûõ ïîëó÷åíû íà ïðåäûäóùåì øåãå,
-    //    è èùåì òå ìåòîäû êîòîðûå ïåðåñåêàþòñÿ ñ íàéäåííûìè ëîêåøîíàìè.
-    //    Åñëè åñòü ëîêåøíîû â ýòîì ìåòîäå, òî èùåì âõîæäåíèÿ â ýòîì ìåòîäå.
-    //    Êîä ïîèñêà âõîæäåíèÿ äîëæåí ñîâïàäàòü ñ êîäîì ïîèñêà ëîêàëüíîé 
-    //    ïåðåìåííîé. Òàê ÷òî èìååò ñìûñë ïîïðîáîâàòü óíèôèöèðîâàòü ýòè ìåòîäû.
-
-    // 3. Scan methods in files which contains entries (files from file 
-    //    indecis list which you make in step 2).
-    //    (It may be done by GetAllMetodsDefinedInFile(fileIndex : int) : SCG.List[MethodBuilder])
-    //    If lacations from step 2 intersect with method try find entries
-    //    in it method.
-    private FindUsages(inType : Decl.Type, fileIndex : int, line : int, column : int, onlyThisFile : bool = false) : list [GotoInfo]
-    {
-      def (declarationLocation, _, declarationObject) = FindObject(inType, fileIndex, line, column);
-      // TODO: test project 2, test case 3: incorrect location found if starting from line 98 - see why ExprFinder returns incorrect location
-      Debug.WriteLine($"Found declaration: $declarationLocation");
-
-      // TODO: for rename refactoring, we should know all usages, including generated
-      // however, this implementation neglects generated usages
-      def findPossibleUsages(name, onlyThisFile)
-      {
-        mutable entries = [];
-        def sources = _engine.ProjectSources;
-        def filesToSearchThrough =
-          if (onlyThisFile)
-            array[fileIndex]
-          else
-            _engine.Sources.GetFileIndices();
-        foreach (fileIndex in filesToSearchThrough)
-        {
-          def source = sources.GetSource(fileIndex);
-          def code = source.GetText();
-          def findEntry(startPos)
-          {
-            def position = code.OrdinalIndexOf(name, startPos);
-            unless (position < 0)
-            {
-              def (line, column) = source.GetLineIndexOfPosition(position);
-              def location = Location(fileIndex, line, column, line, column + name.Length);
-              entries ::= location;
-              findEntry(position + name.Length);
-            }
-          }
-          findEntry(0);
-        }
-        entries.Reverse()
-      }
-
-      def debug(method)
-      {
-          ignore(method);
-          #if phantom
-          Debug.WriteLine("parsed tree:");
-          when (method.BodyLocation.FileIndex > 0)
-            Debug.WriteLine(PrettyPrint.SprintExpr(None(), method.BodyParsed));
-          Debug.WriteLine("typed tree:");
-          Debug.WriteLine(PrettyPrint.SprintTyExpr(method.BodyTyped));
-          #endif
-      }
-      
-      def findInMethod(localValueDeclaration)
-      {
-        def member = inType.Builder.GetActiveMember(fileIndex, line, column);
-        Debug.WriteLine($"searching for $localValueDeclaration");
-        Debug.WriteLine($"enclosing member:\n $member");
-        match (member)
-        {
-          | method is MethodBuilder =>
-            debug(method);
-            ExprFinder().FindLocalValueEntries(method.BodyTyped, localValueDeclaration);
-          | _ => []
-        }
-      }
-
-      def makeUsage(location, declarationLocation)
-      {
-        if (location == declarationLocation)
-          GotoInfo(location, UsageType.Definition)
-        else
-          GotoInfo(location, UsageType.Usage)
-      }
-      
-      def usageIsReal(mustBeMember : IMember, usage)
-      {
-        if (usage.UsageType == UsageType.Definition)
-          true
-        else
-        {
-          Debug.WriteLine($"checking usage $usage for consistency");
-          Debug.WriteLine($"must be member:\n $mustBeMember");
-          // phantom: strange, why it doesn't catch exeption on christianity.n, any interface member?
-          try
-          {
-            match (GetActiveDecl(usage.FileIndex, usage.Line, usage.Column))
-            {
-              | ty is Decl.Type => //VladD2: don't use identifier with quote ('). It prevent match braces
-                match (ty.Builder.GetActiveMember(usage.FileIndex, usage.Line, usage.Column))
-                {
-                  | method is MethodBuilder =>
-                    debug(method);
-                    def (_, _, usageTypedExpression) = ExprFinder().Find(method.BodyParsed, method.BodyTyped, usage.Line, usage.Column);
-                    Debug.WriteLine($"Expression Finder found such an expression of a usage: $usageTypedExpression");
-                    match (usageTypedExpression)
-                    {
-                      | member is IMember => mustBeMember.GetFullName() == member.GetFullName()
-                      | _ => Debug.WriteLine("Not known IMember type! Perhaps, should be added to isReal function"); false
-                    }
-                  | _ => false
-                }
-              | _ =>  false
-            }
-          }
-          catch
-          {
-            | _ => false  // somewhere tree is not consistent
-          }
-        }
-      }
-
-      match (declarationObject)
-      {
-        | localValue is LocalValue => findInMethod(localValue)
-        | member is MemberBuilder =>
-          def declarationLocation = member.Ast.name.Location;
-          findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage(_, declarationLocation)).Filter(usageIsReal(member, _))
-        //| member is IMember =>
-          //findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage).Filter(usageIsReal(member, _));
-        | _ => [] //TODO: May be it wrong!
-      }
-    }
-
     GetMethodTip(
       typeDecl  : Decl.Type,
       fileIndex : int,

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	Tue Dec 19 18:52:20 2006
@@ -259,39 +259,6 @@
       }
     }
 
-    public GetUsages([NotNull] filePath : string, line : int, col : int) : array [GotoInfo]
-    {
-      def fileIndex = _compileUnits.GetFileIndex(filePath);
-      def decl      = GetActiveDecl(fileIndex, line, col);
-
-      match (decl)
-      {
-      | Type as ty => FindUsages(ty, fileIndex, line, col).ToArray();
-      | _          => null
-      }
-    }
-
-    public HandleIdleTime([NotNull] lexer : ScanLexer, [NotNull] filePath : string, line : int, col : int) : void
-    {
-      def fileIndex = _compileUnits.GetFileIndex(filePath);
-      def decl      = GetActiveDecl(fileIndex, line, col);
-      
-      match (decl)
-      {
-      | Type as ty => 
-        def highlights = FindUsages(ty, fileIndex, line, col, true).Map(goto =>
-        {
-          match(goto.UsageType)
-          {
-            | UsageType.Usage => (goto.Location, 0)
-            | _ => (goto.Location, 1)
-          }
-        });
-        lexer.SetHighlights(highlights);
-      | _          => ()
-      }
-    }
-
     public GetTypes(fileIndex : int) : List[TypeBuilder]
     {
       def l = List();

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n	Tue Dec 19 18:52:20 2006
@@ -411,7 +411,7 @@
       def manager = ProjectManager();
       engine = Engine(manager, null);
       manager.Engine = engine;
-      WriteLine($"Compiler is in completion mode: $(engine.IsInCompletionMode)");
+      //WriteLine($"Compiler is in completion mode: $(engine.IsInIntellisenseMode)");
 
       WriteLine(references);
       references.Iter(assembly =>

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	Tue Dec 19 18:52:20 2006
@@ -16,10 +16,25 @@
 {
   public module Utils
   {
-    InvariantCultureCompareInfo : CompareInfo 
-      = CultureInfo.InvariantCulture.CompareInfo;
+    InvariantCultureCompareInfo : CompareInfo = CultureInfo.InvariantCulture.CompareInfo;
 
-    // Returns (non-strictly) whether the first location is before the second
+    // Returns whether the first location is strictly inside the second
+    public StrictlyContains(this firstLocation : Location, secondLocation : Location) : bool
+    {
+      firstLocation.Contains(secondLocation) && firstLocation != secondLocation
+    }
+
+    // Returns whether the first location is (not strictly) inside the second
+    public Contains(this firstLocation : Location, secondLocation : Location) : bool
+    {
+      if (firstLocation.FileIndex == secondLocation.FileIndex)
+        firstLocation.Contains(secondLocation.Line, secondLocation.Column) &&
+          firstLocation.Contains(secondLocation.EndLine, secondLocation.EndColumn)
+      else
+        false
+    }
+
+    // Returns whether the first location is not strictly before the second
     public NotStrictlyBefore(this firstLocation : Location, secondLocation: Location) : bool
     {
       if (firstLocation.Line < secondLocation.Line)

Modified: vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/Guids.h
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/Guids.h	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/Guids.h	Tue Dec 19 18:52:20 2006
@@ -35,4 +35,9 @@
 
 // Guid of the command set containing the command IDs of this package
 // {EDCC3B7F-0BAD-11DB-BC1A-00112FDE8B61}
-//#define guidNemerleEditorFactory {0xEDCC3B7F, 0x0BAD, 0x11DB, {0xBC, 0x1A, 0x00, 0x11, 0x2F, 0xDE, 0x8B, 0x61} }
+#define guidNemerleEditorFactory {0xEDCC3B7F, 0x0BAD, 0x11DB, {0xBC, 0x1A, 0x00, 0x11, 0x2F, 0xDE, 0x8B, 0x61} }
+//phantom: don't know, it's needed or not
+#ifdef DEFINE_GUID
+DEFINE_GUID(CLSID_guidNemerleEditorFactory, 
+0xEDCC3B7F, 0x0BAD, 0x11DB, 0xBC, 0x1A, 0x00, 0x11, 0x2F, 0xDE, 0x8B, 0x61);
+#endif

Modified: vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmd.ctc
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmd.ctc	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmd.ctc	Tue Dec 19 18:52:20 2006
@@ -87,9 +87,6 @@
     guidNemerleProjectCmdSet:SelectionGroup,      guidNemerleProjectCmdSet:Selection,            0x600;
     guidNemerleProjectCmdSet:RefactorGroup,       guidNemerleProjectCmdSet:Refactor,             0x600;
 
-    // TODO: kill it
-    guidNemerleProjectCmdSet:TestMenuGroup,       guidSHLMainMenu:IDM_VS_MENU_TOOLS,            0x0600;
-
   NEWGROUPS_END
 
   // Button section.
@@ -111,9 +108,6 @@
     // Command ID,                                    Parent Group                          Priority,    Image,                      Type,   Visibility,                           Text
     guidNemerleProjectCmdSet:cmdidSetAsMain,       guidNemerleProjectCmdSet:CodeFileGroup,   0x100,   guidOfficeIcon:msotcidNoIcon, BUTTON, DYNAMICVISIBILITY | DEFAULTINVISIBLE, "Set as Main";
 
-    // TODO: kill it
-    guidNemerleProjectCmdSet:cmdIdTestCommand,     guidNemerleProjectCmdSet:TestMenuGroup,  0x0100,   guidOfficeIcon:msotcidNoIcon, BUTTON,                ,                      "Test (nemerle) command";
-
     guidNemerleProjectCmdSet:cmdIdExtendSelection, guidNemerleProjectCmdSet:SelectionGroup,  0x100,   guidOfficeIcon:msotcidNoIcon, BUTTON,                ,                      "&Extend";
     guidNemerleProjectCmdSet:cmdIdShrinkSelection, guidNemerleProjectCmdSet:SelectionGroup,  0x100,   guidOfficeIcon:msotcidNoIcon, BUTTON,                ,                      "&Shrink";
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmdID.h
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmdID.h	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/CtcComponents/PkgCmdID.h	Tue Dec 19 18:52:20 2006
@@ -32,8 +32,6 @@
 #define SelectionGroup       0x2102
 #define RefactorGroup        0x2103
 
-#define TestMenuGroup        0x1020
-
 /////////////////////////////////////////////////////////////////////
 // Commands
 //
@@ -47,8 +45,6 @@
 
 #define cmdIdOptions         0x3105
 
-#define cmdIdTestCommand     0x100
-
 /////////////////////////////////////////////////////////////////////
 // Bitmaps
 //

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	Tue Dec 19 18:52:20 2006
@@ -450,11 +450,7 @@
 
 		private static string SetTextSpan(ref TextSpan span, GotoInfo result)
 		{
-			span.iStartLine  = result.Location.Line - 1;
-			span.iEndLine    = result.Location.EndLine - 1;
-			span.iStartIndex = result.Location.Column - 1;
-			span.iEndIndex   = result.Location.EndColumn - 1;
-
+			Utils.CopyLocationToSpan(result.Location, ref span);
 			return result.FilePath;
 		}
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs	Tue Dec 19 18:52:20 2006
@@ -23,18 +23,50 @@
 			switch (nCmdId)
 			{
 				case 0x3001: txt = "cmdidSetAsMain"; break;
-				case 0x3101: txt = "cmdIdExtendSelection"; break;
+				case 0x3101:
+					// cmdIdExtendSelection
+					ExpandSelection();
+					break;
 				case 0x3102: txt = "cmdIdShrinkSelection"; break;
 				case 0x3103: txt = "cmdIdRename"; break;
 				case 0x3104: txt = "cmdIdInline"; break;
 				case 0x3105: txt = "cmdIdOptions"; break;
 			}
 			if (txt != null)
-				System.Diagnostics.Trace.Assert(false, "Âðîäå êàê ñðàáîòàëî âàøå ìåíþ, ñýð! ;)\r\nID: " + txt);
+			    System.Diagnostics.Trace.Assert(false, "Implement the menu!\r\nID: " + txt);
 			
 			return base.ExecCommand(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut);
 		}
 
+		private void ExpandSelection()
+		{
+			TextSpan span = GetEnclosingExpressionSpan(GetSelection());
+			TextView.SetSelection(span.iEndLine, span.iEndIndex, span.iStartLine, span.iStartIndex);
+		}
+
+		private TextSpan GetEnclosingExpressionSpan(TextSpan span)
+		{
+			NemerleSource source = Source as NemerleSource;
+			if (source != null)
+			{
+				Nemerle.Compiler.Location location = Utils.LocationFromSpan(source.FileIndex, span);
+				return Utils.SpanFromLocation(source.ProjectInfo.Project.GetEnclosingExpressionLocation(location));
+			}
+			else
+			{
+				// TODO: use GetWordExtend for files that are not NemerleSource
+				Trace.WriteLine("NemerleViewFilter.GetEnclosingExpressionSpan : no NemerleSource found!");
+				return new TextSpan();
+			}
+		}
+
+		//public override int GetWordExtent(int line, int index, uint flags, TextSpan[] span)
+		//{
+		//    //System.Diagnostics.Trace.Assert(false, "Âðîäå " + line + " aedf " + index + " flags " + flags + " sfd " + span.Length);
+		//    span[0] = GetSelection();
+		//    return 0;
+		//}
+		
 		protected override int QueryCommandStatus(ref Guid guidCmdGroup, uint nCmdId)
 		{
 			if (guidCmdGroup == VSConstants.VSStd2K && 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs	Tue Dec 19 18:52:20 2006
@@ -125,9 +125,6 @@
 				RegisterCommand(menuService, NemerleMenus.Inline, new EventHandler(OnExtendSelection));
 
 				RegisterCommand(menuService, NemerleMenus.Options, new EventHandler(OnExtendSelection));
-
-				// TODO: kill it
-				RegisterCommand(menuService, NemerleMenus.TestCommand, new EventHandler(OnExtendSelection));
 			}
 			else
 				Trace.WriteLine("Command Service is null!");

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleEditorFactory.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleEditorFactory.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleEditorFactory.cs	Tue Dec 19 18:52:20 2006
@@ -24,50 +24,6 @@
 		public NemerleEditorFactory(NemerlePackage package)
 		{
 			_package = package;
-			//registerNemerleCommands();
-		}
-
-		private void registerNemerleCommands()
-		{
-			IMenuCommandService menuService = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
-			if (menuService != null)
-			{
-				registerCommand(menuService, NemerleMenus.ExtendSelection, new EventHandler(OnExtendSelection));
-				//registerCommand(NemerleMenus.ShrinkSelection);
-
-				//registerCommand(NemerleMenus.Rename);
-				//registerCommand(NemerleMenus.Inline);
-
-				//registerCommand(NemerleMenus.Options);
-			}
-			else
-				Trace.WriteLine("Command Service is null!");
-		}
-
-		private static void registerCommand(IMenuCommandService service, CommandID commandId, EventHandler handler)
-		{
-			MenuCommand command = new MenuCommand(handler, commandId);
-			service.AddCommand(command);
-		}
-
-		private void OnExtendSelection(object sender, EventArgs e)
-		{
-			Debug.WriteLine("Extend Selection called");
-			IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
-			Guid clsid = Guid.Empty;
-			int result;
-			uiShell.ShowMessageBox(
-					   0,
-					   ref clsid,
-					   "Package Name",
-					   string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()),
-					   string.Empty,
-					   0,
-					   OLEMSGBUTTON.OLEMSGBUTTON_OK,
-					   OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
-					   OLEMSGICON.OLEMSGICON_INFO,
-					   0,        // false
-					   out result);
 		}
 
 		#endregion

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleMenus.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleMenus.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleMenus.cs	Tue Dec 19 18:52:20 2006
@@ -12,8 +12,6 @@
 
 		internal static readonly CommandID SetAsMain = new CommandID(guidNemerleProjectCmdSet, 0x3001);
 
-		internal static readonly CommandID TestCommand = new CommandID(guidNemerleProjectCmdSet, 0x100);
-
 		internal static readonly CommandID ExtendSelection = new CommandID(guidNemerleProjectCmdSet, 0x3101);
 		internal static readonly CommandID ShrinkSelection = new CommandID(guidNemerleProjectCmdSet, 0x3102);
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Utils.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Utils.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Utils.cs	Tue Dec 19 18:52:20 2006
@@ -9,10 +9,32 @@
 
 using Msbuild = Microsoft.Build.BuildEngine;
 
+using Microsoft.VisualStudio.TextManager.Interop;
+
 namespace Nemerle.VisualStudio
 {
 	static class Utils
 	{
+		public static Location LocationFromSpan(int fileIndex, TextSpan span)
+		{
+			return new Location(fileIndex, span.iStartLine + 1, span.iStartIndex + 1, span.iEndLine + 1, span.iEndIndex + 1);
+		}
+
+		public static TextSpan SpanFromLocation(Location location)
+		{
+			TextSpan span = new TextSpan();
+			CopyLocationToSpan(location, ref span);
+			return span;
+		}
+
+		public static void CopyLocationToSpan(Location location, ref TextSpan span)
+		{
+			span.iStartLine = location.Line - 1;
+			span.iEndLine = location.EndLine - 1;
+			span.iStartIndex = location.Column - 1;
+			span.iEndIndex = location.EndColumn - 1;
+		}
+
 		public static bool IsAllWhiteSpace(string str)
 		{
 			foreach (char ch in str)



More information about the svn mailing list