public IntellisenseData(IIntellisenseContext context, DType expectedType, TexlBinding binding, TexlFunction curFunc, TexlNode curNode, int argIndex, int argCount, IsValidSuggestion isValidSuggestionFunc, IList <DType> missingTypes, List <CommentToken> comments) { Contracts.AssertValue(context); Contracts.AssertValid(expectedType); Contracts.AssertValue(binding); Contracts.AssertValue(curNode); Contracts.Assert(0 <= context.CursorPosition && context.CursorPosition <= context.InputText.Length); Contracts.AssertValue(isValidSuggestionFunc); Contracts.AssertValueOrNull(missingTypes); Contracts.AssertValueOrNull(comments); _expectedType = expectedType; _suggestions = new IntellisenseSuggestionList(); _substringSuggestions = new IntellisenseSuggestionList(); _binding = binding; _comments = comments; _curFunc = curFunc; _curNode = curNode; _script = context.InputText; _cursorPos = context.CursorPosition; _argIndex = argIndex; _argCount = argCount; _isValidSuggestionFunc = isValidSuggestionFunc; _matchingStr = string.Empty; _matchingLength = 0; _replacementStartIndex = context.CursorPosition; _missingTypes = missingTypes; BoundTo = string.Empty; _cleanupHandlers = new List <ISpecialCaseHandler>(); }
public static CoercionKind GetCoercionKind(DType fromType, DType toType) { Contracts.AssertValid(fromType); Contracts.AssertValid(toType); if (!fromType.IsAggregate && !fromType.IsOptionSet && !fromType.IsView && fromType == toType) { return(CoercionKind.None); } if (fromType.IsAggregate && toType.Kind == DKind.DataEntity) { return(CoercionKind.AggregateToDataEntity); } if (toType.IsLargeImage && (fromType.Kind == DKind.Image || fromType == DType.MinimalLargeImage)) { if (fromType.Kind == DKind.Image) { return(CoercionKind.ImageToLargeImage); } else { return(CoercionKind.SingleColumnRecordToLargeImage); } } return(FlattenCoercionMatrix(fromType, toType)); }
public IntellisenseSuggestion(UIString text, SuggestionKind kind, SuggestionIconKind iconKind, DType type, string exactMatch, int argCount, string definition, string functionName, string functionParamDescription, uint sortPriority = 0) { Contracts.AssertValue(text); Contracts.AssertNonEmpty(text.Text); Contracts.AssertValid(type); Contracts.AssertValue(exactMatch); Contracts.AssertValue(definition); Contracts.Assert(argCount >= -1); Contracts.AssertValueOrNull(functionName); Contracts.AssertValueOrNull(functionParamDescription); DisplayText = text; _overloads = new List <IIntellisenseSuggestion>(); _text = text.Text; Kind = kind; IconKind = iconKind; Type = type; _argIndex = -1; ExactMatch = exactMatch; _argCount = argCount; FunctionName = functionName; SortPriority = sortPriority; ShouldPreselect = sortPriority != 0; FunctionParameterDescription = functionParamDescription ?? string.Empty; Definition = definition; IsTypeMatch = false; }
internal static IEnumerable <KeyValuePair <string, DType> > GetSuggestionsFromType(DType typeToSuggestFrom, DType suggestionType) { Contracts.AssertValid(typeToSuggestFrom); Contracts.AssertValid(suggestionType); // If no suggestion type provided, accept all suggestions. if (suggestionType == DType.Invalid) { suggestionType = DType.Error; } List <KeyValuePair <string, DType> > suggestions = new List <KeyValuePair <string, DType> >(); foreach (TypedName tName in typeToSuggestFrom.GetNames(DPath.Root)) { if (suggestionType.Accepts(tName.Type)) { var usedName = tName.Name.Value; string maybeDisplayName; if (DType.TryGetDisplayNameForColumn(typeToSuggestFrom, usedName, out maybeDisplayName)) { usedName = maybeDisplayName; } suggestions.Add(new KeyValuePair <string, DType>(usedName, tName.Type)); } } return(suggestions); }
public ColumnMetadata(string name, DType schema, DataFormat?dataFormat, string displayName, bool isReadOnly, bool isKey, bool isRequired, ColumnCreationKind creationKind, ColumnVisibility visibility, string titleColumnName, string subtitleColumnName, string thumbnailColumnName, ColumnLookupMetadata?lookupMetadata, ColumnAttachmentMetadata?attachmentMetadata) { Contracts.AssertNonEmpty(name); Contracts.AssertValid(schema); Contracts.AssertOneOfValueTypeOrNull(dataFormat, DataTypeInfo.GetValidDataFormats(schema.Kind)); Contracts.AssertNonEmpty(displayName); Contracts.AssertNonEmptyOrNull(titleColumnName); Contracts.AssertNonEmptyOrNull(subtitleColumnName); Contracts.AssertNonEmptyOrNull(thumbnailColumnName); Contracts.AssertValueOrNull(lookupMetadata); Contracts.AssertValueOrNull(attachmentMetadata); Name = name; Type = schema; DataFormat = dataFormat; DisplayName = displayName; IsReadOnly = isReadOnly; IsKey = isKey; IsRequired = isRequired; _kind = creationKind; _visibility = visibility; TitleColumnName = titleColumnName; SubtitleColumnName = subtitleColumnName; ThumbnailColumnName = thumbnailColumnName; LookupMetadata = lookupMetadata; AttachmentMetadata = attachmentMetadata; if (dataFormat == PowerFx.Core.App.DataFormat.AllowedValues) { AllowedValues = AllowedValuesMetadata.CreateForValue(schema); } }
public static string GetSortComparatorIdForType(DType type) { Contracts.AssertValid(type); switch (type.Kind) { case DKind.Boolean: return("0"); case DKind.Number: case DKind.Color: case DKind.Currency: case DKind.Date: case DKind.Time: case DKind.DateTime: return("1"); case DKind.String: case DKind.Image: case DKind.PenImage: case DKind.Hyperlink: case DKind.Media: case DKind.Blob: default: Contracts.Assert(DType.String.Accepts(type, exact: false)); return("2"); } }
public void Errors(TexlNode node, DType nodeType, KeyValuePair <string, DType> schemaDifference, DType schemaDifferenceType) { Contracts.AssertValue(node); Contracts.AssertValid(nodeType); Error(DocumentErrorSeverity.Severe, node, TexlStrings.ErrBadSchema_ExpectedType, nodeType.GetKindString()); // If there's no schema difference, this was just an invalid type. if (string.IsNullOrEmpty(schemaDifference.Key)) { return; } if (schemaDifferenceType.IsValid) { Error( DocumentErrorSeverity.Severe, node, TexlStrings.ErrColumnTypeMismatch_ColName_ExpectedType_ActualType, schemaDifference.Key, schemaDifference.Value.GetKindString(), schemaDifferenceType.GetKindString()); } else { Error( DocumentErrorSeverity.Severe, node, TexlStrings.ErrColumnMissing_ColName_ExpectedType, schemaDifference.Key, schemaDifference.Value.GetKindString()); } }
public override OperationCapabilityMetadata Parse(JsonElement dataServiceCapabilitiesJsonObject, DType schema) { Contracts.AssertValid(schema); Dictionary <DPath, DelegationCapability> columnRestrictions = new Dictionary <DPath, DelegationCapability>(); if (!dataServiceCapabilitiesJsonObject.TryGetProperty(CapabilitiesConstants.Group_Restriction, out var groupRestrictionJsonObject)) { return(null); } if (groupRestrictionJsonObject.TryGetProperty(CapabilitiesConstants.Group_UngroupableProperties, out var ungroupablePropertiesJsonArray)) { foreach (var prop in ungroupablePropertiesJsonArray.EnumerateArray()) { var columnName = new DName(prop.GetString()); var columnPath = DPath.Root.Append(columnName); if (!columnRestrictions.ContainsKey(columnPath)) { columnRestrictions.Add(columnPath, new DelegationCapability(DelegationCapability.Group)); } } } return(new GroupOpMetadata(schema, columnRestrictions)); }
public void MarkSinkTypeError(DName name) { Contracts.AssertValid(name); Contracts.Assert(!_nameMapIDs.Contains(name.Value)); _nameMapIDs.Add(name.Value); }
public RecordFieldAccessNode(IRContext irContext, IntermediateNode from, DName field) : base(irContext) { Contracts.AssertValid(field); Contracts.AssertValue(from); From = from; Field = field; }
public bool IsColumnSearchable(DPath columnPath) { Contracts.AssertValid(columnPath); return(IsDelegationSupportedByColumn(columnPath, DelegationCapability.Filter | DelegationCapability.Contains) || IsDelegationSupportedByColumn(columnPath, DelegationCapability.Filter | DelegationCapability.IndexOf | DelegationCapability.GreaterThan) || IsDelegationSupportedByColumn(columnPath, DelegationCapability.Filter | DelegationCapability.SubStringOf | DelegationCapability.Equal)); }
public SingleColumnTableAccessNode(IRContext irContext, IntermediateNode from, DName field) : base(irContext) { Contracts.AssertValid(field); Contracts.AssertValue(from); From = from; Field = field; }
public AsInfo(AsNode node, DName identifier) { Contracts.AssertValue(node); Contracts.AssertValid(identifier); AsIdentifier = identifier; Node = node; }
public bool Matches(DName leftIdentifier, DName rightIdentifier) { Contracts.AssertValid(leftIdentifier); Contracts.AssertValid(rightIdentifier); FirstNameNode leftName; return((leftName = Left as FirstNameNode) != null && leftName.Ident.Name == leftIdentifier && Right.Name == rightIdentifier); }
public VariableDefinition(DName name, bool isGlobal, TexlNode node) { Contracts.AssertValid(name); Contracts.AssertValue(node); Name = name; IsGlobal = isGlobal; Node = node; }
public ControlKeywordInfo(NameNode node, DPath path, IExternalControl data) : base(BindKind.Control, node.VerifyValue()) { Contracts.AssertValid(path); Contracts.AssertValueOrNull(data); Path = path; Data = data; }
internal static IEnumerable <KeyValuePair <string, DType> > GetColumnNameStringSuggestions(DType scopeType) { Contracts.AssertValid(scopeType); foreach (var name in scopeType.GetNames(DPath.Root)) { yield return(new KeyValuePair <string, DType>(("\"" + CharacterUtils.ExcelEscapeString(name.Name.Value) + "\""), name.Type)); } }
/// <summary> /// Suggest possibilities that can come after a value of a certain type. /// </summary> internal static void AddSuggestionsForAfterValue(IntellisenseData.IntellisenseData intellisenseData, DType type) { Contracts.AssertValue(intellisenseData); Contracts.AssertValid(type); intellisenseData.Suggestions.Clear(); intellisenseData.SubstringSuggestions.Clear(); intellisenseData.SetMatchArea(intellisenseData.ReplacementStartIndex, intellisenseData.ReplacementStartIndex); AddSuggestionsForMatches(intellisenseData, TexlLexer.LocalizedInstance.GetOperatorKeywords(type), SuggestionKind.BinaryOperator, SuggestionIconKind.Other, requiresSuggestionEscaping: false); }
private bool IsSortOrderSuppportedByColumn(string order, SortOpMetadata metadata, DPath columnPath) { Contracts.AssertValue(order); Contracts.AssertValue(metadata); Contracts.AssertValid(columnPath); order = order.ToLower(); // If column is marked as ascending only then return false if order requested is descending. return(order != Microsoft.PowerFx.Core.Utils.LanguageConstants.DescendingSortOrderString || !metadata.IsColumnAscendingOnly(columnPath)); }
public DelegationMetadata(DType schema, string delegationMetadataJson) { Contracts.AssertValid(schema); var metadataParser = new DelegationMetadataParser(); _compositeMetadata = metadataParser.Parse(delegationMetadataJson, schema); Contracts.AssertValue(_compositeMetadata); Schema = schema; }
public TabularDataQueryOptions GetQueryOptions(DName tabularDataSourceInfoName) { Contracts.AssertValid(tabularDataSourceInfoName); if (_tabularDataQueryOptionsSet.ContainsKey(tabularDataSourceInfoName)) { return(_tabularDataQueryOptionsSet[tabularDataSourceInfoName]); } return(null); }
public ScopedNameLookupInfo(DType type, int argIndex, DName namesp, DName name, bool isStateful) { Contracts.AssertValid(type); Contracts.AssertValid(name); Type = type; ArgIndex = argIndex; Namespace = namesp; Name = name; IsStateful = isStateful; }
public static UIString DisambiguateGlobals(IntellisenseSuggestionList curList, UIString curSuggestion, SuggestionKind suggestionKind, DType type) { Contracts.AssertValue(curList); Contracts.AssertValue(curSuggestion); Contracts.AssertValid(type); UIString retVal = curSuggestion; string sug = curSuggestion.Text; bool suggestionKindIsGlobalOrScope = (suggestionKind == SuggestionKind.Global || suggestionKind == SuggestionKind.ScopeVariable); foreach (var s in curList.SuggestionsForText(sug)) { // Retrive global/appVariable suggestions which // -- Don't have the same type as current suggestion (because, if it's of same type, it will be filtered out anyway) // -- Match the current suggestion text (filtered in the loop definition above for efficiency) if ((!suggestionKindIsGlobalOrScope && s.Kind != SuggestionKind.Global && s.Kind != SuggestionKind.ScopeVariable) || s.Type == type) { continue; } // The retrived list represents collisions. Update the suggestion text with global disambiguation. int punctuatorLen = TexlLexer.PunctuatorAt.Length + TexlLexer.PunctuatorAt.Length; // The suggestion already in the list is global. Update it. if (s.Kind == SuggestionKind.Global || s.Kind == SuggestionKind.ScopeVariable) { int index = curList.IndexOf(s); Contracts.Assert(index >= 0); UIString dispText = curList[index].DisplayText; // If we are already using the global syntax, we should not add it again. if (dispText.Text.StartsWith(TexlLexer.PunctuatorBracketOpen + TexlLexer.PunctuatorAt)) { continue; } curList.UpdateDisplayText(index, new UIString(TexlLexer.PunctuatorBracketOpen + TexlLexer.PunctuatorAt + dispText.Text + TexlLexer.PunctuatorBracketClose, dispText.HighlightStart + punctuatorLen, dispText.HighlightEnd + punctuatorLen)); } // Current suggestion is global. Update it. else { retVal = new UIString(TexlLexer.PunctuatorBracketOpen + TexlLexer.PunctuatorAt + sug + TexlLexer.PunctuatorBracketClose, curSuggestion.HighlightStart + punctuatorLen, curSuggestion.HighlightEnd + punctuatorLen); } } return(retVal); }
protected bool TryGetColumnRestrictions(DPath columnPath, out DelegationCapability restrictions) { Contracts.AssertValid(columnPath); if (ColumnRestrictions.TryGetValue(columnPath, out restrictions)) { return(true); } restrictions = DelegationCapability.None; return(false); }
public DataColumnMetadata(string name, DType type, DataTableMetadata tableMetadata) { Contracts.AssertValue(name); Contracts.AssertValid(type); Contracts.AssertValue(tableMetadata); Name = name; Type = type; ParentTableMetadata = tableMetadata; IsSearchable = false; IsSearchRequired = false; IsExpandEntity = true; }
// Returns true if column is marked as AscendingOnly. public bool IsColumnAscendingOnly(DPath columnPath) { Contracts.AssertValid(columnPath); DelegationCapability columnRestrictions; if (!TryGetColumnRestrictions(columnPath, out columnRestrictions)) { return(false); } return(columnRestrictions.HasCapability(DelegationCapability.SortAscendingOnly)); }
public virtual bool IsUnaryOpInDelegationSupportedByColumn(UnaryOp op, DPath columnPath) { Contracts.AssertValid(columnPath); if (!IsUnaryOpInDelegationSupported(op)) { return(false); } Contracts.Assert(DelegationCapability.UnaryOpToDelegationCapabilityMap.ContainsKey(op)); return(IsDelegationSupportedByColumn(columnPath, DelegationCapability.UnaryOpToDelegationCapabilityMap[op])); }
private static IEnumerable <KeyValuePair <string, DType> > StringTypeSuggestions(DType scopeType, int argumentIndex, out bool requiresSuggestionEscaping) { Contracts.AssertValid(scopeType); Contracts.Assert(0 <= argumentIndex); requiresSuggestionEscaping = true; if (argumentIndex == 0) { return(IntellisenseHelper.GetSuggestionsFromType(scopeType, DType.String)); } return(EnumerableUtils.Yield <KeyValuePair <string, DType> >()); }
// Verifies if provided column node supports delegation. protected bool IsDelegatableColumnNode(FirstNameNode node, TexlBinding binding, IOpDelegationStrategy opDelStrategy, DelegationCapability capability) { Contracts.AssertValue(node); Contracts.AssertValue(binding); Contracts.AssertValueOrNull(opDelStrategy); Contracts.Assert(binding.IsRowScope(node)); FirstNameInfo firstNameInfo = binding.GetInfo(node.AsFirstName()); if (firstNameInfo == null) { return(false); } IDelegationMetadata metadata = GetCapabilityMetadata(firstNameInfo); // This means that this row scoped field is from some parent scope which is non-delegatable. That should deny delegation at that point. // For this scope, this means that value will be provided from some other source. // For example, AddColumns(CDS, "Column1", LookUp(CDS1, Name in FirstName)) // CDS - *[Name:s], CDS1 - *[FirstName:s] if (metadata == null) { return(true); } var columnName = firstNameInfo.Name; Contracts.AssertValid(columnName); var columnPath = DPath.Root.Append(columnName); if (!metadata.FilterDelegationMetadata.IsDelegationSupportedByColumn(columnPath, capability)) { var safeColumnName = CharacterUtils.MakeSafeForFormatString(columnName.Value); var message = string.Format(StringResources.Get(TexlStrings.OpNotSupportedByColumnSuggestionMessage_OpNotSupportedByColumn), safeColumnName); SuggestDelegationHintAndAddTelemetryMessage(node, binding, message, TexlStrings.OpNotSupportedByColumnSuggestionMessage_OpNotSupportedByColumn, safeColumnName); TrackingProvider.Instance.SetDelegationTrackerStatus(DelegationStatus.NoDelSupportByColumn, node, binding, _function, DelegationTelemetryInfo.CreateNoDelSupportByColumnTelemetryInfo(firstNameInfo)); return(false); } // If there is any operator applied on this node then check if column supports operation. if (opDelStrategy != null && !opDelStrategy.IsOpSupportedByColumn(metadata.FilterDelegationMetadata, node.AsFirstName(), columnPath, binding)) { return(false); } return(true); }
public override OperationCapabilityMetadata Parse(JsonElement dataServiceCapabilitiesJsonObject, DType schema) { Contracts.AssertValid(schema); Dictionary <DPath, DPath> oDataReplacement = new Dictionary <DPath, DPath>(); if (dataServiceCapabilitiesJsonObject.TryGetProperty(CapabilitiesConstants.ColumnsCapabilities, out var columnCapabilitiesJsonObj)) { foreach (var column in columnCapabilitiesJsonObj.EnumerateObject()) { var columnPath = DPath.Root.Append(new DName(column.Name)); var capabilitiesDefinedByColumn = column.Value; if (capabilitiesDefinedByColumn.TryGetProperty(CapabilitiesConstants.Capabilities, out var columnCapabilities)) { if (columnCapabilities.TryGetProperty(CapabilitiesConstants.PropertyIsChoice, out var choice) && choice.GetBoolean()) { oDataReplacement.Add(columnPath.Append(new DName(ValueProperty)), columnPath); } } if (!capabilitiesDefinedByColumn.TryGetProperty(CapabilitiesConstants.Properties, out var propertyCapabilities)) { continue; } foreach (var property in propertyCapabilities.EnumerateObject()) { var propertyPath = columnPath.Append(new DName(property.Name)); var capabilitiesDefinedByColumnProperty = property.Value; if (!capabilitiesDefinedByColumnProperty.TryGetProperty(CapabilitiesConstants.Capabilities, out var propertyCapabilityJsonObject)) { continue; } if (propertyCapabilityJsonObject.TryGetProperty(CapabilitiesConstants.PropertyQueryAlias, out var alias)) { oDataReplacement.Add(propertyPath, getReplacementPath(alias.GetString(), columnPath)); } } } } return(new ODataOpMetadata(schema, oDataReplacement)); }