Home Explore Blog CI



zed

6th chunk of `docs/src/extensions/languages.md`
33aafd33ceb944d69eb7870dda40806a758f566efad10f2c00000001000007f2
| @class.inside    | The contents of a class definition.                                     | `ic` text object                                 |
| @comment.around  | An entire comment (e.g. all adjacent line comments, or a block comment) | `gc` text object                                 |
| @comment.inside  | The contents of a comment                                               | `igc` text object (rarely supported)             |

For example:

```scheme
; include only the content of the method in the function
(method_definition
    body: (_
        "{"
        (_)* @function.inside
        "}")) @function.around

; match function.around for declarations with no body
(function_signature_item) @function.around

; join all adjacent comments into one
(comment)+ @comment.around
```

### Text redactions

The `redactions.scm` file defines text redaction rules. When collaborating and sharing your screen, it makes sure that certain syntax nodes are rendered in a redacted mode to avoid them from leaking.

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)

Title: Text Redactions and Runnable Code Detection
Summary
This section continues the discussion on Tree-sitter integration in Zed, focusing on text redactions and runnable code detection. Text redactions, defined in `redactions.scm`, are used to prevent information leakage during screen sharing by redacting specific syntax nodes, like number and string values in JSON key-value pairs and arrays. Runnable code detection, defined in `runnables.scm`, identifies runnable code blocks within a file, exemplified by detecting scripts within a JSON document. The document provides examples and explanation of the captures used in both features.