Skip to content

Commit

Permalink
allow setting the base path for code sources (dotnet#2663)
Browse files Browse the repository at this point in the history
* WIP: allow setting the base path for code sources

* Fix bug
  • Loading branch information
vicancy authored May 4, 2018
1 parent c38bf58 commit cf61d69
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ExtractMetadataOptions

public Dictionary<string, string> MSBuildProperties { get; set; }

public string CodeSourceBasePath { get; set; }

[JsonIgnore]
public IReadOnlyDictionary<Compilation, IEnumerable<IMethodSymbol>> RoslynExtensionMethods { get; set; }

Expand All @@ -29,7 +31,9 @@ public bool HasChanged(IncrementalCheck check, bool careMSBuildProperties)
check.BuildInfo.Options.PreserveRawInlineComments != PreserveRawInlineComments ||
check.BuildInfo.Options.FilterConfigFile != FilterConfigFile ||
check.IsFileModified(FilterConfigFile) ||
(careMSBuildProperties && check.MSBuildPropertiesUpdated(MSBuildProperties));
(careMSBuildProperties && check.MSBuildPropertiesUpdated(MSBuildProperties)) ||
check.BuildInfo.Options.CodeSourceBasePath != CodeSourceBasePath
;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface ITripleSlashCommentParserContext
Action<string, string> AddReferenceDelegate { get; set; }
Func<string, CRefTarget> ResolveCRef { get; }
SourceDetail Source { get; set; }
string CodeSourceBasePath { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ private void ResolveCodeSource(XDocument doc, ITripleSlashCommentParserContext c
var path = source.Value;
if (!Path.IsPathRooted(path))
{
string currentFilePath = context.Source.Remote != null ? Path.Combine(EnvironmentContext.BaseDirectory, context.Source.Remote.RelativePath) : context.Source.Path;
var directory = Path.GetDirectoryName(currentFilePath);
path = Path.Combine(directory, path);
var basePath = !string.IsNullOrEmpty(context.CodeSourceBasePath) ? context.CodeSourceBasePath : Path.GetDirectoryName(Path.Combine(EnvironmentContext.BaseDirectory, context.Source.Path));

path = Path.Combine(basePath, path);
}

ResolveCodeSource(node, path, region?.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public class TripleSlashCommentParserContext : ITripleSlashCommentParserContext
public Func<string, CRefTarget> ResolveCRef { get; set; }

public SourceDetail Source { get; set; }

public string CodeSourceBasePath { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public MetadataItem Extract(ExtractMetadataOptions options)
SymbolVisitorAdapter visitor;
if (_compilation.Language == "Visual Basic")
{
visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.VB, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.VB, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods, options.CodeSourceBasePath);
}
else if (_compilation.Language == "C#")
{
visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.CSharp, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.CSharp, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods, options.CodeSourceBasePath);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public class SymbolVisitorAdapter
private readonly IReadOnlyDictionary<Compilation, IEnumerable<IMethodSymbol>> _extensionMethods;
private readonly Compilation _currentCompilation;
private readonly CompilationReference _currentCompilationRef;
private readonly string _codeSourceBasePath;

#endregion

#region Constructor

public SymbolVisitorAdapter(YamlModelGenerator generator, SyntaxLanguage language, Compilation compilation, bool preserveRawInlineComments = false, string filterConfigFile = null, IReadOnlyDictionary<Compilation, IEnumerable<IMethodSymbol>> extensionMethods = null)
public SymbolVisitorAdapter(YamlModelGenerator generator, SyntaxLanguage language, Compilation compilation, bool preserveRawInlineComments = false, string filterConfigFile = null, IReadOnlyDictionary<Compilation, IEnumerable<IMethodSymbol>> extensionMethods = null, string codeSourceBasePath = null)
{
_generator = generator;
Language = language;
Expand All @@ -44,6 +45,7 @@ public SymbolVisitorAdapter(YamlModelGenerator generator, SyntaxLanguage languag
var configFilterRule = ConfigFilterRule.LoadWithDefaults(filterConfigFile);
FilterVisitor = new DefaultFilterVisitor().WithConfig(configFilterRule).WithCache();
_extensionMethods = extensionMethods != null ? extensionMethods.ToDictionary(p => p.Key, p => p.Value.Where(e => FilterVisitor.CanVisitApi(e))) : new Dictionary<Compilation, IEnumerable<IMethodSymbol>>();
_codeSourceBasePath = codeSourceBasePath;
}

#endregion
Expand Down Expand Up @@ -772,7 +774,8 @@ private ITripleSlashCommentParserContext GetTripleSlashCommentParserContext(Meta
{
AddReferenceDelegate = GetAddReferenceDelegate(item),
PreserveRawInlineComments = preserve,
Source = item.Source
Source = item.Source,
CodeSourceBasePath = _codeSourceBasePath
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ExtractMetadataInputModel

public string GlobalNamespaceId { get; set; }

public string CodeSourceBasePath { get; set; }

public Dictionary<string, string> MSBuildProperties { get; set; }

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public ExtractMetadataWorker(ExtractMetadataInputModel input)
PreserveRawInlineComments = input.PreserveRawInlineComments,
FilterConfigFile = input.FilterConfigFile != null ? new FileInformation(input.FilterConfigFile).NormalizedPath : null,
MSBuildProperties = msbuildProperties,
CodeSourceBasePath = input.CodeSourceBasePath
};

_useCompatibilityFileName = input.UseCompatibilityFileName;
Expand Down
3 changes: 3 additions & 0 deletions src/docfx/Models/MetadataJsonItemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ public class MetadataJsonItemConfig

[JsonProperty("disableGitFeatures")]
public bool DisableGitFeatures { get; set; }

[JsonProperty("codeSourceBasePath")]
public string CodeSourceBasePath { get; set; }
}
}
1 change: 1 addition & 0 deletions src/docfx/SubCommands/MetadataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private ExtractMetadataInputModel ConvertToInputModel(MetadataJsonItemConfig con
UseCompatibilityFileName = configModel?.UseCompatibilityFileName ?? false,
MSBuildProperties = configModel?.MSBuildProperties,
OutputFolder = outputFolder,
CodeSourceBasePath = configModel?.CodeSourceBasePath
};

var expandedFileMapping = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects);
Expand Down
1 change: 1 addition & 0 deletions tools/MergeDeveloperComments/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ internal sealed class TripleSlashCommentParserContext : ITripleSlashCommentParse
public Func<string, CRefTarget> ResolveCRef { get; set; }
public bool PreserveRawInlineComments { get; set; }
public SourceDetail Source { get; set; }
public string CodeSourceBasePath { get; set; }
}

#endregion
Expand Down

0 comments on commit cf61d69

Please sign in to comment.