protected override IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, string directiveName)
        {
            if (directiveName == Constants.ViewModelDirectiveName || directiveName == Constants.BaseTypeDirective)
            {
                // get list of all custom types
                var types = typeNames.GetOrRetrieve(() =>
                {
                    return CompletionHelper.GetSyntaxTrees(context)
                        .SelectMany(i => i.Tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>()
                        .Select(n => new { Symbol = i.SemanticModel.GetDeclaredSymbol(n), Compilation = i.Compilation })
                        .Where(n => n.Symbol != null))
                        .Select(t => new CompletionData(
                            string.Format("{0} (in namespace {1})", t.Symbol.Name, t.Symbol.ContainingNamespace),
                            t.Symbol.ToString() + ", " + t.Compilation.AssemblyName))
                        .ToList();
                });

                // return completion items
                var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupClass, StandardGlyphItem.GlyphItemPublic);
                return types.Select(t => new SimpleRwHtmlCompletion(t.DisplayText, t.CompletionText, glyph));
            }
            else
            {
                return Enumerable.Empty<SimpleRwHtmlCompletion>();
            }
        }
        public override IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context)
        {
            var bindingTypes = new[] { Constants.CommandBinding, Constants.ValueBinding, Constants.ResourceBinding };
            var userControlBindingTypes = new[] { Constants.ControlStateBinding, Constants.ControlCommandBinding, Constants.ControlPropertyBinding };

            var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphKeyword, StandardGlyphItem.GlyphItemPublic);
            return Enumerable.Concat(bindingTypes, userControlBindingTypes).Select(b => new SimpleRwHtmlCompletion(b, b + ": ", glyph));
        }
 public override IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context)
 {
     if (context.CurrentNode is RwHtmlDirectiveNode)
     {
         var directiveName = ((RwHtmlDirectiveNode)context.CurrentNode).Name;
         return GetItemsCore(context, directiveName);
     }
     return Enumerable.Empty<SimpleRwHtmlCompletion>();
 }
Exemplo n.º 4
0
        public IEnumerable<CompletionData> GetElementNames(RwHtmlCompletionContext context, List<string> tagNameHierarchy)
        {
            var controls = allControls.GetOrRetrieve(() => ReloadAllControls(context));

            ControlMetadata currentControl;
            ControlPropertyMetadata currentProperty;
            GetElementContext(tagNameHierarchy, out currentControl, out currentProperty);

            if (currentControl != null && currentProperty == null && currentControl.Properties.Any(p => p.IsElement))
            {
                return currentControl.Properties.Where(p => p.IsElement).Select(p => new CompletionData(p.Name));
            }
            return controls;
        }
        public sealed override IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context)
        {
            if (context.CurrentNode is RwHtmlElementNode)
            {
                var tagNameHierarchy = GetTagHierarchy(context);
                
                if (tagNameHierarchy.Any())
                {
                    tagNameHierarchy.RemoveAt(tagNameHierarchy.Count - 1);
                }

                return GetItemsCore(context, tagNameHierarchy);
            }
            return Enumerable.Empty<SimpleRwHtmlCompletion>();
        }
        public override sealed IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context)
        {
            if (context.CurrentNode is RwHtmlElementNode || context.CurrentNode is RwHtmlAttributeNode)
            {
                var tagNameHierarchy = GetTagHierarchy(context);

                // if the tag has already some attributes, don't show them in the IntelliSense
                var tag = context.CurrentNode as RwHtmlElementNode ?? ((RwHtmlAttributeNode)context.CurrentNode).ParentElement;
                var existingAttributeNames = tag.Attributes.Select(a => a.AttributeName).ToList();

                return GetItemsCore(context, tagNameHierarchy)
                    .Where(n => !existingAttributeNames.Contains(n.DisplayText));
            }
            return Enumerable.Empty<SimpleRwHtmlCompletion>();
        }
Exemplo n.º 7
0
        public IEnumerable<CompletionData> GetControlAttributeNames(RwHtmlCompletionContext context, List<string> tagNameHierarchy, out bool combineWithHtmlCompletions)
        {
            allControls.GetOrRetrieve(() => ReloadAllControls(context));

            ControlMetadata currentControl;
            ControlPropertyMetadata currentProperty;
            GetElementContext(tagNameHierarchy, out currentControl, out currentProperty);

            combineWithHtmlCompletions = currentControl != null && currentControl.Name == typeof(HtmlGenericControl).Name && currentControl.Namespace == typeof(HtmlGenericControl).Namespace;

            if (currentControl != null && currentProperty == null)
            {
                return currentControl.Properties.Where(p => !p.IsElement).Select(p => new CompletionData(p.Name));
            }
            return Enumerable.Empty<CompletionData>();
        }
        protected override IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, List<string> tagNameHierarchy)
        {
            var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphXmlItem, StandardGlyphItem.GlyphItemPublic);

            var tagNames = context.MetadataControlResolver.GetElementNames(context, tagNameHierarchy).ToList();
            foreach (var n in tagNames)
            {
                yield return new SimpleRwHtmlCompletion(n.DisplayText, n.CompletionText, glyph);
            }

            if (tagNameHierarchy.Any())
            {
                var tagName = tagNameHierarchy[tagNameHierarchy.Count - 1];
                yield return new SimpleRwHtmlCompletion("/" + tagName, "/" + tagName + ">", null);
            }
        }
        protected override IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, List<string> tagNameHierarchy)
        {
            var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupProperty, StandardGlyphItem.GlyphItemPublic);
            var glyph2 = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupProperty, StandardGlyphItem.GlyphItemShortcut);

            var keepHtmlAttributes = false;
            var results = Enumerable.Concat(
                context.MetadataControlResolver.GetControlAttributeNames(context, tagNameHierarchy, out keepHtmlAttributes)
                    .Select(n => new SimpleRwHtmlCompletion(n.DisplayText, n.CompletionText, glyph)),
                context.MetadataControlResolver.GetAttachedPropertyNames(context)
                    .Select(n => new SimpleRwHtmlCompletion(n.DisplayText, n.CompletionText, glyph2))
            );

            CombineWithHtmlCompletions = keepHtmlAttributes;

            return results;
        }
        protected override IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, string directiveName)
        {
            if (directiveName == Constants.MasterPageDirective)
            {
                var documents = CompletionHelper.GetCurrentProjectFiles(context)
                    .Where(i => i.Name.EndsWith(".rwhtml", StringComparison.CurrentCultureIgnoreCase))
                    .Select(CompletionHelper.GetProjectItemRelativePath)
                    .ToList();

                var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphJSharpDocument, StandardGlyphItem.GlyphItemPublic);
                return documents.Select(d => new SimpleRwHtmlCompletion(d, d, glyph));
            }
            else
            {
                return Enumerable.Empty<SimpleRwHtmlCompletion>();
            }
        }
Exemplo n.º 11
0
        public static List<ITypeSymbol> GetReferencedSymbols(RwHtmlCompletionContext context)
        {
            var compilations = GetCompilations(context);

            var symbols = compilations
                .SelectMany(c => c.References.Select(r => new { Compilation = c, Reference = r }))
                .SelectMany(r =>
                {
                    var symbol = r.Compilation.GetAssemblyOrModuleSymbol(r.Reference);
                    if (symbol is IModuleSymbol) return new[] { symbol }.OfType<IModuleSymbol>();
                    return ((IAssemblySymbol)symbol).Modules;
                })
                .SelectMany(m => GetAllTypesInModuleSymbol(m.GlobalNamespace))
                .ToList();

            return symbols;
        }
Exemplo n.º 12
0
        protected List<string> GetTagHierarchy(RwHtmlCompletionContext context)
        {
            var hierarchy = new List<string>();

            var node = context.CurrentNode as RwHtmlElementNode;
            if (node == null && context.CurrentNode is RwHtmlAttributeNode)
            {
                node = ((RwHtmlAttributeNode)context.CurrentNode).ParentElement;
            }

            while (node != null)
            {
                hierarchy.Add(node.FullTagName);
                node = node.ParentElement;
            }

            hierarchy.Reverse();
            return hierarchy;
        }
        public override sealed IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context)
        {
            if (context.CurrentNode is RwHtmlAttributeNode)
            {
                var tagNameHierarchy = GetTagHierarchy(context);

                string attributeName = null;
                for (int i = context.CurrentTokenIndex - 1; i >= 0; i--)
                {
                    if (context.Tokens[i].Type == RwHtmlTokenType.Text)
                    {
                        attributeName = context.Tokens[i].Text;
                        break;
                    }
                }
                if (attributeName != null)
                {
                    return GetItemsCore(context, tagNameHierarchy, attributeName);
                }
            }
            return Enumerable.Empty<SimpleRwHtmlCompletion>();
        }
Exemplo n.º 14
0
        public IEnumerable<CompletionData> GetControlAttributeValues(RwHtmlCompletionContext context, List<string> tagNameHierarchy, string attributeName)
        {
            allControls.GetOrRetrieve(() => ReloadAllControls(context));

            ControlMetadata currentControl;
            ControlPropertyMetadata currentProperty;
            GetElementContext(tagNameHierarchy, out currentControl, out currentProperty);

            if (currentControl != null && currentProperty == null)
            {
                var property = currentControl.Properties.FirstOrDefault(p => p.Name == attributeName);
                if (property != null)
                {
                    // it is a real property
                    return HintPropertyValues(property.Type);
                }
                else
                {
                    // it can be an attached property
                    return GetAttachedPropertyValues(context, attributeName);
                }
            }
            return Enumerable.Empty<CompletionData>();
        }
 protected override IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, List<string> tagNameHierarchy, string attributeName)
 {
     var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupEnum, StandardGlyphItem.GlyphItemPublic);
     return context.MetadataControlResolver.GetControlAttributeValues(context, tagNameHierarchy, attributeName)
         .Select(n => new SimpleRwHtmlCompletion(n.DisplayText, n.CompletionText, glyph));
 }
Exemplo n.º 16
0
 public abstract IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context);
 protected abstract IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, string directiveName);
Exemplo n.º 18
0
 public static IEnumerable<ProjectItem> GetCurrentProjectFiles(RwHtmlCompletionContext context)
 {
     return context.DTE.ActiveDocument.ProjectItem.ContainingProject.ProjectItems.OfType<ProjectItem>().SelectMany(GetSelfAndChildProjectItems);
 }
Exemplo n.º 19
0
        private static List<Compilation> GetCompilations(RwHtmlCompletionContext context)
        {
            var compilations = new List<Compilation>();

            foreach (var p in context.RoslynWorkspace.CurrentSolution.Projects)
            {
                try
                {
                    var compilation = Task.Run(() => p.GetCompilationAsync()).Result;
                    if (compilation != null)
                    {
                        compilations.Add(compilation);
                    }
                }
                catch (Exception ex)
                {
                    LogService.LogError(new Exception("Cannot get the compilation!", ex));
                }
            }

            return compilations;
        }
Exemplo n.º 20
0
        internal List<AttachedPropertyMetadata> ReloadAllAttachedProperties(RwHtmlCompletionContext context)
        {
            // get all possible control symbols
            var allClasses = ReloadAllClasses(context);
            var attachedPropertyClasses = allClasses
                .Where(c => c.GetThisAndAllBaseTypes().Any(t => t.GetAttributes().Any(a => CheckType(a.AttributeClass, typeof(ContainsRedwoodPropertiesAttribute)))))
                .ToList();

            // find all attached properties
            var attachedProperties = attachedPropertyClasses
                .SelectMany(c => c.GetMembers().OfType<IFieldSymbol>())
                .Where(f => CheckType(f.Type, typeof(RedwoodProperty)))
                .Where(f => f.GetAttributes().Any(a => CheckType(a.AttributeClass, typeof(AttachedPropertyAttribute))));

            return attachedProperties
                .Select(f => new AttachedPropertyMetadata()
                {
                    Name = ComposeAttachedPropertyName(f),
                    Type = f.GetAttributes().First(a => CheckType(a.AttributeClass, typeof(AttachedPropertyAttribute)))
                        .ConstructorArguments[0].Value as ITypeSymbol
                })
                .ToList();
        }
Exemplo n.º 21
0
        internal List<CompletionData> ReloadAllControls(RwHtmlCompletionContext context)
        {
            // get all possible control symbols
            var allClasses = ReloadAllClasses(context);
            var controlClasses = allClasses
                .Where(c => CompletionHelper.GetBaseTypes(c).Any(t => CheckType(t, typeof(RedwoodControl))))
                .ToList();

            var result = new List<CompletionData>();
            metadata = new ConcurrentDictionary<string, ControlMetadata>(StringComparer.CurrentCultureIgnoreCase);
            htmlGenericControlMetadata = null;

            foreach (var rule in context.Configuration.Markup.Controls)
            {
                string tagName;
                if (!string.IsNullOrEmpty(rule.Src))
                {
                    // markup control
                    tagName = rule.TagPrefix + ":" + rule.TagName;

                    // TODO: parse markup, find base type and extract metadata

                    result.Add(new CompletionData(tagName));
                }
                else
                {
                    // find all classes declared in the project
                    var controls = controlClasses.Where(c => c.ContainingAssembly.Name == rule.Assembly && c.ContainingNamespace.ToDisplayString() == rule.Namespace);
                    foreach (var control in controls)
                    {
                        tagName = rule.TagPrefix + ":" + control.Name;
                        var controlMetadata = GetControlMetadata(control, rule.TagPrefix, control.Name);
                        metadata[tagName] = controlMetadata;
                        result.Add(new CompletionData(tagName));

                        if (CheckType(control, typeof(HtmlGenericControl)))
                        {
                            htmlGenericControlMetadata = controlMetadata;
                        }
                    }
                }
            }

            return result;
        }
Exemplo n.º 22
0
 public IEnumerable<CompletionData> GetAttachedPropertyValues(RwHtmlCompletionContext context, string attachedPropertyName)
 {
     return attachedProperties.GetOrRetrieve(() => ReloadAllAttachedProperties(context))
         .Where(a => a.Name == attachedPropertyName)
         .SelectMany(p => HintPropertyValues(p.Type));
 }
Exemplo n.º 23
0
 private List<INamedTypeSymbol> ReloadAllClasses(RwHtmlCompletionContext context)
 {
     return allClasses.GetOrRetrieve(() =>
     {
         var syntaxTrees = CompletionHelper.GetSyntaxTrees(context);
         var ownSymbols = syntaxTrees.SelectMany(t => t.Tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>()
             .Select(c => t.SemanticModel.GetDeclaredSymbol(c))).ToList();
         var referencedSymbols = CompletionHelper.GetReferencedSymbols(context);
         return Enumerable.Concat(referencedSymbols, ownSymbols).OfType<INamedTypeSymbol>()
             .Where(c => c.DeclaredAccessibility == Accessibility.Public && !c.IsAbstract)
             .ToList();
     });
 }
Exemplo n.º 24
0
 public IEnumerable<CompletionData> GetAttachedPropertyNames(RwHtmlCompletionContext context)
 {
     return attachedProperties.GetOrRetrieve(() => ReloadAllAttachedProperties(context)).Select(a => new CompletionData(a.Name));
 }
 protected abstract IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, List<string> tagNameHierarchy);
Exemplo n.º 26
0
 public RwHtmlCompletionContext GetCompletionContext()
 {
     var context = new RwHtmlCompletionContext()
     {
         Tokens = classifier.Tokens,
         Parser = parser,
         Tokenizer = classifier.Tokenizer,
         RoslynWorkspace = workspace,
         GlyphService = glyphService,
         DTE = dte,
         Configuration = configurationProvider.GetConfiguration(dte.ActiveDocument.ProjectItem.ContainingProject),
         MetadataControlResolver = MetadataControlResolver
     };
     parser.Parse(classifier.Tokens);
     return context;
 }
Exemplo n.º 27
0
        public static List<SyntaxTreeInfo> GetSyntaxTrees(RwHtmlCompletionContext context)
        {
            var compilations = GetCompilations(context);

            var trees = compilations
                .SelectMany(c => c.SyntaxTrees.Select(t => new SyntaxTreeInfo() { Tree = t, SemanticModel = c.GetSemanticModel(t), Compilation = c }))
                .Where(t => t.Tree != null)
                .ToList();
            return trees;
        }
Exemplo n.º 28
0
        public void TestInit()
        {
            workspace = new AdhocWorkspace();
            project = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "TestProj", "TestProj", LanguageNames.CSharp)
                .WithMetadataReferences(new[] {
                    MetadataReference.CreateFromAssembly(typeof(RedwoodConfiguration).Assembly),
                    MetadataReference.CreateFromAssembly(typeof(object).Assembly)
                });
            workspace.AddProject(project);

            workspace.AddDocument(project.Id, "test", SourceText.From("class A {}"));

            context = new RwHtmlCompletionContext()
            {
                Configuration = RedwoodConfiguration.CreateDefault(),
                RoslynWorkspace = workspace
            };
        }