Skip to content

Commit 74c2d94

Browse files
committed
feat: use getJsonSchemas to configure json worker
1 parent de2d9e5 commit 74c2d94

File tree

2 files changed

+50
-65
lines changed

2 files changed

+50
-65
lines changed

src/features/jsonContribution.ts

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,21 @@
11
import 'monaco-editor/esm/vs/language/json/monaco.contribution'
22
import * as monaco from 'monaco-editor'
3+
import { getJsonSchemas, onDidChangeJsonSchema } from 'vscode/monaco'
34
import { registerWorkerLoader } from '../worker'
45

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-
336
function updateDiagnosticsOptions () {
347
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
358
comments: 'ignore',
369
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+
})
7314
})
7415
}
7516

7617
updateDiagnosticsOptions()
77-
registry.onDidChangeSchema(updateDiagnosticsOptions)
18+
onDidChangeJsonSchema(updateDiagnosticsOptions)
7819

7920
const workerLoader = async () => (await import(/* webpackChunkName: "MonacoJsonWorker" */'monaco-editor/esm/vs/language/json/json.worker?worker')).default
8021
registerWorkerLoader('json', workerLoader)

src/keybindings/vim.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,52 @@
11
import { IDisposable } from 'monaco-editor'
22
import * as monacoVim from 'monaco-vim'
33
import * as monaco from 'monaco-editor'
4+
import { IJSONSchema } from 'vscode/monaco'
5+
import { configurationRegistry, ConfigurationScope } from 'vscode/service-override/configuration'
46
import { getConfiguration, onConfigurationChanged } from '../configuration'
57

8+
const vimKeybindingsSchema: IJSONSchema = {
9+
type: 'object',
10+
properties: {
11+
before: {
12+
type: 'array',
13+
items: {
14+
type: 'string'
15+
}
16+
},
17+
after: {
18+
type: 'array',
19+
items: {
20+
type: 'string'
21+
}
22+
}
23+
}
24+
}
25+
configurationRegistry.registerConfiguration({
26+
id: 'vim',
27+
order: 5,
28+
type: 'object',
29+
title: 'Vim',
30+
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,
31+
properties: {
32+
'vim.normalModeKeyBindings': {
33+
type: 'array',
34+
description: 'Remapped keys in Normal mode.',
35+
items: vimKeybindingsSchema
36+
},
37+
'vim.insertModeKeyBindings': {
38+
type: 'array',
39+
description: 'Remapped keys in Insert mode.',
40+
items: vimKeybindingsSchema
41+
},
42+
'vim.visualModeKeyBindings': {
43+
type: 'array',
44+
description: 'Remapped keys in Visual mode.',
45+
items: vimKeybindingsSchema
46+
}
47+
}
48+
})
49+
650
interface VimKeybindingConfiguration {
751
before?: string[]
852
after?: string[]

0 commit comments

Comments
 (0)