public override void AddError(string path, string message, string lineText, CodeSpan location, int errorCode, Severity severity)
        {
            // keep the error list under 100 items which is a reasonable number and avoids spending too much time on error processing
            if (Errors.Count < 100)
            {
                int startIndex, endIndex;
                if (location.StartLine > 0 && location.EndLine > 0)
                {
                    // get the error bounds to create a span pointing to the error text so it can be navigated to later on by the Error List
                    startIndex = textBuffer.CurrentSnapshot.GetLineFromLineNumber(location.StartLine - 1).Start.Position + location.StartColumn;
                    endIndex = textBuffer.CurrentSnapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn;

                    if (startIndex < endIndex && endIndex < textBuffer.CurrentSnapshot.GetText().Length)
                    {
                        // add the error with all its necessary information
                        Errors.Add(new ValidationError(new Span(startIndex, endIndex - startIndex), message, GetSeverity(severity), ValidationErrorType.Syntactic));

                        if (Errors.Count == 100)
                        {
                            // add a friendly error telling the user the maximum number of errors has been reached
                            Errors.Add(new ValidationError(new Span(startIndex, endIndex - startIndex), "The maximum number of errors or warnings has been reached."));
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Converts between an IronPython's CodeSpan and the new text editor's Span
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        private Span ConvertCodeSpanToSpan(CodeSpan location)
        {
            if (location.StartLine > 0 && location.EndLine > 0)
            {
                var startIndex = snapshot.GetLineFromLineNumber(location.StartLine - 1).Start.Position + location.StartColumn - 1;
                var endIndex = snapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn - 1;

                if (startIndex != -1 && startIndex < endIndex && endIndex < snapshot.GetText().Length)
                {
                    return new Span(startIndex, endIndex - startIndex);
                }
            }

            return new Span();
        }
Exemplo n.º 3
0
        public override void AddError(string path, string message, string lineText, CodeSpan span, int errorCode, Severity severity)
        {
            if (severity == Severity.Warning) {
                throw Ops.SyntaxWarning(message, path, span.StartLine, span.StartColumn, lineText, severity);
            }

            switch (errorCode & ErrorCodes.ErrorMask) {
                case ErrorCodes.IndentationError:
                    throw Ops.IndentationError(message, path, span.StartLine, span.StartColumn, lineText, errorCode, severity);
                case ErrorCodes.TabError:
                    throw Ops.TabError(message, path, span.StartLine, span.StartColumn, lineText, errorCode, severity);
                default:
                    throw Ops.SyntaxError(message, path, span.StartLine, span.StartColumn, lineText, errorCode, severity);
            }
        }
Exemplo n.º 4
0
        private static TextSpan CodeToText(Hosting.CodeSpan code)
        {
            TextSpan span = new TextSpan();

            if (code.StartLine > 0)
            {
                span.iStartLine = code.StartLine - 1;
            }
            span.iStartIndex = code.StartColumn;
            if (code.EndLine > 0)
            {
                span.iEndLine = code.EndLine - 1;
            }
            span.iEndIndex = code.EndColumn;
            return(span);
        }
Exemplo n.º 5
0
        public override void AddError(string path, string message, string lineText, Hosting.CodeSpan location, int errorCode, Hosting.Severity severity)
        {
            TextSpan span = new TextSpan();

            if (location.StartLine > 0)
            {
                span.iStartLine = location.StartLine - 1;
            }
            span.iStartIndex = location.StartColumn;
            if (location.EndLine > 0)
            {
                span.iEndLine = location.EndLine - 1;
            }
            span.iEndIndex = location.EndColumn;
            authoringSink.AddError(path, message, span, Severity.Error);
        }
Exemplo n.º 6
0
 public void SetLoc(CodeSpan span)
 {
     SetLoc(null, span);
 }
Exemplo n.º 7
0
 public override void QualifyName(Hosting.CodeSpan selector, Hosting.CodeSpan span, string name)
 {
     authoringSink.QualifyName(CodeToText(selector), CodeToText(span), name);
 }
Exemplo n.º 8
0
 public virtual void StartParameters(CodeSpan context)
 {
 }
Exemplo n.º 9
0
 public virtual void QualifyName(CodeSpan selector, CodeSpan span, string name)
 {
 }
Exemplo n.º 10
0
 public virtual void MatchTriple(CodeSpan start, CodeSpan middle, CodeSpan end, int priority)
 {
 }
Exemplo n.º 11
0
        public override void AddError(string path, string message, string lineText, CodeSpan location, int errorCode, Severity severity)
        {
            string sev;
            if (severity >= Severity.Error)
                sev = "Error";
            else if (severity >= Severity.Warning)
                sev = "Warning";
            else
                sev = "Message";

            throw new CompilerException(string.Format("{0}:{1} at {2} {3}:{4}-{5}:{6}", sev, message, path, location.StartLine, location.StartColumn, location.EndLine, location.EndColumn));
        }
Exemplo n.º 12
0
 public virtual void MatchTriple(CodeSpan start, CodeSpan middle, CodeSpan end, int priority)
 {
 }
Exemplo n.º 13
0
 public virtual void MatchPair(CodeSpan start, CodeSpan end, int priority)
 {
 }
Exemplo n.º 14
0
 public virtual void AddError(string path, string message, CodeSpan location, int errorCode, Severity severity)
 {
     AddError(path, message, String.Empty, location.startLine, location.startColumn, location.endLine, location.endColumn, errorCode, severity);
 }
Exemplo n.º 15
0
 public override void EndParameters(Hosting.CodeSpan span)
 {
     authoringSink.EndParameters(CodeToText(span));
 }
Exemplo n.º 16
0
 public override void MatchPair(Hosting.CodeSpan span, Hosting.CodeSpan endContext, int priority)
 {
     authoringSink.MatchPair(CodeToText(span), CodeToText(endContext), priority);
 }
Exemplo n.º 17
0
 internal void SetLoc(ExternalLineMapping externalInfo, CodeSpan span)
 {
     start.Line = span.StartLine;
     start.Column = span.StartColumn;
     end.Line = span.EndLine;
     end.Column = span.EndColumn;
     externalMapping = externalInfo;
 }
Exemplo n.º 18
0
 public virtual void EndParameters(CodeSpan span)
 {
 }
Exemplo n.º 19
0
 public virtual void EndParameters(CodeSpan span)
 {
 }
Exemplo n.º 20
0
 public override void StartName(Hosting.CodeSpan span, string name)
 {
     authoringSink.StartName(CodeToText(span), name);
 }
Exemplo n.º 21
0
 public abstract void AddError(string path, string message, string lineText, CodeSpan location, int errorCode, Severity severity);
Exemplo n.º 22
0
 public virtual void NextParameter(CodeSpan span)
 {
 }
Exemplo n.º 23
0
 public virtual void MatchPair(CodeSpan start, CodeSpan end, int priority)
 {
 }
Exemplo n.º 24
0
 public virtual void QualifyName(CodeSpan selector, CodeSpan span, string name)
 {
 }
Exemplo n.º 25
0
 public virtual void NextParameter(CodeSpan span)
 {
 }
Exemplo n.º 26
0
 public virtual void StartName(CodeSpan span, string name)
 {
 }
Exemplo n.º 27
0
 public virtual void StartName(CodeSpan span, string name)
 {
 }
Exemplo n.º 28
0
 public virtual void StartParameters(CodeSpan context)
 {
 }
Exemplo n.º 29
0
        public override void AddError(string path, string message, string lineText, CodeSpan span, int errorCode, Severity severity)
        {
            if (severity >= Severity.Error) errors++;
            else if (severity >= Severity.Warning) warnings++;
            else messages++;

            if (sink != null) {
                sink.AddError(path, message, lineText, span, errorCode, severity);
            } else {
                throw new CompilerException(string.Format("{0}:{1} at {2} {3}:{4}-{5}:{6}", severity, message, path,
                                                  span.StartLine, span.StartColumn, span.EndLine, span.EndColumn));
            }
        }
 public override void MatchPair(CodeSpan opening, CodeSpan closing, int priority)
 {
     Matches.Add(new System.Tuple<SnapshotSpan, SnapshotSpan>(new SnapshotSpan(snapshot, ConvertCodeSpanToSpan(opening)), new SnapshotSpan(snapshot, ConvertCodeSpanToSpan(closing))));
 }
 public override void AddError(string path, string message, string lineText, CodeSpan span, int errorCode, Severity severity)
 {
 }
Exemplo n.º 32
0
 public override void NextParameter(Hosting.CodeSpan span)
 {
     authoringSink.NextParameter(CodeToText(span));
 }