Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private set
if (value != oldLink)
{
UnsubscribeMdWatcher();
WatchMdFile(value.OriginalString);
WatchMdFile(value?.OriginalString, CurrentGraphName, CurrentPackageName);
}

this.link = value;
Expand Down Expand Up @@ -298,7 +298,7 @@ private string GetGraphLinkFromMDLocation(Uri link,bool isOwnedByPackage)
}
}

private bool IsBuiltInDocPath(string mdLink)
internal bool IsBuiltInDocPath(string mdLink)
{
if (string.IsNullOrEmpty(mdLink)) return false;

Expand Down Expand Up @@ -327,13 +327,12 @@ private bool IsBuiltInDocPath(string mdLink)
}
}

private void WatchMdFile(string mdLink)
private void WatchMdFile(string mdLink, string nodeNamespace, string packageName)
{
if (string.IsNullOrWhiteSpace(mdLink))
return;

var fileName = Path.GetFileNameWithoutExtension(mdLink);
if (!packageManagerDoc.ContainsAnnotationDoc(fileName))
if (!packageManagerDoc.ContainsAnnotationDoc(nodeNamespace ?? string.Empty, packageName ?? string.Empty))
return;

markdownFileWatcher = new FileSystemWatcher(Path.GetDirectoryName(mdLink))
Expand Down Expand Up @@ -493,7 +492,7 @@ internal void InsertGraph()
internal delegate void InsertDocumentationLinkEventHandler(object sender, InsertDocumentationLinkEventArgs e);
internal event InsertDocumentationLinkEventHandler HandleInsertFile;

private string DynamoGraphFromMDFilePath(string path, bool IsOwnedByPackage)
internal string DynamoGraphFromMDFilePath(string path, bool IsOwnedByPackage)
Comment thread
johnpierson marked this conversation as resolved.
{
path = HttpUtility.UrlDecode(path);
if (!IsOwnedByPackage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class PackageDocumentationManager : IDisposable
/// </summary>
private Dictionary<string, FileSystemWatcher> markdownFileWatchers = new Dictionary<string, FileSystemWatcher>();

/// <summary>
/// Map of package name to its node documentation directory path. Used to resolve hash-named doc files in packages.
/// </summary>
private Dictionary<string, string> packageDocDirectories = new Dictionary<string, string>();

private const string VALID_DOC_FILEEXTENSION = "*.md";
private const string FALLBACK_DOC_DIRECTORY_NAME = "fallback_docs";
private static PackageDocumentationManager instance;
Expand Down Expand Up @@ -97,8 +102,24 @@ public string GetAnnotationDoc(string nodeNamespace, string packageName)
}

var shortName = Hash.GetHashFilenameFromString(nodeNamespace);

FileInfo matchingDoc = null;

// Try hash-named file in package doc directory (packages may use hash filenames for long paths)
if (!string.IsNullOrEmpty(packageName) && packageDocDirectories.TryGetValue(packageName, out var pkgDocPath))
{
var pkgDir = new DirectoryInfo(pkgDocPath);
if (pkgDir.Exists)
{
matchingDoc = pkgDir.GetFiles($"{shortName}.md", SearchOption.AllDirectories).FirstOrDefault();
if (matchingDoc != null)
{
// Cache so future lookups and file watcher logic resolve correctly
nodeDocumentationFileLookup[Path.Combine(packageName, nodeNamespace)] = matchingDoc.FullName;
return matchingDoc.FullName;
}
}
}

if (hostDynamoFallbackDocPath != null)
{
matchingDoc = hostDynamoFallbackDocPath.GetFiles($"{shortName}.md").FirstOrDefault() ??
Expand All @@ -119,13 +140,14 @@ public string GetAnnotationDoc(string nodeNamespace, string packageName)
}

/// <summary>
/// Checks if the nodeNamespace has a documentation markdown associated.
/// Checks if the node has a documentation markdown associated (by direct lookup or hash-named file in package/fallback).
/// </summary>
/// <param name="nodeNamespace"></param>
/// <returns></returns>
public bool ContainsAnnotationDoc(string nodeNamespace)
/// <param name="nodeNamespace">Namespace (e.g. minimum qualified name) of the node.</param>
/// <param name="packageName">Package name if the node is from a package; otherwise empty.</param>
/// <returns>True if documentation can be resolved for this node.</returns>
public bool ContainsAnnotationDoc(string nodeNamespace, string packageName)
{
return nodeDocumentationFileLookup.ContainsKey(nodeNamespace);
return !string.IsNullOrEmpty(GetAnnotationDoc(nodeNamespace, packageName));
}

/// <summary>
Expand All @@ -143,6 +165,7 @@ internal void AddPackageDocumentation(string packageDocumentationPath, string pa
return;

MonitorDirectory(directoryInfo);
packageDocDirectories[packageName] = directoryInfo.FullName;
var files = directoryInfo.GetFiles(VALID_DOC_FILEEXTENSION, SearchOption.AllDirectories);
TrackDocumentationFiles(files, packageName);
}
Expand All @@ -165,7 +188,8 @@ private void TrackDocumentationFiles(FileInfo[] files, string packageName)
{
try
{
nodeDocumentationFileLookup.Add(Path.Combine(packageName,Path.GetFileNameWithoutExtension(file.Name)), file.FullName);
var key = Path.Combine(packageName, Path.GetFileNameWithoutExtension(file.Name));
nodeDocumentationFileLookup[key] = file.FullName;
}
catch (Exception e)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/DocumentationBrowserViewExtension/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,31 @@
<data name="MessageHeading" xml:space="preserve">
<value>Message</value>
</data>
<data name="NodeHelpAuditCompleted" xml:space="preserve">
<value>Node help audit CSV saved to: {0}</value>
</data>
<data name="NodeHelpAuditCsvHeader" xml:space="preserve">
<value>Library,Category,Name,FullName,MissingMd,MissingDyn,MissingImage,MarkdownPath,SampleGraphPath,ImagePaths</value>
</data>
<data name="NodeHelpAuditEntryFailed" xml:space="preserve">
<value>Node help audit skipped '{0}': {1}</value>
</data>
<data name="NodeHelpAuditFailed" xml:space="preserve">
<value>Node help audit failed: {0}</value>
</data>
<data name="NodeHelpAuditManagerMissing" xml:space="preserve">
<value>Node help audit failed: documentation manager is not available.</value>
</data>
<data name="NodeHelpAuditNoEntries" xml:space="preserve">
<value>Node help audit found no search entries to process.</value>
</data>
<data name="NodeHelpAuditNotReady" xml:space="preserve">
<value>Node help audit is not available yet.</value>
</data>
<data name="NodeHelpAuditSaveDialogFilter" xml:space="preserve">
<value>CSV (*.csv)|*.csv</value>
</data>
<data name="NodeHelpAuditSaveDialogTitle" xml:space="preserve">
<value>Save Node Help Audit CSV</value>
</data>
</root>
10 changes: 10 additions & 0 deletions src/DynamoCoreWpf/Extensions/ViewLoadedParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public event RequestOpenDocumentationLinkHandler RequestOpenDocumentationLink
}
}

/// <summary>
/// Event raised when the user requests a node help documentation audit (e.g. from Debug menu).
/// Extensions (e.g. Documentation Browser) should subscribe to this event to run the audit.
/// </summary>
public event Action NodeHelpAuditRequested
{
add => dynamoViewModel.NodeHelpAuditRequested += value;
remove => dynamoViewModel.NodeHelpAuditRequested -= value;
}

/// <summary>
/// Request to open a view extension in the side panel by name.
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ Don't worry, you'll have the option to save your work.</value>
<value>Debug _Modes</value>
<comment>Debug menu | Show debug modes</comment>
</data>
<data name="DynamoViewDebugMenuAuditNodeHelpDocs" xml:space="preserve">
<value>Audit Node Help Docs (CSV)</value>
<comment>Debug menu | Audit node help documentation</comment>
</data>
<data name="DynamoViewEditMenu" xml:space="preserve">
<value>_Edit</value>
<comment>Edit menu</comment>
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@
<value>Debug _Modes</value>
<comment>Debug menu | Show debug modes</comment>
</data>
<data name="DynamoViewDebugMenuAuditNodeHelpDocs" xml:space="preserve">
<value>Audit Node Help Docs (CSV)</value>
<comment>Debug menu | Audit node help documentation</comment>
</data>
<data name="DynamoViewEditMenu" xml:space="preserve">
<value>_Edit</value>
<comment>Edit menu</comment>
Expand Down
10 changes: 10 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public virtual void OnRequestOpenDocumentationLink(OpenDocumentationLinkEventArg
RequestOpenDocumentationLink?.Invoke(e);
}

/// <summary>
/// Event raised when the user requests a node help documentation audit (e.g. from Debug menu).
/// The Documentation Browser extension subscribes to this event to run the audit.
/// </summary>
internal event Action NodeHelpAuditRequested;
internal virtual void OnNodeHelpAuditRequested()
{
NodeHelpAuditRequested?.Invoke();
}

public event Action RequestShowHideSidebar;
public virtual void OnShowHideSidebar(bool show)
{
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@
Header="{x:Static p:Resources.DynamoViewDebugMenuDumpNodeIcons}"
IsEnabled="True" />
</MenuItem>
<MenuItem Name="AuditNodeHelpDocs"
Click="OnAuditNodeHelpDocsClick"
Header="{x:Static p:Resources.DynamoViewDebugMenuAuditNodeHelpDocs}"
IsCheckable="False" />
<MenuItem Name="DebugModes"
Click="OnDebugModesClick"
Header="{x:Static p:Resources.DynamoViewDebugMenuDebugModes}"
Expand Down
5 changes: 5 additions & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,11 @@ private void OnDebugModesClick(object sender, RoutedEventArgs e)
debugModesWindow.ShowDialog();
}

private void OnAuditNodeHelpDocsClick(object sender, RoutedEventArgs e)
{
dynamoViewModel.OnNodeHelpAuditRequested();
}

private void OnPreferencesWindowClick(object sender, RoutedEventArgs e)
{
preferencesWindow = new PreferencesView(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ public void CanGetNodeDocumentationMarkdownFromPackageDocumentationManager()
var nodeWithoutDocumentation = "Package.Package.Package";

// Assert
Assert.That(PackageDocumentationManager.Instance.ContainsAnnotationDoc(Path.Combine(packageName, nodeWithDocumentation)));
Assert.That(!PackageDocumentationManager.Instance.ContainsAnnotationDoc(Path.Combine(packageName, nodeWithoutDocumentation)));
Assert.That(PackageDocumentationManager.Instance.ContainsAnnotationDoc(nodeWithDocumentation, packageName));
Assert.That(!PackageDocumentationManager.Instance.ContainsAnnotationDoc(nodeWithoutDocumentation, packageName));
}

[Test]
Expand Down
Loading