Add language-specific filename filtering to fix request_full_symbol_tree

This commit is contained in:
Dominik Jain committed 2025-03-25 21:46:14 +01:00
1 parent 8f70e95b92
commit 5adc2f130e
2 files changed
+33 -4

No files matched your search

+9 -3
View File
@@ -190,11 +190,12 @@ class LanguageServer:
self.language_id = language_id
self.open_file_buffers: Dict[str, LSPFileBuffer] = {}
# --------------------------------- MODIFICATIONS BY MISCHA ---------------------------------
# --------------------------------- MODIFICATIONS BY ORAIOS ---------------------------------
self._document_symbols_cache: dict[str, Tuple[str, Tuple[List[multilspy_types.UnifiedSymbolInformation], List[multilspy_types.UnifiedSymbolInformation]]]] = {}
"""Maps file paths to a tuple of (file_content_hash, result_of_request_document_symbols)"""
self.load_cache()
self._cache_has_changed = bool
self.language = Language(language_id)
@asynccontextmanager
async def start_server(self) -> AsyncIterator["LanguageServer"]:
@@ -765,13 +766,15 @@ class LanguageServer:
raise MultilspyException("Language Server not started")
# Helper function to check if a path should be ignored
def should_ignore_path(path: str) -> bool:
def should_ignore_dir(path: str) -> bool:
parts = path.split(os.sep)
return any(part.startswith('.') or part == '__pycache__' for part in parts)
fn_matcher = self.language.get_source_fn_matcher()
# Helper function to recursively process directories
async def process_directory(dir_path: str) -> List[multilspy_types.UnifiedSymbolInformation]:
if should_ignore_path(dir_path):
if should_ignore_dir(dir_path):
return []
result = []
@@ -803,6 +806,9 @@ class LanguageServer:
package_symbol["children"].extend(child_symbols)
elif os.path.isfile(abs_item_path):
if not fn_matcher.is_relevant_filename(item):
continue
_, root_nodes = await self.request_document_symbols(item_path, include_body=include_body)
# Create module symbol
+24 -1
View File
@@ -1,10 +1,25 @@
"""
Configuration parameters for Multilspy.
"""
import fnmatch
from enum import Enum
from dataclasses import dataclass
class FilenameMatcher:
def __init__(self, *patterns: str) -> None:
"""
:param patterns: fnmatch-compatible patterns
"""
self.patterns = patterns
def is_relevant_filename(self, fn: str) -> bool:
for pattern in self.patterns:
if fnmatch.fnmatch(fn, pattern):
return True
return False
class Language(str, Enum):
"""
Possible languages with Multilspy.
@@ -22,6 +37,14 @@ class Language(str, Enum):
def __str__(self) -> str:
return self.value
def get_source_fn_matcher(self) -> FilenameMatcher:
match self:
case self.PYTHON:
return FilenameMatcher("*.py")
case _:
raise ValueError
@dataclass
class MultilspyConfig:
"""