-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathmessages.ts
More file actions
1122 lines (1035 loc) · 23.8 KB
/
messages.ts
File metadata and controls
1122 lines (1035 loc) · 23.8 KB
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Types for messages exchanged during jsonrpc communication with the
* the CodeQL query server.
*
* This file exists in the queryserver and in the vscode extension, and
* should be kept in sync between them.
*
* A note about the namespaces below, which look like they are
* essentially enums, namely Severity, ResultColumnKind, and
* QueryResultType. By design, for the sake of extensibility, clients
* receiving messages of this protocol are supposed to accept any
* number for any of these types. We commit to the given meaning of
* the numbers listed in constants in the namespaces, and we commit to
* the fact that any unknown QueryResultType value counts as an error.
*/
import * as rpc from 'vscode-jsonrpc';
/**
* A position within a QL file.
*/
export interface Position {
/**
* The one-based index of the start line
*/
line: number;
/**
* The one-based offset of the start column within
* the start line in UTF-16 code-units
*/
column: number;
/**
* The one-based index of the end line line
*/
endLine: number;
/**
* The one-based offset of the end column within
* the end line in UTF-16 code-units
*/
endColumn: number;
/**
* The path of the file.
* If the file name is "Compiler Generated" the
* the position is not a real position but
* arises from compiler generated code.
*/
fileName: string;
}
/**
* A query that should be checked for any errors or warnings
*/
export interface CheckQueryParams {
/**
* The options for compilation, if missing then the default options.
*/
compilationOptions?: CompilationOptions;
/**
* The ql program to check.
*/
queryToCheck: QlProgram;
/**
* The way of compiling a query
*/
target: CompilationTarget;
}
/**
* A query that should compiled into a qlo
*/
export interface CompileQueryParams {
/**
* The options for compilation, if missing then the default options.
*/
compilationOptions?: CompilationOptions;
/**
* The options for compilation that do not affect the result.
*/
extraOptions?: ExtraOptions;
/**
* The ql program to check.
*/
queryToCheck: QlProgram;
/**
* The way of compiling a query
*/
target: CompilationTarget;
/**
* The path to write the qlo at.
*/
resultPath?: string;
}
/**
* A dil (datalog intermediate language) query that should compiled into a qlo
*/
export interface CompileDilParams {
/**
* The options for compilation, if missing then the default options.
*/
compilationOptions?: DilCompilationOptions;
/**
* The options for compilation that do not affect the result.
*/
extraOptions?: ExtraOptions;
/**
* The dil query to compile
*/
dilQuery?: DILQuery;
/**
* The path to write the qlo at.
*/
resultPath?: string;
}
/**
* The options for QL compilation.
*/
export interface CompilationOptions {
/**
* Whether to ensure that elements that do not have a location or URL
* get a default location.
*/
computeNoLocationUrls: boolean;
/**
* Whether to fail if any warnings occur in the ql code.
*/
failOnWarnings: boolean;
/**
* Whether to compile as fast as possible, at the expense
* of optimization.
*/
fastCompilation: boolean;
/**
* Whether to include dil within qlos.
*/
includeDilInQlo: boolean;
/**
* Whether to only do the initial program checks on the subset of the program that
* is used.
*/
localChecking: boolean;
/**
* Whether to disable urls in the results.
*/
noComputeGetUrl: boolean;
/**
* Whether to disable toString values in the results.
*/
noComputeToString: boolean;
/**
* Whether to ensure that elements that do not have a displayString
* get reported anyway. Useful for universal compilation options.
*/
computeDefaultStrings: boolean;
}
/**
* Compilation options that do not affect the result of
* query compilation
*/
export interface ExtraOptions {
/**
* The uris of any additional compilation caches
* TODO: Document cache uri format
*/
extraCompilationCache?: string;
/**
* The compilation timeout in seconds. If it is
* zero then there is no timeout.
*/
timeoutSecs: number;
}
/**
* The DIL compilation options
*/
export interface DilCompilationOptions {
/**
* Whether to compile as fast as possible, at the expense
* of optimization.
*/
fastCompilation: boolean;
/**
* Whether to include dil within qlos.
*/
includeDilInQlo: boolean;
}
/**
* A full ql program
*/
export interface QlProgram {
/**
* The path to the dbscheme
*/
dbschemePath: string;
/**
*The ql library search path
*/
libraryPath: string[];
/**
* The path to the query
*/
queryPath: string;
/**
* If set then the contents of the source files.
* Otherwise they will be searched for on disk.
*/
sourceContents?: QlFileSet;
}
/**
* A representation of files in query with all imports
* pre-resolved.
*/
export interface QlFileSet {
/**
* The files imported by the given file
*/
imports: { [key: string]: string[] };
/**
* An id of each file
*/
nodeNumbering: { [key: string]: number };
/**
* The code for each file
*/
qlCode: { [key: string]: string };
/**
* The resolution of an import in each directory.
*/
resolvedDirImports: { [key: string]: { [key: string]: string } };
}
/**
* An uncompiled dil query
*/
export interface DILQuery {
/**
* The path to the dbscheme
*/
dbschemePath: string;
/**
* The path to the dil file
*/
dilPath: string;
/**
* The dil source
*/
dilSource: string;
}
/**
* The way of compiling the query, as a normal query
* or a subset of it. Note that precisely one of the two options should be set.
*/
export interface CompilationTarget {
/**
* Compile as a normal query
*/
query?: Record<string, never>;
/**
* Compile as a quick evaluation
*/
quickEval?: QuickEvalOptions;
}
/**
* Options for quick evaluation
*/
export interface QuickEvalOptions {
quickEvalPos?: Position;
}
/**
* The result of checking a query.
*/
export interface CheckQueryResult {
/**
* Whether the query came from a compilation cache
*/
fromCache: boolean;
/**
* The errors or warnings that occurred during compilation
*/
messages: CompilationMessage[];
/**
* The types of the query predicates of the query
*/
resultPatterns: ResultPattern[];
}
/**
* A compilation message (either an error or a warning)
*/
export interface CompilationMessage {
/**
* The text of the message
*/
message: string;
/**
* The source position associated with the message
*/
position: Position;
/**
* The severity of the message
*/
severity: Severity;
}
export type Severity = number;
/**
* Severity of different messages. This namespace is intentionally not
* an enum, see "for the sake of extensibility" comment above.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Severity {
/**
* The message is a compilation error.
*/
export const ERROR = 0;
/**
* The message is a compilation warning.
*/
export const WARNING = 1;
}
/**
* The type of a query predicate
*/
export interface ResultPattern {
/**
* The types of the columns of the query predicate
*/
columns: ResultColumn[];
/**
* The name of the query predicate.
* #select" is used as the name of a select clause.
*/
name: string;
}
/**
* The name and type of a single column
*/
export interface ResultColumn {
/**
* The kind of the column. See `ResultColumnKind`
* for the current possible meanings
*/
kind: ResultColumnKind;
/**
* The name of the column.
* This may be compiler generated for complex select expressions.
*/
name: string;
}
export type ResultColumnKind = number;
/**
* The kind of a result column. This namespace is intentionally not an enum, see "for the sake of
* extensibility" comment above.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace ResultColumnKind {
/**
* A column of type `float`
*/
export const FLOAT = 0;
/**
* A column of type `int`
*/
export const INTEGER = 1;
/**
* A column of type `string`
*/
export const STRING = 2;
/**
* A column of type `boolean`
*/
export const BOOLEAN = 3;
/**
* A column of type `date`
*/
export const DATE = 4;
/**
* A column of a non-primitive type
*/
export const ENTITY = 5;
}
/**
* Parameters for compiling an upgrade.
*/
export interface CompileUpgradeParams {
/**
* The parameters for how to compile the upgrades
*/
upgrade: UpgradeParams;
/**
* A directory to store parts of the compiled upgrade
*/
upgradeTempDir: string;
/**
* Enable single file upgrades, set to true to allow
* using single file upgrades.
*/
singleFileUpgrades: true;
}
/**
* Parameters for compiling an upgrade.
*/
export interface CompileUpgradeSequenceParams {
/**
* The sequence of upgrades to compile
*/
upgradePaths: string[];
/**
* A directory to store parts of the compiled upgrade
*/
upgradeTempDir: string;
}
/**
* Parameters describing an upgrade
*/
export interface UpgradeParams {
/**
* The location of non built-in upgrades
*/
additionalUpgrades: string[];
/**
* The path to the current dbscheme to start the upgrade
*/
fromDbscheme: string;
/**
* The path to the target dbscheme to try an upgrade to
*/
toDbscheme: string;
}
/**
* The result of checking an upgrade
*/
export interface CheckUpgradeResult {
/**
* A description of the steps to take to upgrade this dataset.
* Note that the list may be partial.
*/
checkedUpgrades?: UpgradesDescription;
/**
* Any errors that occurred when checking the scripts.
*/
upgradeError?: string;
}
/**
* The result of compiling an upgrade
*/
export interface CompileUpgradeResult {
/**
* The compiled upgrade.
*/
compiledUpgrades?: CompiledUpgrades;
/**
* Any errors that occurred when checking the scripts.
*/
error?: string;
}
export interface CompileUpgradeSequenceResult {
/**
* The compiled upgrades as a single file.
*/
compiledUpgrade?: string;
/**
* Any errors that occurred when checking the scripts.
*/
error?: string;
}
/**
* A description of a upgrade process
*/
export interface UpgradesDescription {
/**
* The initial sha of the dbscheme to upgrade from
*/
initialSha: string;
/**
* A list of description of the steps in the upgrade process.
* Note that this may only upgrade partially
*/
scripts: UpgradeDescription[];
/**
* The sha of the target dataset.
*/
targetSha: string;
}
/**
* The description of a single step
*/
export interface UpgradeDescription {
/**
* The compatibility of the upgrade
*/
compatibility: string;
/**
* A description of the upgrade
*/
description: string;
/**
* The dbscheme sha after this upgrade has run.
*/
newSha: string;
}
export type CompiledUpgrades = MultiFileCompiledUpgrades | SingleFileCompiledUpgrades
/**
* The parts shared by all compiled upgrades
*/
interface CompiledUpgradesBase {
/**
* The initial sha of the dbscheme to upgrade from
*/
initialSha: string;
/**
* The path to the new dataset statistics
*/
newStatsPath: string;
/**
* The sha of the target dataset.
*/
targetSha: string;
}
/**
* A compiled upgrade.
* The upgrade is spread among multiple files.
*/
interface MultiFileCompiledUpgrades extends CompiledUpgradesBase {
/**
* The path to the new dataset dbscheme
*/
newDbscheme: string;
/**
* The steps in the upgrade path
*/
scripts: CompiledUpgradeScript[];
/**
* Will never exist in an old result
*/
compiledUpgradeFile?: never;
}
/**
* A compiled upgrade.
* The upgrade is in a single file.
*/
export interface SingleFileCompiledUpgrades extends CompiledUpgradesBase {
/**
* The steps in the upgrade path
*/
descriptions: UpgradeDescription[];
/**
* A path to a file containing the upgrade
*/
compiledUpgradeFile: string;
}
/**
* A compiled step to upgrade the dataset.
*/
export interface CompiledUpgradeScript {
/**
* A description of the spec
*/
description: UpgradeDescription;
/**
* The path to the dbscheme that this upgrade step
* upgrades to.
*/
newDbschemePath: string;
/**
* The actions required to run this step.
*/
specs: UpgradeAction[];
}
/**
* An action used to upgrade a query.
* Only one of the options should be set
*/
export interface UpgradeAction {
deleted?: DeleteSpec;
runQuery?: QloSpec;
}
/**
* Delete a relation
*/
export interface DeleteSpec {
/**
* The name of the relation to delete
*/
relationToDelete: string;
}
/**
* Run a qlo to provide a relation
*/
export interface QloSpec {
/**
* The name of the relation to create/replace
*/
newRelation: string;
/**
* The Uri of the qlo to run
*/
qloUri: string;
}
/**
* Parameters to clear the cache
*/
export interface ClearCacheParams {
/**
* The dataset for which we want to clear the cache
*/
db: Dataset;
/**
* Whether the cache should actually be cleared.
*/
dryRun: boolean;
}
/**
* Parameters to start a new structured log
*/
export interface StartLogParams {
/**
* The dataset for which we want to start a new structured log
*/
db: Dataset;
/**
* The path where we want to place the new structured log
*/
logPath: string;
}
/**
* Parameters to terminate a structured log
*/
export interface EndLogParams {
/**
* The dataset for which we want to terminated the log
*/
db: Dataset;
/**
* The path of the log to terminate, will be a no-op if we aren't logging here
*/
logPath: string;
}
/**
* Parameters for trimming the cache of a dataset
*/
export interface TrimCacheParams {
/**
* The dataset that we want to trim the cache of.
*/
db: Dataset;
}
/**
* A ql dataset
*/
export interface Dataset {
/**
* The path to the dataset
*/
dbDir: string;
/**
* The name of the working set (normally "default")
*/
workingSet: string;
}
/**
* The result of trimming or clearing the cache.
*/
export interface ClearCacheResult {
/**
* A user friendly message saying what was or would be
* deleted.
*/
deletionMessage: string;
}
/**
* The result of starting a new structured log.
*/
export interface StartLogResult {
/**
* A user friendly message saying what happened.
*/
outcomeMessage: string;
}
/**
* The result of terminating a structured.
*/
export interface EndLogResult {
/**
* A user friendly message saying what happened.
*/
outcomeMessage: string;
}
/**
* Parameters for running a set of queries
*/
export interface EvaluateQueriesParams {
/**
* The dataset to run on
*/
db: Dataset;
/**
* An identifier used in callbacks to identify this run.
*/
evaluateId: number;
/**
* The queries to run
*/
queries: QueryToRun[];
/**
* Whether the evaluator should stop on a non fatal-error
*/
stopOnError: boolean;
/**
* Whether the evaluator should assume this is the final
* run on this dataset before it's cache would be deleted.
*/
useSequenceHint: boolean;
}
export type TemplateDefinitions = { [key: string]: TemplateSource }
export interface MlModel {
/** A URI pointing to the root directory of the model. */
uri: string;
}
/**
* A single query that should be run
*/
export interface QueryToRun {
/**
* The id of this query within the run
*/
id: number;
/**
* A uri pointing to the qlo to run.
*/
qlo: string;
/**
* A uri pointing to the compiled upgrade file.
*/
compiledUpgrade?: string;
/**
* The path where we should save this queries results
*/
resultsPath: string;
/**
* The per stage timeout (0 for no timeout)
*/
timeoutSecs: number;
/**
* Values to set for each template
*/
templateValues?: TemplateDefinitions;
/**
* Whether templates without values in the templateValues
* map should be set to the empty set or give an error.
*/
allowUnknownTemplates: boolean;
/**
* The list of ML models that should be made available
* when evaluating the query.
*/
availableMlModels?: MlModel[];
}
/**
* The source of templates. Only one
*/
export interface TemplateSource {
/**
* Do basic interpretation of query results and
* use the interpreted results in the query.
* This should only be used to support legacy filter
* queries.
*/
interpretedInput?: ProblemResults;
/**
* Use the explicitly listed values
*/
values?: RelationValues;
}
/**
* A relation as a list of tuples
*/
export interface RelationValues {
tuples: Value[][];
}
/**
* A single primitive value for templates.
* Only one case should be set.
*/
export interface Value {
booleanValue?: boolean;
dateValue?: string;
doubleValue?: number;
intValue?: number;
stringValue?: string;
}
/**
* A relation made by interpreting the results of a problem or metric query
* to be used as the input to a filter query.
*/
export interface ProblemResults {
/**
* The path to the original query.
*/
queryPath: string;
/**
* The way of obtaining the queries
*/
results: ResultSet;
/**
* Whether the results are for a defect filter or a metric filter.
*/
type: ResultType;
}
/**
* The type of results that are going to be sent into the filter query.
*/
export enum ResultType {
METRIC = 0,
DEFECT = 1,
}
/**
* The way of obtaining the results
*/
export interface ResultSet {
/**
* Via an earlier query in the evaluation run
*/
precedingQuery?: number;
/**
* Directly from an existing results set.
*/
resultsFile?: string;
}
/**
* The type returned when the evaluation is complete
*/
export type EvaluationComplete = Record<string, never>;
/**
* The result of a single query
*/
export interface EvaluationResult {
/**
* The id of the run that this query was in
*/
runId: number;
/**
* The id of the query within the run
*/
queryId: number;
/**
* The type of the result. See QueryResultType for
* possible meanings. Any other result should be interpreted as an error.
*/
resultType: QueryResultType;
/**
* The wall clock time it took to evaluate the query.
* The time is from when we initially tried to evaluate the query
* to when we get the results. Hence with parallel evaluation the times may
* look odd.
*/
evaluationTime: number;
/**
* An error message if an error happened
*/
message?: string;
/**
* Full path to file with all log messages emitted while this query was active, if one exists
*/
logFileLocation?: string;
}
export type QueryResultType = number;
/**
* The result of running a query. This namespace is intentionally not
* an enum, see "for the sake of extensibility" comment above.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace QueryResultType {
/**
* The query ran successfully
*/
export const SUCCESS = 0;
/**
* The query failed due to an reason
* that isn't listed
*/
export const OTHER_ERROR = 1;
/**
* The query failed due to running out of
* memory
*/
export const OOM = 2;
/**
* The query failed due to exceeding the timeout
*/
export const TIMEOUT = 3;
/**
* The query failed because it was cancelled.
*/
export const CANCELLATION = 4;
}
/**
* Parameters for running an upgrade
*/
export interface RunUpgradeParams {
/**
* The dataset to upgrade
*/
db: Dataset;
/**
* The per stage timeout in seconds. Use 0
* for no timeout.
*/
timeoutSecs: number;
/**
* The upgrade to run
*/
toRun: CompiledUpgrades;
}
/**
* The result of running an upgrade
*/
export interface RunUpgradeResult {
/**
* The type of the result. See QueryResultType for
* possible meanings. Any other result should be interpreted as an error.
*/
resultType: QueryResultType;
/**
* The error message if an error occurred
*/
error?: string;
/**
* The new dbscheme sha.
*/
finalSha: string;
}
export interface RegisterDatabasesParams {
databases: Dataset[];
}
export interface DeregisterDatabasesParams {
databases: Dataset[];
}