mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 00:15:05 +00:00
Remove include_body from interface of SolidLS.request_document_symbols
(body is always in data structure, callers can decide whether to use it)
This commit is contained in:
1 parent
7450fd73f6
commit
44d1a404cd
10 files changed
+24
-33
No files matched your search
+2
-4
@@ -478,8 +478,7 @@ class ProjectCommands(AutoRegisteringGroup):
|
||||
files_failed = []
|
||||
for i, f in enumerate(tqdm(files, desc="Indexing")):
|
||||
try:
|
||||
ls.request_document_symbols(f, include_body=False)
|
||||
ls.request_document_symbols(f, include_body=True)
|
||||
ls.request_document_symbols(f)
|
||||
except Exception as e:
|
||||
log.error(f"Failed to index {f}, continuing.")
|
||||
collected_exceptions.append(e)
|
||||
@@ -538,9 +537,8 @@ class ProjectCommands(AutoRegisteringGroup):
|
||||
try:
|
||||
for ls in ls_mgr.iter_language_servers():
|
||||
click.echo(f"Indexing for language {ls.language.value} …")
|
||||
document_symbols = ls.request_document_symbols(file, include_body=False)
|
||||
document_symbols = ls.request_document_symbols(file)
|
||||
symbols, _ = document_symbols.get_all_symbols_and_roots()
|
||||
ls.request_document_symbols(file, include_body=True)
|
||||
if verbose:
|
||||
click.echo(f"Symbols in file '{file}':")
|
||||
for symbol in symbols:
|
||||
|
||||
@@ -517,7 +517,7 @@ class LanguageServerSymbolRetriever:
|
||||
if location.relative_path is None:
|
||||
return None
|
||||
lang_server = self.get_language_server(location.relative_path)
|
||||
document_symbols = lang_server.request_document_symbols(location.relative_path, include_body=False)
|
||||
document_symbols = lang_server.request_document_symbols(location.relative_path)
|
||||
for symbol_dict in document_symbols.iter_symbols():
|
||||
symbol = LanguageServerSymbol(symbol_dict)
|
||||
if symbol.location == location:
|
||||
|
||||
@@ -713,7 +713,7 @@ class ALLanguageServer(SolidLanguageServer):
|
||||
|
||||
if os.path.isfile(within_abs_path):
|
||||
# Single file case - use parent class implementation
|
||||
root_nodes = self.request_document_symbols(within_relative_path, include_body=include_body).root_symbols
|
||||
root_nodes = self.request_document_symbols(within_relative_path).root_symbols
|
||||
return root_nodes
|
||||
|
||||
# Directory case - scan within this directory
|
||||
@@ -755,7 +755,7 @@ class ALLanguageServer(SolidLanguageServer):
|
||||
try:
|
||||
# Use our overridden request_document_symbols which handles opening
|
||||
self.logger.log(f"AL: Getting symbols for {relative_path}", logging.DEBUG)
|
||||
all_syms, root_syms = self.request_document_symbols(relative_path, include_body=include_body).get_all_symbols_and_roots()
|
||||
all_syms, root_syms = self.request_document_symbols(relative_path).get_all_symbols_and_roots()
|
||||
|
||||
if root_syms:
|
||||
# Create a file-level symbol containing the document symbols
|
||||
|
||||
@@ -193,7 +193,7 @@ class BashLanguageServer(SolidLanguageServer):
|
||||
else:
|
||||
self.logger.log("Bash server initialization complete", logging.INFO)
|
||||
|
||||
def request_document_symbols(self, relative_file_path: str, include_body: bool = False) -> DocumentSymbols:
|
||||
def request_document_symbols(self, relative_file_path: str) -> DocumentSymbols:
|
||||
"""
|
||||
Request document symbols from bash-language-server via LSP.
|
||||
|
||||
@@ -215,7 +215,7 @@ class BashLanguageServer(SolidLanguageServer):
|
||||
self.logger.log(f"Requesting document symbols via LSP for {relative_file_path}", logging.DEBUG)
|
||||
|
||||
# Use the standard LSP approach - bash-language-server handles all function syntaxes correctly
|
||||
document_symbols = super().request_document_symbols(relative_file_path, include_body)
|
||||
document_symbols = super().request_document_symbols(relative_file_path)
|
||||
|
||||
# Log detection results for debugging
|
||||
functions = [s for s in document_symbols.iter_symbols() if s.get("kind") == 12]
|
||||
|
||||
@@ -138,7 +138,7 @@ class FortranLanguageServer(SolidLanguageServer):
|
||||
return symbol
|
||||
|
||||
@override
|
||||
def request_document_symbols(self, relative_file_path: str, include_body: bool = False) -> DocumentSymbols:
|
||||
def request_document_symbols(self, relative_file_path: str) -> DocumentSymbols:
|
||||
"""
|
||||
Override to fix fortls's incorrect selectionRange bug.
|
||||
|
||||
@@ -153,7 +153,7 @@ class FortranLanguageServer(SolidLanguageServer):
|
||||
|
||||
"""
|
||||
# Get symbols from fortls (with incorrect selectionRange)
|
||||
document_symbols = super().request_document_symbols(relative_file_path, include_body)
|
||||
document_symbols = super().request_document_symbols(relative_file_path)
|
||||
|
||||
# Get file content for parsing
|
||||
with self.open_file(relative_file_path) as file_data:
|
||||
|
||||
@@ -70,7 +70,7 @@ class NixLanguageServer(SolidLanguageServer):
|
||||
return symbol
|
||||
|
||||
@override
|
||||
def request_document_symbols(self, relative_file_path: str, include_body: bool = False) -> DocumentSymbols:
|
||||
def request_document_symbols(self, relative_file_path: str) -> DocumentSymbols:
|
||||
"""
|
||||
Override to extend Nix symbol ranges to include trailing semicolons.
|
||||
|
||||
@@ -78,7 +78,7 @@ class NixLanguageServer(SolidLanguageServer):
|
||||
statement-level ranges (including semicolons) for proper symbol replacement.
|
||||
"""
|
||||
# Get symbols from parent implementation
|
||||
document_symbols = super().request_document_symbols(relative_file_path, include_body)
|
||||
document_symbols = super().request_document_symbols(relative_file_path)
|
||||
|
||||
# Get file content for range extension
|
||||
file_content = self.language_server.retrieve_full_file_content(relative_file_path)
|
||||
|
||||
+3
-4
@@ -941,12 +941,11 @@ class SolidLanguageServer(ABC):
|
||||
with self.open_file(relative_file_path) as opened_file_data:
|
||||
return get_symbols(opened_file_data)
|
||||
|
||||
def request_document_symbols(self, relative_file_path: str, include_body: bool = False) -> DocumentSymbols:
|
||||
def request_document_symbols(self, relative_file_path: str) -> DocumentSymbols:
|
||||
"""
|
||||
Retrieves the collection of symbols in the given file
|
||||
|
||||
:param relative_file_path: The relative path of the file that has the symbols
|
||||
:param include_body: whether to include the body of the symbols in the result.
|
||||
:return: the collection of symbols in the file.
|
||||
All contained symbols will have a location, children, and a parent attribute,
|
||||
where the parent attribute is None for root symbols.
|
||||
@@ -1090,7 +1089,7 @@ class SolidLanguageServer(ABC):
|
||||
)
|
||||
return []
|
||||
else:
|
||||
root_nodes = self.request_document_symbols(within_relative_path, include_body=include_body).root_symbols
|
||||
root_nodes = self.request_document_symbols(within_relative_path).root_symbols
|
||||
return root_nodes
|
||||
|
||||
# Helper function to recursively process directories
|
||||
@@ -1149,7 +1148,7 @@ class SolidLanguageServer(ABC):
|
||||
child["parent"] = package_symbol
|
||||
|
||||
elif os.path.isfile(contained_dir_or_file_abs_path):
|
||||
document_symbols = self.request_document_symbols(contained_dir_or_file_rel_path, include_body=include_body)
|
||||
document_symbols = self.request_document_symbols(contained_dir_or_file_rel_path)
|
||||
file_root_nodes = document_symbols.root_symbols
|
||||
|
||||
# Create file symbol, link with children
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestBashLanguageServerBasics:
|
||||
def test_bash_request_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test request_document_symbols for bash files."""
|
||||
# Test getting symbols from main.sh
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("main.sh", include_body=False).get_all_symbols_and_roots()
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("main.sh").get_all_symbols_and_roots()
|
||||
|
||||
# Extract function symbols (LSP Symbol Kind 12)
|
||||
function_symbols = [symbol for symbol in all_symbols if symbol.get("kind") == 12]
|
||||
@@ -41,7 +41,7 @@ class TestBashLanguageServerBasics:
|
||||
def test_bash_request_document_symbols_with_body(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test request_document_symbols with body extraction."""
|
||||
# Test with include_body=True
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("main.sh", include_body=True).get_all_symbols_and_roots()
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("main.sh").get_all_symbols_and_roots()
|
||||
|
||||
function_symbols = [symbol for symbol in all_symbols if symbol.get("kind") == 12]
|
||||
|
||||
@@ -58,9 +58,7 @@ class TestBashLanguageServerBasics:
|
||||
def test_bash_utils_functions(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test function detection in utils.sh file."""
|
||||
# Test with utils.sh as well
|
||||
utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols(
|
||||
"utils.sh", include_body=False
|
||||
).get_all_symbols_and_roots()
|
||||
utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols("utils.sh").get_all_symbols_and_roots()
|
||||
|
||||
utils_function_symbols = [symbol for symbol in utils_all_symbols if symbol.get("kind") == 12]
|
||||
utils_function_names = [symbol["name"] for symbol in utils_function_symbols]
|
||||
@@ -86,16 +84,12 @@ class TestBashLanguageServerBasics:
|
||||
def test_bash_function_syntax_patterns(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test that LSP detects different bash function syntax patterns correctly."""
|
||||
# Test main.sh (has both 'function' keyword and traditional syntax)
|
||||
main_all_symbols, _main_root_symbols = language_server.request_document_symbols(
|
||||
"main.sh", include_body=False
|
||||
).get_all_symbols_and_roots()
|
||||
main_all_symbols, _main_root_symbols = language_server.request_document_symbols("main.sh").get_all_symbols_and_roots()
|
||||
main_functions = [symbol for symbol in main_all_symbols if symbol.get("kind") == 12]
|
||||
main_function_names = [func["name"] for func in main_functions]
|
||||
|
||||
# Test utils.sh (all use 'function' keyword)
|
||||
utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols(
|
||||
"utils.sh", include_body=False
|
||||
).get_all_symbols_and_roots()
|
||||
utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols("utils.sh").get_all_symbols_and_roots()
|
||||
utils_functions = [symbol for symbol in utils_all_symbols if symbol.get("kind") == 12]
|
||||
utils_function_names = [func["name"] for func in utils_functions]
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestMarkdownLanguageServerBasics:
|
||||
def test_markdown_request_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test request_document_symbols for markdown files."""
|
||||
# Test getting symbols from README.md
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("README.md", include_body=False).get_all_symbols_and_roots()
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("README.md").get_all_symbols_and_roots()
|
||||
|
||||
# Extract heading symbols (LSP Symbol Kind 15 is String, but marksman uses kind 15 for headings)
|
||||
# Note: Different markdown LSPs may use different symbol kinds for headings
|
||||
@@ -38,7 +38,7 @@ class TestMarkdownLanguageServerBasics:
|
||||
@pytest.mark.parametrize("language_server", [Language.MARKDOWN], indirect=True)
|
||||
def test_markdown_request_symbols_from_guide(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test symbol detection in guide.md file."""
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("guide.md", include_body=False).get_all_symbols_and_roots()
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("guide.md").get_all_symbols_and_roots()
|
||||
|
||||
# At least some headings should be found
|
||||
assert len(all_symbols) > 0, f"Should find headings in guide.md, found {len(all_symbols)}"
|
||||
@@ -46,7 +46,7 @@ class TestMarkdownLanguageServerBasics:
|
||||
@pytest.mark.parametrize("language_server", [Language.MARKDOWN], indirect=True)
|
||||
def test_markdown_request_symbols_from_api(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test symbol detection in api.md file."""
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("api.md", include_body=False).get_all_symbols_and_roots()
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("api.md").get_all_symbols_and_roots()
|
||||
|
||||
# Should detect headings from api.md
|
||||
assert len(all_symbols) > 0, f"Should find headings in api.md, found {len(all_symbols)}"
|
||||
@@ -55,7 +55,7 @@ class TestMarkdownLanguageServerBasics:
|
||||
def test_markdown_request_document_symbols_with_body(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test request_document_symbols with body extraction."""
|
||||
# Test with include_body=True
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("README.md", include_body=True).get_all_symbols_and_roots()
|
||||
all_symbols, _root_symbols = language_server.request_document_symbols("README.md").get_all_symbols_and_roots()
|
||||
|
||||
# Should have found some symbols
|
||||
assert len(all_symbols) > 0, "Should find symbols in README.md"
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestPerlLanguageServer:
|
||||
def test_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
||||
"""Test that document symbols are correctly identified."""
|
||||
# Request document symbols
|
||||
all_symbols, _ = language_server.request_document_symbols("main.pl", include_body=False).get_all_symbols_and_roots()
|
||||
all_symbols, _ = language_server.request_document_symbols("main.pl").get_all_symbols_and_roots()
|
||||
|
||||
assert all_symbols, "Expected to find symbols in main.pl"
|
||||
assert len(all_symbols) > 0, "Expected at least one symbol"
|
||||
|
||||
Reference in new issue
Block a user