Exemple #1
0
        private static ErrorTask CreateTask(CompilerError error, ErrorListProvider provider)
        {
            ErrorTask task = new ErrorTask()
            {
                Line = error.LineNumber,
                Column = error.ColumnNumber,
                ErrorCategory = error.IsWarning ? TaskErrorCategory.Warning : TaskErrorCategory.Error,
                Category = TaskCategory.BuildCompile,
                Document = error.FileName,
                Priority = TaskPriority.Normal,
                Text = $"(WebCompiler) {error.Message}",
            };

            EnvDTE.ProjectItem item = WebCompilerPackage._dte.Solution.FindProjectItem(error.FileName);

            if (item != null && item.ContainingProject != null)
                AddHierarchyItem(task, item.ContainingProject);

            task.Navigate += (s, e) =>
            {
                provider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindPrimary));

                if (task.Column > 0)
                {
                    var doc = (EnvDTE.TextDocument)WebCompilerPackage._dte.ActiveDocument.Object("textdocument");
                    doc.Selection.MoveToLineAndOffset(task.Line, task.Column, false);
                }
            };

            return task;
        }
Exemple #2
0
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            try
            {
                RunCompilerProcess(config, info);

                int sourceMapIndex = _output.LastIndexOf("*/");
                if (sourceMapIndex > -1 && _output.Contains("sourceMappingURL=data:"))
                {
                    _output = _output.Substring(0, sourceMapIndex + 2);
                }

                result.CompiledContent = _output;

                if (_error.Length > 0)
                {
                    JObject json = JObject.Parse(_error);

                    CompilerError ce = new CompilerError
                    {
                        FileName = info.FullName,
                        Message = json["message"].ToString(),
                        ColumnNumber = int.Parse(json["column"].ToString()),
                        LineNumber = int.Parse(json["line"].ToString()),
                        IsWarning = !string.IsNullOrEmpty(_output)
                    };

                    result.Errors.Add(ce);
                }
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = string.IsNullOrEmpty(_error) ? ex.Message : _error,
                    LineNumber = 0,
                    ColumnNumber = 0,
                };

                result.Errors.Add(error);
            }

            return result;
        }
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            try
            {
                RunCompilerProcess(config, info);

                result.CompiledContent = _output;

                if (_error.Length > 0)
                {
                    CompilerError ce = new CompilerError
                    {
                        FileName = info.FullName,
                        Message = _error.Replace(baseFolder, string.Empty),
                        IsWarning = !string.IsNullOrEmpty(_output)
                    };

                    var match = _errorRx.Match(_error);

                    if (match.Success)
                    {
                        ce.Message = match.Groups["message"].Value.Replace(baseFolder, string.Empty);
                        ce.LineNumber = int.Parse(match.Groups["line"].Value);
                        ce.ColumnNumber = int.Parse(match.Groups["column"].Value);
                    }

                    result.Errors.Add(ce);
                }
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = string.IsNullOrEmpty(_error) ? ex.Message : _error,
                    LineNumber = 0,
                    ColumnNumber = 0,
                };

                result.Errors.Add(error);
            }

            return result;
        }
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            CoffeeScriptOptions options = new CoffeeScriptOptions(config);

            try
            {
                string compilerResult = _engine.Compile(content, filename: info.FullName, bare: options.Bare, globals: options.Globals);
                result.CompiledContent = compilerResult;
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = ex.Message.Replace(info.FullName, string.Empty).Trim()
                };

                Match match = _error.Match(ex.Message);

                if (match.Success)
                {
                    int line;
                    if (int.TryParse(match.Groups["line"].Value, out line))
                        error.LineNumber = line;

                    int column;
                    if (int.TryParse(match.Groups["column"].Value, out column))
                        error.ColumnNumber = column;

                    error.Message = match.Groups["message"].Value.Trim();
                }

                result.Errors.Add(error);
            }

            return result;
        }
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            string sourceMap = config.SourceMap ? config.GetAbsoluteOutputFile() + ".map" : null;

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            SassOptions options = new SassOptions(config);

            try
            {
                LibSassNet.SassCompiler compiler = new LibSassNet.SassCompiler();
                var compilerResult = compiler.CompileFile(inputFile, (LibSassNet.OutputStyle)options.OutputStyle, sourceMap, options.IncludeSourceComments, options.Precision);
                result.CompiledContent = compilerResult.CSS;
                result.SourceMap = compilerResult.SourceMap;
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = ex.Message.Replace("/", "\\").Replace(info.FullName, string.Empty).Trim()
                };

                if (error.Message.StartsWith(":"))
                {
                    int end = error.Message.IndexOf(':', 1);
                    int line = 0;
                    if (int.TryParse(error.Message.Substring(1, end - 1), out line))
                    {
                        error.LineNumber = line;
                        error.Message = error.Message.Substring(end + 1).Trim();
                    }
                }

                result.Errors.Add(error);
            }

            return result;
        }
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            string tempFile = Path.ChangeExtension(Path.Combine(_temp, info.Name), ".js");
            string tempMapFile = tempFile + ".map";

            try
            {
                RunCompilerProcess(config, info);

                if (File.Exists(tempFile))
                {
                    result.CompiledContent = File.ReadAllText(tempFile);

                    var options = IcedCoffeeScriptOptions.FromConfig(config);

                    if (options.SourceMap || config.SourceMap)
                    {
                        if (File.Exists(tempMapFile))
                            result.SourceMap = File.ReadAllText(tempMapFile);
                    }
                }

                if (_error.Length > 0)
                {
                    CompilerError ce = new CompilerError
                    {
                        FileName = info.FullName,
                        Message = _error.Replace(baseFolder, string.Empty),
                    };

                    var match = _errorRx.Match(_error);

                    if (match.Success)
                    {
                        ce.Message = match.Groups["message"].Value.Replace(baseFolder, string.Empty);
                        ce.LineNumber = int.Parse(match.Groups["line"].Value);
                        ce.ColumnNumber = int.Parse(match.Groups["column"].Value);
                    }

                    result.Errors.Add(ce);
                }
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = string.IsNullOrEmpty(_error) ? ex.Message : _error,
                    LineNumber = 0,
                    ColumnNumber = 0,
                };

                result.Errors.Add(error);
            }
            finally
            {
                File.Delete(tempFile);
                File.Delete(tempMapFile);
            }

            return result;
        }