From be324b220a9d3adb98b7dec2c1eaf5a0924c3a8f Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 15 Oct 2015 17:01:39 -0700 Subject: [PATCH] Expose `FilePath` on `MappingLocation`. - We had the `FilePath` information available to us but we weren't exposing it on the `MappingLocation` context object. - By exposing the `FilePath` the Razor editor can 100% know where a `MappingLocation` is resolved from. If `null` the location is deemed to be the current source/generated file. #552 --- .../CodeGenerators/CSharpLineMappingWriter.cs | 1 + .../CodeGenerators/MappingLocation.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs b/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs index 5fa2f5157b..e4f003e024 100644 --- a/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs +++ b/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs @@ -98,6 +98,7 @@ namespace Microsoft.AspNet.Razor.CodeGenerators { documentMapping = new MappingLocation( location: new SourceLocation( + _documentMapping.FilePath, _documentMapping.AbsoluteIndex, _documentMapping.LineIndex, _documentMapping.CharacterIndex), diff --git a/src/Microsoft.AspNet.Razor/CodeGenerators/MappingLocation.cs b/src/Microsoft.AspNet.Razor/CodeGenerators/MappingLocation.cs index 64fa4021ab..235974058a 100644 --- a/src/Microsoft.AspNet.Razor/CodeGenerators/MappingLocation.cs +++ b/src/Microsoft.AspNet.Razor/CodeGenerators/MappingLocation.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Globalization; using Microsoft.Extensions.Internal; @@ -18,6 +19,7 @@ namespace Microsoft.AspNet.Razor.CodeGenerators AbsoluteIndex = location.AbsoluteIndex; LineIndex = location.LineIndex; CharacterIndex = location.CharacterIndex; + FilePath = location.FilePath; } public int ContentLength { get; } @@ -28,6 +30,8 @@ namespace Microsoft.AspNet.Razor.CodeGenerators public int CharacterIndex { get; } + public string FilePath { get; } + public override bool Equals(object obj) { var other = obj as MappingLocation; @@ -36,7 +40,8 @@ namespace Microsoft.AspNet.Razor.CodeGenerators return false; } - return AbsoluteIndex == other.AbsoluteIndex && + return string.Equals(FilePath, other.FilePath, StringComparison.Ordinal) && + AbsoluteIndex == other.AbsoluteIndex && ContentLength == other.ContentLength && LineIndex == other.LineIndex && CharacterIndex == other.CharacterIndex; @@ -45,6 +50,7 @@ namespace Microsoft.AspNet.Razor.CodeGenerators public override int GetHashCode() { var hashCodeCombiner = HashCodeCombiner.Start(); + hashCodeCombiner.Add(FilePath, StringComparer.Ordinal); hashCodeCombiner.Add(AbsoluteIndex); hashCodeCombiner.Add(ContentLength); hashCodeCombiner.Add(LineIndex); @@ -56,11 +62,12 @@ namespace Microsoft.AspNet.Razor.CodeGenerators public override string ToString() { return string.Format( - CultureInfo.CurrentCulture, "({0}:{1},{2} [{3}])", + CultureInfo.CurrentCulture, "({0}:{1},{2} [{3}] {4})", AbsoluteIndex, LineIndex, CharacterIndex, - ContentLength); + ContentLength, + FilePath); } public static bool operator ==(MappingLocation left, MappingLocation right)