From 79140e9f802eb572711ff2b5f1a5db53da8b641e Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Tue, 25 Mar 2025 22:24:00 +0100 Subject: [PATCH] LS: use File symbol instead of Module --- src/multilspy/language_server.py | 11 ++++++----- test/multilspy/test_symbol_retrieval.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/multilspy/language_server.py b/src/multilspy/language_server.py index 247b3db..f6aedc5 100644 --- a/src/multilspy/language_server.py +++ b/src/multilspy/language_server.py @@ -811,10 +811,10 @@ class LanguageServer: _, root_nodes = await self.request_document_symbols(item_path, include_body=include_body) - # Create module symbol - module_symbol = multilspy_types.UnifiedSymbolInformation( # type: ignore + # Create file symbol + file_symbol = multilspy_types.UnifiedSymbolInformation( # type: ignore name=os.path.splitext(item)[0], - kind=multilspy_types.SymbolKind.Module, + kind=multilspy_types.SymbolKind.File, location=multilspy_types.Location( uri=str(pathlib.Path(abs_item_path).as_uri()), range={"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 0}}, @@ -824,7 +824,7 @@ class LanguageServer: children=root_nodes ) - package_symbol["children"].append(module_symbol) + package_symbol["children"].append(file_symbol) return result @@ -907,7 +907,7 @@ class LanguageServer: roots = await self.request_full_symbol_tree() paths = [] def collect_module_files(symbol): - if symbol["kind"] == multilspy_types.SymbolKind.Module: + if symbol["kind"] == multilspy_types.SymbolKind.File: assert "location" in symbol paths.append(symbol["location"]["relativePath"]) @@ -946,6 +946,7 @@ class LanguageServer: all_files = await self.request_parsed_files() for path in all_files: # Apply glob filters if provided + # TODO: fnmatch is not exactly the same as glob if paths_include_glob and not fnmatch(path, paths_include_glob): self.logger.log(f"Skipping {path}: does not match include pattern {paths_include_glob}", logging.DEBUG) continue diff --git a/test/multilspy/test_symbol_retrieval.py b/test/multilspy/test_symbol_retrieval.py index 74335a0..af2ffb9 100644 --- a/test/multilspy/test_symbol_retrieval.py +++ b/test/multilspy/test_symbol_retrieval.py @@ -338,7 +338,7 @@ class TestLanguageServerSymbols: examples_package = next(child for child in repo_structure[0]["children"] if child["name"] == "examples") # assert that children are __init__ and user_management assert {child["name"] for child in examples_package["children"]} == {"__init__", "user_management"} - assert {child["kind"] for child in examples_package["children"]} == {SymbolKind.Module} + assert {child["kind"] for child in examples_package["children"]} == {SymbolKind.File} # assert that tree of user_management node is same as retrieved directly user_management_node = next(child for child in examples_package["children"] if child["name"] == "user_management") @@ -357,7 +357,7 @@ class TestLanguageServerSymbols: assert examples_package["kind"] == SymbolKind.Package # assert that children are __init__ and user_management assert {child["name"] for child in examples_package["children"]} == {"__init__", "user_management"} - assert {child["kind"] for child in examples_package["children"]} == {SymbolKind.Module} + assert {child["kind"] for child in examples_package["children"]} == {SymbolKind.File} # assert that tree of user_management node is same as retrieved directly user_management_node = next(child for child in examples_package["children"] if child["name"] == "user_management")