def METHOD_NAME(path: str) -> List[str]:
    """
    Collect all compilation database paths that may be relevant for the source
    files at the given path. This means compilation databases anywhere under
    this path and in the parent directories up to the root.
    """
    dirs = []
    for root, _, files in os.walk(path):
        if COMPILATION_DATABASE in files:
            dirs.append(os.path.join(root, COMPILATION_DATABASE))
    path = os.path.abspath(path)
    root = os.path.abspath(os.sep)
    while True:
        path = os.path.dirname(path)
        compile_commands_json = os.path.join(path, COMPILATION_DATABASE)
        if os.path.isfile(compile_commands_json):
            dirs.append(compile_commands_json)
        if path == root:
            break
    return dirs