public DothtmlCompletionSource(DothtmlCompletionSourceProvider sourceProvider, DothtmlParser parser, 
     DothtmlClassifier classifier, ITextBuffer textBuffer, VisualStudioWorkspace workspace, 
     IGlyphService glyphService, DTE2 dte, DotvvmConfigurationProvider configurationProvider,
     MetadataControlResolver metadataControlResolver)
 {
     this.sourceProvider = sourceProvider;
     this.textBuffer = textBuffer;
     this.classifier = classifier;
     this.parser = parser;
     this.workspace = workspace;
     this.glyphService = glyphService;
     this.dte = dte;
     this.configurationProvider = configurationProvider;
     this.MetadataControlResolver = metadataControlResolver;
 }
        public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
        {
            return textBuffer.Properties.GetOrCreateSingletonProperty(() =>
            {
                var classifierProvider = new DothtmlClassifierProvider()
                {
                    Registry = Registry
                };

                ConfigurationProvider = new DotvvmConfigurationProvider();
                MetadataControlResolver = new MetadataControlResolver();

                WatchWorkspaceChanges();

                Parser = new DothtmlParser();
                Classifier = (DothtmlClassifier)classifierProvider.GetClassifier(textBuffer);

                return new DothtmlCompletionSource(this, Parser, Classifier, textBuffer,
                    Workspace, GlyphService, CompletionHelper.DTE, ConfigurationProvider, MetadataControlResolver);
            });
        }
        protected override bool Execute(uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, IOleCommandTarget nextCommandTarget)
        {
            var groupId = CommandGroupId;
            if (nextCommandTarget.Exec(ref groupId, nCmdID, nCmdexecopt, pvaIn, pvaOut) == VSConstants.S_OK)
            {
                // parse the content
                var tokenizer = new DothtmlTokenizer();
                var text = TextView.TextSnapshot.GetText();
                tokenizer.Tokenize(new StringReader(text));
                var parser = new DothtmlParser();
                var node = parser.Parse(tokenizer.Tokens);

                // prepare the metadata control resolver
                var completionSource = TextView.TextBuffer.Properties.GetProperty<DothtmlCompletionSource>(typeof(DothtmlCompletionSource));
                var metadataControlResolver = completionSource.MetadataControlResolver;
                metadataControlResolver.ReloadAllControls(completionSource.GetCompletionContext());

                try
                {
                    CompletionHelper.DTE.UndoContext.Open("Format Dothtml document");
                    var edit = TextView.TextBuffer.CreateEdit(EditOptions.None, null, null);

                    // fix the casing of all elements
                    var editText = new StringBuilder(text);
                    foreach (var element in node.EnumerateNodes().OfType<DothtmlElementNode>())
                    {
                        FixElement(editText, metadataControlResolver, TextView.TextBuffer, element);
                    }
                    edit.Replace(0, editText.Length, editText.ToString());
                    edit.Apply();
                }
                finally
                {
                    CompletionHelper.DTE.UndoContext.Close();
                }
            }

            return true;
        }
Beispiel #4
0
        /// <summary>
        /// Compiles the view and returns a function that can be invoked repeatedly. The function builds full control tree and activates the page.
        /// </summary>
        public IControlBuilder CompileView(IReader reader, string fileName, string assemblyName, string namespaceName, string className)
        {
            // parse the document
            var tokenizer = new DothtmlTokenizer();
            tokenizer.Tokenize(reader);
            var parser = new DothtmlParser();
            var node = parser.Parse(tokenizer.Tokens);

            var resolvedView = controlTreeResolver.ResolveTree(node, fileName);

            var styleVisitor = new StylingVisitor(configuration.Styles);
            resolvedView.Accept(styleVisitor);

            var emitter = new DefaultViewCompilerCodeEmitter();
            var compilingVisitor = new ViewCompilingVisitor(emitter, configuration.ServiceLocator.GetService<IBindingCompiler>(), className);
            
            resolvedView.Accept(compilingVisitor);

            // create the assembly
            var assembly = BuildAssembly(emitter, assemblyName, namespaceName, className);
            var controlBuilder = (IControlBuilder)assembly.CreateInstance(namespaceName + "." + className);
            resolvedView.Metadata.ControlBuilderType = controlBuilder.GetType();
            return controlBuilder;
        }
Beispiel #5
0
 public static DothtmlRootNode ParseMarkup(string markup)
 {
     var tokenizer = new DothtmlTokenizer();
     tokenizer.Tokenize(new StringReader(markup));
     var parser = new DothtmlParser();
     var node = parser.Parse(tokenizer.Tokens);
     return node;
 }