From 1db52b16bfa9fac33b082bff2471904cdf125d03 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Mon, 23 Feb 2026 19:32:41 +0100 Subject: [PATCH] Overview tool: raise ValueError for directory paths (if multiple LS are active) The error is raised through `LanguageServerManager.get_language_server`, where it is done conservatively (only if multiple LS are available and we can't decide) --- src/serena/ls_manager.py | 4 ++++ src/serena/symbol.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/serena/ls_manager.py b/src/serena/ls_manager.py index 6fdf0c24..47a62858 100644 --- a/src/serena/ls_manager.py +++ b/src/serena/ls_manager.py @@ -1,4 +1,5 @@ import logging +import os.path import threading from collections.abc import Iterator @@ -129,8 +130,11 @@ class LanguageServerManager: return ls def get_language_server(self, relative_path: str) -> SolidLanguageServer: + """:param relative_path: relative path to a file""" ls: SolidLanguageServer | None = None if len(self._language_servers) > 1: + if os.path.isdir(relative_path): + raise ValueError(f"Expected a file path, but got a directory: {relative_path}") for candidate in self._language_servers.values(): if not candidate.is_ignored_path(relative_path, ignore_unsupported_files=True): ls = candidate diff --git a/src/serena/symbol.py b/src/serena/symbol.py index fbf9f012..03f593d0 100644 --- a/src/serena/symbol.py +++ b/src/serena/symbol.py @@ -697,6 +697,7 @@ class LanguageServerSymbolRetriever: return self._ls_manager.get_root_path() def get_language_server(self, relative_path: str) -> SolidLanguageServer: + """:param relative_path: relative path to a file""" return self._ls_manager.get_language_server(relative_path) def find( @@ -837,7 +838,7 @@ class LanguageServerSymbolRetriever: def get_symbol_overview(self, relative_path: str) -> dict[str, list[LanguageServerSymbol]]: """ - :param relative_path: the path of the file or directory for which to get the symbol overview + :param relative_path: the path of the file for which to get the symbol overview :return: a mapping from file paths to lists of symbols. For the case where a file is passed, the mapping will contain a single entry. """