コード例 #1
0
            public static void FindErrorLocation(string code, Diagnostic error, out int globalErrorPos, out UserCode.Entry?userCodeEntry)
            {
                globalErrorPos = 0;
                userCodeEntry  = null;

                if (!error.Location.IsInSource)
                {
                    return;
                }
                var lineSpan = error.Location.GetLineSpan();

                if (!lineSpan.IsValid)
                {
                    return;
                }

                List <UserCode.LineInfo> lines = new List <UserCode.LineInfo>(UserCode.GetLines(code));

                int lineIdx = lineSpan.EndLinePosition.Line;

                if (lineIdx < 0 || lineIdx >= lines.Count)
                {
                    return;
                }

                globalErrorPos = lines[lineIdx].Position + lineSpan.EndLinePosition.Character;
                foreach (UserCode.Entry uce in UserCode.GetEntries(code))
                {
                    if (globalErrorPos >= uce.Index && globalErrorPos < (uce.Index + uce.Length))
                    {
                        userCodeEntry = uce;
                        break;
                    }
                }
            }
コード例 #2
0
            public static void FindErrorLocation(string code, CompilerError error, out int globalErrorPos, out UserCode.Entry?userCodeEntry)
            {
                globalErrorPos = 0;
                userCodeEntry  = null;

                List <UserCode.LineInfo> lines = new List <UserCode.LineInfo>(UserCode.GetLines(code));

                int lineIdx = error.Line - 1;

                if (lineIdx < 0 || lineIdx >= lines.Count)
                {
                    return;
                }

                globalErrorPos = lines[lineIdx].Position + error.Column - 1;
                foreach (UserCode.Entry uce in UserCode.GetEntries(code))
                {
                    if (globalErrorPos >= uce.Index && globalErrorPos < (uce.Index + uce.Length))
                    {
                        userCodeEntry = uce;
                        break;
                    }
                }
            }