Skip to content

Commit

Permalink
feat: add extension enable control
Browse files Browse the repository at this point in the history
  • Loading branch information
kvoon3 committed Aug 5, 2024
1 parent 6beac29 commit d2d642d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,26 @@
"contributes": {
"commands": [
{
"title": "Show Generated Which Key",
"title": "Which Key Config Generator: Show Menu",
"command": "whichKeyConfigGen.show"
},
{
"title": "Show Generated Which Key",
"command": "whichKeyConfigGen.gen"
"title": "Which Key Config Generator: Update Config",
"command": "whichKeyConfigGen.updateConfig"
},
{
"title": "Update Which Key Config",
"command": "whichKeyConfigGen.updateConfig"
"title": "Which Key Config Generator: Toggle Enable",
"command": "whichKeyConfigGen.toggleEnable"
}
],
"configuration": {
"type": "object",
"title": "Which key Config Generator",
"properties": {
"whichKeyConfigGen.enable": {
"type": "boolean",
"default": true
},
"whichKeyConfigGen.bindingOverrides": {
"type": "array",
"items": "object",
Expand Down
42 changes: 25 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,45 @@ import type { VimKeybinding } from './types'
import { trans } from './utils'
import { scopedConfigs } from './generated/meta'

Check failure on line 6 in src/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module './generated/meta' or its corresponding type declarations.
import * as Meta from './generated/meta'

Check failure on line 7 in src/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module './generated/meta' or its corresponding type declarations.
import { configs } from './configs'

function updateConfig() {
async function updateConfig() {
const vimConfigs = workspace.getConfiguration('vim')
const nnoremaps = vimConfigs.inspect<VimKeybinding[]>('normalModeKeyBindingsNonRecursive')?.globalValue

if (nnoremaps) {
const bindings = trans(nnoremaps)
return workspace

await workspace
.getConfiguration(scopedConfigs.scope)
.update('bindings', bindings, ConfigurationTarget.Global)
.then(() => {
return bindings
})

await commands.executeCommand('whichkey.register', {
bindings: [Meta.scopedConfigs.scope, 'bindings'],
overrides: [Meta.scopedConfigs.scope, 'bindingOverrides'],
title: 'Genrated whichkey config',
})

logger.info('whichkey registered:', JSON.stringify(bindings, null, 2))

return bindings
}
else {
return Promise.reject(new Error('no nnoremaps'))
return Promise.reject(new Error('not find vim.normalModeKeyBindingsNonRecursive config'))
}
}

export const { activate, deactivate } = defineExtension(async () => {
const bindings = await updateConfig()
logger.info(JSON.stringify(bindings, null, 2))
commands.executeCommand('whichkey.register', {
bindings: [Meta.scopedConfigs.scope, 'bindings'],
overrides: [Meta.scopedConfigs.scope, 'bindingOverrides'],
title: 'Genrated whichkey config',
})
await updateConfig()

useCommand(Meta.commands.show, () => commands.executeCommand('whichkey.show', Meta.configs.bindings.key))
useCommand(Meta.commands.updateConfig, async () => {
const bindings = await updateConfig()
logger.info(JSON.stringify(bindings, null, 2))
useCommand(Meta.commands.show, () => {
if (configs.enable.value)
commands.executeCommand('whichkey.show', Meta.configs.bindings.key)
else
commands.executeCommand('whichkey.show')
})
useCommand(Meta.commands.updateConfig, async () => await updateConfig())
useCommand(Meta.commands.toggleEnable, async () => {
configs.enable.value = !configs.enable.value
})
})

0 comments on commit d2d642d

Please sign in to comment.