-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node docs generator tool without MetaDataLoadContext #11950
Changes from all commits
f9093e4
354e682
3dd5ad4
05f5984
d7fab57
f3c2bd0
bf971d0
e5ea6c2
70bf7c3
67353b4
999a0b5
f8c13eb
7548c79
97d29e4
7599dfb
f1f5df5
a7b1542
cc9705e
3cc3667
e372af6
62009d5
b3443ed
f9a5627
6772242
6328716
e2e3789
9590d1a
dbe0a36
87fc191
2742147
f72a3ef
6c2d726
1383b06
8002f35
a427e28
4a10ed3
26b00dd
aa38bcd
bd8112a
a7bd10c
b65a2fd
a0c1eb2
5559e8b
1138c92
d9b74e1
259f870
2b24e18
18aa5b9
2cec9a2
0131c59
c0c0632
c76af1c
35ef80d
1bcd524
b2929ff
2a223fb
ae986dc
a4c5984
8db0547
a5d514a
9d88dd2
15cb6e6
8a84827
530b0fc
85a7d76
1faafb1
e5fd0da
6d9ae63
a0aa8cb
087bf81
e168952
c228f59
943a9df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ | |
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Dynamo.Interfaces; | ||
using Dynamo.Logging; | ||
|
||
namespace Dynamo.DocumentationBrowser | ||
{ | ||
|
@@ -18,14 +21,18 @@ public class PackageDocumentationManager : IDisposable | |
/// key: node namespace - value: file path to markdown file. | ||
/// </summary> | ||
private Dictionary<string, string> nodeDocumentationFileLookup = new Dictionary<string, string>(); | ||
|
||
/// <summary> | ||
/// Dictionary to keep track of each FileSystemWatcher created for the package node annotation directory path | ||
/// key: directory path - value: FileSystemWatcher | ||
/// </summary> | ||
private Dictionary<string, FileSystemWatcher> markdownFileWatchers = new Dictionary<string, FileSystemWatcher>(); | ||
|
||
private const string fileExtension = "*.md"; | ||
private const string VALID_DOC_FILEEXTENSION = "*.md"; | ||
private const string FALLBACK_DOC_DIRECTORY_NAME = "fallback_docs"; | ||
private static PackageDocumentationManager instance; | ||
private DirectoryInfo dynamoCoreFallbackDocPath; | ||
private DirectoryInfo hostDynamoFallbackDocPath; | ||
|
||
/// <summary> | ||
/// PackageDocManager singleton instance. | ||
|
@@ -39,17 +46,64 @@ public static PackageDocumentationManager Instance | |
} | ||
} | ||
|
||
internal Action<ILogMessage> MessageLogged; | ||
|
||
/// <summary> | ||
/// Uses the path manager to set the fallback_doc path for DynamoCore and any Host running | ||
/// </summary> | ||
/// <param name="pathManager"></param> | ||
internal void AddDynamoPaths(IPathManager pathManager) | ||
{ | ||
if (pathManager is null) | ||
{ | ||
return; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(pathManager.DynamoCoreDirectory)) | ||
{ | ||
var coreDir = new DirectoryInfo(Path.Combine(pathManager.DynamoCoreDirectory, FALLBACK_DOC_DIRECTORY_NAME)); | ||
dynamoCoreFallbackDocPath = coreDir.Exists ? coreDir : null; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(pathManager.HostApplicationDirectory)) | ||
{ | ||
var hostDir = new DirectoryInfo(Path.Combine(pathManager.HostApplicationDirectory, FALLBACK_DOC_DIRECTORY_NAME)); | ||
hostDynamoFallbackDocPath = hostDir.Exists ? hostDir : null; | ||
} | ||
} | ||
|
||
private PackageDocumentationManager() { } | ||
|
||
/// <summary> | ||
/// Retrieves the markdown node documentation file associated with the input node namespace | ||
/// </summary> | ||
/// <param name="nodeNamespace">Namespace of the node to lookup documentation for</param> | ||
/// <returns></returns> | ||
public string GetAnnotationDoc(string nodeNamespace) | ||
public string GetAnnotationDoc(string nodeNamespace, string packageName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add packageName to param list? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes @sm6srw, I had the same reaction initially, https://github.com/DynamoDS/Dynamo/pull/11725/files#r646888243 - but it's actually inside an extension, I think it's okay to break this with chance of risk and if possible it would be nice to decide and/or codify extensions being part of the API boundary or not but it will take a cross team effort / discussion I think. in this case I'm okay with the change unless there are objections. |
||
{ | ||
nodeDocumentationFileLookup.TryGetValue(nodeNamespace, out string output); | ||
return output; | ||
if(nodeDocumentationFileLookup | ||
.TryGetValue(Path.Combine(packageName, nodeNamespace), | ||
out string output)) | ||
{ | ||
return output; | ||
} | ||
|
||
FileInfo matchingDoc = null; | ||
if (hostDynamoFallbackDocPath != null) | ||
{ | ||
matchingDoc = hostDynamoFallbackDocPath.GetFiles($"{nodeNamespace}.md").FirstOrDefault(); | ||
if (matchingDoc != null) | ||
{ | ||
return matchingDoc.FullName; | ||
} | ||
} | ||
|
||
if (dynamoCoreFallbackDocPath != null) | ||
{ | ||
matchingDoc = dynamoCoreFallbackDocPath.GetFiles($"{nodeNamespace}.md").FirstOrDefault(); | ||
} | ||
|
||
return matchingDoc is null ? string.Empty : matchingDoc.FullName; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -67,7 +121,7 @@ public bool ContainsAnnotationDoc(string nodeNamespace) | |
/// Note this only works for Markdown files. | ||
/// </summary> | ||
/// <param name="package"></param> | ||
internal void AddPackageDocumentation(string packageDocumentationPath) | ||
internal void AddPackageDocumentation(string packageDocumentationPath, string packageName) | ||
{ | ||
if (string.IsNullOrWhiteSpace(packageDocumentationPath)) | ||
return; | ||
|
@@ -77,27 +131,34 @@ internal void AddPackageDocumentation(string packageDocumentationPath) | |
return; | ||
|
||
MonitorDirectory(directoryInfo); | ||
var files = directoryInfo.GetFiles(fileExtension, SearchOption.AllDirectories); | ||
TrackDocumentationFiles(files); | ||
var files = directoryInfo.GetFiles(VALID_DOC_FILEEXTENSION, SearchOption.AllDirectories); | ||
TrackDocumentationFiles(files, packageName); | ||
} | ||
|
||
private void MonitorDirectory(DirectoryInfo directoryInfo) | ||
{ | ||
if (markdownFileWatchers.ContainsKey(directoryInfo.FullName)) | ||
return; | ||
|
||
var watcher = new FileSystemWatcher(directoryInfo.FullName, fileExtension) { EnableRaisingEvents = true }; | ||
var watcher = new FileSystemWatcher(directoryInfo.FullName, VALID_DOC_FILEEXTENSION) { EnableRaisingEvents = true }; | ||
watcher.Renamed += OnFileRenamed; | ||
watcher.Deleted += OnFileDeleted; | ||
watcher.Created += OnFileCreated; | ||
markdownFileWatchers.Add(watcher.Path, watcher); | ||
} | ||
|
||
private void TrackDocumentationFiles(FileInfo[] files) | ||
private void TrackDocumentationFiles(FileInfo[] files, string packageName) | ||
{ | ||
foreach (var file in files) | ||
{ | ||
nodeDocumentationFileLookup.Add(Path.GetFileNameWithoutExtension(file.Name), file.FullName); | ||
try | ||
{ | ||
nodeDocumentationFileLookup.Add(Path.Combine(packageName,Path.GetFileNameWithoutExtension(file.Name)), file.FullName); | ||
} | ||
catch (Exception e) | ||
{ | ||
LogWarning(e.Message, WarningLevel.Error); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -110,20 +171,28 @@ private void OnFileDeleted(object sender, FileSystemEventArgs e) | |
{ | ||
var fileName = Path.GetFileNameWithoutExtension(e.Name); | ||
if (nodeDocumentationFileLookup.ContainsKey(fileName)) | ||
{ | ||
nodeDocumentationFileLookup.Remove(fileName); | ||
} | ||
} | ||
|
||
private void OnFileRenamed(object sender, RenamedEventArgs e) | ||
{ | ||
var oldFileName = Path.GetFileNameWithoutExtension(e.OldName); | ||
if (nodeDocumentationFileLookup.ContainsKey(oldFileName)) | ||
{ | ||
nodeDocumentationFileLookup.Remove(oldFileName); | ||
} | ||
|
||
var newFileName = Path.GetFileNameWithoutExtension(e.Name); | ||
if (!nodeDocumentationFileLookup.ContainsKey(newFileName)) | ||
{ | ||
nodeDocumentationFileLookup.Add(newFileName, e.FullPath); | ||
} | ||
} | ||
|
||
private void LogWarning(string msg, WarningLevel level) => this.MessageLogged?.Invoke(LogMessage.Warning(msg, level)); | ||
|
||
public void Dispose() | ||
{ | ||
foreach (var watcher in markdownFileWatchers.Values) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sm6srw to answer your question about how useful this is - it actually uses the
DynamoHostPath
property as the root - which can be set using a startupconfiguration - for example, DynamoRevit sets this to the location of theDynamoRevit.dll
entry point.so I think this is pretty useful.