Permalink
Browse files

Updated code completion to the latest type system changes.

  • Loading branch information...
1 parent a564ebb commit c453405dcfbd1f9f39e02de1cc9317478acad980 @mkrueger mkrueger committed Nov 29, 2011

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -34,6 +34,7 @@
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
+using ICSharpCode.NRefactory.CSharp.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp.Completion
{
@@ -45,11 +46,11 @@ public class CSharpCompletionEngineBase
protected IDocument document;
protected int offset;
protected TextLocation location;
- protected ITypeDefinition currentType;
- protected IMember currentMember;
+ protected IUnresolvedTypeDefinition currentType;
+ protected IUnresolvedMember currentMember;
#region Input properties
- public ITypeResolveContext ctx { get; set; }
+ public CSharpTypeResolveContext ctx { get; set; }
public CompilationUnit Unit { get; set; }
@@ -322,7 +323,7 @@ protected CompilationUnit ParseStub (string continuation, bool appendSemicolon =
using (var stream = new System.IO.StringReader (wrapper.ToString ())) {
try {
var parser = new CSharpParser ();
- return parser.Parse (stream, wrapInClass ? memberLocation.Line - 2 : 0);
+ return parser.Parse (stream, "stub.cs" , wrapInClass ? memberLocation.Line - 2 : 0);
} catch (Exception){
Console.WriteLine ("------");
Console.WriteLine (wrapper);
@@ -460,17 +461,15 @@ protected virtual void Reset ()
resolveNode = expr;
}
- var csResolver = new CSharpResolver (ctx, System.Threading.CancellationToken.None);
+ var csResolver = new CSharpResolver (ctx);
var navigator = new NodeListResolveVisitorNavigator (new[] { resolveNode });
- if (ProjectContent is SimpleProjectContent)
- ((SimpleProjectContent)ProjectContent).UpdateProjectContent (CSharpParsedFile, file);
+ ProjectContent.UpdateProjectContent (CSharpParsedFile, file);
var visitor = new ResolveVisitor (csResolver, file, navigator);
visitor.Scan (unit);
var state = visitor.GetResolverStateBefore (resolveNode);
var result = visitor.GetResolveResult (resolveNode);
- if (ProjectContent is SimpleProjectContent)
- ((SimpleProjectContent)ProjectContent).UpdateProjectContent (file, CSharpParsedFile);
+ ProjectContent.UpdateProjectContent (file, CSharpParsedFile);
return Tuple.Create (result, state);
}
@@ -30,6 +30,7 @@
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.CSharp.Resolver;
+using ICSharpCode.NRefactory.CSharp.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp.Completion
{
@@ -64,7 +65,7 @@ public CSharpParameterCompletionEngine (IDocument document, IParameterCompletion
var member2 = baseUnit.GetNodeAt<AttributedNode> (memberLocation);
member2.Remove ();
member.ReplaceWith (member2);
- var tsvisitor = new TypeSystemConvertVisitor (ProjectContent, CSharpParsedFile.FileName);
+ var tsvisitor = new TypeSystemConvertVisitor (CSharpParsedFile.FileName);
Unit.AcceptVisitor (tsvisitor, null);
return Tuple.Create (tsvisitor.ParsedFile, (AstNode)expr, Unit);
}
@@ -175,13 +176,15 @@ List<string> GetUsedNamespaces ()
{
var scope = CSharpParsedFile.GetUsingScope (location);
var result = new List<string> ();
+ var resolver = new CSharpResolver (ctx);
while (scope != null) {
result.Add (scope.NamespaceName);
+
foreach (var u in scope.Usings) {
- var ns = u.ResolveNamespace (ctx);
+ var ns = u.ResolveNamespace (resolver);
if (ns == null)
continue;
- result.Add (ns.NamespaceName);
+ result.Add (ns.FullName);
}
scope = scope.Parent;
}
@@ -93,6 +93,14 @@ public void AddType (IType type, string shortType)
usedTypes.Add (shortType);
result.Add (Factory.CreateTypeCompletionData (type, shortType));
}
+
+ public void AddType (IUnresolvedTypeDefinition type, string shortType)
+ {
+ if (type == null || string.IsNullOrEmpty (shortType) || usedTypes.Contains (shortType))
+ return;
+ usedTypes.Add (shortType);
+ result.Add (Factory.CreateTypeCompletionData (type, shortType));
+ }
Dictionary<string, List<ICompletionData>> data = new Dictionary<string, List<ICompletionData>> ();
@@ -104,14 +112,51 @@ public void AddVariable (IVariable variable)
result.Add (Factory.CreateVariableCompletionData (variable));
}
- public void AddTypeParameter (ITypeParameter variable)
+ public void AddTypeParameter (IUnresolvedTypeParameter variable)
{
if (data.ContainsKey (variable.Name))
return;
data [variable.Name] = new List<ICompletionData> ();
result.Add (Factory.CreateVariableCompletionData (variable));
}
+ public ICompletionData AddMember (IUnresolvedMember member)
+ {
+ var newData = Factory.CreateEntityCompletionData (member);
+
+// newData.HideExtensionParameter = HideExtensionParameter;
+ string memberKey = newData.DisplayText;
+ if (memberKey == null)
+ return null;
+ if (member is IMember) {
+ newData.CompletionCategory = GetCompletionCategory (member.DeclaringTypeDefinition.Resolve (completion.ctx));
+ }
+ List<ICompletionData> existingData;
+ data.TryGetValue (memberKey, out existingData);
+
+ if (existingData != null) {
+ var a = member as IEntity;
+ foreach (var d in existingData) {
+ if (!(d is IEntityCompletionData))
+ continue;
+ var b = ((IEntityCompletionData)d).Entity;
+ if (a == null || b == null || a.EntityType == b.EntityType) {
+ d.AddOverload (newData);
+ return d;
+ }
+ }
+ if (newData != null) {
+ result.Add (newData);
+ data [memberKey].Add (newData);
+ }
+ } else {
+ result.Add (newData);
+ data [memberKey] = new List<ICompletionData> ();
+ data [memberKey].Add (newData);
+ }
+ return newData;
+ }
+
public ICompletionData AddMember (IMember member)
{
var newData = Factory.CreateEntityCompletionData (member);
@@ -149,7 +194,7 @@ public ICompletionData AddMember (IMember member)
return newData;
}
- internal CompletionCategory GetCompletionCategory (ITypeDefinition type)
+ internal CompletionCategory GetCompletionCategory (IType type)
{
if (type == null)
return null;
@@ -158,15 +203,15 @@ internal CompletionCategory GetCompletionCategory (ITypeDefinition type)
return completionCategories [type];
}
- Dictionary<ITypeDefinition, CompletionCategory> completionCategories = new Dictionary<ITypeDefinition, CompletionCategory> ();
+ Dictionary<IType, CompletionCategory> completionCategories = new Dictionary<IType, CompletionCategory> ();
class TypeCompletionCategory : CompletionCategory
{
- public ITypeDefinition Type {
+ public IType Type {
get;
private set;
}
- public TypeCompletionCategory (ITypeDefinition type) : base (type.FullName, null)
+ public TypeCompletionCategory (IType type) : base (type.FullName, null)
{
this.Type = type;
}
@@ -32,11 +32,13 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
{
public interface ICompletionDataFactory
{
+ ICompletionData CreateEntityCompletionData (IUnresolvedEntity entity);
+ ICompletionData CreateEntityCompletionData (IUnresolvedEntity entity, string text);
ICompletionData CreateEntityCompletionData (IEntity entity);
-
ICompletionData CreateEntityCompletionData (IEntity entity, string text);
ICompletionData CreateTypeCompletionData (IType type, string shortType);
+ ICompletionData CreateTypeCompletionData (IUnresolvedTypeDefinition type, string shortType);
/// <summary>
/// Creates a generic completion data.
@@ -56,11 +58,11 @@ public interface ICompletionDataFactory
ICompletionData CreateVariableCompletionData (IVariable variable);
- ICompletionData CreateVariableCompletionData (ITypeParameter parameter);
+ ICompletionData CreateVariableCompletionData (IUnresolvedTypeParameter parameter);
- ICompletionData CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IMember currentMember, ITypeDefinition currentType);
+ ICompletionData CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType);
- ICompletionData CreateNewOverrideCompletionData (int declarationBegin, ITypeDefinition type, IMember m);
+ ICompletionData CreateNewOverrideCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IMember m);
IEnumerable<ICompletionData> CreateCodeTemplateCompletionData ();
@@ -312,6 +312,10 @@
<Compile Include="TypeSystem\UsingScope.cs" />
<Compile Include="Ast\GeneralScope\PreProcessorDirective.cs" />
<Compile Include="Ast\Expressions\ErrorExpression.cs" />
+ <Compile Include="Completion\CompletionDataWrapper.cs" />
+ <Compile Include="Completion\CSharpCompletionEngine.cs" />
+ <Compile Include="Completion\CSharpCompletionEngineBase.cs" />
+ <Compile Include="Completion\CSharpParameterCompletionEngine.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
@@ -322,7 +326,6 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Folder Include="Completion\" />
- <Folder Include="TypeSystem" />
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
@@ -39,6 +39,7 @@
using ICSharpCode.NRefactory.Editor;
using System.Diagnostics;
using System.Text;
+using ICSharpCode.NRefactory.CSharp.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
@@ -133,6 +134,21 @@ public ICompletionData CreateEntityCompletionData (ICSharpCode.NRefactory.TypeSy
return new CompletionData (text);
}
+ public ICompletionData CreateEntityCompletionData (ICSharpCode.NRefactory.TypeSystem.IUnresolvedEntity entity)
+ {
+ return new CompletionData (entity.Name);
+ }
+
+ public ICompletionData CreateEntityCompletionData (ICSharpCode.NRefactory.TypeSystem.IUnresolvedEntity entity, string text)
+ {
+ return new CompletionData (text);
+ }
+
+ public ICompletionData CreateTypeCompletionData (ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition type, string shortType)
+ {
+ return new CompletionData (shortType);
+ }
+
public ICompletionData CreateTypeCompletionData (ICSharpCode.NRefactory.TypeSystem.IType type, string shortType)
{
return new CompletionData (shortType);
@@ -153,17 +169,17 @@ public ICompletionData CreateVariableCompletionData (ICSharpCode.NRefactory.Type
return new CompletionData (variable.Name);
}
- public ICompletionData CreateVariableCompletionData (ICSharpCode.NRefactory.TypeSystem.ITypeParameter parameter)
+ public ICompletionData CreateVariableCompletionData (ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeParameter parameter)
{
return new CompletionData (parameter.Name);
}
- public ICompletionData CreateEventCreationCompletionData (string varName, ICSharpCode.NRefactory.TypeSystem.IType delegateType, ICSharpCode.NRefactory.TypeSystem.IEvent evt, string parameterDefinition, ICSharpCode.NRefactory.TypeSystem.IMember currentMember, ICSharpCode.NRefactory.TypeSystem.ITypeDefinition currentType)
+ public ICompletionData CreateEventCreationCompletionData (string varName, ICSharpCode.NRefactory.TypeSystem.IType delegateType, ICSharpCode.NRefactory.TypeSystem.IEvent evt, string parameterDefinition, ICSharpCode.NRefactory.TypeSystem.IUnresolvedMember currentMember, ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition currentType)
{
return new CompletionData (varName);
}
- public ICompletionData CreateNewOverrideCompletionData (int declarationBegin, ICSharpCode.NRefactory.TypeSystem.ITypeDefinition type, ICSharpCode.NRefactory.TypeSystem.IMember m)
+ public ICompletionData CreateNewOverrideCompletionData (int declarationBegin, ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition type, ICSharpCode.NRefactory.TypeSystem.IMember m)
{
return new CompletionData (m.Name);
}
@@ -197,15 +213,16 @@ static CompletionDataList CreateProvider (string text, bool isCtrlSpace)
var doc = new ReadOnlyDocument (editorText);
var engine = new CSharpCompletionEngine (doc, new TestFactory ());
- var pctx = new SimpleProjectContent ();
+ var pctx = new CSharpProjectContent ();
+ pctx.AddAssemblyReferences (new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
- var compilationUnit = new CSharpParser ().Parse (parsedText);
+ var compilationUnit = new CSharpParser ().Parse (parsedText, "program.cs");
- var parsedFile = new TypeSystemConvertVisitor (pctx, "program.cs").Convert (compilationUnit);
+ var parsedFile = compilationUnit.ToTypeSystem ();
pctx.UpdateProjectContent (null, parsedFile);
-
- var ctx = new CompositeTypeResolveContext ( new [] { pctx, CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
- engine.ctx = ctx;
+ var cmp = pctx.CreateCompilation ();
+
+ engine.ctx = new CSharpTypeResolveContext (cmp.MainAssembly);
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = new CSharpFormattingOptions ();
engine.CSharpParsedFile = parsedFile;
@@ -225,13 +242,15 @@ static CompletionDataList CreateProvider (string text, bool isCtrlSpace)
Tuple<ReadOnlyDocument, CSharpCompletionEngine> GetContent (string text, CompilationUnit compilationUnit)
{
var doc = new ReadOnlyDocument (text);
- var pctx = new SimpleProjectContent ();
- var parsedFile = new TypeSystemConvertVisitor (pctx, "program.cs").Convert (compilationUnit);
+ var pctx = new CSharpProjectContent ();
+ var parsedFile = compilationUnit.ToTypeSystem ();
pctx.UpdateProjectContent (null, parsedFile);
+ pctx.AddAssemblyReferences (new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
+ var cmp = pctx.CreateCompilation ();
+
var engine = new CSharpCompletionEngine (doc, new TestFactory ());
- var ctx = new CompositeTypeResolveContext ( new [] { pctx, CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
- engine.ctx = ctx;
+ engine.ctx = new CSharpTypeResolveContext (cmp.MainAssembly);
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = new CSharpFormattingOptions ();
engine.CSharpParsedFile = parsedFile;
@@ -306,7 +325,7 @@ public void TestLoadAllTests ()
continue;
var text = File.ReadAllText (file, Encoding.Default);
try {
- var unit = new CSharpParser ().Parse (text);
+ var unit = new CSharpParser ().Parse (text, file);
var cnt = GetContent (text, unit);
@@ -35,6 +35,7 @@
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.TypeSystem;
using System.Linq;
+using ICSharpCode.NRefactory.CSharp.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
@@ -43,9 +44,9 @@ public class ParameterCompletionTests : TestBase
{
class TestFactory : IParameterCompletionDataFactory
{
- ITypeResolveContext ctx;
+ IProjectContent ctx;
- public TestFactory (ITypeResolveContext ctx)
+ public TestFactory (IProjectContent ctx)
{
this.ctx = ctx;
}
@@ -111,7 +112,7 @@ public IParameterDataProvider CreateConstructorProvider (ICSharpCode.NRefactory.
{
return new Provider () {
- Data = type.GetConstructors (ctx, m => m.Accessibility == Accessibility.Public)
+ Data = type.GetConstructors (m => m.Accessibility == Accessibility.Public)
};
}
@@ -139,7 +140,7 @@ public IParameterDataProvider CreateDelegateDataProvider (ICSharpCode.NRefactory
public IParameterDataProvider CreateIndexerParameterDataProvider (IType type, AstNode resolvedNode)
{
return new IndexerProvider () {
- Data = type.GetProperties (ctx, p => p.IsIndexer)
+ Data = type.GetProperties (p => p.IsIndexer)
};
}
#endregion
@@ -161,17 +162,17 @@ internal static IParameterDataProvider CreateProvider (string text)
var doc = new ReadOnlyDocument (editorText);
- var pctx = new SimpleProjectContent ();
+ var pctx = new CSharpProjectContent ();
+ pctx.AddAssemblyReferences (new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
- var compilationUnit = new CSharpParser ().Parse (parsedText);
+ var compilationUnit = new CSharpParser ().Parse (parsedText, "program.cs");
- var parsedFile = new TypeSystemConvertVisitor (pctx, "program.cs").Convert (compilationUnit);
+ var parsedFile = compilationUnit.ToTypeSystem ();
pctx.UpdateProjectContent (null, parsedFile);
-
- var ctx = new CompositeTypeResolveContext ( new [] { pctx, CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
+ var cmp = pctx.CreateCompilation ();
+ var engine = new CSharpParameterCompletionEngine (doc, new TestFactory (pctx));
- var engine = new CSharpParameterCompletionEngine (doc, new TestFactory (ctx));
- engine.ctx = ctx;
+ engine.ctx = new CSharpTypeResolveContext (cmp.MainAssembly);
engine.CSharpParsedFile = parsedFile;
engine.ProjectContent = pctx;
engine.Unit = compilationUnit;
Oops, something went wrong.

0 comments on commit c453405

Please sign in to comment.