示例#1
0
        public DocumentId Initialize(IRoslynHost roslynHost, IClassificationHighlightColors highlightColors, string workingDirectory, string documentText)
        {
            _roslynHost = roslynHost ?? throw new ArgumentNullException(nameof(roslynHost));
            _classificationHighlightColors = highlightColors ?? throw new ArgumentNullException(nameof(highlightColors));

            _braceMatcherHighlighter = new BraceMatcherHighlightRenderer(TextArea.TextView, _classificationHighlightColors);

            _quickInfoProvider    = _roslynHost.GetService <IQuickInfoProvider>();
            _braceMatchingService = _roslynHost.GetService <IBraceMatchingService>();

            var avalonEditTextContainer = new AvalonEditTextContainer(Document)
            {
                Editor = this
            };

            _documentId = roslynHost.AddDocument(avalonEditTextContainer, workingDirectory,
                                                 args => _syncContext.Post(o => ProcessDiagnostics(args), null),
                                                 text => avalonEditTextContainer.UpdateText(text));

            AppendText(documentText);
            Document.UndoStack.ClearAll();
            AsyncToolTipRequest = OnAsyncToolTipRequest;

            TextArea.TextView.LineTransformers.Insert(0, new RoslynHighlightingColorizer(_documentId, _roslynHost, _classificationHighlightColors));

            _contextActionsRenderer = new ContextActionsRenderer(this, _textMarkerService);
            _contextActionsRenderer.Providers.Add(new RoslynContextActionProvider(_documentId, _roslynHost));

            CompletionProvider = new RoslynCodeEditorCompletionProvider(_documentId, _roslynHost);

            return(_documentId);
        }
        public BraceMatcherHighlightRenderer(TextView textView, IClassificationHighlightColors classificationHighlightColors)
        {
            _textView = textView ?? throw new ArgumentNullException(nameof(textView));

            _textView.BackgroundRenderers.Add(this);

            var brush = classificationHighlightColors
                        .GetBrush(ClassificationHighlightColors.BraceMatchingClassificationTypeName)
                        ?.Background?.GetBrush(null);

            if (brush != null)
            {
                _backgroundBrush = brush;
            }
            else
            {
                _backgroundBrush = Brushes.Transparent;
            }
        }
        public RoslynSemanticHighlighter(IDocument document, DocumentId documentId, IRoslynHost roslynHost, IClassificationHighlightColors highlightColors)
        {
            _document        = document ?? throw new ArgumentNullException(nameof(document));
            _documentId      = documentId;
            _roslynHost      = roslynHost;
            _highlightColors = highlightColors;
            _semaphore       = new SemaphoreSlim(0);
            _queue           = new ConcurrentQueue <HighlightedLine>();

            if (document is TextDocument)
            {
                // Use the cache only for the live AvalonEdit document
                // Highlighting in read-only documents (e.g. search results) does
                // not need the cache as it does not need to highlight the same line multiple times
                _cachedLines = new List <CachedLine>();
            }

            _syncContext = SynchronizationContext.Current;
            _cts         = new CancellationTokenSource();
            var cancellationToken = _cts.Token;

            Task.Run(() => Worker(cancellationToken), cancellationToken);
        }
 public RoslynHighlightingColorizer(DocumentId documentId, IRoslynHost roslynHost, IClassificationHighlightColors highlightColors)
 {
     _documentId      = documentId;
     _roslynHost      = roslynHost;
     _highlightColors = highlightColors;
 }