Skip to content

Commit cab36b4

Browse files
authored
Merge pull request #1312 from Arkh74278/fix/dart-hierarchical-document-symbol-support
fix: add hierarchicalDocumentSymbolSupport capability for Dart LSP
1 parent 34a703a commit cab36b4

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Status of the `main` branch. Changes prior to the next official version change will appear here.
44

5+
* Language Servers:
6+
- Fix Dart LSP returning only symbol name as body instead of full method body
7+
58
# 1.1.0
69

710
* General:
@@ -284,4 +287,4 @@ Fixes:
284287

285288
# 2025-04-01
286289

287-
Initial public version
290+
Initial public version

src/solidlsp/language_servers/dart_language_server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
123123
"""
124124
root_uri = pathlib.Path(repository_absolute_path).as_uri()
125125
initialize_params = {
126-
"capabilities": {},
126+
"capabilities": {
127+
"textDocument": {
128+
"documentSymbol": {
129+
"hierarchicalDocumentSymbolSupport": True,
130+
}
131+
}
132+
},
127133
"initializationOptions": {
128134
"onlyAnalyzeProjectsWithOpenFiles": False,
129135
"closingLabels": False,

test/solidlsp/dart/test_dart_basic.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)