From fd25efe43889018ef101c2d8e980b597370534c0 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 13 Dec 2017 14:27:31 -0800 Subject: [PATCH 1/7] Retaining a single space instead of removing all leading whitespaces in text --- .../Models/v1/TypeLookup/DocumentationComment.cs | 10 +++++++++- .../Services/DocumentationConverter.cs | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 4409c79aae..a1d1af2cca 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -146,7 +146,7 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi private static string TrimMultiLineString(string input, string lineEnding) { var lines = input.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - return string.Join(lineEnding, lines.Select(l => l.TrimStart())); + return string.Join(lineEnding, lines.Select(l => TrimLeadingSpaces(l))); } private static string GetCref(string cref) @@ -165,5 +165,13 @@ private static string GetCref(string cref) } return cref + " "; } + + private static string TrimLeadingSpaces(string input) + { + if (!input.StartsWith(@"\s")) + return input; + int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); + return " " + input.Substring(offset); + } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index b02153d1e9..42832bcb80 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -109,7 +109,7 @@ public static string ConvertDocumentation(string xmlDocumentation, string lineEn private static string TrimMultiLineString(string input, string lineEnding) { var lines = input.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - return string.Join(lineEnding, lines.Select(l => l.TrimStart())); + return string.Join(lineEnding, lines.Select(l => TrimLeadingSpaces(l))); } private static string GetCref(string cref) @@ -135,6 +135,14 @@ public static DocumentationComment GetStructuredDocumentation(string xmlDocument return null; return DocumentationComment.From(xmlDocumentation, lineEnding); } + + private static string TrimLeadingSpaces(string input) + { + if (!input.StartsWith(@"\s")) + return input; + int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); + return " " + input.Substring(offset); + } } } From 1c2ef95f2f7caf45a326cf9316943f0cc6de7467 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 13 Dec 2017 15:53:39 -0800 Subject: [PATCH 2/7] Changing tests --- .../v1/TypeLookup/DocumentationComment.cs | 6 ++++- .../Services/DocumentationConverter.cs | 2 +- .../TypeLookupFacts.cs | 23 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index a1d1af2cca..1bfbcda1f5 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -168,10 +168,14 @@ private static string GetCref(string cref) private static string TrimLeadingSpaces(string input) { - if (!input.StartsWith(@"\s")) + if (string.IsNullOrWhiteSpace(input)) + return string.Empty; + if (!Char.IsWhiteSpace(input[0])) return input; int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); return " " + input.Substring(offset); } + + //private static string TrimMultipleSpaces() } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 42832bcb80..e7b8a5767d 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -138,7 +138,7 @@ public static DocumentationComment GetStructuredDocumentation(string xmlDocument private static string TrimLeadingSpaces(string input) { - if (!input.StartsWith(@"\s")) + if (!Char.IsWhiteSpace(input[0])) return input; int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); return " " + input.Substring(offset); diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs index 5150b7d92c..a265ef5aff 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs @@ -546,9 +546,9 @@ public async Task StructuredDocumentationNestedTagSeeAlso() string content = @" public class TestClass { - /// DoWork is a method in the TestClass class. - /// - /// + ///DoWork is a method in the TestClass class. + /// + /// public static void Do$$Work(int Int1) { } @@ -640,5 +640,22 @@ class testissue @"Returns: Returns an array of type T ."; Assert.Equal(expectedReturns, response.StructuredDocumentation.ReturnsText); } + + [Fact] + public async Task StructuredDocumentationSpaceBeforeText() + { + string content = @" +public class TestClass +{ + /// DoWork is a method in the TestClass class. + public static void Do$$Work(int Int1) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: DoWork is a method in the TestClass class."; + Assert.Equal(expected, response.StructuredDocumentation.SummaryText); + } } } From a328b4d9462b60bdd60ffece6c948f2cf44bcac7 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 13 Dec 2017 17:08:58 -0800 Subject: [PATCH 3/7] Changed tests --- .../v1/TypeLookup/DocumentationComment.cs | 27 +++++++++++++++++-- .../Services/DocumentationConverter.cs | 10 +------ .../TypeLookupFacts.cs | 4 +-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 1bfbcda1f5..8dcc389c63 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -140,7 +140,25 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi return null; } } - return new DocumentationComment(summaryText.ToString(), typeParamElements.Select(s => s.ToString()).ToArray(), paramElements.Select(s => s.ToString()).ToArray(), returnsText.ToString(), remarksText.ToString(), exampleText.ToString(), valueText.ToString(), exception.Select(s => s.ToString()).ToArray()); + /* return new DocumentationComment( + TrimMultipleSpaces(summaryText), + typeParamElements.Select(s => TrimMultipleSpaces(s)).ToArray(), + paramElements.Select(s => TrimMultipleSpaces(s)).ToArray(), + TrimMultipleSpaces(returnsText), + TrimMultipleSpaces(remarksText), + TrimMultipleSpaces(exampleText), + TrimMultipleSpaces(valueText), + exception.Select(s => TrimMultipleSpaces(s)).ToArray());*/ + return new DocumentationComment( + summaryText.ToString(), + typeParamElements.Select(s => s.ToString()).ToArray(), + paramElements.Select(s => s.ToString()).ToArray(), + returnsText.ToString(), + remarksText.ToString(), + exampleText.ToString(), + valueText.ToString(), + exception.Select(s => s.ToString()).ToArray()); + } private static string TrimMultiLineString(string input, string lineEnding) @@ -176,6 +194,11 @@ private static string TrimLeadingSpaces(string input) return " " + input.Substring(offset); } - //private static string TrimMultipleSpaces() + // Replace multiple spaces occuring together with a single space + private static string TrimMultipleSpaces(string input) + { + //var convertedString = input.ToString(); + return System.Text.RegularExpressions.Regex.Replace(input, @"[ ]+", " "); + } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index e7b8a5767d..b02153d1e9 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -109,7 +109,7 @@ public static string ConvertDocumentation(string xmlDocumentation, string lineEn private static string TrimMultiLineString(string input, string lineEnding) { var lines = input.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - return string.Join(lineEnding, lines.Select(l => TrimLeadingSpaces(l))); + return string.Join(lineEnding, lines.Select(l => l.TrimStart())); } private static string GetCref(string cref) @@ -135,14 +135,6 @@ public static DocumentationComment GetStructuredDocumentation(string xmlDocument return null; return DocumentationComment.From(xmlDocumentation, lineEnding); } - - private static string TrimLeadingSpaces(string input) - { - if (!Char.IsWhiteSpace(input[0])) - return input; - int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); - return " " + input.Substring(offset); - } } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs index a265ef5aff..9f443aa524 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs @@ -458,7 +458,7 @@ public class TestClass }"; var response = await GetTypeLookUpResponse(content); var expected = - @"Summary: DoWork is a method in the TestClass class. System.Console.WriteLine(System.String) for information about output statements."; + @"Summary: DoWork is a method in the TestClass class. System.Console.WriteLine(System.String) for information about output statements."; Assert.Equal(expected, response.StructuredDocumentation.SummaryText); } @@ -505,7 +505,7 @@ public class TestClass }"; var response = await GetTypeLookUpResponse(content); var expected = - @"Example: This sample shows how to call the TestClass.GetZero method. + @"Example: This sample shows how to call the TestClass.GetZero method. class TestClass { From ecd2befbe944c8fdf4f66fcdbf1a0806d3fe1a69 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 14 Dec 2017 11:01:19 -0800 Subject: [PATCH 4/7] Removed unnecessary function --- .../Models/v1/TypeLookup/DocumentationComment.cs | 7 ------- tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs | 6 +++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 7ee0f351bb..aa424629ae 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -176,13 +176,6 @@ private static string TrimLeadingSpaces(string input) int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); return " " + input.Substring(offset); } - - // Replace multiple spaces occuring together with a single space - private static string TrimMultipleSpaces(string input) - { - //var convertedString = input.ToString(); - return System.Text.RegularExpressions.Regex.Replace(input, @"[ ]+", " "); - } } class DocumentationItemBuilder diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs index fb56bfbb4a..cf62e70fb8 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs @@ -540,9 +540,9 @@ public async Task StructuredDocumentationNestedTagSeeAlso() string content = @" public class TestClass { - ///DoWork is a method in the TestClass class. - /// - /// + /// DoWork is a method in the TestClass class. + /// + /// public static void Do$$Work(int Int1) { } From 8a2f4df5c4a7c1d98877c3538409c50c00e04fc2 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 14 Dec 2017 11:11:48 -0800 Subject: [PATCH 5/7] Renamed Method --- .../Models/v1/TypeLookup/DocumentationComment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index aa424629ae..3f78c5d8c7 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -147,7 +147,7 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi private static string TrimMultiLineString(string input, string lineEnding) { var lines = input.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - return string.Join(lineEnding, lines.Select(l => TrimLeadingSpaces(l))); + return string.Join(lineEnding, lines.Select(l => RetainSingleLeadingSpace(l))); } private static string GetCref(string cref) @@ -167,7 +167,7 @@ private static string GetCref(string cref) return cref + " "; } - private static string TrimLeadingSpaces(string input) + private static string RetainSingleLeadingSpace(string input) { if (string.IsNullOrWhiteSpace(input)) return string.Empty; From f76d560a5ac431ce5c049896763a3ebd9e77364a Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 14 Dec 2017 14:05:22 -0800 Subject: [PATCH 6/7] Renamed Method and used space plus trimStart --- .../Models/v1/TypeLookup/DocumentationComment.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 3f78c5d8c7..0a907256e2 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -147,7 +147,7 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi private static string TrimMultiLineString(string input, string lineEnding) { var lines = input.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - return string.Join(lineEnding, lines.Select(l => RetainSingleLeadingSpace(l))); + return string.Join(lineEnding, lines.Select(l => TrimStartRetainingSingleLeadingSpace(l))); } private static string GetCref(string cref) @@ -167,14 +167,13 @@ private static string GetCref(string cref) return cref + " "; } - private static string RetainSingleLeadingSpace(string input) + private static string TrimStartRetainingSingleLeadingSpace(string input) { if (string.IsNullOrWhiteSpace(input)) return string.Empty; if (!Char.IsWhiteSpace(input[0])) return input; - int offset = input.TakeWhile(c => char.IsWhiteSpace(c)).Count(); - return " " + input.Substring(offset); + return $" {input.TrimStart()}"; } } From c092873d1642b125cec2d94306fe7189699c7aa1 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 3 Jan 2018 12:24:18 -0800 Subject: [PATCH 7/7] Replaced Char with char --- .../Models/v1/TypeLookup/DocumentationComment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 0a907256e2..4dab014516 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -171,7 +171,7 @@ private static string TrimStartRetainingSingleLeadingSpace(string input) { if (string.IsNullOrWhiteSpace(input)) return string.Empty; - if (!Char.IsWhiteSpace(input[0])) + if (!char.IsWhiteSpace(input[0])) return input; return $" {input.TrimStart()}"; }