[svn] r7278: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
Nemerle.Compiler.Utils/...
VladD2
svnadmin at nemerle.org
Tue Jan 16 15:49:18 CET 2007
Log:
1. Move completion in method header on untyped AST (TopDeclaration/ClassMember variants).
2. Move using directive completion untyped AST (Decl/TopDeclaration).
3. Move some completion logic from Project to Engine class.
4. Cach TopDeclaration in top namespace of compiled unit (Decl.Namespace).
5. Move Members combo to use cached TopDeclaration if it exist.
6. Show nested classes in AstToolWindow.
7 Rename Engine.BuildTypedtreeAndInitProject() to BuildNamespaceTreeAndInitProject().
8. Add FileIndex property to ISource.
9. Add some to do.
10. Rename IsTypeTreeParsed property to IsProjectAvailable (in Engine and IsProjectAvailable classes).
11. Move overloads in Engine class into separate file.
Author: VladD2
Date: Tue Jan 16 15:49:09 2007
New Revision: 7278
Added:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-overrides.n
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.MakeCompletionList.n
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/CodeModel/Project.Using.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Debug/AstUtils.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Decl.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.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/NemerleCodeDomProvider.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
vs-plugin/trunk/Nemerle.VsIntegration/!ToDo/ToDo.txt
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs
vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.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 Tue Jan 16 15:49:09 2007
@@ -188,6 +188,12 @@
<ItemGroup>
<Compile Include="Nemerle.Completion2\Debug\AstUtils.n" />
</ItemGroup>
+ <ItemGroup>
+ <Compile Include="Nemerle.Completion2\Engine\Engine-overrides.n" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Nemerle.Completion2\Engine\Engine.Completion.Using.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.
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Checker.n Tue Jan 16 15:49:09 2007
@@ -397,7 +397,7 @@
usings.Add(us);
- | Namespace(decls, _, locations, _, _, nsloc) =>
+ | Namespace(decls, _, locations, _, _, nsloc, _) =>
ProcessRegions(decls);
@@ -486,10 +486,7 @@
def engine = _project.Engine;
def isBraceMatch()
{
- def code = _source.GetText();
- def lex = LexerString(engine, code, Location(_fileIndex, 1, 1));
- //lex.BeginParseFile();
- lex.Keywords = lex.Manager.CoreEnv.Keywords;
+ def lex = engine.GetLexer(_source);
def stack = Stack();
stack.Push(Token.EndOfFile());
def scan(toc : Token)
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n Tue Jan 16 15:49:09 2007
@@ -52,11 +52,7 @@
public FormatDocument(filePath : string) : SCG.List[FormatterResult]
{
def results = SCG.List.[FormatterResult]();
-
def declNS = this.Engine.Project.CompileUnits[filePath];
-
- //def source = ProjectManager.SimpleSourceTextManager(this.Engine.Sources[filePath]);
-
def usings = SCG.List.[Decl.Using]();
mutable usingsLocation = Location.Default;
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.MakeCompletionList.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.MakeCompletionList.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.MakeCompletionList.n Tue Jan 16 15:49:09 2007
@@ -11,7 +11,7 @@
namespace Nemerle.Completion2
{
- public partial class Project
+ public partial class Engine
{
public static MakeCompletionList(result : CompletionResult) : array[CompletionElem]
{
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 Tue Jan 16 15:49:09 2007
@@ -9,9 +9,9 @@
namespace Nemerle.Completion2
{
- public partial class Project
+ public partial class Engine
{
- CompleteInNamespace(
+ internal CompleteInNamespace(
_ns : Decl.Namespace,
_fileIndex : int,
_line : int,
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 Jan 16 15:49:09 2007
@@ -18,6 +18,8 @@
{
public partial class Project
{
+ public static TopKeywords : array[CompletionElem] { get { Engine.TopKeywords } }
+
/// Complete word inside the method.
CompleteInType(
@type : Decl.Type,
@@ -44,90 +46,13 @@
if (result == null)
{
Trace.WriteLine("### RunCompletionEngine() return null!");
- _topKeywords
+ TopKeywords
}
else
- {
- Debug.WriteLine($"# RunCompletionEngine() return $(result.ObjectType)");
- MakeCompletionList(result);
- }
+ Engine.MakeCompletionList(result);
}
else // Completion outside method body.
- {
- def tryGetTypeEnforcementExpressionTokens() : bool * list[Token]
- {
- def header = method.Ast.header;
- Debug.WriteLine($"# Completion outside body");
- // Get all tokens of method...
- // Note: If method not wellformed it can take next methods
- // tokens or no take body tokens.
- def lex = this.Engine.GetLexer(source, header.Location);
- def toks = lex.ReadAllTokens(); // toks is array!
- // Fing near (to completion point) token index...
- mutable index = toks.FindIndex(fun(x : Token)
- {
- 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 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)
- )
- index--; // Shift to the previos token location index...
-
- if (index >= 0)
- {
- def findColonToken(i, lst) : bool * list[Token]
- { // scat tokens backward.
- def tok = toks[i];
- match (tok)
- {
- | Operator(":") => (true, lst)
- | Operator(".") => findColonToken(i - 1, tok :: lst)
- | BeginBrace | BeginQuote | BeginRound | CharLiteral | EndBrace
- | EndQuote | EndRound | FloatLiteral | Operator | Semicolon | null | EndOfFile
- => (false, []) // this tokens can't contains in type
- | _ => findColonToken(i - 1, tok :: lst)
- }
- }
-
- // Get list of completion tokens. It can be situated on the interval
- // from colone token to toks[index]. If before toks[index] no
- // colon token it is not type enforcement expression.
- findColonToken(index, []);
- }
- else (false, [])
- }
-
- def completeTypeEnforcement(lst)
- {
- // Make fake expression and type it...
- def prefix = "_ : ";
- def loc = if (lst is []) Location(fileIndex, line, col, line, col)
- else lst.Head.Location + lst.Last.Location;
- def typeName = if (lst is []) "" else source.GetRegion(loc);
- def code = prefix + typeName;
- def result = _engine.RunCompletionEngine(method, code, loc, line, col + prefix.Length);
- if (result == null)
- {
- Trace.WriteLine("### RunCompletionEngine() (type enforcement completion) return null!");
- array(0)
- }
- else if ("void".StartsWithIgnoreCace(typeName) || typeName.TrimEnd() == "")
- MakeCompletionList(result).Append(CompletionElem(0, "void", "type System.Void", null));
- else MakeCompletionList(result)
- }
-
- def (ok, tokens) = tryGetTypeEnforcementExpressionTokens();
-
- if (ok) completeTypeEnforcement(tokens)
- else _topKeywords;
- }
+ this.Engine.ComplateWordInMethodHeader(method.Ast, fileIndex, line, col, source);
}
def FindCorrespondMethod(isMethodFound)
@@ -145,7 +70,7 @@
});
- match (result) { m is MethodBuilder => scanMethod(m) | _ => _topKeywords }
+ match (result) { m is MethodBuilder => scanMethod(m) | _ => TopKeywords }
}
match (member)
@@ -155,12 +80,12 @@
FindCorrespondMethod(isAccessor);
| method is MethodBuilder => scanMethod(method)
- | null => _topKeywords
+ | null => TopKeywords
| field is FieldBuilder =>
if (field.InitializerLocation.Contains(fileIndex, line, col))
scanMethod(field.LookupInitializerMethod());
else
- _topKeywords
+ TopKeywords
| _ => throw System.Exception($"Unknown member type '$member'.");
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n Tue Jan 16 15:49:09 2007
@@ -11,12 +11,12 @@
namespace Nemerle.Completion2
{
- public partial class Project
+ public partial class Engine
{
static UsingLen : int = 5;
/// Complete word inside the using directive.
- CompleteInUsing(
+ internal CompleteInUsing(
us : Decl.Using,
fileIndex : int,
line : int,
@@ -30,7 +30,7 @@
if (us.Name is []) // using directive with empty namspace name
{
if (loc.Line == line && col <= loc.Column + UsingLen)
- _topKeywords // completion on the end of "using" keyword
+ TopKeywords // completion on the end of "using" keyword
else
GetCompletionElems(us.BeforeEnv.CurrentNamespace, null, false);
}
@@ -175,7 +175,7 @@
}
}
- private GetUsingQuickTip(
+ internal GetUsingQuickTip(
usingDecl : Decl.Using,
fileIndex : int,
line : int,
@@ -223,7 +223,7 @@
}
}
- private GetUsingGoto(
+ internal GetUsingGoto(
usingDecl : Decl.Using,
fileIndex : int,
line : int,
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 Jan 16 15:49:09 2007
@@ -30,53 +30,26 @@
[Accessor] _errors : list[CompilerMessage];
public CompleteWord(
- /*[NotNull]*/ filePath : string,
+ fileIndex : int,
line : int,
col : int,
/*[NotNull]*/ source : ISource
)
: array[CompletionElem]
{
- def fileIndex = _compileUnits.GetFileIndex(filePath);
// Find the declaration under text cursor.
def decl = GetActiveDecl(fileIndex, line, col);
match (decl)
{
| GlobalAttribute => array(0)
- | Using as us => CompleteInUsing (us, fileIndex, line, col, source);
- | Namespace as ns => CompleteInNamespace(ns, fileIndex, line, col, source);
+ | Using as us => this.Engine.CompleteInUsing (us, fileIndex, line, col, source);
+ | Namespace as ns => this.Engine.CompleteInNamespace(ns, fileIndex, line, col, source);
| Type as ty => CompleteInType (ty, fileIndex, line, col, source);
| None => throw System.Exception();
}
}
- static StrsToCompletionElems(
- strs : SCG.IEnumerable[string],
- glyphType : int,
- info : string
- )
- : array[CompletionElem]
- {
- def ary = SCG.List();
-
- foreach (name when name != null in strs)
- ary.Add(CompletionElem(glyphType, name, info, null));
-
- ary.ToArray();
- }
-
- static this()
- {
- _topKeywords = StrsToCompletionElems(
- ["using", "class", "struct", "variant", "namespace", "enum", "public", "protected",
- "internal", "private", "abstract", "sealed"],
- GlyphType.Snippet :> int,
- "snippet or top level keyword");
- }
-
- static _topKeywords : array[CompletionElem];
-
static _autoModule = "_N_AutoModule";
public GetActiveNamespaces(fileIndex : int, line : int, column : int) : list[Decl.Namespace]
@@ -233,7 +206,7 @@
match (decl)
{
- | Using as us => GetUsingQuickTip(us, fileIndex, line, col)
+ | Using as us => this.Engine.GetUsingQuickTip(us, fileIndex, line, col)
| Type as tp => GetTypeQuickTip (tp, fileIndex, line, col, _engine);
| _ => null
}
@@ -246,7 +219,7 @@
match (decl)
{
- | Using as us => GetUsingGoto(us, fileIndex, line, col).ToArray();
+ | Using as us => this.Engine.GetUsingGoto(us, fileIndex, line, col).ToArray();
| Type as tp => GetTypeGoto (tp, fileIndex, line, col).ToArray();
| _ => null
}
@@ -304,15 +277,6 @@
l
}
- public GetTopDeclarations(code : string, fileIndex : int) : list[TopDeclaration]
- {
- def lex = LexerString(Engine, code, Location(fileIndex, 1, 1));
-
- lex.Keywords = lex.Manager.CoreEnv.Keywords;
-
- MainParser.Parse(lex);
- }
-
internal GetAllCompilerMessageForFile(fileIndex : int) : SCG.IEnumerable[CompilerMessage]
{
foreach (cm when cm.Location.FileIndex == fileIndex in Errors)
@@ -419,5 +383,38 @@
when (obj != null)
_ = obj.ToString();
}
+
+ /// Find TypeBuilder by it full qualified name (include outer classes)/
+ /// namespacePath - list of namespace path.
+ /// typeInfs - list of names with type parametrs count of class and it
+ /// outer classes which it nested.
+ public LookupTypeBuilder(
+ namespacePath : list[string],
+ typeInfs : list[string * int]
+ )
+ : TypeBuilder // nullable
+ {
+ def nsTree = NamespaceTree;
+ def fullName = namespacePath + [typeInfs.Head[0]];
+ def typeInfo = nsTree.LookupType(fullName, typeInfs.Head[1]);
+ match (typeInfo)
+ {
+ | Some(tb is TypeBuilder) =>
+ def nesteds = typeInfs.Tail;
+
+ if (nesteds.IsEmpty) tb
+ else nesteds.FoldRight(tb, fun((name, tArgs) : string * int, obj : TypeBuilder) : TypeBuilder
+ {
+ Trace.Assert(obj.LookupMemberAvailable);
+ match (obj.GetNestedTypes().Find(a : TypeInfo => a.Name == name && a.TyparmsCount == tArgs))
+ {
+ | Some(nestedTb is TypeBuilder) => nestedTb
+ | _ => obj
+ }
+ });
+
+ | _ => null
+ }
+ }
}
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Debug/AstUtils.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Debug/AstUtils.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Debug/AstUtils.n Tue Jan 16 15:49:09 2007
@@ -85,9 +85,10 @@
scanType(subTb, indent + " ");
//
def mems = tb.GetDirectMembers(); //GetMembers(BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Public);
- foreach (mem is MemberBuilder when mem.Location.FileIndex == fileIndex in mems)
+ foreach (mem when mem.Location.FileIndex == fileIndex in mems)
match (mem)
{
+ | tb is TypeBuilder => scanType(tb, indent + " ");
| method is MethodBuilder => scanMethod(method, indent + " ");
| field is FieldBuilder => scanField(field, indent + " ");
| prop is PropertyBuilder => scanProp(prop, indent + " ");
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Decl.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Decl.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Decl.n Tue Jan 16 15:49:09 2007
@@ -1,5 +1,6 @@
using Nemerle.Compiler;
using Nemerle.Utility;
+using Nemerle.Compiler.Parsetree;
namespace Nemerle.Completion2
{
@@ -24,6 +25,8 @@
OutsideEnv : GlobalEnv;
InsideEnv : GlobalEnv;
mutable BodyLocation : Location;
+ /// TopDeclaration-s of file. Exists only in top namespace.
+ TopDeclarations : list[TopDeclaration];
}
| Type { Builder : TypeBuilder; }
| None
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 Jan 16 15:49:09 2007
@@ -22,8 +22,19 @@
{
public event TypedtreeCreated : EventHandler;
+ public ParceTopDeclarations(source : ISource) : list[TopDeclaration]
+ {
+ if (IsProjectAvailable) // Get cached TopDeclaration-s.
+ this.Project.CompileUnits[source.FileIndex].TopDeclarations;
+ else // Perce TopDeclaration-s from source.
+ {
+ _decls = []; // reset ToDeclaration list
+ MainParser.Parse(GetLexer(source));
+ }
+ }
+
/// Makes the typed tree and constructs compile unit collection.
- private BuildTypedtreeAndInitProject() : void
+ private BuildNamespaceTreeAndInitProject() : void
{
try
{
@@ -34,7 +45,7 @@
Init();
_namespaces.Clear();
_decls = [];
-
+ _fileInfos.Clear();
// lexing of the NotParsed files
// we save the parsed files to improve performance
@@ -50,18 +61,20 @@
{
_fileIndex = fileIndex;
mutable endLoc;
+ mutable topDecls;
def source = projSources.GetSource(fileIndex);
def code = source.GetText();
BeginParseFile(fileIndex);
try
{
+ topDecls = null;
def lexer = LexerString (this, code, Location(_fileIndex, 1, 1));
- def decls = ParsingPipeline (lexer);
+ topDecls = ParsingPipeline (lexer);
regionsMap.Add(fileIndex, lexer.Regions);
endLoc = lexer.Location;
- trees ::= decls.Rev();
+ trees ::= topDecls.Rev();
}
- finally { EndParseFile(fileIndex, endLoc); }
+ finally { EndParseFile(fileIndex, endLoc, topDecls); }
}
// create N.C.TypeBuilders for all parsed types and add them to namespace hierarchy
@@ -145,71 +158,6 @@
_currentMessages = null;
}
}
-
- private ParseMethodBody(method : MethodBuilder, lexer : LexerBase) : FunBody.Parsed
- {
- def header = method.GetHeader();
- def env = if (method.Env != null) method.Env else method.DeclaringType.GlobalEnv;
- def body = FunBody.Parsed(MainParser.ParseExpr(env, lexer, method.Ast.header));
-
- header.body = body;
- body
- }
-
- protected override SetCompiletMessages (messages : SCG.List[CompilerMessage]) : void
- {
- _currentMessages = messages;
- }
-
- protected override PreParseMethodBody (method : MethodBuilder) : Token.BracesGroup
- {
- def reportError(e, msg)
- {
- Trace.WriteLine($"$msg method body of:");
- Trace.WriteLine($"\t$method");
- Trace.WriteLine($"\tfailed.");
- Trace.WriteLine($"\tError: $(e.Message)");
- }
-
- def loc = method.BodyLocation;
- def bodyCode =
- if (loc == Location.Default)
- "{}"
- else try { ProjectSources.GetSource(loc.File).GetRegion(loc); }
- catch { e => reportError(e, "Try get"); "{}" }; // return empty body!
-
- try
- {
- def lexer = LexerString(this, bodyCode, loc);
- def preparser = PreParser(lexer, method.Env);
-
- preparser.PreParse()
- }
- catch
- { e =>
- reportError(e, "Try to compile");
- Token.BracesGroup(null)
- } // return empty body!
- }
-
- /// Return true if 'method' is extension method.
- protected override IsExtensionMethod (method : IMethod, tyVar : TyVar) : bool
- {
- match (method.GetFreshType())
- {
- | (MType.Fun(from, _), _) =>
- match (from.Fix().GetFunctionArguments())
- {
- | paramMType :: _ =>
- def res = paramMType.TryProvide(tyVar);
- assert(true);
- res
-
- | _ => false
- }
- | _ => false
- }
- }
} // end class Engine
} // end namespace
Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-overrides.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-overrides.n Tue Jan 16 15:49:09 2007
@@ -0,0 +1,72 @@
+using System;
+using System.Diagnostics;
+
+using SCG = System.Collections.Generic;
+
+using Nemerle.Assertions;
+using Nemerle.Collections;
+using Nemerle.Compiler;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Imperative;
+using Nemerle.Utility;
+
+namespace Nemerle.Completion2
+{
+ public partial class Engine
+ {
+ protected override SetCompiletMessages (messages : SCG.List[CompilerMessage]) : void
+ {
+ _currentMessages = messages;
+ }
+
+ protected override PreParseMethodBody (method : MethodBuilder) : Token.BracesGroup
+ {
+ def reportError(e, msg)
+ {
+ Trace.WriteLine($"$msg method body of:");
+ Trace.WriteLine($"\t$method");
+ Trace.WriteLine($"\tfailed.");
+ Trace.WriteLine($"\tError: $(e.Message)");
+ }
+
+ def loc = method.BodyLocation;
+ def bodyCode =
+ if (loc == Location.Default)
+ "{}"
+ else try { ProjectSources.GetSource(loc.File).GetRegion(loc); }
+ catch { e => reportError(e, "Try get"); "{}" }; // return empty body!
+
+ try
+ {
+ def lexer = LexerString(this, bodyCode, loc);
+ def preparser = PreParser(lexer, method.Env);
+
+ preparser.PreParse()
+ }
+ catch
+ { e =>
+ reportError(e, "Try to compile");
+ Token.BracesGroup(null)
+ } // return empty body!
+ }
+
+ /// Return true if 'method' is extension method.
+ protected override IsExtensionMethod (method : IMethod, tyVar : TyVar) : bool
+ {
+ match (method.GetFreshType())
+ {
+ | (MType.Fun(from, _), _) =>
+ match (from.Fix().GetFunctionArguments())
+ {
+ | paramMType :: _ =>
+ def res = paramMType.TryProvide(tyVar);
+ assert(true);
+ res
+
+ | _ => false
+ }
+ | _ => false
+ }
+ }
+ }
+}
\ No newline at end of file
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 Tue Jan 16 15:49:09 2007
@@ -20,6 +20,198 @@
{
public partial class Engine
{
+ public CompleteWord(
+ /*[NotNull]*/ filePath : string,
+ line : int,
+ col : int,
+ /*[NotNull]*/ source : ISource
+ )
+ : array[CompletionElem]
+ {
+ def fileIndex = Location.GetFileIndex(filePath);
+
+ if (IsProjectAvailable)
+ this.Project.CompleteWord(fileIndex, line, col, source)
+ else
+ {
+ //// Find the declaration under text cursor.
+ //// Òàê êàê äåðåâà òèïîâ íåò, íóæíî ïîñòðîèòü Decl è TopDeclarations
+ //// äëÿ òåêóùåãî ôàéëà.
+ def topDecls = ParceTopDeclarations(source);
+ Trace.Assert(!IsProjectAvailable);
+ def decls = _decls.Rev();
+
+ def scan(decls)
+ {
+ | decl :: tail =>
+ if (decl.Location.Contains(line, col))
+ match (decl : Decl)
+ {
+ | GlobalAttribute => array(0)
+ | Using as us => CompleteInUsing (us, fileIndex, line, col, source);
+ | Namespace as ns => CompleteInNamespace(ns, fileIndex, line, col, source);
+ | Type => throw System.Exception();
+ | None => throw System.Exception();
+ }
+ else scan(tail)
+ | _ => TopKeywords
+ }
+ def scanTopDecls(topDecls : list[TopDeclaration]) : DeclarationBase
+ {
+ | topDecl :: tail =>
+ if (topDecl.Location.Contains(line, col))
+ scanTopDecl(topDecl)
+ else
+ scanTopDecls(tail)
+ | [] => null
+ }
+ and scanTopDecl (topDecl : TopDeclaration)
+ {
+ | Class(_, decls) | Enum(_, decls) | Interface(_, decls) | Variant(_, decls)
+ | VariantOption(decls) =>
+ def member = scanMembers(decls);
+ if (member != null)
+ member
+ else
+ topDecl
+
+ | Macro | Delegate | Alias => topDecl
+ }
+ and scanMembers(members) : DeclarationBase
+ {
+ | member :: tail =>
+ if (member.Location.Contains(line, col))
+ match (member)
+ {
+ | TypeDeclaration(topDeclaration) => scanTopDecl(topDeclaration)
+ | _ => member
+ }
+ else
+ scanMembers(tail)
+ | [] => null
+ }
+
+ def decl = scanTopDecls(topDecls);
+ match (decl)
+ {
+ | null => scan(decls)
+ | fn is ClassMember.Function =>
+ def bodyLocation = fn.body.CalcExclusiveBodyLocation();
+ if (bodyLocation.Contains(line, col))
+ this.Project.CompleteWord(fileIndex, line, col, source);
+ else
+ ComplateWordInMethodHeader(fn, fileIndex, line, col, source)
+
+ | _ => TopKeywords
+ }
+ }
+ }
+
+ internal ComplateWordInMethodHeader(
+ /*[NotNull]*/ methodAst : ClassMember.Function,
+ fileIndex : int,
+ line : int,
+ col : int,
+ /*[NotNull]*/ source : ISource
+ )
+ : array[CompletionElem]
+ {
+ 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 toks = lex.ReadAllTokens(); // toks is array!
+ // Fing near (to completion point) token index...
+ mutable index = toks.FindIndex(fun(x : Token)
+ {
+ 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 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)
+ )
+ index--; // Shift to the previos token location index...
+
+ if (index >= 0)
+ {
+ def findColonToken(i, lst) : bool * list[Token]
+ { // scat tokens backward.
+ def tok = toks[i];
+ match (tok)
+ {
+ | Operator(":") => (true, lst)
+ | Operator(".") => findColonToken(i - 1, tok :: lst)
+ | BeginBrace | BeginQuote | BeginRound | CharLiteral | EndBrace
+ | EndQuote | EndRound | FloatLiteral | Operator | Semicolon | null | EndOfFile
+ => (false, []) // this tokens can't contains in type
+ | _ => findColonToken(i - 1, tok :: lst)
+ }
+ }
+
+ // Get list of completion tokens. It can be situated on the interval
+ // from colone token to toks[index]. If before toks[index] no
+ // 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])
+ {
+ // Make fake expression and type it...
+ def prefix = "_ : ";
+ def loc = if (typeExpr is []) Location(fileIndex, line, col, line, col)
+ else typeExpr.Head.Location + typeExpr.Last.Location;
+ def typeName = if (typeExpr is []) "" else source.GetRegion(loc);
+ def code = prefix + typeName;
+ def result = RunCompletionEngine(method, code, loc, line, col + prefix.Length);
+ if (result == null)
+ {
+ Trace.WriteLine("### RunCompletionEngine() (type enforcement completion) return null!");
+ TopKeywords
+ }
+ else if ("void".StartsWithIgnoreCace(typeName) || typeName.TrimEnd() == "")
+ MakeCompletionList(result).Append(CompletionElem(0, "void", "type System.Void", null));
+ else MakeCompletionList(result)
+ }
+
+ def (ok, tokens) = tryGetTypeEnforcementExpressionTokens();
+
+ if (ok)
+ {
+ def method = findMethodBuilder();
+ if (method == null) TopKeywords
+ else completeTypeEnforcement(method, tokens)
+ }
+ else TopKeywords;
+ }
+
// Callback method. Process completion in expressin.
protected override Complete (
expression : PExpr,
@@ -220,10 +412,10 @@
_currentMessages = SCG.List(32);
mutable completionList = null;
-
def content = content + " ";
+ def lexer = LexerCompletion (this, content, methodBodyLocation,
+ completionMarkLine, completionMarkChar);
- def lexer = LexerCompletion (this, content, methodBodyLocation, completionMarkLine, completionMarkChar);
try
{
_ = ParseMethodBody(method, lexer);
@@ -245,6 +437,16 @@
}
}
+ private ParseMethodBody(method : MethodBuilder, lexer : LexerBase) : FunBody.Parsed
+ {
+ def header = method.GetHeader();
+ def env = if (method.Env != null) method.Env else method.DeclaringType.GlobalEnv;
+ def body = FunBody.Parsed(MainParser.ParseExpr(env, lexer, method.Ast.header));
+
+ header.body = body;
+ body
+ }
+
/// Get lexer for some range in source file.
/// The range specified by loc parametr.
// Note: All locations strat at start point of loc.
@@ -256,5 +458,16 @@
lex.Keywords = lex.Manager.CoreEnv.Keywords;
lex
}
+
+ /// Get lexer for a source.
+ public GetLexer(source : ISource) : LexerBase
+ {
+ def code = source.GetText();
+ def loc = Location(source.FileIndex, 1, 1);
+ def lex = LexerString(this, code, loc);
+ lex.BeginParseFile();
+ lex.Keywords = lex.Manager.CoreEnv.Keywords;
+ lex
+ }
} // end class Engine
} // end namespace
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.ParseEvents.n Tue Jan 16 15:49:09 2007
@@ -42,12 +42,12 @@
// HACK: see usings
public static VeryBigNumber = 1000000;
- EndParseFile(fileIndex : int, endLocation : Location) : void
+ EndParseFile(fileIndex : int, endLocation : Location, topDeclarations : list[TopDeclaration]) : void
{
def loc = Location(fileIndex, 1, 1, endLocation.EndLine, endLocation.EndColumn);
_fileInfos[fileIndex] = Decl.Namespace(loc, _decls.Rev(), [], [],
- CoreEnv, CoreEnv, loc);
+ CoreEnv, CoreEnv, loc, topDeclarations);
_decls = [];
assert(_namespaces.Count == 0);
@@ -87,7 +87,7 @@
_decls = _namespaces.Pop(); // Pop parent namespace declarations
// Create new namespace info and add it to parent namespace declarations
_decls ::= Decl.Namespace(location, currentNsDecls, name, nameLocations,
- outsideEnv, insideEnv, bodyLocation);
+ outsideEnv, insideEnv, bodyLocation, null);
}
} // end class Engine
} // end namespace
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n Tue Jan 16 15:49:09 2007
@@ -32,6 +32,35 @@
[Obsolete] mutable _rowProject : Project;
[Accessor] _projectSources : IProjectSources;
+ static StrsToCompletionElems(
+ strs : SCG.IEnumerable[string],
+ glyphType : int,
+ info : string
+ )
+ : array[CompletionElem]
+ {
+ def ary = SCG.List();
+
+ foreach (name when name != null in strs)
+ ary.Add(CompletionElem(glyphType, name, info, null));
+
+ ary.ToArray();
+ }
+
+ static this()
+ {
+ _topKeywords = StrsToCompletionElems(
+ ["using", "class", "struct", "variant", "namespace", "enum", "public", "protected",
+ "internal", "private", "abstract", "sealed", "delegate", "#if", "#region", "extern",
+ "interface", "partial", "static", "[Accessor]", "[Record]"],
+ GlyphType.Snippet :> int,
+ "snippet or top level keyword");
+
+ //"out", "ref"
+ }
+
+ [Accessor] static _topKeywords : array[CompletionElem];
+
#pragma warning disable 618 // Obsolete
public Project : Project
{
@@ -44,7 +73,7 @@
}
when (_project == null)
- BuildTypedtreeAndInitProject();
+ BuildNamespaceTreeAndInitProject();
_project;
}
@@ -58,7 +87,7 @@
if (_project == null)
{
when (_rowProject == null)
- BuildTypedtreeAndInitProject();
+ BuildNamespaceTreeAndInitProject();
_rowProject
}
@@ -68,7 +97,7 @@
}
public ResetTypeTree() : void { _project = null; }
- public IsTypeTreeParsed : bool { get { return _project != null; } }
+ public IsProjectAvailable : bool { get { return _project != null; } }
#pragma warning restore 618 // Obsolete
// If you want to recover the messages done by the parser/typer
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 Jan 16 15:49:09 2007
@@ -131,6 +131,12 @@
throw System.Exception("Tag not found.");
}
+ GetSource(filePath : string) : ISource
+ {
+ ProjectManager.SimpleSourceTextManager(
+ Location.GetFileIndex(filePath), File.ReadAllText(filePath))
+ }
+
private class TestSourceTextManager : ISource
{
public this(filePath : string)
@@ -140,6 +146,8 @@
_filePath : string;
+ public FileIndex : int { get { Location.GetFileIndex(_filePath) } }
+
public GetRegion(line : int, col : int, lineEnd : int, colEnd : int) : string
{
def line = line - 1; def col = col - 1; def lineEnd = lineEnd - 1; def colEnd = colEnd - 1;
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n Tue Jan 16 15:49:09 2007
@@ -20,7 +20,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in return type 1");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result[0].DisplayName, "Microsoft");
}
@@ -30,7 +30,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in return type 2");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 1);
Assert.AreEqual(result[0].DisplayName, "void");
@@ -41,7 +41,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in return type 3");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 1);
Assert.AreEqual(result[0].DisplayName, "int");
@@ -52,7 +52,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in return type 4");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 3);
Assert.AreEqual(result[0].DisplayName, "System.Int16");
@@ -63,7 +63,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in match variant 6");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 1);
Assert.AreEqual(result[0].ToString(), "_");
@@ -74,7 +74,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in match variant 5");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 2);
Assert.AreEqual(result[0].ToString(), "_");
@@ -86,7 +86,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in match variant 4");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 2);
Assert.AreEqual(result[0].ToString(), "_");
@@ -98,7 +98,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete 2");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 10);
}
@@ -108,7 +108,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete empty");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 10);
}
@@ -118,7 +118,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete System.Collections.Generic.List/Collections");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 1);
}
@@ -128,7 +128,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete namespace 2");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 1);
}
@@ -138,7 +138,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete expr");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(result.Length, 18);
}
@@ -148,7 +148,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "ExtensionMethod_1");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(4, result.Length, "Expected 4 elements.");
}
@@ -186,7 +186,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete enum");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(32, result.Length, "Expected 32 elements."); //VladD2: ýòîò òåñò âûäàåò ñëèøêîì ìíîãî ýëåìåíòîâ. Ïîçæå íàäî áóäåò ðàçîáðàòüñÿ.
}
@@ -196,7 +196,7 @@
{
def file = FilePath1;
def (line, _) = ReadLocation(file, $"Start block 1");
- def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+ def txtMan = GetSource(file);
def result = txtMan.GetLine(line);
@@ -209,7 +209,7 @@
{
def file = FilePath1;
def (line, _) = ReadLocation(file, $"EOF");
- def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+ def txtMan = GetSource(file);
def result = txtMan.GetLine(line);
@@ -222,7 +222,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, $"Start block 1");
- def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+ def txtMan = GetSource(file);
def pos = txtMan.GetPositionOfLineIndex(line, col);
def (line2, col2) = txtMan.GetLineIndexOfPosition(pos);
@@ -263,7 +263,7 @@
def file = FilePath1;
def (line, col) = ReadLocation(file, $"Start block $blockNum");
def (endLine, endCol) = ReadLocation(file, $"End block $blockNum");
- def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+ def txtMan = GetSource(file);
def result = txtMan.GetRegion(line, col, endLine, endCol);
def result = result.Replace("\r\n", "\n");
@@ -288,7 +288,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete glabal ns");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(2, result.Length, "Expected 2 elements.");
}
@@ -341,7 +341,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete generic type cast");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.Greater(result.Length, 0);
}
@@ -350,7 +350,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete type cast");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.Greater(result.Length, 0);
}
@@ -359,7 +359,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete namespace 1");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
}
@@ -369,7 +369,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete vars with same name");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(2, result.Length, "Expected 2 elements.");
}
@@ -379,7 +379,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in match variant 3");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
}
@@ -389,7 +389,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in match variant 2");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
}
@@ -399,7 +399,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete in match variant 1");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
}
@@ -409,7 +409,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete type escalation 3");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
}
@@ -419,7 +419,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete type escalation 2");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
}
@@ -429,7 +429,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete type escalation");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(18, result.Length, "Expected 1 elements.");
}
@@ -439,7 +439,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete qualidend");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.AreEqual(2, result.Length, "Expected 1 elements.");
}
@@ -449,7 +449,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Main() 2");
- def decl = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def decl = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(decl, "decl is null");
}
@@ -458,7 +458,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "using");
- def decl = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def decl = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(decl, "decl is null");
}
@@ -479,7 +479,7 @@
{
def file = FilePath1;
def (line, col) = ReadLocation(file, "Complete aliased type");
- def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+ def result = _engine.CompleteWord(file, line, col, TestSourceTextManager(file));
Assert.IsNotNull(result, "result is null");
Assert.Greater(result.Length, 0);
//FixMe
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 Jan 16 15:49:09 2007
@@ -5,6 +5,7 @@
{
public interface ISource
{
+ FileIndex : int { get; };
GetText() : string;
GetRegion(lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string;
GetRegion(location : Location) : 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 Jan 16 15:49:09 2007
@@ -11,7 +11,7 @@
/// Get manager of code file by file path.
public virtual GetSource(filePath : string) : ISource
{
- SimpleSourceTextManager(this.Engine.Sources[filePath])
+ SimpleSourceTextManager(Location.GetFileIndex(filePath), this.Engine.Sources[filePath])
}
/// Get manager of code file by file index.
@@ -24,6 +24,7 @@
[Record]
internal class SimpleSourceTextManager : ISource
{
+ [Accessor] _fileIndex : int;
[Accessor] _code : string;
/// !!! Coordinats is zero based!
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeDomProvider.n Tue Jan 16 15:49:09 2007
@@ -22,8 +22,7 @@
[Obsolete("Callers should not use the ICodeParser interface.")]
public override CreateParser(): ICodeParser
{
- // Obsolete
-#pragma warning disable 618
+#pragma warning disable 618 // Obsolete
def parser = provider.CreateParser();
#pragma warning restore 618
@@ -36,8 +35,7 @@
[Obsolete("Callers should not use the ICodeGenerator interface.")]
public override CreateGenerator(): ICodeGenerator
{
- // Obsolete
-#pragma warning disable 618
+#pragma warning disable 618 // Obsolete
provider.CreateGenerator();
#pragma warning restore 618
}
@@ -45,8 +43,7 @@
[Obsolete("Callers should not use the ICodeCompiler interface.")]
public override CreateCompiler(): ICodeCompiler
{
- // Obsolete
-#pragma warning disable 618
+#pragma warning disable 618 // Obsolete
provider.CreateCompiler();
#pragma warning restore 618
}
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 Jan 16 15:49:09 2007
@@ -353,5 +353,32 @@
scan(lex.GetToken()).ToArray();
}
+
+ public Clear[T](this ary : array[T]) : void
+ {
+ Array.Clear(ary, 0, ary.Length);
+ }
+
+ /// Retrieve full namespace path and names of all outer types.
+ /// list[string] - namespace path.
+ /// list[string * int]:
+ /// string - name of type
+ /// int - type parametrs count.
+ public static MakeFullName(this topDecl : TopDeclaration)
+ : list[string] * list[string * int]
+ {
+ def makeFullName(topDecl : TopDeclaration, typeInfs)
+ {
+ def typeParamCount = topDecl.typarms.tyvars.Length;
+
+ if (topDecl.DefinedIn == null)
+ (topDecl.ParsedName.context.CurrentNamespace.FullName,
+ ((topDecl.Name, typeParamCount) :: typeInfs))
+ else
+ makeFullName(topDecl.DefinedIn, (topDecl.Name, typeParamCount) :: typeInfs)
+ }
+
+ makeFullName(topDecl, [])
+ }
} // End of Utils module
} // End of namespace
\ No newline at end of file
Modified: vs-plugin/trunk/Nemerle.VsIntegration/!ToDo/ToDo.txt
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/!ToDo/ToDo.txt (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/!ToDo/ToDo.txt Tue Jan 16 15:49:09 2007
@@ -15,3 +15,22 @@
9. Íàäî ðåàëçîâàòü ïåðåõîä íà ïàðíóþ ñêîáêó ïî Ctrl+}.
10. Íàäî ðåàëèçîâàòü êîìëèò â óòî÷íåíèÿõ òèïîâ (type enforcement) â ÷ëåíàõ êëàññîâ
îòëè÷íûõ îò ìåòîäîâ (ñåé÷àñ îí ðàáîòàåò òîëüêî â íèõ).
+11. Îïðèìèçàöèÿ! Ïðè ðåäàêòèðîâàíèè âíå òåëà ìåòîäà íàäî ïîñòàðàòüñÿ íå ïåðåñîçäàâàòü
+ äåðåâî òèïîâ ïîêà â ýòîì íå âîçíèêíåò íàñóùüíîé ïîòðåáíîñòè. Âìåñòî ýòîãî íóæíî
+ ïûòàòüñÿ ïðîèçâåñòè ïàðñèíã òîëüêî òåêóùåãî ôàéëà (ïîëó÷àÿ òîëüêî Decl
+ è TopDeclaration).  ïðèíöèïå ïðàêòè÷åñêè âñå îïåðàöèè íà âíå òåëà ìåòîäîâ
+ ìîæíî îñóùåñòâëÿòü íà áàçå Decl è TopDeclaration. Ýòî óáåðåò çàâèñèìîñòü
+ ñêîðîñòè ðåäàêòèðîâàíèÿ ôàéëà îò ðàçìåðà ïðîåêòà. Äåðåâî òèïîâ ïî èäåå
+ äîëæíî ïåðåñòðàèâàòüñÿ òîëüêî íà Chack(), ïðè ïîïûòêå ïîñìîòðåòü õèíòû
+ èëè ïðîèçâåñòè êîìïëèò â òåëå ìåòîäà.
+12. Ïîñëå ïðåñòðîåíèÿ äåðåâà òèïîâ îñòàþòñÿ ñîîáùåíèÿ îá îøèáêàõ â ìåòîäàõ.
+ Ýòè îøèáêè óæå ìîãóò áûòü èñïðàâëåíû â ñëåäñòâèè òîãî, ÷òî èçìåíèëîñü äåðåâî
+ òèïîâ. Ïðîèñõîäèò ýòî ïîòîìó, ÷òî Check() âûçûâàåòñÿ òîëüêî äëÿ èçìåíåííîãî
+ ôàéëà, à ìåòîä ñ îøèáêîé íàõîäèòñÿ â äðóãîì ôàéëå. Íàäî êàê-òî ñäåëàòü
+ òåíåâîé âûçîâ Check() äëÿ âñåõ ôàéëîâ ñîäåðæàùèõ îøèáêè â ìåòîäàõ
+ ïîñëå èçìåíåíèÿ äåðåâà òèïîâ.
+13. Íàäî ðåàëèçîâàòü îòîáðàæåíèå êîìáîâ íàâèãàöèè â ôàéëàõ íå ïîäêëþ÷åííûõ ê
+ ïðîåêòó. Ïîäðîáíîñòè ñì. â OnSynchronizeDropdowns().
+14. Ïðè êîìïëèòå ñïèñêîâ íàäî ðàñïîçíîâàòü ýòî è çàìåíÿòü Nil íà [], à
+ Cons íà èìÿ ïàðàìåòðà ñ îòðåçàííûì ñóôèêñîì "s" (åñëè òàêîâîé åñòü).
+15. Ðåàëèçîâàòü êîìïëèò â ïàðìåòðàõ ëàìä è ëîêàëüíûõ ôóíêöèé.
\ No newline at end of file
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs Tue Jan 16 15:49:09 2007
@@ -97,7 +97,7 @@
{
if (_source != null && _source.ProjectInfo != null)
{
-#pragma warning disable 618
+#pragma warning disable 618 // Obsolete
Nemerle.Completion2.Project project = _source.ProjectInfo.Engine.RawProject;
#pragma warning restore 618
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleTypeAndMemberDropdownBars .cs Tue Jan 16 15:49:09 2007
@@ -39,6 +39,10 @@
ref int selectedMember)
{
if (_source.ProjectInfo == null)
+ //TODO: èñïîëüçîâàòü íåêèé ëåâûé (çàêýøèðîâàííûé) ïðîåêò äëÿ ïàðñèíãà
+ // ôàéëà íå ïîäêëþ÷åííîãî ê ïðîåêòó. Ýòî ïîçâîëèò íàì ïîêàçûâàòü
+ // êîìáû è äëÿ îòäåëüíûõ ôàéëîâ. Êýøèðîâàòü ïðîåêò íàäî, òàê êàê
+ // åãî ñîçäàíèå äîâîëüíî äîðîãàÿ îïåðàöèÿ.
return false;
bool ret = false;
@@ -49,10 +53,9 @@
List<NemerleDropDownMember> list = new List<NemerleDropDownMember>();
-#pragma warning disable 618
IEnumerable decls = AstUtils.GetAllDeclarations(
- _source.ProjectInfo.Engine.RawProject.GetTopDeclarations(_source.GetText(), _source.FileIndex));
-#pragma warning restore 618
+ _source.ProjectInfo.Engine.ParceTopDeclarations(
+ new SourceTextManager(_source)));
foreach (Tuple<string,TopDeclaration> decl in decls)
if (decl.field1.name.GetName().context != null)
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 Jan 16 15:49:09 2007
@@ -13,6 +13,8 @@
{
class SourceTextManager : ISource
{
+ public int FileIndex { get { return _source.FileIndex; } }
+
public SourceTextManager(NemerleSource source)
{
_source = source;
Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs Tue Jan 16 15:49:09 2007
@@ -285,9 +285,9 @@
return null;
}
- public bool IsTypeTreeParsed
+ public bool IsProjectAvailable
{
- get { return _engine.IsTypeTreeParsed; }
+ get { return _engine.IsProjectAvailable; }
}
public void ResetTypeTree()
@@ -303,7 +303,7 @@
{
ErrorHelper.ThrowIfPathNullOrEmpty(filePath, "filePath");
- if (!IsTypeTreeParsed || IsDocumentOpening)
+ if (!IsProjectAvailable || IsDocumentOpening)
return;
// If can't add relocation we must reparse types tree.
@@ -362,7 +362,7 @@
public CompletionElem[] CompleteWord(string filePath, int line, int col, ISource source)
{
ErrorHelper.ThrowIfPathNullOrEmpty(filePath, "filePath");
- return Project.CompleteWord(filePath, line + 1, col + 1, source);
+ return Engine.CompleteWord(filePath, line + 1, col + 1, source);
}
public QuickTipInfo GetQuickTip(string filePath, int line, int col, ISource source)
More information about the svn
mailing list