File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
src/Microsoft.VisualStudio.Jdt Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ internal static JObject CloneWithLineInfo(this JObject objectToClone)
5555 {
5656 var loadSettings = new JsonLoadSettings ( )
5757 {
58- LineInfoHandling = LineInfoHandling . Load
58+ LineInfoHandling = JdtUtilities . GetLineInfoHandling ( )
5959 } ;
6060
6161 using ( var objectReader = objectToClone . CreateReader ( ) )
Original file line number Diff line number Diff line change 33
44namespace Microsoft . VisualStudio . Jdt
55{
6+ using System ;
7+ using System . Reflection ;
8+ using Newtonsoft . Json . Linq ;
9+
610 /// <summary>
711 /// Utilities class for handling JSON files
812 /// </summary>
@@ -13,6 +17,8 @@ public static class JdtUtilities
1317 /// </summary>
1418 internal const string JdtSyntaxPrefix = "@jdt." ;
1519
20+ private static LineInfoHandling ? lineInfoHandling = null ;
21+
1622 /// <summary>
1723 /// Wheter the given key corresponds to a JDT verb
1824 /// </summary>
@@ -36,5 +42,32 @@ public static string GetJdtSyntax(string key)
3642 // If it is a JDT verb, remove the prefix
3743 return IsJdtSyntax ( key ) ? key . Substring ( JdtSyntaxPrefix . Length ) : null ;
3844 }
45+
46+ /// <summary>
47+ /// Gets the <see cref="LineInfoHandling"/> depending on the Newtonsoft version
48+ /// This is due to a bug in previous versions of JSON.Net that loaded line info on ignore and vice-versa
49+ /// See https://github.com/JamesNK/Newtonsoft.Json/pull/1250
50+ /// </summary>
51+ /// <returns>The correct line info handling</returns>
52+ internal static LineInfoHandling GetLineInfoHandling ( )
53+ {
54+ if ( lineInfoHandling == null )
55+ {
56+ Version newtonsoftVersion = typeof ( JObject ) . GetTypeInfo ( ) . Assembly . GetName ( ) . Version ;
57+
58+ if ( newtonsoftVersion >= new Version ( "10.0.2" ) )
59+ {
60+ return LineInfoHandling . Load ;
61+ }
62+ else
63+ {
64+ return LineInfoHandling . Ignore ;
65+ }
66+ }
67+ else
68+ {
69+ return lineInfoHandling . Value ;
70+ }
71+ }
3972 }
4073}
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ private void SetTransform(Stream transformStream)
162162 this . loadSettings = new JsonLoadSettings ( )
163163 {
164164 CommentHandling = CommentHandling . Ignore ,
165- LineInfoHandling = LineInfoHandling . Load
165+ LineInfoHandling = JdtUtilities . GetLineInfoHandling ( )
166166 } ;
167167
168168 using ( StreamReader transformStreamReader = new StreamReader ( transformStream ) )
You can’t perform that action at this time.
0 commit comments