|
1 | 1 | import 'monaco-editor/esm/vs/language/json/monaco.contribution' |
2 | 2 | import * as monaco from 'monaco-editor' |
| 3 | +import { getJsonSchemas, onDidChangeJsonSchema } from 'vscode/monaco' |
3 | 4 | import { registerWorkerLoader } from '../worker' |
4 | 5 |
|
5 | | -const registry = monaco.extra.Registry.as<monaco.extra.IJSONContributionRegistry>(monaco.extra.JsonContributionExtensions.JSONContribution) |
6 | | - |
7 | | -// Hack because the commands are filled by a code not run in monaco-editor |
8 | | -{ |
9 | | - const allCommands = monaco.extra.CommandsRegistry.getCommands() |
10 | | - const keybindingsCommandSchema = (registry.getSchemaContributions().schemas['vscode://schemas/keybindings']!.items as monaco.extra.IJSONSchema).properties!.command!.anyOf![0]! |
11 | | - keybindingsCommandSchema.enum = Array.from(allCommands.keys()) |
12 | | - keybindingsCommandSchema.enumDescriptions = <string[]>Array.from(allCommands.values()).map(command => command.description?.description) |
13 | | -} |
14 | | - |
15 | | -const vimKeybindingsSchema = { |
16 | | - type: 'object', |
17 | | - properties: { |
18 | | - before: { |
19 | | - type: 'array', |
20 | | - items: { |
21 | | - type: 'string' |
22 | | - } |
23 | | - }, |
24 | | - after: { |
25 | | - type: 'array', |
26 | | - items: { |
27 | | - type: 'string' |
28 | | - } |
29 | | - } |
30 | | - } |
31 | | -} |
32 | | - |
33 | 6 | function updateDiagnosticsOptions () { |
34 | 7 | monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ |
35 | 8 | comments: 'ignore', |
36 | 9 | validate: true, |
37 | | - schemas: [{ |
38 | | - uri: 'vscode://schemas/settings/resourceLanguage', |
39 | | - schema: registry.getSchemaContributions().schemas['vscode://schemas/settings/resourceLanguage'] |
40 | | - }, { |
41 | | - uri: 'vscode://schemas/keybindings', |
42 | | - fileMatch: ['file:///keybindings.json'], |
43 | | - schema: registry.getSchemaContributions().schemas['vscode://schemas/keybindings'] |
44 | | - }, |
45 | | - { |
46 | | - uri: 'vscode://schemas/settings/user', |
47 | | - fileMatch: ['file:///settings.json'], |
48 | | - schema: { |
49 | | - properties: { |
50 | | - ...monaco.extra.allSettings.properties, |
51 | | - 'vim.normalModeKeyBindings': { |
52 | | - type: 'array', |
53 | | - description: 'Remapped keys in Normal mode.', |
54 | | - items: vimKeybindingsSchema |
55 | | - }, |
56 | | - 'vim.insertModeKeyBindings': { |
57 | | - type: 'array', |
58 | | - description: 'Remapped keys in Insert mode.', |
59 | | - items: vimKeybindingsSchema |
60 | | - }, |
61 | | - 'vim.visualModeKeyBindings': { |
62 | | - type: 'array', |
63 | | - description: 'Remapped keys in Visual mode.', |
64 | | - items: vimKeybindingsSchema |
65 | | - } |
66 | | - }, |
67 | | - patternProperties: monaco.extra.allSettings.patternProperties, |
68 | | - additionalProperties: true, |
69 | | - allowTrailingCommas: true, |
70 | | - allowComments: true |
71 | | - } |
72 | | - }] |
| 10 | + schemas: getJsonSchemas({ |
| 11 | + keybindings: ['file:///keybindings.json'], |
| 12 | + 'settings/user': ['file:///settings.json'] |
| 13 | + }) |
73 | 14 | }) |
74 | 15 | } |
75 | 16 |
|
76 | 17 | updateDiagnosticsOptions() |
77 | | -registry.onDidChangeSchema(updateDiagnosticsOptions) |
| 18 | +onDidChangeJsonSchema(updateDiagnosticsOptions) |
78 | 19 |
|
79 | 20 | const workerLoader = async () => (await import(/* webpackChunkName: "MonacoJsonWorker" */'monaco-editor/esm/vs/language/json/json.worker?worker')).default |
80 | 21 | registerWorkerLoader('json', workerLoader) |
0 commit comments