@@ -375,3 +375,52 @@ def test_bare_symbol_names(self, language_server) -> None:
375375 f"Found malformed symbols: { [format_symbol_for_assert (sym ) for sym in malformed_symbols ]} " ,
376376 pytrace = False ,
377377 )
378+
379+ @pytest .mark .parametrize ("language_server" , [Language .DART ], indirect = True )
380+ def test_symbol_body_contains_full_method (self , language_server : SolidLanguageServer ) -> None :
381+ """Test that document symbols return the full method body range, not just the identifier.
382+
383+ Regression test: when hierarchicalDocumentSymbolSupport was not declared in client
384+ capabilities, the Dart LSP returned SymbolInformation[] (flat format) where
385+ location.range only covered the identifier name (single line), causing find_symbol
386+ with include_body=True to return just the symbol name instead of its implementation.
387+ """
388+ file_path = os .path .join ("lib" , "main.dart" )
389+ symbols = language_server .request_document_symbols (file_path ).get_all_symbols_and_roots ()
390+ symbol_list = symbols [0 ] if symbols and isinstance (symbols [0 ], list ) else symbols
391+
392+ # Find the 'add' method — defined across multiple lines in main.dart:
393+ # int add(int a, int b) {
394+ # final result = a + b;
395+ # _history.add('$a + $b = $result');
396+ # return result;
397+ # }
398+ add_symbol = None
399+ for sym in symbol_list :
400+ if sym .get ("name" ) == "add" :
401+ add_symbol = sym
402+ break
403+ if sym .get ("name" ) == "Calculator" and "children" in sym :
404+ for child in sym ["children" ]:
405+ if child .get ("name" ) == "add" :
406+ add_symbol = child
407+ break
408+ if add_symbol :
409+ break
410+
411+ assert add_symbol is not None , "Could not find 'add' method symbol in main.dart"
412+
413+ # The body range must span multiple lines (not just the identifier line).
414+ # With hierarchicalDocumentSymbolSupport declared, the Dart LSP returns
415+ # DocumentSymbol[] where range covers the full method body.
416+ body_start = add_symbol ["location" ]["range" ]["start" ]["line" ]
417+ body_end = add_symbol ["location" ]["range" ]["end" ]["line" ]
418+ assert body_end > body_start , (
419+ f"Expected multi-line body range for 'add' method, got start={ body_start } , end={ body_end } . "
420+ f"This likely means hierarchicalDocumentSymbolSupport is not declared in client capabilities."
421+ )
422+
423+ # The body text must contain the method implementation, not just the name.
424+ if add_symbol .get ("body" ):
425+ body_text = add_symbol ["body" ].get_text ()
426+ assert "return result" in body_text , f"Expected method body to contain implementation, got: { body_text !r} "
0 commit comments