Exemple #1
0
        public void Invoke(CancellationToken cancellationToken)
        {
            if (_virtualTextDocument == null)
            {
                return;
            }

            var codeStreamService = ComponentModel?.GetService <ICodeStreamService>();

            if (codeStreamService == null)
            {
                return;
            }

            ThreadHelper.JoinableTaskFactory.Run(async delegate {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                try {
                    var toolWindowProvider = Package.GetGlobalService(typeof(SToolWindowProvider)) as IToolWindowProvider;
                    if (!toolWindowProvider.IsVisible(Guids.WebViewToolWindowGuid))
                    {
                        if (toolWindowProvider?.ShowToolWindowSafe(Guids.WebViewToolWindowGuid) == true)
                        {
                        }
                        else
                        {
                            Log.Warning("Could not activate tool window");
                        }
                    }
                    var sessionService = ComponentModel.GetService <ISessionService>();
                    if (sessionService.WebViewDidInitialize == true)
                    {
                        var editorState = _wpfTextView.GetEditorState();
                        _ = codeStreamService.NewCodemarkAsync(_virtualTextDocument.Uri, editorState?.Range, CodemarkType, "Lightbulb Menu", cancellationToken: cancellationToken);
                    }
                    else
                    {
                        var eventAggregator = ComponentModel.GetService <IEventAggregator>();
                        IDisposable d       = null;
                        d = eventAggregator.GetEvent <WebviewDidInitializeEvent>().Subscribe(e => {
                            try {
                                var editorState = _wpfTextView.GetEditorState();
                                _ = codeStreamService.NewCodemarkAsync(_virtualTextDocument.Uri, editorState?.Range, CodemarkType, "Lightbulb Menu", cancellationToken: cancellationToken); d.Dispose();
                            }
                            catch (Exception ex) {
                                Log.Error(ex, $"{nameof(CodemarkSuggestedActionBase)} event");
                            }
                        });
                    }
                }
                catch (Exception ex) {
                    Log.Error(ex, nameof(CodemarkSuggestedActionBase));
                }
            });
        }
Exemple #2
0
        private IEnumerable <SuggestedActionSet> GetSuggestedActionsCore(IWpfTextView wpfTextView)
        {
            try {
                if (wpfTextView == null)
                {
                    return(Enumerable.Empty <SuggestedActionSet>());
                }

                var editorState = wpfTextView.GetEditorState();
                System.Diagnostics.Debug.WriteLine($"GetSuggestedActions");
                return(new[] {
                    new SuggestedActionSet(
                        actions: new ISuggestedAction[] {
                        new CodemarkCommentSuggestedAction(_componentModel, _textDocument, editorState),
                        new CodemarkIssueSuggestedAction(_componentModel, _textDocument, editorState),
                        new CodemarkPermalinkSuggestedAction(_componentModel, _textDocument, editorState)
                    },
                        categoryName: null,
                        title: null,
                        priority: SuggestedActionSetPriority.None,
                        applicableToSpan: null
                        )
                });
            }
            catch (Exception ex) {
                Log.Warning(ex, nameof(GetSuggestedActionsCore));
            }

            return(Enumerable.Empty <SuggestedActionSet>());
        }
Exemple #3
0
 public EditorState GetEditorState(IWpfTextView wpfTextView)
 {
     try {
         return(wpfTextView.GetEditorState());
     }
     catch (Exception ex) {
         Log.Error(ex, nameof(GetEditorState));
         return(new EditorState(new Range().AsEmpty(), new Position(0, 0), null));
     }
 }