[svn] r6556: nemerle/trunk/ncc: completion/CodeCompletionEngine.n
parsing/MainParser.n typing/OverloadPoss...
VladD2
svnadmin at nemerle.org
Sat Aug 19 17:11:09 CEST 2006
Log:
1. Add type completion in type enforcement (in local value declaration).
2. Remove rudimentary classes LocalValueCompletionPossibility & NamespaceCompletionPossibility.
3. Refuctoring: extract getting of types & namespaces information into separate method Completion.AddTypesAndNamespaces().
Author: VladD2
Date: Sat Aug 19 17:11:01 2006
New Revision: 6556
Modified:
nemerle/trunk/ncc/completion/CodeCompletionEngine.n
nemerle/trunk/ncc/parsing/MainParser.n
nemerle/trunk/ncc/typing/OverloadPossibility.n
nemerle/trunk/ncc/typing/Typer.n
Modified: nemerle/trunk/ncc/completion/CodeCompletionEngine.n
==============================================================================
--- nemerle/trunk/ncc/completion/CodeCompletionEngine.n (original)
+++ nemerle/trunk/ncc/completion/CodeCompletionEngine.n Sat Aug 19 17:11:01 2006
@@ -44,6 +44,61 @@
using Typed = Nemerle.Compiler.Typedtree;
using SR = System.Reflection;
+using SCG = System.Collections.Generic;
+
+namespace Nemerle.Compiler
+{
+ public module
+ {
+ CmpOptins = System.StringComparison.InvariantCultureIgnoreCase;
+
+ /// extract information about types/namespaces and add it to 'elems' list.
+ public AddTypesAndNamespaces (
+ [NotNull] elems : SCG.List[Elem],
+ [NotNull] nss : list [NamespaceTree.Node],
+ obj : PExpr, // nullable
+ [NotNull] name : Parsetree.Name) : void
+ {
+ def prefix = name.Id;
+ def isAll = string.IsNullOrEmpty(prefix); // don't use prefix
+ // scan namespace tree node and add appropriate nodes into 'elems' list.
+ def scanAndAdd (subNode : NamespaceTree.Node)
+ {
+ when (subNode.Children != null)
+ foreach (elem when isAll || elem.Key.StartsWith(prefix, CmpOptins) in subNode.Children)
+ {
+ def name = elem.Key;
+ def node = elem.Value;
+
+ match (node.Value)
+ {
+ | No => ()
+ | MacroCall(macr) =>
+ elems.Add(Elem.Node (
+ if (macr.Keywords.IsEmpty) node.PartName else macr.Keywords.Head,
+ node));
+
+ | _ => elems.Add(Elem.Node (name, node));
+ }
+ }
+ }
+
+ if (obj is null)
+ foreach (subNode in nss)
+ scanAndAdd (subNode)
+ else match (Util.QidOfExpr (obj)) // extract list of name parts from expression
+ {
+ | Some ((nameParts, _)) =>
+ match (NamespaceTree.Node.PassTo (nss, nameParts)) // open node
+ {
+ | null => ()
+ | subNode => scanAndAdd (subNode)
+ }
+ | None => ()
+ }
+ }
+ }
+}
namespace Nemerle.Completion
{
Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n (original)
+++ nemerle/trunk/ncc/parsing/MainParser.n Sat Aug 19 17:11:01 2006
@@ -26,6 +26,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using SCG = System.Collections.Generic;
using Nemerle.Collections;
using Nemerle.Compiler.Parsetree;
using Nemerle.Assertions;
@@ -2109,6 +2110,18 @@
ty = ({ shift (); def e = parse_expr (stop | TokenStoppers.Equal);
expect_operator ("="); e })
| Token.Operator ("=") with ty = null =>
+ match (ty) // Type completion in type enforcement
+ {
+ | PExpr.ToComplete (name) with obj = null
+ | PExpr.Member (obj, Splicable.HalfId (name)) =>
+ def elems = SCG.List ();
+ def nss = Manager.CoreEnv.NameTree.NamespaceTree :: name.GetEnv(env).OpenNamespaces;
+ Completion.AddTypesAndNamespaces (elems, nss, obj, name);
+ throw CompletionResult (elems, name.Id);
+
+ | _ => ()
+ }
+
def expr =
if (ty == null) {
shift ();
Modified: nemerle/trunk/ncc/typing/OverloadPossibility.n
==============================================================================
--- nemerle/trunk/ncc/typing/OverloadPossibility.n (original)
+++ nemerle/trunk/ncc/typing/OverloadPossibility.n Sat Aug 19 17:11:01 2006
@@ -415,25 +415,5 @@
res
}
-
- }
-
- [Record]
- public class LocalValueCompletionPossibility : OverloadPossibility {
- public Value : LocalValue;
-
- public override ToString () : string { Value.ToString () }
- }
-
- [Record]
- public class NamespaceCompletionPossibility : OverloadPossibility {
- public IsAlias : bool;
- public NameOrAlias : string;
- public FullName : string;
-
- public override ToString () : string
- {
- (if (IsAlias) "alias: " else "") + $"$NameOrAlias ($FullName)"
- }
}
}
Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n (original)
+++ nemerle/trunk/ncc/typing/Typer.n Sat Aug 19 17:11:01 2006
@@ -1406,8 +1406,6 @@
| PT.PExpr.Member (obj, PT.Splicable.HalfId (name)) =>
def obj = obj; // for debug
def name = name; // for debug
- def prefix = name.Id;
- def isAll = string.IsNullOrEmpty(prefix);
def tobj = TypeExpr (obj);
def member_overloads = match (TypeMember (tobj, name, expected, for_completion = true))
{
@@ -1420,19 +1418,7 @@
if (member_overloads.IsEmpty)
{
def nss = Manager.CoreEnv.NameTree.NamespaceTree :: name.GetEnv(env).OpenNamespaces;
- match (Util.QidOfExpr (obj))
- {
- | Some ((idl, _)) =>
- match (NamespaceTree.Node.PassTo (nss, idl))
- {
- | null => ()
- | subNode =>
- when (subNode.Children != null)
- foreach (elem when isAll || elem.Key.StartsWith(prefix, CmpOptins) in subNode.Children)
- elems.Add(Elem.Node (elem.Key, elem.Value));
- }
- | None => ()
- }
+ Completion.AddTypesAndNamespaces (elems, nss, obj, name);
}
else
elems.Add(Elem.Overloads (member_overloads));
@@ -1454,26 +1440,10 @@
foreach ((name, local) when name.Id.StartsWith (prefix, CmpOptins) in local_context.GetLocals ())
elems.Add(Elem.Local (local));
- // find namespaces and types
-
- def find_namespaces (ns)
- {
- foreach ((name, node) when name.StartsWith (prefix, CmpOptins) in ns.Children.KeyValuePairs)
- match (node.Value)
- {
- | No => ()
- | MacroCall(macr) =>
- elems.Add(Elem.Node (
- if (macr.Keywords.IsEmpty) node.PartName else macr.Keywords.Head,
- node));
-
- | _ => elems.Add(Elem.Node (name, node));
- }
- }
+ // add namespaces and types
def nss = Manager.CoreEnv.NameTree.NamespaceTree :: name.GetEnv(env).OpenNamespaces;
- foreach (ns when ns.Children != null in nss)
- find_namespaces (ns);
+ Completion.AddTypesAndNamespaces (elems, nss, null, name);
throw CompletionResult (elems, prefix)
More information about the svn
mailing list