Welcome to mirror list, hosted at ThFree Co, Russian Federation.

source_editor_ci_schema_ext.js « extensions « editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7069568275dc1ce2476229cd8bce4b787dcf70c3 (plain)
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
import ciSchemaPath from '~/editor/schema/ci.json';
import { registerSchema } from '~/ide/utils';
import { SourceEditorExtension } from './source_editor_extension_base';

export class CiSchemaExtension extends SourceEditorExtension {
  /**
   * Registers a syntax schema to the editor based on project
   * identifier and commit.
   *
   * The schema is added to the file that is currently edited
   * in the editor.
   *
   * @param {Object} opts
   * @param {String} opts.projectNamespace
   * @param {String} opts.projectPath
   * @param {String?} opts.ref - Current ref. Defaults to main
   */
  registerCiSchema() {
    // 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 = this.getModel().uri.path.split('/').pop();

    registerSchema({
      uri: absoluteSchemaUrl,
      fileMatch: [modelFileName],
    });
  }
}