Beispiel #1
0
        public static void QueueQuickFixAnalysis(MonoDevelop.Ide.Gui.Document doc, TextLocation loc, Action <List <MonoDevelop.CodeActions.CodeAction> > callback)
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                try {
                    var result = new List <MonoDevelop.CodeActions.CodeAction> ();

                    var ext = doc.GetContent <MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
                    if (ext != null)
                    {
                        foreach (var r in ext.GetResultsAtOffset(doc.Editor.LocationToOffset(loc)).OrderBy(r => r.Level))
                        {
                            var fresult = r as FixableResult;
                            if (fresult == null)
                            {
                                continue;
                            }
                            foreach (var action in FixOperationsHandler.GetActions(doc, fresult))
                            {
                                result.Add(new AnalysisContextActionProvider.AnalysisCodeAction(action, r));
                            }
                        }
                    }
                    result.AddRange(GetValidActions(doc, loc).Result);
                    callback(result);
                } catch (Exception ex) {
                    LoggingService.LogError("Error in analysis service", ex);
                }
            });
        }
Beispiel #2
0
        public static void QueueQuickFixAnalysis(Document doc, TextLocation loc, CancellationToken token, Action <List <CodeAction> > callback)
        {
            var ext    = doc.GetContent <MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
            var issues = ext != null?ext.GetResultsAtOffset(doc.Editor.LocationToOffset(loc), token).OrderBy(r => r.Level).ToList() : new List <Result> ();

            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    var result = new List <CodeAction> ();
                    foreach (var r in issues)
                    {
                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        var fresult = r as FixableResult;
                        if (fresult == null)
                        {
                            continue;
                        }
                        foreach (var action in FixOperationsHandler.GetActions(doc, fresult))
                        {
                            result.Add(new AnalysisContextActionProvider.AnalysisCodeAction(action, r)
                            {
                                DocumentRegion = action.DocumentRegion
                            });
                        }
                    }
                    result.AddRange(GetValidActions(doc, loc).Result);
                    callback(result);
                } catch (Exception ex) {
                    LoggingService.LogError("Error in analysis service", ex);
                }
            });
        }
Beispiel #3
0
        public static void QueueQuickFixAnalysis(MonoDevelop.Ide.Gui.Document doc, DomLocation loc, Action <List <ContextAction> > callback)
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                try {
                    string disabledNodes = PropertyService.Get("ContextActions." + doc.Editor.Document.MimeType, "") ?? "";

                    var availableFixes = new List <ContextAction> (contextActions.Where(fix => disabledNodes.IndexOf(fix.Type.FullName) < 0 && fix.Action.IsValid(doc, loc)).Select(fix => fix.Action));
                    var ext            = doc.GetContent <MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
                    if (ext != null)
                    {
                        foreach (var result in ext.GetResultsAtOffset(doc.Editor.LocationToOffset(loc.Line, loc.Column)))
                        {
                            var fresult = result as FixableResult;
                            if (fresult == null)
                            {
                                continue;
                            }
                            foreach (var action in FixOperationsHandler.GetActions(doc, fresult))
                            {
                                availableFixes.Add(new AnalysisContextAction(result, action));
                            }
                        }
                    }

                    callback(availableFixes);
                } catch (Exception ex) {
                    LoggingService.LogError("Error in analysis service", ex);
                }
            });
        }