debian-mirror-gitlab/app/assets/javascripts/editor/extensions/source_editor_ci_schema_ext.js

28 lines
876 B
JavaScript
Raw Normal View History

2021-11-18 22:05:49 +05:30
import ciSchemaPath from '~/editor/schema/ci.json';
2021-03-08 18:12:59 +05:30
import { registerSchema } from '~/ide/utils';
2022-01-26 12:08:38 +05:30
export class CiSchemaExtension {
static get extensionName() {
return 'CiSchema';
}
// eslint-disable-next-line class-methods-use-this
provides() {
return {
registerCiSchema: (instance) => {
// In order for workers loaded from `data://` as the
// ones loaded by monaco editor, we use absolute URLs
// to fetch schema files, hence the `gon.gitlab_url`
// reference. This prevents error:
// "Failed to execute 'fetch' on 'WorkerGlobalScope'"
const absoluteSchemaUrl = gon.gitlab_url + ciSchemaPath;
const modelFileName = instance.getModel().uri.path.split('/').pop();
2021-03-08 18:12:59 +05:30
2022-01-26 12:08:38 +05:30
registerSchema({
uri: absoluteSchemaUrl,
fileMatch: [modelFileName],
});
},
};
2021-03-08 18:12:59 +05:30
}
}