static DirectoryInfo Resolve(ICompletionContext context) { var path = context.DocumentTextProvider.GetText(context.Current.Start, context.Current.Length); var segments = path.Trim('"').Split('/'); var directory = context.Document.Source.Directory; for (int i = 0; i < segments.Length - 1; i++) { // make sure we still have directory if (directory == null) { return(null); } // handle parent navigation var segment = segments[i]; if (segment == "..") { directory = directory.Parent; continue; } var candidates = directory.GetDirectories(segments[i]); if (candidates.Length == 0) { return(null); } directory = candidates[0]; } return(directory); }
protected override void OnCompleteType( ICompletionContext context, DirectiveTypeDefinition definition) { base.OnCompleteType(context, definition); _converter = context.Services.GetTypeConversion(); MiddlewareComponents = definition.MiddlewareComponents.ToList().AsReadOnly(); SyntaxNode = definition.SyntaxNode; ClrType = definition.ClrType == GetType() ? typeof(object) : definition.ClrType; IsRepeatable = definition.IsRepeatable; Locations = definition.Locations.ToList().AsReadOnly(); Arguments = new FieldCollection <Argument>( definition.Arguments.Select(t => new Argument(t))); IsExecutable = MiddlewareComponents.Count > 0; if (!Locations.Any()) { // TODO : resources context.ReportError(SchemaErrorBuilder.New() .SetMessage( $"The `{Name}` directive does not declare any " + "location on which it is valid.") .SetCode(TypeErrorCodes.MissingType) .SetTypeSystemObject(context.Type) .AddSyntaxNode(definition.SyntaxNode) .Build()); } FieldInitHelper.CompleteFields(context, definition, Arguments); }
public static void CompleteFields <TTypeDef, TFieldType, TFieldDef>( ICompletionContext context, TTypeDef definition, IReadOnlyCollection <FieldBase <TFieldType, TFieldDef> > fields) where TTypeDef : DefinitionBase, IHasSyntaxNode where TFieldType : IType where TFieldDef : FieldDefinitionBase { if (context.Type is IType type && fields.Count == 0) { context.ReportError(SchemaErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.FieldInitHelper_NoFields)) .SetCode(TypeErrorCodes.MissingType) .SetTypeSystemObject(context.Type) .AddSyntaxNode(definition.SyntaxNode) .Build()); return; } foreach (FieldBase <TFieldType, TFieldDef> field in fields) { field.CompleteField(context); } }
public IEnumerable <SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; var position = context.Position; if (current is PropertyDeclaration) { yield return(SassCompletionContextType.PropertyValue); } else if (IsInDeclarationContext(current)) { yield return(SassCompletionContextType.PropertyDeclaration); } else { var declaration = FindDeclaration(current); if (declaration == null) { yield break; } if (declaration.Colon == null || declaration.Colon.Start > position) { yield return(SassCompletionContextType.PropertyName); } else if (declaration.Colon != null && (declaration.End > position || declaration.IsUnclosed)) { yield return(SassCompletionContextType.PropertyValue); } } }
protected override void OnCompleteType( ICompletionContext context, EnumTypeDefinition definition) { base.OnCompleteType(context, definition); SyntaxNode = definition.SyntaxNode; foreach (EnumValue enumValue in definition.Values .Select(t => new EnumValue(t))) { _nameToValues[enumValue.Name] = enumValue; _valueToValues[enumValue.Value] = enumValue; enumValue.CompleteValue(context); } if (!Values.Any()) { context.ReportError( SchemaErrorBuilder.New() .SetMessage(TypeResources.EnumType_NoValues, Name) .SetCode(ErrorCodes.Schema.NoEnumValues) .SetTypeSystemObject(this) .AddSyntaxNode(SyntaxNode) .Build()); } }
private void CompleteAbstractTypeResolver( ICompletionContext context, ResolveAbstractType resolveAbstractType) { if (resolveAbstractType == null) { Func <ISchema> schemaResolver = context.GetSchemaResolver(); // if there is no custom type resolver we will use this default // abstract type resolver. IReadOnlyCollection <ObjectType> types = null; _resolveAbstractType = (c, r) => { if (types == null) { ISchema schema = schemaResolver.Invoke(); types = schema.GetPossibleTypes(this); } foreach (ObjectType type in types) { if (type.IsOfType(c, r)) { return(type); } } return(null); }; } else { _resolveAbstractType = resolveAbstractType; } }
public static IValueNode CreateDefaultValue( ICompletionContext context, ArgumentDefinition definition, IInputType fieldType) { try { if (definition.NativeDefaultValue != null) { return(fieldType.ParseValue( definition.NativeDefaultValue)); } return(definition.DefaultValue.IsNull() ? NullValueNode.Default : definition.DefaultValue); } catch (Exception ex) { // TODO : RESOURCES context.ReportError(SchemaErrorBuilder.New() .SetMessage( "Could not parse the native value of input field " + $"`{context.Type.Name}.{definition.Name}`.") .SetCode(TypeErrorCodes.MissingType) .SetTypeSystemObject(context.Type) .AddSyntaxNode(definition.SyntaxNode) .SetException(ex) .Build()); return(NullValueNode.Default); } }
public IEnumerable <SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (IsDefinitionScope(current)) { yield return(SassCompletionContextType.VariableName); } else if (current is VariableDefinition && IsDefinitionScope(current.Parent)) { var definition = current as VariableDefinition; if (definition.Name == null) { yield return(SassCompletionContextType.VariableName); } else { yield return(SassCompletionContextType.VariableValue); if (definition.Values.Any(x => x.IsValid)) { yield return(SassCompletionContextType.VariableDefaultFlag); } } } else if (IsUnclosedVariable(current)) { yield return(SassCompletionContextType.VariableDefaultFlag); } }
protected override void OnCompleteType( ICompletionContext context, DirectiveTypeDefinition definition) { base.OnCompleteType(context, definition); _converter = context.Services.GetTypeConversion(); MiddlewareComponents = definition.MiddlewareComponents.ToList().AsReadOnly(); SyntaxNode = definition.SyntaxNode; Locations = definition.Locations.ToList().AsReadOnly(); Arguments = new FieldCollection <Argument>( definition.Arguments.Select(t => new Argument(t))); IsExecutable = MiddlewareComponents.Count > 0; if (Locations.Count == 0) { context.ReportError(SchemaErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.DirectiveType_NoLocations, Name)) .SetCode(ErrorCodes.Schema.MissingType) .SetTypeSystemObject(context.Type) .AddSyntaxNode(definition.SyntaxNode) .Build()); } FieldInitHelper.CompleteFields(context, definition, Arguments); }
public static DirectiveCollection CreateAndComplete( ICompletionContext context, object source, IEnumerable <DirectiveDefinition> directiveDefinitions) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (source is null) { throw new ArgumentNullException(nameof(source)); } if (directiveDefinitions is null) { throw new ArgumentNullException(nameof(directiveDefinitions)); } var directives = new DirectiveCollection( source, directiveDefinitions); directives.CompleteCollection(context); return(directives); }
public static IValueNode CreateDefaultValue( ICompletionContext context, ArgumentDefinition definition, IInputType fieldType) { try { if (definition.NativeDefaultValue != null) { return(fieldType.ParseValue( definition.NativeDefaultValue)); } return(definition.DefaultValue.IsNull() ? NullValueNode.Default : definition.DefaultValue); } catch (Exception ex) { context.ReportError(SchemaErrorBuilder.New() .SetMessage(TypeResources.FieldInitHelper_InvalidDefaultValue) .SetCode(TypeErrorCodes.MissingType) .SetTypeSystemObject(context.Type) .AddSyntaxNode(definition.SyntaxNode) .SetException(ex) .Build()); return(NullValueNode.Default); } }
internal sealed override void CompleteName(ICompletionContext context) { context.Interceptor.OnBeforeCompleteName( context, Definition, Definition.ContextData); ExecuteConfigurations(context, ApplyConfigurationOn.Naming); OnCompleteName(context, Definition); if (Name.IsEmpty) { context.ReportError(SchemaErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.TypeSystemObjectBase_NameIsNull, GetType().FullName)) .SetCode(ErrorCodes.Schema.NoName) .SetTypeSystemObject(this) .Build()); } base.CompleteName(context); context.Interceptor.OnAfterCompleteName( context, Definition, Definition.ContextData); }
public static void MergeDirectives( ICompletionContext context, IList <DirectiveDefinition> extension, IList <DirectiveDefinition> type) { var directives = new List <(DirectiveType type, DirectiveDefinition def)>(); foreach (DirectiveDefinition directive in type) { DirectiveType directiveType = context.GetDirectiveType(directive.Reference); directives.Add((directiveType, directive)); } foreach (DirectiveDefinition directive in extension) { MergeDirective(context, directives, directive); } type.Clear(); foreach (DirectiveDefinition directive in directives.Select(t => t.def)) { type.Add(directive); } }
internal override void Merge( ICompletionContext context, INamedType type) { if (type is ObjectType objectType) { TypeExtensionHelper.MergeContextData( Definition, objectType.Definition); TypeExtensionHelper.MergeDirectives( context, Definition.Directives, objectType.Definition.Directives); TypeExtensionHelper.MergeObjectFields( context, Definition.Fields, objectType.Definition.Fields); } else { throw new ArgumentException( TypeResources.ObjectTypeExtension_CannotMerge); } }
private static void MergeOutputFields <T>( ICompletionContext context, IList <T> extensionFields, IList <T> typeFields, Action <IList <T>, T, T> action) where T : OutputFieldDefinitionBase { MergeFields(context, extensionFields, typeFields, (fields, extensionField, typeField) => { if (extensionField.IsDeprecated) { typeField.DeprecationReason = extensionField.DeprecationReason; } MergeFields( context, extensionField.Arguments, typeField.Arguments, (args, extensionArg, typeArg) => { }); action(fields, extensionField, typeField); }); }
internal override void Merge( ICompletionContext context, INamedType type) { if (type is InputObjectType inputObjectType) { TypeExtensionHelper.MergeContextData( Definition, inputObjectType.Definition); TypeExtensionHelper.MergeDirectives( context, Definition.Directives, inputObjectType.Definition.Directives); TypeExtensionHelper.MergeInputObjectFields( context, Definition.Fields, inputObjectType.Definition.Fields); TypeExtensionHelper.MergeConfigurations( Definition.Configurations, inputObjectType.Definition.Configurations); } else { throw new ArgumentException( TypeResources.InputObjectTypeExtension_CannotMerge, nameof(type)); } }
private void CompleteInterfaces( ICompletionContext context, ObjectTypeDefinition definition) { if (ClrType != typeof(object)) { foreach (Type interfaceType in ClrType.GetInterfaces()) { if (context.TryGetType( new ClrTypeReference(interfaceType, TypeContext.Output), out InterfaceType type)) { _interfaces[type.Name] = type; } } } foreach (ITypeReference interfaceRef in definition.Interfaces) { if (!context.TryGetType(interfaceRef, out InterfaceType type)) { // TODO : resources context.ReportError(SchemaErrorBuilder.New() .SetMessage( "COULD NOT RESOLVE INTERFACE") .SetCode(ErrorCodes.Schema.MissingType) .SetTypeSystemObject(this) .AddSyntaxNode(SyntaxNode) .Build()); } _interfaces[type.Name] = type; } }
private void CompleteTypeSet( ICompletionContext context, UnionTypeDefinition definition) { var typeSet = new HashSet <ObjectType>(); OnCompleteTypeSet(context, definition, typeSet); foreach (ObjectType objectType in typeSet) { _typeMap[objectType.Name] = objectType; } if (typeSet.Count == 0) { // TODO : RESOURCES context.ReportError(SchemaErrorBuilder.New() .SetMessage("A Union type must define one or " + "more unique member types.") .SetCode(TypeErrorCodes.MissingType) .SetTypeSystemObject(this) .AddSyntaxNode(SyntaxNode) .Build()); } }
protected override void OnCompleteType( ICompletionContext context, InputObjectTypeDefinition definition) { base.OnCompleteType(context, definition); ITypeConversion typeConversion = context.Services.GetTypeConversion(); _objectToValueConverter = new InputObjectToObjectValueConverter(typeConversion); _valueToObjectConverter = new ObjectValueToInputObjectConverter(typeConversion); _objectToDictionary = new InputObjectToDictionaryConverter(typeConversion); _dictionaryToObject = new DictionaryToInputObjectConverter(typeConversion); SyntaxNode = definition.SyntaxNode; var fields = new List <InputField>(); OnCompleteFields(context, definition, fields); Fields = new FieldCollection <InputField>(fields); FieldInitHelper.CompleteFields(context, definition, Fields); }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { switch (type) { // standard variable references case SassCompletionContextType.ConditionalDirectiveExpression: case SassCompletionContextType.EachDirectiveListValue: case SassCompletionContextType.FunctionBody: case SassCompletionContextType.PropertyValue: case SassCompletionContextType.StringInterpolationValue: case SassCompletionContextType.VariableName: case SassCompletionContextType.VariableValue: case SassCompletionContextType.WhileLoopCondition: return context.Cache.GetVariables(context.Position); case SassCompletionContextType.FunctionArgumentDefaultValue: case SassCompletionContextType.IncludeDirectiveMixinArgument: case SassCompletionContextType.IncludeDirectiveMixinArgumentName: case SassCompletionContextType.IncludeDirectiveMixinArgumentValue: case SassCompletionContextType.MixinDirectiveMixinArgumentDefaultValue: // TODO: named arguments break; } return Enumerable.Empty<ICompletionValue>(); }
static DirectoryInfo Resolve(ICompletionContext context) { var path = context.DocumentTextProvider.GetText(context.Current.Start, context.Current.Length); var segments = path.Trim('"').Split('/'); var directory = context.Document.Source.Directory; for (int i = 0; i < segments.Length - 1; i++) { // make sure we still have directory if (directory == null) return null; // handle parent navigation var segment = segments[i]; if (segment == "..") { directory = directory.Parent; continue; } var candidates = directory.GetDirectories(segments[i]); if (candidates.Length == 0) return null; directory = candidates[0]; } return directory; }
private bool ValidateFields( ICompletionContext context, ObjectTypeDefinition definition) { ObjectFieldDefinition[] invalidFields = definition.Fields.Where(t => t.Type is null).ToArray(); foreach (ObjectFieldDefinition field in invalidFields) { // TODO : resources context.ReportError(SchemaErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, "Unable to infer or resolve the type of " + "field {0}.{1}. Try to explicitly provide the " + "type like the following: " + "`descriptor.Field(\"field\")" + ".Type<List<StringType>>()`.", Name, field.Name)) .SetCode(ErrorCodes.Schema.NoFieldType) .SetTypeSystemObject(this) .SetPath(Path.New(Name).Append(field.Name)) .SetExtension(TypeErrorFields.Definition, field) .Build()); } return(invalidFields.Length == 0); }
internal override void Merge( ICompletionContext context, INamedType type) { if (type is EnumType enumType) { TypeExtensionHelper.MergeContextData( Definition, enumType.Definition); TypeExtensionHelper.MergeDirectives( context, Definition.Directives, enumType.Definition.Directives); TypeExtensionHelper.MergeConfigurations( Definition.Configurations, enumType.Definition.Configurations); MergeValues(context, Definition, enumType.Definition); } else { throw new ArgumentException( TypeResources.EnumTypeExtension_CannotMerge, nameof(type)); } }
private static void MergeFields <T>( ICompletionContext context, IList <T> extensionFields, IList <T> typeFields, Action <IList <T>, T, T> action) where T : FieldDefinitionBase { foreach (T extensionField in extensionFields) { T typeField = typeFields.FirstOrDefault(t => t.Name.Equals(extensionField.Name)); if (typeField == null) { typeFields.Add(extensionField); } else { MergeDirectives( context, extensionField.Directives, typeField.Directives); MergeContextData(extensionField, typeField); action(typeFields, extensionField, typeField); } } }
internal override void Merge( ICompletionContext context, INamedType type) { if (type is UnionType unionType) { TypeExtensionHelper.MergeContextData( Definition, unionType.Definition); TypeExtensionHelper.MergeDirectives( context, Definition.Directives, unionType.Definition.Directives); TypeExtensionHelper.MergeTypes( Definition.Types, unionType.Definition.Types); TypeExtensionHelper.MergeConfigurations( Definition.Configurations, unionType.Definition.Configurations); } else { throw new ArgumentException( TypeResources.UnionTypeExtension_CannotMerge); } }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (IsDefinitionScope(current)) { yield return SassCompletionContextType.VariableName; } else if (current is VariableDefinition && IsDefinitionScope(current.Parent)) { var definition = current as VariableDefinition; if (definition.Name == null) { yield return SassCompletionContextType.VariableName; } else { yield return SassCompletionContextType.VariableValue; if (definition.Values.Any(x => x.IsValid)) yield return SassCompletionContextType.VariableDefaultFlag; } } else if (IsUnclosedVariable(current)) { yield return SassCompletionContextType.VariableDefaultFlag; } }
internal sealed override void CompleteType(ICompletionContext context) { if (_definition is null) { throw new InvalidOperationException( TypeResources.TypeSystemObjectBase_DefinitionIsNull); } DefinitionBase?definition = _definition; context.Interceptor.OnBeforeCompleteType( context, definition, _definition.ContextData); ExecuteConfigurations(context, ApplyConfigurationOn.Completion); Description = _definition.Description; OnCompleteType(context, _definition); _contextData = new Dictionary <string, object?>(_definition.ContextData); _definition = null; _configrations = null; base.CompleteType(context); context.Interceptor.OnAfterCompleteType( context, definition, _contextData); }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; var position = context.Position; if (current is PropertyDeclaration) { yield return SassCompletionContextType.PropertyValue; } else if (IsInDeclarationContext(current)) { yield return SassCompletionContextType.PropertyDeclaration; } else { var declaration = FindDeclaration(current); if (declaration == null) yield break; if (declaration.Colon == null || declaration.Colon.Start > position) { yield return SassCompletionContextType.PropertyName; } else if (declaration.Colon != null && (declaration.End > position || declaration.IsUnclosed)) { yield return SassCompletionContextType.PropertyValue; } } }
public static void CompleteFields <TTypeDef, TFieldType, TFieldDef>( ICompletionContext context, TTypeDef definition, IReadOnlyCollection <FieldBase <TFieldType, TFieldDef> > fields) where TTypeDef : DefinitionBase, IHasSyntaxNode where TFieldType : IType where TFieldDef : FieldDefinitionBase { if (context.Type is IType type && fields.Count == 0) { // TODO : RESOURCES context.ReportError(SchemaErrorBuilder.New() .SetMessage($"{type.Kind} `{definition.Name}` has no fields declared.") .SetCode(TypeErrorCodes.MissingType) .SetTypeSystemObject(context.Type) .AddSyntaxNode(definition.SyntaxNode) .Build()); return; } foreach (FieldBase <TFieldType, TFieldDef> field in fields) { field.CompleteField(context); } }
protected virtual void OnCompleteType( ICompletionContext context, IDictionary <string, object> contextData) { Directives = DirectiveCollection.CreateAndComplete( context, this, Array.Empty <DirectiveDefinition>()); }
public override void OnAfterCompleteType( ICompletionContext context, DefinitionBase definition, IDictionary <string, object> contextData) { contextData.Add("touched", true); }
protected override void OnCompleteType( ICompletionContext context, InputObjectTypeDefinition definition) { base.OnCompleteType(context, definition); ITypeConversion converter = context.Services.GetTypeConversion(); _objectToValueConverter = new InputObjectToObjectValueConverter(converter); _objectToDictionary = new InputObjectToDictionaryConverter(converter); SyntaxNode = definition.SyntaxNode; var fields = new List <InputField>(); OnCompleteFields(context, definition, fields); Fields = new FieldCollection <InputField>(fields); FieldInitHelper.CompleteFields(context, definition, Fields); if (ClrType == typeof(object) || Fields.Any(t => t.Property is null)) { _parseLiteral = ov => InputObjectParserHelper.Parse(this, ov, converter); _deserialize = map => InputObjectParserHelper.Deserialize(this, map, converter); }
public static void MergeObjectFields( ICompletionContext context, Type sourceType, IList <ObjectFieldDefinition> extensionFields, IList <ObjectFieldDefinition> typeFields) { MergeOutputFields(context, extensionFields, typeFields, (fields, extensionField, typeField) => { if (extensionField.Resolver != null) { typeField.Resolver = extensionField.Resolver; } if (extensionField.MiddlewareComponents.Count > 0) { foreach (FieldMiddleware component in extensionField.MiddlewareComponents) { typeField.MiddlewareComponents.Add(component); } } }, extensionField => extensionField.SourceType = sourceType); }
internal override void Merge( ICompletionContext context, INamedType type) { if (type is ObjectType objectType) { TypeExtensionHelper.MergeContextData( Definition, objectType.Definition); TypeExtensionHelper.MergeDirectives( context, Definition.Directives, objectType.Definition.Directives); TypeExtensionHelper.MergeObjectFields( context, Definition.Fields, objectType.Definition.Fields); } else { // TODO : resources throw new ArgumentException("CANNOT MERGE"); } }
private bool IsValidProperty(ICompletionContext context) { var schema = SchemaManager.CurrentSchema; if (schema == null) return false; return schema.IsProperty(context.DocumentTextProvider.GetText(context.Current.Start, context.Current.Length)); }
private IEnumerable<SassCompletionContextType> CalculateApplicableContexts(ICompletionContext context) { // it's likely that multiple value providers will return the same context type // so wrap in a set so we only have to process that type once return new HashSet<SassCompletionContextType>( IntellisenseManager.ContextProviders.SelectMany(x => x.GetContext(context)) ); }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { var schema = SchemaManager.CurrentSchema; if (schema == null) return Enumerable.Empty<ICompletionValue>(); return schema.GetPseudos().Select(x => new PseudoCompletionValue(x.Name, x.Description)); }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (current is Stylesheet || current is MediaQueryBlock) yield return SassCompletionContextType.KeyframesDirective; if (current is KeyframeRuleBlock) yield return SassCompletionContextType.KeyframesNamedRange; }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { switch (type) { case SassCompletionContextType.IncludeDirectiveMixinName: return context.Cache.GetMixins(context.Position); } return Enumerable.Empty<ICompletionValue>(); }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { if (type != SassCompletionContextType.ImportDirectiveFile) return Enumerable.Empty<ICompletionValue>(); var directory = Resolve(context); if (directory == null) return Enumerable.Empty<ICompletionValue>(); return GetValues(directory); }
private IEnumerable<ICompletionValue> GetPropertyValues(ICompletionContext context, ICssSchema schema) { var property = context.Current as PropertyDeclaration; if (property == null || property.Name == null || !IsPlainPropertyName(property.Name)) return NO_RESULTS; // right now we just grab full text since we only support plain ol' properties. // in the future may support evaluating #{$name}-left style properties var propertyName = context.DocumentTextProvider.GetText(property.Name.Start, property.Name.Length); return schema.GetPropertyValues(propertyName).Select(x => new PropertyValueCompletionValue(x.Name, x.Description)); }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { switch (type) { case SassCompletionContextType.XmlDocumentationComment: yield return new KeywordCompletionValue("reference"); break; case SassCompletionContextType.FileReferenceFileAttribute: yield return new KeywordCompletionValue("file") { CompletionText = "file=\"" }; break; } }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (current is Stylesheet) { yield return SassCompletionContextType.FunctionDirective; } else if (current is UserFunctionBody) { yield return SassCompletionContextType.FunctionBody; } }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { if (context.Current is FileReferenceTag) { var tag = context.Current as FileReferenceTag; if (tag.Filename == null) yield return SassCompletionContextType.FileReferenceFileAttribute; } else if (context.Current is XmlDocumentationTag) { yield return SassCompletionContextType.XmlDocumentationComment; } }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (current is Stylesheet || current is BlockItem) { yield return SassCompletionContextType.ConditionalDirective; } else if (current is ConditionalControlDirective) { var directive = current as ConditionalControlDirective; if (directive.Rule != null && directive.Rule.Name != null /*&& AllowsExpresion(context.Text, directive.Rule.Name)*/) yield return SassCompletionContextType.ConditionalDirectiveExpression; } }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { var schema = SchemaManager.CurrentSchema; if (schema != null) { switch (type) { case SassCompletionContextType.PropertyDeclaration: case SassCompletionContextType.PropertyName: return GetPropertyNames(context, schema); case SassCompletionContextType.PropertyValue: return GetPropertyValues(context, schema); } } return NO_RESULTS; }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { if (IsValidProperty(context)) yield break; if (FindSelector(context.Current) != null || IsNestedSelector(context.Current)) { yield return SassCompletionContextType.PseudoClass; yield return SassCompletionContextType.PseudoElement; yield return SassCompletionContextType.PseudoFunction; } //else if (FindSelector(context.Predecessor) != null && IsNestedSelector(context.Predecessor)) //{ // yield return SassCompletionContextType.PseudoClass; // yield return SassCompletionContextType.PseudoElement; // yield return SassCompletionContextType.PseudoFunction; //} }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (current == null) yield break; if (current is Stylesheet) { yield return SassCompletionContextType.MixinDirective; } else if (current is MixinDefinitionBody) { yield return SassCompletionContextType.MixinBody; } else if (current is RuleBlock) { yield return SassCompletionContextType.IncludeDirective; } else if (current is MixinReference || (current is AtRule && current.Parent is MixinReference)) { var reference = (current as MixinReference) ?? (current.Parent as MixinReference); if (reference.Name == null) { yield return SassCompletionContextType.IncludeDirectiveMixinName; } else if (reference.OpenBrace != null) { yield return SassCompletionContextType.IncludeDirectiveMixinArgument; } } else if (current is MixinName && current.Parent is MixinReference) { yield return SassCompletionContextType.IncludeDirectiveMixinName; } else if (current is FunctionArgument && current.Parent is MixinReference) { // if current is named argument, then variable has already been named, so we only care about values var namedArgument = current as NamedFunctionArgument; if (namedArgument == null || namedArgument.Variable == null) yield return SassCompletionContextType.IncludeDirectiveMixinArgumentName; yield return SassCompletionContextType.IncludeDirectiveMixinArgumentValue; } }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; var position = context.Position; if (current is EachLoopDirective) { var directive = current as EachLoopDirective; if (directive.Rule != null && BeforeSuccessor(position, directive.Body)) yield return SassCompletionContextType.EachDirectiveListValue; } else if (current is ForLoopDirective) { var directive = current as ForLoopDirective; if (directive.Rule != null) { if (directive.Variable == null || BeforeSuccessor(position, directive.FromKeyword, directive.ToKeyword ?? directive.ThroughKeyword, directive.Body)) { yield return SassCompletionContextType.ForLoopVariable; } else if (directive.FromKeyword == null || BeforeSuccessor(position, directive.ToKeyword ?? directive.ThroughKeyword, directive.Body)) { yield return SassCompletionContextType.ForLoopFromKeyword; } else if ((directive.ThroughKeyword == null || directive.FromKeyword == null) || BeforeSuccessor(position, directive.Body)) { yield return SassCompletionContextType.ForLoopRangeKeyword; } } } else if (current is WhileLoopDirective) { var directive = current as WhileLoopDirective; if (directive.Rule != null && BeforeSuccessor(position, directive.Body)) yield return SassCompletionContextType.WhileLoopCondition; } else { yield return SassCompletionContextType.EachDirective; yield return SassCompletionContextType.ForLoopDirective; yield return SassCompletionContextType.WhileLoopDirective; } }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { var current = context.Current; if (current is RuleBlock) { yield return SassCompletionContextType.ExtendDirective; } else if (current is ExtendDirective) { var directive = current as ExtendDirective; if (directive.Selector == null) { yield return SassCompletionContextType.ExtendDirectiveReference; } else if (directive.Selector != null && directive.Modifier == null) { yield return SassCompletionContextType.ExtendDirectiveOptionalFlag; } } }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { return GetKeywords(type).Select(name => new KeywordCompletionValue(name)); }
private string ResolvePrefix(ICompletionContext context) { var current = context.Current; var parts = new Stack<PropertyDeclaration>(1); while (current != null) { if (current is PropertyDeclaration) { var property = current as PropertyDeclaration; if (property.Name != null && property.Name.Fragments.All(x => x is TokenItem)) parts.Push(property); } current = current.Parent; } var builder = new StringBuilder(); while (parts.Count > 0) { var part = parts.Pop(); if (builder.Length > 0) builder.Append("-"); builder.Append(part.Name.GetName(context.DocumentTextProvider)); } if (builder.Length == 0) return null; // if we aren't currently in "nested" block directly, then chop off current value if (!(context.Current is NestedPropertyBlock)) return builder.ToString(0, LastHyphen(builder)); return builder.ToString(); }
public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType type, ICompletionContext context) { return SystemFunctions.Concat(context.Cache.GetFunctions(context.Position)); }
public IEnumerable<ICompletionValue> GetPropertyNames(ICompletionContext context, ICssSchema schema) { var prefix = ResolvePrefix(context); return schema.GetProperties(prefix).Select(x => new PropertyNameCompletionValue(x.Name, x.Description)); }
public IEnumerable<SassCompletionContextType> GetContext(ICompletionContext context) { // TODO: figure out when we are in import if (context.Current is StringValue) yield break; }