Example #1
0
        void FindCurrentReferences(int start, int end)
        {
            ICompilation compilation             = SD.ParserService.GetCompilationForFile(editor.FileName);
            CSharpFullParseInformation parseInfo = SD.ParserService.GetCachedParseInformation(editor.FileName) as CSharpFullParseInformation;

            if (currentSymbolReference == null || parseInfo == null)
            {
                return;
            }

            IResolveVisitorNavigator currentNavigator = InitNavigator(compilation);
            CSharpAstResolver        resolver         = parseInfo.GetResolver(compilation);

            if (currentNavigator == null || resolver == null)
            {
                return;
            }

            VisitVisibleNodes(parseInfo.SyntaxTree, currentNavigator, resolver, start, end);
        }
Example #2
0
        async void RunAnalysis(ITextSource textSource, CSharpFullParseInformation parseInfo)
        {
            if (markerService == null)
            {
                return;
            }
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }
            cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken        = cancellationTokenSource.Token;
            List <InspectionTag> results = new List <InspectionTag>();

            try {
                await Task.Run(
                    delegate {
                    var compilation = SD.ParserService.GetCompilationForFile(parseInfo.FileName);
                    var resolver    = parseInfo.GetResolver(compilation);
                    var context     = new SDRefactoringContext(textSource, resolver, new TextLocation(0, 0), 0, 0, cancellationToken);
                    foreach (var issueProvider in issueProviders.Value)
                    {
                        if (issueProvider.CurrentSeverity == Severity.None)
                        {
                            continue;
                        }

                        foreach (var issue in issueProvider.GetIssues(context))
                        {
                            if (issue.Start.IsEmpty || issue.End.IsEmpty)
                            {
                                // Issues can occur on invalid locations when analyzing incomplete code.
                                // We'll just ignore them.
                                continue;
                            }
                            results.Add(new InspectionTag(
                                            this,
                                            issueProvider,
                                            textSource.Version,
                                            issue.Description,
                                            context.GetOffset(issue.Start),
                                            context.GetOffset(issue.End),
                                            issue.IssueMarker,
                                            issue.Actions));
                        }
                    }
                }, cancellationToken);
            } catch (TaskCanceledException) {
            } catch (OperationCanceledException) {
            } catch (Exception ex) {
                SD.Log.WarnFormatted("IssueManager crashed: {0}", ex);
                SD.AnalyticsMonitor.TrackException(ex);
            }
            if (!cancellationToken.IsCancellationRequested)
            {
                analyzedVersion = textSource.Version;
                Clear();
                foreach (var newResult in results)
                {
                    newResult.CreateMarker(editor.Document, markerService);
                }
                existingResults = results;
            }
            if (cancellationTokenSource != null && cancellationTokenSource.Token == cancellationToken)
            {
                // Dispose the cancellation token source if it's still the same one as we originally created
                cancellationTokenSource.Dispose();
                cancellationTokenSource = null;
            }
        }
        HighlightedLine DoHighlightLine(int lineNumber, IDocumentLine documentLine, CachedLine cachedLine, ITextSourceVersion newVersion)
        {
            if (parseInfo == null)
            {
                if (forceParseOnNextRefresh)
                {
                    forceParseOnNextRefresh = false;
                    parseInfo = SD.ParserService.Parse(FileName.Create(document.FileName), document) as CSharpFullParseInformation;
                }
                else
                {
                    parseInfo = SD.ParserService.GetCachedParseInformation(FileName.Create(document.FileName), newVersion) as CSharpFullParseInformation;
                }
            }
            if (parseInfo == null)
            {
                if (invalidLines != null && !invalidLines.Contains(documentLine))
                {
                    invalidLines.Add(documentLine);
                    //Debug.WriteLine("Semantic highlighting for line {0} - marking as invalid", lineNumber);
                }

                if (cachedLine != null)
                {
                    // If there's a cached version, adjust it to the latest document changes and return it.
                    // This avoids flickering when changing a line that contains semantic highlighting.
                    cachedLine.Update(newVersion);
                                        #if DEBUG
                    cachedLine.HighlightedLine.ValidateInvariants();
                                        #endif
                    return(cachedLine.HighlightedLine);
                }
                else
                {
                    return(null);
                }
            }

            if (visitor.Resolver == null)
            {
                var compilation = SD.ParserService.GetCompilationForFile(parseInfo.FileName);
                visitor.Resolver = parseInfo.GetResolver(compilation);
            }

            line            = new HighlightedLine(document, documentLine);
            this.lineNumber = lineNumber;
            visitor.UpdateLineInformation(lineNumber);

            if (Debugger.IsAttached)
            {
                parseInfo.SyntaxTree.AcceptVisitor(visitor);
                                #if DEBUG
                line.ValidateInvariants();
                                #endif
            }
            else
            {
                try {
                    parseInfo.SyntaxTree.AcceptVisitor(visitor);
                                        #if DEBUG
                    line.ValidateInvariants();
                                        #endif
                } catch (Exception ex) {
                    hasCrashed = true;
                    throw new ApplicationException("Error highlighting line " + lineNumber, ex);
                }
            }
            //Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count);
            if (cachedLines != null && document.Version != null)
            {
                cachedLines.Add(new CachedLine(line, document.Version));
            }
            return(line);
        }