Commit Graph

10037 Commits

Author SHA1 Message Date
Nathan Sobo
f52d3ea5ef Clean up tooltips, create conversation on cmd-n
Co-Authored-By: Antonio Scandurra <antonio@zed.dev>
2023-06-28 10:27:29 +02:00
Nathan Sobo
d41a7f41fb Space out assistant icons to match pane icons
Co-Authored-By: Antonio Scandurra <antonio@zed.dev>
2023-06-28 10:00:28 +02:00
Max Brunsfeld
f128cf4a33
Defer scanning some worktree subdirectories until they are expanded in the project panel (#2622)
Closes
https://linear.app/zed-industries/issue/Z-352/high-memory-usage-from-fs-scanning-if-project-contains-symlinks-that

### Background

Currently, when you open a project, Zed eagerly scans the directory,
building an in-memory representation of all of the files and directories
within. This scanning includes all git-ignored files and follows any
symlinks. When any directory changes on disk, Zed recursively rescans it
in order to keep its in-memory representation up-to-date. When
collaborating, all of these files are replicated to all guests.

Right now, there are some performance problems associated with the
maintenance of this filesystem state:
* For various reasons, some projects contain symlinks that point out to
large folders like `$HOME`, which itself contains many symlinks that
point to the same large directory. When these projects are opened, the
worktree scans endlessly, using more and more memory.
* Some git-ignored directories (like `target` in a rust project) contain
*many* more files than are actually tracked in the git repository. These
files often change as a result of saving, (e.g. because the compiler
runs). Maintaining in memory all of these paths isn't useful to the
user, and causes significant CPU usage on every save. Most importantly,
when collaborating sending all of these changes to guests can be slow,
and can delay all other RPC messages.

### Change

This PR changes the worktree's filesystem-scanning logic to be *lazy*
about scanning two types of directories:
* git ignored directories
* "external" directories (those that are canonically located outside of
the worktree root, but accessed via symlinks)

The laziness works as follows. When, during a recursive scan, a
directory is found that falls into one of the above 2 categories, that
directory is marked as "unloaded". The directory might later be scanned,
if some explicit operation is performed within it (like opening a
buffer, or creating a file), if any collaborator expands that directory
in their project panel, or if an LSP requests that it be watched.

### Results

When collaborating on the `zed` folder:

| metric | before | after |
|-------|--------|------|
| # `worktree_entries` in collab db initially | 154,763 |  77,679 |
| # `worktree_entries` in collab db after 5 saves | 181,952 | 77,679
(nothing new to scan) |
| app memory footprint (host) | 260MB | 228.5 MB  |

The db thing is a win, because reading and writing to the
`worktree_entries` table is one of the most expensive thing that the
`collab` server does.

There's also generally lower background CPU usage after every save,
because we don't need to recursively rescan directories inside of
`target`.

### Limitations

We still end up scanning some unnecessary directories (like
`target/debug/build/zed-b612db829aeac16e/out`) because the LSP instructs
us to watch those.

### To do:

* [x] Expand parent directories of any path opened via LSP
* [x] Avoid creating orphaned entries when FS events happen inside of
unscanned directories
* [x] Scan any newly-non-ignored directories after gitignore changes
* [x] Emit correct events for newly-discovered paths when expanding dirs
* [x] GC the set of expanded directory ids when dirs are removed
* [x] Don't include "external" entries in file-finder
* [x] Expand any directories watched by LSP
* [ ] manual testing and profiling

### Release Notes:

- Fixed a bug where Zed would use excessive memory when a project folder
contained symlinks pointing to directories outside of the project.
- Reduced Zed's memory and CPU usage when working in folders containing
many git-ignored files.
2023-06-27 17:07:23 -07:00
Max Brunsfeld
201188fdaa Use FakeFs in worktree gitignore test 2023-06-27 15:40:36 -07:00
Max Brunsfeld
fc02381196
Fix bugs in handling combined injections exposed by HEEx (#2652)
Fixes
https://linear.app/zed-industries/issue/Z-2481/heex-this-snippet-triggers-a-hard-crash

Release Notes:

- Fixed a crash that would sometimes occur when editing a HEEx file
([#1703](https://github.com/zed-industries/community/issues/1703)).
2023-06-27 15:17:29 -07:00
Max Brunsfeld
81c26cfea0 Fix bugs in handling combined injections exposed by HEEx 2023-06-27 15:08:26 -07:00
Nate Butler
9389b50646
Update local-collaboration.md
Add missing livekit info
2023-06-27 10:52:38 -04:00
Nate Butler
0548df09d9
Update local-collaboration.md 2023-06-27 10:05:37 -04:00
Nate Butler
f311d307b1
Create local-collaboration.md (#2651)
I forget how to do this every single time 😅 Please update anything that
is incorrect!

[[PR Description]]

Release Notes:

- N/A
2023-06-27 09:52:15 -04:00
Nate Butler
a67eba9fed
Create local-collaboration.md
I forget how to do this every single time 😅
2023-06-27 09:51:30 -04:00
Nathan Sobo
04d93dfbd9
vim: indent/outdent (#2644)
Release Notes:

- vim: support indent/outdent
([#832](https://github.com/zed-industries/community/issues/832>)).
2023-06-27 04:15:55 -06:00
Nathan Sobo
fd3ee0ebd0
Vim toggle case (#2648)
Release Notes:

- vim: Add ~ to toggle case
([#1410](https://github.com/zed-industries/community/issues/1410))
2023-06-27 04:13:24 -06:00
Nathan Sobo
29b2639b4c Merge remote-tracking branch 'origin/main' into vim-indent 2023-06-27 12:09:47 +02:00
Nathan Sobo
16c23557b8
vim: Fix scrolling (#2647)
After #2641 we noticed that scrolling didn't take a count parameter, and
a few other issues with the way that we calculated the distance to
scroll.
 
Release Notes:

- Improved distance calculations for page-up/page-down
- vim: Allow counts to work with scrolling shortcuts.
2023-06-27 04:01:14 -06:00
Nathan Sobo
7294314ce7
vim: shortcuts for tab navigation (#2649)
Release Notes:

- vim: added gt/ctrl-pagedown and gT/ctrl-pageup for tab navigation
2023-06-27 03:57:01 -06:00
Nathan Sobo
0fd0b60bd6
vim: Fix code actions menu (#2650)
Fixes: zed-industries/community#1690

I'm not sure this is the correct way to fix this...
* A simpler approach would be to just say `!showing_code_actions` in the
binding file (as `showing_completions` can only happen in insert mode -
and `VimControl` will be false). This seemed a little error prone if
more menus were added in the future.
* A more complicated approach would be to copy the way this is done from
the MouseContextMenu, which registers its own keyboard shortcuts, and as
such uses those when it's open. This seems "more correct", but is a
major refactoring for a very small reward.

Release Notes:

- vim: Fix code actions menu
([#1690](https://github.com/zed-industries/community/issues/1690))
2023-06-27 03:56:08 -06:00
Conrad Irwin
a1343f0d2c vim: Fix code actions menu
Fixes: zed-industries/community#1690
2023-06-26 21:46:06 -06:00
Conrad Irwin
a9aa5e5196 vim: Add ~ to change case
Fixes: zed-industries/community#1410
2023-06-26 20:22:24 -06:00
Conrad Irwin
77dc22bff6 vim: Fix cursor restoration when undoing substitute 2023-06-26 20:22:24 -06:00
Conrad Irwin
73920807a9 vim: shortcuts for tab navigation 2023-06-26 15:07:19 -06:00
Conrad Irwin
02fc5dd6c9 vim: Fix scrolling
After #2641 we noticed that scrolling didn't take a count parameter.

The PageDown/PageUp logic was also broken by an additional -1 (for both
vim mode and not).
2023-06-26 13:29:14 -06:00
Joseph T. Lyons
a09c6b2691
Add installation_id to panic events (#2642)
We want to add installation_id to the panic events so that we can easily
know if multiple panics are coming from the same person or different
people. 5 panics from one person isn't as bad as 5 panics from 5 people.

[zed.dev pr](https://github.com/zed-industries/zed.dev/pull/343)

Release Notes:

- N/A
2023-06-26 13:35:23 -04:00
Joseph T. Lyons
c0fb98cb3f Factor out key name 2023-06-26 13:31:41 -04:00
Joseph T. Lyons
8d1cc8815b Merge branch 'main' into add-installation-id-to-panic-events 2023-06-26 13:27:14 -04:00
Nate Butler
37814bc4fc
Fix incorrect ThemeAppearance (#2645)
[[PR Description]]

When we updated the way themes were built it looks like we accidentally
gave `Atelier Forest Light` the wrong `ThemeAppearance`. This PR fixes
that.

Release Notes:

- Fixed the `Atelier Forest Light` theme, which was incorrectly set as a
dark theme.
2023-06-26 13:20:32 -04:00
Antonio Scandurra
0d3e75e873
Introduce the ability to load and save conversations with the assistant (#2623)
Closes
https://linear.app/zed-industries/issue/Z-1890/save-assistant-conversations-to-the-filesystem
Closes
https://linear.app/zed-industries/issue/Z-2459/cycling-message-roles-on-the-last-empty-message-alters-the-message
Closes
https://linear.app/zed-industries/issue/Z-2460/cycling-role-in-an-empty-message-cycles-wrong-messages-role
Closes https://linear.app/zed-industries/issue/Z-2365/assistant-toolbar
Closes
https://linear.app/zed-industries/issue/Z-2461/always-insert-an-empty-message-at-the-end-of-the-conversation

Release Notes:

- You can now save conversations with the assistant to
`~/.config/zed/conversations` with `cmd-s`. Conversations are also
automatically saved as they are edited.
2023-06-26 19:17:16 +02:00
Antonio Scandurra
43723168fc Remove assistant panel zoom test
The test was testing pretty straightforward logic, but for some strange reason
it was failing on CI (but passed locally). I think it's fine to delete it and
make progress, if zooming regresses we'll find out pretty quickly.
2023-06-26 19:10:59 +02:00
Nate Butler
1dc52c7547 Fix incorrect ThemeAppearance 2023-06-26 13:07:33 -04:00
Antonio Scandurra
d46d3e6d15 Try fixing test on CI 2023-06-26 18:18:22 +02:00
Conrad Irwin
c3e8cae20f vim: indent/outdent
Fixes: zed-industries/community#832
2023-06-26 10:08:34 -06:00
Antonio Scandurra
e77abbf64f Add hover state to assistant buttons 2023-06-26 17:48:43 +02:00
Antonio Scandurra
723c8b98b3 Show quote selection button 2023-06-26 17:24:31 +02:00
Antonio Scandurra
e723686b72 Shwo tooltips for assistant buttons 2023-06-26 17:17:45 +02:00
Antonio Scandurra
edc7f30660 Add assistant icons to the toolbar
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2023-06-26 16:49:33 +02:00
Antonio Scandurra
c5b3785be5 Revert "Panic in debug if global settings can't be deserialized from defaults"
This reverts commit 7a051a0dcb.
2023-06-26 16:03:19 +02:00
Antonio Scandurra
00e37bc2a2 Merge remote-tracking branch 'origin/main' into save-conversations 2023-06-26 15:59:19 +02:00
Antonio Scandurra
9d4dd5c42b Insert empty user message when assisting with the current last message
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2023-06-26 15:57:36 +02:00
Antonio Scandurra
92d7b6aa3b Allow toggling back and forth between conversation list and editor
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2023-06-26 15:43:21 +02:00
Nathan Sobo
3f4a06f576
Add an Element derive macro for building components out of other elements (#2643)
To turn any struct into a composite element, you can implement a render
method with the following signature:

```rs
fn render<V: View>(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
```

Then add #[derive(Element)] to the struct definition.

This will make it easier to introduce higher-level components that are
expressed in terms of other elements. Instead of calling functions that
return elements, we can now make any struct into an element fairly
easily. The advantage is that we can use method chaining to express
optional state on these components, and they blend in better with other
elements.

cc @mikayla-maki @osiewicz @iamnbutler 

Release Notes:

- N/A
2023-06-25 08:12:02 -06:00
Nathan Sobo
bede668b14 Add a derive macro for Element
To turn any struct into a composite element, you can implement a render method
with the following signature:

fn render<V: View>(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;

Then add #[derive(Element)] to the struct definition.

This will make it easier to introduce higher-level components that are expressed in
terms of other elements.
2023-06-25 07:51:50 -06:00
Kirill Bulatov
82bd5fb564 Fix main compilation 2023-06-25 01:43:58 +03:00
Joseph T. Lyons
7d065fa14e Add installation_id to panic events
Co-Authored-By: Julia <30666851+ForLoveOfCats@users.noreply.github.com>
2023-06-23 21:02:01 -04:00
Max Brunsfeld
030984dca4
Vim: substitute support (#2641)
Release Notes:

- vim mode now supports `s` for substitute
2023-06-23 12:58:14 -07:00
Max Brunsfeld
b0631e90ad
vim: Fix 1G (#2640)
Before this change code could not distinguish between a user providing a
count of 1 and no count at all.

Fixes: zed-industries/community#710

Release Notes:

- 1G now correctly goes to the first line in vim mode
([710](zed-industries/community#710))
2023-06-23 12:55:46 -07:00
Max Brunsfeld
91f87bb31f Scan any external/ignored directories needed for LSP watchers
Also, don't include "external" files in project searches. Treat them
the same as ignored files.

Co-authored-by: Nathan Sobo <nathan@zed.dev>
2023-06-23 12:53:25 -07:00
Max Brunsfeld
27b74e9ea1 Prune the set of expanded dir ids as entries are removed 2023-06-23 10:23:21 -07:00
Max Brunsfeld
b22a18345e Emit loaded events for lazily loaded paths in worktree 2023-06-23 09:39:37 -07:00
Antonio Scandurra
5c5d598623 Insert new message right before the next valid one 2023-06-23 11:13:52 +02:00
Antonio Scandurra
6c7271c633 Test serialization roundtrip 2023-06-23 10:42:15 +02:00
Antonio Scandurra
c38bf2de33 Sort conversations in descending chronological order 2023-06-23 10:05:21 +02:00