From 0de6d8408cf5f3b870c8afecee65fcb5c87ac6f5 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 17 Nov 2017 18:15:55 -0800 Subject: [PATCH 01/14] Added Basic Structure --- .../Models/v2/TypeLookUp/TypeLookUpRequest.cs | 10 ++ .../v2/TypeLookUp/TypeLookUpResponse.cs | 20 +++ .../OmniSharpEndpoints.cs | 2 + .../Services/DocumentationComment.cs | 30 +++++ .../Services/DocumentationConverter.cs | 118 ++++++++++++++++++ .../Services/Types/V2/TypeLookUp.cs | 12 ++ 6 files changed, 192 insertions(+) create mode 100644 src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs create mode 100644 src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs create mode 100644 src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs create mode 100644 src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs new file mode 100644 index 0000000000..a83430810f --- /dev/null +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs @@ -0,0 +1,10 @@ +using OmniSharp.Mef; +namespace OmniSharp.Models.v2.TypeLookUp +{ + [OmniSharpEndpoint(OmniSharpEndpoints.V2.TypeLookup, typeof(TypeLookupRequest), typeof(TypeLookupResponse))] + class TypeLookUpRequest:Request + { + public bool IncludeDocumentation { get; set; } + } +} + diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs new file mode 100644 index 0000000000..d8e50256fa --- /dev/null +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs @@ -0,0 +1,20 @@ + +using System.Composition; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.FindSymbols; +using Microsoft.CodeAnalysis.Text; +using OmniSharp.Mef; +using OmniSharp.Models.TypeLookup; +using OmniSharp.Options; +using OmniSharp.Roslyn.CSharp.Services.Documentation; + +namespace OmniSharp.Models.v2.TypeLookUp +{ + public class TypeLookupResponse + { + public string Type { get; set; } + public DocumentationComment DocComment { get; set; } + } + +} diff --git a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs index 20314bd619..88b6e92c6c 100644 --- a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs +++ b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs @@ -47,12 +47,14 @@ public static class V2 { public const string GetCodeActions = "/v2/getcodeactions"; public const string RunCodeAction = "/v2/runcodeaction"; + public const string TypeLookup = "/v2/typelookup"; public const string GetTestStartInfo = "/v2/getteststartinfo"; public const string RunTest = "/v2/runtest"; public const string DebugTestGetStartInfo = "/v2/debugtest/getstartinfo"; public const string DebugTestLaunch = "/v2/debugtest/launch"; public const string DebugTestStop = "/v2/debugtest/stop"; + } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs new file mode 100644 index 0000000000..5facbc8f79 --- /dev/null +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs @@ -0,0 +1,30 @@ +using System.Text; +namespace OmniSharp.Roslyn.CSharp.Services +{ + class DocumentationComment + { + //[DefaultValue("")] + public StringBuilder RemarksText { get; set; } + public StringBuilder ExampleText { get; set; } + public StringBuilder ExceptionText { get; set; } + public StringBuilder ReturnsText { get; set; } + public StringBuilder SummaryText { get; set; } + public StringBuilder paramref { get; set; } + public StringBuilder param { get; set; } + public StringBuilder value { get; set; } + + + + public DocumentationComment() + { + RemarksText = new StringBuilder(); + ExampleText = new StringBuilder(); + ExceptionText = new StringBuilder(); + ReturnsText = new StringBuilder(); + paramref = new StringBuilder(); + param = new StringBuilder(); + value = new StringBuilder(); + + } + } +} diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 3f667c36e6..a8df3b8326 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -126,5 +126,123 @@ private static string GetCref(string cref) } return cref + " "; } + + private static DocumentationComment ConvertDocumentationObject(string xmlDocumentation, string lineEnding) + { + if (string.IsNullOrEmpty(xmlDocumentation)) + return null; + var docComment = new DocumentationComment(); + var reader = new StringReader("" + xmlDocumentation + ""); + using (var xml = XmlReader.Create(reader)) + { + try + { + xml.Read(); + string elementName = null; + do + { + if (xml.NodeType == XmlNodeType.Element) + { + elementName = xml.Name.ToLowerInvariant(); + switch (elementName) + { + case "filterpriority": + xml.Skip(); + break; + case "remarks": + docComment.RemarksText.Append(lineEnding); + docComment.RemarksText.Append("Remarks:"); + docComment.RemarksText.Append(lineEnding); + docComment.RemarksText.Append(TrimMultiLineString(xml.ReadInnerXml(),lineEnding)); + break; + case "example": + docComment.ExampleText.Append(lineEnding); + docComment.ExampleText.Append("Example:"); + docComment.ExampleText.Append(lineEnding); + docComment.ExampleText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + break; + case "exception": + docComment.ExceptionText.Append(lineEnding); + docComment.ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); + docComment.ExceptionText.Append(": "); + docComment.ExceptionText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + break; + case "returns": + docComment.ReturnsText.Append(lineEnding); + docComment.ReturnsText.Append("Returns: "); + docComment.ReturnsText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + break; + case "summary": + docComment.SummaryText.Append(lineEnding); + docComment.SummaryText.Append("Returns: "); + docComment.SummaryText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + break; + /*case "see": + docComment.Append(GetCref(xml["cref"])); + docComment.Append(xml["langword"]); + break; + case "seealso": + docComment.Append(lineEnding); + docComment.Append("See also: "); + docComment.Append(GetCref(xml["cref"])); + break; + case "paramref": + docComment.paramref.Append(xml["name"]); + docComment.paramref.Append(" "); + break;*/ + case "param": + docComment.param.Append(lineEnding); + docComment.param.Append(TrimMultiLineString(xml["name"], lineEnding)); + docComment.param.Append(": "); + docComment.param.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + break; + case "value": + docComment.value.Append(lineEnding); + docComment.value.Append("Value: "); + docComment.value.Append(lineEnding); + docComment.value.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + break; + case "br": + case "para": + //docComment.Append(lineEnding); + break; + } + } + /*else if (xml.NodeType == XmlNodeType.Text) + { + if (elementName == "code") + { + docComment.Append(xml.Value); + } + else + { + docComment.Append(TrimMultiLineString(xml.Value, lineEnding)); + } + }*/ + } while (xml.Read()); + } + catch (Exception) + { + return null; + } + return docComment; + } + } + private static string ReadInnerXMLText(XmlReader xml, string elementName,string lineEnding) + { + if(xml.NodeType == XmlNodeType.Text) + { + if (elementName == "code") + { + return xml.Value; + } + else + { + return TrimMultiLineString(xml.Value, lineEnding); + } + } + return ""; + } } } + diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs b/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs new file mode 100644 index 0000000000..e022bc004b --- /dev/null +++ b/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OmniSharp.Roslyn.CSharp.Services.Types.V2 +{ + class TypeLookUp + { + } +} From a6933f2de0987f242259daf5eb2e535aeb0d9534 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 20 Nov 2017 14:46:11 -0800 Subject: [PATCH 02/14] Text Fields for Doc Convertor running --- .../v2/TypeLookUp}/DocumentationComment.cs | 12 +- .../Models/v2/TypeLookUp/TypeLookUpRequest.cs | 3 +- .../v2/TypeLookUp/TypeLookUpResponse.cs | 10 - .../Services/DocumentationConverter.cs | 54 +++-- .../Services/Types/V2/TypeLookUp.cs | 54 ++++- .../TypeLookUpV2Facts.cs | 216 ++++++++++++++++++ 6 files changed, 300 insertions(+), 49 deletions(-) rename src/{OmniSharp.Roslyn.CSharp/Services => OmniSharp.Abstractions/Models/v2/TypeLookUp}/DocumentationComment.cs (73%) create mode 100644 tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs similarity index 73% rename from src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs rename to src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index 5facbc8f79..850fac2063 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -1,7 +1,8 @@ -using System.Text; -namespace OmniSharp.Roslyn.CSharp.Services +using System.Collections.Generic; +using System.Text; +namespace OmniSharp.Models.v2.TypeLookUp { - class DocumentationComment + public class DocumentationComment { //[DefaultValue("")] public StringBuilder RemarksText { get; set; } @@ -10,7 +11,7 @@ class DocumentationComment public StringBuilder ReturnsText { get; set; } public StringBuilder SummaryText { get; set; } public StringBuilder paramref { get; set; } - public StringBuilder param { get; set; } + public List Param { get; set; } public StringBuilder value { get; set; } @@ -21,8 +22,9 @@ public DocumentationComment() ExampleText = new StringBuilder(); ExceptionText = new StringBuilder(); ReturnsText = new StringBuilder(); + SummaryText = new StringBuilder(); paramref = new StringBuilder(); - param = new StringBuilder(); + Param = new List(); value = new StringBuilder(); } diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs index a83430810f..194450d233 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs @@ -1,8 +1,9 @@ using OmniSharp.Mef; + namespace OmniSharp.Models.v2.TypeLookUp { [OmniSharpEndpoint(OmniSharpEndpoints.V2.TypeLookup, typeof(TypeLookupRequest), typeof(TypeLookupResponse))] - class TypeLookUpRequest:Request + public class TypeLookupRequest:Request { public bool IncludeDocumentation { get; set; } } diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs index d8e50256fa..8e75b86f66 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs @@ -1,14 +1,4 @@  -using System.Composition; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.FindSymbols; -using Microsoft.CodeAnalysis.Text; -using OmniSharp.Mef; -using OmniSharp.Models.TypeLookup; -using OmniSharp.Options; -using OmniSharp.Roslyn.CSharp.Services.Documentation; - namespace OmniSharp.Models.v2.TypeLookUp { public class TypeLookupResponse diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index a8df3b8326..ad37f5fd08 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -1,3 +1,4 @@ +using OmniSharp.Models.v2.TypeLookUp; using System; using System.IO; using System.Linq; @@ -127,7 +128,7 @@ private static string GetCref(string cref) return cref + " "; } - private static DocumentationComment ConvertDocumentationObject(string xmlDocumentation, string lineEnding) + public static DocumentationComment ConvertDocumentationObject(string xmlDocumentation, string lineEnding) { if (string.IsNullOrEmpty(xmlDocumentation)) return null; @@ -150,32 +151,25 @@ private static DocumentationComment ConvertDocumentationObject(string xmlDocumen xml.Skip(); break; case "remarks": - docComment.RemarksText.Append(lineEnding); - docComment.RemarksText.Append("Remarks:"); - docComment.RemarksText.Append(lineEnding); - docComment.RemarksText.Append(TrimMultiLineString(xml.ReadInnerXml(),lineEnding)); + docComment.RemarksText.Append("Remarks: "); + docComment.RemarksText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); break; case "example": - docComment.ExampleText.Append(lineEnding); - docComment.ExampleText.Append("Example:"); - docComment.ExampleText.Append(lineEnding); - docComment.ExampleText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + docComment.ExampleText.Append("Example: "); + docComment.ExampleText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); break; case "exception": - docComment.ExceptionText.Append(lineEnding); docComment.ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); docComment.ExceptionText.Append(": "); - docComment.ExceptionText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + docComment.ExceptionText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); break; case "returns": - docComment.ReturnsText.Append(lineEnding); docComment.ReturnsText.Append("Returns: "); - docComment.ReturnsText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + docComment.ReturnsText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); break; case "summary": - docComment.SummaryText.Append(lineEnding); - docComment.SummaryText.Append("Returns: "); - docComment.SummaryText.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + docComment.SummaryText.Append("Summary: "); + docComment.SummaryText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); break; /*case "see": docComment.Append(GetCref(xml["cref"])); @@ -191,16 +185,17 @@ private static DocumentationComment ConvertDocumentationObject(string xmlDocumen docComment.paramref.Append(" "); break;*/ case "param": - docComment.param.Append(lineEnding); - docComment.param.Append(TrimMultiLineString(xml["name"], lineEnding)); - docComment.param.Append(": "); - docComment.param.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + StringBuilder parameter = new StringBuilder(); + parameter.Append(TrimMultiLineString(xml["name"], lineEnding)); + parameter.Append(": "); + parameter.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + docComment.Param.Add(parameter); break; case "value": docComment.value.Append(lineEnding); docComment.value.Append("Value: "); docComment.value.Append(lineEnding); - docComment.value.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + //docComment.value.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); break; case "br": case "para": @@ -230,15 +225,18 @@ private static DocumentationComment ConvertDocumentationObject(string xmlDocumen } private static string ReadInnerXMLText(XmlReader xml, string elementName,string lineEnding) { - if(xml.NodeType == XmlNodeType.Text) + if (xml.Read()) { - if (elementName == "code") + if (xml.NodeType == XmlNodeType.Text) { - return xml.Value; - } - else - { - return TrimMultiLineString(xml.Value, lineEnding); + if (elementName == "code") + { + return xml.Value; + } + else + { + return TrimMultiLineString(xml.Value, lineEnding); + } } } return ""; diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs b/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs index e022bc004b..8d1704fbdd 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs @@ -1,12 +1,56 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Composition; using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.FindSymbols; +using Microsoft.CodeAnalysis.Text; +using OmniSharp.Mef; +using OmniSharp.Models.v2.TypeLookUp; +using OmniSharp.Options; +using OmniSharp.Roslyn.CSharp.Services.Documentation; namespace OmniSharp.Roslyn.CSharp.Services.Types.V2 { - class TypeLookUp + [OmniSharpHandler(OmniSharpEndpoints.V2.TypeLookup, LanguageNames.CSharp)] + public class TypeLookupService : IRequestHandler { + private readonly FormattingOptions _formattingOptions; + private readonly OmniSharpWorkspace _workspace; + private static readonly SymbolDisplayFormat DefaultFormat = SymbolDisplayFormat.FullyQualifiedFormat. + WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted). + WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.None). + WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers); + + [ImportingConstructor] + public TypeLookupService(OmniSharpWorkspace workspace, FormattingOptions formattingOptions) + { + _workspace = workspace; + _formattingOptions = formattingOptions; + } + + public async Task Handle(TypeLookupRequest request) + { + var document = _workspace.GetDocument(request.FileName); + var response = new TypeLookupResponse(); + if (document != null) + { + var semanticModel = await document.GetSemanticModelAsync(); + var sourceText = await document.GetTextAsync(); + var position = sourceText.Lines.GetPosition(new LinePosition(request.Line, request.Column)); + var symbol = await SymbolFinder.FindSymbolAtPositionAsync(semanticModel, position, _workspace); + if (symbol != null) + { + response.Type = symbol.Kind == SymbolKind.NamedType ? + symbol.ToDisplayString(DefaultFormat) : + symbol.ToMinimalDisplayString(semanticModel, position); + + if (request.IncludeDocumentation) + { + response.DocComment = DocumentationConverter.ConvertDocumentationObject(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); + } + } + } + + return response; + } } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs new file mode 100644 index 0000000000..3eb89be284 --- /dev/null +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -0,0 +1,216 @@ + +using OmniSharp.Models.v2.TypeLookUp; +using OmniSharp.Roslyn.CSharp.Services.Types.V2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TestUtility; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.Roslyn.CSharp.Tests +{ + public class TypeLookUpV2Facts : AbstractSingleRequestHandlerTestFixture + { + private readonly TestFile s_testFile = new TestFile("dummy.cs", @"using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Checks if object is tagged with the tag. + /// The game object. + /// Name of the tag + /// Returns trueif object is tagged with tag. + + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"); + + public TypeLookUpV2Facts(ITestOutputHelper testOutput) : base(testOutput) + { + } + + protected override string EndpointName => OmniSharpEndpoints.V2.TypeLookup; + + private async Task GetTypeLookUpResponse(string content) + { + TestFile testFile = new TestFile("dummy.cs", content); + using (var host = CreateOmniSharpHost(testFile)) + { + var requestHandler = GetRequestHandler(host); + var point = testFile.Content.GetPointFromPosition(); + var request = new TypeLookupRequest { FileName = testFile.FileName, Line = point.Line, Column = point.Offset }; + request.IncludeDocumentation = true; + + return await requestHandler.Handle(request); + } + } + + [Fact] + public async Task CheckXmlDocumentationRemarksText() + { + string content= @"using System; +namespace hoverXmlDoc +{ + class testissue + { + ///You may have some additional information about this class here. + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Remarks: You may have some additional information about this class here."; + Assert.Equal(expected, response.DocComment.RemarksText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationSummaryText() + { + string content = @"using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Checks if object is tagged with the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: Checks if object is tagged with the tag."; + Assert.Equal(expected, response.DocComment.SummaryText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationReturnsText() + { + string content = @"using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Returns true if object is tagged with tag. + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + + var response = await GetTypeLookUpResponse(content); + var expected = + @"Returns: Returns true if object is tagged with tag."; + Assert.Equal(expected, response.DocComment.ReturnsText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationExampleText() + { + string content = @"using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Checks if object is tagged with the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Example: Checks if object is tagged with the tag."; + Assert.Equal(expected, response.DocComment.ExampleText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationExceptionText() + { + string content = @"using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Thrown when something goes wrong + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"System.Exception: Thrown when something goes wrong"; + Assert.Equal(expected, response.DocComment.ExceptionText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationParameter1() + { + string content = @"using System; +namespace hoverXmlDoc +{ + class testissue + { + /// The game object. + /// Name of the tag + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"gameObject: The game object."; + Assert.Equal(2,response.DocComment.Param.Count); + Assert.Equal(expected, response.DocComment.Param[0].ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationParameter2() + { + string content = @"using System; +namespace hoverXmlDoc +{ + class testissue + { + /// The game object. + /// Name of the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"tagName: Name of the tag."; + Assert.Equal(2, response.DocComment.Param.Count); + Assert.Equal(expected, response.DocComment.Param[1].ToString()); + } + + + } +} From 02e7a35f290698f8c922c3e61ea95bfae24a4853 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 20 Nov 2017 16:37:46 -0800 Subject: [PATCH 03/14] see and seeref working --- .../v2/TypeLookUp/DocumentationComment.cs | 3 + .../Services/DocumentationConverter.cs | 48 ++++++++----- .../TypeLookUpV2Facts.cs | 72 +++++++++++++++++++ 3 files changed, 106 insertions(+), 17 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index 850fac2063..c05f5d5f23 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -10,8 +10,10 @@ public class DocumentationComment public StringBuilder ExceptionText { get; set; } public StringBuilder ReturnsText { get; set; } public StringBuilder SummaryText { get; set; } + public StringBuilder ValueText { get; set; } public StringBuilder paramref { get; set; } public List Param { get; set; } + public List TypeParam { get; set; } public StringBuilder value { get; set; } @@ -25,6 +27,7 @@ public DocumentationComment() SummaryText = new StringBuilder(); paramref = new StringBuilder(); Param = new List(); + TypeParam = new List(); value = new StringBuilder(); } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index ad37f5fd08..fe1a1bfa3d 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -140,6 +140,7 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument { xml.Read(); string elementName = null; + StringBuilder prevElementName = null; do { if (xml.NodeType == XmlNodeType.Element) @@ -153,49 +154,62 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument case "remarks": docComment.RemarksText.Append("Remarks: "); docComment.RemarksText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = docComment.RemarksText; break; case "example": docComment.ExampleText.Append("Example: "); docComment.ExampleText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = docComment.ExampleText; break; case "exception": docComment.ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); docComment.ExceptionText.Append(": "); docComment.ExceptionText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = docComment.ExceptionText; break; case "returns": docComment.ReturnsText.Append("Returns: "); docComment.ReturnsText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = docComment.ReturnsText; break; case "summary": docComment.SummaryText.Append("Summary: "); docComment.SummaryText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = docComment.SummaryText; break; - /*case "see": - docComment.Append(GetCref(xml["cref"])); - docComment.Append(xml["langword"]); + case "see": + prevElementName.Append(GetCref(xml["cref"])); + prevElementName.Append(xml["langword"]); break; case "seealso": - docComment.Append(lineEnding); - docComment.Append("See also: "); - docComment.Append(GetCref(xml["cref"])); + prevElementName.Append(lineEnding); + prevElementName.Append("See also: "); + prevElementName.Append(GetCref(xml["cref"])); break; case "paramref": - docComment.paramref.Append(xml["name"]); - docComment.paramref.Append(" "); - break;*/ + prevElementName.Append(xml["name"]); + prevElementName.Append(" "); + break; case "param": StringBuilder parameter = new StringBuilder(); parameter.Append(TrimMultiLineString(xml["name"], lineEnding)); parameter.Append(": "); parameter.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = parameter; docComment.Param.Add(parameter); break; + case "typeparam": + StringBuilder TypeParameter = new StringBuilder(); + TypeParameter.Append(TrimMultiLineString(xml["name"], lineEnding)); + TypeParameter.Append(": "); + TypeParameter.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = TypeParameter; + docComment.TypeParam.Add(TypeParameter); + break; case "value": - docComment.value.Append(lineEnding); - docComment.value.Append("Value: "); - docComment.value.Append(lineEnding); - //docComment.value.Append(TrimMultiLineString(xml.ReadInnerXml(), lineEnding)); + docComment.ValueText.Append("Value: "); + docComment.ValueText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); + prevElementName = docComment.ValueText; break; case "br": case "para": @@ -203,17 +217,17 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument break; } } - /*else if (xml.NodeType == XmlNodeType.Text) + else if (xml.NodeType == XmlNodeType.Text && prevElementName != null) { if (elementName == "code") { - docComment.Append(xml.Value); + prevElementName.Append(xml.Value); } else { - docComment.Append(TrimMultiLineString(xml.Value, lineEnding)); + prevElementName.Append(TrimMultiLineString(xml.Value, lineEnding)); } - }*/ + } } while (xml.Read()); } catch (Exception) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index 3eb89be284..27a7b19d89 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -211,6 +211,78 @@ class testissue Assert.Equal(expected, response.DocComment.Param[1].ToString()); } + [Fact] + public async Task CheckXmlDocumentationTypeParameter() + { + string content = @"public class TestClass +{ + /// + /// Creates a new array of arbitrary type + /// + /// The element type of the array + public static T[] m$$kArray(int n) + { + return new T[n]; + } + } +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"T: The element type of the array"; + Assert.Single(response.DocComment.TypeParam); + Assert.Equal(expected, response.DocComment.TypeParam[0].ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationValueText() + { + string content = @"public class Employee +{ + private string _name; + + /// The Name property represents the employee's name. + /// The Name property gets/sets the value of the string field, _name. + public string N$$ame + { + get + { + return _name; + } + set + { + _name = value; + } + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Value: The Name property gets/sets the value of the string field, _name."; + Assert.Equal(expected, response.DocComment.ValueText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationSee() + { + string content = @"/// text for class TestClass +public class TestClass +{ + /// DoWork is a method in the TestClass class. for information about output statements. + public static void Do$$Work(int Int1) + { + } + + /// text for Main + static void Main() + { + } + } +"; + 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."; + Assert.Equal(expected, response.DocComment.SummaryText.ToString()); + } } } From 4b50e4ea492e2d0e56d44ef8be21c47d4d5408eb Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 21 Nov 2017 10:56:51 -0800 Subject: [PATCH 04/14] All Test Cases Running --- .../v2/TypeLookUp/DocumentationComment.cs | 5 +- .../Services/DocumentationConverter.cs | 56 ++--- .../TypeLookUpV2Facts.cs | 231 ++++++++++-------- 3 files changed, 158 insertions(+), 134 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index c05f5d5f23..05b9fc89f7 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -14,9 +14,6 @@ public class DocumentationComment public StringBuilder paramref { get; set; } public List Param { get; set; } public List TypeParam { get; set; } - public StringBuilder value { get; set; } - - public DocumentationComment() { @@ -25,10 +22,10 @@ public DocumentationComment() ExceptionText = new StringBuilder(); ReturnsText = new StringBuilder(); SummaryText = new StringBuilder(); + ValueText = new StringBuilder(); paramref = new StringBuilder(); Param = new List(); TypeParam = new List(); - value = new StringBuilder(); } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index fe1a1bfa3d..2b76c89d18 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -140,7 +140,7 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument { xml.Read(); string elementName = null; - StringBuilder prevElementName = null; + StringBuilder CurrentElementText = null; do { if (xml.NodeType == XmlNodeType.Element) @@ -153,79 +153,75 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument break; case "remarks": docComment.RemarksText.Append("Remarks: "); - docComment.RemarksText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = docComment.RemarksText; + CurrentElementText = docComment.RemarksText; break; case "example": docComment.ExampleText.Append("Example: "); - docComment.ExampleText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = docComment.ExampleText; + CurrentElementText = docComment.ExampleText; break; case "exception": docComment.ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); docComment.ExceptionText.Append(": "); - docComment.ExceptionText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = docComment.ExceptionText; + CurrentElementText = docComment.ExceptionText; break; case "returns": docComment.ReturnsText.Append("Returns: "); - docComment.ReturnsText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = docComment.ReturnsText; + CurrentElementText = docComment.ReturnsText; break; case "summary": docComment.SummaryText.Append("Summary: "); - docComment.SummaryText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = docComment.SummaryText; + CurrentElementText = docComment.SummaryText; break; case "see": - prevElementName.Append(GetCref(xml["cref"])); - prevElementName.Append(xml["langword"]); + CurrentElementText.Append(GetCref(xml["cref"])); + CurrentElementText.Append(xml["langword"]); break; case "seealso": - prevElementName.Append(lineEnding); - prevElementName.Append("See also: "); - prevElementName.Append(GetCref(xml["cref"])); + CurrentElementText.Append(lineEnding); + CurrentElementText.Append("See also: "); + CurrentElementText.Append(GetCref(xml["cref"])); break; case "paramref": - prevElementName.Append(xml["name"]); - prevElementName.Append(" "); + CurrentElementText.Append(xml["name"]); + CurrentElementText.Append(" "); break; case "param": StringBuilder parameter = new StringBuilder(); parameter.Append(TrimMultiLineString(xml["name"], lineEnding)); parameter.Append(": "); - parameter.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = parameter; + CurrentElementText = parameter; docComment.Param.Add(parameter); break; + case "typeparamref": + CurrentElementText.Append(xml["name"]); + CurrentElementText.Append(" "); + break; case "typeparam": StringBuilder TypeParameter = new StringBuilder(); TypeParameter.Append(TrimMultiLineString(xml["name"], lineEnding)); TypeParameter.Append(": "); - TypeParameter.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = TypeParameter; + CurrentElementText = TypeParameter; docComment.TypeParam.Add(TypeParameter); break; case "value": docComment.ValueText.Append("Value: "); - docComment.ValueText.Append(ReadInnerXMLText(xml, elementName, lineEnding)); - prevElementName = docComment.ValueText; + CurrentElementText = docComment.ValueText; break; case "br": case "para": - //docComment.Append(lineEnding); + CurrentElementText.Append(lineEnding); break; } } - else if (xml.NodeType == XmlNodeType.Text && prevElementName != null) + else if (xml.NodeType == XmlNodeType.Text && CurrentElementText != null) { if (elementName == "code") { - prevElementName.Append(xml.Value); + CurrentElementText.Append(xml.Value); } else { - prevElementName.Append(TrimMultiLineString(xml.Value, lineEnding)); + CurrentElementText.Append(TrimMultiLineString(xml.Value, lineEnding)); } } } while (xml.Read()); @@ -237,7 +233,7 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument return docComment; } } - private static string ReadInnerXMLText(XmlReader xml, string elementName,string lineEnding) + /* private static string ReadInnerXMLText(XmlReader xml, string elementName,string lineEnding) { if (xml.Read()) { @@ -254,7 +250,7 @@ private static string ReadInnerXMLText(XmlReader xml, string elementName,string } } return ""; - } + }*/ } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index 27a7b19d89..8ff329ed54 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -55,19 +55,15 @@ private async Task GetTypeLookUpResponse(string content) [Fact] public async Task CheckXmlDocumentationRemarksText() { - string content= @"using System; -namespace hoverXmlDoc + string content= @" +class testissue { - class testissue - { ///You may have some additional information about this class here. - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); } -} -"; +}"; var response = await GetTypeLookUpResponse(content); var expected = @"Remarks: You may have some additional information about this class here."; @@ -77,19 +73,14 @@ class testissue [Fact] public async Task CheckXmlDocumentationSummaryText() { - string content = @"using System; -namespace hoverXmlDoc + string content = @" +class testissue { - class testissue - { ///Checks if object is tagged with the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { } -} -"; +}"; var response = await GetTypeLookUpResponse(content); var expected = @"Summary: Checks if object is tagged with the tag."; @@ -99,20 +90,14 @@ class testissue [Fact] public async Task CheckXmlDocumentationReturnsText() { - string content = @"using System; -namespace hoverXmlDoc + string content = @" +class testissue { - class testissue - { ///Returns true if object is tagged with tag. - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { } -} -"; - +}"; var response = await GetTypeLookUpResponse(content); var expected = @"Returns: Returns true if object is tagged with tag."; @@ -122,19 +107,14 @@ class testissue [Fact] public async Task CheckXmlDocumentationExampleText() { - string content = @"using System; -namespace hoverXmlDoc + string content = @" +class testissue { - class testissue - { ///Checks if object is tagged with the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { } -} -"; +}"; var response = await GetTypeLookUpResponse(content); var expected = @"Example: Checks if object is tagged with the tag."; @@ -144,19 +124,14 @@ class testissue [Fact] public async Task CheckXmlDocumentationExceptionText() { - string content = @"using System; -namespace hoverXmlDoc + string content = @" +class testissue { - class testissue - { ///Thrown when something goes wrong - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { } -} -"; +}"; var response = await GetTypeLookUpResponse(content); var expected = @"System.Exception: Thrown when something goes wrong"; @@ -166,20 +141,15 @@ class testissue [Fact] public async Task CheckXmlDocumentationParameter1() { - string content = @"using System; -namespace hoverXmlDoc + string content = @" +class testissue { - class testissue - { /// The game object. /// Name of the tag - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { } -} -"; +}"; var response = await GetTypeLookUpResponse(content); var expected = @"gameObject: The game object."; @@ -190,20 +160,16 @@ class testissue [Fact] public async Task CheckXmlDocumentationParameter2() { - string content = @"using System; -namespace hoverXmlDoc + string content = @" +class testissue { - class testissue - { /// The game object. /// Name of the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } + public static bool C$$ompare(int gameObject, string tagName) + { + } -} -"; +}"; var response = await GetTypeLookUpResponse(content); var expected = @"tagName: Name of the tag."; @@ -214,18 +180,18 @@ class testissue [Fact] public async Task CheckXmlDocumentationTypeParameter() { - string content = @"public class TestClass + string content = @" +public class TestClass { /// /// Creates a new array of arbitrary type /// /// The element type of the array - public static T[] m$$kArray(int n) - { - return new T[n]; - } - } -"; + public static T[] m$$kArray(int n) + { + return new T[n]; + } +}"; var response = await GetTypeLookUpResponse(content); var expected = @"T: The element type of the array"; @@ -236,22 +202,15 @@ public async Task CheckXmlDocumentationTypeParameter() [Fact] public async Task CheckXmlDocumentationValueText() { - string content = @"public class Employee + string content = +@"public class Employee { private string _name; /// The Name property represents the employee's name. /// The Name property gets/sets the value of the string field, _name. - public string N$$ame + public string Na$$me { - get - { - return _name; - } - set - { - _name = value; - } } } "; @@ -262,27 +221,99 @@ public string N$$ame } [Fact] - public async Task CheckXmlDocumentationSee() + public async Task CheckXmlDocumentationNestedTagSee() { - string content = @"/// text for class TestClass + string content = @" public class TestClass { /// DoWork is a method in the TestClass class. for information about output statements. - public static void Do$$Work(int Int1) - { - } - - /// text for Main - static void Main() - { - } - } -"; + public static void Do$$Work(int Int1) + { + } +}"; 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."; Assert.Equal(expected, response.DocComment.SummaryText.ToString()); } + [Fact] + public async Task CheckXmlDocumentationNestedTagParamRef() + { + string content = @" +public class TestClass +{ + /// Creates a new array of arbitrary type + /// The element type of the array + public static T[] mk$$Array(int n) + { + return new T[n]; + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: Creates a new array of arbitrary type T "; + Assert.Equal(expected, response.DocComment.SummaryText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationNestedTagCode() + { + string content = @" +public class TestClass +{ + /// This sample shows how to call the method. + /// + /// class TestClass + /// { + /// static int Main() + /// { + /// return GetZero(); + /// } + /// } + /// + /// + public static int $$GetZero() + { + return 0; + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Example: This sample shows how to call the TestClass.GetZero method. + + class TestClass + { + static int Main() + { + return GetZero(); + } + } + "; + Assert.Equal(expected.Replace("\r",""), response.DocComment.ExampleText.ToString()); + } + + [Fact] + public async Task CheckXmlDocumentationNestedTagPara() + { + string content = @" +public class TestClass +{ + /// DoWork is a method in the TestClass class. + /// Here's how you could make a second paragraph in a description. + /// + public static void Do$$Work(int Int1) + { + } +} + "; + var response = await GetTypeLookUpResponse(content); + var expected = +@"Summary: DoWork is a method in the TestClass class. + +Here's how you could make a second paragraph in a description."; + Assert.Equal(expected.Replace("\r", ""), response.DocComment.SummaryText.ToString()); + } + } } From b35485da4725b9763e75fbe5b1c0ba7f0bf9af81 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 21 Nov 2017 11:03:07 -0800 Subject: [PATCH 05/14] Cleaned the code --- .../Services/DocumentationConverter.cs | 19 ------------------- .../TypeLookUpV2Facts.cs | 18 ------------------ 2 files changed, 37 deletions(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 2b76c89d18..0b2db6a036 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -177,7 +177,6 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument CurrentElementText.Append(xml["langword"]); break; case "seealso": - CurrentElementText.Append(lineEnding); CurrentElementText.Append("See also: "); CurrentElementText.Append(GetCref(xml["cref"])); break; @@ -233,24 +232,6 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument return docComment; } } - /* private static string ReadInnerXMLText(XmlReader xml, string elementName,string lineEnding) - { - if (xml.Read()) - { - if (xml.NodeType == XmlNodeType.Text) - { - if (elementName == "code") - { - return xml.Value; - } - else - { - return TrimMultiLineString(xml.Value, lineEnding); - } - } - } - return ""; - }*/ } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index 8ff329ed54..a5c0d1da81 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -14,24 +14,6 @@ namespace OmniSharp.Roslyn.CSharp.Tests { public class TypeLookUpV2Facts : AbstractSingleRequestHandlerTestFixture { - private readonly TestFile s_testFile = new TestFile("dummy.cs", @"using System; -namespace hoverXmlDoc -{ - class testissue - { - ///Checks if object is tagged with the tag. - /// The game object. - /// Name of the tag - /// Returns trueif object is tagged with tag. - - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } - } -} -"); - public TypeLookUpV2Facts(ITestOutputHelper testOutput) : base(testOutput) { } From 9ca970fde3bd5f57c115ae69e9f78d4316066cc5 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 21 Nov 2017 12:41:23 -0800 Subject: [PATCH 06/14] Removed ParamRef --- .../Models/v2/TypeLookUp/DocumentationComment.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index 05b9fc89f7..52f6fd56ae 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -11,7 +11,6 @@ public class DocumentationComment public StringBuilder ReturnsText { get; set; } public StringBuilder SummaryText { get; set; } public StringBuilder ValueText { get; set; } - public StringBuilder paramref { get; set; } public List Param { get; set; } public List TypeParam { get; set; } @@ -23,7 +22,6 @@ public DocumentationComment() ReturnsText = new StringBuilder(); SummaryText = new StringBuilder(); ValueText = new StringBuilder(); - paramref = new StringBuilder(); Param = new List(); TypeParam = new List(); From 056aed52e25d24146fcf4d0e684a94a43bfeeb0c Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 21 Nov 2017 13:06:32 -0800 Subject: [PATCH 07/14] Added test --- .../Services/DocumentationConverter.cs | 2 +- .../TypeLookUpV2Facts.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 0b2db6a036..cb0e47d3dc 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -1,9 +1,9 @@ -using OmniSharp.Models.v2.TypeLookUp; using System; using System.IO; using System.Linq; using System.Text; using System.Xml; +using OmniSharp.Models.v2.TypeLookUp; namespace OmniSharp.Roslyn.CSharp.Services.Documentation { diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index a5c0d1da81..e1ea3be662 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -297,5 +297,29 @@ public class TestClass Assert.Equal(expected.Replace("\r", ""), response.DocComment.SummaryText.ToString()); } + [Fact] + public async Task CheckXmlDocumentationNestedTagSeeAlso() + { + string content = @" +public class TestClass +{ + /// DoWork is a method in the TestClass class. + /// + /// + public static void Do$$Work(int Int1) + { + } + + static void Main() + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = +@"Summary: DoWork is a method in the TestClass class. +See also: TestClass.Main "; + Assert.Equal(expected.Replace("\r",""), response.DocComment.SummaryText.ToString()); + } + } } From 5013278900b16ad8a2b631d06313199682e9bd6f Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 21 Nov 2017 14:50:15 -0800 Subject: [PATCH 08/14] Converted from stringBuilder to string --- .../v2/TypeLookUp/DocumentationComment.cs | 31 ++++++------ .../Services/DocumentationConverter.cs | 49 +++++++++++++------ .../TypeLookUpV2Facts.cs | 32 ++++++------ 3 files changed, 64 insertions(+), 48 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index 52f6fd56ae..3cf066bec3 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -5,26 +5,23 @@ namespace OmniSharp.Models.v2.TypeLookUp public class DocumentationComment { //[DefaultValue("")] - public StringBuilder RemarksText { get; set; } - public StringBuilder ExampleText { get; set; } - public StringBuilder ExceptionText { get; set; } - public StringBuilder ReturnsText { get; set; } - public StringBuilder SummaryText { get; set; } - public StringBuilder ValueText { get; set; } - public List Param { get; set; } - public List TypeParam { get; set; } + public string RemarksText { get; set; } + public string ExampleText { get; set; } + public string ExceptionText { get; set; } + public string ReturnsText { get; set; } + public string SummaryText { get; set; } + public string ValueText { get; set; } + public string [] Param { get; set; } + public string [] TypeParam { get; set; } public DocumentationComment() { - RemarksText = new StringBuilder(); - ExampleText = new StringBuilder(); - ExceptionText = new StringBuilder(); - ReturnsText = new StringBuilder(); - SummaryText = new StringBuilder(); - ValueText = new StringBuilder(); - Param = new List(); - TypeParam = new List(); - + RemarksText = ""; + ExampleText = ""; + ExceptionText = ""; + ReturnsText = ""; + SummaryText = ""; + ValueText = ""; } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index cb0e47d3dc..468ca36f35 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -134,6 +135,15 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument return null; var docComment = new DocumentationComment(); var reader = new StringReader("" + xmlDocumentation + ""); + StringBuilder RemarksText = new StringBuilder(); + StringBuilder ExampleText = new StringBuilder(); + StringBuilder ExceptionText = new StringBuilder(); + StringBuilder ReturnsText = new StringBuilder(); + StringBuilder SummaryText = new StringBuilder(); + StringBuilder ValueText = new StringBuilder(); + List Param = new List(); + List TypeParam = new List(); + using (var xml = XmlReader.Create(reader)) { try @@ -152,25 +162,25 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument xml.Skip(); break; case "remarks": - docComment.RemarksText.Append("Remarks: "); - CurrentElementText = docComment.RemarksText; + RemarksText.Append("Remarks: "); + CurrentElementText = RemarksText; break; case "example": - docComment.ExampleText.Append("Example: "); - CurrentElementText = docComment.ExampleText; + ExampleText.Append("Example: "); + CurrentElementText = ExampleText; break; case "exception": - docComment.ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); - docComment.ExceptionText.Append(": "); - CurrentElementText = docComment.ExceptionText; + ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); + ExceptionText.Append(": "); + CurrentElementText = ExceptionText; break; case "returns": - docComment.ReturnsText.Append("Returns: "); - CurrentElementText = docComment.ReturnsText; + ReturnsText.Append("Returns: "); + CurrentElementText = ReturnsText; break; case "summary": - docComment.SummaryText.Append("Summary: "); - CurrentElementText = docComment.SummaryText; + SummaryText.Append("Summary: "); + CurrentElementText = SummaryText; break; case "see": CurrentElementText.Append(GetCref(xml["cref"])); @@ -189,7 +199,7 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument parameter.Append(TrimMultiLineString(xml["name"], lineEnding)); parameter.Append(": "); CurrentElementText = parameter; - docComment.Param.Add(parameter); + Param.Add(parameter); break; case "typeparamref": CurrentElementText.Append(xml["name"]); @@ -200,11 +210,11 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument TypeParameter.Append(TrimMultiLineString(xml["name"], lineEnding)); TypeParameter.Append(": "); CurrentElementText = TypeParameter; - docComment.TypeParam.Add(TypeParameter); + TypeParam.Add(TypeParameter); break; case "value": - docComment.ValueText.Append("Value: "); - CurrentElementText = docComment.ValueText; + ValueText.Append("Value: "); + CurrentElementText = ValueText; break; case "br": case "para": @@ -229,6 +239,15 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument { return null; } + docComment.RemarksText = RemarksText.ToString(); + docComment.ExampleText = ExampleText.ToString(); + docComment.ExceptionText = ExceptionText.ToString(); + docComment.ReturnsText = ReturnsText.ToString(); + docComment.SummaryText = SummaryText.ToString(); + docComment.ValueText = ValueText.ToString(); + docComment.Param = Param.Select(s => s.ToString()).ToArray(); + docComment.TypeParam = TypeParam.Select(s => s.ToString()).ToArray(); + return docComment; } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index e1ea3be662..2c2074fc8d 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -49,7 +49,7 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"Remarks: You may have some additional information about this class here."; - Assert.Equal(expected, response.DocComment.RemarksText.ToString()); + Assert.Equal(expected, response.DocComment.RemarksText); } [Fact] @@ -66,7 +66,7 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"Summary: Checks if object is tagged with the tag."; - Assert.Equal(expected, response.DocComment.SummaryText.ToString()); + Assert.Equal(expected, response.DocComment.SummaryText); } [Fact] @@ -83,7 +83,7 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"Returns: Returns true if object is tagged with tag."; - Assert.Equal(expected, response.DocComment.ReturnsText.ToString()); + Assert.Equal(expected, response.DocComment.ReturnsText); } [Fact] @@ -100,7 +100,7 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"Example: Checks if object is tagged with the tag."; - Assert.Equal(expected, response.DocComment.ExampleText.ToString()); + Assert.Equal(expected, response.DocComment.ExampleText); } [Fact] @@ -117,7 +117,7 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"System.Exception: Thrown when something goes wrong"; - Assert.Equal(expected, response.DocComment.ExceptionText.ToString()); + Assert.Equal(expected, response.DocComment.ExceptionText); } [Fact] @@ -135,8 +135,8 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"gameObject: The game object."; - Assert.Equal(2,response.DocComment.Param.Count); - Assert.Equal(expected, response.DocComment.Param[0].ToString()); + Assert.Equal(2,response.DocComment.Param.Length); + Assert.Equal(expected, response.DocComment.Param[0]); } [Fact] @@ -155,8 +155,8 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"tagName: Name of the tag."; - Assert.Equal(2, response.DocComment.Param.Count); - Assert.Equal(expected, response.DocComment.Param[1].ToString()); + Assert.Equal(2, response.DocComment.Param.Length); + Assert.Equal(expected, response.DocComment.Param[1]); } [Fact] @@ -178,7 +178,7 @@ public class TestClass var expected = @"T: The element type of the array"; Assert.Single(response.DocComment.TypeParam); - Assert.Equal(expected, response.DocComment.TypeParam[0].ToString()); + Assert.Equal(expected, response.DocComment.TypeParam[0]); } [Fact] @@ -199,7 +199,7 @@ public string Na$$me var response = await GetTypeLookUpResponse(content); var expected = @"Value: The Name property gets/sets the value of the string field, _name."; - Assert.Equal(expected, response.DocComment.ValueText.ToString()); + Assert.Equal(expected, response.DocComment.ValueText); } [Fact] @@ -216,7 +216,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."; - Assert.Equal(expected, response.DocComment.SummaryText.ToString()); + Assert.Equal(expected, response.DocComment.SummaryText); } [Fact] @@ -235,7 +235,7 @@ public class TestClass var response = await GetTypeLookUpResponse(content); var expected = @"Summary: Creates a new array of arbitrary type T "; - Assert.Equal(expected, response.DocComment.SummaryText.ToString()); + Assert.Equal(expected, response.DocComment.SummaryText); } [Fact] @@ -272,7 +272,7 @@ static int Main() } } "; - Assert.Equal(expected.Replace("\r",""), response.DocComment.ExampleText.ToString()); + Assert.Equal(expected.Replace("\r",""), response.DocComment.ExampleText); } [Fact] @@ -294,7 +294,7 @@ public class TestClass @"Summary: DoWork is a method in the TestClass class. Here's how you could make a second paragraph in a description."; - Assert.Equal(expected.Replace("\r", ""), response.DocComment.SummaryText.ToString()); + Assert.Equal(expected.Replace("\r", ""), response.DocComment.SummaryText); } [Fact] @@ -318,7 +318,7 @@ static void Main() var expected = @"Summary: DoWork is a method in the TestClass class. See also: TestClass.Main "; - Assert.Equal(expected.Replace("\r",""), response.DocComment.SummaryText.ToString()); + Assert.Equal(expected.Replace("\r",""), response.DocComment.SummaryText); } } From eb79ac8bf30c5e0412d89ba1de357678fe6400ca Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 22 Nov 2017 11:18:49 -0800 Subject: [PATCH 09/14] Added array for exceptions --- .../v2/TypeLookUp/DocumentationComment.cs | 3 +- .../Services/DocumentationConverter.cs | 33 ++++++++++--------- .../TypeLookUpV2Facts.cs | 3 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index 3cf066bec3..4ca645dc53 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -7,18 +7,17 @@ public class DocumentationComment //[DefaultValue("")] public string RemarksText { get; set; } public string ExampleText { get; set; } - public string ExceptionText { get; set; } public string ReturnsText { get; set; } public string SummaryText { get; set; } public string ValueText { get; set; } public string [] Param { get; set; } public string [] TypeParam { get; set; } + public string [] Exception { get; set; } public DocumentationComment() { RemarksText = ""; ExampleText = ""; - ExceptionText = ""; ReturnsText = ""; SummaryText = ""; ValueText = ""; diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 468ca36f35..1c2249a74d 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -137,12 +137,12 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument var reader = new StringReader("" + xmlDocumentation + ""); StringBuilder RemarksText = new StringBuilder(); StringBuilder ExampleText = new StringBuilder(); - StringBuilder ExceptionText = new StringBuilder(); StringBuilder ReturnsText = new StringBuilder(); StringBuilder SummaryText = new StringBuilder(); StringBuilder ValueText = new StringBuilder(); List Param = new List(); List TypeParam = new List(); + List Exception = new List(); using (var xml = XmlReader.Create(reader)) { @@ -170,9 +170,11 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument CurrentElementText = ExampleText; break; case "exception": - ExceptionText.Append(GetCref(xml["cref"]).TrimEnd()); - ExceptionText.Append(": "); - CurrentElementText = ExceptionText; + StringBuilder ExceptionInstance = new StringBuilder(); + ExceptionInstance.Append(GetCref(xml["cref"]).TrimEnd()); + ExceptionInstance.Append(": "); + CurrentElementText = ExceptionInstance; + Exception.Add(ExceptionInstance); break; case "returns": ReturnsText.Append("Returns: "); @@ -195,22 +197,22 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument CurrentElementText.Append(" "); break; case "param": - StringBuilder parameter = new StringBuilder(); - parameter.Append(TrimMultiLineString(xml["name"], lineEnding)); - parameter.Append(": "); - CurrentElementText = parameter; - Param.Add(parameter); + StringBuilder ParamInstance = new StringBuilder(); + ParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); + ParamInstance.Append(": "); + CurrentElementText = ParamInstance; + Param.Add(ParamInstance); break; case "typeparamref": CurrentElementText.Append(xml["name"]); CurrentElementText.Append(" "); break; case "typeparam": - StringBuilder TypeParameter = new StringBuilder(); - TypeParameter.Append(TrimMultiLineString(xml["name"], lineEnding)); - TypeParameter.Append(": "); - CurrentElementText = TypeParameter; - TypeParam.Add(TypeParameter); + StringBuilder TypeParamInstance = new StringBuilder(); + TypeParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); + TypeParamInstance.Append(": "); + CurrentElementText = TypeParamInstance; + TypeParam.Add(TypeParamInstance); break; case "value": ValueText.Append("Value: "); @@ -241,13 +243,12 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument } docComment.RemarksText = RemarksText.ToString(); docComment.ExampleText = ExampleText.ToString(); - docComment.ExceptionText = ExceptionText.ToString(); docComment.ReturnsText = ReturnsText.ToString(); docComment.SummaryText = SummaryText.ToString(); docComment.ValueText = ValueText.ToString(); docComment.Param = Param.Select(s => s.ToString()).ToArray(); docComment.TypeParam = TypeParam.Select(s => s.ToString()).ToArray(); - + docComment.Exception = Exception.Select(s => s.ToString()).ToArray(); return docComment; } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index 2c2074fc8d..86127a0291 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -117,7 +117,8 @@ class testissue var response = await GetTypeLookUpResponse(content); var expected = @"System.Exception: Thrown when something goes wrong"; - Assert.Equal(expected, response.DocComment.ExceptionText); + Assert.Single(response.DocComment.Exception); + Assert.Equal(expected, response.DocComment.Exception[0]); } [Fact] From c3d1faf967c3186636af84a243ed49f7bcb80509 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 30 Nov 2017 12:01:19 -0800 Subject: [PATCH 10/14] Unncessary Lines Removed and Tests Modified --- .../v2/TypeLookUp/DocumentationComment.cs | 7 +- .../Models/v2/TypeLookUp/TypeLookUpRequest.cs | 2 +- .../v2/TypeLookUp/TypeLookUpResponse.cs | 6 +- .../Services/DocumentationConverter.cs | 103 +++++++++--------- .../TypeLookUpV2Facts.cs | 42 +++---- 5 files changed, 72 insertions(+), 88 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs index 4ca645dc53..0af4222acc 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs @@ -4,15 +4,14 @@ namespace OmniSharp.Models.v2.TypeLookUp { public class DocumentationComment { - //[DefaultValue("")] public string RemarksText { get; set; } public string ExampleText { get; set; } public string ReturnsText { get; set; } public string SummaryText { get; set; } public string ValueText { get; set; } - public string [] Param { get; set; } - public string [] TypeParam { get; set; } - public string [] Exception { get; set; } + public string [ ] ParamElements { get; set; } + public string [ ] TypeParamElements { get; set; } + public string [ ] Exception { get; set; } public DocumentationComment() { diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs index 194450d233..e42ee7980d 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs @@ -3,7 +3,7 @@ namespace OmniSharp.Models.v2.TypeLookUp { [OmniSharpEndpoint(OmniSharpEndpoints.V2.TypeLookup, typeof(TypeLookupRequest), typeof(TypeLookupResponse))] - public class TypeLookupRequest:Request + public class TypeLookupRequest : Request { public bool IncludeDocumentation { get; set; } } diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs index 8e75b86f66..30c6851862 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs +++ b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs @@ -1,10 +1,8 @@ - -namespace OmniSharp.Models.v2.TypeLookUp +namespace OmniSharp.Models.v2.TypeLookUp { public class TypeLookupResponse { public string Type { get; set; } public DocumentationComment DocComment { get; set; } - } - + } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 1c2249a74d..6d3e2de8b5 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -135,14 +135,14 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument return null; var docComment = new DocumentationComment(); var reader = new StringReader("" + xmlDocumentation + ""); - StringBuilder RemarksText = new StringBuilder(); - StringBuilder ExampleText = new StringBuilder(); - StringBuilder ReturnsText = new StringBuilder(); - StringBuilder SummaryText = new StringBuilder(); - StringBuilder ValueText = new StringBuilder(); - List Param = new List(); - List TypeParam = new List(); - List Exception = new List(); + StringBuilder remarksText = new StringBuilder(); + StringBuilder exampleText = new StringBuilder(); + StringBuilder returnsText = new StringBuilder(); + StringBuilder summaryText = new StringBuilder(); + StringBuilder valueText = new StringBuilder(); + List paramElements = new List(); + List typeParamElements = new List(); + List exception = new List(); using (var xml = XmlReader.Create(reader)) { @@ -150,7 +150,7 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument { xml.Read(); string elementName = null; - StringBuilder CurrentElementText = null; + StringBuilder currentSectionBuilder = null; do { if (xml.NodeType == XmlNodeType.Element) @@ -162,77 +162,77 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument xml.Skip(); break; case "remarks": - RemarksText.Append("Remarks: "); - CurrentElementText = RemarksText; + remarksText.Append("Remarks: "); + currentSectionBuilder = remarksText; break; case "example": - ExampleText.Append("Example: "); - CurrentElementText = ExampleText; + exampleText.Append("Example: "); + currentSectionBuilder = exampleText; break; case "exception": StringBuilder ExceptionInstance = new StringBuilder(); ExceptionInstance.Append(GetCref(xml["cref"]).TrimEnd()); ExceptionInstance.Append(": "); - CurrentElementText = ExceptionInstance; - Exception.Add(ExceptionInstance); + currentSectionBuilder = ExceptionInstance; + exception.Add(ExceptionInstance); break; case "returns": - ReturnsText.Append("Returns: "); - CurrentElementText = ReturnsText; + returnsText.Append("Returns: "); + currentSectionBuilder = returnsText; break; case "summary": - SummaryText.Append("Summary: "); - CurrentElementText = SummaryText; + summaryText.Append("Summary: "); + currentSectionBuilder = summaryText; break; case "see": - CurrentElementText.Append(GetCref(xml["cref"])); - CurrentElementText.Append(xml["langword"]); + currentSectionBuilder.Append(GetCref(xml["cref"])); + currentSectionBuilder.Append(xml["langword"]); break; case "seealso": - CurrentElementText.Append("See also: "); - CurrentElementText.Append(GetCref(xml["cref"])); + currentSectionBuilder.Append("See also: "); + currentSectionBuilder.Append(GetCref(xml["cref"])); break; case "paramref": - CurrentElementText.Append(xml["name"]); - CurrentElementText.Append(" "); + currentSectionBuilder.Append(xml["name"]); + currentSectionBuilder.Append(" "); break; case "param": - StringBuilder ParamInstance = new StringBuilder(); - ParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); - ParamInstance.Append(": "); - CurrentElementText = ParamInstance; - Param.Add(ParamInstance); + StringBuilder paramInstance = new StringBuilder(); + paramInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); + paramInstance.Append(": "); + currentSectionBuilder = paramInstance; + paramElements.Add(paramInstance); break; case "typeparamref": - CurrentElementText.Append(xml["name"]); - CurrentElementText.Append(" "); + currentSectionBuilder.Append(xml["name"]); + currentSectionBuilder.Append(" "); break; case "typeparam": - StringBuilder TypeParamInstance = new StringBuilder(); - TypeParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); - TypeParamInstance.Append(": "); - CurrentElementText = TypeParamInstance; - TypeParam.Add(TypeParamInstance); + StringBuilder typeParamInstance = new StringBuilder(); + typeParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); + typeParamInstance.Append(": "); + currentSectionBuilder = typeParamInstance; + typeParamElements.Add(typeParamInstance); break; case "value": - ValueText.Append("Value: "); - CurrentElementText = ValueText; + valueText.Append("Value: "); + currentSectionBuilder = valueText; break; case "br": case "para": - CurrentElementText.Append(lineEnding); + currentSectionBuilder.Append(lineEnding); break; } } - else if (xml.NodeType == XmlNodeType.Text && CurrentElementText != null) + else if (xml.NodeType == XmlNodeType.Text && currentSectionBuilder != null) { if (elementName == "code") { - CurrentElementText.Append(xml.Value); + currentSectionBuilder.Append(xml.Value); } else { - CurrentElementText.Append(TrimMultiLineString(xml.Value, lineEnding)); + currentSectionBuilder.Append(TrimMultiLineString(xml.Value, lineEnding)); } } } while (xml.Read()); @@ -241,14 +241,15 @@ public static DocumentationComment ConvertDocumentationObject(string xmlDocument { return null; } - docComment.RemarksText = RemarksText.ToString(); - docComment.ExampleText = ExampleText.ToString(); - docComment.ReturnsText = ReturnsText.ToString(); - docComment.SummaryText = SummaryText.ToString(); - docComment.ValueText = ValueText.ToString(); - docComment.Param = Param.Select(s => s.ToString()).ToArray(); - docComment.TypeParam = TypeParam.Select(s => s.ToString()).ToArray(); - docComment.Exception = Exception.Select(s => s.ToString()).ToArray(); + + docComment.RemarksText = remarksText.ToString(); + docComment.ExampleText = exampleText.ToString(); + docComment.ReturnsText = returnsText.ToString(); + docComment.SummaryText = summaryText.ToString(); + docComment.ValueText = valueText.ToString(); + docComment.ParamElements = paramElements.Select(s => s.ToString()).ToArray(); + docComment.TypeParamElements = typeParamElements.Select(s => s.ToString()).ToArray(); + docComment.Exception = exception.Select(s => s.ToString()).ToArray(); return docComment; } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index 86127a0291..3a3c35b6a4 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -122,26 +122,7 @@ class testissue } [Fact] - public async Task CheckXmlDocumentationParameter1() - { - string content = @" -class testissue -{ - /// The game object. - /// Name of the tag - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"gameObject: The game object."; - Assert.Equal(2,response.DocComment.Param.Length); - Assert.Equal(expected, response.DocComment.Param[0]); - } - - [Fact] - public async Task CheckXmlDocumentationParameter2() + public async Task CheckXmlDocumentationParameter() { string content = @" class testissue @@ -150,14 +131,16 @@ class testissue /// Name of the tag. public static bool C$$ompare(int gameObject, string tagName) { - } }"; var response = await GetTypeLookUpResponse(content); - var expected = + var expected0 = + @"gameObject: The game object."; + var expected1 = @"tagName: Name of the tag."; - Assert.Equal(2, response.DocComment.Param.Length); - Assert.Equal(expected, response.DocComment.Param[1]); + Assert.Equal(2, response.DocComment.ParamElements.Length); + Assert.Equal(expected0, response.DocComment.ParamElements[0]); + Assert.Equal(expected1, response.DocComment.ParamElements[1]); } [Fact] @@ -178,8 +161,8 @@ public class TestClass var response = await GetTypeLookUpResponse(content); var expected = @"T: The element type of the array"; - Assert.Single(response.DocComment.TypeParam); - Assert.Equal(expected, response.DocComment.TypeParam[0]); + Assert.Single(response.DocComment.TypeParamElements); + Assert.Equal(expected, response.DocComment.TypeParamElements[0]); } [Fact] @@ -198,9 +181,12 @@ public string Na$$me } "; var response = await GetTypeLookUpResponse(content); - var expected = + var expectedValue = @"Value: The Name property gets/sets the value of the string field, _name."; - Assert.Equal(expected, response.DocComment.ValueText); + Assert.Equal(expectedValue, response.DocComment.ValueText); + var expectedSummary = + @"Summary: The Name property represents the employee's name."; + Assert.Equal(expectedSummary, response.DocComment.SummaryText); } [Fact] From 93b384643f55b50b198afbf39fccb25f67a65b76 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 30 Nov 2017 12:56:00 -0800 Subject: [PATCH 11/14] Added tests for tags appearing together --- .../TypeLookUpV2Facts.cs | 145 ++++++++++++++---- 1 file changed, 116 insertions(+), 29 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs index 3a3c35b6a4..09165c20e8 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs @@ -35,7 +35,7 @@ private async Task GetTypeLookUpResponse(string content) } [Fact] - public async Task CheckXmlDocumentationRemarksText() + public async Task XmlDocumentationRemarksText() { string content= @" class testissue @@ -53,7 +53,7 @@ class testissue } [Fact] - public async Task CheckXmlDocumentationSummaryText() + public async Task XmlDocumentationSummaryText() { string content = @" class testissue @@ -70,7 +70,7 @@ class testissue } [Fact] - public async Task CheckXmlDocumentationReturnsText() + public async Task XmlDocumentationReturnsText() { string content = @" class testissue @@ -87,7 +87,7 @@ class testissue } [Fact] - public async Task CheckXmlDocumentationExampleText() + public async Task XmlDocumentationExampleText() { string content = @" class testissue @@ -104,25 +104,30 @@ class testissue } [Fact] - public async Task CheckXmlDocumentationExceptionText() + public async Task XmlDocumentationExceptionText() { string content = @" class testissue { - ///Thrown when something goes wrong + ///A description + ///B description public static bool C$$ompare(int gameObject, string tagName) { } }"; var response = await GetTypeLookUpResponse(content); - var expected = - @"System.Exception: Thrown when something goes wrong"; - Assert.Single(response.DocComment.Exception); - Assert.Equal(expected, response.DocComment.Exception[0]); + Assert.Equal(2,response.DocComment.Exception.Count()); + + var expectedException0 = + @"A: A description"; + Assert.Equal(expectedException0, response.DocComment.Exception[0]); + var expectedException1 = + @"B: B description"; + Assert.Equal(expectedException1, response.DocComment.Exception[1]); } [Fact] - public async Task CheckXmlDocumentationParameter() + public async Task XmlDocumentationParameter() { string content = @" class testissue @@ -134,39 +139,45 @@ class testissue } }"; var response = await GetTypeLookUpResponse(content); - var expected0 = + Assert.Equal(2, response.DocComment.ParamElements.Length); + + var expectedParam0 = @"gameObject: The game object."; - var expected1 = + Assert.Equal(expectedParam0, response.DocComment.ParamElements[0]); + var expectedParam1 = @"tagName: Name of the tag."; - Assert.Equal(2, response.DocComment.ParamElements.Length); - Assert.Equal(expected0, response.DocComment.ParamElements[0]); - Assert.Equal(expected1, response.DocComment.ParamElements[1]); + Assert.Equal(expectedParam1, response.DocComment.ParamElements[1]); } [Fact] - public async Task CheckXmlDocumentationTypeParameter() + public async Task XmlDocumentationTypeParameter() { string content = @" public class TestClass { /// - /// Creates a new array of arbitrary type + /// Creates a new array of arbitrary type and adds the elements of incoming list to it if possible /// /// The element type of the array - public static T[] m$$kArray(int n) + /// The element type of the list + public static T[] m$$kArray(int n, List list) { return new T[n]; } }"; var response = await GetTypeLookUpResponse(content); - var expected = - @"T: The element type of the array"; - Assert.Single(response.DocComment.TypeParamElements); - Assert.Equal(expected, response.DocComment.TypeParamElements[0]); + Assert.Equal(2,response.DocComment.TypeParamElements.Count()); + + var expected0 = + @"T: The element type of the array"; + Assert.Equal(expected0, response.DocComment.TypeParamElements[0]); + var expected1 = + @"X: The element type of the list"; + Assert.Equal(expected1, response.DocComment.TypeParamElements[1]); } [Fact] - public async Task CheckXmlDocumentationValueText() + public async Task XmlDocumentationValueText() { string content = @"public class Employee @@ -190,7 +201,7 @@ public string Na$$me } [Fact] - public async Task CheckXmlDocumentationNestedTagSee() + public async Task XmlDocumentationNestedTagSee() { string content = @" public class TestClass @@ -207,7 +218,7 @@ public class TestClass } [Fact] - public async Task CheckXmlDocumentationNestedTagParamRef() + public async Task XmlDocumentationNestedTagParamRef() { string content = @" public class TestClass @@ -226,7 +237,7 @@ public class TestClass } [Fact] - public async Task CheckXmlDocumentationNestedTagCode() + public async Task XmlDocumentationNestedTagCode() { string content = @" public class TestClass @@ -263,7 +274,7 @@ static int Main() } [Fact] - public async Task CheckXmlDocumentationNestedTagPara() + public async Task XmlDocumentationNestedTagPara() { string content = @" public class TestClass @@ -285,7 +296,7 @@ public class TestClass } [Fact] - public async Task CheckXmlDocumentationNestedTagSeeAlso() + public async Task XmlDocumentationNestedTagSeeAlso() { string content = @" public class TestClass @@ -308,5 +319,81 @@ static void Main() Assert.Equal(expected.Replace("\r",""), response.DocComment.SummaryText); } + [Fact] + public async Task XmlDocumentationSummaryAndParam() + { + string content = @" +class testissue +{ + ///Checks if object is tagged with the tag. + /// The game object. + /// Name of the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: Checks if object is tagged with the tag."; + Assert.Equal(expected, response.DocComment.SummaryText); + + Assert.Equal(2, response.DocComment.ParamElements.Length); + var expectedParam0 = + @"gameObject: The game object."; + Assert.Equal(expectedParam0, response.DocComment.ParamElements[0]); + var expectedParam1 = + @"tagName: Name of the tag."; + Assert.Equal(expectedParam1, response.DocComment.ParamElements[1]); + } + + [Fact] + public async Task XmlDocumentationManyTags() + { + string content = @" +class testissue +{ + ///Checks if object is tagged with the tag. + ///The game object. + ///Invoke using A.Compare(5) where A is an instance of the class testissue. + ///The element type of the array + ///Thrown when something goes wrong + ///You may have some additional information about this class here. + ///Returns an array of type . + public static T[] C$$ompare(int gameObject) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expectedSummary = + @"Summary: Checks if object is tagged with the tag."; + Assert.Equal(expectedSummary, response.DocComment.SummaryText); + + Assert.Single(response.DocComment.ParamElements); + var expectedParam = + @"gameObject: The game object."; + Assert.Equal(expectedParam, response.DocComment.ParamElements[0]); + + var expectedExample = + @"Example: Invoke using A.Compare(5) where A is an instance of the class testissue."; + Assert.Equal(expectedExample, response.DocComment.ExampleText); + + Assert.Single(response.DocComment.TypeParamElements); + var expectedTypeParam = + @"T: The element type of the array"; + Assert.Equal(expectedTypeParam, response.DocComment.TypeParamElements[0]); + + Assert.Single(response.DocComment.Exception); + var expectedException = + @"System.Exception: Thrown when something goes wrong"; + Assert.Equal(expectedException, response.DocComment.Exception[0]); + + var expectedRemarks = + @"Remarks: You may have some additional information about this class here."; + Assert.Equal(expectedRemarks, response.DocComment.RemarksText); + + var expectedReturns = + @"Returns: Returns an array of type T ."; + Assert.Equal(expectedReturns, response.DocComment.ReturnsText); + } } } From a6b1a97c54db2674eb7bd5a0f85849d566b758cb Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 1 Dec 2017 11:07:26 -0800 Subject: [PATCH 12/14] Added property to V1 --- .../TypeLookup}/DocumentationComment.cs | 10 +- .../v1/TypeLookup/TypeLookupResponse.cs | 3 +- .../Models/v2/TypeLookUp/TypeLookUpRequest.cs | 11 - .../v2/TypeLookUp/TypeLookUpResponse.cs | 8 - .../OmniSharpEndpoints.cs | 2 - .../Services/DocumentationConverter.cs | 4 +- .../Services/Types/TypeLookup.cs | 1 + .../Services/Types/V2/TypeLookUp.cs | 56 --- .../TypeLookUpV2Facts.cs | 399 ------------------ .../TypeLookupFacts.cs | 377 +++++++++++++++++ 10 files changed, 386 insertions(+), 485 deletions(-) rename src/OmniSharp.Abstractions/Models/{v2/TypeLookUp => v1/TypeLookup}/DocumentationComment.cs (65%) delete mode 100644 src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs delete mode 100644 src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs delete mode 100644 src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs delete mode 100644 tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs similarity index 65% rename from src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs rename to src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 0af4222acc..9d329cdd0e 100644 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Text; -namespace OmniSharp.Models.v2.TypeLookUp +namespace OmniSharp.Models.TypeLookup { public class DocumentationComment { @@ -9,9 +7,9 @@ public class DocumentationComment public string ReturnsText { get; set; } public string SummaryText { get; set; } public string ValueText { get; set; } - public string [ ] ParamElements { get; set; } - public string [ ] TypeParamElements { get; set; } - public string [ ] Exception { get; set; } + public string[ ] ParamElements { get; set; } + public string[ ] TypeParamElements { get; set; } + public string[ ] Exception { get; set; } public DocumentationComment() { diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/TypeLookupResponse.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/TypeLookupResponse.cs index 12ac067013..73345ab913 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/TypeLookupResponse.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/TypeLookupResponse.cs @@ -4,5 +4,6 @@ public class TypeLookupResponse { public string Type { get; set; } public string Documentation { get; set; } + public DocumentationComment StructuredDocumentation { get; set; } } -} \ No newline at end of file +} diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs deleted file mode 100644 index e42ee7980d..0000000000 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpRequest.cs +++ /dev/null @@ -1,11 +0,0 @@ -using OmniSharp.Mef; - -namespace OmniSharp.Models.v2.TypeLookUp -{ - [OmniSharpEndpoint(OmniSharpEndpoints.V2.TypeLookup, typeof(TypeLookupRequest), typeof(TypeLookupResponse))] - public class TypeLookupRequest : Request - { - public bool IncludeDocumentation { get; set; } - } -} - diff --git a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs b/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs deleted file mode 100644 index 30c6851862..0000000000 --- a/src/OmniSharp.Abstractions/Models/v2/TypeLookUp/TypeLookUpResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace OmniSharp.Models.v2.TypeLookUp -{ - public class TypeLookupResponse - { - public string Type { get; set; } - public DocumentationComment DocComment { get; set; } - } -} diff --git a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs index 88b6e92c6c..20314bd619 100644 --- a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs +++ b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs @@ -47,14 +47,12 @@ public static class V2 { public const string GetCodeActions = "/v2/getcodeactions"; public const string RunCodeAction = "/v2/runcodeaction"; - public const string TypeLookup = "/v2/typelookup"; public const string GetTestStartInfo = "/v2/getteststartinfo"; public const string RunTest = "/v2/runtest"; public const string DebugTestGetStartInfo = "/v2/debugtest/getstartinfo"; public const string DebugTestLaunch = "/v2/debugtest/launch"; public const string DebugTestStop = "/v2/debugtest/stop"; - } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index 6d3e2de8b5..bab949b78c 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Xml; -using OmniSharp.Models.v2.TypeLookUp; +using OmniSharp.Models.TypeLookup; namespace OmniSharp.Roslyn.CSharp.Services.Documentation { @@ -129,7 +129,7 @@ private static string GetCref(string cref) return cref + " "; } - public static DocumentationComment ConvertDocumentationObject(string xmlDocumentation, string lineEnding) + public static DocumentationComment GetStructuredDocumentation(string xmlDocumentation, string lineEnding) { if (string.IsNullOrEmpty(xmlDocumentation)) return null; diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Types/TypeLookup.cs b/src/OmniSharp.Roslyn.CSharp/Services/Types/TypeLookup.cs index 9eda51d4f5..13d98efa1a 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Types/TypeLookup.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Types/TypeLookup.cs @@ -46,6 +46,7 @@ public async Task Handle(TypeLookupRequest request) if (request.IncludeDocumentation) { response.Documentation = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); + response.StructuredDocumentation = DocumentationConverter.GetStructuredDocumentation(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs b/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs deleted file mode 100644 index 8d1704fbdd..0000000000 --- a/src/OmniSharp.Roslyn.CSharp/Services/Types/V2/TypeLookUp.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Composition; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.FindSymbols; -using Microsoft.CodeAnalysis.Text; -using OmniSharp.Mef; -using OmniSharp.Models.v2.TypeLookUp; -using OmniSharp.Options; -using OmniSharp.Roslyn.CSharp.Services.Documentation; - -namespace OmniSharp.Roslyn.CSharp.Services.Types.V2 -{ - [OmniSharpHandler(OmniSharpEndpoints.V2.TypeLookup, LanguageNames.CSharp)] - public class TypeLookupService : IRequestHandler - { - private readonly FormattingOptions _formattingOptions; - private readonly OmniSharpWorkspace _workspace; - private static readonly SymbolDisplayFormat DefaultFormat = SymbolDisplayFormat.FullyQualifiedFormat. - WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted). - WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.None). - WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers); - - [ImportingConstructor] - public TypeLookupService(OmniSharpWorkspace workspace, FormattingOptions formattingOptions) - { - _workspace = workspace; - _formattingOptions = formattingOptions; - } - - public async Task Handle(TypeLookupRequest request) - { - var document = _workspace.GetDocument(request.FileName); - var response = new TypeLookupResponse(); - if (document != null) - { - var semanticModel = await document.GetSemanticModelAsync(); - var sourceText = await document.GetTextAsync(); - var position = sourceText.Lines.GetPosition(new LinePosition(request.Line, request.Column)); - var symbol = await SymbolFinder.FindSymbolAtPositionAsync(semanticModel, position, _workspace); - if (symbol != null) - { - response.Type = symbol.Kind == SymbolKind.NamedType ? - symbol.ToDisplayString(DefaultFormat) : - symbol.ToMinimalDisplayString(semanticModel, position); - - if (request.IncludeDocumentation) - { - response.DocComment = DocumentationConverter.ConvertDocumentationObject(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); - } - } - } - - return response; - } - } -} diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs deleted file mode 100644 index 09165c20e8..0000000000 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookUpV2Facts.cs +++ /dev/null @@ -1,399 +0,0 @@ - -using OmniSharp.Models.v2.TypeLookUp; -using OmniSharp.Roslyn.CSharp.Services.Types.V2; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TestUtility; -using Xunit; -using Xunit.Abstractions; - -namespace OmniSharp.Roslyn.CSharp.Tests -{ - public class TypeLookUpV2Facts : AbstractSingleRequestHandlerTestFixture - { - public TypeLookUpV2Facts(ITestOutputHelper testOutput) : base(testOutput) - { - } - - protected override string EndpointName => OmniSharpEndpoints.V2.TypeLookup; - - private async Task GetTypeLookUpResponse(string content) - { - TestFile testFile = new TestFile("dummy.cs", content); - using (var host = CreateOmniSharpHost(testFile)) - { - var requestHandler = GetRequestHandler(host); - var point = testFile.Content.GetPointFromPosition(); - var request = new TypeLookupRequest { FileName = testFile.FileName, Line = point.Line, Column = point.Offset }; - request.IncludeDocumentation = true; - - return await requestHandler.Handle(request); - } - } - - [Fact] - public async Task XmlDocumentationRemarksText() - { - string content= @" -class testissue -{ - ///You may have some additional information about this class here. - public static bool C$$ompare(int gameObject, string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Remarks: You may have some additional information about this class here."; - Assert.Equal(expected, response.DocComment.RemarksText); - } - - [Fact] - public async Task XmlDocumentationSummaryText() - { - string content = @" -class testissue -{ - ///Checks if object is tagged with the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Summary: Checks if object is tagged with the tag."; - Assert.Equal(expected, response.DocComment.SummaryText); - } - - [Fact] - public async Task XmlDocumentationReturnsText() - { - string content = @" -class testissue -{ - ///Returns true if object is tagged with tag. - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Returns: Returns true if object is tagged with tag."; - Assert.Equal(expected, response.DocComment.ReturnsText); - } - - [Fact] - public async Task XmlDocumentationExampleText() - { - string content = @" -class testissue -{ - ///Checks if object is tagged with the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Example: Checks if object is tagged with the tag."; - Assert.Equal(expected, response.DocComment.ExampleText); - } - - [Fact] - public async Task XmlDocumentationExceptionText() - { - string content = @" -class testissue -{ - ///A description - ///B description - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - Assert.Equal(2,response.DocComment.Exception.Count()); - - var expectedException0 = - @"A: A description"; - Assert.Equal(expectedException0, response.DocComment.Exception[0]); - var expectedException1 = - @"B: B description"; - Assert.Equal(expectedException1, response.DocComment.Exception[1]); - } - - [Fact] - public async Task XmlDocumentationParameter() - { - string content = @" -class testissue -{ - /// The game object. - /// Name of the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - Assert.Equal(2, response.DocComment.ParamElements.Length); - - var expectedParam0 = - @"gameObject: The game object."; - Assert.Equal(expectedParam0, response.DocComment.ParamElements[0]); - var expectedParam1 = - @"tagName: Name of the tag."; - Assert.Equal(expectedParam1, response.DocComment.ParamElements[1]); - } - - [Fact] - public async Task XmlDocumentationTypeParameter() - { - string content = @" -public class TestClass -{ - /// - /// Creates a new array of arbitrary type and adds the elements of incoming list to it if possible - /// - /// The element type of the array - /// The element type of the list - public static T[] m$$kArray(int n, List list) - { - return new T[n]; - } -}"; - var response = await GetTypeLookUpResponse(content); - Assert.Equal(2,response.DocComment.TypeParamElements.Count()); - - var expected0 = - @"T: The element type of the array"; - Assert.Equal(expected0, response.DocComment.TypeParamElements[0]); - var expected1 = - @"X: The element type of the list"; - Assert.Equal(expected1, response.DocComment.TypeParamElements[1]); - } - - [Fact] - public async Task XmlDocumentationValueText() - { - string content = -@"public class Employee -{ - private string _name; - - /// The Name property represents the employee's name. - /// The Name property gets/sets the value of the string field, _name. - public string Na$$me - { - } -} -"; - var response = await GetTypeLookUpResponse(content); - var expectedValue = - @"Value: The Name property gets/sets the value of the string field, _name."; - Assert.Equal(expectedValue, response.DocComment.ValueText); - var expectedSummary = - @"Summary: The Name property represents the employee's name."; - Assert.Equal(expectedSummary, response.DocComment.SummaryText); - } - - [Fact] - public async Task XmlDocumentationNestedTagSee() - { - string content = @" -public class TestClass -{ - /// DoWork is a method in the TestClass class. for information about output statements. - public static void Do$$Work(int Int1) - { - } -}"; - 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."; - Assert.Equal(expected, response.DocComment.SummaryText); - } - - [Fact] - public async Task XmlDocumentationNestedTagParamRef() - { - string content = @" -public class TestClass -{ - /// Creates a new array of arbitrary type - /// The element type of the array - public static T[] mk$$Array(int n) - { - return new T[n]; - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Summary: Creates a new array of arbitrary type T "; - Assert.Equal(expected, response.DocComment.SummaryText); - } - - [Fact] - public async Task XmlDocumentationNestedTagCode() - { - string content = @" -public class TestClass -{ - /// This sample shows how to call the method. - /// - /// class TestClass - /// { - /// static int Main() - /// { - /// return GetZero(); - /// } - /// } - /// - /// - public static int $$GetZero() - { - return 0; - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Example: This sample shows how to call the TestClass.GetZero method. - - class TestClass - { - static int Main() - { - return GetZero(); - } - } - "; - Assert.Equal(expected.Replace("\r",""), response.DocComment.ExampleText); - } - - [Fact] - public async Task XmlDocumentationNestedTagPara() - { - string content = @" -public class TestClass -{ - /// DoWork is a method in the TestClass class. - /// Here's how you could make a second paragraph in a description. - /// - public static void Do$$Work(int Int1) - { - } -} - "; - var response = await GetTypeLookUpResponse(content); - var expected = -@"Summary: DoWork is a method in the TestClass class. - -Here's how you could make a second paragraph in a description."; - Assert.Equal(expected.Replace("\r", ""), response.DocComment.SummaryText); - } - - [Fact] - public async Task XmlDocumentationNestedTagSeeAlso() - { - string content = @" -public class TestClass -{ - /// DoWork is a method in the TestClass class. - /// - /// - public static void Do$$Work(int Int1) - { - } - - static void Main() - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = -@"Summary: DoWork is a method in the TestClass class. -See also: TestClass.Main "; - Assert.Equal(expected.Replace("\r",""), response.DocComment.SummaryText); - } - - [Fact] - public async Task XmlDocumentationSummaryAndParam() - { - string content = @" -class testissue -{ - ///Checks if object is tagged with the tag. - /// The game object. - /// Name of the tag. - public static bool C$$ompare(int gameObject, string tagName) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expected = - @"Summary: Checks if object is tagged with the tag."; - Assert.Equal(expected, response.DocComment.SummaryText); - - Assert.Equal(2, response.DocComment.ParamElements.Length); - var expectedParam0 = - @"gameObject: The game object."; - Assert.Equal(expectedParam0, response.DocComment.ParamElements[0]); - var expectedParam1 = - @"tagName: Name of the tag."; - Assert.Equal(expectedParam1, response.DocComment.ParamElements[1]); - } - - [Fact] - public async Task XmlDocumentationManyTags() - { - string content = @" -class testissue -{ - ///Checks if object is tagged with the tag. - ///The game object. - ///Invoke using A.Compare(5) where A is an instance of the class testissue. - ///The element type of the array - ///Thrown when something goes wrong - ///You may have some additional information about this class here. - ///Returns an array of type . - public static T[] C$$ompare(int gameObject) - { - } -}"; - var response = await GetTypeLookUpResponse(content); - var expectedSummary = - @"Summary: Checks if object is tagged with the tag."; - Assert.Equal(expectedSummary, response.DocComment.SummaryText); - - Assert.Single(response.DocComment.ParamElements); - var expectedParam = - @"gameObject: The game object."; - Assert.Equal(expectedParam, response.DocComment.ParamElements[0]); - - var expectedExample = - @"Example: Invoke using A.Compare(5) where A is an instance of the class testissue."; - Assert.Equal(expectedExample, response.DocComment.ExampleText); - - Assert.Single(response.DocComment.TypeParamElements); - var expectedTypeParam = - @"T: The element type of the array"; - Assert.Equal(expectedTypeParam, response.DocComment.TypeParamElements[0]); - - Assert.Single(response.DocComment.Exception); - var expectedException = - @"System.Exception: Thrown when something goes wrong"; - Assert.Equal(expectedException, response.DocComment.Exception[0]); - - var expectedRemarks = - @"Remarks: You may have some additional information about this class here."; - Assert.Equal(expectedRemarks, response.DocComment.RemarksText); - - var expectedReturns = - @"Returns: Returns an array of type T ."; - Assert.Equal(expectedReturns, response.DocComment.ReturnsText); - } - } -} diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs index db5392875b..5150b7d92c 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs @@ -1,5 +1,6 @@ using System.IO; using System.Threading.Tasks; +using System.Linq; using OmniSharp.Models.TypeLookup; using OmniSharp.Options; using OmniSharp.Roslyn.CSharp.Services.Types; @@ -263,5 +264,381 @@ public async Task DisplayFormatFor_PropertySymbol_WithGenerics() var response = await GetTypeLookUpResponse(line: 15, column: 70); Assert.Equal("IDictionary> Foo.SomeDict", response.Type); } + + private async Task GetTypeLookUpResponse(string content) + { + TestFile testFile = new TestFile("dummy.cs", content); + using (var host = CreateOmniSharpHost(testFile)) + { + var requestHandler = GetRequestHandler(host); + var point = testFile.Content.GetPointFromPosition(); + var request = new TypeLookupRequest { FileName = testFile.FileName, Line = point.Line, Column = point.Offset }; + request.IncludeDocumentation = true; + + return await requestHandler.Handle(request); + } + } + + [Fact] + public async Task StructuredDocumentationRemarksText() + { + string content = @" +class testissue +{ + ///You may have some additional information about this class here. + public static bool C$$ompare(int gameObject, string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Remarks: You may have some additional information about this class here."; + Assert.Equal(expected, response.StructuredDocumentation.RemarksText); + } + + [Fact] + public async Task StructuredDocumentationSummaryText() + { + string content = @" +class testissue +{ + ///Checks if object is tagged with the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: Checks if object is tagged with the tag."; + Assert.Equal(expected, response.StructuredDocumentation.SummaryText); + } + + [Fact] + public async Task StructuredDocumentationReturnsText() + { + string content = @" +class testissue +{ + ///Returns true if object is tagged with tag. + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Returns: Returns true if object is tagged with tag."; + Assert.Equal(expected, response.StructuredDocumentation.ReturnsText); + } + + [Fact] + public async Task StructuredDocumentationExampleText() + { + string content = @" +class testissue +{ + ///Checks if object is tagged with the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Example: Checks if object is tagged with the tag."; + Assert.Equal(expected, response.StructuredDocumentation.ExampleText); + } + + [Fact] + public async Task StructuredDocumentationExceptionText() + { + string content = @" +class testissue +{ + ///A description + ///B description + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + Assert.Equal(2, response.StructuredDocumentation.Exception.Count()); + + var expectedException0 = + @"A: A description"; + Assert.Equal(expectedException0, response.StructuredDocumentation.Exception[0]); + var expectedException1 = + @"B: B description"; + Assert.Equal(expectedException1, response.StructuredDocumentation.Exception[1]); + } + + [Fact] + public async Task StructuredDocumentationParameter() + { + string content = @" +class testissue +{ + /// The game object. + /// Name of the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + Assert.Equal(2, response.StructuredDocumentation.ParamElements.Length); + + var expectedParam0 = + @"gameObject: The game object."; + Assert.Equal(expectedParam0, response.StructuredDocumentation.ParamElements[0]); + var expectedParam1 = + @"tagName: Name of the tag."; + Assert.Equal(expectedParam1, response.StructuredDocumentation.ParamElements[1]); + } + + [Fact] + public async Task StructuredDocumentationTypeParameter() + { + string content = @" +public class TestClass +{ + /// + /// Creates a new array of arbitrary type and adds the elements of incoming list to it if possible + /// + /// The element type of the array + /// The element type of the list + public static T[] m$$kArray(int n, List list) + { + return new T[n]; + } +}"; + var response = await GetTypeLookUpResponse(content); + Assert.Equal(2, response.StructuredDocumentation.TypeParamElements.Count()); + + var expected0 = + @"T: The element type of the array"; + Assert.Equal(expected0, response.StructuredDocumentation.TypeParamElements[0]); + var expected1 = + @"X: The element type of the list"; + Assert.Equal(expected1, response.StructuredDocumentation.TypeParamElements[1]); + } + + [Fact] + public async Task StructuredDocumentationValueText() + { + string content = +@"public class Employee +{ + private string _name; + + /// The Name property represents the employee's name. + /// The Name property gets/sets the value of the string field, _name. + public string Na$$me + { + } +} +"; + var response = await GetTypeLookUpResponse(content); + var expectedValue = + @"Value: The Name property gets/sets the value of the string field, _name."; + Assert.Equal(expectedValue, response.StructuredDocumentation.ValueText); + var expectedSummary = + @"Summary: The Name property represents the employee's name."; + Assert.Equal(expectedSummary, response.StructuredDocumentation.SummaryText); + } + + [Fact] + public async Task StructuredDocumentationNestedTagSee() + { + string content = @" +public class TestClass +{ + /// DoWork is a method in the TestClass class. for information about output statements. + public static void Do$$Work(int Int1) + { + } +}"; + 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."; + Assert.Equal(expected, response.StructuredDocumentation.SummaryText); + } + + [Fact] + public async Task StructuredDocumentationNestedTagParamRef() + { + string content = @" +public class TestClass +{ + /// Creates a new array of arbitrary type + /// The element type of the array + public static T[] mk$$Array(int n) + { + return new T[n]; + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: Creates a new array of arbitrary type T "; + Assert.Equal(expected, response.StructuredDocumentation.SummaryText); + } + + [Fact] + public async Task StructuredDocumentationNestedTagCode() + { + string content = @" +public class TestClass +{ + /// This sample shows how to call the method. + /// + /// class TestClass + /// { + /// static int Main() + /// { + /// return GetZero(); + /// } + /// } + /// + /// + public static int $$GetZero() + { + return 0; + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Example: This sample shows how to call the TestClass.GetZero method. + + class TestClass + { + static int Main() + { + return GetZero(); + } + } + "; + Assert.Equal(expected.Replace("\r", ""), response.StructuredDocumentation.ExampleText); + } + + [Fact] + public async Task StructuredDocumentationNestedTagPara() + { + string content = @" +public class TestClass +{ + /// DoWork is a method in the TestClass class. + /// Here's how you could make a second paragraph in a description. + /// + public static void Do$$Work(int Int1) + { + } +} + "; + var response = await GetTypeLookUpResponse(content); + var expected = +@"Summary: DoWork is a method in the TestClass class. + +Here's how you could make a second paragraph in a description."; + Assert.Equal(expected.Replace("\r", ""), response.StructuredDocumentation.SummaryText); + } + + [Fact] + public async Task StructuredDocumentationNestedTagSeeAlso() + { + string content = @" +public class TestClass +{ + /// DoWork is a method in the TestClass class. + /// + /// + public static void Do$$Work(int Int1) + { + } + + static void Main() + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = +@"Summary: DoWork is a method in the TestClass class. +See also: TestClass.Main "; + Assert.Equal(expected.Replace("\r", ""), response.StructuredDocumentation.SummaryText); + } + + [Fact] + public async Task StructuredDocumentationSummaryAndParam() + { + string content = @" +class testissue +{ + ///Checks if object is tagged with the tag. + /// The game object. + /// Name of the tag. + public static bool C$$ompare(int gameObject, string tagName) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expected = + @"Summary: Checks if object is tagged with the tag."; + Assert.Equal(expected, response.StructuredDocumentation.SummaryText); + + Assert.Equal(2, response.StructuredDocumentation.ParamElements.Length); + var expectedParam0 = + @"gameObject: The game object."; + Assert.Equal(expectedParam0, response.StructuredDocumentation.ParamElements[0]); + var expectedParam1 = + @"tagName: Name of the tag."; + Assert.Equal(expectedParam1, response.StructuredDocumentation.ParamElements[1]); + } + + [Fact] + public async Task StructuredDocumentationManyTags() + { + string content = @" +class testissue +{ + ///Checks if object is tagged with the tag. + ///The game object. + ///Invoke using A.Compare(5) where A is an instance of the class testissue. + ///The element type of the array + ///Thrown when something goes wrong + ///You may have some additional information about this class here. + ///Returns an array of type . + public static T[] C$$ompare(int gameObject) + { + } +}"; + var response = await GetTypeLookUpResponse(content); + var expectedSummary = + @"Summary: Checks if object is tagged with the tag."; + Assert.Equal(expectedSummary, response.StructuredDocumentation.SummaryText); + + Assert.Single(response.StructuredDocumentation.ParamElements); + var expectedParam = + @"gameObject: The game object."; + Assert.Equal(expectedParam, response.StructuredDocumentation.ParamElements[0]); + + var expectedExample = + @"Example: Invoke using A.Compare(5) where A is an instance of the class testissue."; + Assert.Equal(expectedExample, response.StructuredDocumentation.ExampleText); + + Assert.Single(response.StructuredDocumentation.TypeParamElements); + var expectedTypeParam = + @"T: The element type of the array"; + Assert.Equal(expectedTypeParam, response.StructuredDocumentation.TypeParamElements[0]); + + Assert.Single(response.StructuredDocumentation.Exception); + var expectedException = + @"System.Exception: Thrown when something goes wrong"; + Assert.Equal(expectedException, response.StructuredDocumentation.Exception[0]); + + var expectedRemarks = + @"Remarks: You may have some additional information about this class here."; + Assert.Equal(expectedRemarks, response.StructuredDocumentation.RemarksText); + + var expectedReturns = + @"Returns: Returns an array of type T ."; + Assert.Equal(expectedReturns, response.StructuredDocumentation.ReturnsText); + } } } From 90a236ff83a3df4b8995bce1ee624a948eeff03b Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 5 Dec 2017 16:43:27 -0800 Subject: [PATCH 13/14] Added the code for forming the comment object into the documentation comment class itself --- .../v1/TypeLookup/DocumentationComment.cs | 178 ++++++++++++++++-- .../Services/DocumentationConverter.cs | 120 +----------- 2 files changed, 164 insertions(+), 134 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index 9d329cdd0e..f6e1cb6ad7 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -1,23 +1,171 @@ -namespace OmniSharp.Models.TypeLookup +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Xml; + +namespace OmniSharp.Models.TypeLookup { public class DocumentationComment { - public string RemarksText { get; set; } - public string ExampleText { get; set; } - public string ReturnsText { get; set; } - public string SummaryText { get; set; } - public string ValueText { get; set; } - public string[ ] ParamElements { get; set; } - public string[ ] TypeParamElements { get; set; } - public string[ ] Exception { get; set; } + public string RemarksText { get; } + public string ExampleText { get; } + public string ReturnsText { get; } + public string SummaryText { get; } + public string ValueText { get; } + public string[ ] ParamElements { get; } + public string[ ] TypeParamElements { get; } + public string[ ] Exception { get; } + + private DocumentationComment(string remarksText, string exampleText, string returnsText, string summaryText, string valueText, string [ ] paramElements, string [ ] typeParamElements, string [ ] exception) + { + RemarksText = remarksText; + ExampleText = exampleText; + ReturnsText = returnsText; + SummaryText = summaryText; + ValueText = valueText; + ParamElements = paramElements; + TypeParamElements = typeParamElements; + Exception = exception; + } + + public static DocumentationComment From(string xmlDocumentation, string lineEnding) + { + var reader = new StringReader("" + xmlDocumentation + ""); + StringBuilder remarksText = new StringBuilder(); + StringBuilder exampleText = new StringBuilder(); + StringBuilder returnsText = new StringBuilder(); + StringBuilder summaryText = new StringBuilder(); + StringBuilder valueText = new StringBuilder(); + List paramElements = new List(); + List typeParamElements = new List(); + List exception = new List(); + + using (var xml = XmlReader.Create(reader)) + { + try + { + xml.Read(); + string elementName = null; + StringBuilder currentSectionBuilder = null; + do + { + if (xml.NodeType == XmlNodeType.Element) + { + elementName = xml.Name.ToLowerInvariant(); + switch (elementName) + { + case "filterpriority": + xml.Skip(); + break; + case "remarks": + remarksText.Append("Remarks: "); + currentSectionBuilder = remarksText; + break; + case "example": + exampleText.Append("Example: "); + currentSectionBuilder = exampleText; + break; + case "exception": + StringBuilder ExceptionInstance = new StringBuilder(); + ExceptionInstance.Append(GetCref(xml["cref"]).TrimEnd()); + ExceptionInstance.Append(": "); + currentSectionBuilder = ExceptionInstance; + exception.Add(ExceptionInstance); + break; + case "returns": + returnsText.Append("Returns: "); + currentSectionBuilder = returnsText; + break; + case "summary": + summaryText.Append("Summary: "); + currentSectionBuilder = summaryText; + break; + case "see": + currentSectionBuilder.Append(GetCref(xml["cref"])); + currentSectionBuilder.Append(xml["langword"]); + break; + case "seealso": + currentSectionBuilder.Append("See also: "); + currentSectionBuilder.Append(GetCref(xml["cref"])); + break; + case "paramref": + currentSectionBuilder.Append(xml["name"]); + currentSectionBuilder.Append(" "); + break; + case "param": + StringBuilder paramInstance = new StringBuilder(); + paramInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); + paramInstance.Append(": "); + currentSectionBuilder = paramInstance; + paramElements.Add(paramInstance); + break; + case "typeparamref": + currentSectionBuilder.Append(xml["name"]); + currentSectionBuilder.Append(" "); + break; + case "typeparam": + StringBuilder typeParamInstance = new StringBuilder(); + typeParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); + typeParamInstance.Append(": "); + currentSectionBuilder = typeParamInstance; + typeParamElements.Add(typeParamInstance); + break; + case "value": + valueText.Append("Value: "); + currentSectionBuilder = valueText; + break; + case "br": + case "para": + currentSectionBuilder.Append(lineEnding); + break; + } + } + else if (xml.NodeType == XmlNodeType.Text && currentSectionBuilder != null) + { + if (elementName == "code") + { + currentSectionBuilder.Append(xml.Value); + } + else + { + currentSectionBuilder.Append(TrimMultiLineString(xml.Value, lineEnding)); + } + } + } while (xml.Read()); + } + catch (Exception) + { + return null; + } + } + return new DocumentationComment(remarksText.ToString(),exampleText.ToString(),returnsText.ToString(),summaryText.ToString(),valueText.ToString(), + paramElements.Select(s => s.ToString()).ToArray(),typeParamElements.Select(s => s.ToString()).ToArray(), + exception.Select(s => s.ToString()).ToArray()); + } + + 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())); + } - public DocumentationComment() + private static string GetCref(string cref) { - RemarksText = ""; - ExampleText = ""; - ReturnsText = ""; - SummaryText = ""; - ValueText = ""; + if (cref == null || cref.Trim().Length == 0) + { + return ""; + } + if (cref.Length < 2) + { + return cref; + } + if (cref.Substring(1, 1) == ":") + { + return cref.Substring(2, cref.Length - 2) + " "; + } + return cref + " "; } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs index bab949b78c..b02153d1e9 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/DocumentationConverter.cs @@ -133,125 +133,7 @@ public static DocumentationComment GetStructuredDocumentation(string xmlDocument { if (string.IsNullOrEmpty(xmlDocumentation)) return null; - var docComment = new DocumentationComment(); - var reader = new StringReader("" + xmlDocumentation + ""); - StringBuilder remarksText = new StringBuilder(); - StringBuilder exampleText = new StringBuilder(); - StringBuilder returnsText = new StringBuilder(); - StringBuilder summaryText = new StringBuilder(); - StringBuilder valueText = new StringBuilder(); - List paramElements = new List(); - List typeParamElements = new List(); - List exception = new List(); - - using (var xml = XmlReader.Create(reader)) - { - try - { - xml.Read(); - string elementName = null; - StringBuilder currentSectionBuilder = null; - do - { - if (xml.NodeType == XmlNodeType.Element) - { - elementName = xml.Name.ToLowerInvariant(); - switch (elementName) - { - case "filterpriority": - xml.Skip(); - break; - case "remarks": - remarksText.Append("Remarks: "); - currentSectionBuilder = remarksText; - break; - case "example": - exampleText.Append("Example: "); - currentSectionBuilder = exampleText; - break; - case "exception": - StringBuilder ExceptionInstance = new StringBuilder(); - ExceptionInstance.Append(GetCref(xml["cref"]).TrimEnd()); - ExceptionInstance.Append(": "); - currentSectionBuilder = ExceptionInstance; - exception.Add(ExceptionInstance); - break; - case "returns": - returnsText.Append("Returns: "); - currentSectionBuilder = returnsText; - break; - case "summary": - summaryText.Append("Summary: "); - currentSectionBuilder = summaryText; - break; - case "see": - currentSectionBuilder.Append(GetCref(xml["cref"])); - currentSectionBuilder.Append(xml["langword"]); - break; - case "seealso": - currentSectionBuilder.Append("See also: "); - currentSectionBuilder.Append(GetCref(xml["cref"])); - break; - case "paramref": - currentSectionBuilder.Append(xml["name"]); - currentSectionBuilder.Append(" "); - break; - case "param": - StringBuilder paramInstance = new StringBuilder(); - paramInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); - paramInstance.Append(": "); - currentSectionBuilder = paramInstance; - paramElements.Add(paramInstance); - break; - case "typeparamref": - currentSectionBuilder.Append(xml["name"]); - currentSectionBuilder.Append(" "); - break; - case "typeparam": - StringBuilder typeParamInstance = new StringBuilder(); - typeParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); - typeParamInstance.Append(": "); - currentSectionBuilder = typeParamInstance; - typeParamElements.Add(typeParamInstance); - break; - case "value": - valueText.Append("Value: "); - currentSectionBuilder = valueText; - break; - case "br": - case "para": - currentSectionBuilder.Append(lineEnding); - break; - } - } - else if (xml.NodeType == XmlNodeType.Text && currentSectionBuilder != null) - { - if (elementName == "code") - { - currentSectionBuilder.Append(xml.Value); - } - else - { - currentSectionBuilder.Append(TrimMultiLineString(xml.Value, lineEnding)); - } - } - } while (xml.Read()); - } - catch (Exception) - { - return null; - } - - docComment.RemarksText = remarksText.ToString(); - docComment.ExampleText = exampleText.ToString(); - docComment.ReturnsText = returnsText.ToString(); - docComment.SummaryText = summaryText.ToString(); - docComment.ValueText = valueText.ToString(); - docComment.ParamElements = paramElements.Select(s => s.ToString()).ToArray(); - docComment.TypeParamElements = typeParamElements.Select(s => s.ToString()).ToArray(); - docComment.Exception = exception.Select(s => s.ToString()).ToArray(); - return docComment; - } + return DocumentationComment.From(xmlDocumentation, lineEnding); } } } From 18fe9c500a545838f12eae5e84b26b9fb0986fc8 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 7 Dec 2017 20:06:04 -0800 Subject: [PATCH 14/14] Changed order of the members in DocumentationComment object --- .../v1/TypeLookup/DocumentationComment.cs | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs index f6e1cb6ad7..4409c79aae 100644 --- a/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs +++ b/src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs @@ -9,37 +9,37 @@ namespace OmniSharp.Models.TypeLookup { public class DocumentationComment { + public string SummaryText { get; } + public string[] TypeParamElements { get; } + public string[] ParamElements { get; } + public string ReturnsText { get; } public string RemarksText { get; } public string ExampleText { get; } - public string ReturnsText { get; } - public string SummaryText { get; } public string ValueText { get; } - public string[ ] ParamElements { get; } - public string[ ] TypeParamElements { get; } public string[ ] Exception { get; } - private DocumentationComment(string remarksText, string exampleText, string returnsText, string summaryText, string valueText, string [ ] paramElements, string [ ] typeParamElements, string [ ] exception) + private DocumentationComment(string summaryText, string[] typeParamElements, string[] paramElements, string returnsText, string remarksText, string exampleText, string valueText, string [ ] exception) { + SummaryText = summaryText; + TypeParamElements = typeParamElements; + ParamElements = paramElements; + ReturnsText = returnsText; RemarksText = remarksText; ExampleText = exampleText; - ReturnsText = returnsText; - SummaryText = summaryText; ValueText = valueText; - ParamElements = paramElements; - TypeParamElements = typeParamElements; Exception = exception; } public static DocumentationComment From(string xmlDocumentation, string lineEnding) { var reader = new StringReader("" + xmlDocumentation + ""); + StringBuilder summaryText = new StringBuilder(); + List typeParamElements = new List(); + List paramElements = new List(); + StringBuilder returnsText = new StringBuilder(); StringBuilder remarksText = new StringBuilder(); StringBuilder exampleText = new StringBuilder(); - StringBuilder returnsText = new StringBuilder(); - StringBuilder summaryText = new StringBuilder(); StringBuilder valueText = new StringBuilder(); - List paramElements = new List(); - List typeParamElements = new List(); List exception = new List(); using (var xml = XmlReader.Create(reader)) @@ -140,9 +140,7 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi return null; } } - return new DocumentationComment(remarksText.ToString(),exampleText.ToString(),returnsText.ToString(),summaryText.ToString(),valueText.ToString(), - paramElements.Select(s => s.ToString()).ToArray(),typeParamElements.Select(s => s.ToString()).ToArray(), - exception.Select(s => s.ToString()).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)