Пример #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;
        }
Пример #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;
        }
Пример #3
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);

                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;
        }
Пример #5
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);

            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;
        }
Пример #7
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,
            };

            var extension = Path.GetExtension(inputFile);

            if (!string.IsNullOrWhiteSpace(extension))
            {
                _extension = extension.Substring(1);
            }

            var name = Path.GetFileNameWithoutExtension(inputFile);

            if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("_"))
            {
                _name    = name.Substring(1);
                _partial = true;

                // Temporarily Fix
                // TODO: Remove after actual fix
                var tempFilename = Path.Combine(Path.GetDirectoryName(inputFile), _name + ".handlebarstemp");
                info.CopyTo(tempFilename);
                info       = new FileInfo(tempFilename);
                _extension = "handlebarstemp";
            }

            _mapPath = Path.ChangeExtension(inputFile, ".js.map.tmp");

            try
            {
                RunCompilerProcess(config, info);

                result.CompiledContent = _output;

                var options = HandlebarsOptions.FromConfig(config);
                if (options.SourceMap || config.SourceMap)
                {
                    if (File.Exists(_mapPath))
                    {
                        result.SourceMap = File.ReadAllText(_mapPath);
                    }
                }

                if (_error.Length > 0)
                {
                    CompilerError ce = new CompilerError
                    {
                        FileName  = inputFile,
                        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 = 0;
                    }

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

                result.Errors.Add(error);
            }
            finally
            {
                if (File.Exists(_mapPath))
                {
                    File.Delete(_mapPath);
                }
                // Temporarily Fix
                // TODO: Remove after actual fix
                if (info.Extension == ".handlebarstemp")
                {
                    info.Delete();
                }
            }

            return(result);
        }
Пример #8
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);

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

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

                    if (config.SourceMap)
                    {
                        string mapFile = tempFile + ".map";
                        if (File.Exists(mapFile))
                        {
                            result.SourceMap = File.ReadAllText(mapFile);
                        }
                    }
                }

                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);
            }

            return(result);
        }