yaml-language-server
Version:
216 lines (215 loc) • 8.36 kB
TypeScript
import type { DiagnosticRelatedInformation } from 'vscode-languageserver-types';
import type { JSONSchemaDescription, JSONSchemaDescriptionExt } from '../../requestTypes';
import type { SettingsState } from '../../yamlSettings';
import type { PromiseConstructor, SchemaConfiguration } from '../jsonLanguageTypes';
import type { JSONSchema } from '../jsonSchema';
import type { JSONDocument } from '../parser/jsonDocument';
import type { SchemaRequestService, WorkspaceContextService } from '../yamlLanguageService';
import type { SchemaVersions } from '../yamlTypes';
import { ErrorCode, SchemaDraft } from '../jsonLanguageTypes';
import { SchemaPriority } from '../yamlLanguageService';
export declare type CustomSchemaProvider = (uri: string) => Promise<string | string[]>;
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<ResolvedSchema | undefined>;
/**
* 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<UnresolvedSchema>;
/**
* The schema from the file, with references resolved
*/
getResolvedSchema(): PromiseLike<ResolvedSchema>;
}
export declare class FilePatternAssociation {
private readonly folderUri;
readonly uris: string[];
private readonly isMatch;
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<UnresolvedSchema>;
resolveSchemaContent(schemaToResolve: UnresolvedSchema, schemaURL: string, dependencies: SchemaDependencies): PromiseLike<ResolvedSchema>;
}
export declare class SchemaHandle implements ISchemaHandle {
readonly uri: string;
dependencies: SchemaDependencies;
anchors: Map<string, JSONSchema> | undefined;
private resolvedSchema;
private unresolvedSchema;
private readonly service;
constructor(service: SchemaHandleService, uri: string, unresolvedSchemaContent?: JSONSchema);
getUnresolvedSchema(): PromiseLike<UnresolvedSchema>;
getResolvedSchema(): PromiseLike<ResolvedSchema>;
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<string, Set<SchemaPriority>>;
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 getSchemaIdsForResource;
getSchemaDescriptionsForResource(resource: string, doc: JSONDocument): Promise<JSONSchemaDescription[]>;
resolveSchemaContent(schemaToResolve: UnresolvedSchema, schemaURL: string, dependencies: SchemaDependencies): Promise<ResolvedSchema>;
getSchemaForResource(resource: string, doc: JSONDocument): Promise<ResolvedSchema>;
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<void>;
/**
* Delete schemas on specific path
*/
deleteSchemas(deletions: SchemaDeletionsAll): Promise<void>;
/**
* Delete a schema with schema ID.
*/
deleteSchema(schemaId: string): Promise<void>;
/**
* Add content to a specified schema at a specified path
*/
addContent(additions: SchemaAdditions): Promise<void>;
/**
* Delete content in a specified schema at a specified path
*/
deleteContent(deletions: SchemaDeletions): Promise<void>;
/**
* 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;
loadSchema(schemaUri: string): Promise<UnresolvedSchema>;
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<ResolvedSchema | undefined>;
onResourceChange(uri: string): boolean;
}