A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
discover.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef A11_FLOW_DISCOVER_H_
18#define A11_FLOW_DISCOVER_H_
19
20#include <cstddef>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include <absl/types/span.h>
27
28#include "a11/flow/catalogue.h"
29
30namespace a11::flow {
31
36namespace discover {
37
40
42enum class Language {
43 kPython,
44 kCpp,
46};
47
50std::optional<Language> LanguageOf(std::string_view path);
51
53struct Options {
57 std::vector<std::string> skip_directories;
58
60 size_t max_file_bytes = 1u << 20;
61
63 size_t max_files = 20000;
64
66 size_t max_entries = 50000;
67
69 static Options Default();
70};
71
73struct Result {
76 size_t files_read = 0;
78 std::vector<std::string> too_large;
80 bool reached_file_limit = false;
82 size_t entries_visited = 0;
84 bool reached_entry_limit = false;
85};
86
89Result Discover(absl::Span<const std::string> roots,
91
93catalogue::Catalogue DiscoverInSource(std::string_view source,
94 std::string_view path, Language language);
95
97inline constexpr std::string_view kScanFormat = catalogue::kCatalogueFormat;
98
99} // namespace discover
100} // namespace a11::flow
101
102#endif // A11_FLOW_DISCOVER_H_
Everything the tools know about the world, in one place.
Definition catalogue.h:91
std::string path
Definition main.cc:135
std::vector< std::string > roots
Definition main.cc:137
constexpr std::string_view kCatalogueFormat
The format field of the catalogue envelope.
Definition catalogue.h:145
Result Discover(absl::Span< const std::string > roots, const Options &options)
Scans directories or files under roots for action declarations.
Definition discover.cc:1389
constexpr std::string_view kScanFormat
Scan results use the catalogue envelope format.
Definition discover.h:97
catalogue::Catalogue DiscoverInSource(std::string_view source, std::string_view path, Language language)
Scans supplied source and records path as its origin.
Definition discover.cc:1383
std::optional< Language > LanguageOf(std::string_view path)
The language a path's extension says it is, or nullopt for a file this does not read.
Definition discover.cc:1350
Language
A language an ActionSchema may be declared in.
Definition discover.h:42
Definition catalogue.cc:29
stores::ChunkStoreReaderOptions options
Definition runtime_streams.cc:31
Source location of a discovered entry, with 1-based line and column.
Definition catalogue.h:39
What to read and what to leave alone.
Definition discover.h:53
std::vector< std::string > skip_directories
Directory names never descended into.
Definition discover.h:57
static Options Default()
Options with the defaults filled in.
Definition discover.cc:1370
size_t max_file_bytes
Maximum file size read during a scan.
Definition discover.h:60
size_t max_entries
The most directory entries visited, including non-source files.
Definition discover.h:66
size_t max_files
The most files read in one scan.
Definition discover.h:63
Discovered actions and limits reached during the scan.
Definition discover.h:73
catalogue::Catalogue found
Definition discover.h:74
std::vector< std::string > too_large
Files skipped for being larger than max_file_bytes.
Definition discover.h:78
size_t entries_visited
Directory entries visited, including directories and non-source files.
Definition discover.h:82
bool reached_entry_limit
Whether max_entries stopped traversal.
Definition discover.h:84
size_t files_read
Files opened and read to the end.
Definition discover.h:76
bool reached_file_limit
Whether max_files stopped the walk before it ran out of files.
Definition discover.h:80