25 Commits
Author SHA1 Message Date
Miguel Raz Guzmán Macedo 81299967df lints: Add map_lookup_then_insert lint (#62681)
## Objective

Sometimes we can do a hash lookup twice, which is slow and unidiomatic.
We should use the Entry API instead.

## Solution

Add another `dylint` lint called `map_lookup_then_insert` that catches
those cases.

This works with HashMap, BTreeMap, HashSet, BTreeSet and
entry-compatible ADTs.

## What it catches

See the examples in the `tooling/lints/ui/map_lookup_then_insert.rs`.

It's mostly things of the form

```rust
if let Some(value) = map.get(&key) {
    *value
} else {
    map.insert(key, 1);
    1
}
```

which should be 

```rust
*map.entry(key).or_insert(1)
```

The two key expressions are matched up to borrows/derefs,
value-preserving
conversions (`clone`, `to_owned`, `to_string` on string types, `to_vec`
on
slices, `String::from` on `&str` — each resolved by definition, not by
name),
and immutable local aliases. So looking up `&key` and inserting
`key.clone()`
is caught too. When a conversion had to be peeled, the diagnostic
carries a
note that an entry-API rewrite would perform that copy on hits as well
as
misses.

## What it deliberately does not catch

Forms Clippy already catches.

## Findings

A `--workspace` run finds 31 warnings at 30 unique sites in `zed`:
the 16 the plain key matching finds, plus 15 more that require the
conversion/alias matching (e.g. `tiles_by_key.get(key)` followed by
`tiles_by_key.insert(key.clone(), tile)` in `metal_atlas.rs`).

Will post those fixes in a follow up PR.

## Testing

UI tests cover every `Entry` method positively and negatively, BTreeMap
mirrors, set cases, and the Clippy-deferral boundary. The
key-normalization logic is covered by nine positive cases (cloned keys,
UFCS forms, `to_owned`/`to_string`/`to_vec`/`String::from`, deref
layers, local aliases, sets) and six negative cases (inherent methods
merely named `clone`/`to_owned`, mutated aliases, a clone of a different
key, `to_string` on a non-string key, and side-effecting initializers).

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- N/A
2026-08-28 20:01:28 +00:00
Miguel Raz Guzmán Macedo 513ad12cef Avoid redundant string allocations (#63377)
Remove unnecessary intermediate `String` allocations when constructing
`Arc<str>` and `SharedString` values. Use static `SharedString` storage
for fixed worktree picker identifiers.

Validation:

- `cargo fmt --all -- --check`
- `tooling/lints/single-lint owned_string_into_shared -p editor -p
git_ui_core -p toolchain_selector`
- `cargo test -p editor -p git_ui_core -p toolchain_selector`

Release Notes:

- N/A
2026-08-28 17:31:36 +00:00
Miguel Raz Guzmán Macedo b90c4869f9 Require clear sections in lint UI fixtures (#62659)
Add `// --- SHOULD FIRE ---- ` and `// ---- SHOULD NOT FIRE ---- ` to
the `/lint-creator` skill.

Release Notes:

- N/A
2026-08-27 05:53:18 +00:00
Miguel Raz Guzmán Macedo 22a582a86a Remove wasted clones of loop-invariant values (#62763)
# Objective

Remove avoidable clones of loop-invariant values that pay a copy on
every loop iteration. These were found by running a prototype
`deep_clone_in_loop` dylint (modeled on the accidentally quadratic
project-search fix in #62658) across the workspace. None of these sites
are quadratic in practice — the loops are bounded — but each one does
strictly wasted work that a one-line change removes.

## Solution

- `collab/src/api/extensions.rs`: use `next_marker.take()` instead of
`next_marker.clone()` for the S3 pagination marker. The marker is either
overwritten via `clone_from` at the end of the iteration or the loop
breaks, so it is never read after the `take`.
- `project/src/manifest_tree/path_trie.rs`: build the trie key with
`Arc::from(path_so_far.as_rel_path())` instead of
`path_so_far.clone().into()`. The `From<RelPathBuf> for Arc<RelPath>`
impl copies the bytes into the `Arc` anyway, so the intermediate
`RelPathBuf` clone was a second, redundant copy.
- `context_server/src/client.rs`: in `notify`, split off the last
handler and move the `serde_json::Value` payload into it, cloning only
for the preceding handlers. Previously every handler received a clone
and the final one was always wasted.
- `editor/src/rewrap.rs`: use `std::mem::replace` to move the
comment-delimiter and rewrap-prefix accumulators into the pushed range
instead of cloning them and immediately reassigning.

## Testing

- `cargo check -p collab -p project -p context_server -p editor` —
clean.
- `cargo test -p editor rewrap` — 7/7 pass, including the
boundary-sensitive `test_rewrap*` editor tests.
- `cargo test -p context_server` — 97/97 pass.
- `cargo test -p project path_trie` — 2/2 pass.
- Re-ran the `deep_clone_in_loop` lint on the four crates: the
`extensions.rs`, `path_trie.rs`, and `rewrap.rs` hits are gone;
`client.rs` still (correctly) reports the remaining required per-handler
clone.
- Not tested platform-specifically; the changes are
platform-independent.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- N/A
2026-08-27 05:35:30 +00:00
Miguel Raz Guzmán Macedo 1a42a2b714 Improve lint-creator skill (#60383)
Rewrote `.agents/skills/lint-creator/SKILL.md` to be more concrete and
concrete.

Release Notes:

- N/A
2026-08-27 05:34:16 +00:00
Miguel Raz Guzmán Macedo f9ed08004c Use unstable sorts before deduplication (#63199)
# Objective

Get some speedups by using unstable sortts.
Supersedes #58761 after rebasing onto current `main`.

## Solution

replace `.sort()` by `.unstable_sort()`.

## Testing

All tests pass in affected crates:

```
cargo test -p edit_prediction_context -p editor -p git -p language -p language_tools -p migrator
```

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- N/A
2026-08-25 15:46:41 +00:00
Miguel Raz Guzmán Macedo 4af4524d2e Disable one-time code autofill in Zed text inputs (#60116)
Closes #46899

## Summary

- Set `NSAutoFillRequiresTextContentTypeForOneTimeCodeOnMac` in the
macOS Info.plist fragments
- Prevent macOS 26 Security Code AutoFill from appearing in regular Zed
text inputs unless explicitly annotated as one-time-code fields

## Testing

- Not run; Info.plist-only change

Release Notes:

- Fixed macOS showing one-time-code AutoFill suggestions in regular Zed
text inputs.
2026-08-20 17:53:01 +00:00
Miguel Raz Guzmán Macedo 6c4b9ae965 Replace panicking unwraps in iterator and Option chains (#61277)
# Objective

Remove `.unwrap()` calls in iterator/`Option` chains that could panic at
runtime.

## Solution

Use `and_then`/`filter_map` with `.ok()` for fallible downcasts
(`entry_view_state.rs`) and keystroke parsing (`vim/command.rs`); use a
descriptive `expect` in `suggest_autoindents` where the invariant is
intentional (`buffer.rs`).

## Testing

- `cargo test -p language buffer` (69 passed)
- `cargo test -p vim command` (26 passed)
- `cargo test -p agent_ui entry_view` (3 passed)

## Self-Review Checklist:

- [x] I have reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content adheres to Zed's UI standards
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
2026-07-23 07:54:43 +00:00
Miguel Raz Guzmán Macedo 78652e2f50 Fix several small performance inefficiencies in hot paths (#61275)
# Objective

Land five small, independent performance fixes found during an audit of
hot paths (anchor resolution, line shaping, worktree scanning, and
sorting in multibuffers).

## Solution

Each fix is its own commit, so **this PR is best reviewed
commit-by-commit** — every commit message contains the full reasoning
for that change:

- `text`: Avoid redundant rope traversal in `Anchor → usize` conversion
— call `offset_for_anchor` directly instead of `summary_for_anchor`,
which recomputed the same byte offset with ~4 extra O(log n) tree walks.
This is the hottest anchor-resolution path.
- `editor`: Avoid double allocation per shaped line —
`line.as_str().into()` instead of `line.clone().into()`, which allocated
twice per visible line, every frame.
- `text`: Use `sort_unstable_by_key` in operation queue insertion —
Lamport timestamps are unique keys and duplicates are deduped right
after, so stability buys nothing.
- `multi_buffer`: Sort with an explicit comparator instead of
`sort_unstable_by_key`, which cloned a `PathKey` (`Arc` refcount bump)
on every comparison.
- `worktree`: Replace O(n²) `Vec::remove` in the deferred-directory pass
with an O(1) `None` assignment — the vec is already
`Vec<Option<ScanJob>>` and is consumed with `.flatten()`.

## Testing

- No behavior changes intended; all changes are mechanical and tests
affected crates pass: `text`, `editor`, `multi_buffer`, `worktree`.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Improved editor performance through several micro-optimizations in
anchor resolution, line shaping, and worktree scanning.
2026-07-19 05:36:35 +00:00
Miguel Raz Guzmán Macedo b099024705 Fix typos and grammatical mistakes in docs (#59495)
# Objective

- Describe the objective or issue this PR addresses. -> ** Typo and
grammar fixes!**

## Solution


## Testing

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Showcase

---

Release Notes:

- N/A
2026-07-08 12:32:00 +00:00
Miguel Raz Guzmán Macedo 657962ab30 Use more .array_windows::<N>() (#58877)
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

The fight against entropy continues...

Release Notes:

- N/A or Added/Fixed/Improved ...
2026-07-08 12:10:32 +00:00
Miguel Raz Guzmán Macedo 1d1e19985a Add dylint lint library for Zed-specific patterns (#58496)
Adds a dylint library under tooling/lints that flags Zed-specific
anti-patterns:

* shared_string_from_str_literal, 
* async_block_without_await, 
* entity_update_in_render, 
* notify_in_render, 
* owned_string_into_shared, 
* len_in_loop_condition, and 
* blocking_io_on_foreground. 

Includes UI tests, a single-lint helper, and workspace.metadata.dylint
registration so cargo dylint --all discovers it. The library pins its
own nightly toolchain (kept out of the main workspace) and tracks dylint
6.

Release Notes:

- N/A

Self-Review Checklist:

- [ ] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [ ] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A or Added/Fixed/Improved ...
2026-07-03 22:05:34 +00:00
Miguel Raz Guzmán Macedo 7b556c9060 Add zed: get merch command palette action (#60330)
Adds a `zed: get merch` command palette action that opens
https://merch.zed.dev/ in the system browser.

Just thought it'd be fun!

Release Notes:

- Added a `zed: get merch` action that opens the Zed merch store.
2026-07-03 05:59:13 +00:00
316ab20bb5 util: Use job objects to reap spawned process trees on Windows (#58885)
On Windows, `util::process::Child::kill()` only terminated the direct
child process, and nothing tied the lifetime of spawned process trees to
Zed. External agent servers launched through ACP (e.g. `claude-code-acp`
via `npx`) spawn node workers and MCP servers as grandchildren, which
were orphaned on every session teardown and accumulated indefinitely —
hundreds of idle `node.exe` processes and GBs of RAM over days.

This PR assigns spawned processes to a Win32 job object configured with
`JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`:

- `kill()` now calls `TerminateJobObject`, killing the entire tree
instead of just the (shell wrapper) child.
- Dropping `Child` closes the job handle, which makes the OS reap the
tree — including when Zed exits for any reason (even crashes), since the
OS closes its handles.
- Unix behavior (process groups via `killpg`) is unchanged.

Added two Windows tests that spawn a real `powershell -> ping` process
tree and assert the grandchild is terminated on `kill()` and on drop.
Both fail without the fix and pass with it. Verified with `cargo test -p
util`, `script/clippy -p util`, and `cargo check -p agent_servers -p
dap` on Windows 11.

Closes #58873

Release Notes:

- Fixed external agent servers and debug adapters leaking helper
processes (e.g. node workers and MCP servers) on Windows.

---------

Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
2026-06-15 10:55:39 +00:00
02275294af Limit top context identifiers and diagnostics (#58870)
- Replace full sort and truncate with a budgeted top-N approach for
context identifiers using truncate_to_bottom_n_sorted_by.
- Introduce MAX_DIAGNOSTICS = 10 and prune diagnostics to this limit
with select_nth_unstable_by_key, then sort the remainder.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- Removed small allocations on the edit_predictions critical path by
using select_nth and sort_unstable

Co-authored-by: Nathan Barry <nathanbarry474@gmail.com>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
2026-06-08 22:43:48 +00:00
Miguel Raz Guzmán Macedo b1ba025093 Use unstable sorts if deduplicating (#58751)
# Impact

Recent Project picker, `find all references`, the sidebar's
`rebuild_contents` might get a slight speed boost.

# Reasoning

Unstable sort variants

https://doc.rust-lang.org/stable/std/primitive.slice.html#method.sort_unstable
are non-allocating but potentially destructive. Since we're
deduplicating elements anyways, use the unstable variant.

This call will use ipnsort


https://github.com/Voultapher/sort-research-rs/blob/main/writeup/unreasonable/text.md#various-generic-algorithms

I expect the speedups to be at least 30%, though it's highly input
dependent.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
2026-06-08 19:47:30 +00:00
Miguel Raz Guzmán Macedo 70a1715fc3 Change .join("") to .concat() (#58200)
Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- N/A
2026-06-01 17:04:14 +00:00
Miguel Raz Guzmán Macedo a2da6d971f Fix grammatical errors throughout the documentation (#58183)
Fixes a batch of grammatical mistakes found across the `docs/` folder:
typos/misspellings, subject-verb agreement errors, missing and
duplicated words, article errors (`a`/`an`), wrong word forms, and
punctuation issues (doubled periods, unclosed parentheses).

Scope is limited to prose in `docs/src/**`; no behavior, settings, or
code changes. 33 files updated, 49 lines changed.

Representative fixes:

- `globs.md`: "features varies" -> "features"; "platforms libc" ->
"platform's libc".
- `installation.md`: "the follow macOS releases" -> "the following macOS
releases".
- `key-bindings.md`: "command pallets" -> "command palette's".
- `linux.md`: capitalization after a period; "able to the environment
variable" -> "able to set the environment variable"; "These feature also
requires" -> "This feature also requires".
- `multibuffers.md`: "Window/Linux" -> "Windows/Linux"; added a missing
closing parenthesis.
- `reference/all-settings.md`: several agreement/article/missing-word
fixes plus an unclosed parenthesis.
- `languages/*`: "partent" -> "parent", "complimentary" ->
"complementary", "setup" -> "set up", "is enabled" -> "are enabled", and
similar.

Release Notes:

- N/A
2026-05-31 22:05:41 +00:00
Miguel Raz Guzmán Macedo 46dafb774d gpui: Remove naga dependency (#55070)
Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes
https://github.com/zed-industries/zed/issues/54981#issuecomment-4333425722

Release Notes:

- N/A or Added/Fixed/Improved ...
2026-04-28 10:00:07 +00:00
Miguel Raz Guzmán MacedoandJoseph T. Lyons c8d38a5d9d docs: Center and re-flow perf images (#53004)
Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A or Added/Fixed/Improved ...

Co-authored-by: Joseph T. Lyons <JosephTLyons@gmail.com>
2026-04-02 10:24:43 -06:00
Miguel Raz Guzmán Macedo 28ee501f7d Add script/triage_watcher.jl (#45384)
Release Notes:

- N/A
2025-12-19 18:09:40 +00:00
Miguel Raz Guzmán Macedo 0d92fb1916 Add davidbarsky to community champion labelers (#45132) 2025-12-17 17:32:18 +00:00
Miguel Raz Guzmán MacedoandKunall Banerjee f59e5669df Add WSL Linux choice and settings.json prompt for GitHub issue template (#43479)
Release Notes:

- N/A

---------

Co-authored-by: Kunall Banerjee <hey@kimchiii.space>
2025-11-26 11:57:27 -06:00
Miguel Raz Guzmán Macedoandmikayla 9d89985c66 project_panel: Add CollapseAllEntries keybinding (#43112)
Motivated by user feature requests

* https://github.com/zed-industries/zed/issues/6880
* https://discord.com/channels/869392257814519848/1439453067119562793

In analogy with VSCode functionality, we're adding a keybinding to the
project panel.

This is particularly for useful for large monorepos.

Release Notes:

- Keybinding added for `CollapseAllEntries` when in the `ProjectPanel`.

Co-authored-by: mikayla <mikayla@zed.dev>
2025-11-20 14:30:13 +05:30
Miguel Raz Guzmán Macedo 6cb14ef002 Add @miguelraz to reviewers and support sections (#42904)
Release Notes:

- N/A *or* Added/Fixed/Improved ...
2025-11-17 15:22:34 -06:00