All files / app/assets/javascripts/editor/extensions source_editor_ci_schema_ext.js

100% Statements 5/5
100% Branches 0/0
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32          9x       11x             3x 3x   3x                        
import ciSchemaPath from '~/editor/schema/ci.json';
import { registerSchema } from '~/ide/utils';
 
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 = new URL(ciSchemaPath, gon.gitlab_url).href;
        const modelFileName = instance.getModel().uri.path.split('/').pop();
 
        registerSchema(
          {
            uri: absoluteSchemaUrl,
            fileMatch: [modelFileName],
          },
          // eslint-disable-next-line @gitlab/require-i18n-strings
          { customTags: ['!reference sequence'] },
        );
      },
    };
  }
}