[svn] r7379: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n
Nem...
VladD2
svnadmin at nemerle.org
Mon Feb 5 01:21:13 CET 2007
Log:
Work on completion in namespace.
Author: VladD2
Date: Mon Feb 5 01:21:10 2007
New Revision: 7379
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
vs-plugin/trunk/Nemerle.VsIntegration/GUI/AstToolControl.cs
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Namespace.n Mon Feb 5 01:21:10 2007
@@ -12,15 +12,16 @@
public partial class Engine
{
internal CompleteInNamespace(
- _ns : Decl.Namespace,
- _fileIndex : int,
- _line : int,
- _col : int,
- _source : ISource
+ ns : Decl.Namespace,
+ fileIndex : int,
+ line : int,
+ col : int,
+ source : ISource
)
: array[CompletionElem]
{
- _topKeywords
+ ComplateInParsedTypeAst(ns.Location, ns.InsideEnv,
+ fileIndex, line, col, source)
}
} // end class Project
} // end 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 Mon Feb 5 01:21:10 2007
@@ -52,7 +52,7 @@
Engine.MakeCompletionList(result);
}
else // Completion outside method body.
- this.Engine.ComplateWordInMethodHeader(method.Ast, fileIndex, line, col, source);
+ this.Engine.ComplateInParsedTypeAst(method.Ast, fileIndex, line, col, source)
}
def FindCorrespondMethod()
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n Mon Feb 5 01:21:10 2007
@@ -113,38 +113,30 @@
if (bodyLocation.Contains(line, col))
this.Project.CompleteWord(fileIndex, line, col, source);
else
- ComplateWordInMethodHeader(fn, fileIndex, line, col, source)
+ ComplateInParsedTypeAst(ast, fileIndex, line, col, source)
- | cls is TopDeclaration.Class =>
- _ = cls;
-
- unless (cls.t_extends.IsEmpty)
- {
- //def expr = cls.t_extends.Head;
- def ctx = cls.ParsedName.context;
- def expr = PExpr.ToComplete(Name("ManagerCla", MacroColors.Color, ctx));
- try
- {
- _ = TyVarEnv(this).MonoBind(ctx, null, expr, false);
- }
- catch
- { | e is CompletionResult =>
- Trace.WriteLine($"NamePrefix: $(e.NamePrefix)");
- def objectType = e.ObjectType ?? "<null>" : object;
- Trace.WriteLine($" ObjectType: $objectType");
- def elems = e.Elems.ToList();
- Trace.WriteLine($" Elems: $elems");
+ | _ => ComplateInParsedTypeAst(ast, fileIndex, line, col, source)
}
}
- TopKeywords
- | _ => TopKeywords
- }
+ internal ComplateInParsedTypeAst(
+ ast : DeclarationBase,
+ fileIndex : int,
+ line : int,
+ col : int,
+ /*[NotNull]*/ source : ISource
+ )
+ : array[CompletionElem]
+ {
+ def loc = ast.Location;
+ def env = ast.ParsedName.context;
+ ComplateInParsedTypeAst(loc, env, fileIndex, line, col, source)
}
- internal ComplateWordInMethodHeader(
- /*[NotNull]*/ methodAst : ClassMember.Function,
+ internal ComplateInParsedTypeAst(
+ loc : Location,
+ env : GlobalEnv,
fileIndex : int,
line : int,
col : int,
@@ -152,12 +144,13 @@
)
: array[CompletionElem]
{
+ Trace.Assert(loc.FileIndex == fileIndex);
def tryGetTypeEnforcementExpressionTokens() : bool * list[Token]
{
// Get all tokens of method...
// Note: If method not wellformed it can take next methods
// tokens or no take body tokens.
- def lex = GetLexer(source, methodAst.header.Location);
+ def lex = GetLexer(source, loc);
def toks = lex.ReadAllTokens(); // toks is array!
// Fing near (to completion point) token index...
mutable index = toks.FindIndex(fun(x : Token)
@@ -165,19 +158,25 @@
def loc = x.Location;
loc.Contains(line, col) || loc.Line > line || loc.Line == line && loc.Column >= col
});
+
//DEBUG def (line, col) = (line, col);
+ // If last token is ":" we should unconditionally compete types.
+ if (index < 0 && toks.GetLast(null) is Token.Operator(":"))
+ (true, [])
+ else if (index < 0) // ":" not found
+ (false, [])
+ else // ":" found... process ompete...
+ {
// If last token location not on the completion point
// or completion point at the start of last token location
// we must ignore this token. Skip it...
- def lastLoc = toks[index].Location;
- when (index >= 0 && (!lastLoc.Contains(line, col)
- || lastLoc.Line == line && lastLoc.Column == col)
+ def lastToc = toks[index].Location;
+ when (!lastToc.Contains(line, col)
+ || lastToc.Line == line && lastToc.Column == col
)
index--; // Shift to the previos token location index...
- if (index >= 0)
- {
def findColonToken(i, lst) : bool * list[Token]
{ // scat tokens backward.
def tok = if (i < 0) null else toks[i];
@@ -197,28 +196,9 @@
// colon token it is not type enforcement expression.
findColonToken(index, []);
}
- else (false, [])
}
- def findMethodBuilder() : MethodBuilder // nullable
- {
- // Find TypeBuilder where defined method.
-#pragma warning disable 618 // Obsolete
- def realTb = RawProject.LookupTypeBuilder(methodAst.DefinedIn.MakeFullName());
-#pragma warning restore 618
-
- if (realTb == null)
- null //TODO: resolve this situation. Try use Project (rebuild NsTree).
- else match (
- // Find first appropriate MethodBuilder...
- realTb.GetDirectMembers().Find(mem =>
- mem.Location.FileIndex == fileIndex && mem is MethodBuilder)
- )
- {
- | Some(method is MethodBuilder) => method
- | _ => null
- }
- }
- def completeTypeEnforcement(method, typeExpr : list[Token])
+
+ def completeTypeEnforcement(env, typeExpr : list[Token])
{
// Make fake expression and type it...
//def prefix = "_ : ";
@@ -226,8 +206,7 @@
else typeExpr.Head.Location + typeExpr.Last.Location;
def typeName = if (typeExpr is []) "" else source.GetRegion(loc);
def code = /*prefix +*/ typeName;
- def result = CompleteType(method.Env, code, loc, line, col/* + prefix.Length*/);
- //def result = RunCompletionEngine(method, code, loc, line, col + prefix.Length);
+ def result = CompleteType(env, code, loc, line, col/* + prefix.Length*/);
if (result == null)
{
Trace.WriteLine("### RunCompletionEngine() (type enforcement completion) return null!");
@@ -240,12 +219,7 @@
def (ok, tokens) = tryGetTypeEnforcementExpressionTokens();
- if (ok)
- {
- def method = findMethodBuilder();
- if (method == null) TopKeywords
- else completeTypeEnforcement(method, tokens)
- }
+ if (ok) completeTypeEnforcement(env, tokens)
else TopKeywords;
}
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 Mon Feb 5 01:21:10 2007
@@ -18,6 +18,28 @@
{
InvariantCultureCompareInfo : CompareInfo = CultureInfo.InvariantCulture.CompareInfo;
+ public GetLast[T](this source : SCG.IList[T]) : T
+ {
+ source[source.Count - 1]
+ }
+
+ public GetLast[T](this source : array[T]) : T
+ {
+ source[source.Length - 1]
+ }
+
+ public GetLast[T](this source : SCG.IList[T], aDefault : T) : T
+ {
+ if (source.Count > 0) source[source.Count - 1]
+ else aDefault
+ }
+
+ public GetLast[T](this source : array[T], aDefault : T) : T
+ {
+ if (source.Length > 0) source[source.Length - 1]
+ else aDefault
+ }
+
// For debug purposes, brief output
public Brief(this output : string, maximalLength : int = 100) : string
{
Modified: vs-plugin/trunk/Nemerle.VsIntegration/GUI/AstToolControl.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/GUI/AstToolControl.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/GUI/AstToolControl.cs Mon Feb 5 01:21:10 2007
@@ -104,6 +104,9 @@
internal void ShowInfo(NemerleSource source)
{
+ if (!IsAutoUpdate)
+ return;
+
_checkCountLabel.Text = (++_checkCount).ToString();
_items.Clear();
ProjectInfo projectInfo = source.ProjectInfo;
More information about the svn
mailing list