示例#1
0
        private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            _viewModel = (OpenDocumentViewModel)args.NewValue;
            _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled;
            _roslynHost        = _viewModel.MainViewModel.RoslynHost;
            _quickInfoProvider = _roslynHost.GetService <IQuickInfoProvider>();

            _viewModel.MainViewModel.EditorFontSizeChanged += OnEditorFontSizeChanged;
            Editor.FontSize = _viewModel.MainViewModel.EditorFontSize;

            var avalonEditTextContainer = new AvalonEditTextContainer(Editor);

            await _viewModel.Initialize(
                avalonEditTextContainer,
                a => _syncContext.Post(o => ProcessDiagnostics(a), null),
                text => avalonEditTextContainer.UpdateText(text),
                OnError,
                () => new TextSpan(Editor.SelectionStart, Editor.SelectionLength),
                this).ConfigureAwait(true);

            var documentText = await _viewModel.LoadText().ConfigureAwait(true);

            Editor.AppendText(documentText);
            Editor.Document.UndoStack.ClearAll();
            Editor.Document.TextChanged += (o, e) => _viewModel.SetDirty(Editor.Document.TextLength);
            Editor.AsyncToolTipRequest   = AsyncToolTipRequest;

            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);
        }
示例#2
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);
        }
示例#3
0
 public Model(
     ITextVersion textVersion,
     QuickInfoItem item,
     IQuickInfoProvider provider,
     bool trackMouse)
 {
     this.TextVersion = textVersion;
     this.Item        = item;
     this.Provider    = provider;
     this.TrackMouse  = trackMouse;
 }
示例#4
0
文件: Model.cs 项目: GloryChou/roslyn
        public Model(
            ITextVersion textVersion,
            QuickInfoItem item,
            IQuickInfoProvider provider,
            bool trackMouse)
        {
            Contract.ThrowIfNull(item);

            this.TextVersion = textVersion;
            this.Item = item;
            this.Provider = provider;
            this.TrackMouse = trackMouse;
        }
示例#5
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Occurs when the button is clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
        private void OnShowQuickInfoButtonClick(object sender, RoutedEventArgs e)
        {
            // Ensure the editor has focus
            editor.Focus();

            // Get the IQuickInfoProvider that is registered with the language
            IQuickInfoProvider provider = editor.Document.Language.GetService <CustomQuickInfoProvider>();

            if (provider != null)
            {
                // Create a context
                object context = provider.GetContext(editor.ActiveView, editor.ActiveView.Selection.CaretOffset);

                if (context != null)
                {
                    // Request that a session is created based on the context, and disable mouse tracking since
                    //   this request is initiated from a button click
                    provider.RequestSession(editor.ActiveView, context, false);
                }
            }
        }