-
Notifications
You must be signed in to change notification settings - Fork 113
/
jsonLanguageTypes.ts
327 lines (298 loc) · 10 KB
/
jsonLanguageTypes.ts
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
import { JSONSchema } from './jsonSchema';
import {
Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange,
Diagnostic, DiagnosticSeverity,
CompletionItem, CompletionItemKind, CompletionList, Position,
InsertTextFormat, MarkupContent,
SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions, DefinitionLink
} from 'vscode-languageserver-types';
import { TextDocument } from 'vscode-languageserver-textdocument';
export {
TextDocument,
Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector,
Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange,
Diagnostic, DiagnosticSeverity,
CompletionItem, CompletionItemKind, CompletionList, Position,
InsertTextFormat, MarkupContent, MarkupKind, DefinitionLink,
SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions
};
/**
* Error codes used by diagnostics
*/
export enum ErrorCode {
Undefined = 0,
EnumValueMismatch = 1,
Deprecated = 2,
UnexpectedEndOfComment = 0x101,
UnexpectedEndOfString = 0x102,
UnexpectedEndOfNumber = 0x103,
InvalidUnicode = 0x104,
InvalidEscapeCharacter = 0x105,
InvalidCharacter = 0x106,
PropertyExpected = 0x201,
CommaExpected = 0x202,
ColonExpected = 0x203,
ValueExpected = 0x204,
CommaOrCloseBacketExpected = 0x205,
CommaOrCloseBraceExpected = 0x206,
TrailingComma = 0x207,
DuplicateKey = 0x208,
CommentNotPermitted = 0x209,
SchemaResolveError = 0x300
}
export type ASTNode = ObjectASTNode | PropertyASTNode | ArrayASTNode | StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode;
export interface BaseASTNode {
readonly type: 'object' | 'array' | 'property' | 'string' | 'number' | 'boolean' | 'null';
readonly parent?: ASTNode;
readonly offset: number;
readonly length: number;
readonly children?: ASTNode[];
readonly value?: string | boolean | number | null;
}
export interface ObjectASTNode extends BaseASTNode {
readonly type: 'object';
readonly properties: PropertyASTNode[];
readonly children: ASTNode[];
}
export interface PropertyASTNode extends BaseASTNode {
readonly type: 'property';
readonly keyNode: StringASTNode;
readonly valueNode?: ASTNode;
readonly colonOffset?: number;
readonly children: ASTNode[];
}
export interface ArrayASTNode extends BaseASTNode {
readonly type: 'array';
readonly items: ASTNode[];
readonly children: ASTNode[];
}
export interface StringASTNode extends BaseASTNode {
readonly type: 'string';
readonly value: string;
}
export interface NumberASTNode extends BaseASTNode {
readonly type: 'number';
readonly value: number;
readonly isInteger: boolean;
}
export interface BooleanASTNode extends BaseASTNode {
readonly type: 'boolean';
readonly value: boolean;
}
export interface NullASTNode extends BaseASTNode {
readonly type: 'null';
readonly value: null;
}
export interface MatchingSchema {
node: ASTNode;
schema: JSONSchema;
}
export interface LanguageSettings {
/**
* If set, the validator will return syntax and semantic errors.
*/
validate?: boolean;
/**
* Defines whether comments are allowed or not. If set to false, comments will be reported as errors.
* DocumentLanguageSettings.allowComments will override this setting.
*/
allowComments?: boolean;
/**
* A list of known schemas and/or associations of schemas to file names.
*/
schemas?: SchemaConfiguration[];
}
export type SeverityLevel = 'error' | 'warning' | 'ignore';
export interface DocumentLanguageSettings {
/**
* The severity of reported comments. If not set, 'LanguageSettings.allowComments' defines whether comments are ignored or reported as errors.
*/
comments?: SeverityLevel;
/**
* The severity of reported trailing commas. If not set, trailing commas will be reported as errors.
*/
trailingCommas?: SeverityLevel;
/**
* The severity of problems from schema validation. If set to 'ignore', schema validation will be skipped. If not set, 'warning' is used.
*/
schemaValidation?: SeverityLevel;
/**
* The severity of problems that occurred when resolving and loading schemas. If set to 'ignore', schema resolving problems are not reported. If not set, 'warning' is used.
*/
schemaRequest?: SeverityLevel;
}
export interface SchemaConfiguration {
/**
* The URI of the schema, which is also the identifier of the schema.
*/
uri: string;
/**
* A list of file path patterns that are associated to the schema. The '*' wildcard can be used. Exclusion patterns starting with '!'.
* For example '*.schema.json', 'package.json', '!foo*.schema.json'.
* A match succeeds when there is at least one pattern matching and last matching pattern does not start with '!'.
*/
fileMatch?: string[];
/**
* The schema for the given URI.
* If no schema is provided, the schema will be fetched with the schema request service (if available).
*/
schema?: JSONSchema;
}
export interface WorkspaceContextService {
resolveRelativePath(relativePath: string, resource: string): string;
}
/**
* The schema request service is used to fetch schemas. The result should the schema file comment, or,
* in case of an error, a displayable error string
*/
export interface SchemaRequestService {
(uri: string): Thenable<string>;
}
export interface PromiseConstructor {
/**
* Creates a new Promise.
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | Thenable<T>) => void, reject: (reason?: any) => void) => void): Thenable<T>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: Array<T | Thenable<T>>): Thenable<T[]>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject<T>(reason: any): Thenable<T>;
/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>(value: T | Thenable<T>): Thenable<T>;
}
export interface Thenable<R> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
}
export interface LanguageServiceParams {
/**
* The schema request service is used to fetch schemas from a URI. The provider returns the schema file content, or,
* in case of an error, a displayable error string
*/
schemaRequestService?: SchemaRequestService;
/**
* The workspace context is used to resolve relative paths for relative schema references.
*/
workspaceContext?: WorkspaceContextService;
/**
* An optional set of completion and hover participants.
*/
contributions?: JSONWorkerContribution[];
/**
* A promise constructor. If not set, the ES5 Promise will be used.
*/
promiseConstructor?: PromiseConstructor;
/**
* Describes the LSP capabilities the client supports.
*/
clientCapabilities?: ClientCapabilities;
}
/**
* Describes what LSP capabilities the client supports
*/
export interface ClientCapabilities {
/**
* The text document client capabilities
*/
textDocument?: {
/**
* Capabilities specific to completions.
*/
completion?: {
/**
* The client supports the following `CompletionItem` specific
* capabilities.
*/
completionItem?: {
/**
* Client supports the follow content formats for the documentation
* property. The order describes the preferred format of the client.
*/
documentationFormat?: MarkupKind[];
/**
* The client supports commit characters on a completion item.
*/
commitCharactersSupport?: boolean
};
};
/**
* Capabilities specific to hovers.
*/
hover?: {
/**
* Client supports the follow content formats for the content
* property. The order describes the preferred format of the client.
*/
contentFormat?: MarkupKind[];
};
};
}
export namespace ClientCapabilities {
export const LATEST: ClientCapabilities = {
textDocument: {
completion: {
completionItem: {
documentationFormat: [MarkupKind.Markdown, MarkupKind.PlainText],
commitCharactersSupport: true
}
}
}
};
}
export interface FoldingRangesContext {
/**
* The maximal number of ranges returned.
*/
rangeLimit?: number;
/**
* Called when the result was cropped.
*/
onRangeLimitExceeded?: (uri: string) => void;
}
export interface DocumentSymbolsContext {
/**
* The maximal number of document symbols returned.
*/
resultLimit?: number;
/**
* Called when the result was cropped.
*/
onResultLimitExceeded?: (uri: string) => void;
}
export interface ColorInformationContext {
/**
* The maximal number of color informations returned.
*/
resultLimit?: number;
/**
* Called when the result was cropped.
*/
onResultLimitExceeded?: (uri: string) => void;
}