@codingame/monaco-editor-wrapper 3.3.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,6 @@
1
1
  import 'monaco-editor/esm/vs/language/json/monaco.contribution';
2
+ import * as monaco from 'monaco-editor';
3
+ import { Disposable } from 'vscode';
4
+ declare type Unpacked<T> = T extends (infer U)[] ? U : T;
5
+ export declare function addJsonSchema(schema: Unpacked<NonNullable<monaco.languages.json.DiagnosticsOptions['schemas']>>): Disposable;
6
+ export {};
@@ -1,16 +1,23 @@
1
1
  import 'monaco-editor/esm/vs/language/json/monaco.contribution';
2
2
  import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
3
3
  import { onDidChangeJsonSchema, getJsonSchemas } from 'vscode/monaco';
4
+ import { Disposable } from 'vscode';
4
5
  import { r as registerWorkerLoader } from '../worker.js';
5
6
 
7
+ const customSchemas = [];
8
+
6
9
  function updateDiagnosticsOptions() {
7
10
  monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
8
11
  comments: 'ignore',
9
12
  validate: true,
10
- schemas: getJsonSchemas({
13
+ enableSchemaRequest: true,
14
+ schemas: [...getJsonSchemas({
11
15
  keybindings: ['file:///keybindings.json'],
12
16
  'settings/user': ['file:///settings.json']
13
- })
17
+ }), {
18
+ uri: 'https://json-schema.org/draft/2019-09/schema',
19
+ fileMatch: ['*.schema.json']
20
+ }, ...customSchemas]
14
21
  });
15
22
  }
16
23
 
@@ -22,3 +29,17 @@ const workerLoader = async () => (await import(
22
29
  '../json.worker.js').then(module => module)).default;
23
30
 
24
31
  registerWorkerLoader('json', workerLoader);
32
+ function addJsonSchema(schema) {
33
+ customSchemas.push(schema);
34
+ updateDiagnosticsOptions();
35
+ return new Disposable(() => {
36
+ const index = customSchemas.indexOf(schema);
37
+
38
+ if (index >= 0) {
39
+ customSchemas.splice(index, 1);
40
+ updateDiagnosticsOptions();
41
+ }
42
+ });
43
+ }
44
+
45
+ export { addJsonSchema };
package/dist/main.js CHANGED
@@ -4443,17 +4443,19 @@ async function collapseCodeSections(editor, startToken, endToken) {
4443
4443
  ranges.push(monaco.Range.fromPositions(match.range.getStartPosition(), currentPosition));
4444
4444
  }
4445
4445
 
4446
- const selections = editor.getSelections();
4447
- editor.setSelections(ranges.map(r => ({
4448
- selectionStartLineNumber: r.startLineNumber,
4449
- selectionStartColumn: r.startColumn,
4450
- positionLineNumber: r.endLineNumber,
4451
- positionColumn: r.endColumn
4452
- })));
4453
- await editor.getAction('editor.createFoldingRangeFromSelection').run();
4454
-
4455
- if (selections != null) {
4456
- editor.setSelections(selections);
4446
+ if (ranges.length > 0) {
4447
+ const selections = editor.getSelections();
4448
+ editor.setSelections(ranges.map(r => ({
4449
+ selectionStartLineNumber: r.startLineNumber,
4450
+ selectionStartColumn: r.startColumn,
4451
+ positionLineNumber: r.endLineNumber,
4452
+ positionColumn: r.endColumn
4453
+ })));
4454
+ await editor.getAction('editor.createFoldingRangeFromSelection').run();
4455
+
4456
+ if (selections != null) {
4457
+ editor.setSelections(selections);
4458
+ }
4457
4459
  }
4458
4460
  }
4459
4461
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-editor-wrapper",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
4
4
  "private": false,
5
5
  "description": "Enhanced Monaco editor with TextMate grammars and more",
6
6
  "scripts": {