Custom contexts
VSCode's when clause contexts can be used to selectively enable or disable extension commands and UI elements, such as menus and views. reactive-vscode provides useVscodeContext to define custom contexts in a reactive way.
ts
import { computed, defineExtension, ref, useVscodeContext } from 'reactive-vscode'
export = defineExtension(() => {
const contextA = useVscodeContext('demo.fromValue', true)
const contextB = useVscodeContext('demo.fromRef', contextA)
const contextC = useVscodeContext('demo.fromGetter', () => !contextA.value)
})
Note that contextA
and contextB
are ref
s, which means you can set them later, and the context will be updated accordingly. contextC
is a computed
value, which means it will be updated automatically when contextA
changes.
For more information on when
clause contexts, please refer to the official documentation.