Context key expressions
Context key expressions are a way to express values dynamically in thefields of a Sourcegraph extension's manifest.
With string interpolation, you can insert these expressions directly into stringfields.
Context keys are like variables that you can use inside of these interpolatedexpressions. Context keys give you access to values that are available to yourextension dynamically, such as
resource for the currently viewed resource, or
config for the configuration settings.
Context key expressions can be interpolated inside of strings. In manifestfields that support interpolated expressions, you can interpolate an expressionby surrounding it with
Supported fields in the manifest
These fields in the manifest support context key expressions.
In contributed actions
String fields that accept interpolated expressions, in contributedactions:
commandArguments: each string item in the array accepts interpolatedexpressions.
Fields that expect a context key expression:
actionItem.pressed: renders the action in a pressed state when thisexpression evaluates to true.
In menu contributions
Fields that expect a context key expression, in menucontributions:
when: enables the menu contribution when this expression evaluates to true.
Available context keys
Context keys are the variables that you can use inside of expressions.
config: a namespace containing all the settings that are available. Forexample,
sourcegraphBaseUrlvaluefrom Sourcegraph settings.
resource: the current resource being viewed, such as a file.
component: true if a component is open, such as a panel, directory view, orfile view.
component.selections: an object representing the current selections.
panel: the panel component, if a panel is open.
Returns the value of a property named
object or return undefined ifeither the object or the property doesn't exist.
Returns the object converted to a JSON string using
The expression syntax is simple and isn't intended to be a full programminglanguage, so there are some limitations.
- Lack of operator precedence. Because of the simplicity of the parser,operators do not have any precedence and are simply evaluated left-to-right.Use parentheses to specify precedence.
- Lack of a ternary operator. Instead of a ternary operator, you can usecombinations of
||operators to achieve a similar result.