@@ -20,13 +20,19 @@ export interface IResolveResult {
2020}
2121
2222export class KeybindingResolver {
23+ private readonly _log : ( str : string ) => void ;
2324 private readonly _defaultKeybindings : ResolvedKeybindingItem [ ] ;
2425 private readonly _keybindings : ResolvedKeybindingItem [ ] ;
2526 private readonly _defaultBoundCommands : Map < string , boolean > ;
2627 private readonly _map : Map < string , ResolvedKeybindingItem [ ] > ;
2728 private readonly _lookupMap : Map < string , ResolvedKeybindingItem [ ] > ;
2829
29- constructor ( defaultKeybindings : ResolvedKeybindingItem [ ] , overrides : ResolvedKeybindingItem [ ] ) {
30+ constructor (
31+ defaultKeybindings : ResolvedKeybindingItem [ ] ,
32+ overrides : ResolvedKeybindingItem [ ] ,
33+ log : ( str : string ) => void
34+ ) {
35+ this . _log = log ;
3036 this . _defaultKeybindings = defaultKeybindings ;
3137
3238 this . _defaultBoundCommands = new Map < string , boolean > ( ) ;
@@ -254,6 +260,7 @@ export class KeybindingResolver {
254260 }
255261
256262 public resolve ( context : IContext , currentChord : string | null , keypress : string ) : IResolveResult | null {
263+ this . _log ( `| Resolving ${ keypress } ${ currentChord ? ` chorded from ${ currentChord } ` : `` } ` ) ;
257264 let lookupMap : ResolvedKeybindingItem [ ] | null = null ;
258265
259266 if ( currentChord !== null ) {
@@ -262,6 +269,7 @@ export class KeybindingResolver {
262269 const candidates = this . _map . get ( currentChord ) ;
263270 if ( typeof candidates === 'undefined' ) {
264271 // No chords starting with `currentChord`
272+ this . _log ( `\\ No keybinding entries.` ) ;
265273 return null ;
266274 }
267275
@@ -277,6 +285,7 @@ export class KeybindingResolver {
277285 const candidates = this . _map . get ( keypress ) ;
278286 if ( typeof candidates === 'undefined' ) {
279287 // No bindings with `keypress`
288+ this . _log ( `\\ No keybinding entries.` ) ;
280289 return null ;
281290 }
282291
@@ -285,11 +294,13 @@ export class KeybindingResolver {
285294
286295 let result = this . _findCommand ( context , lookupMap ) ;
287296 if ( ! result ) {
297+ this . _log ( `\\ From ${ lookupMap . length } keybinding entries, no when clauses matched the context.` ) ;
288298 return null ;
289299 }
290300
291301 // TODO@chords
292302 if ( currentChord === null && result . keypressParts . length > 1 && result . keypressParts [ 1 ] !== null ) {
303+ this . _log ( `\\ From ${ lookupMap . length } keybinding entries, matched chord, when: ${ printWhenExplanation ( result . when ) } , source: ${ printSourceExplanation ( result ) } .` ) ;
293304 return {
294305 enterChord : true ,
295306 leaveChord : false ,
@@ -299,6 +310,7 @@ export class KeybindingResolver {
299310 } ;
300311 }
301312
313+ this . _log ( `\\ From ${ lookupMap . length } keybinding entries, matched ${ result . command } , when: ${ printWhenExplanation ( result . when ) } , source: ${ printSourceExplanation ( result ) } .` ) ;
302314 return {
303315 enterChord : false ,
304316 leaveChord : result . keypressParts . length > 1 ,
@@ -362,3 +374,23 @@ export class KeybindingResolver {
362374 return unboundCommands ;
363375 }
364376}
377+
378+ function printWhenExplanation ( when : ContextKeyExpression | undefined ) : string {
379+ if ( ! when ) {
380+ return `no when condition` ;
381+ }
382+ return `${ when . serialize ( ) } ` ;
383+ }
384+
385+ function printSourceExplanation ( kb : ResolvedKeybindingItem ) : string {
386+ if ( kb . isDefault ) {
387+ if ( kb . extensionId ) {
388+ return `built-in extension ${ kb . extensionId } ` ;
389+ }
390+ return `built-in` ;
391+ }
392+ if ( kb . extensionId ) {
393+ return `user extension ${ kb . extensionId } ` ;
394+ }
395+ return `user` ;
396+ }
0 commit comments