示例#1
0
        private bool IsLineHashDifferent(IAnalysisIssueLocation location, ITextSnapshotLine snapshotLine)
        {
            if (string.IsNullOrEmpty(location.LineHash))
            {
                return(false);
            }

            var textInSnapshot   = snapshotLine.GetText();
            var snapshotLineHash = checksumCalculator.Calculate(textInSnapshot);

            return(snapshotLineHash != location.LineHash);
        }
示例#2
0
        public SnapshotSpan CalculateSpan(IAnalysisIssueLocation location, ITextSnapshot currentSnapshot)
        {
            if (location.StartLine > currentSnapshot.LineCount)
            {
                // Race condition: the line reported in the diagnostic is beyond the end of the file, so presumably
                // the file has been edited while the analysis was being executed
                return(EmptySpan);
            }

            // SonarLint issues line numbers are 1-based, spans lines are 0-based
            var startLine = currentSnapshot.GetLineFromLineNumber(location.StartLine - 1);

            if (IsLineHashDifferent(location, startLine))
            {
                // Out of sync: the line reported in the diagnostic has been edited, so we can no longer calculate the span
                return(EmptySpan);
            }

            var maxLength = currentSnapshot.Length;

            var startPos = startLine.Start.Position + location.StartLineOffset;

            int endPos;

            if (location.EndLine == 0 ||    // Special case : EndLine = 0 means "select whole of the start line, ignoring the offset"
                startPos > maxLength)       // Defensive : issue start position is beyond the end of the file. Just select the last line.
            {
                startPos = startLine.Start.Position;
                endPos   = startLine.Start.Position + startLine.Length;
            }
            else
            {
                endPos = currentSnapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndLineOffset;
                // Make sure the end position isn't beyond the end of the snapshot either
                endPos = Math.Min(maxLength, endPos);
            }

            var start = new SnapshotPoint(currentSnapshot, startPos);
            var end   = new SnapshotPoint(currentSnapshot, endPos);

            return(new SnapshotSpan(start, end));
        }
 public AnalysisIssueLocationVisualization(int stepNumber, IAnalysisIssueLocation location)
 {
     StepNumber      = stepNumber;
     Location        = location;
     CurrentFilePath = location.FilePath;
 }
 private void SetupSpanCalculator(IAnalysisIssueLocation issueLocation, SnapshotSpan nonEmptySpan)
 {
     issueSpanCalculatorMock.Setup(x => x.CalculateSpan(issueLocation, textSnapshotMock)).Returns(nonEmptySpan);
 }
示例#5
0
 private void SetupCalculatedSpan(IAnalysisIssueLocation analysisIssueLocation, SnapshotSpan span)
 {
     spanCalculatorMock.Setup(x => x.CalculateSpan(analysisIssueLocation, textViewCurrentSnapshotMock)).Returns(span);
 }