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

IT svnadmin at nemerle.org
Wed Sep 6 04:58:09 CEST 2006


Log:
Working on "Go To Definition".

Author: IT
Date: Wed Sep  6 04:58:01 2006
New Revision: 6621

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/GotoInfo.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/CodeModel/QuickTipInfo.n
   vs-plugin/trunk/Nemerle.VsIntegration/Engine/ProjectInfo.cs
   vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Parsing/NemerleAuthoringScope.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	Wed Sep  6 04:58:01 2006
@@ -106,6 +106,9 @@
   <ItemGroup>
     <Compile Include="Nemerle.Completion2\CodeModel\ExprFinder.n" />
   </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Nemerle.Completion2\CodeModel\GotoInfo.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/GotoInfo.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/GotoInfo.n	Wed Sep  6 04:58:01 2006
@@ -0,0 +1,59 @@
+using System;
+
+using Nemerle.Utility;
+using Nemerle.Compiler;
+//using Nemerle.Imperative;
+using Nemerle.Compiler.Typedtree;
+using Nemerle.Compiler.Parsetree;
+//using Nemerle.IO;
+//using Nemerle.Compiler.Utils;
+
+namespace Nemerle.Completion2
+{
+  public class GotoInfo
+  {
+    [Accessor] mutable _filePath  : string;
+    [Accessor] mutable _lineStart : int;
+    [Accessor] mutable _lineEnd   : int;
+    [Accessor] mutable _colStart  : int;
+    [Accessor] mutable _colEnd    : int;
+
+    public this(member : IMember)
+    {
+      SetLocation(member.Location);
+    }
+
+    public this(value : LocalValue)
+    {
+      SetLocation(value.Location);
+    }
+
+    public this(tv : TyVar)
+    {
+    | MType.Class(tycon, _) => SetLocation(tycon.Location);
+    | _ => ()
+    }
+
+    public this(_fh : Typedtree.Fun_header)
+    {
+    }
+
+    public this(_mc : PExpr.MacroCall, _texpr : TExpr)
+    {
+    }
+
+    private SetLocation(location : Location) : void
+    {
+      _filePath  = location.File;
+      _lineStart = location.Line      - 1;
+      _colStart  = location.Column    - 1;
+      _lineEnd   = location.EndLine   - 1;
+      _colEnd    = location.EndColumn - 1;
+    }
+
+    public HasLocation : bool
+    {
+      get { !string.IsNullOrEmpty(_filePath) && _lineEnd >= 0 }
+    }
+  }
+}

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  6 04:58:01 2006
@@ -81,7 +81,8 @@
       fileIndex : int,
       line      : int,
       col       : int,
-      getText   : GetText) : QuickTipInfo
+      getText   : GetText)
+    : QuickTipInfo
     {
       def typeBuilder = typeDecl.Builder;
       def members     = typeBuilder.GetActiveMembers(fileIndex, line, col);
@@ -178,5 +179,109 @@
         throw System.Exception($"Unknown member type '$member'.");
       }
     }
+
+    private GetTypeGoto(
+      typeDecl  : Decl.Type,
+      fileIndex : int,
+      line      : int,
+      col       : int,
+      getText   : GetText)
+    : GotoInfo
+    {
+      def typeBuilder = typeDecl.Builder;
+      def members     = typeBuilder.GetActiveMembers(fileIndex, line, col);
+
+      def member = match (members)
+      {
+      | [m]       => m
+      | []        => null
+      | m :: tail => tail.FindWithDefault(m, (f) => f is PropertyBuilder);
+      }
+
+      match (member)
+      {
+      | method is MethodBuilder =>
+
+        def location = method.BodyLocation;
+
+        if (location.Contains(line, col)) // in method body
+        {
+          mutable bodyCode = getText(location.Line, location.Column, location.EndLine, location.EndColumn);
+
+          def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, location);
+
+          mutable ret          = null;
+          mutable findLocation = false;
+          mutable pExpr;
+          mutable pLocation;
+          mutable pObj;
+
+          when (pBody != null)
+          {
+            (pLocation, pObj) = ExprFinder().Find(pBody.expr, line, col);
+
+            match (pObj)
+            {
+            | PExpr.MacroCall as mc =>
+
+              findLocation = true;
+              pExpr        = mc;
+
+            | _ => ()
+            }
+          }
+
+          when (ret == null && tBody != null)
+          {
+            def (eLocation, obj) = ExprFinder().Find(tBody.expr, line, col, pLocation, findLocation);
+
+            def _loc = if (pLocation.Contains(line, col)) pLocation else eLocation;
+
+            if (findLocation)
+            {
+              match (pExpr)
+              {
+              | PExpr.MacroCall as mc => ret = GotoInfo(mc, obj :> TExpr)
+              | _ => ()
+              }
+            }
+            else match (obj)
+            {
+            | lv is LocalValue           => ret = GotoInfo(lv);
+            | mm is IMember              => ret = GotoInfo(mm);
+            | tv is TyVar                => ret = GotoInfo(tv);
+            | fh is Typedtree.Fun_header => ret = GotoInfo(fh);
+            | _ => ()
+            }
+          }
+
+          ret
+
+        }
+        else
+        {
+          /*
+          // Completin in AutoModule
+          if (member.DeclaringType.FullName	== _autoModule)
+          {
+            //_topKeywords;
+          }
+          else
+          {
+            //Trace.WriteLine($"# Completion outside body");
+            //array(0); // completion outside body (try conplete types)
+          }
+          */
+          null
+        }
+
+      | fb is FieldBuilder    => GotoInfo(fb)
+      | pb is PropertyBuilder => GotoInfo(pb)
+      | null => null
+      | _    =>
+        Trace.Assert(false, $"Unknown member type '$member'.");
+        throw System.Exception($"Unknown member type '$member'.");
+      }
+    }
   } // end class Project
 } // end namespace

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  6 04:58:01 2006
@@ -128,6 +128,19 @@
       }
     }
 
+    public GetGotoInfo([NotNull] filePath : string, line : int, col : int, getText : GetText) : GotoInfo
+    {
+      def fileIndex = _compileUnits.GetFileIndex(filePath);
+      def decl      = GetActiveDecl(fileIndex, line, col);
+
+      match (decl)
+      {
+      | Type  as tp => GetTypeGoto(tp, fileIndex, line, col, getText);
+      | None        => throw System.Exception()
+      | _ => null
+      }
+    }
+
     public CheckErrors([NotNull] fileName : string, addError : AddError, getText : GetText) : void
     {
       foreach (cm in _engine.CompilerMessages)

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	Wed Sep  6 04:58:01 2006
@@ -14,7 +14,6 @@
   public class QuickTipInfo
   {
     [Accessor(flags = WantSetter)] mutable _text      : string;
-
     [Accessor] mutable _lineStart : int;
     [Accessor] mutable _lineEnd   : int;
     [Accessor] mutable _colStart  : int;

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Engine/ProjectInfo.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Engine/ProjectInfo.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Engine/ProjectInfo.cs	Wed Sep  6 04:58:01 2006
@@ -275,5 +275,10 @@
 
 			return info;
 		}
+
+		public GotoInfo GetGoto(string filePath, int line, int col, GetText getText)
+		{
+			return Project.GetGotoInfo(filePath, line + 1, col + 1, getText);
+		}
 	}
 }
\ No newline at end of file

Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs	Wed Sep  6 04:58:01 2006
@@ -144,14 +144,14 @@
 				case ParseReason.CodeSpan:          break;
 				case ParseReason.CompleteWord:      return GetCompleteWord(request);
 				case ParseReason.DisplayMemberList: break;
-				case ParseReason.Goto:              break;
 				case ParseReason.HighlightBraces:   break;
 				case ParseReason.MatchBraces:       break;
 				case ParseReason.MemberSelect:      break;
 				case ParseReason.MemberSelectAndHighlightBraces: break;
 				case ParseReason.MethodTip:         break;
 				case ParseReason.None:              break;
-				case ParseReason.QuickInfo:         return GetQuickInfo(request);
+				case ParseReason.Goto:
+				case ParseReason.QuickInfo:         return GetScope(request);
 			}
 
 			NemerleSource source;
@@ -169,10 +169,9 @@
 			if (projectInfo == null)
 				return null;
 
-			projectInfo.Engine.ProcessMessages = true;
-
 			try
 			{
+				projectInfo.Engine.ProcessMessages = true;
 				projectInfo.UpdateFile(request);
 
 				Project project = projectInfo.Engine.GetProject();
@@ -209,7 +208,7 @@
 			return GetDefaultScope(request);
 		}
 
-		AuthoringScope GetQuickInfo(ParseRequest request)
+		AuthoringScope GetScope(ParseRequest request)
 		{
 			string text;
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Parsing/NemerleAuthoringScope.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Parsing/NemerleAuthoringScope.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Parsing/NemerleAuthoringScope.cs	Wed Sep  6 04:58:01 2006
@@ -75,6 +75,28 @@
 			return info.Text;
 		}
 
+		public override string Goto(
+			VSConstants.VSStd97CmdID cmd, 
+			IVsTextView textView,
+			int line, int col, out TextSpan span)
+		{
+			span = new TextSpan();
+
+			GotoInfo info = _project.GetGoto(_filePath, line, col, _getText);
+
+			ShowCompilerMessages();
+
+			if (info == null || !info.HasLocation)
+				return null;
+
+			span.iStartLine  = info.LineStart;
+			span.iEndLine    = info.LineEnd;
+			span.iStartIndex = info.ColStart;
+			span.iEndIndex   = info.ColEnd;
+
+			return info.FilePath;
+		}
+
 		public override Declarations GetDeclarations(IVsTextView view, 
 			int line, int col, TokenInfo info, ParseReason reason)
 		{
@@ -88,14 +110,6 @@
 			throw new Exception("The method or operation is not implemented.");
 		}
 
-		public override string Goto(VSConstants.VSStd97CmdID cmd, 
-			IVsTextView textView, int line, int col, out TextSpan span)
-		{
-			span = new TextSpan();
-			return "123";
-			//throw new Exception("The method or operation is not implemented.");
-		}
-
 		private void ShowCompilerMessages()
 		{
 			return;



More information about the svn mailing list