Skip to content

Commit

Permalink
Merge pull request #181 from pflannery/fix-coffee-script-err-line-num…
Browse files Browse the repository at this point in the history
…bers

Added location info to coffee-script errors
  • Loading branch information
madskristensen committed Nov 4, 2013
2 parents a040919 + 86d28ba commit 48dacb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 5 additions & 1 deletion EditorExtensions/Margin/CoffeeScriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ protected override string CreateHtml(string source, string state)
"window.external.Execute(result, '" + state.Replace("\\", "\\\\") + "');" +
"}" +
"catch (err){" +
"window.external.Execute('ERROR:' + err, '" + state.Replace("\\", "\\\\") + "');" +
"var locationMsg = '';" +
"if (err && err.location) {" +
"locationMsg = err.location.first_line + ':' + err.location.first_column + ':';" +
"}" +
"window.external.Execute('ERROR:'+locationMsg+err, '" + state.Replace("\\", "\\\\") + "');" +
"}";

return "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" /><script>" + script + "</script></head><html/>";
Expand Down
17 changes: 7 additions & 10 deletions EditorExtensions/Margin/CoffeeScriptMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Threading;

namespace MadsKristensen.EditorExtensions
Expand Down Expand Up @@ -108,25 +109,21 @@ private void _compiler_Completed(object sender, CompilerEventArgs e)
private CompilerError ParseError(string error)
{
string message = error.Replace("ERROR:", string.Empty).Replace("Error:", string.Empty);
int index = message.IndexOf(':');
int line = 0;
int line = 0, column = 0;

if (index > -1)
Match match = Regex.Match(message, @"^(\d{1,})[:](\d{1,})");
if (match.Success)
{
int start = message.LastIndexOf(' ', index);
if (start > -1)
{
int length = index - start - 1;
string part = message.Substring(start + 1, length);
int.TryParse(part, out line);
}
int.TryParse(match.Groups[1].Value, out line);
int.TryParse(match.Groups[2].Value, out column);
}

CompilerError result = new CompilerError()
{
Message = "CoffeeScript: " + message,
FileName = Document.FilePath,
Line = line,
Column = column
};

return result;
Expand Down

0 comments on commit 48dacb9

Please sign in to comment.