コード例 #1
0
        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>();
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 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>();
 }
コード例 #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;
        }
コード例 #5
0
        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>();
        }
コード例 #6
0
        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>();
        }
コード例 #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>();
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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;
        }
コード例 #10
0
        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>();
            }
        }
コード例 #11
0
ファイル: CompletionHelper.cs プロジェクト: adamjez/dotvvm
        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;
        }
コード例 #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;
        }
コード例 #13
0
        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>();
        }
コード例 #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>();
        }
コード例 #15
0
 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));
 }
コード例 #16
0
 public abstract IEnumerable<SimpleRwHtmlCompletion> GetItems(RwHtmlCompletionContext context);
コード例 #17
0
 protected abstract IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, string directiveName);
コード例 #18
0
ファイル: CompletionHelper.cs プロジェクト: adamjez/dotvvm
 public static IEnumerable<ProjectItem> GetCurrentProjectFiles(RwHtmlCompletionContext context)
 {
     return context.DTE.ActiveDocument.ProjectItem.ContainingProject.ProjectItems.OfType<ProjectItem>().SelectMany(GetSelfAndChildProjectItems);
 }
コード例 #19
0
ファイル: CompletionHelper.cs プロジェクト: adamjez/dotvvm
        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;
        }
コード例 #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();
        }
コード例 #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;
        }
コード例 #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));
 }
コード例 #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();
     });
 }
コード例 #24
0
 public IEnumerable<CompletionData> GetAttachedPropertyNames(RwHtmlCompletionContext context)
 {
     return attachedProperties.GetOrRetrieve(() => ReloadAllAttachedProperties(context)).Select(a => new CompletionData(a.Name));
 }
コード例 #25
0
 protected abstract IEnumerable<SimpleRwHtmlCompletion> GetItemsCore(RwHtmlCompletionContext context, List<string> tagNameHierarchy);
コード例 #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;
 }
コード例 #27
0
ファイル: CompletionHelper.cs プロジェクト: adamjez/dotvvm
        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;
        }
コード例 #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
            };
        }