public MemberResult(string name, PythonMemberType type) { Name = Completion = name; Scope = null; _type = new Lazy <PythonMemberType>(() => type); _vars = EmptyValues; }
public ConstantInfo(object value, PythonAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjectsThrowOnNull(projectState.GetTypeFromObject(value))) { _value = value; _memberType = PythonMemberType.Constant; _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(_type)).Instance; }
internal CompletionResult(string name, string completion, string doc, PythonMemberType memberType, AP.CompletionValue[] values) { _name = name; _memberType = memberType; _completion = completion; _doc = doc; _values = values; }
internal ConstantInfo(BuiltinClassInfo klass, object value, PythonMemberType memberType) : base(klass) { _value = value; _memberType = memberType; _builtinInfo = klass.Instance; }
public BuiltinMethodInfo(IPythonFunction function, PythonMemberType memType, PythonAnalyzer projectState) : base(projectState.Types.BuiltinMethodDescriptor, projectState) { _memberType = memType; _function = function; _returnTypes = Utils.GetReturnTypes(function, projectState); }
public ConstantInfo(IPythonConstant value, PythonAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)) { _value = value; _memberType = value.MemberType; _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)).Instance; }
private static CompletionItemKind ToCompletionItemKind(PythonMemberType memberType) { switch (memberType) { case PythonMemberType.Unknown: return(CompletionItemKind.Text); case PythonMemberType.Class: return(CompletionItemKind.Class); case PythonMemberType.Instance: return(CompletionItemKind.Value); case PythonMemberType.Function: return(CompletionItemKind.Function); case PythonMemberType.Method: return(CompletionItemKind.Method); case PythonMemberType.Module: return(CompletionItemKind.Module); case PythonMemberType.Property: return(CompletionItemKind.Property); case PythonMemberType.Union: return(CompletionItemKind.Struct); case PythonMemberType.Variable: return(CompletionItemKind.Variable); case PythonMemberType.Generic: return(CompletionItemKind.TypeParameter); } return(CompletionItemKind.Text); }
internal ConstantInfo(BuiltinClassInfo classInfo, object value, PythonMemberType memberType) : base(classInfo) { _value = value; _memberType = memberType; _builtinInfo = classInfo.Instance; }
public static StandardGlyphGroup ToGlyphGroup(this PythonMemberType objectType) { StandardGlyphGroup group; switch (objectType) { case PythonMemberType.Class: group = StandardGlyphGroup.GlyphGroupClass; break; case PythonMemberType.Module: group = StandardGlyphGroup.GlyphGroupModule; break; case PythonMemberType.Property: group = StandardGlyphGroup.GlyphGroupProperty; break; case PythonMemberType.Instance: group = StandardGlyphGroup.GlyphGroupVariable; break; case PythonMemberType.Union: group = StandardGlyphGroup.GlyphGroupUnion; break; case PythonMemberType.Variable: group = StandardGlyphGroup.GlyphGroupVariable; break; case PythonMemberType.Generic: group = StandardGlyphGroup.GlyphGroupTemplate; break; case PythonMemberType.Unknown: group = StandardGlyphGroup.GlyphGroupUnknown; break; case PythonMemberType.Function: case PythonMemberType.Method: default: group = StandardGlyphGroup.GlyphGroupMethod; break; } return(group); }
internal CompletionResult(string name, PythonMemberType memberType) { MergeKey = name ?? throw new ArgumentNullException(nameof(name)); Name = name; Completion = name; MemberType = memberType; }
private PythonMemberType GetMemberType() { PythonMemberType result = PythonMemberType.Unknown; foreach (var ns in _vars) { var nsType = ns.ResultType; if (result == PythonMemberType.Unknown) { result = nsType; } else if (result != nsType) { if ((nsType == PythonMemberType.Constant && result == PythonMemberType.Instance) || (nsType == PythonMemberType.Instance && result == PythonMemberType.Constant)) { nsType = PythonMemberType.Instance; } else { return(PythonMemberType.Multiple); } } } if (result == PythonMemberType.Unknown) { return(PythonMemberType.Instance); } return(result); }
public AndConstraint <PythonTypeAssertions> HaveMemberType(PythonMemberType memberType, string because = "", params object[] reasonArgs) { Execute.Assertion.ForCondition(Subject is IPythonType m && m.MemberType == memberType) .BecauseOf(because, reasonArgs) .FailWith($"Expected {_moduleName}.{_name} to be {memberType} {{reason}}."); return(new AndConstraint <PythonTypeAssertions>(this)); }
internal CompletionResult(string name, string completion, string doc, PythonMemberType memberType, AP.CompletionValue[] values) { _name = name; _memberType = memberType; _completion = completion; _doc = doc; _values = values; }
public BuiltinMethodInfo(IPythonMethodDescriptor method, PythonAnalyzer projectState) : base(projectState.Types[BuiltinTypeId.BuiltinMethodDescriptor], projectState) { var function = method.Function; _memberType = method.MemberType; _function = function; _returnTypes = Utils.GetReturnTypes(function, projectState); }
public BuiltinMethodInfo(IPythonFunction function, PythonMemberType memType, PythonAnalyzer projectState) : base(projectState.Types[ memType == PythonMemberType.Function ? BuiltinTypeId.Function : BuiltinTypeId.Method ], projectState) { MemberType = memType; Function = function; ReturnTypes = GetReturnTypes(function, projectState); }
internal CompletionResult(string mergeKey, string name, string completion, string doc, PythonMemberType memberType, AP.CompletionValue[] values) { MergeKey = mergeKey ?? throw new ArgumentNullException(nameof(mergeKey)); Name = name ?? throw new ArgumentNullException(nameof(name)); Completion = completion ?? throw new ArgumentNullException(nameof(completion)); MemberType = memberType; Documentation = doc; _values = values; }
public CallableProtocol(ProtocolInfo self, string qualname, IReadOnlyList <IAnalysisSet> arguments, IAnalysisSet returnType, PythonMemberType memberType = PythonMemberType.Function) : base(self) { Name = qualname ?? "callable"; Arguments = arguments; ReturnType = returnType.AsUnion(1); _overloads = new Lazy <OverloadResult[]>(GenerateOverloads); MemberType = memberType; }
public string HandleCommand(string commandId, string body) { var serializer = new JavaScriptSerializer(); Dictionary<string, HashSet<AnalysisValue>> variables; switch (commandId) { case Commands.GetTags: return serializer.Serialize(_tags.Keys.ToArray()); case Commands.GetVariables: variables = GetVariablesForTemplateFile(body); if (variables != null) { return serializer.Serialize(variables.Keys.ToArray()); } return "[]"; case Commands.GetFilters: Dictionary<string, string> res = new Dictionary<string, string>(); foreach (var filter in _filters) { res[filter.Key] = filter.Value.Documentation; } return serializer.Serialize(res); case Commands.GetUrls: // GroupBy + Select have the same effect as Distinct with a long EqualityComparer return serializer.Serialize(_urls.GroupBy(url => url.FullName).Select(urlGroup => urlGroup.First())); case Commands.GetMembers: string[] args = serializer.Deserialize<string[]>(body); var file = args[0]; var varName = args[1]; variables = GetVariablesForTemplateFile(file); HashSet<AnalysisValue> values; IProjectEntry projEntry; if (_analyzer.TryGetProjectEntryByPath(file, out projEntry)) { var context = projEntry.AnalysisContext; if (variables != null && variables.TryGetValue(varName, out values)) { var newTags = new Dictionary<string, PythonMemberType>(); foreach (var member in values.SelectMany(item => item.GetAllMembers(context))) { string name = member.Key; PythonMemberType type, newType = GetMemberType(member.Value); if (!newTags.TryGetValue(name, out type)) { newTags[name] = newType; } else if (type != newType && type != PythonMemberType.Unknown && newType != PythonMemberType.Unknown) { newTags[name] = PythonMemberType.Multiple; } } var dict = newTags.ToDictionary(x => x.Key, x => x.Value.ToString().ToLowerInvariant()); return serializer.Serialize(dict); } } return "{}"; default: return String.Empty; } }
public AndConstraint <VariableDefAssertions> HaveMemberType(PythonMemberType memberType, string because = "", params object[] reasonArgs) { Execute.Assertion.ForCondition(Subject.Types is IAnalysisValue av && av.MemberType == memberType) .BecauseOf(because, reasonArgs) .FailWith(Subject.Types != null ? $"Expected {_moduleName}.{_name} to be {memberType}, but it is {((AnalysisValue) Subject.Types).MemberType} {{reason}}." : $"Expected {_moduleName}.{_name} to be {memberType} {{reason}}."); return(new AndConstraint <VariableDefAssertions>(this)); }
public NameProtocol(ProtocolInfo self, string name, string documentation = null, BuiltinTypeId typeId = BuiltinTypeId.Unknown, PythonMemberType memberType = PythonMemberType.Unknown) : base(self) { _name = name; _doc = documentation; _typeId = typeId; MemberType = memberType; _richDescription = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Type, _name) }; }
public static AndWhichConstraint <TAssertions, TMember> OfMemberType <TMember, TAssertions> (this AndWhichConstraint <TAssertions, TMember> constraint, PythonMemberType memberType, string because = "", params object[] reasonArgs) where TMember : IPythonType { Execute.Assertion.ForCondition(constraint.Which.MemberType == memberType) .BecauseOf(because, reasonArgs) .FailWith($"Expected {AssertionsUtilities.GetQuotedName(constraint.Which)} to have type '{memberType}', but found '{constraint.Which.MemberType}'"); return(new AndWhichConstraint <TAssertions, TMember>(constraint.And, constraint.Which)); }
internal MemberResult(string name, string completion, IEnumerable<AnalysisValue> vars, PythonMemberType? type) { _name = name; _vars = () => vars ?? Empty; _completion = completion; if (type != null) { _type = () => type.Value; } else { _type = null; _type = GetMemberType; } }
private static CompletionItem ToCompletionItem(string text, PythonMemberType type, string label = null) { return(new CompletionItem { label = label ?? text, insertText = text, // Place regular items first, advanced entries last sortText = char.IsLetter(text, 0) ? "1" : "2", kind = ToCompletionItemKind(type), _kind = type.ToString().ToLowerInvariant() }); }
private static PythonMemberType GetMemberType(IAnalysisSet values) { PythonMemberType newType = PythonMemberType.Unknown; foreach (var value in values) { if (value.MemberType == newType) { continue; } else if (newType == PythonMemberType.Unknown) { newType = value.MemberType; } else { newType = PythonMemberType.Multiple; break; } } return newType; }
private static CompletionItemKind ToCompletionItemKind(PythonMemberType memberType) { switch (memberType) { case PythonMemberType.Unknown: return(CompletionItemKind.None); case PythonMemberType.Class: return(CompletionItemKind.Class); case PythonMemberType.Instance: return(CompletionItemKind.Value); case PythonMemberType.Delegate: return(CompletionItemKind.Class); case PythonMemberType.DelegateInstance: return(CompletionItemKind.Function); case PythonMemberType.Enum: return(CompletionItemKind.Enum); case PythonMemberType.EnumInstance: return(CompletionItemKind.EnumMember); case PythonMemberType.Function: return(CompletionItemKind.Function); case PythonMemberType.Method: return(CompletionItemKind.Method); case PythonMemberType.Module: return(CompletionItemKind.Module); case PythonMemberType.Namespace: return(CompletionItemKind.Module); case PythonMemberType.Constant: return(CompletionItemKind.Constant); case PythonMemberType.Event: return(CompletionItemKind.Event); case PythonMemberType.Field: return(CompletionItemKind.Field); case PythonMemberType.Property: return(CompletionItemKind.Property); case PythonMemberType.Multiple: return(CompletionItemKind.Value); case PythonMemberType.Keyword: return(CompletionItemKind.Keyword); case PythonMemberType.CodeSnippet: return(CompletionItemKind.Snippet); case PythonMemberType.NamedArgument: return(CompletionItemKind.Variable); default: return(CompletionItemKind.None); } }
public static StandardGlyphGroup ToGlyphGroup(this PythonMemberType objectType) { StandardGlyphGroup group; switch (objectType) { case PythonMemberType.Class: group = StandardGlyphGroup.GlyphGroupClass; break; case PythonMemberType.DelegateInstance: case PythonMemberType.Delegate: group = StandardGlyphGroup.GlyphGroupDelegate; break; case PythonMemberType.Enum: group = StandardGlyphGroup.GlyphGroupEnum; break; case PythonMemberType.Namespace: group = StandardGlyphGroup.GlyphGroupNamespace; break; case PythonMemberType.Multiple: group = StandardGlyphGroup.GlyphGroupOverload; break; case PythonMemberType.Field: group = StandardGlyphGroup.GlyphGroupField; break; case PythonMemberType.Module: group = StandardGlyphGroup.GlyphGroupModule; break; case PythonMemberType.Property: group = StandardGlyphGroup.GlyphGroupProperty; break; case PythonMemberType.Instance: group = StandardGlyphGroup.GlyphGroupVariable; break; case PythonMemberType.Constant: group = StandardGlyphGroup.GlyphGroupVariable; break; case PythonMemberType.EnumInstance: group = StandardGlyphGroup.GlyphGroupEnumMember; break; case PythonMemberType.Event: group = StandardGlyphGroup.GlyphGroupEvent; break; case PythonMemberType.Keyword: group = StandardGlyphGroup.GlyphKeyword; break; case PythonMemberType.CodeSnippet: group = StandardGlyphGroup.GlyphCSharpExpansion; break; case PythonMemberType.NamedArgument: group = StandardGlyphGroup.GlyphGroupMapItem; break; case PythonMemberType.Function: case PythonMemberType.Method: default: group = StandardGlyphGroup.GlyphGroupMethod; break; } return(group); }
private static SymbolKind ToSymbolKind(PythonMemberType memberType) { switch (memberType) { case PythonMemberType.Unknown: return(SymbolKind.None); case PythonMemberType.Class: return(SymbolKind.Class); case PythonMemberType.Instance: return(SymbolKind.Variable); case PythonMemberType.Enum: return(SymbolKind.Enum); case PythonMemberType.EnumInstance: return(SymbolKind.EnumMember); case PythonMemberType.Function: return(SymbolKind.Function); case PythonMemberType.Method: return(SymbolKind.Method); case PythonMemberType.Module: return(SymbolKind.Module); case PythonMemberType.Constant: return(SymbolKind.Constant); case PythonMemberType.Event: return(SymbolKind.Event); case PythonMemberType.Field: return(SymbolKind.Field); case PythonMemberType.Property: return(SymbolKind.Property); case PythonMemberType.Multiple: return(SymbolKind.Object); case PythonMemberType.Keyword: return(SymbolKind.None); case PythonMemberType.CodeSnippet: return(SymbolKind.None); case PythonMemberType.NamedArgument: return(SymbolKind.None); default: return(SymbolKind.None); } }
public MemberResult(string name, PythonMemberType type) { _name = _completion = name; _type = () => type; _vars = () => Empty; }
internal ConstantInfo(BuiltinClassInfo klass, object value, PythonMemberType memberType) : base(klass) { _value = value; _memberType = memberType; _builtinInfo = klass.Instance; }
public ConstantInfo(IPythonConstant value, PythonAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)) { _value = value; _memberType = value.MemberType; _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)).Instance; }
public IEnumerable <CompletionInfo> GetCompletions(IDjangoCompletionContext context, int position) { if (Expression == null) { return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField)); } else if (position <= Expression.Value.Length + ExpressionStart) { if (position - ExpressionStart - 1 >= 0 && Expression.Value[position - ExpressionStart - 1] == '.') { // TODO: Handle multiple dots string varName = Expression.Value.Substring(0, Expression.Value.IndexOf('.')); // get the members of this variable HashSet <AnalysisValue> values; if (context.Variables != null && context.Variables.TryGetValue(varName, out values)) { var newTags = new Dictionary <string, PythonMemberType>(); foreach (var member in values.SelectMany(item => item.GetAllMembers(context.ModuleContext))) { string name = member.Key; PythonMemberType type, newType = GetMemberType(member.Value); if (!newTags.TryGetValue(name, out type)) { newTags[name] = newType; } else if (type != newType && type != PythonMemberType.Unknown && newType != PythonMemberType.Unknown) { newTags[name] = PythonMemberType.Multiple; } } return(CompletionInfo.ToCompletionInfo(newTags)); } } else { return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField)); } } else if (Filters.Length > 0) { // we are triggering in the filter or arg area foreach (var curFilter in Filters) { if (position >= curFilter.FilterStart && position <= curFilter.FilterStart + curFilter.Filter.Length) { // it's in this filter area return(CompletionInfo.ToCompletionInfo(context.Filters, StandardGlyphGroup.GlyphKeyword)); } else if (curFilter.Arg != null && position >= curFilter.ArgStart && position < curFilter.ArgStart + curFilter.Arg.Value.Length) { // it's in this argument return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField)); } } if (String.IsNullOrWhiteSpace(Filters.Last().Filter)) { // last filter was blank, so provide filters return(CompletionInfo.ToCompletionInfo(context.Filters, StandardGlyphGroup.GlyphKeyword)); } else { // ... else, provide variables return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField)); } } return(Enumerable.Empty <CompletionInfo>()); }
private PythonMemberType GetMemberType() { bool includesNone = false; PythonMemberType result = PythonMemberType.Unknown; var allVars = _vars().SelectMany(ns => { var mmi = ns as MultipleMemberInfo; if (mmi != null) { return(mmi.Members); } else { return(Enumerable.Repeat(ns, 1)); } }); foreach (var ns in allVars) { if (ns == null) { Debug.Fail("Unexpected null AnalysisValue"); continue; } var nsType = ns.MemberType; var ci = ns as ConstantInfo; if (ci != null) { if (ci.ClassInfo == ci.ProjectState.ClassInfos[BuiltinTypeId.Function]) { nsType = PythonMemberType.Function; } else if (ci.ClassInfo == ci.ProjectState.ClassInfos[BuiltinTypeId.Type]) { nsType = PythonMemberType.Class; } } if (ns.TypeId == BuiltinTypeId.NoneType) { includesNone = true; } else if (result == PythonMemberType.Unknown) { result = nsType; } else if (result == nsType) { // No change } else if (result == PythonMemberType.Constant && nsType == PythonMemberType.Instance) { // Promote from Constant to Instance result = PythonMemberType.Instance; } else { return(PythonMemberType.Multiple); } } if (result == PythonMemberType.Unknown) { return(includesNone ? PythonMemberType.Constant : PythonMemberType.Instance); } return(result); }
public MemberResult(string name, PythonMemberType type) { _name = _completion = name; _type = () => type; _vars = () => Empty; }
public IronPythonGenericMember(IronPythonInterpreter interpreter, ObjectIdentityHandle obj, PythonMemberType type) : base(interpreter, obj) { _type = type; }
public AndWhichConstraint <VariableAssertions, IVariable> HaveMemberType(PythonMemberType memberType, string because = "", params object[] reasonArgs) { Value.Should().HaveMemberType(memberType, because, reasonArgs); return(new AndWhichConstraint <VariableAssertions, IVariable>(this, Subject)); }
public ConstantInfo(object value, PythonAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjectsThrowOnNull(projectState.GetTypeFromObject(value))) { _value = value; _memberType = PythonMemberType.Constant; _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(_type)).Instance; }
protected EmptyLocatedMember(IPythonModule declaringModule, PythonMemberType memberType) { DeclaringModule = declaringModule; MemberType = memberType; Location = new Location(DeclaringModule); }
internal CompletionResult(string name, PythonMemberType memberType) { _name = name; _completion = name; _memberType = memberType; }