diff --git a/src/Core/SharpDox.Core/Config/CoreConfigSection.cs b/src/Core/SharpDox.Core/Config/CoreConfigSection.cs index 2b8fcccb..dd478c3d 100644 --- a/src/Core/SharpDox.Core/Config/CoreConfigSection.cs +++ b/src/Core/SharpDox.Core/Config/CoreConfigSection.cs @@ -185,7 +185,7 @@ public SDPath OutputPath [Name(typeof(CoreStrings), "DocLanguage")] public string DocLanguage { - get { return _docLanguage; } + get { return string.IsNullOrEmpty(_docLanguage) ? "en" : _docLanguage; } set { if (_docLanguage != value) diff --git a/src/Core/SharpDox.Model/Documentation/Token/SDTokenList.cs b/src/Core/SharpDox.Model/Documentation/Token/SDTokenList.cs index d2995ff5..52c39872 100644 --- a/src/Core/SharpDox.Model/Documentation/Token/SDTokenList.cs +++ b/src/Core/SharpDox.Model/Documentation/Token/SDTokenList.cs @@ -24,7 +24,7 @@ public class SDTokenList : List break; } } - return text; + return text.Trim(); } public SDTemplate ToMarkdown(Dictionary tokens) @@ -59,7 +59,7 @@ public SDTemplate ToMarkdown(Dictionary tokens) break; } } - return new SDTemplate(text, tokens); + return new SDTemplate(text.Trim(), tokens); } } } diff --git a/src/Core/SharpDox.Model/Repository/SDRegion.cs b/src/Core/SharpDox.Model/Repository/SDRegion.cs index 5668fb22..2112325a 100644 --- a/src/Core/SharpDox.Model/Repository/SDRegion.cs +++ b/src/Core/SharpDox.Model/Repository/SDRegion.cs @@ -41,7 +41,43 @@ public class SDRegion /// /// - /// Gets or sets the file within the region is defined. + /// Gets or sets the start line of the region. + /// + /// + /// + /// + /// Setzt oder liefert die Startzeile der Region. + /// + /// + public int StartLine { get; set; } + + /// + /// + /// Gets or sets the end line of the region. + /// + /// + /// + /// + /// Setzt oder liefert die Endzeile der Region. + /// + /// + public int EndLine { get; set; } + + /// + /// + /// Gets or sets the file path within the region is defined. + /// + /// + /// + /// + /// Setzt oder liefert den Pfad der Datei in der die Region definiert ist. + /// + /// + public string FilePath { get; set; } + + /// + /// + /// Gets or sets the file name within the region is defined. /// /// /// @@ -50,5 +86,17 @@ public class SDRegion /// /// public string Filename { get; set; } + + /// + /// + /// Gets or sets the content of the file. + /// + /// + /// + /// + /// Setzt oder liefert den Inhalt der Datei. + /// + /// + public string Content { get; set; } } } diff --git a/src/Core/SharpDox.Sdk/Config/Attributes/NameAttribute.cs b/src/Core/SharpDox.Sdk/Config/Attributes/NameAttribute.cs index 5427adca..8cdcc091 100644 --- a/src/Core/SharpDox.Sdk/Config/Attributes/NameAttribute.cs +++ b/src/Core/SharpDox.Sdk/Config/Attributes/NameAttribute.cs @@ -13,8 +13,8 @@ namespace SharpDox.Sdk.Config.Attributes /// [Name(typeof(CoreStrings), "ProjectName")] /// public string ProjectName /// { - /// get { [...] } - /// set { [...] } + /// get { /* ... */ } + /// set { /* ... */ } /// } /// /// @@ -31,8 +31,8 @@ namespace SharpDox.Sdk.Config.Attributes /// [Name(typeof(CoreStrings), "ProjectName")] /// public string ProjectName /// { - /// get { [...] } - /// set { [...] } + /// get { /* ... */ } + /// set { /* ... */ } /// } /// /// diff --git a/src/Core/SharpDox.Sdk/SDPath.cs b/src/Core/SharpDox.Sdk/SDPath.cs index 18206696..1d50c38f 100644 --- a/src/Core/SharpDox.Sdk/SDPath.cs +++ b/src/Core/SharpDox.Sdk/SDPath.cs @@ -53,7 +53,7 @@ public void UpdatePath(string fullPath, string basePath) public static implicit operator string (SDPath path) { - return path != null ? path.ResolvePath() : null; + return path?.ResolvePath(); } public static implicit operator SDPath (string fullPath) diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/DocumentationParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/DocumentationParser.cs index fe9b792f..d8f4487d 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/DocumentationParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/DocumentationParser.cs @@ -4,6 +4,10 @@ using System.Linq; using System.Xml.Linq; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Formatting; +using Microsoft.CodeAnalysis.MSBuild; +using Microsoft.CodeAnalysis.Options; using SharpDox.Model.Documentation; using SharpDox.Model.Documentation.Token; using SharpDox.Model.Repository; @@ -107,7 +111,7 @@ private SDTokenList ParseContentTokens(XElement xmlElement, bool multilang) content.Add(new SDToken { Role = SDTokenRole.Text, - Text = element.ToString().Trim() + Text = element.ToString() }); } @@ -128,7 +132,9 @@ private SDTokenList ParseContentTokens(XElement xmlElement, bool multilang) content.Add(new SDToken { Role = SDTokenRole.ParamRef, Text = nodeElement.Attribute("name")?.Value }); break; case "code": - content.Add(new SDCodeToken { Text = nodeElement.Value, IsInline = false }); + var workspace = MSBuildWorkspace.Create(); + var formattedResult = Formatter.Format(CSharpSyntaxTree.ParseText(nodeElement.Value, CSharpParseOptions.Default).GetRoot(), workspace); + content.Add(new SDCodeToken { Text = formattedResult.ToString(), IsInline = false }); break; case "c": content.Add(new SDCodeToken { Text = nodeElement.Value, IsInline = true }); diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/EventParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/EventParser.cs index d0719a7e..7501981a 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/EventParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/EventParser.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.IO; using Microsoft.CodeAnalysis; using SharpDox.Model.Repository; using SharpDox.Model.Repository.Members; @@ -32,12 +33,22 @@ internal void ParseEvents(SDType sdType, INamedTypeSymbol typeSymbol) private SDEvent GetParsedEvent(IEventSymbol eve) { + var syntaxReference = eve.DeclaringSyntaxReferences.Any() ? eve.DeclaringSyntaxReferences.Single() : null; var sdEvent = new SDEvent(eve.GetIdentifier()) { Name = eve.Name, DeclaringType = _typeRefParser.GetParsedTypeReference(eve.ContainingType), Accessibility = eve.DeclaredAccessibility.ToString().ToLower(), - Documentations = DocumentationParser.ParseDocumentation(eve) + Documentations = DocumentationParser.ParseDocumentation(eve), + Region = syntaxReference != null ? new SDRegion + { + Start = syntaxReference.Span.Start, + StartLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).StartLinePosition.Line + 1, + EndLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).EndLinePosition.Line + 1, + End = syntaxReference.Span.End, + FilePath = syntaxReference.SyntaxTree.FilePath, + Filename = Path.GetFileName(syntaxReference.SyntaxTree.FilePath) + } : null }; ParserOptions.SDRepository.AddMember(sdEvent); diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/FieldParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/FieldParser.cs index de9661e7..c36ed9e1 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/FieldParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/FieldParser.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.IO; +using System.Linq; using Microsoft.CodeAnalysis; using SharpDox.Model.Repository; using SharpDox.Model.Repository.Members; @@ -32,6 +33,7 @@ internal void ParseFields(SDType sdType, INamedTypeSymbol typeSymbol) private SDField GetParsedField(IFieldSymbol field) { + var syntaxReference = field.DeclaringSyntaxReferences.Any() ? field.DeclaringSyntaxReferences.Single() : null; var sdField = new SDField(field.GetIdentifier()) { Name = field.Name, @@ -41,7 +43,16 @@ private SDField GetParsedField(IFieldSymbol field) ConstantValue = field.ConstantValue != null ? field.ConstantValue.ToString() : string.Empty, IsConst = field.IsConst, IsReadonly = field.IsReadOnly, - Documentations = DocumentationParser.ParseDocumentation(field) + Documentations = DocumentationParser.ParseDocumentation(field), + Region = syntaxReference != null ? new SDRegion + { + Start = syntaxReference.Span.Start, + End = syntaxReference.Span.End, + StartLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).StartLinePosition.Line + 1, + EndLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).EndLinePosition.Line + 1, + FilePath = syntaxReference.SyntaxTree.FilePath, + Filename = Path.GetFileName(syntaxReference.SyntaxTree.FilePath) + } : null }; ParserOptions.SDRepository.AddMember(sdField); diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodCallParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodCallParser.cs index 6af9ade0..83358b32 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodCallParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodCallParser.cs @@ -18,7 +18,7 @@ internal void ParseMethodCalls() foreach (var sdMethod in sdType.Methods) { HandleOnItemParseStart(sdMethod.Name); - var fileId = ParserOptions.CodeSolution.GetDocumentIdsWithFilePath(sdMethod.Region.Filename).Single(); + var fileId = ParserOptions.CodeSolution.GetDocumentIdsWithFilePath(sdMethod.Region.FilePath).Single(); var file = ParserOptions.CodeSolution.GetDocument(fileId); var syntaxTree = file.GetSyntaxTreeAsync().Result; diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodParser.cs index 613cd388..f02e8f5f 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/MethodParser.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.CodeAnalysis; using SharpDox.Model; @@ -75,7 +76,10 @@ private SDMethod GetParsedMethod(IMethodSymbol method, bool isCtor) { Start = syntaxReference.Span.Start, End = syntaxReference.Span.End, - Filename = syntaxReference.SyntaxTree.FilePath + StartLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).StartLinePosition.Line + 1, + EndLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).EndLinePosition.Line + 1, + FilePath = syntaxReference.SyntaxTree.FilePath, + Filename = Path.GetFileName(syntaxReference.SyntaxTree.FilePath) } : null }; diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/NamespaceParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/NamespaceParser.cs index f11b3a11..f3beed9b 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/NamespaceParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/NamespaceParser.cs @@ -38,14 +38,14 @@ internal void ParseProjectNamespacesRecursively(INamespaceSymbol namespaceSymbol private SDNamespace GetParsedNamespace(INamespaceSymbol namespaceSymbol) { - var descriptionFiles = _descriptionFiles.Where(d => Path.GetFileName(d).ToLower().Contains(namespaceSymbol.Name.ToLower() + ".sdnd")); + var descriptionFiles = _descriptionFiles.Where(d => Path.GetFileName(d).ToLower().Contains(namespaceSymbol.ToDisplayString().ToLower() + ".sdnd")); var descriptions = new SDLanguageItemCollection(); foreach (var file in descriptionFiles) { - if (!string.IsNullOrEmpty(namespaceSymbol.Name.Trim())) + if (!string.IsNullOrEmpty(namespaceSymbol.ToDisplayString().Trim())) { - var splitted = Path.GetFileName(file).ToLower().Replace(namespaceSymbol.Name.ToLower(), " ").Split('.'); + var splitted = Path.GetFileName(file).ToLower().Replace(namespaceSymbol.ToDisplayString().ToLower(), " ").Split('.'); if (splitted.Length > 0 && splitted[0].Length == 2 && CultureInfo.GetCultures(CultureTypes.AllCultures).Any(c => c.TwoLetterISOLanguageName == splitted[0])) { descriptions.Add(splitted[0], new SDTemplate(File.ReadAllText(file), ParserOptions.Tokens)); diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/PropertyParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/PropertyParser.cs index 199c8953..f4ca748c 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/PropertyParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/PropertyParser.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.IO; +using System.Linq; using Microsoft.CodeAnalysis; using SharpDox.Model.Repository; using SharpDox.Model.Repository.Members; @@ -32,6 +33,7 @@ internal void ParseProperties(SDType sdType, INamedTypeSymbol typeSymbol) private SDProperty GetParsedProperty(IPropertySymbol property) { + var syntaxReference = property.DeclaringSyntaxReferences.Any() ? property.DeclaringSyntaxReferences.Single() : null; var sdProperty = new SDProperty(property.GetIdentifier()) { Name = property.Name, @@ -43,7 +45,16 @@ private SDProperty GetParsedProperty(IPropertySymbol property) IsAbstract = property.IsAbstract, IsVirtual = property.IsVirtual, IsOverride = property.IsOverride, - Documentations = DocumentationParser.ParseDocumentation(property) + Documentations = DocumentationParser.ParseDocumentation(property), + Region = syntaxReference != null ? new SDRegion + { + Start = syntaxReference.Span.Start, + End = syntaxReference.Span.End, + StartLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).StartLinePosition.Line + 1, + EndLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).EndLinePosition.Line + 1, + FilePath = syntaxReference.SyntaxTree.FilePath, + Filename = Path.GetFileName(syntaxReference.SyntaxTree.FilePath) + } : null }; ParserOptions.SDRepository.AddMember(sdProperty); diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/TypeParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/TypeParser.cs index 3ab7d224..263a4bb8 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/TypeParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/TypeParser.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.CodeAnalysis; using SharpDox.Model.Repository; @@ -49,6 +50,7 @@ private void ParseTheProjectType(INamedTypeSymbol typeSymbol) else // already parsed as stranger { sdType.Namespace = ParserOptions.SDRepository.GetNamespaceByIdentifier(typeSymbol.ContainingNamespace.GetIdentifier()); + sdType.Regions = GetRegions(typeSymbol); sdType.IsProjectStranger = false; if(!sdNamespace.Types.Contains(sdType)) sdNamespace.Types.Add(sdType); @@ -126,18 +128,29 @@ private SDType CreateSDType(INamedTypeSymbol typeSymbol, SDNamespace sdNamespace IsProjectStranger = false, Kind = typeSymbol.TypeKind.ToString().ToLower() }; - + sdType.Regions = GetRegions(typeSymbol); + + return sdType; + } + + private List GetRegions(INamedTypeSymbol typeSymbol) + { + var regions = new List(); foreach (var reference in typeSymbol.DeclaringSyntaxReferences.ToList()) { var region = new SDRegion { Start = reference.Span.Start, End = reference.Span.End, - Filename = reference.SyntaxTree.FilePath + StartLine = reference.SyntaxTree.GetLineSpan(reference.Span).StartLinePosition.Line + 1, + EndLine = reference.SyntaxTree.GetLineSpan(reference.Span).EndLinePosition.Line + 1, + FilePath = reference.SyntaxTree.FilePath, + Filename = Path.GetFileName(reference.SyntaxTree.FilePath), + Content = File.ReadAllText(reference.SyntaxTree.FilePath) }; - sdType.Regions.Add(region); + regions.Add(region); } - return sdType; + return regions; } } } diff --git a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/UseParser.cs b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/UseParser.cs index 5b4ca2bf..87e2e999 100644 --- a/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/UseParser.cs +++ b/src/Libraries/SharpDox.Build.Roslyn/Parser/ProjectParser/UseParser.cs @@ -33,7 +33,7 @@ private void ResolveCall(SDNode call) var calledType = _sdRepository.GetTypeByIdentifier(targetNode.CalledType.Identifier); var callerType = _sdRepository.GetTypeByIdentifier(targetNode.CallerType.Identifier); - if (calledType != null && callerType != null && calledType.Identifier != callerType.Identifier) + if (calledType != null && callerType != null && calledType.Identifier != callerType.Identifier && !calledType.IsProjectStranger && !callerType.IsProjectStranger) { if (!calledType.IsProjectStranger && calledType.UsedBy.SingleOrDefault(u => u.Identifier == callerType.Identifier) == null) calledType.UsedBy.Add(callerType);