Ejemplo n.º 1
0
        private Diagnostic ConvertErrorToDiagnostic(PhysicalFile file, DiagnosticElement e)
        {
            int line   = e.Tok.line - 1;
            int col    = e.Tok.col - 1;
            int length = file.GetLengthOfLine(line) - col;

            var range = this.CreateRange(line, col, length);

            if (e.Msg.EndsWith("."))
            {
                e.Msg = e.Msg.Substring(0, e.Msg.Length - 1);
            }

            string msg;

            if (e.Tok.val == "anything so that it is nonnull" || e.Tok.val == null)
            {
                msg = e.Msg;
            }
            else if (e.Tok.val.Equals("{") && _fileRepository.SymbolTableManager != null)
            {
                ISymbolInformation wrappingSymbol = _fileRepository.SymbolTableManager.GetSymbolWrapperForCurrentScope(file.Uri, line, col);
                range = CreateRange(wrappingSymbol.Position.BodyStartToken, wrappingSymbol.Position.BodyEndToken);
                msg   = e.Msg + $"\n at {wrappingSymbol.Name}";
            }
            else
            {
                msg = e.Msg + $" \n at {e.Tok.val}\n ";
            }

            string src = file.Filepath.Split('/').Last();

            DiagnosticSeverity severity;

            switch (e.Severity)
            {
            case ErrorLevel.Error:
                severity = DiagnosticSeverity.Error;
                break;

            case ErrorLevel.Warning:
                severity = DiagnosticSeverity.Warning;
                break;

            case ErrorLevel.Info:
                severity = DiagnosticSeverity.Information;
                break;

            default:
                severity = DiagnosticSeverity.Error;
                break;
            }

            Diagnostic d = new Diagnostic
            {
                Message  = msg,
                Range    = range,
                Severity = severity,
                Source   = src
            };

            return(d);
        }
Ejemplo n.º 2
0
        private IEnumerable <Diagnostic> ExtractRelatedInformationOfAnError(PhysicalFile file, DiagnosticElement e)
        {
            List <Diagnostic> relatedInformations = new List <Diagnostic>();

            foreach (ErrorInformation.AuxErrorInfo aux in e.Aux)
            {
                if (aux.Category == "Execution trace")
                {
                    continue;
                }
                string auxmessage = aux.Msg;
                int    auxline    = aux.Tok.line - 1;
                int    auxcol     = aux.Tok.col - 1;
                int    auxlength  = file.GetLengthOfLine(auxline) - auxcol;
                Range  auxrange   = CreateRange(auxline, auxcol, auxlength);

                string     src = file.FileName;
                Diagnostic relatedDiagnostic = new Diagnostic
                {
                    Message  = auxmessage,
                    Range    = auxrange,
                    Severity = DiagnosticSeverity.Information,
                    Source   = src
                };

                relatedInformations.Add(relatedDiagnostic);
            }
            return(relatedInformations);
        }