Example #1
0
        /// <summary>
        /// 拿到异常之后进行后处理,如果处理后可以重编译,将再次编译
        /// </summary>
        /// <param name="errors"></param>
        /// <returns></returns>
        private bool CanRetryCompile(ImmutableArray <Diagnostic> errors)
        {
            Exceptions = NatashaException.GetCompileException(Compiler.AssemblyName, errors);
            Dictionary <string, string> codeMappings = new Dictionary <string, string>();

            foreach (var item in Exceptions)
            {
                if (item.Formatter != default)
                {
                    codeMappings[item.Formatter] = item.Formatter;
                    if (item.HasError)
                    {
                        foreach (var error in item.Diagnostics)
                        {
                            if (ErrorHandlers.ContainsKey(error.Id))
                            {
                                CanRetry = true;
                                ErrorHandlers[error.Id](item, error, Syntax, codeMappings);
                            }
                        }
                    }
                }
            }
            if (CanRetry)
            {
                CanRetry    = false;
                RetryCount += 1;
                if (RetryCount < RetryLimit)
                {
                    foreach (var item in codeMappings)
                    {
                        Syntax.Update(item.Key, item.Value);
                    }
                    return(true);
                }
            }
            return(false);
        }