Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceMap: Independent of settings. #833

Merged
merged 2 commits into from
Apr 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions EditorExtensions/LESS/Compilers/LessCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.ComponentModel.Composition;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using MadsKristensen.EditorExtensions.Settings;
using Microsoft.VisualStudio.Utilities;
Expand All @@ -23,17 +22,13 @@ public class LessCompiler : CssCompilerBase

protected override string GetArguments(string sourceFileName, string targetFileName)
{
var args = new StringBuilder("--no-color --relative-urls ");
MapFileName = targetFileName + ".map";
MapFileName = GenerateSourceMap ? MapFileName : Path.Combine(Path.GetTempPath(), Path.GetFileName(MapFileName));

if (WESettings.Instance.Less.GenerateSourceMaps)
{
args.AppendFormat(CultureInfo.CurrentCulture, "--source-map-basepath=\"{0}\" --source-map=\"{1}.map\" ",
Path.GetDirectoryName(targetFileName), targetFileName);
}
string mapDirectory = Path.GetDirectoryName(MapFileName);

args.AppendFormat(CultureInfo.CurrentCulture, "\"{0}\" \"{1}\"", sourceFileName, targetFileName);

return args.ToString();
return string.Format(CultureInfo.CurrentCulture, "--no-color --relative-urls --source-map-basepath=\"{0}\" --source-map=\"{1}\" \"{2}\" \"{3}\"",
mapDirectory, MapFileName, sourceFileName, targetFileName);
}
}
}
13 changes: 3 additions & 10 deletions EditorExtensions/SCSS/Compilers/ScssCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.ComponentModel.Composition;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using MadsKristensen.EditorExtensions.Settings;
using Microsoft.VisualStudio.Utilities;
Expand All @@ -24,16 +23,10 @@ public class ScssCompiler : CssCompilerBase

protected override string GetArguments(string sourceFileName, string targetFileName)
{
var args = new StringBuilder();
MapFileName = targetFileName + ".map";
MapFileName = GenerateSourceMap ? MapFileName : Path.Combine(Path.GetTempPath(), Path.GetFileName(MapFileName));

if (GenerateSourceMap)
{
args.Append("--source-map ");
}

args.AppendFormat(CultureInfo.CurrentCulture, "--output-style=expanded \"{0}\" --output \"{1}\"", sourceFileName, targetFileName);

return args.ToString();
return string.Format(CultureInfo.CurrentCulture, "--source-map \"{0}\" --output-style=expanded \"{1}\" --output \"{2}\"", MapFileName, sourceFileName, targetFileName);
}

//https://github.com/hcatlin/libsass/issues/242
Expand Down
1 change: 0 additions & 1 deletion EditorExtensions/Shared/Compilers/CssCompilerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public abstract class CssCompilerBase : NodeExecutorBase
{
private static readonly Regex _sourceMapInCss = new Regex(@"\/\*#([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/", RegexOptions.Multiline);


protected override string PostProcessResult(string resultSource, string sourceFileName, string targetFileName)
{
// Inserts an empty row between each rule and replace two space indentation with 4 space indentation
Expand Down
23 changes: 14 additions & 9 deletions EditorExtensions/Shared/Compilers/NodeExecutorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ public abstract class NodeExecutorBase
protected static readonly string WebEssentialsResourceDirectory = Path.Combine(Path.GetDirectoryName(typeof(NodeExecutorBase).Assembly.Location), @"Resources");
private static readonly string NodePath = Path.Combine(WebEssentialsResourceDirectory, @"nodejs\node.exe");

public abstract string TargetExtension { get; }
public abstract string ServiceName { get; }
protected string MapFileName { get; set; }
protected abstract string CompilerPath { get; }
protected virtual Regex ErrorParsingPattern { get { return null; } }
protected virtual Func<string, IEnumerable<CompilerError>> ParseErrors { get { return ParseErrorsWithRegex; } }

///<summary>Indicates whether this compiler will emit a source map file. Will only return true if aupported and enabled in user settings.</summary>
public abstract bool GenerateSourceMap { get; }

protected abstract string CompilerPath { get; }
public abstract string TargetExtension { get; }
public abstract string ServiceName { get; }
///<summary>Indicates whether this compiler is capable of compiling to a filename that doesn't match the source filename.</summary>
public virtual bool RequireMatchingFileName { get { return false; } }
protected virtual Regex ErrorParsingPattern { get { return null; } }
protected virtual Func<string, IEnumerable<CompilerError>> ParseErrors { get { return ParseErrorsWithRegex; } }

public async Task<CompilerResult> CompileAsync(string sourceFileName, string targetFileName)
{
Expand Down Expand Up @@ -53,16 +54,19 @@ public async Task<CompilerResult> CompileAsync(string sourceFileName, string tar
{
ProjectHelpers.CheckOutFileFromSourceControl(targetFileName);

MapFileName = MapFileName ?? targetFileName + ".map";

if (GenerateSourceMap)
ProjectHelpers.CheckOutFileFromSourceControl(targetFileName + ".map");
ProjectHelpers.CheckOutFileFromSourceControl(MapFileName);

using (var process = await start.ExecuteAsync())
{
return ProcessResult(
process,
File.ReadAllText(errorOutputFile).Trim(),
sourceFileName,
targetFileName
targetFileName,
MapFileName
);
}
}
Expand All @@ -72,7 +76,7 @@ public async Task<CompilerResult> CompileAsync(string sourceFileName, string tar
}
}

private CompilerResult ProcessResult(Process process, string errorText, string sourceFileName, string targetFileName)
private CompilerResult ProcessResult(Process process, string errorText, string sourceFileName, string targetFileName, string mapFileName)
{
var result = ValidateResult(process, targetFileName, errorText);
var resultText = result.Result;
Expand All @@ -94,6 +98,7 @@ private CompilerResult ProcessResult(Process process, string errorText, string s
var compilerResult = CompilerResultFactory.GenerateResult(
sourceFileName: sourceFileName,
targetFileName: targetFileName,
mapFileName: mapFileName,
isSuccess: success,
result: resultText,
errors: errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ public static class CompilerResultFactory
{
public static CompilerResult GenerateResult(string sourceFileName, string targetFileName)
{
return GenerateResult(sourceFileName, targetFileName, true, null, null);
return GenerateResult(sourceFileName, targetFileName, null, true, null, null);
}

public static CompilerResult GenerateResult(string sourceFileName, string targetFileName, bool isSuccess, string result, IEnumerable<CompilerError> errors)
{
return GenerateResult(sourceFileName, targetFileName, null, isSuccess, result, errors);
}

public static CompilerResult GenerateResult(string sourceFileName, string targetFileName, string mapFileName, bool isSuccess, string result, IEnumerable<CompilerError> errors)
{
CompilerResult instance;

var mapFileName = targetFileName + ".map";
mapFileName = mapFileName ?? targetFileName + ".map";

if (result == null && File.Exists(targetFileName))
result = File.ReadAllText(targetFileName);
Expand Down
24 changes: 19 additions & 5 deletions EditorExtensions/Shared/Margins/CssTextViewMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,27 @@ private void GoToDefinitionCommandHandler()
if (selector == null)
return;

int start = selector.Start;
int column = start - containingLine.Start;
int column = Math.Max(0, selector.SimpleSelectors.Last().Start - containingLine.Start - 1);

var sourceInfo = _compilerResult.SourceMap.MapNodes.FirstOrDefault(s => s.GeneratedLine == line && s.GeneratedColumn == column);
var sourceInfoCollection = _compilerResult.SourceMap.MapNodes.Where(s => s.GeneratedLine == line && s.GeneratedColumn == column);

if (sourceInfo == null)
return;
if (!sourceInfoCollection.Any())
{
if (selector.SimpleSelectors.Last().PreviousSibling == null)
return;

// In case previous selector had > or + sign at the end,
// LESS compiler does count it as well.
var point = selector.SimpleSelectors.Last().PreviousSibling.AfterEnd - 1;

column = Math.Max(0, point - containingLine.Start - 1);
sourceInfoCollection = _compilerResult.SourceMap.MapNodes.Where(s => s.GeneratedLine == line && s.GeneratedColumn == column);

if (!sourceInfoCollection.Any())
return;
}

var sourceInfo = sourceInfoCollection.First();

if (sourceInfo.SourceFilePath != Document.FilePath)
FileHelpers.OpenFileInPreviewTab(sourceInfo.SourceFilePath);
Expand Down