[svn] r6883: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/CompileUnitCollection.n...

VladD2 svnadmin at nemerle.org
Tue Nov 14 03:02:47 CET 2006


Log:
Refactorin and comments to phantom.

Author: VladD2
Date: Tue Nov 14 03:02:41 2006
New Revision: 6883

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/CompileUnitCollection.n
   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/Engine/Engine-main.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Init.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/SourceCollection.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IProjectManager.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ISource.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/CompileUnitCollection.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/CompileUnitCollection.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/CompileUnitCollection.n	Tue Nov 14 03:02:41 2006
@@ -15,7 +15,7 @@
     public this(
       [NotNull] engine     : Engine, 
       [NotNull] fileInfos  : array[Decl.Namespace],
-      [NotNull] regionsMap : Hashtable[string, list[Region]]
+      [NotNull] regionsMap : Hashtable[int, list[Region]]
     )
     {
       _engine     = engine;
@@ -25,16 +25,16 @@
 
     _engine     : Engine;
     _fileInfos  : array[Decl.Namespace];
-    _regionsMap : Hashtable[string, list[Region]];
+    _regionsMap : Hashtable[int, list[Region]];
 
     public GetFileIndex(filePath : string) : int
     {
       Location.GetFileIndex(filePath);
     }
 
-    public GetRegions(filePath : string) : list[Region]
+    public GetRegions(fileIndex : int) : list[Region]
     {
-      _regionsMap[filePath];
+      _regionsMap[fileIndex];
     }
 
     public Item[fileIndex : int] : Decl.Namespace

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 Nov 14 03:02:41 2006
@@ -72,6 +72,8 @@
       }
     }
 
+    //VladD2: IT, äîêóìåíòèðóé, ïîæàëóéñòà, òàêèå ìåòîäû. À òî êàê äîãàäàòüñÿ, ÷òî
+    //        òû èìåë ïîä ýòèìè "object * object".
     private FindObject(
       typeDecl  : Decl.Type,
       fileIndex : int,
@@ -272,35 +274,90 @@
       : list [GotoInfo]
     {
       def (_, _, declarationObject) = FindObject(typeDecl, fileIndex, line, col);
-      // TODO: implement other type usages finding, not only variables
-      def (declaration, _) = match (declarationObject)
+
+      // TODO: use lexer output for quick search, cache it if it is not cached yet
+      //VladD2:  ëåñ lexer. Ïîèñê ïî èñõîäíèêàì áîëåå ÷åì äîñòàòî÷åí äëÿ
+      // òîãî ÷òîáû íàéòè íóæíûå ìåòîäû.
+      def findPossibleUsages(name)
       {
-      | localValue is LocalValue => (localValue, GotoInfo(localValue))
-      | _ => (null, null)
-      }
-      if (declaration == null)
-        []
-      else
+        def entries = SCG.List();
+        def projSources = _engine.ProjectSources;
+
+        foreach (fileIndex in _engine.Sources.GetFileIndices())
       {
-        // TODO: use lexer output for quick search, cache it if it is not cached yet
-        def findPossibleUsages(declaration)
+          def source = projSources.GetSource(fileIndex); // get ISource
+          def code = source.GetText(); // get code as text
+          def findEntry(startPos)
         {
-          mutable entries = [];
-          foreach ((path, code) in _engine.Sources._sources.KeyValuePairs)
+            def pos = code.OrdinalIndexOf(name, startPos);
+            when (pos >= 0) // we found entry...
           {
-            Debug.WriteLine(path);
-            def position = code.IndexOf(declaration.Name);
-            unless (position < 0)
-              entries ::= Location(path, 10, 1, 12, 2);
+              def (line, ch) = source.GetLineIndexOfPosition(pos);
+              def loc = Location(fileIndex, line, ch, line, ch + name.Length);
+              entries.Add(loc);
+              Debug.WriteLine($"\t$(loc.File)($(loc.Line),$(loc.Column)): ...");
+              findEntry(pos + name.Length); // try again...
+            }
+          }
+
+          Debug.WriteLine($"Try finde name '$name'");
+
+          findEntry(0); // find from start of file
+
+          Debug.WriteLine($"End: Try finde name '$name'");
           }
+
           entries
         }
+
         // TODO: check the symbol found
-        def onlyRightUsages(_)
+      def isRealUsages(_)
         {
           true
         }
-        findPossibleUsages(declaration).Filter(onlyRightUsages).Map(GotoInfo(_));
+
+      // TODO: implement other type usages finding, not only variables
+      match (declarationObject)
+      {
+        | localValue is LocalValue => // try find only on method body!
+          [GotoInfo(localValue)] //TODO: find entry of local value
+
+        | member is IMember => 
+          // Ïðèìåðíîå îïèñàíèå àëãîðèòìà ïîèñêà ÷ëåíà êëàññà:
+          // 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.
+
+          // Èç âûøå ñêàçàííîãî ÿñíî, ÷òî äàííûé êîä íå âåðíûé, òàê íî ïîêà õîòü òàê...
+          $[GotoInfo(x) | x in findPossibleUsages(member.Name), isRealUsages(x)]
+
+        | _ => [] //TODO: May be it wrong!
       }
     }
 

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 Nov 14 03:02:41 2006
@@ -146,8 +146,8 @@
 
       match (decl)
       {
-      | Type as type' => FindUsages(type', fileIndex, line, col).ToArray();
-      | None => throw System.Exception()
+      | Type as ty => FindUsages(ty, fileIndex, line, col).ToArray();
+      | None       => throw System.Exception() //VladD2: Êàòåãîðè÷åñêè íå íàäî òàê äåëàòü!
       | _ => null
       }
     }
@@ -429,7 +429,7 @@
         }
 
         //TODO: Ðåãèîíû ïîêà íå ðåëîêåéòÿòñÿ. Òàê ÷òî ïðè çìåíåíèè èñõîäíèêîâ îíè äîëæíû âðàòü.
-        def regions = CompileUnits.GetRegions(fileName);
+        def regions = CompileUnits.GetRegions(fileIndex);
 
         foreach (r in regions)
         {

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	Tue Nov 14 03:02:41 2006
@@ -41,18 +41,22 @@
         mutable trees = [];
         def regionsMap = Hashtable();
 
-        foreach ((filePath, code) in Sources._sources.KeyValuePairs)
+        def projSources = ProjectSources;
+
+        foreach (fileIndex in Sources.GetFileIndices())
         {
-          _fileIndex = Location.GetFileIndex(filePath);
-          BeginParseFile(_fileIndex);
+          _fileIndex = fileIndex;
+          def source = projSources.GetSource(fileIndex);
+          def code = source.GetText();
+          BeginParseFile(fileIndex);
           try
           {
             def lexer = LexerString (this, code, Location(_fileIndex, 1, 1));
             def decls = ParsingPipeline (lexer);
-            regionsMap.Add(filePath, lexer.Regions);
-            trees ::= decls;
+            regionsMap.Add(fileIndex, lexer.Regions);
+            trees ::= decls.Rev();
           }
-          finally { EndParseFile(_fileIndex); }
+          finally { EndParseFile(fileIndex); }
         }
          
         // create N.C.TypeBuilders for all parsed types and add them to namespace hierarchy
@@ -136,8 +140,6 @@
       requires completionPosition <= content.Length
     {
       _currentMessages = SCG.List(32);
-      // Tell the methods we are in completion mode
-      _isInCompletionMode = true;
 
       def content =
         if (completionPosition == 0 

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Init.n
==============================================================================

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/SourceCollection.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/SourceCollection.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/SourceCollection.n	Tue Nov 14 03:02:41 2006
@@ -7,6 +7,7 @@
 
 using Typed = Nemerle.Compiler.Typedtree;
 using SR = System.Reflection;
+using SCG = System.Collections.Generic;
 
 namespace Nemerle.Completion2
 {
@@ -22,19 +23,30 @@
         _sources = Hashtable();
       }
       
-      internal mutable _sources : Hashtable[string, string];
+      private mutable _sources     : Hashtable[string, string];
+      private         _fileIndices : SCG.List[int] = SCG.List();
+
+      public GetFileIndices() : array[int]
+      {
+        _fileIndices.ToArray();
+      }
 
       public AddOrUpdate (file : string, content : string) : void
       {
         when (!ContainsKey(file))
+        {
+          _fileIndices.Add(Location.GetFileIndex(file));
           _engine.ResetTypeTree();
+        }
 
         _sources[file] = content;
       }
       
       public Remove (file : string) : void
       {
-        _sources.Remove (file);
+        def ok = _fileIndices.Remove(Location.GetFileIndex(file));
+        assert(ok);
+        _sources.Remove(file);
         _engine.ResetTypeTree();
       }
 

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	Tue Nov 14 03:02:41 2006
@@ -148,6 +148,8 @@
         builder.ToString();
       }
 
+      public GetText() : string { File.ReadAllText(_filePath) }
+
       public GetRegion(loc : Location) : string
       {
         GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn)

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IProjectManager.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IProjectManager.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IProjectManager.n	Tue Nov 14 03:02:41 2006
@@ -5,6 +5,9 @@
 {
   public interface IProjectSources
   {
-    GetSource(filePath : string) : ISource
+    /// Get manager of code file by file path.
+    GetSource(filePath : string) : ISource;
+    /// Get manager of code file by file index.
+    GetSource(fileIndex : int) : ISource;
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ISource.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ISource.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ISource.n	Tue Nov 14 03:02:41 2006
@@ -5,6 +5,7 @@
 {
   public interface ISource
   {
+    GetText() : string;
     GetRegion(lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string;
     GetRegion(location : Location) : string;
     GetLine(line : int) : string;

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n	Tue Nov 14 03:02:41 2006
@@ -8,12 +8,19 @@
   {
     [Accessor (flags = WantSetter)] mutable _engine : Engine;
 
-    /// Get manager of code file.
+    /// Get manager of code file by file path.
     public virtual GetSource(filePath : string) : ISource
     {
       SimpleSourceTextManager(this.Engine.Sources[filePath])
     }
 
+    /// Get manager of code file by file index.
+    public GetSource(fileIndex : int) : ISource
+    {
+      def filePath = Location.GetFileName(fileIndex);
+      GetSource(filePath)
+    }
+
     [Record]
     internal class SimpleSourceTextManager : ISource
     {
@@ -75,6 +82,12 @@
         result
       }
 
+      public GetText() : string
+      {
+        System.Diagnostics.Trace.Assert(_code != null, "_code is null!");
+        _code
+      }
+
       /// Return string corresponding to given coordinates.
       /// Coordinats is 1 based.
       public GetRegion(lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string

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 Nov 14 03:02:41 2006
@@ -5,8 +5,8 @@
 using Nemerle.Completion2;
 using Nemerle.Imperative;
 using System;
+using System.Globalization;
 using Nemerle.Utility;
-
 using Nemerle.Compiler.Parsetree;
 using TExpr = Nemerle.Compiler.Typedtree.TExpr;
 using SCG   = System.Collections.Generic;
@@ -15,6 +15,16 @@
 {
   public module Utils
   {
+    InvariantCultureCompareInfo : CompareInfo 
+      = CultureInfo.InvariantCulture.CompareInfo;
+
+    /// Fast find index of substing.
+    public OrdinalIndexOf(this source : string, value : string, startIndex : int) : int
+    {
+      InvariantCultureCompareInfo.IndexOf(source, value, 
+        startIndex, CompareOptions.Ordinal);
+    }
+
     public GetParsedBody(this /*[NotNull]*/ method : MethodBuilder) : PExpr
     {
       //VladD2: Ìíå ýòî ñîâñåì íå íðàâèòñÿ. Íå íàäî çàìçûâàòü îøèáêè. Åñëè îíè åñòü èõ íóæíî èñïðàâëÿòü.

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 Nov 14 03:02:41 2006
@@ -98,9 +98,8 @@
 					info = _project.GetUsages(_filePath, line, col, _sourceText);
 					break;
 				default:
-					// phantom: don't know what other command ids possible,
-					// let it be goto declaration by default
-					info = _project.GetGoto(_filePath, line, col, _sourceText);
+					System.Diagnostics.Trace.Assert(false, "Unknown cmd (" + cmd + ")");
+					info = null;
 					break;
 			}
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
==============================================================================

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs	Tue Nov 14 03:02:41 2006
@@ -29,6 +29,11 @@
 			get { return _source; }
 		}
 
+		public string GetText()
+		{
+			return Source.GetText();
+		}
+
 		public string GetRegion(int lineStart, int colStart, int lineEnd, int colEnd)
 		{
 			return Source.GetText(lineStart - 1, colStart - 1, lineEnd - 1, colEnd - 1);



More information about the svn mailing list