private ObjectInfo PipFragmentInfo(EvaluationContext context, PipFragment pipFrag) { return(pipFrag.FragmentType == PipFragmentType.StringLiteral ? GetObjectInfo(context, pipFrag.GetStringIdValue()) : pipFrag.FragmentType == PipFragmentType.AbsolutePath ? GetObjectInfo(context, pipFrag.GetPathValue()) : pipFrag.FragmentType == PipFragmentType.NestedFragment ? GetObjectInfo(context, pipFrag.GetNestedFragmentValue()) : new ObjectInfo("{invalid}")); }
/// <summary> /// Returns a "VSCode Protocol" variable representing a given object. For the name of the returned /// variable, the <paramref name="variableName"/> argument is used verbatim; the value of the returned /// variable is the preview of the <paramref name="value"/> argument, exactly the same as it would be /// rendered in the "variables" pane in VSCode; finally, the a handle is created and the /// <see cref="IVariable.VariablesReference"/> field is set to non-zero if the object is compound /// (i.e., can be drilled down into). /// </summary> internal IVariable ObjectToVariable(EvaluationContext context, object value, string variableName) { // fetch info for the property to see if it's compound or not var propObjInfo = GetObjectInfo(context, value); var varRef = propObjInfo.Properties.Any() ? m_handles.Create(new ObjectContext(context, value)) : 0; // the VSCode debug protocol specifies 0 to mean "non-compound object" (one that has no properties) return(new Variable(variableName, propObjInfo.Preview, varRef)); }
private static List <Property> GetPackageProperties(EvaluationContext context, Package package) { Contract.Requires(context != null); Contract.Requires(package != null); return(new List <Property> { new Property(":name", package.Id.Name.ToString(context.StringTable)), new Property(":version", package.Id.Version.ToString(context.StringTable)), }); }
private static ObjectInfo ModuleLiteralInfo(EvaluationContext context, ModuleLiteral modLit) { Contract.Requires(context != null); Contract.Requires(modLit != null); string preview = GetModuleKind(modLit); var properties = new List <Property>(); PopulatePredefinedModuleLiteralProperties(modLit, properties, context); properties.AddRange(DictToProps(modLit.GetAllBindings(context))); return(new ObjectInfo(preview, properties)); }
private static ObjectLiteral GetQualifierSpaceValue(EvaluationContext context, QualifierSpaceId qualifierSpaceId) { Contract.Requires(context != null); Contract.Requires(context.FrontEndContext.QualifierTable.IsValidQualifierSpaceId(qualifierSpaceId)); var qualifierSpace = context.FrontEndContext.QualifierTable.GetQualifierSpace(qualifierSpaceId); var bindings = new List <Binding>(qualifierSpace.Keys.Count); foreach (var kvp in qualifierSpace.AsDictionary) { var values = ArrayLiteral.CreateWithoutCopy(kvp.Value.Select(s => EvaluationResult.Create(s.ToString(context.StringTable))).ToArray(), default(LineInfo), AbsolutePath.Invalid); bindings.Add(new Binding(kvp.Key, values, default(LineInfo))); } return(ObjectLiteral.Create(bindings, default(LineInfo), AbsolutePath.Invalid)); }
private ObjectInfo CallableValueInfo(EvaluationContext context, CallableValue cv) { if (cv.IsProperty) { return(GetObjectInfo(context, cv.Apply(context, EvaluationStackFrame.Empty()))); } var captures = EvaluationStackFrame.Empty(); var @null = UndefinedValue.Instance; Func <object> func = CreateFunc(); return(func != null ? FuncObjInfo(func, RenderCallableSignature(cv.CallableMember)) : new ObjectInfo("function(" + RenderCallableSignature(cv.CallableMember) + ")")); // Local functions Func <object> CreateFunc() { var undefined = EvaluationResult.Undefined; switch (cv.CallableMember.Kind) { case SyntaxKind.Function0: return(() => cv.Apply(context, captures).Value); case SyntaxKind.Function1 when cv.CallableMember.MinArity == 0: return(() => cv.Apply(context, undefined, captures).Value); case SyntaxKind.Function2 when cv.CallableMember.MinArity == 0: return(() => cv.Apply(context, undefined, undefined, captures).Value); case SyntaxKind.FunctionN when cv.CallableMember.MinArity == 0: return(() => cv.Apply(context, BuildXL.Utilities.Collections.CollectionUtilities.EmptyArray <EvaluationResult>(), captures).Value); } return(null); } }
internal IEnumerable <Property> GetAmbientProperties(EvaluationContext context, object obj) { if (obj == null) { return(Property.Empty); } AmbientDefinitionBase ambientDefinition; if (!((ModuleRegistry)context.FrontEndHost.ModuleRegistry).PredefinedTypes.AllAmbientDefinitions.TryGetValue(obj.GetType(), out ambientDefinition)) { return(Property.Empty); } return(ambientDefinition.GetCallableMembers(context.StringTable) // sort by: properties first, functions next; in both groups, sort by name .OrderBy(kvp => Invariant("{0}_{1}", kvp.Value.IsProperty ? 1 : 2, kvp.Key)) .Select(kvp => new Property( name: kvp.Key, value: TryBind(kvp.Value, obj) ?? "<error: couldn't bind callable member to receiver>", kind: kvp.Value.IsProperty ? CompletionItemType.property : CompletionItemType.method))); }
private static ObjectInfo PrimitiveObjInfo(EvaluationContext context, object obj) { return(new ObjectInfo(ToStringConverter.ObjectToString(context, obj))); }
private static ObjectInfo PackageInfo(EvaluationContext context, Package package) { return(new ObjectInfo("package", GetPackageProperties(context, package))); }
private static ObjectInfo ErrorValueInfo(EvaluationContext context) { Contract.Requires(context != null); return(new ObjectInfo("<error>")); }
private static void PopulatePredefinedModuleLiteralProperties(ModuleLiteral env, List <Property> properties, EvaluationContext context) { Contract.Requires(env != null); Contract.Requires(context != null); // TODO: path, package, and parent are not projectable from a module literal, but very useful for debugging. if (env.IsFileModule) { // TODO:ST: hide module instantiation from the clients! // This is last case when we need Id! UninstantiatedModuleInfo moduleInfo = context.ModuleRegistry.GetUninstantiatedModuleInfoByModuleId(env.Id); properties.AddRange(new[] { new Property(":path", env.Path.ToDisplayString(context)), new Property(":package", env.Package), new Property(":qualifierSpace", GetQualifierSpaceValue(context, moduleInfo.QualifierSpaceId)), }); } properties.Add(new Property(":parent", env.OuterScope)); if (env.IsFileModule) { properties.Add(new Property("qualifier", env.Qualifier.Qualifier)); } }
internal static ObjectInfo ObjectLiteralInfo(EvaluationContext context, ObjectLiteral objLit) { return(new ObjectInfo( "object{" + Invariant(objLit.Count) + "}", objLit.Members.Select(kvp => new Property(kvp.Key.ToString(context.StringTable), kvp.Value)).ToArray())); }
internal ObjectInfo GetObjectInfo(EvaluationContext context, object obj) { obj = obj is EvaluationResult evalResult ? evalResult.Value : obj; var result = IsInvalid(obj) ? s_nullObj : Match(obj, new CaseMatcher <ObjectInfo>[] { Case <ScopeLocals>(scope => new ObjectInfo(LocalsScopeName, null, Lazy.Create(() => GetLocalsForStackEntry(scope.EvalState, scope.FrameIndex)))), Case <ScopeCurrentModule>(scope => ModuleLiteralInfo(context, scope.Env).WithPreview(CurrentModuleScopeName)), Case <ScopePipGraph>(scope => PipGraphInfo(scope.Graph).WithPreview(PipGraphScopeName)), Case <ScopeAllModules>(scope => ArrayObjInfo(scope.EvaluatedModules).WithPreview(EvaluatedModulesScopeName)), Case <IModuleAndContext>(mc => GetObjectInfo(mc.Tree.RootContext, mc.Module)), Case <ObjectInfo>(objInf => objInf), Case <AmbientPlaceholder>(amb => new ObjectInfo(string.Empty, GetAmbientProperties(context, amb.Value).ToList())), Case <IPipGraph>(graph => PipGraphInfo(graph)), Case <Pip>(pip => GenericObjectInfo(pip, $"<{pip.PipType}>")), Case <PipProvenance>(prov => ProvenanceInfo(prov)), Case <EnvironmentVariable>(envVar => EnvironmentVariableInfo(envVar)), Case <PipFragment>(pipFrag => PipFragmentInfo(context, pipFrag)), Case <Thunk>(thunk => thunk.Value != null ? GetObjectInfo(context, thunk.Value) : new ObjectInfo("<not evaluated>")), Case <FunctionLikeExpression>(lambda => LambdaInfo(lambda)), Case <Closure>(cls => LambdaInfo(cls.Function)), Case <FullSymbol>(sym => new ObjectInfo(sym.ToString(context.FrontEndContext.SymbolTable))), Case <SymbolAtom>(sym => new ObjectInfo(sym.ToString(context.StringTable))), Case <StringId>(id => new ObjectInfo(id.ToString(context.StringTable))), Case <PipId>(id => new ObjectInfo($"{id.Value}")), Case <UndefinedLiteral>(_ => new ObjectInfo("undefined", UndefinedLiteral.Instance)), Case <UndefinedValue>(_ => new ObjectInfo("undefined", UndefinedValue.Instance)), Case <AbsolutePath>(path => new ObjectInfo($"p`{path.ToString(context.PathTable)}`", path)), Case <RelativePath>(path => new ObjectInfo($"r`{path.ToString(context.StringTable)}`", path)), Case <PathAtom>(atom => new ObjectInfo($"a`{atom.ToString(context.StringTable)}`", atom)), Case <FileArtifact>(file => new ObjectInfo($"f`{file.Path.ToString(context.PathTable)}`", file)), Case <DirectoryArtifact>(dir => new ObjectInfo($"d`{dir.Path.ToString(context.PathTable)}`", dir)), Case <uint>(num => new ObjectInfo($"{num}")), Case <short>(num => new ObjectInfo($"{num}", (int)num)), Case <long>(num => new ObjectInfo($"{num}")), Case <char>(ch => new ObjectInfo($"'{ch}'", ch.ToString())), Case <string>(str => new ObjectInfo($"\"{str}\"", str)), Case <Enum>(e => new ObjectInfo($"{e.GetType().Name}.{e}", e)), Case <NumberLiteral>(numLit => new ObjectInfo(numLit.UnboxedValue.ToString(), numLit)), Case <Func <object> >(func => FuncObjInfo(func)), Case <IEnumerable>(arr => ArrayObjInfo(arr.Cast <object>())), Case <ArrayLiteral>(arrLit => ArrayObjInfo(arrLit.Values.Select(v => v.Value)).WithOriginal(arrLit)), Case <ModuleBinding>(binding => GetObjectInfo(context, binding.Body)), Case <ModuleLiteral>(modLit => ModuleLiteralInfo(context, modLit)), Case <CallableValue>(cv => CallableValueInfo(context, cv).WithOriginal(cv)), Case <ErrorValue>(error => ErrorValueInfo(context)), Case <Package>(package => PackageInfo(context, package)), Case <ObjectLiteral>(objLit => ObjectLiteralInfo(context, objLit).WithOriginal(objLit)), Case <object>(o => o.GetType().IsArray ? ArrayObjInfo(((IEnumerable)o).Cast <object>()) : PrimitiveObjInfo(context, o)), }, defaultResult: s_nullObj); var ambientProperties = obj is AmbientPlaceholder ? new Property[0] : new[] { new Property("__prototype__", new AmbientPlaceholder(obj)) }; return(new ObjectInfo(result.Preview, result.Properties.Concat(ambientProperties).ToArray())); }