Esempio n. 1
0
        /// <summary>
        /// Constructs the editor parser.  One instance should be used per active editor.  This
        /// instance _can_ be shared among reparses, but should _never_ be shared between documents.
        /// </summary>
        /// <param name="host">The <see cref="RazorEngineHost"/> which defines the environment in which the generated code will live.  <see cref="F:RazorEngineHost.DesignTimeMode"/> should be set if design-time code mappings are desired</param>
        /// <param name="sourceFileName">The physical path to use in line pragmas</param>
        public RazorEditorParser(RazorEngineHost host, string sourceFileName)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (String.IsNullOrEmpty(sourceFileName))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "sourceFileName");
            }

            Host                  = host;
            FileName              = sourceFileName;
            _parser               = new BackgroundParser(host, sourceFileName);
            _parser.ResultsReady += (sender, args) => OnDocumentParseComplete(args);
            _parser.Start();
        }
        public TestWorkspace(ExportProvider?exportProvider = null, TestComposition?composition = null, string?workspaceKind = WorkspaceKind.Host, bool disablePartialSolutions = true, bool ignoreUnchangeableDocumentsWhenApplyingChanges = true)
            : base(GetHostServices(exportProvider, composition), workspaceKind ?? WorkspaceKind.Host)
        {
            Contract.ThrowIfTrue(exportProvider != null && composition != null);

            this.TestHookPartialSolutionsDisabled = disablePartialSolutions;
            this.ExportProvider          = exportProvider ?? GetComposition(composition).ExportProviderFactory.CreateExportProvider();
            _workspaceKind               = workspaceKind ?? WorkspaceKind.Host;
            this.Projects                = new List <TestHostProject>();
            this.Documents               = new List <TestHostDocument>();
            this.AdditionalDocuments     = new List <TestHostDocument>();
            this.AnalyzerConfigDocuments = new List <TestHostDocument>();
            this.ProjectionDocuments     = new List <TestHostDocument>();

            this.CanApplyChangeDocument = true;
            this.IgnoreUnchangeableDocumentsWhenApplyingChanges = ignoreUnchangeableDocumentsWhenApplyingChanges;

            if (Services.GetService <INotificationService>() is INotificationServiceCallback callback)
            {
                // Avoid showing dialogs in tests by default
                callback.NotificationCallback = (message, title, severity) =>
                {
                    var severityText = severity switch
                    {
                        NotificationSeverity.Information => "💡",
                        NotificationSeverity.Warning => "⚠",
                        _ => "❌"
                    };

                    var fullMessage = string.IsNullOrEmpty(title)
                        ? message
                        : $"{title}:{Environment.NewLine}{Environment.NewLine}{message}";

                    throw new InvalidOperationException($"{severityText} {fullMessage}");
                };
            }

            _backgroundCompiler = new BackgroundCompiler(this);
            _backgroundParser   = new BackgroundParser(this);
            _backgroundParser.Start();

            _metadataAsSourceFileService = ExportProvider.GetExportedValues <IMetadataAsSourceFileService>().FirstOrDefault();

            RegisterDocumentOptionProviders(ExportProvider.GetExports <IDocumentOptionsProviderFactory, OrderableMetadata>());
        }
Esempio n. 3
0
        public TestWorkspace(ExportProvider exportProvider, string workspaceKind = null, bool disablePartialSolutions = true)
            : base(VisualStudioMefHostServices.Create(exportProvider), workspaceKind ?? WorkspaceKind.Test)
        {
            this.TestHookPartialSolutionsDisabled = disablePartialSolutions;
            this.ExportProvider      = exportProvider;
            this.Projects            = new List <TestHostProject>();
            this.Documents           = new List <TestHostDocument>();
            this.AdditionalDocuments = new List <TestHostDocument>();
            this.ProjectionDocuments = new List <TestHostDocument>();

            this.CanApplyChangeDocument = true;

            _backgroundCompiler = new BackgroundCompiler(this);
            _backgroundParser   = new BackgroundParser(this);
            _backgroundParser.Start();

            _metadataAsSourceFileService = exportProvider.GetExportedValues <IMetadataAsSourceFileService>().FirstOrDefault();
        }
Esempio n. 4
0
        public TestWorkspace(ExportProvider exportProvider, string workspaceKind = null, bool disablePartialSolutions = true)
            : base(MefV1HostServices.Create(exportProvider.AsExportProvider()), workspaceKind ?? WorkspaceName)
        {
            ResetThreadAffinity();

            this.TestHookPartialSolutionsDisabled = disablePartialSolutions;
            this.ExportProvider      = exportProvider;
            this.Projects            = new List <TestHostProject>();
            this.Documents           = new List <TestHostDocument>();
            this.AdditionalDocuments = new List <TestHostDocument>();
            this.ProjectionDocuments = new List <TestHostDocument>();

            this.CanApplyChangeDocument = true;

            _backgroundCompiler = new BackgroundCompiler(this);
            _backgroundParser   = new BackgroundParser(this);
            _backgroundParser.Start();
        }
Esempio n. 5
0
        public RazorEditorParser(RazorTemplateEngine templateEngine, string filePath)
        {
            if (templateEngine == null)
            {
                throw new ArgumentNullException(nameof(templateEngine));
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(
                          AspNetCore.Razor.Language.Resources.ArgumentCannotBeNullOrEmpty,
                          nameof(filePath));
            }

            TemplateEngine        = templateEngine;
            FilePath              = filePath;
            _parser               = new BackgroundParser(this, filePath);
            _parser.ResultsReady += (sender, args) => OnDocumentParseComplete(args);
            _parser.Start();
        }
        internal async Task <List <ITagSpan <TTag> > > GetTagSpans <TTagger, TTag>(string sourceCode, CreateTagger <TTagger, TTag> createTagger)
            where TTagger : AsyncTagger <TTag>
            where TTag : ITag
        {
            var textBuffer       = TextBufferUtility.CreateTextBuffer(Container, sourceCode);
            var backgroundParser = new BackgroundParser(textBuffer);
            var snapshot         = textBuffer.CurrentSnapshot;
            var tagger           = createTagger(backgroundParser, textBuffer);

            await tagger.InvalidateTags(snapshot, CancellationToken.None);

            var tags = tagger.GetTags(new NormalizedSnapshotSpanCollection(new[]
            {
                new SnapshotSpan(snapshot, 0, snapshot.Length)
            })).ToList();

            backgroundParser.Dispose();

            return(tags);
        }
Esempio n. 7
0
        public VisualStudioWorkspace(
            SVsServiceProvider serviceProvider,
            ITextDocumentFactoryService textDocumentFactoryService)
            : base(MefV1HostServices.Create(GetExportProvider(serviceProvider)))
        {
            PrimaryWorkspace.Register(this);

            _serviceProvider            = serviceProvider;
            _textDocumentFactoryService = textDocumentFactoryService;

            _backgroundParser = new BackgroundParser(this);
            _backgroundParser.Start();

            _textBufferToTextDocumentMap = new ConditionalWeakTable <ITextBuffer, ITextDocument>();
            _textBufferToDocumentIdMap   = new ConditionalWeakTable <ITextBuffer, DocumentId>();
            _textBufferToViewsMap        = new ConditionalWeakTable <ITextBuffer, List <ITextView> >();
            _textViewToBuffersMap        = new ConditionalWeakTable <ITextView, List <ITextBuffer> >();

            Services.GetService <IDocumentTrackingService>();
        }
Esempio n. 8
0
        internal VisualStudioWorkspace(HostServices hostServices, WorkspaceBackgroundWork backgroundWork)
            : base(hostServices, WorkspaceKind.Host)
        {
            if ((backgroundWork & WorkspaceBackgroundWork.Compile) != 0)
            {
                _backgroundCompiler = new BackgroundCompiler(this);

                var cacheService = Services.GetService <IWorkspaceCacheService>();
                if (cacheService != null)
                {
                    cacheService.CacheFlushRequested += OnCacheFlushRequested;
                }
            }

            if ((backgroundWork & WorkspaceBackgroundWork.Parse) != 0)
            {
                _backgroundParser = new BackgroundParser(this);
                _backgroundParser.Start();
            }
        }
        public void TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent()
        {
            var   factory  = SpanFactory.CreateCsHtml();
            Block original = new MarkupBlock(
                factory.Markup("<p>"),
                new ExpressionBlock(factory.CodeTransition()),
                factory.Markup("</p>")
                );
            Block modified = new MarkupBlock(
                factory.Markup("<p>"),
                new ExpressionBlock(
                    factory.CodeTransition("@"),
                    factory
                    .Code("f")
                    .AsImplicitExpression(
                        CSharpCodeParser.DefaultKeywords,
                        acceptTrailingDot: false
                        )
                    ),
                factory.Markup("</p>")
                );
            ITextBuffer oldBuffer = new StringTextBuffer("<p>@</p>");
            ITextBuffer newBuffer = new StringTextBuffer("<p>@f</p>");

            Assert.True(
                BackgroundParser.TreesAreDifferent(
                    original,
                    modified,
                    new[]
            {
                new TextChange(
                    position: 4,
                    oldLength: 0,
                    oldBuffer: oldBuffer,
                    newLength: 1,
                    newBuffer: newBuffer
                    )
            }
                    )
                );
        }
Esempio n. 10
0
        public TestWorkspace(ExportProvider exportProvider, string?workspaceKind = null, bool disablePartialSolutions = true, bool ignoreUnchangeableDocumentsWhenApplyingChanges = true)
            : base(VisualStudioMefHostServices.Create(exportProvider), workspaceKind ?? WorkspaceKind.Test)
        {
            this.TestHookPartialSolutionsDisabled = disablePartialSolutions;
            this.ExportProvider          = exportProvider;
            this.Projects                = new List <TestHostProject>();
            this.Documents               = new List <TestHostDocument>();
            this.AdditionalDocuments     = new List <TestHostDocument>();
            this.AnalyzerConfigDocuments = new List <TestHostDocument>();
            this.ProjectionDocuments     = new List <TestHostDocument>();

            this.CanApplyChangeDocument = true;
            this.IgnoreUnchangeableDocumentsWhenApplyingChanges = ignoreUnchangeableDocumentsWhenApplyingChanges;

            _backgroundCompiler = new BackgroundCompiler(this);
            _backgroundParser   = new BackgroundParser(this);
            _backgroundParser.Start();

            _metadataAsSourceFileService = exportProvider.GetExportedValues <IMetadataAsSourceFileService>().FirstOrDefault();

            RegisterDocumentOptionProviders(exportProvider.GetExports <IDocumentOptionsProviderFactory, OrderableMetadata>());
        }
Esempio n. 11
0
 private OutliningTagger CreateTagger(BackgroundParser backgroundParser, ITextBuffer textBuffer)
 {
     return(new OutliningTagger(textBuffer, backgroundParser, new FakeOptionsService()));
 }
Esempio n. 12
0
        public OutliningTagger(BackgroundParser backgroundParser, IOptionsService optionsService)
        {
            backgroundParser.RegisterSyntaxTreeHandler(BackgroundParserHandlerPriority.Medium, this);

            _enabled = optionsService.AdvancedOptions.EnterOutliningModeWhenFilesOpen;
        }
 protected TParser GetParser() => BackgroundParser <TResult> .GetParser <TParser> ((ITextBuffer2)textView.TextBuffer);
Esempio n. 14
0
 protected MSBuildBackgroundParser GetParser() => BackgroundParser <MSBuildParseResult> .GetParser <MSBuildBackgroundParser> ((ITextBuffer2)textBuffer);
 private SemanticTagger CreateTagger(BackgroundParser backgroundParser, ITextBuffer textBuffer)
 {
     return(new SemanticTagger(_hlslClassificationService, backgroundParser));
 }
Esempio n. 16
0
 protected abstract TTagger CreateTagger(BackgroundParser backgroundParser, ITextBuffer textBuffer);
Esempio n. 17
0
 protected override OutliningTagger CreateTagger(BackgroundParser backgroundParser, ITextSnapshot snapshot)
 {
     return(new OutliningTagger(backgroundParser, new FakeOptionsService()));
 }
 protected override SyntaxErrorTagger CreateTagger(BackgroundParser backgroundParser, ITextSnapshot snapshot)
 {
     return(new SyntaxErrorTagger(Substitute.For <ITextView>(), backgroundParser, _errorListHelper, new FakeOptionsService()));
 }
Esempio n. 19
0
 protected abstract TTagger CreateTagger(BackgroundParser backgroundParser, ITextSnapshot snapshot);
Esempio n. 20
0
 public SemanticTagger(HlslClassificationService classificationService, BackgroundParser backgroundParser)
 {
     _classificationService = classificationService;
     backgroundParser.RegisterSyntaxTreeHandler(BackgroundParserHandlerPriority.High, this);
 }
Esempio n. 21
0
        /// <summary>
        /// Constructs the editor parser. One instance should be used per active editor. This
        /// instance <em>can</em> be shared among reparses, but should <em>never</em> be shared between documents.
        /// </summary>
        /// <param name="host">The <see cref="RazorEngineHost"/> which defines the environment in which the generated
        /// code will live. <see cref="RazorEngineHost.DesignTimeMode"/> should be set if design-time behavior is
        /// desired.</param>
        /// <param name="sourceFileName">The physical path to use in line pragmas.</param>
        public RazorEditorParser(RazorEngineHost host, string sourceFileName)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            if (string.IsNullOrEmpty(sourceFileName))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, nameof(sourceFileName));
            }

            Host = host;
            FileName = sourceFileName;
            _parser = new BackgroundParser(host, sourceFileName);
            _parser.ResultsReady += (sender, args) => OnDocumentParseComplete(args);
            _parser.Start();
        }
Esempio n. 22
0
 protected override SyntaxTagger CreateTagger(BackgroundParser backgroundParser, ITextSnapshot snapshot)
 {
     return(new SyntaxTagger(_hlslClassificationService, backgroundParser));
 }