Zed Improved. Aiming to improve upon Zed and make a truly delightful code editor.
https://zed.dev
![]() Closes #21541 Closes #22726 This should fix snippets in languages, like PHP, that are based on the HTML syntax layer. To be honest, I don't totally get where HTML comes into it, but the issues outlined in #21541 and #22726 both boil down to "Zed only shows me HTML snippets in PHP/ERB files; I expected to see PHP/ERB snippets". This solution is based on the comments between @mrnugget and @osiewicz in #22726: resolve/combine snippets for all language layers at the given position, whereas current behavior is to resolve snippets only for the `.last()` language layer at the given position. - add `Buffer:languages_at()` (note the plural) - update `snippet_completions()` in `editor.rs` to loop over each language, gathering snippets as it goes - the primary logic for resolving snippets within a single language has not changed ### Verifying this change I couldn't find tests related to snippet and currently active languages (CI may show them to me 😆 ) but I can add some if desired and w/ perhaps a little coaching or prompting about another test to look to for inspiration. I have confirmed that this works for PHP, but I have not checked ERB because I'm not familiar with it or set up for it. To check this manually: 1. install the PHP extension 2. install at least 1 snippet for each of html, php and phpdoc. If you don't have any, these should work: ```sh # BEWARE these will clobber existing snippets! echo '{"dddd":{"body":"hello from phpdoc"}}' > ~/.config/zed/snippets/phpdoc.json echo '{"pppp":{"body":"hello from PHP"}}' > ~/.config/zed/snippets/php.json echo '{"hhhh":{"body":"hello from HTML"}}' > ~/.config/zed/snippets/html.json ``` 3. open any PHP file. If you don't have one, here's one that should work: ```php <?php /** * */ function function_name() { } ``` 4. Place your cursor in a PHPdoc comment (eg after the `/**` on line 3) - you should be able to use the `dddd`, `pppp` and `hhhh` snippets; on `main`, only the `dddd` snippet works here 5. Move your cursor to a non-comment PHP area (eg after the `{` on line 7) - you should be able to use the `pppp` and `hhhh` snippets, but not `dddd`; on `main`, only `hhhh` works here ### Performance This adds 2 separate (not nested) loops to `snippet_completions()`, each of which will iterate over the active language scopes at the given location. I have not looked into the specifics of how many layers most languages have, but I suspect that *most* users will see identical performance as before because there will only be 1 scope active most of the time. In some cases, though (eg PHP, ERB, maybe template strings in JS), the editor will be looping over more layers, possibly many in some deeply injected/embedded cases (I'm thinking of a regex template string in a JS heredoc string in a PHP script in an HTML file). I don't expect this to be an issue – nor has it been in my usage and testing – but performance of snippets could be affected in pathological cases. ### Alternate solutions Instead of resolving snippets for *all* layers, we could just change how we pick which language to resolve. Instead of always using `.last()`, perhaps we could do something more clever. This feels like it could be tricky and potentially error prone, though. Release Notes: - Snippets are now resolved for all languages active at the cursor location. - Fixed snippets in PHP, ERB and other languages whose syntax layers are based on HTML |
||
---|---|---|
.cargo | ||
.cloudflare | ||
.config | ||
.github | ||
.zed | ||
assets | ||
crates | ||
docs | ||
extensions | ||
legal | ||
nix | ||
script | ||
tooling | ||
.git-blame-ignore-revs | ||
.gitattributes | ||
.gitignore | ||
.mailmap | ||
Cargo.lock | ||
Cargo.toml | ||
clippy.toml | ||
CODE_OF_CONDUCT.md | ||
compose.yml | ||
CONTRIBUTING.md | ||
Cross.toml | ||
debug.plist | ||
default.nix | ||
docker-compose.sql | ||
Dockerfile-collab | ||
Dockerfile-collab.dockerignore | ||
Dockerfile-cross | ||
Dockerfile-cross.dockerignore | ||
Dockerfile-distros | ||
Dockerfile-distros.dockerignore | ||
flake.lock | ||
flake.nix | ||
LICENSE-AGPL | ||
LICENSE-APACHE | ||
LICENSE-GPL | ||
livekit.yaml | ||
Procfile | ||
Procfile.postgrest | ||
README.md | ||
renovate.json | ||
rust-toolchain.toml | ||
shell.nix | ||
typos.toml |
Zed
Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Installation
On macOS and Linux you can download Zed directly or install Zed via your local package manager.
Other platforms are not yet available:
- Windows (tracking issue)
- Web (tracking issue)
Developing Zed
- Building Zed for macOS
- Building Zed for Linux
- Building Zed for Windows
- Running Collaboration Locally
Contributing
See CONTRIBUTING.md for ways you can contribute to Zed.
Also... we're hiring! Check out our jobs page for open roles.
Licensing
License information for third party dependencies must be correctly provided for CI to pass.
We use cargo-about
to automatically comply with open source licenses. If CI is failing, check the following:
- Is it showing a
no license specified
error for a crate you've created? If so, addpublish = false
under[package]
in your crate's Cargo.toml. - Is the error
failed to satisfy license requirements
for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to theaccepted
array inscript/licenses/zed-licenses.toml
. - Is
cargo-about
unable to find the license for a dependency? If so, add a clarification field at the end ofscript/licenses/zed-licenses.toml
, as specified in the cargo-about book.