Skip to content

Commit 1677682

Browse files
authored
Merge pull request #61 from CodinGame/fix-keybindings-keyboard-layout
Use vscode keyboard layout service
2 parents 7b589a7 + 122815c commit 1677682

5 files changed

Lines changed: 84 additions & 18 deletions

File tree

package-lock.json

Lines changed: 65 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"@codingame/eslint-config": "^1.1.6",
150150
"@codingame/tsconfig": "^1.1.1",
151151
"@octokit/rest": "^19.0.5",
152+
"@rollup/plugin-dynamic-import-vars": "^2.0.3",
152153
"@rollup/plugin-node-resolve": "^15.0.1",
153154
"@rollup/plugin-replace": "^5.0.2",
154155
"@rollup/plugin-typescript": "^11.0.0",
@@ -177,8 +178,8 @@
177178
},
178179
"peerDependencies": {
179180
"monaco-editor": "~0.34.0",
180-
"vscode-textmate": "^7.0.1",
181-
"vscode-oniguruma": "^1.6.2"
181+
"vscode-oniguruma": "^1.6.2",
182+
"vscode-textmate": "^7.0.1"
182183
},
183184
"overrides": {
184185
"rollup-plugin-styles": {

rollup/rollup.config.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import replace from '@rollup/plugin-replace'
1010
import styles from 'rollup-plugin-styles'
1111
import * as tslib from 'tslib'
1212
import * as babylonParser from 'recast/parsers/babylon.js'
13+
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
1314
import * as fs from 'fs'
1415
import * as path from 'path'
1516
import * as vm from 'vm'
@@ -50,6 +51,7 @@ const VSCODE_DIR = path.resolve(__dirname, '../vscode')
5051
const NODE_MODULES_DIR = path.resolve(__dirname, '../node_modules')
5152
const MONACO_EDITOR_DIR = path.resolve(NODE_MODULES_DIR, './monaco-editor')
5253
const OVERRIDE_PATH = path.resolve(__dirname, '../src/override')
54+
const KEYBOARD_LAYOUT_DIR = path.resolve(VSCODE_DIR, 'vs/workbench/services/keybinding/browser/keyboardLayouts')
5355

5456
function getMemberExpressionPath (node: recast.types.namedTypes.MemberExpression | recast.types.namedTypes.Identifier): string | null {
5557
if (node.type === 'MemberExpression') {
@@ -106,7 +108,7 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
106108
annotations: true,
107109
preset: 'smallest',
108110
moduleSideEffects (id) {
109-
return id.startsWith(SRC_DIR) || id.endsWith('.css')
111+
return id.startsWith(SRC_DIR) || id.endsWith('.css') || id.startsWith(KEYBOARD_LAYOUT_DIR)
110112
}
111113
},
112114
external,
@@ -148,7 +150,7 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
148150
return undefined
149151
},
150152
transform (code) {
151-
return toggleEsmComments(code).replaceAll("'vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.' + platform", "'./keyboardLayouts/_.contribution'")
153+
return toggleEsmComments(code).replaceAll("'vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.' + platform", "'./keyboardLayouts/layout.contribution.' + platform + '.js'")
152154
},
153155
load (id) {
154156
if (id.startsWith(VSCODE_DIR) && id.endsWith('.css')) {
@@ -276,8 +278,8 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
276278
}
277279
} else if (node.callee.type === 'Identifier' && PURE_FUNCTIONS.has(node.callee.name)) {
278280
path.replace(addComment(node))
279-
} else if (node.callee.type === 'FunctionExpression') {
280-
// Mark IIFE as pure, because typescript compile enums as IIFE
281+
} else if (node.callee.type === 'FunctionExpression' && node.arguments.length === 1) {
282+
// Mark IIFE with single parameter as pure, because typescript compile enums as IIFE
281283
path.replace(addComment(node))
282284
}
283285
this.traverse(path)
@@ -309,7 +311,8 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
309311
right: ').then(module => module.default ?? module)'
310312
}
311313
}
312-
}
314+
},
315+
dynamicImportVars()
313316
]
314317
}, {
315318
// 2nd pass to improve treeshaking
@@ -358,8 +361,8 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
358361
}
359362
} else if (node.callee.type === 'Identifier' && PURE_FUNCTIONS.has(node.callee.name)) {
360363
path.replace(addComment(node))
361-
} else if (node.callee.type === 'FunctionExpression') {
362-
// Mark IIFE as pure, because typescript compile enums as IIFE
364+
} else if (node.callee.type === 'FunctionExpression' && node.arguments.length === 1) {
365+
// Mark IIFE with single parameter as pure, because typescript compile enums as IIFE
363366
path.replace(addComment(node))
364367
}
365368
this.traverse(path)

src/service-override/keybindings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { CommandsQuickAccessProvider } from 'vs/workbench/contrib/quickaccess/br
1919
import { DisposableStore } from 'vs/base/common/lifecycle'
2020
import { CancellationToken } from 'vs/base/common/cancellation'
2121
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'
22+
import { IKeyboardLayoutService } from 'vs/platform/keyboardLayout/common/keyboardLayout'
23+
import { BrowserKeyboardLayoutService } from 'vs/workbench/services/keybinding/browser/keyboardLayoutService'
2224
import getFileServiceOverride from './files'
2325
import { consoleExtensionMessageHandler, getExtensionPoint } from './tools'
2426
import { DEFAULT_EXTENSION } from '../vscode-services/extHost'
@@ -125,7 +127,8 @@ function updateUserKeybindings (keybindingsJson: string): void {
125127
export default function getServiceOverride (): IEditorOverrideServices {
126128
return {
127129
...getFileServiceOverride(),
128-
[IKeybindingService.toString()]: new SyncDescriptor(DelegateStandaloneKeybindingService)
130+
[IKeybindingService.toString()]: new SyncDescriptor(DelegateStandaloneKeybindingService),
131+
[IKeyboardLayoutService.toString()]: new SyncDescriptor(BrowserKeyboardLayoutService)
129132
}
130133
}
131134

src/vscode-services/missing-services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ class WorkbenchEnvironmentService implements IBrowserWorkbenchEnvironmentService
291291
get webviewExternalEndpoint () { return unsupported() }
292292
debugRenderer = false
293293
get userRoamingDataHome () { return unsupported() }
294-
get keyboardLayoutResource () { return unsupported() }
294+
keyboardLayoutResource = URI.from({ scheme: 'user', path: '/keyboardLayout.json' })
295295
get argvResource () { return unsupported() }
296-
get snippetsHome () { return URI.from({ scheme: 'user', path: '/snippets' }) }
296+
snippetsHome = URI.from({ scheme: 'user', path: '/snippets' })
297297
get untitledWorkspacesHome () { return unsupported() }
298298
get globalStorageHome () { return unsupported() }
299299
get workspaceStorageHome () { return unsupported() }

0 commit comments

Comments
 (0)