mirror of
https://github.com/tiennm99/serena.git
synced 2026-07-14 20:22:36 +00:00
Fix tests to correctly use gitignore for LS setup
This commit is contained in:
@@ -6,23 +6,43 @@ import pytest
|
||||
from multilspy.language_server import SyncLanguageServer
|
||||
from multilspy.multilspy_config import Language, MultilspyConfig
|
||||
from multilspy.multilspy_logger import MultilspyLogger
|
||||
from serena.util.file_system import GitignoreParser
|
||||
from test.conftest import get_repo_path
|
||||
|
||||
# This mark will be applied to all tests in this module
|
||||
pytestmark = pytest.mark.python
|
||||
|
||||
|
||||
def create_ls_with_ignored_dirs(
|
||||
ignored_paths: list[str] | None = None,
|
||||
repo_path: Path | None = None,
|
||||
language: Language = Language.PYTHON,
|
||||
) -> SyncLanguageServer:
|
||||
"""Helper function to create a SyncLanguageServer with ignored directories."""
|
||||
if ignored_paths is None:
|
||||
ignored_paths = []
|
||||
|
||||
if repo_path is None:
|
||||
repo_path = get_repo_path(language)
|
||||
|
||||
gitignore_parser = GitignoreParser(str(repo_path))
|
||||
for spec in gitignore_parser.get_ignore_specs():
|
||||
ignored_paths.extend(spec.patterns)
|
||||
|
||||
config = MultilspyConfig(
|
||||
code_language=language,
|
||||
trace_lsp_communication=False,
|
||||
ignored_paths=ignored_paths, # Configure the relative path to be ignored
|
||||
)
|
||||
logger = MultilspyLogger()
|
||||
return SyncLanguageServer.create(config, logger, str(repo_path))
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def ls_with_ignored_dirs() -> Generator[SyncLanguageServer, None, None]:
|
||||
"""Fixture to set up an LS for the python test repo with the 'scripts' directory ignored."""
|
||||
config = MultilspyConfig(
|
||||
code_language=Language.PYTHON,
|
||||
trace_lsp_communication=False,
|
||||
ignored_paths=["scripts", "custom_test"], # Configure the relative path to be ignored
|
||||
)
|
||||
logger = MultilspyLogger()
|
||||
repo_path = get_repo_path(Language.PYTHON)
|
||||
ls = SyncLanguageServer.create(config, logger, str(repo_path))
|
||||
ignored_paths = ["scripts", "custom_test_repo"]
|
||||
ls = create_ls_with_ignored_dirs(ignored_paths=ignored_paths, language=Language.PYTHON)
|
||||
ls.start()
|
||||
try:
|
||||
yield ls
|
||||
@@ -56,13 +76,8 @@ def test_find_references_ignores_dir(ls_with_ignored_dirs: SyncLanguageServer):
|
||||
@pytest.mark.parametrize("repo_path", [Language.PYTHON], indirect=True)
|
||||
def test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:
|
||||
"""Tests that refs and symbols with glob patterns are ignored."""
|
||||
config = MultilspyConfig(
|
||||
code_language=Language.PYTHON,
|
||||
trace_lsp_communication=False,
|
||||
ignored_paths=["*ipts", "custom_t*"],
|
||||
)
|
||||
logger = MultilspyLogger()
|
||||
ls = SyncLanguageServer.create(config, logger, str(repo_path))
|
||||
ignored_paths = ["*ipts", "custom_t*"]
|
||||
ls = create_ls_with_ignored_dirs(ignored_paths=ignored_paths, repo_path=repo_path, language=Language.PYTHON)
|
||||
ls.start()
|
||||
# same as in the above tests
|
||||
root = ls.request_full_symbol_tree()[0]
|
||||
|
||||
Reference in New Issue
Block a user