feat: add Fortran support and tab controls
This commit is contained in:
@@ -11,15 +11,17 @@ from .text_io import DEFAULT_TEXT_PREVIEW_BYTES, is_within_size_limit, read_text
|
||||
|
||||
PYTHON_EXTENSIONS = {".py", ".pyw", ".pyi"}
|
||||
CPP_EXTENSIONS = {".c", ".cc", ".cxx", ".cpp", ".h", ".hh", ".hxx", ".hpp"}
|
||||
FORTRAN_EXTENSIONS = {".f", ".for", ".f90", ".f95"}
|
||||
|
||||
FILE_GROUP_EXTENSIONS = {
|
||||
"markdown": MARKDOWN_EXTENSIONS | WEBPAGE_EXTENSIONS,
|
||||
"python": PYTHON_EXTENSIONS,
|
||||
"cpp": CPP_EXTENSIONS,
|
||||
"fortran": FORTRAN_EXTENSIONS,
|
||||
}
|
||||
DEFAULT_DOCUMENT_FILE_GROUPS = ("markdown",)
|
||||
SUPPORTED_DOCUMENT_EXTENSIONS = set().union(*FILE_GROUP_EXTENSIONS.values())
|
||||
CODE_DOCUMENT_EXTENSIONS = PYTHON_EXTENSIONS | CPP_EXTENSIONS
|
||||
CODE_DOCUMENT_EXTENSIONS = PYTHON_EXTENSIONS | CPP_EXTENSIONS | FORTRAN_EXTENSIONS
|
||||
MAX_DISCOVERABLE_CODE_BYTES = DEFAULT_TEXT_PREVIEW_BYTES
|
||||
|
||||
EXCLUDED_DIR_NAMES = {
|
||||
@@ -80,6 +82,8 @@ def code_language_for_path(path: Path) -> str:
|
||||
return "c"
|
||||
if suffix in CPP_EXTENSIONS:
|
||||
return "cpp"
|
||||
if suffix in FORTRAN_EXTENSIONS:
|
||||
return "fortran"
|
||||
return "text"
|
||||
|
||||
|
||||
@@ -102,6 +106,29 @@ def first_heading(path: Path) -> str | None:
|
||||
return headings[0].title if headings else None
|
||||
|
||||
|
||||
|
||||
def document_directory_signature(project_root: Path, enabled_groups: object = None) -> tuple[tuple[str, int, int], ...]:
|
||||
root = project_root.resolve()
|
||||
supported_extensions = document_extensions_for_groups(enabled_groups)
|
||||
signatures: list[tuple[str, int, int]] = []
|
||||
|
||||
for path in _iter_project_files(root):
|
||||
suffix = path.suffix.lower()
|
||||
if suffix not in supported_extensions:
|
||||
continue
|
||||
try:
|
||||
stat = path.stat()
|
||||
if suffix in CODE_DOCUMENT_EXTENSIONS and stat.st_size > MAX_DISCOVERABLE_CODE_BYTES:
|
||||
continue
|
||||
relative_path = path.relative_to(root).as_posix()
|
||||
except OSError:
|
||||
continue
|
||||
except ValueError:
|
||||
continue
|
||||
signatures.append((relative_path, stat.st_mtime_ns, stat.st_size))
|
||||
|
||||
return tuple(sorted(signatures))
|
||||
|
||||
def discover_documents(project_root: Path, enabled_groups: object = None) -> list[DocumentEntry]:
|
||||
root = project_root.resolve()
|
||||
supported_extensions = document_extensions_for_groups(enabled_groups)
|
||||
@@ -151,3 +178,4 @@ def _iter_project_files(root: Path) -> Iterator[Path]:
|
||||
|
||||
def _is_excluded_name(name: str) -> bool:
|
||||
return name.startswith(".") or name in EXCLUDED_DIR_NAMES
|
||||
|
||||
|
||||
Reference in New Issue
Block a user