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); }
private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { _viewModel = (OpenDocumentViewModel)args.NewValue; _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _roslynHost = _viewModel.MainViewModel.RoslynHost; var avalonEditTextContainer = new AvalonEditTextContainer(Editor); await _viewModel.Initialize( avalonEditTextContainer, a => _syncContext.Post(o => ProcessDiagnostics(a), null), text => avalonEditTextContainer.UpdateText(text) ).ConfigureAwait(true); Editor.Document.UndoStack.ClearAll(); Editor.TextArea.TextView.LineTransformers.Insert(0, new RoslynHighlightingColorizer(_viewModel.DocumentId, _roslynHost)); _contextActionsRenderer = new ContextActionsRenderer(Editor, _textMarkerService); _contextActionsRenderer.Providers.Add(new RoslynContextActionProvider(_viewModel.DocumentId, _roslynHost)); Editor.CompletionProvider = new RoslynCodeEditorCompletionProvider(_viewModel.DocumentId, _roslynHost); }