Skip to content

Commit db25e42

Browse files
authored
Complete Meta Model (#930)
* Make LSPAny work * Generate SemanticToken enums and LSPErrorCodes * Add missing types to meta model * Support for ErrorCodes
1 parent 74206ed commit db25e42

11 files changed

Lines changed: 629 additions & 78 deletions

File tree

client/src/common/notebook.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function ensure<T, K extends keyof T>(target: T, key: K): T[K] {
2727
return target[key];
2828
}
2929

30-
type LSPObject = { [key: string]: LSPAny };
31-
type LSPArray = LSPAny[];
30+
type $LSPObject = { [key: string]: LSPAny };
31+
type $LSPArray = LSPAny[];
3232

3333
namespace Converter {
3434
export namespace c2p {
@@ -48,7 +48,7 @@ namespace Converter {
4848
export function asNotebookCells(cells: vscode.NotebookCell[], base: _c2p.Converter): proto.NotebookCell[] {
4949
return cells.map(cell => asNotebookCell(cell, base));
5050
}
51-
export function asMetadata(metadata: { [key: string]: any}): LSPObject {
51+
export function asMetadata(metadata: { [key: string]: any}): $LSPObject {
5252
const seen: Set<any> = new Set();
5353
return deepCopy(seen, metadata);
5454
}
@@ -73,14 +73,14 @@ namespace Converter {
7373
return proto.NotebookCellKind.Code;
7474
}
7575
}
76-
function deepCopy(seen: Set<any>, value: {[key: string]: any}): LSPObject;
77-
function deepCopy(seen: Set<any>, value: any[]): LSPArray;
78-
function deepCopy(seen: Set<any>, value: {[key: string]: any} | any[]): LSPArray | LSPObject {
76+
function deepCopy(seen: Set<any>, value: {[key: string]: any}): $LSPObject;
77+
function deepCopy(seen: Set<any>, value: any[]): $LSPArray;
78+
function deepCopy(seen: Set<any>, value: {[key: string]: any} | any[]): $LSPArray | $LSPObject {
7979
if (seen.has(value)) {
8080
throw new Error(`Can't deep copy cyclic structures.`);
8181
}
8282
if (Array.isArray(value)) {
83-
const result: LSPArray = [];
83+
const result: $LSPArray = [];
8484
for (const elem of value) {
8585
if (elem !== null && typeof elem === 'object' || Array.isArray(elem)) {
8686
result.push(deepCopy(seen, elem));
@@ -94,7 +94,7 @@ namespace Converter {
9494
return result;
9595
} else {
9696
const props = Object.keys(value);
97-
const result: LSPObject = Object.create(null);
97+
const result: $LSPObject = Object.create(null);
9898
for (const prop of props) {
9999
const elem = value[prop];
100100
if (elem !== null && typeof elem === 'object' || Array.isArray(elem)) {
@@ -258,7 +258,7 @@ namespace $NotebookCell {
258258
}
259259
for (let i = 0; i < oneKeys.length; i++) {
260260
const prop = oneKeys[i];
261-
if (!equalsMetadata((one as LSPObject)[prop], (other as LSPObject)[prop])) {
261+
if (!equalsMetadata((one as $LSPObject)[prop], (other as $LSPObject)[prop])) {
262262
return false;
263263
}
264264
}

jsonrpc/src/common/messages.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ export interface RequestMessage extends Message {
3838
*/
3939
export namespace ErrorCodes {
4040
// Defined by JSON RPC
41-
export const ParseError: number = -32700;
42-
export const InvalidRequest: number = -32600;
43-
export const MethodNotFound: number = -32601;
44-
export const InvalidParams: number = -32602;
45-
export const InternalError: number = -32603;
41+
export const ParseError: -32700 = -32700;
42+
export const InvalidRequest: -32600 = -32600;
43+
export const MethodNotFound: -32601 = -32601;
44+
export const InvalidParams: -32602 = -32602;
45+
export const InternalError: -32603 = -32603;
4646

4747
/**
4848
* This is the start range of JSON RPC reserved error codes.
@@ -53,30 +53,32 @@ export namespace ErrorCodes {
5353
*
5454
* @since 3.16.0
5555
*/
56-
export const jsonrpcReservedErrorRangeStart: number = -32099;
56+
export const jsonrpcReservedErrorRangeStart: -32099 = -32099;
5757
/** @deprecated use jsonrpcReservedErrorRangeStart */
58-
export const serverErrorStart: number = jsonrpcReservedErrorRangeStart;
58+
export const serverErrorStart: -32099 = /* jsonrpcReservedErrorRangeStart */ -32099;
5959

60-
export const MessageWriteError: number = -32099;
61-
export const MessageReadError: number = -32098;
60+
export const MessageWriteError: -32099 = -32099;
61+
export const MessageReadError: -32098 = -32098;
6262

6363
/**
6464
* Error code indicating that a server received a notification or
6565
* request before the server has received the `initialize` request.
6666
*/
67-
export const ServerNotInitialized: number = -32002;
68-
export const UnknownErrorCode: number = -32001;
67+
export const ServerNotInitialized: -32002 = -32002;
68+
export const UnknownErrorCode: -32001 = -32001;
6969

7070
/**
7171
* This is the end range of JSON RPC reserved error codes.
7272
* It doesn't denote a real error code.
7373
*
7474
* @since 3.16.0
7575
*/
76-
export const jsonrpcReservedErrorRangeEnd = -32000;
76+
export const jsonrpcReservedErrorRangeEnd: -32000 = -32000;
7777
/** @deprecated use jsonrpcReservedErrorRangeEnd */
78-
export const serverErrorEnd: number = jsonrpcReservedErrorRangeEnd;
78+
export const serverErrorEnd: -32000 = /* jsonrpcReservedErrorRangeEnd */ -32000;
7979
}
80+
type integer = number;
81+
export type ErrorCodes= integer;
8082

8183
export interface ResponseErrorLiteral<D = void> {
8284
/**

0 commit comments

Comments
 (0)