This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-9p/tools/_lib/lsp/workspace.py

21 lines
623 B
Python

"""Workspace root detection: walk up from a file to find language-specific markers."""
import os
from pathlib import Path
def find_root(filepath: str, markers: list[str], fallback: str | None = None) -> str:
"""Walk up from filepath looking for any marker file/dir. Return the directory containing it."""
p = Path(filepath).resolve()
if p.is_file():
p = p.parent
while True:
for marker in markers:
if (p / marker).exists():
return str(p)
parent = p.parent
if parent == p:
break
p = parent
return fallback or os.getcwd()