|
@@ -4,10 +4,147 @@
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
import * as mode from './jsonMode';
|
|
|
-import { Emitter, IEvent, languages } from '../../fillers/monaco-editor-core';
|
|
|
+import { Emitter, IEvent, languages, Uri } from 'monaco-editor-core';
|
|
|
+
|
|
|
+// ---- JSON service types ----
|
|
|
+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;
|
|
|
+}
|
|
|
|
|
|
-// --- JSON configuration and defaults ---------
|
|
|
+export type ASTNode =
|
|
|
+ | ObjectASTNode
|
|
|
+ | PropertyASTNode
|
|
|
+ | ArrayASTNode
|
|
|
+ | StringASTNode
|
|
|
+ | NumberASTNode
|
|
|
+ | BooleanASTNode
|
|
|
+ | NullASTNode;
|
|
|
+
|
|
|
+export type JSONDocument = {
|
|
|
+ root: ASTNode | undefined;
|
|
|
+ getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
|
|
|
+};
|
|
|
+
|
|
|
+export type JSONSchemaRef = JSONSchema | boolean;
|
|
|
|
|
|
+export interface JSONSchemaMap {
|
|
|
+ [name: string]: JSONSchemaRef;
|
|
|
+}
|
|
|
+
|
|
|
+export interface JSONSchema {
|
|
|
+ id?: string;
|
|
|
+ $id?: string;
|
|
|
+ $schema?: string;
|
|
|
+ type?: string | string[];
|
|
|
+ title?: string;
|
|
|
+ default?: any;
|
|
|
+ definitions?: {
|
|
|
+ [name: string]: JSONSchema;
|
|
|
+ };
|
|
|
+ description?: string;
|
|
|
+ properties?: JSONSchemaMap;
|
|
|
+ patternProperties?: JSONSchemaMap;
|
|
|
+ additionalProperties?: boolean | JSONSchemaRef;
|
|
|
+ minProperties?: number;
|
|
|
+ maxProperties?: number;
|
|
|
+ dependencies?:
|
|
|
+ | JSONSchemaMap
|
|
|
+ | {
|
|
|
+ [prop: string]: string[];
|
|
|
+ };
|
|
|
+ items?: JSONSchemaRef | JSONSchemaRef[];
|
|
|
+ minItems?: number;
|
|
|
+ maxItems?: number;
|
|
|
+ uniqueItems?: boolean;
|
|
|
+ additionalItems?: boolean | JSONSchemaRef;
|
|
|
+ pattern?: string;
|
|
|
+ minLength?: number;
|
|
|
+ maxLength?: number;
|
|
|
+ minimum?: number;
|
|
|
+ maximum?: number;
|
|
|
+ exclusiveMinimum?: boolean | number;
|
|
|
+ exclusiveMaximum?: boolean | number;
|
|
|
+ multipleOf?: number;
|
|
|
+ required?: string[];
|
|
|
+ $ref?: string;
|
|
|
+ anyOf?: JSONSchemaRef[];
|
|
|
+ allOf?: JSONSchemaRef[];
|
|
|
+ oneOf?: JSONSchemaRef[];
|
|
|
+ not?: JSONSchemaRef;
|
|
|
+ enum?: any[];
|
|
|
+ format?: string;
|
|
|
+ const?: any;
|
|
|
+ contains?: JSONSchemaRef;
|
|
|
+ propertyNames?: JSONSchemaRef;
|
|
|
+ examples?: any[];
|
|
|
+ $comment?: string;
|
|
|
+ if?: JSONSchemaRef;
|
|
|
+ then?: JSONSchemaRef;
|
|
|
+ else?: JSONSchemaRef;
|
|
|
+ defaultSnippets?: {
|
|
|
+ label?: string;
|
|
|
+ description?: string;
|
|
|
+ markdownDescription?: string;
|
|
|
+ body?: any;
|
|
|
+ bodyText?: string;
|
|
|
+ }[];
|
|
|
+ errorMessage?: string;
|
|
|
+ patternErrorMessage?: string;
|
|
|
+ deprecationMessage?: string;
|
|
|
+ enumDescriptions?: string[];
|
|
|
+ markdownEnumDescriptions?: string[];
|
|
|
+ markdownDescription?: string;
|
|
|
+ doNotSuggest?: boolean;
|
|
|
+ suggestSortText?: string;
|
|
|
+ allowComments?: boolean;
|
|
|
+ allowTrailingCommas?: boolean;
|
|
|
+}
|
|
|
+
|
|
|
+export interface MatchingSchema {
|
|
|
+ node: ASTNode;
|
|
|
+ schema: JSONSchema;
|
|
|
+}
|
|
|
+
|
|
|
+// --- JSON configuration and defaults ---------
|
|
|
export interface DiagnosticsOptions {
|
|
|
/**
|
|
|
* If set, the validator will be enabled and perform syntax and schema based validation,
|
|
@@ -197,8 +334,16 @@ export const jsonDefaults: LanguageServiceDefaults = new LanguageServiceDefaults
|
|
|
modeConfigurationDefault
|
|
|
);
|
|
|
|
|
|
+export interface IJSONWorker {
|
|
|
+ parseJSONDocument(uri: string): Promise<JSONDocument | null>;
|
|
|
+ getMatchingSchemas(uri: string): Promise<MatchingSchema[]>;
|
|
|
+}
|
|
|
+
|
|
|
+export const getWorker = (): Promise<(...uris: Uri[]) => Promise<IJSONWorker>> =>
|
|
|
+ getMode().then((mode) => mode.getWorker());
|
|
|
+
|
|
|
// export to the global based API
|
|
|
-(<any>languages).json = { jsonDefaults };
|
|
|
+(<any>languages).json = { jsonDefaults, getWorker };
|
|
|
|
|
|
// --- Registration to monaco editor ---
|
|
|
|