forked from remcohaszing/monaco-yaml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonaco.contribution.ts
85 lines (69 loc) · 2.35 KB
/
monaco.contribution.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as mode from './yamlMode';
import Emitter = monaco.Emitter;
import IEvent = monaco.IEvent;
declare var require: <T>(
moduleId: [string],
callback: (module: T) => void
) => void;
// --- YAML configuration and defaults ---------
export class LanguageServiceDefaultsImpl
implements monaco.languages.yaml.LanguageServiceDefaults {
private _onDidChange = new Emitter<
monaco.languages.yaml.LanguageServiceDefaults
>();
private _diagnosticsOptions: monaco.languages.yaml.DiagnosticsOptions;
private _languageId: string;
constructor(
languageId: string,
diagnosticsOptions: monaco.languages.yaml.DiagnosticsOptions
) {
this._languageId = languageId;
this.setDiagnosticsOptions(diagnosticsOptions);
}
get onDidChange(): IEvent<monaco.languages.yaml.LanguageServiceDefaults> {
return this._onDidChange.event;
}
get languageId(): string {
return this._languageId;
}
get diagnosticsOptions(): monaco.languages.yaml.DiagnosticsOptions {
return this._diagnosticsOptions;
}
public setDiagnosticsOptions(
options: monaco.languages.yaml.DiagnosticsOptions
): void {
this._diagnosticsOptions = options || Object.create(null);
this._onDidChange.fire(this);
}
}
const diagnosticDefault: monaco.languages.yaml.DiagnosticsOptions = {
validate: true,
schemas: [],
enableSchemaRequest: false,
};
const yamlDefaults = new LanguageServiceDefaultsImpl('yaml', diagnosticDefault);
// Export API
function createAPI(): typeof monaco.languages.yaml {
return {
yamlDefaults,
};
}
monaco.languages.yaml = createAPI();
// --- Registration to monaco editor ---
function withMode(callback: (module: typeof mode) => void): void {
require<typeof mode>(['vs/language/yaml/yamlMode'], callback);
}
monaco.languages.register({
id: 'yaml',
extensions: ['.yaml', '.yml'],
aliases: ['YAML', 'yaml', 'YML', 'yml'],
mimetypes: ['application/x-yaml'],
});
monaco.languages.onLanguage('yaml', () => {
withMode(mode => mode.setupMode(yamlDefaults));
});