[svn] r6661: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n Ne...

VladD2 svnadmin at nemerle.org
Mon Sep 18 02:49:38 CEST 2006


Log:


Author: VladD2
Date: Mon Sep 18 02:49:35 2006
New Revision: 6661

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
   vs-plugin/trunk/Nemerle.VsIntegration/Engine/ProjectInfo.cs
   vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs
   vs-plugin/trunk/Nemerle.VsIntegration/NemerleSource.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n	Mon Sep 18 02:49:35 2006
@@ -18,6 +18,8 @@
 {
 	public partial class Project
 	{
+    public static mutable TmpLocation : Location; //TODO: Remove this field if relocation working properly
+
     /// This method add relocation information, if changes made in 
     /// methode/property accessor body or in fields initialisation expression.
     /// If relocation added this method return true. Otherwise false.
@@ -58,7 +60,12 @@
               if (loc.Contains(startLine, startChar) && loc.Contains(startLine, startChar))
               {
                 this.Engine.AddRelocation(fileIndex, newEndChar, newEndLine, oldEndChar, oldEndLine);
-                this.Engine.Output.WriteLine(loc);
+                assert(1 == 1);
+                //this.Engine.Output.WriteLine(loc);
+                def l = loc.EndLine;
+                def c = loc.EndColumn;
+                _ = l + c;
+                TmpLocation = loc;
                 true
               }
               else

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n	Mon Sep 18 02:49:35 2006
@@ -23,13 +23,13 @@
       oldEndChar : int, oldEndLine : int
     ) : void
     {
-      def a  = Math.Max(oldEndLine, newEndLine);
+      def a  = oldEndLine; //Math.Max(oldEndLine, newEndLine);
       def firstLine  = a;
       def firstChar  = if (newEndLine == oldEndLine && newEndChar > oldEndChar) newEndChar else oldEndChar;
       def lineOffset = newEndLine - oldEndLine;
       def charOffset = newEndChar - oldEndChar;
 
-      assert(firstLine == Math.Max(oldEndLine, newEndLine));
+      //assert(firstLine == Math.Max(oldEndLine, newEndLine));
 
       def relMap = Location.RelocationMaps[fileIndex];
 
@@ -47,7 +47,7 @@
         def prevLineOffset = if (index > 0) relMap[index - 1].LineOffset else 0;
 
         if (res < 0)
-          relMap.Insert(index, Relocation(firstLine, firstChar, 
+          relMap.Insert(index, Relocation(firstLine - prevLineOffset, firstChar, 
             lineOffset + prevLineOffset, charOffset));
         else
         {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n	Mon Sep 18 02:49:35 2006
@@ -181,7 +181,7 @@
       if (method.ParsedFunction != null)
       {
         def header = method.GetHeader();
-        def env    = method.Env;
+        def env    = if (method.Env != null) method.Env else method.DeclaringType.GlobalEnv;
         def body   = FunBody.Parsed(MainParser.ParseExpr(env, lexer, method.ParsedFunction.header));
 
         header.body = body;

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	Mon Sep 18 02:49:35 2006
@@ -228,7 +228,16 @@
 			get { return _project != null; }
 		}
 
-		public void ResetTypeTree() { _project = null; }
+		public void ResetTypeTree()
+		{
+			_project = null;
+
+			List<List<Relocation>> map = Location.RelocationMaps;
+			for (int i = 0; i < map.Count; i++)
+				map[i] = null;
+
+			NemerleSource.DebugClear();
+		}
 
 		public void AddRelocation(
 			string filePath,

Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs	Mon Sep 18 02:49:35 2006
@@ -28,6 +28,7 @@
 using Nemerle.Compiler.Utils;
 using Nemerle.VsIntegration;
 using System.Security.Permissions;
+using PR = Microsoft.VisualStudio.Package.ParseReason;
 
 namespace Microsoft.Samples.VisualStudio.NemerleLanguageService
 {
@@ -143,19 +144,22 @@
 
 			switch (request.Reason)
 			{
-				case ParseReason.Check:             return Check();
-				case ParseReason.MemberSelect:
-				case ParseReason.CompleteWord:      return GetCompleteWord();
-				case ParseReason.Goto:
-				case ParseReason.QuickInfo:         return GetMethodScope();
-				case ParseReason.MethodTip:         return GetMethodTip  ();
-				case ParseReason.Autos:
-				case ParseReason.CodeSpan:
-				case ParseReason.DisplayMemberList:
-				case ParseReason.HighlightBraces:
-				case ParseReason.MatchBraces:
-				case ParseReason.None:
-				case ParseReason.MemberSelectAndHighlightBraces: break;
+				case PR.Check:                          throw new NotImplementedException("Check"); //// return Check();
+				case PR.MemberSelect:
+				case PR.CompleteWord:                   return GetCompleteWord();
+				case PR.Goto:
+				case PR.QuickInfo:                      return GetMethodScope();
+				case PR.MethodTip:                      return GetMethodTip();
+
+				case PR.Autos:
+				case PR.CodeSpan:
+				case PR.DisplayMemberList:
+				case PR.HighlightBraces:
+				case PR.MatchBraces:
+				case PR.None:
+				case PR.MemberSelectAndHighlightBraces: 
+					Trace.WriteLine("Reson '" + request.Reason + "' not handled.");
+					break;
 			}
 
 			NemerleSource source;

Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerleSource.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerleSource.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerleSource.cs	Mon Sep 18 02:49:35 2006
@@ -19,6 +19,10 @@
 using Microsoft.VisualStudio.Shell.Interop;
 using Microsoft.VisualStudio;
 using Nemerle.VsIntegration;
+using Nemerle.Compiler;
+using System.Windows.Forms;
+using System.Runtime.InteropServices;
+using VsShell = Microsoft.VisualStudio.Shell.VsShellUtilities;
 
 namespace Microsoft.Samples.VisualStudio.NemerleLanguageService
 {
@@ -71,37 +75,162 @@
 					changes.iStartIndex, changes.iStartLine);
 			}
 
-			//{
-			//  Project project = projectInfo.Project;
-			//  int fileIndex = project.CompileUnits.GetFileIndex(fileName);
+			base.OnChangeLineText(lineChange, last);
 
-			//  for (int i = 0; i < lineChange.Length; i++)
-			//  {
-			//    TextLineChange changes = ConvertToLocation(lineChange[i]);
-			//    PExpr expr = project.GetActiveExpressinOrNull(fileIndex, line, col);
-			//    if (expr != null)
-			//    {
-			//      project.
-			//    }
 
-			//    int line = Math.Min(changes.iStartLine, changes.iOldEndLine);
-			//    //áđĺä int col = Math.Min(changes.iStartIndex, changes.iOldEndIndex);
-			//    Decl decl = project.GetActiveDecl(fileIndex, line, col);
-			//    Decl.Type ty = decl as Decl.Type;
-			//    if (ty == null)
-			//    {
-			//      projectInfo.ResetTypeTree();
-			//      break;
-			//    }
-			//    else
+			// Debug
+			ListBox relocs = TestForm.GetInstance(this).Relocs;
+			relocs.BeginUpdate();
+
+			try
+			{
+				relocs.Items.Clear();
+
+				List<Relocation> relocations = Location.RelocationMaps[Location.GetFileIndex(GetFilePath())];
+
+				Location loc = Project.TmpLocation;
+
+				if (!loc.Equals(Location.Default))
+					relocs.Items.Add(new Relocation(loc.Line, loc.Column,
+						loc.EndLine - loc.Line, loc.EndColumn - loc.Column));
+
+				if (relocations != null)
+					foreach (Relocation relo in relocations)
+						relocs.Items.Add(relo);
+			}
+			finally
+			{
+				relocs.EndUpdate();
+			}
+		}
+
+		internal static void DebugClear()
+		{
+			TestForm.GetInstance(null).Relocs.Items.Clear();
+		}
+
+		internal class TestForm : Form
+		{
+			public TestForm()
+			{
+				Bounds = new System.Drawing.Rectangle(858, 641, 300, 161);
+				TopMost = true;
+				Relocs.Dock = DockStyle.Fill;
+				Controls.Add(Relocs);
+				Relocs.SelectedIndexChanged += Relocs_SelectedIndexChanged;
+			}
+
+			new object GetService(Type serviceType)
+			{
+				return _source.LanguageService.Site.GetService(serviceType);
+			}
+
+			[ComImport, Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+			public interface IOleServiceProvider
+			{
+				[PreserveSig]
+				int QueryService([In] ref Guid guidService, [In] ref Guid riid, out IntPtr ppvObject);
+			}
+
+			void Relocs_SelectedIndexChanged(object sender, EventArgs e)
+			{
+				if (Relocs.SelectedItem == null)
+					return;
+
+				Relocation reloc = (Relocation)Relocs.SelectedItem;
+
+				TextSpan span = new TextSpan();
+				span.iStartLine = reloc.Line - 1;
+				span.iStartIndex = reloc.Column - 1;
+				span.iEndLine = span.iStartLine + reloc.LineOffset;
+				span.iEndIndex = span.iStartIndex + reloc.ColumnOffset;
+
+				string fileName = _source.GetFilePath();
+				IVsUIHierarchy hierarchy;
+				uint itemID;
+				IVsWindowFrame docFrame;
+				IVsTextView textView;
+				VsShell.OpenDocument(_source.LanguageService.Site, fileName, 
+					NativeMethods.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);
+
+				NativeMethods.ThrowOnFailure(docFrame.Show());
+				if (textView != null)
+				{
+					NativeMethods.ThrowOnFailure(textView.SetCaretPos(span.iStartLine, span.iStartIndex));
+					TextSpanHelper.MakePositive(ref span);
+					NativeMethods.ThrowOnFailure(textView.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
+					NativeMethods.ThrowOnFailure(textView.EnsureSpanVisible(span));
+				}
+
+
+				//IVsUIShellOpenDocument openDoc = GetService(
+				//  typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
+
+				//if (openDoc == null)
+				//  return;
+
+				//IVsWindowFrame frame;
+				//IOleServiceProvider sp;
+				//IVsUIHierarchy hier;
+				//uint itemid;
+				//Guid logView = logicalView;
+
+				//if (NativeMethods.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logView, out sp, out hier, out itemid, out frame)) || frame == null)
+				//  return;
+
+				//object docData;
+				//frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);
+
+				//VsTextBuffer buffer = docData as VsTextBuffer;
+				//if (buffer == null)
+				//{
+				//  IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
+				//  if (bufferProvider != null)
 			//    {
-			//      ty.Builder
-			//      Trace.WriteLine(decl);
-			//    }
+				//    IVsTextLines lines;
+				//    NativeMethods.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
+				//    buffer = lines as VsTextBuffer;
+				//    Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
+				//    if (buffer == null)
+				//      return;
 			//  }
 			//}
 
-			base.OnChangeLineText(lineChange, last);
+				//IVsTextManager mgr = GetService(
+				//  typeof(VsTextManagerClass)) as IVsTextManager;
+
+				//if (mgr == null)
+				//  return;
+
+				//int line = 0;
+
+				//mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, 0, line, 0);
+			}
+
+			NemerleSource _source;
+
+			public static TestForm GetInstance(NemerleSource source)
+			{
+				if (_instance == null)
+				{
+					_instance = new TestForm();
+					_instance.Show();
+				}
+				
+				_instance._source = source;
+
+				return _instance;
+			}
+
+			protected override void OnClosed(EventArgs e)
+			{
+				_instance = null;
+				base.OnClosed(e);
+			}
+
+			static TestForm _instance;
+
+			public ListBox Relocs = new ListBox();
 		}
 
 		private static TextLineChange ConvertToLocation(TextLineChange changes)
@@ -164,7 +293,7 @@
 
 				for (int i = 0, n = errors.Count; i < n; i++)
 				{
-					ErrorNode enode = (ErrorNode)errors[i];
+					ErrorNode enode = errors[i];
 					string filename = enode.Uri;
 					bool thisFile = (!string.IsNullOrEmpty(filename) && NativeMethods.IsSamePath(fname, filename));
 					TextSpan span = enode.Context;



More information about the svn mailing list