[svn] r7139: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2: CodeModel/Project.Refactoring.n C...

phantom svnadmin at nemerle.org
Fri Dec 22 21:17:39 CET 2006


Log:
Extend Selection improved.

Author: phantom
Date: Fri Dec 22 21:17:38 2006
New Revision: 7139

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n	Fri Dec 22 21:17:38 2006
@@ -12,6 +12,7 @@
 using Nemerle.Compiler.Parsetree;
 using Nemerle.Compiler.Typedtree;
 using Nemerle.Utility;
+using Nemerle.Logging;
 
 using SCG = System.Collections.Generic;
 
@@ -233,9 +234,9 @@
 
       def chainInside(topDeclaration : Decl)
       {
-        | GlobalAttribute => []
+        | GlobalAttribute => System.Diagnostics.Trace.Assert(false, "Got GlobalAttribute in a match, implement!"); []
         | Using as Using => chainInsideUsing(Using)
-        | Namespace => []
+        | Namespace => [] // could be only the top implied namespace in a file
         | Type(builder) => chainInsideType(builder)
         | _ => []
       }
@@ -256,19 +257,20 @@
       {
       | member is MethodBuilder =>
         if (member.BodyLocation.Contains(line, column))
-        {
           Analyser().GetChainOfEnclosingLocations(member.BodyTokens, line, column)
-        }
         else
         {
           Debug.WriteLine($"line: $line, column: $column, member: $(member.Location), body: $(member.BodyLocation)");
           []
         }
-      | _ => Debug.WriteLine($"// TODO: implement chainInsideMember for IMember type $(member.GetType())"); []
+        | null => []
+        | _ => Trace.Assert(false, $"// TODO: implement chainInsideMember for IMember type $(member.GetType())"); []
       }
 
       def topDeclaration = GetActiveDecl(fileIndex, line, column);
-      withLineLocation(wholeFile :: topDeclaration.Location :: chainInside(topDeclaration))
+      log(phantom, $"top declaration: $topDeclaration");
+      def namespaces = GetActiveNamespaces(fileIndex, line, column);
+      withLineLocation(wholeFile :: namespaces.Map(_.Location) + (topDeclaration.Location :: chainInside(topDeclaration)))
     }
     
     public GetEnclosingExpressionLocation(location : Location) : Location

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	Fri Dec 22 21:17:38 2006
@@ -78,6 +78,24 @@
 
     static _autoModule = "_N_AutoModule";
 
+    public GetActiveNamespaces(fileIndex : int, line : int, column : int) : list[Decl.Namespace]
+    {
+      def findNamespaces(declaration) : list[Decl.Namespace]
+      {
+        | @namespace is Decl.Namespace =>
+          def namespaces =
+            match (@namespace.Decls.Find(declaration => declaration.Location.Contains(line, column)))
+            {
+              | Some(declaration) => findNamespaces(declaration);
+              | None => [];
+            }
+          @namespace :: namespaces
+        | _ => []
+      }
+
+      findNamespaces(_compileUnits[fileIndex])
+    }
+
     /// Finds the innermost top level construction (namespace, class,
     /// using, attribute) located at fileIndex, line, and col.
     public GetActiveDecl(fileIndex : int, line : int, col : int) : Decl

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n	Fri Dec 22 21:17:38 2006
@@ -106,24 +106,21 @@
       }
     }
 
-    //AccumulateLocations(exprWalkInfo: ExprWalkInfo) : void
-    //{
-      //def node = exprWalkInfo.Node;
-      //log(phantom, $"processing node: $(node.ToString().Brief())");
-      //when (node is Located)
-      //{
-        //def node = node :> Located;
-        //log(phantom, $"(location: $(node.Location)");
-        //enclosingLocations ::= node.Location;
-      //}
-    //}
-
     AccumulateLocations(token : Token, line : int, column : int) : void
     {
       unless (token == null)
       {
         if (token.Location.Contains(line, column))
         {
+          mutable current = token;
+          mutable next = token.Next;
+          while (next != null)
+          {
+            current = current.Next;
+            next = next.Next;
+          }
+          unless (token.Next == null)
+            enclosingLocations ::= token.Location + current.Location;
           enclosingLocations ::= token.Location;
           match (token)
           {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n	Fri Dec 22 21:17:38 2006
@@ -41,10 +41,11 @@
 
     EndParseFile(fileIndex : int) : void
     {
-      def loc = Location(fileIndex, 1, 1, 1000000, 1);
+      def source = ProjectSources.GetSource(fileIndex);
+      def (lastLine, lastColumn) = source.GetLineIndexOfPosition(source.GetText().Length);
+      def wholeFile = Location(fileIndex, 1, 1, lastLine, lastColumn);
       
-      _fileInfos[fileIndex] = Decl.Namespace(loc, _decls.Rev(), [], 
-        [], CoreEnv, CoreEnv, loc);
+      _fileInfos[fileIndex] = Decl.Namespace(wholeFile, _decls.Rev(), [], [], CoreEnv, CoreEnv, wholeFile);
 
       _decls = [];
       assert(_namespaces.Count == 0);



More information about the svn mailing list