Here's an example from a `redactions.scm` file for JSON:
```scheme
(pair value: (number) @redact)
(pair value: (string) @redact)
(array (number) @redact)
(array (string) @redact)
```
This query marks number and string values in key-value pairs and arrays for redaction.
| Capture | Description |
| ------- | ------------------------------ |
| @redact | Captures values to be redacted |
### Runnable code detection
The `runnables.scm` file defines rules for detecting runnable code.
Here's an example from an `runnables.scm` file for JSON:
```scheme
(
(document
(object
(pair
key: (string
(string_content) @_name
(#eq? @_name "scripts")
)
value: (object
(pair
key: (string (string_content) @run @script)
)
)
)
)
)
(#set! tag package-script)
(#set! tag composer-script)
)
```
This query detects runnable scripts in package.json and composer.json files.
The `@run` capture specifies where the run button should appear in the editor. Other captures, except those prefixed with an underscore, are exposed as environment variables with a prefix of `ZED_CUSTOM_$(capture_name)` when running the code.
| Capture | Description |
| ------- | ------------------------------------------------------ |
| @\_name | Captures the "scripts" key |
| @run | Captures the script name |
| @script | Also captures the script name (for different purposes) |
<!--
TBD: `#set! tag`
-->
## Language Servers
Zed uses the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) to provide advanced language support.
An extension may provide any number of language servers. To provide a language server from your extension, add an entry to your `extension.toml` with the name of your language server and the language(s) it applies to:
```toml
[language_servers.my-language]
name = "My Language LSP"
languages = ["My Language"]
```
Then, in the Rust code for your extension, implement the `language_server_command` method on your extension:
```rust
impl zed::Extension for MyExtension {
fn language_server_command(
&mut self,
language_server_id: &LanguageServerId,
worktree: &zed::Worktree,
) -> Result<zed::Command> {
Ok(zed::Command {
command: get_path_to_language_server_executable()?,
args: get_args_for_language_server()?,
env: get_env_for_language_server()?,
})
}
}
```
You can customize the handling of the language server using several optional methods in the `Extension` trait. For example, you can control how completions are styled using the `label_for_completion` method. For a complete list of methods, see the [API docs for the Zed extension API](https://docs.rs/zed_extension_api).