mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-07-08 20:40:46 +00:00
feat: allow user to provide custom schema service
This commit is contained in:
parent
fb04c29c52
commit
5476403375
11 changed files with 37 additions and 89 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "monaco-yaml",
|
"name": "monaco-yaml",
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"description": "YAML plugin for the Monaco Editor",
|
"description": "YAML plugin for the Monaco Editor",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "rimraf ./out && yarn compile:umd && yarn compile:esm",
|
"compile": "rimraf ./out && yarn compile:umd && yarn compile:esm",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import * as Json from 'jsonc-parser';
|
||||||
import {JSONSchema, JSONSchemaMap} from '../jsonSchema';
|
import {JSONSchema, JSONSchemaMap} from '../jsonSchema';
|
||||||
import URI from 'vscode-uri';
|
import URI from 'vscode-uri';
|
||||||
import * as Strings from '../utils/strings';
|
import * as Strings from '../utils/strings';
|
||||||
import {SchemaRequestService, WorkspaceContextService, PromiseConstructor, Thenable} from '../yamlLanguageService';
|
import {SchemaRequestService, WorkspaceContextService, Thenable} from '../yamlLanguageService';
|
||||||
|
|
||||||
|
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
|
|
@ -142,7 +142,7 @@ class SchemaHandle implements ISchemaHandle {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
if (unresolvedSchemaContent) {
|
if (unresolvedSchemaContent) {
|
||||||
this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
|
this.unresolvedSchema = Promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,13 +242,11 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
private contextService: WorkspaceContextService;
|
private contextService: WorkspaceContextService;
|
||||||
private callOnDispose: Function[];
|
private callOnDispose: Function[];
|
||||||
private requestService: SchemaRequestService;
|
private requestService: SchemaRequestService;
|
||||||
private promiseConstructor: PromiseConstructor;
|
|
||||||
private customSchemaProvider: CustomSchemaProvider | undefined;
|
private customSchemaProvider: CustomSchemaProvider | undefined;
|
||||||
|
|
||||||
constructor(requestService: SchemaRequestService, contextService?: WorkspaceContextService, promiseConstructor?: PromiseConstructor) {
|
constructor(requestService: SchemaRequestService, contextService?: WorkspaceContextService) {
|
||||||
this.contextService = contextService;
|
this.contextService = contextService;
|
||||||
this.requestService = requestService;
|
this.requestService = requestService;
|
||||||
this.promiseConstructor = promiseConstructor || Promise;
|
|
||||||
this.callOnDispose = [];
|
this.callOnDispose = [];
|
||||||
this.customSchemaProvider = undefined;
|
this.customSchemaProvider = undefined;
|
||||||
this.contributionSchemas = {};
|
this.contributionSchemas = {};
|
||||||
|
|
@ -270,10 +268,6 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public get promise() {
|
|
||||||
return this.promiseConstructor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
while (this.callOnDispose.length > 0) {
|
while (this.callOnDispose.length > 0) {
|
||||||
this.callOnDispose.pop()();
|
this.callOnDispose.pop()();
|
||||||
|
|
@ -376,13 +370,13 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
if (schemaHandle) {
|
if (schemaHandle) {
|
||||||
return schemaHandle.getResolvedSchema();
|
return schemaHandle.getResolvedSchema();
|
||||||
}
|
}
|
||||||
return this.promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadSchema(url: string): Thenable<UnresolvedSchema> {
|
public loadSchema(url: string): Thenable<UnresolvedSchema> {
|
||||||
if (!this.requestService) {
|
if (!this.requestService) {
|
||||||
let errorMessage = localize('json.schema.norequestservice', 'Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
|
let errorMessage = localize('json.schema.norequestservice', 'Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
|
||||||
return this.promise.resolve(new UnresolvedSchema(<JSONSchema>{}, [errorMessage]));
|
return Promise.resolve(new UnresolvedSchema(<JSONSchema>{}, [errorMessage]));
|
||||||
}
|
}
|
||||||
return this.requestService(url).then(
|
return this.requestService(url).then(
|
||||||
content => {
|
content => {
|
||||||
|
|
@ -507,7 +501,7 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
collectMapEntries(next.definitions, next.properties, next.patternProperties, <JSONSchemaMap>next.dependencies);
|
collectMapEntries(next.definitions, next.properties, next.patternProperties, <JSONSchemaMap>next.dependencies);
|
||||||
collectArrayEntries(next.anyOf, next.allOf, next.oneOf, <JSONSchema[]>next.items, next.schemaSequence);
|
collectArrayEntries(next.anyOf, next.allOf, next.oneOf, <JSONSchema[]>next.items, next.schemaSequence);
|
||||||
}
|
}
|
||||||
return this.promise.all(openPromises);
|
return Promise.all(openPromises);
|
||||||
};
|
};
|
||||||
|
|
||||||
return resolveRefs(schema, schema, schemaURL).then(_ => new ResolvedSchema(schema, resolveErrors));
|
return resolveRefs(schema, schema, schemaURL).then(_ => new ResolvedSchema(schema, resolveErrors));
|
||||||
|
|
@ -522,7 +516,7 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
return entry.getCombinedSchema(this).getResolvedSchema();
|
return entry.getCombinedSchema(this).getResolvedSchema();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
};
|
};
|
||||||
if (this.customSchemaProvider) {
|
if (this.customSchemaProvider) {
|
||||||
return this.customSchemaProvider(resource).then(schemaUri => {
|
return this.customSchemaProvider(resource).then(schemaUri => {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import * as Json from 'jsonc-parser';
|
||||||
import * as SchemaService from './jsonSchemaService';
|
import * as SchemaService from './jsonSchemaService';
|
||||||
import { JSONSchema } from '../jsonSchema';
|
import { JSONSchema } from '../jsonSchema';
|
||||||
import { JSONWorkerContribution, CompletionsCollector } from '../jsonContributions';
|
import { JSONWorkerContribution, CompletionsCollector } from '../jsonContributions';
|
||||||
import { PromiseConstructor, Thenable } from 'vscode-json-languageservice';
|
import { Thenable } from 'vscode-json-languageservice';
|
||||||
|
|
||||||
import { CompletionItem, CompletionItemKind, CompletionList, TextDocument, Position, Range, TextEdit, InsertTextFormat } from 'vscode-languageserver-types';
|
import { CompletionItem, CompletionItemKind, CompletionList, TextDocument, Position, Range, TextEdit, InsertTextFormat } from 'vscode-languageserver-types';
|
||||||
|
|
||||||
|
|
@ -25,14 +25,12 @@ export class YAMLCompletion {
|
||||||
|
|
||||||
private schemaService: SchemaService.IJSONSchemaService;
|
private schemaService: SchemaService.IJSONSchemaService;
|
||||||
private contributions: JSONWorkerContribution[];
|
private contributions: JSONWorkerContribution[];
|
||||||
private promise: PromiseConstructor;
|
|
||||||
private customTags: Array<String>;
|
private customTags: Array<String>;
|
||||||
private completion: boolean;
|
private completion: boolean;
|
||||||
|
|
||||||
constructor(schemaService: SchemaService.IJSONSchemaService, contributions: JSONWorkerContribution[] = [], promiseConstructor?: PromiseConstructor) {
|
constructor(schemaService: SchemaService.IJSONSchemaService, contributions: JSONWorkerContribution[] = []) {
|
||||||
this.schemaService = schemaService;
|
this.schemaService = schemaService;
|
||||||
this.contributions = contributions;
|
this.contributions = contributions;
|
||||||
this.promise = promiseConstructor || Promise;
|
|
||||||
this.customTags = [];
|
this.customTags = [];
|
||||||
this.completion = true;
|
this.completion = true;
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +51,7 @@ export class YAMLCompletion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.promise.resolve(item);
|
return Promise.resolve(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public doComplete(document: TextDocument, position: Position, doc): Thenable<CompletionList> {
|
public doComplete(document: TextDocument, position: Position, doc): Thenable<CompletionList> {
|
||||||
|
|
@ -142,7 +140,6 @@ export class YAMLCompletion {
|
||||||
let collectionPromises: Thenable<any>[] = [];
|
let collectionPromises: Thenable<any>[] = [];
|
||||||
|
|
||||||
let addValue = true;
|
let addValue = true;
|
||||||
let currentKey = '';
|
|
||||||
|
|
||||||
let currentProperty: Parser.PropertyASTNode = null;
|
let currentProperty: Parser.PropertyASTNode = null;
|
||||||
if (node) {
|
if (node) {
|
||||||
|
|
@ -152,7 +149,6 @@ export class YAMLCompletion {
|
||||||
if (stringNode.isKey) {
|
if (stringNode.isKey) {
|
||||||
addValue = !(node.parent && ((<Parser.PropertyASTNode>node.parent).value));
|
addValue = !(node.parent && ((<Parser.PropertyASTNode>node.parent).value));
|
||||||
currentProperty = node.parent ? <Parser.PropertyASTNode>node.parent : null;
|
currentProperty = node.parent ? <Parser.PropertyASTNode>node.parent : null;
|
||||||
currentKey = document.getText().substring(node.start + 1, node.end - 1);
|
|
||||||
if (node.parent) {
|
if (node.parent) {
|
||||||
node = node.parent.parent;
|
node = node.parent.parent;
|
||||||
}
|
}
|
||||||
|
|
@ -209,7 +205,7 @@ export class YAMLCompletion {
|
||||||
this.getCustomTagValueCompletions(collector);
|
this.getCustomTagValueCompletions(collector);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.promise.all(collectionPromises).then(() => {
|
return Promise.all(collectionPromises).then(() => {
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
import * as Parser from '../parser/jsonParser';
|
import * as Parser from '../parser/jsonParser';
|
||||||
import * as SchemaService from './jsonSchemaService';
|
import * as SchemaService from './jsonSchemaService';
|
||||||
import {JSONWorkerContribution} from '../jsonContributions';
|
import {JSONWorkerContribution} from '../jsonContributions';
|
||||||
import {PromiseConstructor, Thenable} from 'vscode-json-languageservice';
|
import {Thenable} from 'vscode-json-languageservice';
|
||||||
|
|
||||||
import {Hover, TextDocument, Position, Range, MarkedString} from 'vscode-languageserver-types';
|
import {Hover, TextDocument, Position, Range, MarkedString} from 'vscode-languageserver-types';
|
||||||
import { matchOffsetToDocument } from '../utils/arrUtils';
|
import { matchOffsetToDocument } from '../utils/arrUtils';
|
||||||
|
|
@ -19,13 +19,11 @@ export class YAMLHover {
|
||||||
|
|
||||||
private schemaService: SchemaService.IJSONSchemaService;
|
private schemaService: SchemaService.IJSONSchemaService;
|
||||||
private contributions: JSONWorkerContribution[];
|
private contributions: JSONWorkerContribution[];
|
||||||
private promise: PromiseConstructor;
|
|
||||||
private shouldHover: boolean;
|
private shouldHover: boolean;
|
||||||
|
|
||||||
constructor(schemaService: SchemaService.IJSONSchemaService, contributions: JSONWorkerContribution[] = [], promiseConstructor: PromiseConstructor) {
|
constructor(schemaService: SchemaService.IJSONSchemaService, contributions: JSONWorkerContribution[] = []) {
|
||||||
this.schemaService = schemaService;
|
this.schemaService = schemaService;
|
||||||
this.contributions = contributions;
|
this.contributions = contributions;
|
||||||
this.promise = promiseConstructor || Promise;
|
|
||||||
this.shouldHover = true;
|
this.shouldHover = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,18 +36,18 @@ export class YAMLHover {
|
||||||
public doHover(document: TextDocument, position: Position, doc): Thenable<Hover> {
|
public doHover(document: TextDocument, position: Position, doc): Thenable<Hover> {
|
||||||
|
|
||||||
if(!this.shouldHover || !document){
|
if(!this.shouldHover || !document){
|
||||||
return this.promise.resolve(void 0);
|
return Promise.resolve(void 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = document.offsetAt(position);
|
let offset = document.offsetAt(position);
|
||||||
let currentDoc = matchOffsetToDocument(offset, doc);
|
let currentDoc = matchOffsetToDocument(offset, doc);
|
||||||
if(currentDoc === null){
|
if(currentDoc === null){
|
||||||
return this.promise.resolve(void 0);
|
return Promise.resolve(void 0);
|
||||||
}
|
}
|
||||||
const currentDocIndex = doc.documents.indexOf(currentDoc);
|
const currentDocIndex = doc.documents.indexOf(currentDoc);
|
||||||
let node = currentDoc.getNodeFromOffset(offset);
|
let node = currentDoc.getNodeFromOffset(offset);
|
||||||
if (!node || (node.type === 'object' || node.type === 'array') && offset > node.start + 1 && offset < node.end - 1) {
|
if (!node || (node.type === 'object' || node.type === 'array') && offset > node.start + 1 && offset < node.end - 1) {
|
||||||
return this.promise.resolve(void 0);
|
return Promise.resolve(void 0);
|
||||||
}
|
}
|
||||||
let hoverRangeNode = node;
|
let hoverRangeNode = node;
|
||||||
|
|
||||||
|
|
@ -60,7 +58,7 @@ export class YAMLHover {
|
||||||
let propertyNode = <Parser.PropertyASTNode>node.parent;
|
let propertyNode = <Parser.PropertyASTNode>node.parent;
|
||||||
node = propertyNode.value;
|
node = propertyNode.value;
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return this.promise.resolve(void 0);
|
return Promise.resolve(void 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,16 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
||||||
import { JSONDocument, ObjectASTNode, IProblem, ProblemSeverity } from '../parser/jsonParser';
|
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
||||||
import { TextDocument, Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
|
import { LanguageSettings} from '../yamlLanguageService';
|
||||||
import { PromiseConstructor, Thenable, LanguageSettings} from '../yamlLanguageService';
|
|
||||||
|
|
||||||
export class YAMLValidation {
|
export class YAMLValidation {
|
||||||
|
|
||||||
private jsonSchemaService: JSONSchemaService;
|
private jsonSchemaService: JSONSchemaService;
|
||||||
private promise: PromiseConstructor;
|
|
||||||
private comments: boolean;
|
|
||||||
private validationEnabled: boolean;
|
private validationEnabled: boolean;
|
||||||
|
|
||||||
public constructor(jsonSchemaService, promiseConstructor) {
|
public constructor(jsonSchemaService) {
|
||||||
this.jsonSchemaService = jsonSchemaService;
|
this.jsonSchemaService = jsonSchemaService;
|
||||||
this.promise = promiseConstructor;
|
|
||||||
this.validationEnabled = true;
|
this.validationEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,11 +24,11 @@ export class YAMLValidation {
|
||||||
this.validationEnabled = shouldValidate.validate;
|
this.validationEnabled = shouldValidate.validate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public doValidation(textDocument, yamlDocument) {
|
public doValidation(textDocument, yamlDocument) {
|
||||||
|
|
||||||
if(!this.validationEnabled){
|
if(!this.validationEnabled){
|
||||||
return this.promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.jsonSchemaService.getSchemaForResource(textDocument.uri).then(function (schema) {
|
return this.jsonSchemaService.getSchemaForResource(textDocument.uri).then(function (schema) {
|
||||||
|
|
@ -56,7 +52,7 @@ export class YAMLValidation {
|
||||||
|
|
||||||
}
|
}
|
||||||
if(newSchema && newSchema.errors.length > 0){
|
if(newSchema && newSchema.errors.length > 0){
|
||||||
|
|
||||||
for(let curDiagnostic of newSchema.errors){
|
for(let curDiagnostic of newSchema.errors){
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
severity: DiagnosticSeverity.Error,
|
severity: DiagnosticSeverity.Error,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { YAMLCompletion } from './services/yamlCompletion';
|
||||||
import { YAMLHover } from './services/yamlHover';
|
import { YAMLHover } from './services/yamlHover';
|
||||||
import { YAMLValidation } from './services/yamlValidation';
|
import { YAMLValidation } from './services/yamlValidation';
|
||||||
import { format } from './services/yamlFormatter';
|
import { format } from './services/yamlFormatter';
|
||||||
import { JSONDocument } from 'vscode-json-languageservice';
|
import { JSONDocument, JSONWorkerContribution } from 'vscode-json-languageservice';
|
||||||
import { parse as parseYAML } from "./parser/yamlParser";
|
import { parse as parseYAML } from "./parser/yamlParser";
|
||||||
|
|
||||||
export interface LanguageSettings {
|
export interface LanguageSettings {
|
||||||
|
|
@ -26,38 +26,6 @@ export interface LanguageSettings {
|
||||||
|
|
||||||
export type YAMLDocument = { documents: JSONDocument[] };
|
export type YAMLDocument = { documents: JSONDocument[] };
|
||||||
|
|
||||||
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> {
|
export interface Thenable<R> {
|
||||||
/**
|
/**
|
||||||
* Attaches callbacks for the resolution and/or rejection of the Promise.
|
* Attaches callbacks for the resolution and/or rejection of the Promise.
|
||||||
|
|
@ -109,15 +77,13 @@ export interface LanguageService {
|
||||||
parseYAMLDocument(document: TextDocument): YAMLDocument;
|
parseYAMLDocument(document: TextDocument): YAMLDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLanguageService(schemaRequestService, workspaceContext, contributions, promiseConstructor?): LanguageService {
|
export function getLanguageService(schemaRequestService: SchemaRequestService, workspaceContext: WorkspaceContextService, contributions: JSONWorkerContribution[]): LanguageService {
|
||||||
let promise = promiseConstructor || Promise;
|
|
||||||
|
|
||||||
let schemaService = new JSONSchemaService(schemaRequestService, workspaceContext);
|
let schemaService = new JSONSchemaService(schemaRequestService, workspaceContext);
|
||||||
|
|
||||||
let completer = new YAMLCompletion(schemaService, contributions, promise);
|
let completer = new YAMLCompletion(schemaService, contributions);
|
||||||
let hover = new YAMLHover(schemaService, contributions, promise);
|
let hover = new YAMLHover(schemaService, contributions);
|
||||||
let yamlDocumentSymbols = new YAMLDocumentSymbols();
|
let yamlDocumentSymbols = new YAMLDocumentSymbols();
|
||||||
let yamlValidation = new YAMLValidation(schemaService, promise);
|
let yamlValidation = new YAMLValidation(schemaService);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configure: (settings) => {
|
configure: (settings) => {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.yaml.Langua
|
||||||
const diagnosticDefault: monaco.languages.yaml.DiagnosticsOptions = {
|
const diagnosticDefault: monaco.languages.yaml.DiagnosticsOptions = {
|
||||||
validate: true,
|
validate: true,
|
||||||
schemas: [],
|
schemas: [],
|
||||||
enableSchemaRequest: false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const yamlDefaults = new LanguageServiceDefaultsImpl('yaml', diagnosticDefault);
|
const yamlDefaults = new LanguageServiceDefaultsImpl('yaml', diagnosticDefault);
|
||||||
|
|
|
||||||
5
src/monaco.d.ts
vendored
5
src/monaco.d.ts
vendored
|
|
@ -29,9 +29,10 @@ declare module monaco.languages.yaml {
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set, the schema service would load schema content on-demand with 'fetch' if available
|
* If not set, the schema service would load schema content on-demand with 'fetch' if available,
|
||||||
|
* otherwise, it will try to load with the custom schema request.
|
||||||
*/
|
*/
|
||||||
readonly enableSchemaRequest?: boolean;
|
readonly schemaRequestService?: (url: string) => Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LanguageServiceDefaults {
|
export interface LanguageServiceDefaults {
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ export class WorkerManager {
|
||||||
createData: {
|
createData: {
|
||||||
languageSettings: this._defaults.diagnosticsOptions,
|
languageSettings: this._defaults.diagnosticsOptions,
|
||||||
languageId: this._defaults.languageId,
|
languageId: this._defaults.languageId,
|
||||||
enableSchemaRequest: this._defaults.diagnosticsOptions.enableSchemaRequest
|
schemaRequestService: this._defaults.diagnosticsOptions.schemaRequestService
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,8 @@ export class YAMLWorker {
|
||||||
this._ctx = ctx;
|
this._ctx = ctx;
|
||||||
this._languageSettings = createData.languageSettings;
|
this._languageSettings = createData.languageSettings;
|
||||||
this._languageId = createData.languageId;
|
this._languageId = createData.languageId;
|
||||||
this._languageService = yamlService.getLanguageService(createData.enableSchemaRequest && defaultSchemaRequestService,
|
this._languageService = yamlService.getLanguageService(
|
||||||
null, [], PromiseAdapter,
|
createData.schemaRequestService || defaultSchemaRequestService, null, []);
|
||||||
);
|
|
||||||
this._languageService.configure({ ...this._languageSettings, hover: true, isKubernetes: true });
|
this._languageService.configure({ ...this._languageSettings, hover: true, isKubernetes: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +107,7 @@ export class YAMLWorker {
|
||||||
export interface ICreateData {
|
export interface ICreateData {
|
||||||
languageId: string;
|
languageId: string;
|
||||||
languageSettings: yamlService.LanguageSettings;
|
languageSettings: yamlService.LanguageSettings;
|
||||||
enableSchemaRequest: boolean;
|
schemaRequestService: (url: string) => Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(ctx: IWorkerContext, createData: ICreateData): YAMLWorker {
|
export function create(ctx: IWorkerContext, createData: ICreateData): YAMLWorker {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ spec:
|
||||||
});
|
});
|
||||||
|
|
||||||
monaco.languages.yaml.yamlDefaults.setDiagnosticsOptions({
|
monaco.languages.yaml.yamlDefaults.setDiagnosticsOptions({
|
||||||
enableSchemaRequest: true,
|
|
||||||
validate: true,
|
validate: true,
|
||||||
schemas: [
|
schemas: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue