Esempio n. 1
0
        public async Task <FormattingContext> WithTextAsync(SourceText changedText)
        {
            if (changedText is null)
            {
                throw new ArgumentNullException(nameof(changedText));
            }

            var engine        = OriginalSnapshot.Project.GetProjectEngine();
            var importSources = new List <RazorSourceDocument>();

            var imports = OriginalSnapshot.GetImports();

            foreach (var import in imports)
            {
                var sourceText = await import.GetTextAsync();

                var source = sourceText.GetRazorSourceDocument(import.FilePath, import.TargetPath);
                importSources.Add(source);
            }

            var changedSourceDocument = changedText.GetRazorSourceDocument(OriginalSnapshot.FilePath, OriginalSnapshot.TargetPath);

            var codeDocument = engine.ProcessDesignTime(changedSourceDocument, OriginalSnapshot.FileKind, importSources, OriginalSnapshot.Project.TagHelpers);

            ValidateComponents(CodeDocument, codeDocument);

            var newContext = Create(Uri, OriginalSnapshot, codeDocument, Options, _workspaceFactory, IsFormatOnType);

            return(newContext);
        }
Esempio n. 2
0
        private async Task InitializeProjectEngineAsync()
        {
            var engine        = OriginalSnapshot.Project.GetProjectEngine();
            var importSources = new List <RazorSourceDocument>();

            var imports = OriginalSnapshot.GetImports();

            foreach (var import in imports)
            {
                var sourceText = await import.GetTextAsync().ConfigureAwait(false);

                var source = sourceText.GetRazorSourceDocument(import.FilePath, import.TargetPath);
                importSources.Add(source);
            }

            _engine        = engine;
            _importSources = importSources;
        }