forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptions.h
321 lines (283 loc) · 11.5 KB
/
options.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#ifndef RUBY_TYPER_OPTIONS_H
#define RUBY_TYPER_OPTIONS_H
#include "common/EarlyReturnWithCode.h"
#include "common/FileSystem.h"
#include "common/common.h"
#include "common/strings/ConstExprStr.h"
#include "core/StrictLevel.h"
#include "core/TrackUntyped.h"
#include "main/pipeline/semantic_extension/SemanticExtension.h"
#include "spdlog/spdlog.h"
#include <optional>
namespace sorbet::realmain::options {
class PrinterConfig {
public:
bool enabled = false;
std::string outputPath;
bool supportsFlush = false;
void print(const std::string_view &contents) const;
template <typename... Args> void fmt(fmt::format_string<Args...> msg, Args &&...args) const {
auto contents = fmt::format(msg, std::forward<Args>(args)...);
print(contents);
}
void flush();
std::string flushToString();
PrinterConfig();
PrinterConfig(const PrinterConfig &) = default;
PrinterConfig(PrinterConfig &&) = default;
PrinterConfig &operator=(const PrinterConfig &) = default;
PrinterConfig &operator=(PrinterConfig &&) = default;
private:
struct GuardedState {
fmt::memory_buffer buf;
absl::Mutex mutex;
};
std::shared_ptr<GuardedState> state;
};
struct Printers {
PrinterConfig ParseTree;
PrinterConfig ParseTreeJson;
PrinterConfig ParseTreeJsonWithLocs;
PrinterConfig ParseTreeWhitequark;
PrinterConfig DesugarTree;
PrinterConfig DesugarTreeRaw;
PrinterConfig RewriterTree;
PrinterConfig RewriterTreeRaw;
PrinterConfig IndexTree;
PrinterConfig IndexTreeRaw;
PrinterConfig NameTree;
PrinterConfig NameTreeRaw;
PrinterConfig ResolveTree;
PrinterConfig ResolveTreeRaw;
PrinterConfig FlattenTree;
PrinterConfig FlattenTreeRaw;
PrinterConfig AST;
PrinterConfig ASTRaw;
PrinterConfig CFG;
PrinterConfig CFGText;
PrinterConfig CFGRaw;
PrinterConfig TypedSource;
PrinterConfig SymbolTable;
PrinterConfig SymbolTableRaw;
PrinterConfig SymbolTableProto;
PrinterConfig SymbolTableMessagePack;
PrinterConfig SymbolTableJson;
PrinterConfig SymbolTableFull;
PrinterConfig SymbolTableFullRaw;
PrinterConfig SymbolTableFullProto;
PrinterConfig SymbolTableFullMessagePack;
PrinterConfig SymbolTableFullJson;
PrinterConfig FileTableJson;
PrinterConfig FileTableProto;
PrinterConfig FileTableMessagePack;
PrinterConfig FileTableFullJson;
PrinterConfig FileTableFullProto;
PrinterConfig FileTableFullMessagePack;
PrinterConfig MissingConstants;
PrinterConfig Autogen;
PrinterConfig AutogenMsgPack;
PrinterConfig AutogenSubclasses;
PrinterConfig Packager;
PrinterConfig MinimizeRBI;
PrinterConfig PayloadSources;
PrinterConfig UntypedBlame;
// Ensure everything here is in PrinterConfig::printers().
std::vector<std::reference_wrapper<PrinterConfig>> printers();
bool isAutogen() const;
};
enum class Phase {
INIT,
PARSER,
DESUGARER,
REWRITER,
LOCAL_VARS,
NAMER,
PACKAGER,
RESOLVER,
CFG,
INFERENCER,
};
enum class Parser {
PRISM,
SORBET,
};
struct ParserOptions {
std::string option;
Parser flag;
};
const std::vector<ParserOptions> parser_options({
{"sorbet", Parser::SORBET},
{"prism", Parser::PRISM},
});
struct AutogenConstCacheConfig {
// A file which contains a cache that can be used to potentially skip autogen
std::string cacheFile;
// A list of files which have changed since the last autogen run.
std::vector<std::string> changedFiles;
};
namespace {
#if !defined(EMSCRIPTEN)
constexpr size_t MAX_CACHE_SIZE_BYTES = 4L * 1024 * 1024 * 1024; // 4 GiB
#else
// Cache is unused in emscripten, so this value doesn't matter, but sizeof(size_t) on emscripten is 4 bytes
constexpr size_t MAX_CACHE_SIZE_BYTES = 1L * 1024 * 1024 * 1024; // 1 GiB
#endif
} // namespace
struct Options {
Printers print;
Phase stopAfterPhase = Phase::INFERENCER;
Parser parser = Parser::SORBET;
bool noStdlib = false;
// Should we monitor STDOUT for HUP and exit if it hangs up. This is a
// workaround for https://bugzilla.mindrot.org/show_bug.cgi?id=2863
bool stdoutHUPHack = false;
core::StrictLevel forceMinStrict = core::StrictLevel::Ignore;
core::StrictLevel forceMaxStrict = core::StrictLevel::Strong;
bool showProgress = false;
bool suggestTyped = false;
std::optional<std::string> suggestUnsafe = std::nullopt;
bool silenceErrors = false;
bool silenceDevMessage = false;
bool suppressNonCriticalErrors = false;
bool runLSP = false;
bool disableWatchman = false;
std::string watchmanPath = "watchman";
std::string watchmanPauseStateName;
bool stressIncrementalResolver = false;
std::optional<int> sleepInSlowPathSeconds = std::nullopt;
bool traceLexer = false;
bool traceParser = false;
bool noErrorCount = false;
bool autocorrect = false;
bool didYouMean = true;
bool waitForDebugger = false;
bool censorForSnapshotTests = false;
bool forceHashing = false;
int threads = 0;
int logLevel = 0; // number of time -v was passed
int autogenVersion = 0;
bool uniquelyDefinedBehavior = false;
bool stripePackages = false;
std::string stripePackagesHint = "";
std::vector<std::string> extraPackageFilesDirectoryUnderscorePrefixes;
std::vector<std::string> extraPackageFilesDirectorySlashDeprecatedPrefixes;
std::vector<std::string> extraPackageFilesDirectorySlashPrefixes;
std::vector<std::string> allowRelaxedPackagerChecksFor;
std::vector<std::string> packagerLayers;
std::string typedSource = "";
std::string cacheDir = "";
// This configured both maximum filesystem db size and max virtual memory usage
// Needs to be a multiple of getpagesize(2) which is 4096 by default on macOS and Linux
size_t maxCacheSizeBytes = MAX_CACHE_SIZE_BYTES;
UnorderedMap<std::string, core::StrictLevel> strictnessOverrides;
std::string storeState = "";
bool enableCounters = false;
std::string errorUrlBase = "https://srb.help/";
bool ruby3KeywordArgs = false;
bool typedSuper = true;
std::vector<std::string> suppressPayloadSuperclassRedefinitionFor;
std::set<int> isolateErrorCode;
std::set<int> suppressErrorCode;
bool noErrorSections = false;
/** Prefix to remove from all printed paths. */
std::string pathPrefix;
uint32_t reserveClassTableCapacity = 0;
uint32_t reserveMethodTableCapacity = 0;
uint32_t reserveFieldTableCapacity = 0;
uint32_t reserveTypeArgumentTableCapacity = 0;
uint32_t reserveTypeMemberTableCapacity = 0;
uint32_t reserveUtf8NameTableCapacity = 0;
uint32_t reserveConstantNameTableCapacity = 0;
uint32_t reserveUniqueNameTableCapacity = 0;
/* The maximum number of files that are permitted to typecheck on the fast path concurrently. Not exposed on CLI.
* Placed on Options for convenience so tests can override. */
uint32_t lspMaxFilesOnFastPath = 50;
/* The maximum number of errors to report to the client when in LSP mode. Prevents editor UI slowdown
* related to large error lists. 0 means no limit. */
uint32_t lspErrorCap = 1000;
std::string statsdHost;
std::string statsdPrefix = "ruby_typer.unknown";
int statsdPort = 8200;
std::string metricsFile;
std::string metricsRepo = "none";
std::string metricsPrefix = "ruby_typer.unknown";
std::string metricsBranch = "none";
std::string metricsSha = "none";
std::map<std::string, std::string> metricsExtraTags; // be super careful with cardinality here
bool packageRBIGeneration = false;
std::string dumpPackageInfo = "";
std::string singlePackage = "";
std::string packageRBIDir = "";
std::vector<std::string> packageSkipRBIExportEnforcementDirs;
// Contains the allowed extensions Sorbet can parse.
UnorderedSet<std::string> allowedExtensions;
// Contains the file names passed in to Sorbet.
std::vector<std::string> rawInputFileNames;
// Contains the directory names passed in to Sorbet.
std::vector<std::string> rawInputDirNames;
// Ignore patterns beginning from the root of an input folder.
std::vector<std::string> absoluteIgnorePatterns;
// Ignore patterns that can occur anywhere in a file's path from an input folder.
std::vector<std::string> relativeIgnorePatterns;
// Contains the expanded list of all Ruby file inputs (rawInputFileNames + all Ruby files in rawInputDirNames)
std::vector<std::string> inputFileNames;
// A list of parent classes to be used in `-p autogen-subclasses`
std::vector<std::string> autogenSubclassesParents;
// Ignore patterns beginning from the root of an input folder.
std::vector<std::string> autogenSubclassesAbsoluteIgnorePatterns;
// Ignore patterns that can occur anywhere in a file's path from an input folder.
std::vector<std::string> autogenSubclassesRelativeIgnorePatterns;
// Allow RBI files to define behavior if they are in one of these paths.
std::vector<std::string> autogenBehaviorAllowedInRBIFilesPaths;
// When set, msgpack serialization of references skips extra metadata like inheritance information and expression
// ranges.
bool autogenMsgpackSkipReferenceMetadata;
// List of directories not available editor-side. References to files in these directories should be sent via
// sorbet: URIs to clients that support them.
std::vector<std::string> lspDirsMissingFromClient;
// Path to the executable used for document formatting
std::string rubyfmtPath = "rubyfmt";
// Enable stable-but-not-yet-shipped features suitable for late-stage beta-testing.
bool lspAllBetaFeaturesEnabled = false;
// Booleans enabling various experimental LSP features. Each will be removed once corresponding feature stabilizes.
bool lspDocumentHighlightEnabled = false;
bool lspDocumentFormatRubyfmtEnabled = false;
bool lspSignatureHelpEnabled = false;
bool lspExtractToVariableEnabled = false;
bool forciblySilenceLspMultipleDirError = false;
// Enables out-of-order reference checking
bool outOfOrderReferenceChecksEnabled = false;
core::TrackUntyped trackUntyped = core::TrackUntyped::Nowhere;
// Experimental feature `requires_ancestor`
bool requiresAncestorEnabled = false;
std::string inlineInput; // passed via -e
std::string debugLogFile;
std::string webTraceFile;
std::string inlineRBIInput; // passed via --e-rbi
// Path to an RBI whose contents should be minimized by subtracting parts that Sorbet already
// has a record of in its own GlobalState.
//
// Used primarily by missing_methods.rb / `srb rbi hidden-definitions` to minimize an RBI file
// generated by requiring a codebase and inspecting it via reflection.
std::string minimizeRBI;
std::shared_ptr<FileSystem> fs = std::make_shared<OSFileSystem>();
void flushPrinters();
Options clone() {
Options options(*this);
return options;
};
Options() = default;
Options(Options &&) = default;
Options &operator=(Options &&) = delete;
private:
Options(const Options &) = default;
Options &operator=(const Options &) = default;
};
void readOptions(
Options &, std::vector<std::unique_ptr<pipeline::semantic_extension::SemanticExtension>> &configuredExtensions,
int argc, char *argv[],
const std::vector<pipeline::semantic_extension::SemanticExtensionProvider *> &semanticExtensionProviders,
std::shared_ptr<spdlog::logger> logger) noexcept(false); // throw(EarlyReturnWithCode);
void flushPrinters(Options &);
} // namespace sorbet::realmain::options
#endif // RUBY_TYPER_OPTIONS_H