@@ -31,86 +31,10 @@ function M.out(node)
3131 if util .is_markdown_file () then
3232 return markdown_targets .out ()
3333 end
34-
35- -- Special handling for specific test positions: if we're at row 121, col 3
36- -- in the TypeScript test, we know we should navigate to the class declaration
37- local current_row = vim .fn .line (' .' )
38- local current_col = vim .fn .col (' .' )
39- if current_row == 121 and current_col == 3 then
40- -- This is the specific failing test case - look for class declaration at row 119
41- local class_node = nodes .get_at_row (119 )
42- if class_node and class_node :type ():match (" class" ) then
43- return class_node , 119
44- end
45- end
46-
4734 local candidate = strategies .get_first_ancestor_with_diff_scol (node )
48- -- If no ancestor with different column found, try to find the first valid ancestor
4935 if not candidate then
5036 candidate = strategies .get_first_ancestor_jump_target (node )
5137 end
52-
53- -- Special case: if we're in a comment and the candidate is a body node,
54- -- we probably want to go to the declaration instead
55- if node :type ():match (" comment" ) and candidate and candidate :type ():match (" body" ) then
56- local declaration = candidate :parent ()
57- if declaration and nodes .is_jump_target (declaration ) then
58- candidate = declaration
59- end
60- end
61-
62- -- Special case: if we're in a comment and didn't find an ancestor to jump to,
63- -- the comment might be structured differently (e.g., not nested in class_body in some parsers)
64- -- Try to find a related class or function
65- if not candidate and node :type ():match (" comment" ) then
66- -- Walk up to find the highest comment node
67- local top_comment = node
68- while top_comment :parent () and top_comment :parent ():type ():match (" comment" ) do
69- top_comment = top_comment :parent ()
70- end
71-
72- -- Check if we're inside a class_body or similar structure
73- local parent = top_comment :parent ()
74- if parent and parent :type ():match (" body" ) then
75- -- We're inside a body, go to the parent declaration
76- candidate = parent :parent ()
77- elseif parent then
78- -- We're at a different level, look for a previous sibling that's a declaration
79- local sibling = top_comment :prev_sibling ()
80- while sibling do
81- if nodes .is_jump_target (sibling ) then
82- -- Found a sibling that's a valid target
83- if sibling :type ():match (" class" ) or sibling :type ():match (" function" ) then
84- candidate = sibling
85- break
86- end
87- end
88- sibling = sibling :prev_sibling ()
89- end
90- end
91- end
92-
93- -- Additional fallback for comment-related nodes: if we still don't have a candidate
94- -- and we're in a position that looks like it could be comment-related,
95- -- search nearby for a class or function declaration
96- if not candidate then
97- -- Check if we're at a position that suggests we're in or near a comment
98- local current_line = require (' treewalker.lines' ).get_line (current_row )
99- if current_line and (current_line :match (" /%*" ) or current_line :match (" %*" ) or current_line :match (" %*/" )) then
100- -- Look for a class declaration in nearby lines (within 10 lines)
101- for i = math.max (1 , current_row - 10 ), math.min (vim .api .nvim_buf_line_count (0 ), current_row + 10 ) do
102- local line = require (' treewalker.lines' ).get_line (i )
103- if line and line :match (" class%s" ) then
104- local potential_node = nodes .get_at_row (i )
105- if potential_node and potential_node :type ():match (" class" ) and nodes .is_jump_target (potential_node ) then
106- candidate = potential_node
107- break
108- end
109- end
110- end
111- end
112- end
113-
11438 candidate = coincident (candidate )
11539 if not candidate then return end
11640 local row = nodes .get_srow (candidate )
0 commit comments