import type { DiagnosticRelatedInformation } from 'vscode-languageserver-types'; import type { JSONSchemaDescription, JSONSchemaDescriptionExt } from '../../requestTypes.js'; import type { SettingsState } from '../../yamlSettings.js'; import type { PromiseConstructor, SchemaConfiguration } from '../jsonLanguageTypes.js'; import type { JSONSchema } from '../jsonSchema.js'; import type { JSONDocument } from '../parser/jsonDocument.js'; import type { SchemaRequestService, WorkspaceContextService } from '../yamlLanguageService.js'; import type { SchemaVersions } from '../yamlTypes.js'; import { ErrorCode, SchemaDraft } from '../jsonLanguageTypes.js'; import { SchemaPriority } from '../yamlLanguageService.js'; export declare type CustomSchemaProvider = (uri: string) => Promise; export declare enum MODIFICATION_ACTIONS { delete = 0, add = 1, deleteAll = 2 } export interface SchemaAdditions { schema: string; action: MODIFICATION_ACTIONS.add; path: string; key: string; content: any; } export interface SchemaDeletions { schema: string; action: MODIFICATION_ACTIONS.delete; path: string; key: string; } export interface SchemaDeletionsAll { schemas: string[]; action: MODIFICATION_ACTIONS.deleteAll; } export interface IJSONSchemaService { /** * Clears all cached schema files */ clearExternalSchemas(): void; /** * Registers contributed schemas */ setSchemaContributions(schemaContributions: ISchemaContributions): void; /** * Registers an external schema */ registerExternalSchema(config: SchemaConfiguration | string, filePatterns?: string[], unresolvedSchemaContent?: JSONSchema): SchemaHandle; /** * Looks up the appropriate schema for the given URI */ getSchemaForResource(resource: string, document?: JSONDocument): PromiseLike; /** * Looks up schema URIs for the given URI */ getSchemaURIsForResource(resource: string, document?: JSONDocument): string[]; /** * Returns all registered schema ids */ getRegisteredSchemaIds(filter?: (scheme: string) => boolean): string[]; } export interface SchemaAssociation { pattern: string[]; uris: string[]; folderUri?: string; } export interface ISchemaContributions { schemas?: { [id: string]: JSONSchema; }; schemaAssociations?: SchemaAssociation[]; } export interface ISchemaHandle { /** * The schema id */ uri: string; /** * The schema from the file, with potential $ref references */ getUnresolvedSchema(): PromiseLike; /** * The schema from the file, with references resolved */ getResolvedSchema(): PromiseLike; } export declare class FilePatternAssociation { private readonly folderUri; readonly uris: string[]; private readonly isMatch; private readonly isNegMatch; constructor(pattern: string[], folderUri: string | undefined, uris: string[]); matchesPattern(fileName: string): boolean; getURIs(): string[]; } export type SchemaDependencies = { [uri: string]: boolean; }; export interface SchemaHandleService { readonly promise: PromiseConstructor; loadSchema(url: string): PromiseLike; resolveSchemaContent(schemaToResolve: UnresolvedSchema, schemaURL: string, dependencies: SchemaDependencies): PromiseLike; } /** How long a failed schema load is remembered, in milliseconds. */ export declare const FAILED_SCHEMA_CACHE_MS = 5000; export declare class SchemaHandle implements ISchemaHandle { readonly uri: string; dependencies: SchemaDependencies; anchors: Map | undefined; private resolvedSchema; private unresolvedSchema; /** When the cached load failed, or undefined if it succeeded or has not been attempted. */ private failedAt; private readonly service; constructor(service: SchemaHandleService, uri: string, unresolvedSchemaContent?: JSONSchema); /** * Whether a previously cached failure has been held long enough that the schema is worth requesting again. * @returns true when the cached failure has expired */ private isFailureExpired; getUnresolvedSchema(): PromiseLike; getResolvedSchema(): PromiseLike; clearSchema(): boolean; } export declare class UnresolvedSchema { readonly schema: JSONSchema; readonly errors: SchemaDiagnostic[]; uri?: string; constructor(schema: JSONSchema, errors?: SchemaDiagnostic[]); } export type SchemaDiagnostic = { readonly message: string; readonly code: ErrorCode; relatedInformation?: DiagnosticRelatedInformation[]; }; export declare class ResolvedSchema { readonly schema: JSONSchema; readonly errors: SchemaDiagnostic[]; readonly warnings: SchemaDiagnostic[]; readonly schemaDraft: SchemaDraft | undefined; constructor(schema: JSONSchema, errors?: SchemaDiagnostic[], warnings?: SchemaDiagnostic[], schemaDraft?: SchemaDraft); getSection(path: string[]): JSONSchema | undefined; private getSectionRecursive; } export declare class YAMLSchemaService implements IJSONSchemaService { private contributionSchemas; private contributionAssociations; private schemasById; private filePatternAssociations; private registeredSchemasIds; private contextService; private callOnDispose; private requestService; private promiseConstructor; private cachedSchemaForResource; private customSchemaProvider; private yamlSettings; schemaPriorityMapping: Map>; private schemaUriToNameAndDescription; constructor(requestService: SchemaRequestService, contextService?: WorkspaceContextService, promiseConstructor?: PromiseConstructor, yamlSettings?: SettingsState); registerCustomSchemaProvider(customSchemaProvider: CustomSchemaProvider): void; getAllSchemas(): JSONSchemaDescriptionExt[]; private collectSchemaNodes; private schemaMapValues; private resolveSchemaRef; private resolveModelineSchema; private resolveDollarSchema; private getSchemaCandidatesForResource; private getSchemaIdsForResource; getSchemaDescriptionsForResource(resource: string, doc: JSONDocument): Promise; resolveSchemaContent(schemaToResolve: UnresolvedSchema, schemaURL: string, dependencies: SchemaDependencies): Promise; getSchemaForResource(resource: string, doc: JSONDocument): Promise; private finalizeResolvedSchema; addSchemaPriority(uri: string, priority: number): void; /** * Search through all the schemas and find the ones with the highest priority */ private highestPrioritySchemas; private resolveCustomSchema; /** * Save a schema with schema ID and schema content. * Overrides previous schemas set for that schema ID. */ saveSchema(schemaId: string, schemaContent: JSONSchema): Promise; /** * Delete schemas on specific path */ deleteSchemas(deletions: SchemaDeletionsAll): Promise; /** * Delete a schema with schema ID. */ deleteSchema(schemaId: string): Promise; /** * Add content to a specified schema at a specified path */ addContent(additions: SchemaAdditions): Promise; /** * Delete content in a specified schema at a specified path */ deleteContent(deletions: SchemaDeletions): Promise; /** * Take a JSON Schema and the path that you would like to get to * @returns the JSON Schema resolved at that specific path */ private resolveJSONSchemaToSection; /** * Resolve the next Object if they have compatible types * @param object a location in the JSON Schema * @param token the next token that you want to search for */ private resolveNext; get promise(): PromiseConstructor; dispose(): void; private addSchemaHandle; private getOrAddSchemaHandle; private addFilePatternAssociation; private createCombinedSchema; private getAssociatedSchemas; getSchemaURIsForResource(resource: string, document?: JSONDocument): string[]; private loadJSONSchema; loadYAMLSchema(url: string, content: string): Promise; loadSchema(schemaUri: string): Promise; registerExternalSchema(uri: string, filePatterns?: string[], unresolvedSchema?: JSONSchema, name?: string, description?: string, versions?: SchemaVersions): SchemaHandle; clearExternalSchemas(): void; setSchemaContributions(schemaContributions: ISchemaContributions): void; getRegisteredSchemaIds(filter?: (scheme: string) => boolean): string[]; getResolvedSchema(schemaId: string): Promise; onResourceChange(uri: string): boolean; } /** * Extracts a concise, human-readable reason from a schema request failure. * @param error the value thrown by the request, an Error or a string * @returns the reason to report, or an empty string when none can be determined */ export declare function toLoadErrorReason(error: unknown): string;