Skip to content

Commit c15b1cd

Browse files
committed
Add more types and documentation to protocol file
Reduce the chances that someone reading this file forgets the intent of the extensible 'enum' namespaces by redundantly putting it loudly at the beginning. Add some eponymous type aliases for these 'enum' types so that code can refer to them.
1 parent dfab590 commit c15b1cd

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

extensions/ql-vscode/src/messages.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
/**
22
* Types for messages exchanged during jsonrpc communication with the
33
* the CodeQL query server.
4+
*
5+
* This file exists in the queryserver and in the vscode extension, and
6+
* should be kept in sync between them.
7+
*
8+
* A note about the namespaces below, which look like they are
9+
* essentially enums, namely Severity, ResultColumnKind, and
10+
* QueryResultType. By design, for the sake of extensibility, clients
11+
* receiving messages of this protocol are supposed to accept any
12+
* number for any of these types. We commit to the given meaning of
13+
* the numbers listed in constants in the namespaces, and we commit to
14+
* the fact that any unknown QueryResultType value counts as an error.
415
*/
516

617
import * as rpc from 'vscode-jsonrpc';
@@ -294,10 +305,13 @@ export interface CompilationMessage {
294305
/**
295306
* The severity of the message
296307
*/
297-
severity: number;
308+
severity: Severity;
298309
}
310+
311+
export type Severity = number;
299312
/**
300-
* Severity of different messages
313+
* Severity of different messages. This namespace is intentionally not
314+
* an enum, see "for the sake of extensibility" comment above.
301315
*/
302316
export namespace Severity {
303317
/**
@@ -333,16 +347,18 @@ export interface ResultColumn {
333347
* The kind of the column. See `ResultColumnKind`
334348
* for the current possible meanings
335349
*/
336-
kind: number;
350+
kind: ResultColumnKind;
337351
/**
338352
* The name of the column.
339353
* This may be compiler generated for complex select expressions.
340354
*/
341355
name: string;
342356
}
343357

358+
export type ResultColumnKind = number;
344359
/**
345-
* The kind of a result column.
360+
* The kind of a result column. This namespace is intentionally not an enum, see "for the sake of
361+
* extensibility" comment above.
346362
*/
347363
export namespace ResultColumnKind {
348364
/**
@@ -748,7 +764,7 @@ export interface EvaluationResult {
748764
* The type of the result. See QueryResultType for
749765
* possible meanings. Any other result should be interpreted as an error.
750766
*/
751-
resultType: number;
767+
resultType: QueryResultType;
752768
/**
753769
* The wall clock time it took to evaluate the query.
754770
* The time is from when we initially tried to evaluate the query
@@ -762,8 +778,10 @@ export interface EvaluationResult {
762778
message?: string;
763779
}
764780

781+
export type QueryResultType = number;
765782
/**
766-
* The result of running a query,
783+
* The result of running a query. This namespace is intentionally not
784+
* an enum, see "for the sake of extensibility" comment above.
767785
*/
768786
export namespace QueryResultType {
769787
/**
@@ -818,7 +836,7 @@ export interface RunUpgradeResult {
818836
* The type of the result. See QueryResultType for
819837
* possible meanings. Any other result should be interpreted as an error.
820838
*/
821-
resultType: number;
839+
resultType: QueryResultType;
822840
/**
823841
* The error message if an error occurred
824842
*/

0 commit comments

Comments
 (0)