public override IEnumerable<SimpleDothtmlCompletion> GetItems(DothtmlCompletionContext context)
        {
            var directives = new[] { Constants.BaseTypeDirective, Constants.MasterPageDirective, Constants.ViewModelDirectiveName };

            var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphKeyword, StandardGlyphItem.GlyphItemPublic);
            return directives.Select(d => new SimpleDothtmlCompletion(d, d + " ", glyph));
        }
        protected override IEnumerable<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext 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 SimpleDothtmlCompletion(t.DisplayText, t.CompletionText, glyph));
            }
            else
            {
                return Enumerable.Empty<SimpleDothtmlCompletion>();
            }
        }
        public void TestInit()
        {
            try
            {
                workspace = new AdhocWorkspace();

                project = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "TestProj", "TestProj", LanguageNames.CSharp)
                    .WithMetadataReferences(new[] {
                        MetadataReference.CreateFromFile(typeof(DotvvmConfiguration).Assembly.Location),
                        MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
                    });
                workspace.AddProject(project);

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

                context = new DothtmlCompletionContext()
                {
                    Configuration = DotvvmConfiguration.CreateDefault(),
                    RoslynWorkspace = workspace
                };

            }
            catch (ReflectionTypeLoadException ex)
            {
                throw new Exception(string.Join("\r\n", ex.LoaderExceptions.Select(e => e.ToString())));
            }
        }
        public override IEnumerable<SimpleDothtmlCompletion> GetItems(DothtmlCompletionContext context)
        {
            var bindingTypes = new[] { Constants.CommandBinding, Constants.ValueBinding, Constants.ResourceBinding };
            var userControlBindingTypes = new[] { Constants.StaticCommandBinding, Constants.ControlCommandBinding, Constants.ControlPropertyBinding };

            var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphKeyword, StandardGlyphItem.GlyphItemPublic);
            return Enumerable.Concat(bindingTypes, userControlBindingTypes).Select(b => new SimpleDothtmlCompletion(b, b + ": ", glyph));
        }
 public override IEnumerable<SimpleDothtmlCompletion> GetItems(DothtmlCompletionContext context)
 {
     if (context.CurrentNode is DothtmlDirectiveNode)
     {
         var directiveName = ((DothtmlDirectiveNode)context.CurrentNode).Name;
         return GetItemsCore(context, directiveName);
     }
     return Enumerable.Empty<SimpleDothtmlCompletion>();
 }
Beispiel #6
0
        public static List<SyntaxTreeInfo> GetSyntaxTrees(DothtmlCompletionContext 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;
        }
        public IEnumerable<CompletionData> GetElementNames(DothtmlCompletionContext 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<SimpleDothtmlCompletion> GetItems(DothtmlCompletionContext context)
        {
            if (context.CurrentNode is DothtmlElementNode)
            {
                var tagNameHierarchy = GetTagHierarchy(context);
                
                if (tagNameHierarchy.Any())
                {
                    tagNameHierarchy.RemoveAt(tagNameHierarchy.Count - 1);
                }

                return GetItemsCore(context, tagNameHierarchy);
            }
            return Enumerable.Empty<SimpleDothtmlCompletion>();
        }
        public sealed override IEnumerable<SimpleDothtmlCompletion> GetItems(DothtmlCompletionContext context)
        {
            if (context.CurrentNode is DothtmlElementNode || context.CurrentNode is DothtmlAttributeNode)
            {
                var tagNameHierarchy = GetTagHierarchy(context);

                // if the tag has already some attributes, don't show them in the IntelliSense
                var tag = context.CurrentNode as DothtmlElementNode ?? ((DothtmlAttributeNode)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<SimpleDothtmlCompletion>();
        }
 public DothtmlCompletionContext GetCompletionContext()
 {
     var context = new DothtmlCompletionContext()
     {
         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;
 }
        public IEnumerable<CompletionData> GetControlAttributeNames(DothtmlCompletionContext 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<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext 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 SimpleDothtmlCompletion(n.DisplayText, n.CompletionText, glyph);
            }
                
            if (tagNameHierarchy.Any())
            {
                var tagName = tagNameHierarchy[tagNameHierarchy.Count - 1];
                yield return new SimpleDothtmlCompletion("/" + tagName, "/" + tagName + ">", null);
            }
        }
        protected override IEnumerable<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext context, string directiveName)
        {
            if (directiveName == Constants.MasterPageDirective)
            {
                var documents = CompletionHelper.GetCurrentProjectFiles(context)
                    .Where(i => i.Name.EndsWith(".dothtml", StringComparison.CurrentCultureIgnoreCase))
                    .Select(DTEHelper.GetProjectItemRelativePath)
                    .ToList();

                var glyph = context.GlyphService.GetGlyph(StandardGlyphGroup.GlyphJSharpDocument, StandardGlyphItem.GlyphItemPublic);
                return documents.Select(d => new SimpleDothtmlCompletion(d, d, glyph));
            }
            else
            {
                return Enumerable.Empty<SimpleDothtmlCompletion>();
            }
        }
Beispiel #14
0
        public static List<ITypeSymbol> GetReferencedSymbols(DothtmlCompletionContext 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;
        }
        protected override IEnumerable<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext 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 SimpleDothtmlCompletion(n.DisplayText, n.CompletionText, glyph)),
                context.MetadataControlResolver.GetAttachedPropertyNames(context)
                    .Select(n => new SimpleDothtmlCompletion(n.DisplayText, n.CompletionText, glyph2))
            );

            CombineWithHtmlCompletions = keepHtmlAttributes;

            return results;
        }
        protected List<string> GetTagHierarchy(DothtmlCompletionContext context)
        {
            var hierarchy = new List<string>();

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

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

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

                string attributeName = null;
                for (int i = context.CurrentTokenIndex - 1; i >= 0; i--)
                {
                    if (context.Tokens[i].Type == DothtmlTokenType.Text)
                    {
                        attributeName = context.Tokens[i].Text;
                        break;
                    }
                }
                if (attributeName != null)
                {
                    return GetItemsCore(context, tagNameHierarchy, attributeName);
                }
            }
            return Enumerable.Empty<SimpleDothtmlCompletion>();
        }
Beispiel #18
0
        private static List<Compilation> GetCompilations(DothtmlCompletionContext 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;
        }
        public IEnumerable<CompletionData> GetControlAttributeValues(DothtmlCompletionContext 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 abstract IEnumerable<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext context, List<string> tagNameHierarchy);
        internal List<CompletionData> ReloadAllControls(DothtmlCompletionContext context)
        {
            // get all possible control symbols
            var allClasses = ReloadAllClasses(context);
            var controlClasses = allClasses
                .Where(c => CompletionHelper.GetBaseTypes(c).Any(t => CheckType(t, typeof(DotvvmControl))))
                .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;
        }
Beispiel #22
0
 public static IEnumerable<ProjectItem> GetCurrentProjectFiles(DothtmlCompletionContext context)
 {
     return Enumerable.OfType<ProjectItem>(context.DTE.ActiveDocument.ProjectItem.ContainingProject.ProjectItems).SelectMany(DTEHelper.GetSelfAndChildProjectItems);
 }
        internal List<AttachedPropertyMetadata> ReloadAllAttachedProperties(DothtmlCompletionContext 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(ContainsDotvvmPropertiesAttribute)))))
                .ToList();

            // find all attached properties
            var attachedProperties = attachedPropertyClasses
                .SelectMany(c => c.GetMembers().OfType<IFieldSymbol>())
                .Where(f => CheckType(f.Type, typeof(DotvvmProperty)))
                .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();
        }
 private List<INamedTypeSymbol> ReloadAllClasses(DothtmlCompletionContext 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();
     });
 }
 public IEnumerable<CompletionData> GetAttachedPropertyNames(DothtmlCompletionContext context)
 {
     return attachedProperties.GetOrRetrieve(() => ReloadAllAttachedProperties(context)).Select(a => new CompletionData(a.Name));
 }
 protected abstract IEnumerable<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext context, string directiveName);
 public IEnumerable<CompletionData> GetAttachedPropertyValues(DothtmlCompletionContext context, string attachedPropertyName)
 {
     return attachedProperties.GetOrRetrieve(() => ReloadAllAttachedProperties(context))
         .Where(a => a.Name == attachedPropertyName)
         .SelectMany(p => HintPropertyValues(p.Type));
 }
 protected override IEnumerable<SimpleDothtmlCompletion> GetItemsCore(DothtmlCompletionContext 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 SimpleDothtmlCompletion(n.DisplayText, n.CompletionText, glyph));
 }
 public abstract IEnumerable<SimpleDothtmlCompletion> GetItems(DothtmlCompletionContext context);