[svn] r6658: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
Nemerle.Co...
IT
svnadmin at nemerle.org
Sun Sep 17 08:01:50 CEST 2006
Log:
Working on the method parameter tips.
Author: IT
Date: Sun Sep 17 08:01:42 2006
New Revision: 6658
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/MethodTipInfo.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.VsIntegration/Engine/ProjectInfo.cs
vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs
vs-plugin/trunk/Nemerle.VsIntegration/NemerleMethods.cs
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n Sun Sep 17 08:01:42 2006
@@ -21,7 +21,7 @@
mutable _pexprLocation : Location;
mutable _findLocation : bool;
- //#region Find PExpr
+ #region Find PExpr
DoSyntaxElement(syntaxElement : SyntaxElement) : void
{
@@ -237,9 +237,9 @@
(_retLocation, _retObject)
}
- //#endregion
+ #endregion
- //#region Find TExpr
+ #region Find TExpr
DoPattern(pattern : Pattern) : void
{
@@ -550,9 +550,63 @@
(_retLocation, _retObject)
}
- //#endregion
+ #endregion
+
+ #region Find Token
+
+ Go(token : Token, stack : list[Token]) : list[Token]
+ {
+ when (_stop || token == null)
+ return stack;
+
+ Print(token, token.Location);
+ _counter++;
+
+ mutable newStack = match (token)
+ {
+ | RoundGroup (child) // { Child : Token; } // ( ... )
+ | BracesGroup(child) // { Child : Token; } // { ... }
+ | SquareGroup(child) // { mutable Child : Token; } // [ ... ]
+ | QuoteGroup (child) // { Child : Token; } // <[ ... ]>
+ | LooseGroup (child) // { mutable Child : Token; } // ; ... ;
+ | Namespace(_,child) => // { Env : GlobalEnv; Body : Token; }
+
+ Go(child, token :: stack);
- //#region Helpers
+ | _ =>
+
+ stack
+
+ }
+
+ _counter--;
+
+ unless (_stop)
+ {
+ _stop = IsIn(token.Location);
+
+ unless (_stop)
+ newStack = Go(token.Next, newStack);
+ }
+
+ if (_stop) (newStack) else (stack);
+ }
+
+ public Find(
+ root : Token,
+ line : int,
+ col : int
+ )
+ : list[Token]
+ {
+ Init(root.Location, line, col);
+
+ (Go(root, []));
+ }
+
+ #endregion
+
+ #region Helpers
Init(rootLocation : Location, line : int, col : int) : void
{
@@ -636,22 +690,27 @@
Print(ex : Located) : void
{
+ Print(ex, ex.Location);
+ }
+
+ Print(obj : object, loc : Location) : void
+ {
#if PRINT_AST
mutable s = "";
for (mutable i = 0; i < _counter; i++)
s += " ";
- Trace.WriteLine(s + $"$(ex.GetType().FullName) $(ex.loc.Line):$(ex.loc.Column):"
- "$(ex.loc.EndLine):$(ex.loc.EndColumn) "
+ Trace.WriteLine(s + $"$(obj.GetType().FullName) $(loc.Line):$(loc.Column):"
+ "$(loc.EndLine):$(loc.EndColumn) "
"cur:$(_curLocation.Line):$(_curLocation.Column):"
"$(_curLocation.EndLine):$(_curLocation.EndColumn) "
"$_line:$_col.");
- Trace.WriteLine(s + ex.ToString().Replace("\n", "\n" + s));
+ Trace.WriteLine(s + obj.ToString().Replace("\n", "\n" + s));
Trace.WriteLine("");
#endif
- ignore(ex);
+ ignore(obj);
}
//#endregion
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/MethodTipInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/MethodTipInfo.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/MethodTipInfo.n Sun Sep 17 08:01:42 2006
@@ -1,8 +1,100 @@
using System;
+using System.Collections.Generic;
+
+using Nemerle.Assertions;
+using Nemerle.Compiler;
+using Nemerle.Utility;
namespace Nemerle.Completion2
{
public class MethodTipInfo
{
+ public this([NotNull] methods : List[IMethod], tokens : list[Token])
+ {
+ _methods = methods;
+ _tokens = tokens;
+ }
+
+ _methods : List[IMethod];
+ _tokens : list[Token];
+
+ public GetCount() : int
+ {
+ _methods.Count
+ }
+
+ public GetDescription(index : int) : string
+ {
+ def member = _methods[index];
+ def xml = XmlDocReader.GetInfo(member, member.Location);
+
+ if (xml != null) xml.Summary else "";
+ }
+
+ public GetType(index : int) : string
+ {
+ ": " + _methods[index].ReturnType.ToString()
+ }
+
+ public GetParameterCount(index : int) : int
+ {
+ _methods[index].GetParameters().Length
+ }
+
+ public GetParameterInfo(index : int, parameter : int) : string * string * string
+ {
+ def member = _methods[index];
+ def parm = member.GetParameters().Nth(parameter);
+ def xml = XmlDocReader.GetInfo(member, member.Location);
+ def description = if (xml != null)
+ {
+ match (xml.Params.Find((name, _) => name == parm.name))
+ {
+ | Some((_, text)) => text
+ | _ => ""
+ }
+ }
+ else
+ "";
+
+ (parm.Name, $"$(parm.name) : $(parm.ty)", description)
+ }
+
+ public GetName(index : int) : string
+ {
+ _methods[index].Name;
+ }
+
+ public GetMethodLocation() : Location
+ {
+ def memberName = GetName(0);
+
+ def findIdentifier(token : Token)
+ {
+ | Identifier(name) when name == memberName && token.Next == null => token
+ | Identifier(name) when name == memberName =>
+
+ def t = findIdentifier(token.Next);
+ if (t == null) token else t
+
+ | LooseGroup(child) => findIdentifier(child)
+ | _ when token.Next != null => findIdentifier(token.Next);
+ | _ => null
+ }
+
+ def findBeforeRoundGroup(tokens)
+ {
+ | h :: t => if (h is Token.RoundGroup) t else findBeforeRoundGroup(t)
+ | _ => []
+ }
+
+ def token = match (findBeforeRoundGroup(_tokens))
+ {
+ | t :: _ => findIdentifier(t)
+ | _ => null
+ }
+
+ if (token == null) Location() else token.Location
+ }
}
}
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 Sun Sep 17 08:01:42 2006
@@ -1,16 +1,16 @@
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using Nemerle.Assertions;
using Nemerle.Compiler;
+using Nemerle.Compiler.Utils;
using Nemerle.Compiler.Parsetree;
using Nemerle.Compiler.Typedtree;
using Nemerle.Utility;
using SCG = System.Collections.Generic;
-using Nemerle.Compiler.Utils;
-
namespace Nemerle.Completion2
{
public partial class Project
@@ -204,7 +204,7 @@
col : int,
getText : GetText
)
- : list[MethodTipInfo]
+ : MethodTipInfo
{
def typeBuilder = typeDecl.Builder;
def member = typeBuilder.GetActiveMember(fileIndex, line, col);
@@ -212,33 +212,53 @@
match (member)
{
| method is MethodBuilder =>
+
def loc = method.BodyLocation;
if (loc.Contains(line, col)) // completion in method body
{
def bodyCode = getText(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
- def completionCode = getText(loc.Line, loc.Column, line, col);
+ def groups = _engine.PreParse(bodyCode, loc);
+ def tokens = ExprFinder().Find(groups, line, col);
- def pos = completionCode.LastIndexOf('(');
-
- if (pos > 0)
+ match (tokens.Find(t => t is Token.RoundGroup))
{
- // This primitive step back should be replaced with something more intelligent
- // handling brackets and, strings like "".Substring("".Substring(0).Length)
- //
- def code = completionCode.Substring(0, pos).TrimEnd(' ', '\t', '\r', '\n');
+ | Some(group) =>
+
+ def completionCode = getText(loc.Line, loc.Column, group.Location.Line, group.Location.Column);
+ def code = completionCode.TrimEnd(' ', '\t', '\r', '\n');
def result = _engine.RunCompletionEngine(method, bodyCode, code.Length);
if (result != null)
{
- ([])
+ def members = List();
+
+ foreach (elem in result.Elems)
+ {
+ | Overloads(values) =>
+
+ foreach (overload in values)
+ {
+ match (overload.Member)
+ {
+ | m is IMethod => members.Add(m);
+ | _ => ()
}
- else ([])
}
- else ([])
+
+ | _ => ()
+ }
+
+ if (members.Count > 0) MethodTipInfo(members, tokens) else (null)
}
- else ([])
- | null => ([])
+ else (null)
+
+ | None => (null)
+ }
+ }
+ else (null)
+
+ | null => (null)
| _ => throw System.Exception($"Unknown member type '$member'.");
}
}
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 Sun Sep 17 08:01:42 2006
@@ -170,7 +170,7 @@
}
}
- public GetMethodTip([NotNull] filePath : string, line : int, col : int, getText : GetText) : list[MethodTipInfo]
+ public GetMethodTip([NotNull] filePath : string, line : int, col : int, getText : GetText) : MethodTipInfo
{
def fileIndex = _compileUnits.GetFileIndex(filePath);
def decl = GetActiveDecl(fileIndex, line, col);
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 Sun Sep 17 08:01:42 2006
@@ -216,6 +216,15 @@
else
(pBody, null, null)
}
+
+ public PreParse([NotNull] content : string, location : Location) : Token.BracesGroup
+ {
+ def lexer = LexerString(this, content, location);
+ def preparser = PreParser(lexer);
+
+ preparser.PreParse();
+ }
+
} // end class Engine
} // end namespace
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 Sun Sep 17 08:01:42 2006
@@ -15,6 +15,7 @@
using Nemerle.Compiler.Utils;
using Utils = Nemerle.VsIntegration.Project.Utils;
using Microsoft.VisualStudio;
+using Nemerle.VsIntegration;
namespace Microsoft.Samples.VisualStudio.NemerleLanguageService
{
@@ -281,10 +282,11 @@
return Project.GetGotoInfo(filePath, line + 1, col + 1, getText);
}
- public Methods GetMethodTip(string filePath, int line, int col, GetText getText)
+ public NemerleMethods GetMethodTip(string filePath, int line, int col, GetText getText)
{
- object obj = Project.GetMethodTip(filePath, line + 1, col + 1, getText);
- return null;
+ MethodTipInfo info = Project.GetMethodTip(filePath, line + 1, col + 1, getText);
+
+ return info != null? new NemerleMethods(info): null;
}
}
}
\ No newline at end of file
Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerleLanguage.cs Sun Sep 17 08:01:42 2006
@@ -258,14 +258,36 @@
if (projectInfo == null)
return null;
- Methods methods = projectInfo.GetMethodTip(
+ NemerleMethods methods = projectInfo.GetMethodTip(
_request.FileName, _request.Line, _request.Col, GetCodeRegion);
if (methods != null)
{
+ TextSpan ts = new TextSpan();
+ Location loc = methods.GetMethodLocation();
+
+ if (loc.EndLine == 0)
+ {
+ ts.iStartLine = _request.Line;
+ ts.iEndLine = _request.Line;
+ ts.iStartIndex = _request.Col - 1;
+ ts.iEndIndex = _request.Col + 1;
+ }
+ else
+ {
+ ts.iStartLine = loc.Line - 1;
+ ts.iEndLine = loc.EndLine - 1;
+ ts.iStartIndex = loc.Column - 1;
+ ts.iEndIndex = loc.EndColumn - 1;
+ }
+
+ _request.Sink.StartName(ts, methods.GetName(0));
+ //_request.Sink.QualifyName(ts, ts, methods.GetName(0));
+ _request.Sink.StartParameters(ts);
+
return new NemerleAuthoringScope(
ProjectInfo.FindProject(_request.FileName),
- (NemerleAuthoringSink)_request.Sink, methods);
+ _request.Sink, methods);
}
return GetDefaultScope();
Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerleMethods.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerleMethods.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerleMethods.cs Sun Sep 17 08:01:42 2006
@@ -1,71 +1,60 @@
-/***************************************************************************
-
-Copyright (c) Microsoft Corporation. All rights reserved.
-This code is licensed under the Visual Studio SDK license terms.
-THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
-ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
-IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
-PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
-
-***************************************************************************/
-
using System;
+
using Microsoft.VisualStudio.Package;
-namespace Microsoft.Samples.VisualStudio.NemerleLanguageService
+using Nemerle.Completion2;
+using Nemerle.Builtins;
+using Nemerle.Compiler;
+
+namespace Nemerle.VsIntegration
{
- class NemerleMethods : Methods
+ public class NemerleMethods : Methods
+ {
+ public NemerleMethods(MethodTipInfo info)
{
- //private IList<FunctionInfo> methods;
+ _info = info;
+ }
- //public NemerleMethods(IList<FunctionInfo> methods)
- //{
- // this.methods = methods;
- //}
+ MethodTipInfo _info;
public override int GetCount()
{
- //return methods != null ? methods.Count : 0;
- throw new NotImplementedException();
+ return _info.GetCount();
}
public override string GetDescription(int index)
{
- //return methods != null && 0 <= index
- // && index < methods.Count ? methods[index].Description : "";
- throw new NotImplementedException();
+ return _info.GetDescription(index);
}
public override string GetType(int index)
{
- //return methods != null && 0 <= index
- // && index < methods.Count ? methods[index].Type : "";
- throw new NotImplementedException();
+ return _info.GetType(index);
}
public override int GetParameterCount(int index)
{
- //return methods != null && 0 <= index
- // && index < methods.Count ? methods[index].ParameterCount : 0;
- throw new NotImplementedException();
+ return _info.GetParameterCount(index);
}
public override void GetParameterInfo(int index, int parameter,
out string name, out string display, out string description)
{
- //if (methods != null && 0 <= index && index < methods.Count)
- // methods[index].GetParameterInfo(parameter, out name, out display,
- // out description);
- //else
- // name = display = description = string.Empty;
- throw new NotImplementedException();
+ Tuple<string,string,string> info = _info.GetParameterInfo(index, parameter);
+
+ name = info.field0;
+ display = info.field1;
+ description = info.field2;
}
public override string GetName(int index)
{
- //return methods != null && 0 <= index
- // && index < methods.Count ? methods[index].Name : "";
- throw new NotImplementedException();
+ return _info.GetName(index);
+ }
+
+ public Location GetMethodLocation()
+ {
+ return _info.GetMethodLocation();
}
}
}
More information about the svn
mailing list