Skip to content

Commit 858f83c

Browse files
d1820claude
andcommitted
Walk up ancestor nodes to find documentable node at cursor position
FindDocumentableNode now uses AncestorsAndSelf() so types where FindNode returns a child node (EventField, ConversionOperator, etc.) correctly resolve to their parent declaration. Existing types are unaffected since they match on the first (self) check. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3010ad1 commit 858f83c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

CodeDocumentor2026/Commands/Context/CodeDocumentorEditorCommand.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.Design;
4+
using System.Linq;
35
using System.Threading.Tasks;
46
using CodeDocumentor.Common.Interfaces;
57
using CodeDocumentor2026.Extensions;
@@ -331,13 +333,11 @@ private SyntaxNode FindDocumentableNode(SyntaxNode root, int line, int column)
331333
// Find the node at the exact cursor position
332334
var nodeAtPosition = root.FindNode(Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(position, position));
333335

334-
// Use the service to determine if it's documentable - don't traverse up
335-
if (_commentBuilderService.IsDocumentableNode(nodeAtPosition))
336-
{
337-
return nodeAtPosition;
338-
}
339-
340-
return null;
336+
// Walk up from the found node to find the nearest documentable ancestor.
337+
// AncestorsAndSelf() checks the node itself first, so existing behavior is preserved
338+
// for types where FindNode already returns the declaration node directly.
339+
return nodeAtPosition.AncestorsAndSelf()
340+
.FirstOrDefault(n => _commentBuilderService.IsDocumentableNode(n));
341341
}
342342
catch (Exception ex)
343343
{

0 commit comments

Comments
 (0)