void AddTypesAndNamespaces (CompletionDataWrapper wrapper, CppResolver state, AstNode node, Predicate<IType> typePred = null, Predicate<IMember> memberPred = null) { if (currentType != null) { for (var ct = currentType; ct != null; ct = ct.DeclaringTypeDefinition) { foreach (var nestedType in ct.NestedTypes) { if (typePred == null || typePred (nestedType.Resolve (ctx))) { string name = nestedType.Name; if (node is Attribute && name.EndsWith ("Attribute") && name.Length > "Attribute".Length) name = name.Substring (0, name.Length - "Attribute".Length); wrapper.AddType (nestedType, name); } } } if (this.currentMember != null && !(node is AstType)) { var def = ctx.CurrentTypeDefinition ?? Compilation.MainAssembly.GetTypeDefinition (currentType); if (def != null) { foreach (var member in def.GetMembers ()) { if (member is IMethod && ((IMethod)member).FullName == "System.Object.Finalize") continue; if (member.EntityType == EntityType.Operator) continue; if (memberPred == null || memberPred (member)) wrapper.AddMember (member); } var declaring = def.DeclaringTypeDefinition; while (declaring != null) { foreach (var member in declaring.GetMembers (m => m.IsStatic)) { if (memberPred == null || memberPred (member)) wrapper.AddMember (member); } declaring = declaring.DeclaringTypeDefinition; } } } foreach (var p in currentType.TypeParameters) { wrapper.AddTypeParameter (p); } } var scope = CSharpParsedFile.GetUsingScope (location).Resolve (Compilation); for (var n = scope; n != null; n = n.Parent) { foreach (var pair in n.UsingAliases) { wrapper.AddNamespace (pair.Key); } foreach (var u in n.Usings) { foreach (var type in u.Types) { if (typePred == null || typePred (type)) { string name = type.Name; if (node is Attribute && name.EndsWith ("Attribute") && name.Length > "Attribute".Length) name = name.Substring (0, name.Length - "Attribute".Length); wrapper.AddType (type, name); } } } foreach (var type in n.Namespace.Types) { if (typePred == null || typePred (type)) wrapper.AddType (type, type.Name); } foreach (var curNs in n.Namespace.ChildNamespaces) { wrapper.AddNamespace (curNs.Name); } } }
void AddContextCompletion (CompletionDataWrapper wrapper, CppResolver state, AstNode node) { if (state != null && !(node is AstType)) { foreach (var variable in state.LocalVariables) { if (variable.Region.IsInside (location.Line, location.Column - 1)) continue; wrapper.AddVariable (variable); } } if (currentMember is IUnresolvedParameterizedMember && !(node is AstType)) { var param = (IParameterizedMember)currentMember.CreateResolved (ctx); foreach (var p in param.Parameters) { wrapper.AddVariable (p); } } if (currentMember is IUnresolvedMethod) { var method = (IUnresolvedMethod)currentMember; foreach (var p in method.TypeParameters) { wrapper.AddTypeParameter (p); } } Predicate<IType> typePred = null; if (node is Attribute) { var attribute = Compilation.FindType (KnownTypeCode.Attribute); typePred = t => { return t.GetAllBaseTypeDefinitions ().Any (bt => bt.Equals (attribute)); }; } AddTypesAndNamespaces (wrapper, state, node, typePred); wrapper.Result.Add (factory.CreateLiteralCompletionData ("global")); if (!(node is AstType)) { if (currentMember != null) { AddKeywords (wrapper, statementStartKeywords); AddKeywords (wrapper, expressionLevelKeywords); } else if (currentType != null) { AddKeywords (wrapper, typeLevelKeywords); } else { AddKeywords (wrapper, globalLevelKeywords); } var prop = currentMember as IUnresolvedProperty; if (prop != null && prop.Setter != null && prop.Setter.Region.IsInside (location)) wrapper.AddCustom ("value"); if (currentMember is IUnresolvedEvent) wrapper.AddCustom ("value"); if (IsInSwitchContext (node)) { wrapper.AddCustom ("case"); } } AddKeywords (wrapper, primitiveTypesKeywords); if (currentMember != null) wrapper.AddCustom ("var"); wrapper.Result.AddRange (factory.CreateCodeTemplateCompletionData ()); if (node != null && node.Role == AstNode.Roles.Argument) { var resolved = ResolveExpression (CSharpParsedFile, node.Parent, Unit); var invokeResult = resolved != null ? resolved.Item1 as CppInvocationResolveResult : null; if (invokeResult != null) { int argNum = 0; foreach (var arg in node.Parent.Children.Where (c => c.Role == AstNode.Roles.Argument)) { if (arg == node) break; argNum++; } var param = argNum < invokeResult.Member.Parameters.Count ? invokeResult.Member.Parameters [argNum] : null; if (param != null && param.Type.Kind == TypeKind.Enum) { AddEnumMembers (wrapper, param.Type, state); } } } }