[svn] r7800: nemerle/trunk/ncc/parsing/MainParser.n vs-plugin/trunk/Nemerle.Compiler.Utils vs-plugin/trunk...

pbludov svnadmin at nemerle.org
Sat Sep 15 13:31:46 CEST 2007


Log:
QuickTips & Navigation for events, base types, constraints, etc.

Author: pbludov
Date: Sat Sep 15 13:31:38 2007
New Revision: 7800

Modified:
   nemerle/trunk/ncc/parsing/MainParser.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/   (props changed)
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Sat Sep 15 13:31:38 2007
@@ -1227,7 +1227,7 @@
           when (add == null || remove == null)
             Message.Error (loc, "both of event accessors `add' and 'remove' must be specified");
           
-          ClassMember.Event (loc, id, mods, ret_type, null, add, remove)
+          ClassMember.Event (loc + group.Location, id, mods, ret_type, null, add, remove)
           
         | Token.EndOfGroup =>
           // first take out event attributes (those without target also get here)

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	Sat Sep 15 13:31:38 2007
@@ -187,6 +187,7 @@
                 def typedParameter = function.parms.Nth(number);
                 (loc, parsedParameter.name, typedParameter)
               }
+            | ty is TExpr.This | ty is TExpr.Base => (loc, null, ty.MType)
             | _ => found
           }
         }
@@ -230,6 +231,16 @@
         }
       }
 
+      def checkMethods (methods)
+      {
+        | hd :: tail =>
+          if (hd != null && hd.BodyLocation.Contains(line, col))
+            getMethod(hd)
+          else
+            checkMethods(tail)
+        | []         => (Location.Default, null, null)
+      }
+
       match (member)
       {
       | mb is MethodBuilder   => getMethod(mb)
@@ -240,19 +251,7 @@
           else if (eb.Ast.name.Location.Contains(line, col))
             (eb.Ast.name.Location, null, eb)
           else
-          {
-            def adder = eb.GetAdder();
-            if (adder != null && adder.BodyLocation.Contains(line, col))
-              getMethod(adder)
-            else
-            {
-              def remover = eb.GetRemover();
-              if (remover != null && remover.BodyLocation.Contains(line, col))
-                getMethod(remover)
-              else
-               (eb.Location,          null, eb)
-            }
-          }
+            checkMethods([eb.GetAdder(), eb.GetRemover()])
 
       | fb is FieldBuilder    => 
 
@@ -286,17 +285,6 @@
             }
           else if (pb.Ast.name.Location.Contains(line, col))
             (pb.Ast.name.Location, null, pb)
-          else if ({
-              def getter = pb.GetGetter() :> MethodBuilder;
-              getter != null && getter.BodyLocation.Contains(line, col)
-            })
-            // IT: This finds an object located, but it's the 'ERROR' :xz:
-            getMethod(pb.GetGetter() :> MethodBuilder)
-          else if ({
-              def setter = pb.GetSetter() :> MethodBuilder;
-              setter != null && setter.BodyLocation.Contains(line, col)
-            })
-            getMethod(pb.GetSetter() :> MethodBuilder)
           else
           {
             def parms = pb.Ast.dims;
@@ -304,13 +292,71 @@
             match (parms.Find(p => p.ty.Location.Contains(line, col)))
             {
             | Some(p) => checkType(p.ty, pb.GetParameters().Nth(parms.IndexOf(p)))
+            | _       => checkMethods([pb.GetGetter() :> MethodBuilder, pb.GetSetter() :> MethodBuilder])
+            }
+          }
+
+      | tb is TypeBuilder     =>
+
+        match (tb.Ast)
+        {
+        | TopDeclaration.Class    (extends, _)
+        | TopDeclaration.Interface(extends, _) =>
+
+          def typarms = tb.Ast.typarms;
+
+          if (extends.OrderedContains(line, col))
+            match (extends.Find(t => t.Location.Contains(line, col)))
+            {
+            | Some(t) => checkType(t, tb.GetDirectSuperTypes().Nth(extends.IndexOf(t)))
             | _       => (Location.Default, null, null)
             }
+          else if (typarms.tyvars.OrderedContains(line, col))
+            match (typarms.tyvars.Find(t => t.Location.Contains(line, col)))
+            {
+            | Some(t) => (t.Location, null, tb.Typarms.Nth(typarms.tyvars.IndexOf(t)))
+            | _       => (Location.Default, null, null)
+            }
+          else
+          {
+            // Covarian/Contravariant constraints breaks OrderedContains optimization
+            // so process them one-by-one.
+            //
+            def isSpecialConstraint(ty)
+            {
+            | PExpr.Ref(name) =>
+              match (name.Id)
+              {
+              | "new"
+              | "class"
+              | "struct"
+              | "+"
+              | "-" => true
+              | _   => false
+              }
+            | _   => false
           }
 
-      | tb is TypeBuilder     => (tb.Location, null, tb)
-      | null                  => 
+            def constraints = typarms.constraints.RevFilter(c => !isSpecialConstraint(c.ty));
 
+            match (constraints.Find(c => c.ty.Location.Contains(line, col)))
+            {
+            | Some(c) =>
+
+              def tyVarConstraints = constraints.Filter(tc => tc.tyvar.Equals(c.tyvar));
+              def typarm = tb.Typarms.Nth(typarms.tyvars.IndexOf(c.tyvar));
+
+              Debug.Assert(tyVarConstraints.Length == typarm.Constraints.Length);
+              (c.ty.Location, null, typarm.Constraints.Nth(tyVarConstraints.IndexOf(c)))
+
+            | _       => (tb.Ast.ParsedName.Location, null, tb : object)
+            }
+          }
+        | _ => (tb.Location, null, tb)
+        }
+
+      | null                  => (Location.Default, null, null)
+/*
         def part = typeBuilder.AstParts.Find(
           p => p is TopDeclaration.Class && p.Location.FileIndex == fileIndex && p.Location.Contains(line, col));
 
@@ -334,7 +380,7 @@
 
         | _ => (Location.Default, null, null)
         }
-
+*/
       | _                     => 
         Trace.Assert(false, $"Unknown member type '$member'.");
         throw System.Exception($"Unknown member type '$member'.");
@@ -360,6 +406,7 @@
       | me is TExpr.MacroEnvelope         => (QuickTipInfo(loc, me))
       | lv is LocalValue                  => (QuickTipInfo(loc, lv))
       | mm is IMember                     => (QuickTipInfo(loc, mm, manager))
+      | st is StaticTyVar                 => (QuickTipInfo(loc, st))
       | tv is TyVar                       => (QuickTipInfo(loc, tv))
       | tc is TExpr.ImplicitValueTypeCtor => (QuickTipInfo(loc, tc.ty))
       | fh is Typedtree.Fun_header        => (QuickTipInfo(loc, fh))

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n	Sat Sep 15 13:31:38 2007
@@ -53,6 +53,12 @@
       }
     }
 
+    public this(location : Location, st : StaticTyVar)
+    {
+      SetLocation(location);
+      _text = $"(type parameter) $(st.Name): $(st.Constraints.ToString(\", \"))";
+    }
+
     public this(location : Location, fh : Typedtree.Fun_header)
     {
       match (fh.parms)

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	Sat Sep 15 13:31:38 2007
@@ -87,9 +87,10 @@
     static this()
     {
       foreach (name in 
-        ["object",  "bool", "byte",  "float", "uint",   "char", "ulong",  "ushort",
-         "decimal", "int",  "sbyte", "short", "double", "long", "string", "void",
-         "get", "set", "list"])
+        ["object", "int", "string", "void", "bool", "list",
+         "byte", "float", "uint", "char", "ulong", "ushort",
+         "decimal", "sbyte", "short", "double", "long",
+         "get", "set", "add", "remove" ])
       {
         _keywords.Add(name, name);
       }

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	Sat Sep 15 13:31:38 2007
@@ -266,7 +266,7 @@
       line             : int,
       col              : int
     )
-      : MemberBuilder
+      : IMember
     {
       def find(members : list[IMember]) 
       {
@@ -276,9 +276,10 @@
         {
         | tb is TypeBuilder     => 
 
-          def m = GetMemberByLocation(tb, fileIndex, line, col);
-
-          if (m != null) m else find(tail)
+          if (tb.Location.Contains(fileIndex, line, col))
+            GetMemberByLocation(tb, fileIndex, line, col) ?? tb;
+          else
+            find(tail)
 
         //| pb is PropertyBuilder =>
 

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	Sat Sep 15 13:31:38 2007
@@ -409,7 +409,7 @@
 
 			// TODO: implement other languages than Nemerle
 
-			if (_findExactLocation && Path.GetExtension(infos[0].FilePath) == ".n")
+			if (_findExactLocation && Path.GetExtension(infos[0].FilePath).ToLowerInvariant() == ".n")
 			{
 				try
 				{



More information about the svn mailing list