[svn] r6887: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
Nemerle....
pbludov
svnadmin at nemerle.org
Tue Nov 14 08:02:47 CET 2006
Log:
Refactoring changes
Author: pbludov
Date: Tue Nov 14 08:02:43 2006
New Revision: 6887
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleAuthoringScope.cs
vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs
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 08:02:43 2006
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using Nemerle.Assertions;
using Nemerle.Collections;
@@ -74,6 +75,9 @@
// Finds an object by provided location.
// Returns object location * associated Parsetree * associated Typedtree
+
+ // PB061114: Ìîæåò ÿâíî äîáàâèòü ïàòòåðíû TExpr.None è PExpr.None è
+ // èñïîëüçîâàòü èõ âìåñòî null? Åù¸ âàðèàíò: èñïîëüçîâàòü option[TExpr] è option[PExpr]
//
private FindObject(
typeDecl : Decl.Type,
@@ -116,6 +120,7 @@
match (ty)
{
| MType.Array (p, _) => [p]
+ | MType.Fun (f, t) => [f,t]
| MType.Class (_, p)
| MType.Tuple (p) => p
| _ => []
@@ -132,21 +137,23 @@
{
| method is MethodBuilder =>
- if (method.BodyLocation.Contains(line, col))
+ def ast = method.Ast;
+
+ if (ast.Body.Location.Contains(line, col))
{
ExprFinder().Find(method.GetParsedBody(), method.GetTypedBody(), line, col);
}
- else if (method.fun_header.Location.Contains(line, col))
+ else if (ast.header.Location.Contains(line, col))
{
- if (method.fun_header.ret_type_loc.Contains(line, col))
- checkType(method.Ast.header.ret_type, method.ReturnType);
+ if (ast.header.ret_type.Location.Contains(line, col))
+ checkType(ast.header.ret_type, method.ReturnType);
else
{
- def parm = method.fun_header.parms.Find((p) => p.ty_loc.Contains(line, col));
+ def parms = ast.header.parms;
- match (parm)
+ match (parms.Find((p) => p.ty.Location.Contains(line, col)))
{
- | Some(p) => (p.ty_loc, null, p.ty)
+ | Some(p) => checkType(p.ty, method.fun_header.parms.Nth(parms.IndexOf(p)).ty)
| _ => (Location.Default, null, null)
}
}
@@ -233,10 +240,8 @@
def members = ti.GetMembers(BindingFlags.Static
%| BindingFlags.Instance %| BindingFlags.Public
%| BindingFlags.NonPublic %| BindingFlags.DeclaredOnly)
- .Filter(fun(m) {
- System.Attribute.GetCustomAttribute(m.GetHandle(),
- typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)) == null;
- });
+ .Filter((p) => System.Attribute.GetCustomAttribute(p.GetHandle(),
+ typeof(CompilerGeneratedAttribute)) == null);
List.Map(members, GotoInfo);
}
@@ -245,6 +250,7 @@
{
| MType.Class(tycon is TypeBuilder, _) =>
List.Map(tycon.PartsLocation, GotoInfo);
+
| MType.Class(tycon, _) => getMembers(tycon);
| _ => []
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n Tue Nov 14 08:02:43 2006
@@ -12,10 +12,13 @@
public AddCompilerMessage(message : string, location : Location, kind : MessageKind, ) : void
{
- if (_currentMessages != null)
- _currentMessages.Add(CompilerMessage(message, location, kind));
- else
+ when (null == _currentMessages)
+ {
System.Diagnostics.Trace.WriteLine("_currentMessages is null???");
+ _currentMessages = SCG.List();
+ }
+
+ _currentMessages.Add(CompilerMessage(message, location, kind));
}
ProcessTopLevelCompilerMessage(location : Location, message : string) : void
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 08:02:43 2006
@@ -4,6 +4,7 @@
using System.Runtime.InteropServices;
using System.Diagnostics.SymbolStore;
using System.Windows.Forms;
+
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
@@ -56,6 +57,7 @@
private ProjectInfo _project;
private string _filePath;
private ISource _sourceText;
+ private /*readonly*/ Guid IID_MetaDataImport = new Guid("7DAC8207-D3AE-4c75-9B67-92801A497D44");
#endregion
@@ -88,17 +90,20 @@
span = new TextSpan();
GotoInfo[] info;
+
switch (cmd)
{
case VSConstants.VSStd97CmdID.GotoDecl:
case VSConstants.VSStd97CmdID.GotoDefn:
info = _project.GetGoto(_filePath, line, col, _sourceText);
break;
+
case VSConstants.VSStd97CmdID.GotoRef:
info = _project.GetUsages(_filePath, line, col, _sourceText);
break;
+
default:
- System.Diagnostics.Trace.Assert(false, "Unknown cmd (" + cmd + ")");
+ Trace.Assert(false, "Unknown cmd (" + cmd + ")");
info = null;
break;
}
@@ -110,14 +115,65 @@
return null;
}
- ISymbolBinder1 binder = null;
+ LookupMethodLocationsFromPdb(info);
+
+ List<GotoInfo> gotoInfos = new List<GotoInfo>(info.Length);
+
+ // Remove duplicates and members which location still is not known.
+ //
+ for (int i = 0; i < info.Length; ++i)
+ {
+ if (info[i].HasLocation && gotoInfos.FindIndex(
+ delegate (GotoInfo item)
+ {
+ return item.FilePath == info[i].FilePath
+ && item.LineStart == info[i].LineStart;
+ }) < 0)
+ gotoInfos.Add(info[i]);
+ }
+
+ if (gotoInfos.Count == 1)
+ return SetTextSpan(ref span, gotoInfos[0]);
+ else if (gotoInfos.Count > 0)
+ {
+ NativeWindow textEditorWnd =
+ NativeWindow.FromHandle(textView.GetWindowHandle());
+
+ using (GoToTypeForm popup = new GoToTypeForm(gotoInfos))
+ if (popup.ShowDialog(textEditorWnd) == DialogResult.OK)
+ return SetTextSpan(ref span, popup.Result);
+ }
+
+ return null;
+ }
+
+ public override Declarations GetDeclarations(
+ IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
+ {
+ return new NemerleDeclarations(_overloadPossibility ?? new CompletionElem[0]);
+ }
+
+ public override Methods GetMethods(int line, int col, string name)
+ {
+ return _methods;
+ }
+
+ #endregion
+
+ #region Implementation
+
+ private void LookupMethodLocationsFromPdb(GotoInfo[] info)
+ {
IntPtr mdiPtr = IntPtr.Zero;
+ ISymbolBinder1 binder = null;
ISymbolDocument[] documents = null;
int[] lines = null;
int[] columns = null;
int[] endLines = null;
int[] endColumns = null;
int[] offsets = null;
+ string prevFile = null;
+ ISymbolReader reader = null;
try
{
@@ -132,10 +188,9 @@
//
if (mdiPtr == IntPtr.Zero)
{
- Guid mdiGuid = new Guid("7DAC8207-D3AE-4c75-9B67-92801A497D44");
object mdiUnk;
- if (VSConstants.S_OK == _project.SmartOpenScope.OpenScope(info[0].FilePath, 0, ref mdiGuid, out mdiUnk))
+ if (VSConstants.S_OK == _project.SmartOpenScope.OpenScope(info[0].FilePath, 0, ref IID_MetaDataImport, out mdiUnk))
{
mdiPtr = Marshal.GetIUnknownForObject(mdiUnk);
binder = new SymBinder();
@@ -146,12 +201,22 @@
endColumns = new int[1];
offsets = new int[1];
}
+ else
+ {
+ Debug.WriteLineIf(TS.TraceWarning, "Failed to obtain MetaDataImport from VS", TS.DisplayName);
+ break;
+ }
}
try
{
+ if (gotoInfo.FilePath != prevFile)
+ {
+ reader = binder.GetReader(mdiPtr, gotoInfo.FilePath, null);
+ prevFile = gotoInfo.FilePath;
+ }
+
SymbolToken token = new SymbolToken(gotoInfo.Member.MetadataToken);
- ISymbolReader reader = binder.GetReader(mdiPtr, gotoInfo.FilePath, null);
ISymbolMethod method = reader.GetMethod(token);
if (method.SequencePointCount > 0)
@@ -181,52 +246,6 @@
if (IntPtr.Zero != mdiPtr)
Marshal.Release(mdiPtr);
}
-
- if (info.Length == 1)
- {
- if (info[0].HasLocation)
- {
- span.iStartLine = info[0].LineStart;
- span.iEndLine = info[0].LineEnd;
- span.iStartIndex = info[0].ColStart;
- span.iEndIndex = info[0].ColEnd;
-
- return info[0].FilePath;
- }
- }
- else
- {
- List<GotoInfo> gotoInfos = new List<GotoInfo>(info.Length);
-
- // Remove duplicates and members which location still is not known.
- //
- for (int i = 0; i < info.Length; ++i)
- {
- if (info[i].HasLocation && gotoInfos.FindIndex(
- delegate (GotoInfo item)
- {
- return item.FilePath == info[i].FilePath
- && item.LineStart == info[i].LineStart;
- }) < 0)
- gotoInfos.Add(info[i]);
- }
-
- if (gotoInfos.Count <= 0)
- return null;
- else if (gotoInfos.Count == 1)
- return SetTextSpan(ref span, gotoInfos[0]);
- else
- {
- NativeWindow textEditorWnd =
- NativeWindow.FromHandle(textView.GetWindowHandle());
-
- using (GoToTypeForm popup = new GoToTypeForm(gotoInfos))
- if (popup.ShowDialog(textEditorWnd) == DialogResult.OK)
- return SetTextSpan(ref span, popup.Result);
- }
- }
-
- return null;
}
private static string SetTextSpan(ref TextSpan span, GotoInfo result)
@@ -239,23 +258,11 @@
return result.FilePath;
}
- public override Declarations GetDeclarations(
- IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
- {
- return new NemerleDeclarations(_overloadPossibility ?? new CompletionElem[0]);
- }
-
- public override Methods GetMethods(int line, int col, string name)
- {
- return _methods;
- }
-
#endregion
#region Debug
private static TraceSwitch _authoringScopeTrace;
-
private static TraceSwitch TS
{
get
@@ -268,6 +275,5 @@
}
#endregion
-
}
}
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 Nov 14 08:02:43 2006
@@ -40,6 +40,7 @@
{
ErrorHelper.ThrowIsNull(projectNode, "projectNode");
ErrorHelper.ThrowIsNull(hierarchy, "hierarchy");
+ Debug.Assert(projectNode.Site != null);
_projectNode = projectNode;
_hierarchy = hierarchy;
More information about the svn
mailing list