Compare commits

..

143 Commits

Author SHA1 Message Date
Richard Feldman
c6724d598e Render our code edit tool use differently 2024-11-20 11:42:09 -05:00
Richard Feldman
61a516e95f Replace assistant XML parsing with tool use 2024-11-20 11:03:37 -05:00
Richard Feldman
eb1754a091 Use tool call with Suggest Edits 2024-11-20 10:42:08 -05:00
Richard Feldman
2386595de5 wip 2024-11-20 01:01:36 -05:00
Richard Feldman
b36ed56443 wip 2024-11-20 00:49:22 -05:00
Richard Feldman
1b72c5402d Revert "Try cusotomizing RootSchema (decided against this approach)"
This reverts commit e82987db19286a18779f9e2e9d634d9cf98672ee.
2024-11-20 00:45:50 -05:00
Richard Feldman
a143fdc630 Try cusotomizing RootSchema (decided against this approach) 2024-11-20 00:43:08 -05:00
Richard Feldman
1e9666649e Add preliminary tool use for code edits 2024-11-20 00:39:59 -05:00
Conrad Irwin
3c57a4071c vim: Fix jj to exit insert mode (#20890)
Release Notes:

- (Preview only) fixed binding `jj` to exit insert mode
2024-11-19 20:00:11 -07:00
Conrad Irwin
ad6a07e574 Remove comments from discord release announcements (#20888)
Release Notes:

- N/A
2024-11-19 20:00:03 -07:00
Conrad Irwin
c2668bc953 Fix draft-releaase-notes (#20885)
Turns out this was broken because (a) we didn't have tags fetched,
and (b) because the gh-release action we use is buggy.

Release Notes:

- N/A
2024-11-19 19:08:33 -07:00
Conrad Irwin
705a06c3dd Send Country/OS/Version amplitude style (#20884)
Release Notes:

- N/A
2024-11-19 16:38:14 -07:00
Conrad Irwin
f77b6ab79c Fix space repeating in terminal (#20877)
This is broken because of the way we try to emulate macOS's
ApplePressAndHoldEnabled.

Release Notes:

- Fixed holding down space in the terminal (preview only)
2024-11-19 13:43:24 -07:00
Conrad Irwin
ea5131ce0a Country Code To Snowflake (#20875)
Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
2024-11-19 12:52:00 -07:00
Peter Tripp
1c2b3ad782 Add editor::SelectAllMatches to SublimeText base keymap (#20866)
`alt-f3` on Linux
`ctrl-cmd-g` on MacOS

Co-authored-by: Roman Seidelsohn <rseidelsohn@gmail.com>
2024-11-19 14:33:35 -05:00
Conrad Irwin
496dae968b Remove old CPU/Memory events (#20865)
Release Notes:

- Telemetry: stop reporting CPU/RAM on a timer
2024-11-19 12:25:16 -07:00
Piotr Osiewicz
5c6565a9e0 editor: Use completion filter_range for fuzzy matching (#20869)
Fixes regression from #13958

Closes #20868

Release Notes:

- N/A
2024-11-19 19:49:36 +01:00
Jaagup Averin
7853e32f80 python: Highlight attribute docstrings (#20763)
Adds more docstring highlights missing from #20486.
[PEP257](https://peps.python.org/pep-0257/) defines attribute docstrings
as
> String literals occurring immediately after a simple assignment at the
top level of a module, class, or __init__ method are called “attribute
docstrings”.

This PR adds `@string.doc` for such cases.
Before:

![Screenshot_20241116_162257](https://github.com/user-attachments/assets/6b471cff-717e-4755-9291-d596da927dc6)
After:

![Screenshot_20241116_162457](https://github.com/user-attachments/assets/96674157-9c86-45b6-8ce9-e433ca0ae8ea)

Release Notes:

- Added Python syntax highlighting for attribute docstrings.

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
2024-11-19 18:53:36 +01:00
Marshall Bowers
f5cbfa718e assistant: Fix evaluating slash commands in slash command output (like /default) (#20864)
This PR fixes an issue where slash commands in the output of other slash
commands were not being evaluated when configured to do so.

Closes https://github.com/zed-industries/zed/issues/20820.

Release Notes:

- Fixed slash commands from other slash commands (like `/default`) not
being evaluated (Preview only).
2024-11-19 11:20:30 -05:00
Conrad Irwin
6a2c712990 Use Instant not chrono for telemetry (#20756)
We occasionally see dates in the future appearing in our telemetry. One
hypothesis is that this is caused by a clock change while Zed is running
causing date math based on chrono to be incorrect.

Instant *should* be a more stable source of relative timestamps.

Release Notes:

- N/A
2024-11-19 08:23:12 -07:00
Egor Krugletsov
9454f0f1c7 clangd: Use Url::to_file_path() to get actual file path for header/source (#20856)
Using `Url::path()` seems fine on POSIX systems as it will leave forward
slash (given hostname is empty). On Windows it will result in error.

Release Notes:

- N/A
2024-11-19 15:49:21 +02:00
Julian de Ruiter
5b0c15d8c4 Add pytest-based test discovery and runnables for Python (#18824)
Closes  #12080, #18649.

Screenshot:

<img width="1499" alt="image"
src="https://github.com/user-attachments/assets/2644c2fc-19cf-4d2c-a992-5c56cb22deed">

Still in progress:

1. I'd like to add configuration options for selecting a Python test
runner (either pytest or unittest) so that users can explicitly choose
which runner they'd like to use for running their tests. This preference
has to be configured as unittest-style tests can also be run by pytest,
meaning we can't rely on auto-discovery to choose the desired test
runner.
2. I'd like to add venv auto-discovery similar to the feature currently
provided by the terminal using detect_venv.
3. Unit tests.

Unfortunately I'm struggling a bit with how to add settings in the
appropriate location (e.g. Python language settings). Can anyone provide
me with some pointers and/or examples on how to either add extra
settings or to re-use the existing ones?

My rust programming level is OK-ish but I'm not very familiar with the
Zed project structure and could use some help.

I'm also open for pair programming as mentioned on the website if that
helps!

Release Notes:

- Added pytest-based test discovery and runnables for Python.
- Adds a configurable option for switching between unittest and pytest
as a test runner under Python language settings. Set "TASK_RUNNER" to
"unittest" under task settings for Python if you wish to use unittest to
run Python tasks; the default is pytest.

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
2024-11-19 14:34:56 +01:00
Bennet Bo Fenner
aae39071ef editor: Show hints for using AI features on empty lines (#20824)
Co-Authored-by: Thorsten <thorsten@zed.dev>
Co-Authored-by: Antonio <antonio@zed.dev>

Screenshot:

![screenshot-2024-11-18-17 11
08@2x](https://github.com/user-attachments/assets/610fd7db-7476-4b9b-9465-a3d55df12340)

TODO:
- [x] docs

Release Notes:

- Added inline hints that guide users on how to invoke the inline
assistant and open the assistant panel. (These hints can be disabled by
setting `{"assistant": {"show_hints": false}}`.)

---------

Co-authored-by: Thorsten <thorsten@zed.dev>
Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
2024-11-19 09:41:44 +01:00
Nate Butler
a35b73e63e Revert "remove usages of theme::color_alpha"
This reverts commit c0d11be75f.
2024-11-19 00:24:48 -05:00
Nate Butler
c0d11be75f remove usages of theme::color_alpha 2024-11-19 00:24:37 -05:00
uncenter
0e26d22fea Add HTML injections for markdown (#20527)
Closes https://github.com/zed-industries/extensions/issues/1588.

| Before | After |
| --- | --- |
| ![CleanShot 2024-11-11 at 22 48
43](https://github.com/user-attachments/assets/9470e6a8-6a37-4b8f-8daa-5c8c5ed2bb17)
| ![CleanShot 2024-11-11 at 22 49
43](https://github.com/user-attachments/assets/f2b858d0-9274-4332-b30e-61c13ac347c6)
|

Release Notes:

- Added HTML injections for markdown syntax highlighting
2024-11-18 20:19:24 -07:00
Kyle Kelley
bd0f197415 Create RunningKernel trait to allow for native and remote jupyter kernels (#20842)
Starts setting up a `RunningKernel` trait to make the remote kernel
implementation easy to get started with. No release notes until this is
all hooked up.

Release Notes:

- N/A
2024-11-18 18:12:23 -08:00
Peter Tripp
343c88574a Improve file_types in default.json (#20429)
Detect .env.* as Shell Script
Move non glob json/jsonc/toml file_types into langauges/*/config.toml
2024-11-18 19:56:45 -05:00
Conrad Irwin
e7a0890086 Don't call setAllowsAutomaticKeyEquivalentLocalization on Big Sur (#20844)
Closes #20821

Release Notes:

- Fixed a crash on Big Sur (preview only)
2024-11-18 16:47:36 -07:00
Conrad Irwin
d4c5c0f05e Don't render invisibles with elements (#20841)
Turns out that in the case you have a somehow valid utf-8 file that
contains almost all ascii control characters, we run out of element
arena space.

Fixes: #20652

Release Notes:

- Fixed a crash when opening a file containing a very large number of
ascii control characters on one line.
2024-11-18 16:47:25 -07:00
lord
f0c7e62adc Leave goal_x unchanged when moving by rows past the start or end of the document (#20705)
Perhaps this was intentional behavior, but if not, I've attempted to
write this hacky fix — I noticed using the vertical arrow keys to move
past the document start/end would reset the goal_x to either zero (for
moving upwards) or the line width (for moving downwards). This change
makes Zed match most native text fields (at least on macOS) which leave
goal_x unchanged, even when hitting the end of the document.

I tested this change manually. Would be happy to add automatic tests for
it too, but couldn't find any existing cursor movement tests.

Release Notes:

- Behavior when moving vertically past the start or end of a document
now matches native text fields; it no longer resets the selection goal
2024-11-18 16:32:43 -07:00
Marshall Bowers
80d50f56f3 collab: Add feature flag to bypass account age check (#20843)
This PR adds a `bypass-account-age-check` feature flag that can be used
to bypass the minimum account age check.

Release Notes:

- N/A
2024-11-18 18:20:32 -05:00
Carroll Wainwright
fb6c987e3e python: Improve function syntax highlighting (#20487)
Release Notes:

- Differentiate between function and method calls and definitions.
`function.definition` matches the highlight for e.g. rust,
`function.call` is new.
- Likewise differentiate between class calls and class definitions.
- Better highlighting of function decorators (the `@` symbol is
punctuation, and now the decorator itself has a `function.decorator`
tag)
- Make `cls` a special variable (like `self`)
- Add `ellipsis` as a built-in constant

Note that most themes do not currently make use of the
`function.definition` tags, and none make use of the
`type.class.definition` tag. Hopefully more themes will pick this up.

*Before:*
<img width="248" alt="image"
src="https://github.com/user-attachments/assets/550ccd3d-594c-413a-b543-ef9caf39eee1">


*After:*
<img width="245" alt="image"
src="https://github.com/user-attachments/assets/47aa43b1-006b-4f9f-9029-510880f390ea">
2024-11-19 00:05:39 +01:00
Michael Sloan
b4c2f29c8b Remove use of current File for new buffers that never have File (#20832)
`create_buffer` calls `Buffer::local` which sets `file` to `None`
[here](f12981db32/crates/language/src/buffer.rs (L629)).
So there's no point in then immediately attempting to update maps that
rely on `file` being present.

Release Notes:

- N/A
2024-11-18 14:30:38 -08:00
Peter Tripp
8666ec95ba ssh: Fix SSH to mac remotes (#20838)
Restore ability to SSH to macOS arm remotes (`uname -m` on mac == `arm64`).
Fix regression introduced in https://github.com/zed-industries/zed/pull/20618
2024-11-18 17:17:24 -05:00
Anthony Eid
889aac9c03 Snippet choices (#13958)
Closes: #12739

Release Notes:

Solves #12739 by
- Enable snippet parsing to successfully parse snippets with choices
- Show completion menu when tabbing to a snippet variable with multiple
choices

Todo:
 - [x] Parse snippet choices
- [x] Open completion menu when tabbing to a snippet variable with
several choices (Thank you Piotr)
- [x] Get snippet choices to reappear when tabbing back to a previous
tabstop in a snippet
 - [x] add snippet unit tests
- [x] Add fuzzy search to snippet choice completion menu & update
completion menu based on choices
 - [x] add completion menu unit tests

Current State:

Using these custom snippets

```json
  "my snippet": {
      "prefix": "log",
      "body": ["type ${1|i32, u32|} = $2"],
      "description": "Expand `log` to `console.log()`"
  },
  "my snippet2": {
      "prefix": "snip",
      "body": [
        "type ${1|i,i8,i16,i64,i32|} ${2|test,test_again,test_final|} = $3"
      ],
      "description": "snippet choice tester"
    }
```

Using snippet choices:



https://github.com/user-attachments/assets/d29fb1a2-7632-4071-944f-daeaa243e3ac

---------

Co-authored-by: Piotr Osiewicz <piotr@zed.dev>
Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
2024-11-18 22:56:34 +01:00
Peter Tripp
5b9916e34b ci: Add shellcheck for scripts (#20631)
Fixes shellcheck errors in script/*
Adds a couple trailing newlines.
Adds `script/shellcheck-scripts` and associated CI machinery.
Current set ultra-conservative, does not output warnings, only errors.
2024-11-18 16:41:22 -05:00
Peter Tripp
5b317f60df Improve install-cmake script (#20836)
- Don't output junk to stderr when cmake unavailable
- Kitware PPA does not include up to date bins for all distros (e.g.
Ubuntu 24 only has 3.30.2 although 3.30.4 has been out for a while) so
don't try to force install a specific version. Take the best we can get.
2024-11-18 16:39:57 -05:00
Marshall Bowers
e2552b9add collab: Bypass account age check for users with active LLM subscriptions (#20837)
This PR makes it so users with an active LLM subscription can bypass the
account age check.

Release Notes:

- N/A
2024-11-18 16:37:28 -05:00
Danilo Leal
37899187c6 Adjust file finder width configuration (#20819)
Follow up to: https://github.com/zed-industries/zed/pull/18682

This PR tweaks the setting value, so it's clear we're referring to
`max-width`, meaning the width will change up to a specific value
depending on the available window size. Then, it also makes `Small` the
default value, which, in practice, makes the modal size the same as it
was before the original PR linked above.

Release Notes:

- N/A

---------

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2024-11-18 16:32:16 -03:00
Michael Sloan
d265e44209 Don't treat absence of a file on fs as conflict for new files from CLI (#20828)
Closes #20827

Release Notes:

- Fixes bug where save for new files created via CLI would report a
conflict and ask about overwriting.
2024-11-18 10:55:44 -08:00
Peter Tripp
f12981db32 docs: Add Language extension config TBDs (To Be Documented) (#20829)
Release Notes:

- N/A
2024-11-18 13:31:24 -05:00
Michael Sloan
d99f5fe83e Add File.disk_state enum to clarify filesystem states (#20776)
Motivation for this is to make things more understandable while figuring
out #20775.

This is intended to be a refactoring that does not affect behavior, but
there are a few tricky spots:

* Previously `File.mtime()` (now `File.disk_state().mtime()`) would
return last known modification time for deleted files. Looking at uses,
I believe this will not affect anything. If there are behavior changes
here I believe they would be improvements.

* `BufferEvent::DirtyChanged` is now only emitted if dirtiness actually
changed, rather than if it may have changed. This should only be an
efficiency improvement.

Release Notes:

- N/A

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
2024-11-18 10:30:08 -08:00
Marshall Bowers
df1d0dec0a ocaml: Extract to zed-extensions/ocaml repository (#20825)
This PR extracts the OCaml extensions to the
[zed-extensions/ocaml](https://github.com/zed-extensions/ocaml)
repository.

Release Notes:

- N/A
2024-11-18 11:30:45 -05:00
Marshall Bowers
ad94ad511a ocaml: Bump to v0.1.1 (#20823)
This PR bumps the OCaml extension to v0.1.1.

Changes:

- https://github.com/zed-industries/zed/pull/20700

Release Notes:

- N/A
2024-11-18 11:02:32 -05:00
Danilo Leal
0e7770a9a2 theme: Add color darken function (#20746)
This PR adds a `darken` function that allows to reduce the lightness of
a color by a certain factor. This popped up as I wanted to add hover
styles to tinted-colors buttons.

Release Notes:

- N/A
2024-11-18 12:44:49 -03:00
Danilo Leal
3f905d57e5 assistant: Adjust title summarization prompt (#20822)
Meant to avoid the excessive use of "Here's a concise 3-7 word title..."
and "Title:" instances we've been seeing lately.
Follow up to: https://github.com/zed-industries/zed/pull/19530

Release Notes:

- Improve prompt for generating title summaries, avoiding preambles
2024-11-18 12:44:06 -03:00
Peter Tripp
f01a86c644 Support for Back/Forward multimedia keys (#20695)
- Added Support for Back/Forward multimedia keys (Linux)
2024-11-18 09:36:08 -05:00
Peter Tripp
5fd7afb9da docs: More language extension config.toml key documentation (#20818)
Release Notes:

- N/A
2024-11-18 09:23:29 -05:00
Michael Sloan
9260abafba Use HashMap<ProjectEntryId, Entry> instead of HashSet<Entry> in outline_panel (#20780)
Came across this because I noticed that `Entry` implements `Hash`, which
was surprising to me. I believe that `ProjectEntryId` should be unique
and so it seems better to dedupe based on this.

Release Notes:

- N/A
2024-11-18 14:38:31 +02:00
Kirill Bulatov
d92166f9f6 Revert "Use livekit's Rust SDK instead of their swift SDK (#13343)" (#20809)
Issues found:

* audio does not work well with various set-ups using USB
* switching audio during initial join may leave the client with no audio
at all
* audio streaming is done on the main thread, beachballing certain
set-ups
* worse screenshare quality (seems that there's no dynamic scaling
anymore, compared to the Swift SDK)

This reverts commit 1235d0808e.

Release Notes:

- N/A
2024-11-18 11:43:53 +02:00
moshyfawn
59a355da74 docs: Update Svelte extension link (#20804)
Closes #20768

Release Notes:

- N/A
2024-11-18 09:51:47 +02:00
Nathan Sobo
ee207ab77e Map "feature upsell" events to the new "Noun Verbed" format (#20787)
Release Notes:

- N/A
2024-11-17 07:38:30 -07:00
Isaac Donaldson
31566cb5a0 Add width setting for the file finder (#18682)
This PR adds the ability to adjust the width of the file finder popup. I
found when searching my projects the default width was not always wide
enough and there was no option to change it.

It allows values `small`, `medium` (default), `large`, `xlarge`, and
`full`

Release Notes:

- Added a setting to adjust the width of the file finder modal


Example Setting:
```json
  "file_finder": {
    "modal_width": "medium"
  },
```

Screenshots can be found in the comments below.
2024-11-16 20:52:43 +02:00
Lu Wan
2d3476530e lsp: Retrieve links to documentation for the given symbol (#19233)
Closes #18924 

Release Notes:

- Added an `editor:OpenDocs` action to open links to documentation via
rust-analyzer
2024-11-16 20:23:49 +02:00
Nathan Sobo
f9990b42fa Send events to Snowflake in the format they're expected by Amplitude (#20765)
This will allow us to use the events table directly in Amplitude, which
lets us use the newer event ingestion flow that detects changes to the
table. Otherwise we'll need a transformation.

I think Amplitude's API is probably a pretty good example to follow for
the raw event schema, even if we don't end up using their product. They
also recommend a "Noun Verbed" format for naming events, so I think we
should go with this. This will help us be consistent and encourage the
author of events to think more clearly about what event they're
reporting.

cc @ConradIrwin 

Release Notes:

- N/A
2024-11-16 09:58:19 -07:00
Siddharth M. Bhatia
97e9137cb7 Update references of Ollama Llama 3.1 to model Llama 3.2 (#20757)
Release Notes:

- N/A
2024-11-16 11:18:53 -05:00
Jason Lee
932c7e23c8 gpui: Fix SVG color render, when color have alpha (#20537)
Release Notes:

- N/A


## Demo

- [Source
SVG](https://github.com/user-attachments/assets/1c681e01-baba-4613-a3e7-ea5cb3015406)
click here open in browser.

| Before | After |
| --- | --- |
| <img width="1212" alt="image"
src="https://github.com/user-attachments/assets/ba323b13-538b-4a34-bb64-9dcf490aface">
| <img width="1212" alt="image"
src="https://github.com/user-attachments/assets/4635926a-843e-426d-89a1-4e9b4f4cc37e">
|

---------

Co-authored-by: Floyd Wang <gassnake999@gmail.com>
2024-11-16 16:53:57 +02:00
Aaron Ruan
65a9c8d994 Dynamic tab bar height (#19076)
Tracking issue: https://github.com/zed-industries/zed/issues/18078

Release Notes:

- Change tab bar height according to `ui-density`

---------

Signed-off-by: Aaron Ruan <aaron212cn@outlook.com>
2024-11-16 13:48:25 +02:00
狐狸
33f09bad60 Highlight ? and : in ternary expressions as operator in JavaScript, TypeScript, and TSX (#20573)
Closes #ISSUE

Release Notes:

- N/A *or* Added/Fixed/Improved ...
2024-11-16 13:42:10 +02:00
Jason Lee
792c1e4710 gpui: Add paint_path example (#20499)
Release Notes:

- N/A

---

```
cargo run -p gpui --example painting
```

I added this demo to verify the detailed support of Path drawing in
GPUI.

Because of, when we actually used GPUI to draw a 2D line chart, we found
that the straight line Path#line_to did not support `anti-aliasing`, and
the drawn line looked very bad.

As shown in the demo image, if we zoom in on the image, we can clearly
see that all the lines are jagged.

I read and tried to make some appropriate adjustments to the functions
in Path, but since I have no experience in the graphics field, I still
cannot achieve anti-aliasing support so far.

I don't know if I used it wrong somewhere. I checked `curve_to` and
found that the curves drawn have anti-aliasing effects, as shown in the
arc part of the figure below.

<img width="1136" alt="image"
src="https://github.com/user-attachments/assets/4dfb7603-e746-43e9-b737-cff56b56329f">
2024-11-16 13:36:13 +02:00
Gowtham K
b421ffafb5 Windows: Add transparency effect (#20400)
Release Notes:

- Added Transparency effect for Windows #19405 


![image](https://github.com/user-attachments/assets/b0750020-5a89-48c9-b26e-13b30874cf8d)


![image](https://github.com/user-attachments/assets/80609a14-b8c3-4159-b909-1e61f4c3eac3)

---------

Co-authored-by: thedeveloper-sharath <35845141+thedeveloper-sharath@users.noreply.github.com>
2024-11-16 13:24:30 +02:00
SweetPPro
21c785ede4 Add more common Prettier plugin base paths (#20758)
Closes #19024

Release Notes:
- Added some more common Prettier plugin base paths
2024-11-16 13:20:52 +02:00
Mikayla Maki
516f7b3642 Add Loading and Fallback States to Image Elements (via StyledImage) (#20371)
@iamnbutler edit:

This pull request enhances the image element by introducing the ability
to display loading and fallback states.

Changes:

- Implemented the loading and fallback states for image elements using
`.with_loading` and `.with_fallback` respectively.
- Introduced the `StyledImage` trait and `ImageStyle` to enable a fluent
API for changing image styles across image types (`Img`,
`Stateful<Img>`, etc).

Example Usage:

```rust
fn loading_element() -> impl IntoElement {
    div().size_full().flex_none().p_0p5().rounded_sm().child(
        div().size_full().with_animation(
            "loading-bg",
            Animation::new(Duration::from_secs(3))
                .repeat()
                .with_easing(pulsating_between(0.04, 0.24)),
            move |this, delta| this.bg(black().opacity(delta)),
        ),
    )
}

fn fallback_element() -> impl IntoElement {
    let fallback_color: Hsla = black().opacity(0.5);

    div().size_full().flex_none().p_0p5().child(
        div()
            .size_full()
            .flex()
            .items_center()
            .justify_center()
            .rounded_sm()
            .text_sm()
            .text_color(fallback_color)
            .border_1()
            .border_color(fallback_color)
            .child("?"),
    )
}

impl Render for ImageLoadingExample {
    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
        img("some/image/path")
            .id("image-1")
            .with_fallback(|| Self::fallback_element().into_any_element())
            .with_loading(|| Self::loading_element().into_any_element())
    }
}
```

Note:

An `Img` must have an `id` to be able to add a loading state.

Release Notes:

- N/A

---------

Co-authored-by: nate <nate@zed.dev>
Co-authored-by: michael <michael@zed.dev>
Co-authored-by: Nate Butler <iamnbutler@gmail.com>
Co-authored-by: Antonio Scandurra <me@as-cii.com>
2024-11-15 19:12:01 -08:00
Michael Sloan
f34877334e Fix tab strikethrough logic (#20755)
This fix was in downstream commits before splitting out #20711, should
have tested locally before merging.

Release Notes:

- N/A
2024-11-15 17:14:49 -07:00
Peter Tripp
6e296eb4b6 ssh: Use openbsd nc on macOS (#20751)
Co-authored-by: Conrad Irwin <conrad@zed.dev>
2024-11-15 17:27:45 -05:00
Wes Higbee
4c8c6c08fe docs: Fix assistant prompt_overrides template directory (#20434)
Update docs to reflect the correct path for prompt handlebars templates.
Link to git repo for prompts rather than including an out of date version inline.

Co-authored-by: Peter Tripp <peter@zed.dev>
2024-11-15 17:26:50 -05:00
Michael Sloan
050ce919ba Rename "Overwrite" to "Save" for prompt about recreating a deleted file (#20750)
Release Notes:

- N/A
2024-11-15 15:12:40 -07:00
Michael Sloan
369828f51c Require save confirmation and prevent autosave for deleted files (#20742)
* `has_conflict` will now return true if the file has been deleted on
disk.  This is for treating multi-buffers as conflicted, and also
blocks auto-save.

* `has_deleted_file` is added so that the single-file buffer save can
specifically mention the delete conflict. This does not yet handle
discard (#20745).

Closes #9101
Closes #9568
Closes #20462

Release Notes:

- Improved handling of externally deleted files: auto-save will be
disabled, multibuffers will treat this as a save conflict, and single
buffers will ask for restore confirmation.

Co-authored-by: Conrad <conrad@zed.dev>
2024-11-15 15:01:16 -07:00
Conrad Irwin
ac5ecf5487 Don't log every value (#20744)
Release Notes:

- N/A
2024-11-15 14:36:58 -07:00
Max Brunsfeld
1235d0808e Use livekit's Rust SDK instead of their swift SDK (#13343)
See https://github.com/livekit/rust-sdks/pull/355

Todo:

* [x] make `call` / `live_kit_client` crates use the livekit rust sdk
* [x] create a fake version of livekit rust API for integration tests
* [x] capture local audio
* [x] play remote audio
* [x] capture local video tracks
* [x] play remote video tracks
* [x] tests passing
* bugs
* [x] deafening does not work
(https://github.com/livekit/rust-sdks/issues/359)
* [x] mute and speaking status are not replicated properly:
(https://github.com/livekit/rust-sdks/issues/358)
* [x] **linux** - crash due to symbol conflict between WebRTC's
BoringSSL and libcurl's openssl
(https://github.com/livekit/rust-sdks/issues/89)
* [x] **linux** - libwebrtc-sys adds undesired dependencies on `libGL`
and `libXext`
* [x] **windows** - linker error, maybe related to the C++ stdlib
(https://github.com/livekit/rust-sdks/issues/364)
        ```
libwebrtc_sys-54978c6ad5066a35.rlib(video_frame.obj) : error LNK2038:
mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't
match value 'MD_DynamicRelease' in
libtree_sitter_yaml-df6b0adf8f009e8f.rlib(2e40c9e35e9506f4-scanner.o)
        ```
    * [x] audio problems

Release Notes:

- Switch from Swift to Rust LiveKit SDK 🦀

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
Co-authored-by: Conrad Irwin <conrad@zed.dev>
Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Co-authored-by: Michael Sloan <michael@zed.dev>
2024-11-15 23:18:50 +02:00
Conrad Irwin
6ff69faf37 Start to send data to Snowflake too (#20698)
This PR adds support for sending telemetry events to AWS Kinesis.

In our AWS account we now have three new things:
* The [Kinesis data
stream](https://us-east-1.console.aws.amazon.com/kinesis/home?region=us-east-1#/streams/details/zed-telemetry/monitoring)
that we will actually write to.
* A [Firehose for
Axiom](https://us-east-1.console.aws.amazon.com/firehose/home?region=us-east-1#/details/telemetry-to-axiom/monitoring)
that sends events from that stream to Axiom for ad-hoc queries over
recent data.
* A [Firehose for
Snowflake](https://us-east-1.console.aws.amazon.com/firehose/home?region=us-east-1#/details/telemetry-to-snowflake/monitoring)
that sends events from that stream to Snowflake for long-term retention.
This Firehose also backs up data into an S3 bucket in case we want to
change how the system works in the future.

In a follow-up PR, we'll add support for ad-hoc telemetry events; and
slowly move away from the current Clickhouse defined schemas; though we
won't move off click house until we have what we need in Snowflake.

Co-Authored-By: Nathan <nathan@zed.dev>

Release Notes:

- N/A
2024-11-15 12:58:00 -07:00
renovate[bot]
f449e8d3d3 Migrate Renovate config (#20741)
The Renovate config in this repository needs migrating. Typically this
is because one or more configuration options you are using have been
renamed.

You don't need to merge this PR right away, because Renovate will
continue to migrate these fields internally each time it runs. But later
some of these fields may be fully deprecated and the migrations removed.
So it's a good idea to merge this migration PR soon.





🔕 **Ignore**: Close this PR and you won't be reminded about config
migration again, but one day your current config may no longer be valid.

 Got questions? Does something look wrong to you? Please don't hesitate
to [request help
here](https://redirect.github.com/renovatebot/renovate/discussions).


---

Release Notes:

- N/A

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
2024-11-15 14:37:39 -05:00
Marshall Bowers
da09cbd055 assistant: Show more details for assist errors (#20740)
This PR updates the Assistant to show more detailed error messages when
the user encounters an assist error.

Here are some examples:

<img width="415" alt="Screenshot 2024-11-15 at 1 47 03 PM"
src="https://github.com/user-attachments/assets/5e7c5d5f-bd78-4af3-86ed-af4c6712770f">

<img width="417" alt="Screenshot 2024-11-15 at 2 11 14 PM"
src="https://github.com/user-attachments/assets/02cb659b-1239-4e24-865f-3a512703a94f">

The notification will scroll if the error lines overflow the set maximum
height.

Release Notes:

- Updated the Assistant to show more details in error cases.
2024-11-15 14:23:46 -05:00
Caleb Heydon
4327459d2a Fix Rust LSP adapter on FreeBSD (#20736)
This PR fixes the Rust LSP adapter on FreeBSD. This issue was creating
build errors.

Release Notes:

- Fixed Rust LSP adapter on FreeBSD
2024-11-15 11:03:55 -07:00
Michael Sloan
cc601bd770 Use strikethrough style in label implementation (#20735)
Release Notes:

- N/A

---------

Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Marshall Bowers <marshall@zed.dev>
2024-11-15 10:57:23 -07:00
Marshall Bowers
c491b75e07 assistant: Fix panic when using /project (#20733)
This PR fixes a panic when using `/project` (which is staff-flagged).

We weren't initializing the `SemanticDb` global if the
`project-slash-command` feature flag was enabled.

Closes #20563.

Release Notes:

- N/A
2024-11-15 12:25:29 -05:00
Marshall Bowers
3420ebb428 util: Remove unused code (#20734)
This PR removes the `with_clone` macro from `util`, as it wasn't used
(and isn't needed).

Release Notes:

- N/A
2024-11-15 12:25:18 -05:00
Marshall Bowers
b23d72ec4f gpui: Clean up Styled doc comments (#20731)
This PR cleans up the doc comments on the `Styled` trait to make them
more consistent.

Release Notes:

- N/A
2024-11-15 11:27:49 -05:00
Peter Tripp
e25a03cd3c docs: Variable escaping in tasks (#20730) 2024-11-15 11:14:30 -05:00
Marshall Bowers
9e8ff3f198 Update .mailmap (#20729)
This PR updates the `.mailmap` file to merge some more commit authors.

Release Notes:

- N/A
2024-11-15 11:05:41 -05:00
Marshall Bowers
6d80d5b74b gpui: Add line_through method to Styled (#20728)
This PR adds a `.line_through` method to the `Styled` trait that mirrors
the corresponding Tailwind class.

Release Notes:

- N/A
2024-11-15 10:51:09 -05:00
TOULAR
7137bdee02 Fix scrollbar not always being on top (#20665)
Set the elevation of the scrollbar to 1 borderless, so that the blue
outline is no longer above the scrollbar.

Closes #19875

Release Notes:

- N/A

---------

Co-authored-by: Peter Tripp <peter@zed.dev>
2024-11-15 16:47:17 +01:00
Kirill Bulatov
98403aa994 Disable signature help shown by default (#20726)
Closes https://github.com/zed-industries/zed/issues/20725

Stop showing the pop-up that gets an issue open every now and then.

Release Notes:

- Stopped showing signature help after completions by default
2024-11-15 17:19:11 +02:00
lord
794ad1af75 ocaml: Improve highlighting and bracketing (#20700)
Some small improvements to OCaml. Would happily split these into smaller
changes, discard anything, etc.

Before:
<img width="441" alt="before"
src="https://github.com/user-attachments/assets/2fb82b03-0d45-4c59-a94d-6f48d634fe19">

After:
<img width="448" alt="after"
src="https://github.com/user-attachments/assets/aa232d8f-4b1b-48f8-93e2-2147de37a20d">

OCaml highlighting and bracketing improvements
    - Fixed bug where `<` was automatically closed with `>`.
    - Typing `{|` now automatically closes with `|}`
- Type variables are now colored with `variable.special` instead of
`variable`.
- Argument names in function declarations and application are now
colored with `label` instead of `property`, even if they are punned.
- `[@@` and `[%` in macros are now colored as bracket punctuation to
match the closing `]`, rather than colored as `attribute`

Release Notes:

- N/A
2024-11-15 10:17:46 -05:00
Conrad Irwin
4b1f0c033b html: Bump to v0.1.4 (#20692)
Changes:

- https://github.com/zed-industries/zed/pull/20536

Release Notes:

- N/A
2024-11-15 10:10:25 -05:00
Danilo Leal
3796b4a55c project panel: Update decoration icon active color (#20723)
Just so that the icon decoration knockout color matches the background
of a selected/market item.

<img width="600" alt="Screenshot 2024-11-15 at 10 50 24"
src="https://github.com/user-attachments/assets/0037fe5a-f42d-47e8-8559-97ca11ff2d97">

Release Notes:

- N/A
2024-11-15 11:48:26 -03:00
Piotr Osiewicz
8c02929710 pane: Fix rough edges around pinning of dropped project entries (#20722)
Closes #20485

Release Notes:

- Fixed quirks around dropping project entries into tab bar which
might've led to tabs being pinned sometimes.
2024-11-15 13:51:40 +01:00
Kirill Bulatov
1e14697bb6 Fix Linux rust-analyzer downloads in Preview (#20718)
Follow-up of https://github.com/zed-industries/zed/pull/20408

Release Notes:

- (Preview) Fixed broken rust-analyzer downloads
2024-11-15 11:57:54 +02:00
Adam Wolff
f619a872b5 python: Prefer conda environments that match CONDA_PREFIX (#20702)
Release Notes:

- Improved Python toolchain selection for conda environments
2024-11-15 09:12:35 +01:00
Michael Sloan
c03f5b351b Use strikethrough on tab label to indicate file deletion (#20711)
Closes #5364

Release Notes:

- Added indication of deleted files. Files deleted outside of Zed will
have a strikethrough in the title of the tab.
2024-11-15 00:39:09 -07:00
Conrad Irwin
a8df0642a8 vim: Allow :cpplink for CopyPermalinkToLine (#20707)
Release Notes:

- vim: Added `:<range>cpplink` to copy a permanent git link to the
highlighted range to the clipboard
2024-11-14 23:44:40 -07:00
Thorsten Ball
aee01f2c50 assistant: Remove low_speed_timeout (#20681)
This removes the `low_speed_timeout` setting from all providers as a
response to issue #19509.

Reason being that the original `low_speed_timeout` was only as part of
#9913 because users wanted to _get rid of timeouts_. They wanted to bump
the default timeout from 5sec to a lot more.

Then, in the meantime, the meaning of `low_speed_timeout` changed in
#19055 and was changed to a normal `timeout`, which is a different thing
and breaks slower LLMs that don't reply with a complete response in the
configured timeout.

So we figured: let's remove the whole thing and replace it with a
default _connect_ timeout to make sure that we can connect to a server
in 10s, but then give the server as long as it wants to complete its
response.

Closes #19509

Release Notes:

- Removed the `low_speed_timeout` setting from LLM provider settings,
since it was only used to _increase_ the timeout to give LLMs more time,
but since we don't have any other use for it, we simply remove the
setting to give LLMs as long as they need.

---------

Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Peter Tripp <peter@zed.dev>
2024-11-15 07:37:31 +01:00
chottolabs
c9546070ac docs: Update Zig Tree-sitter grammar link (#20708)
lines up with
https://github.com/zed-industries/zed/blob/main/extensions/zig/extension.toml

Release Notes:

- N/A
2024-11-15 07:45:36 +02:00
Marshall Bowers
1855a312d0 Use Extension trait in ExtensionLspAdapter (#20704)
This PR updates the `ExtensionLspAdapter` to go through the `Extension`
trait for interacting with extensions rather than going through the
`WasmHost` directly.

Release Notes:

- N/A
2024-11-14 20:44:57 -05:00
Dairon M.
332b33716a erlang: Update tree-sitter grammar (#20699)
erlang: Update tree-sitter grammar for new OTP 27 features:
- -moduledoc and -doc attributes
- Sigils
- Triple quoted strings

<img width="717" alt="Screenshot 2024-11-14 at 5 18 08 PM"
src="https://github.com/user-attachments/assets/24812b17-4e64-47f3-a6ab-6bc7260cd53f">

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
2024-11-14 18:10:00 -05:00
Conrad Irwin
acf25324be Delete a.html (#20691)
Closes #ISSUE

Release Notes:

- N/A *or* Added/Fixed/Improved ...
2024-11-14 13:00:03 -07:00
hrou0003
f0882f44a7 vim: Enable % to jump between tags (#20536)
Closes #12986

Release Notes:

- Enable `%` to jump between pairs of tags

---------

Co-authored-by: Harrison <hrouillard@sfi.com.au>
2024-11-14 12:41:53 -07:00
Harsh Narayan Jha
189a034e71 docs: Document exec flags for GDScript (#20688)
While looking up the GDScript extension docs, I noticed that the
original extension repo mentions of `{line}:{col}` placeholders too in
addition to `{project} {file}` that the Zed docs suggest adding.

This PR Improves the docs to add those missing options to the suggested
flags.
2024-11-14 14:28:25 -05:00
Conrad Irwin
7f52071513 Use the project env when running LSPs (#20641)
This change ensures we always run LSPs with the project environment (in
addition to any overrides they provide). This helps ensure the
environment is
set correctly on remotes where we don't load the login shell environment
and
assign it to the current process.

Also fixed the go language to use the project env to find the go
command.

Release Notes:

- Improved environment variable handling for SSH remotes
2024-11-14 12:26:55 -07:00
Piotr Osiewicz
56c93be4de project panel: Fix rendering of groups of dragged project panel entries (#20686)
This PR introduces a new parameter for `on_drag` in gpui, which is an
offset from the element origin to the mouse event origin.

Release Notes:

- Fixed rendering of dragged project panel entries
2024-11-14 19:29:18 +01:00
Marshall Bowers
43999c47e1 client: Remove unneeded return (#20685)
This PR removes an unneeded `return` that was introduced in #19928.

Release Notes:

- N/A
2024-11-14 13:16:55 -05:00
David Soria Parra
690a725667 context_servers: Upgrade protocol to version 2024-11-05 (#20615)
This updates context servers to the most recent version

Release Notes:

- N/A

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
2024-11-14 13:03:30 -05:00
Marshall Bowers
b5ce8e7aa5 zed_extension_api: Release v0.2.0 (#20683)
This PR releases v0.2.0 of the Zed extension API.

Support for this version of the extension API will land in Zed v0.162.x.

Release Notes:

- N/A
2024-11-14 12:44:10 -05:00
Marshall Bowers
d177a1d4e5 Move ExtensionStore tests back to extension_host (#20682)
This PR moves the tests for the `ExtensionStore` back into the
`extension_host` crate.

We now have a separate `TestExtensionRegistrationHooks` to use in the
test that implements the minimal required functionality needed for the
tests. This means that we can depend on the `theme` crate only in the
tests.

Release Notes:

- N/A
2024-11-14 12:09:41 -05:00
renovate[bot]
5d17cfab31 Update Rust crate wasmtime to v24.0.2 [SECURITY] (#20614)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [wasmtime](https://redirect.github.com/bytecodealliance/wasmtime) |
workspace.dependencies | patch | `24.0.1` -> `24.0.2` |

### GitHub Vulnerability Alerts

####
[CVE-2024-51745](https://redirect.github.com/bytecodealliance/wasmtime/security/advisories/GHSA-c2f5-jxjv-2hh8)

### Impact

Wasmtime's filesystem sandbox implementation on Windows blocks access to
special device filenames such as "COM1", "COM2", "LPT0", "LPT1", and so
on, however it did not block access to the special device filenames
which use superscript digits, such as "COM¹", "COM²", "LPT⁰", "LPT¹",
and so on. Untrusted Wasm programs that are given access to any
filesystem directory could bypass the sandbox and access devices through
those special device filenames with superscript digits, and through them
gain access peripheral devices connected to the computer, or network
resources mapped to those devices. This can include modems, printers,
network printers, and any other device connected to a serial or parallel
port, including emulated USB serial ports.

### Patches

Patch releases for Wasmtime have been issued as 24.0.2, 25.0.3, and
26.0.1. Users of Wasmtime 23.0.x and prior are recommended to upgrade to
one of these patched versions.

### Workarounds

There are no known workarounds for this issue. Affected Windows users
are recommended to upgrade.

### References

- [Microsoft's
documentation](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions)
of the special device filenames
 - [ISO-8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
- [The original PR reporting the
issue](https://redirect.github.com/bytecodealliance/cap-std/pull/371)

---

### Release Notes

<details>
<summary>bytecodealliance/wasmtime (wasmtime)</summary>

###
[`v24.0.2`](https://redirect.github.com/bytecodealliance/wasmtime/releases/tag/v24.0.2)

[Compare
Source](https://redirect.github.com/bytecodealliance/wasmtime/compare/v24.0.1...v24.0.2)

#### 24.0.2

Released 2024-11-05.

##### Fixed

- Update to cap-std 3.4.1, for
[#&#8203;9559](https://redirect.github.com/bytecodealliance/wasmtime/issues/9559),
which fixes a wasi-filesystem sandbox
    escape on Windows.

[CVE-2024-51745](https://redirect.github.com/bytecodealliance/wasmtime/security/advisories/GHSA-c2f5-jxjv-2hh8).

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "" in timezone America/New_York,
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 18:35:31 +02:00
renovate[bot]
404ddeebc5 Update Rust crate serde_json to v1.0.132 (#20638)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [serde_json](https://redirect.github.com/serde-rs/json) | dependencies
| patch | `1.0.128` -> `1.0.132` |
| [serde_json](https://redirect.github.com/serde-rs/json) |
workspace.dependencies | patch | `1.0.128` -> `1.0.132` |

---

### Release Notes

<details>
<summary>serde-rs/json (serde_json)</summary>

###
[`v1.0.132`](https://redirect.github.com/serde-rs/json/releases/tag/1.0.132)

[Compare
Source](https://redirect.github.com/serde-rs/json/compare/1.0.131...1.0.132)

- Improve binary size and compile time for JSON array and JSON object
deserialization by about 50%
([#&#8203;1205](https://redirect.github.com/serde-rs/json/issues/1205))
- Improve performance of JSON array and JSON object deserialization by
about 8%
([#&#8203;1206](https://redirect.github.com/serde-rs/json/issues/1206))

###
[`v1.0.131`](https://redirect.github.com/serde-rs/json/releases/tag/1.0.131)

[Compare
Source](https://redirect.github.com/serde-rs/json/compare/1.0.130...1.0.131)

- Implement Deserializer and IntoDeserializer for `Map<String, Value>`
and `&Map<String, Value>`
([#&#8203;1135](https://redirect.github.com/serde-rs/json/issues/1135),
thanks [@&#8203;swlynch99](https://redirect.github.com/swlynch99))

###
[`v1.0.130`](https://redirect.github.com/serde-rs/json/releases/tag/1.0.130)

[Compare
Source](https://redirect.github.com/serde-rs/json/compare/1.0.129...1.0.130)

- Support converting and deserializing `Number` from i128 and u128
([#&#8203;1141](https://redirect.github.com/serde-rs/json/issues/1141),
thanks [@&#8203;druide](https://redirect.github.com/druide))

###
[`v1.0.129`](https://redirect.github.com/serde-rs/json/releases/tag/1.0.129)

[Compare
Source](https://redirect.github.com/serde-rs/json/compare/1.0.128...1.0.129)

- Add
[`serde_json::Map::sort_keys`](https://docs.rs/serde_json/1/serde_json/struct.Map.html#method.sort_keys)
and
[`serde_json::Value::sort_all_objects`](https://docs.rs/serde_json/1/serde_json/enum.Value.html#method.sort_all_objects)
([#&#8203;1199](https://redirect.github.com/serde-rs/json/issues/1199))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 18:35:13 +02:00
renovate[bot]
ad370ed986 Update Rust crate sys-locale to v0.3.2 (#20639)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [sys-locale](https://redirect.github.com/1Password/sys-locale) |
workspace.dependencies | patch | `0.3.1` -> `0.3.2` |

---

### Release Notes

<details>
<summary>1Password/sys-locale (sys-locale)</summary>

###
[`v0.3.2`](https://redirect.github.com/1Password/sys-locale/releases/tag/v0.3.2)

[Compare
Source](https://redirect.github.com/1Password/sys-locale/compare/v0.3.1...v0.3.2)

#### What's Changed

##### Added

- Support for all other Apple targets, such as watchOS and tvOS by
[@&#8203;complexspaces](https://redirect.github.com/complexspaces) in
[https://github.com/1Password/sys-locale/pull/38](https://redirect.github.com/1Password/sys-locale/pull/38).
- Support for ignoring POSIX modifiers in UNIX locales with them present
by [@&#8203;pasabanov](https://redirect.github.com/pasabanov) in
[https://github.com/1Password/sys-locale/pull/33](https://redirect.github.com/1Password/sys-locale/pull/33).
    -   Parsing support/recognition may come at a later date.
- Support for returning a list of user locales on Linux/BSD UNIX
platforms by [@&#8203;pasabanov](https://redirect.github.com/pasabanov)
in
[https://github.com/1Password/sys-locale/pull/35](https://redirect.github.com/1Password/sys-locale/pull/35).

##### Fixed

- No longer use `LC_CTYPE` when determining the locale; the crate now
uses `LC_MESSAGES` in its place by
[@&#8203;pasabanov](https://redirect.github.com/pasabanov) in
[https://github.com/1Password/sys-locale/pull/35](https://redirect.github.com/1Password/sys-locale/pull/35).
- Skip empty locale environment variables on UNIX platforms by
[@&#8203;complexspaces](https://redirect.github.com/complexspaces) in
[https://github.com/1Password/sys-locale/pull/29](https://redirect.github.com/1Password/sys-locale/pull/29).
- Corrected types mentioned and improved the public API documentation by
[@&#8203;pasabanov](https://redirect.github.com/pasabanov) in
[https://github.com/1Password/sys-locale/pull/37](https://redirect.github.com/1Password/sys-locale/pull/37).

##### Changed

- Improved crate download size by excluding unused directories and files
by [@&#8203;pasabanov](https://redirect.github.com/pasabanov).
- Very slight improvement to locale fetching performance on Windows by
[@&#8203;complexspaces](https://redirect.github.com/complexspaces) in
[https://github.com/1Password/sys-locale/pull/29](https://redirect.github.com/1Password/sys-locale/pull/29).
- Increased MSRV to Rust 1.56, which is 3 years old as of this release
by [@&#8203;complexspaces](https://redirect.github.com/complexspaces).

#### New Contributors

- [@&#8203;pasabanov](https://redirect.github.com/pasabanov) made their
first contribution in
[https://github.com/1Password/sys-locale/pull/30](https://redirect.github.com/1Password/sys-locale/pull/30)

**Full Changelog**:
https://github.com/1Password/sys-locale/compare/v0.3.1...v0.3.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 18:35:05 +02:00
renovate[bot]
ced9045591 Update Rust crate thiserror to v1.0.69 (#20643)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [thiserror](https://redirect.github.com/dtolnay/thiserror) |
workspace.dependencies | patch | `1.0.64` -> `1.0.69` |

---

### Release Notes

<details>
<summary>dtolnay/thiserror (thiserror)</summary>

###
[`v1.0.69`](https://redirect.github.com/dtolnay/thiserror/releases/tag/1.0.69)

[Compare
Source](https://redirect.github.com/dtolnay/thiserror/compare/1.0.68...1.0.69)

-   Backport 2.0.2 fixes

###
[`v1.0.68`](https://redirect.github.com/dtolnay/thiserror/releases/tag/1.0.68)

[Compare
Source](https://redirect.github.com/dtolnay/thiserror/compare/1.0.67...1.0.68)

- Handle incomplete expressions more robustly in format arguments, such
as while code is being typed
([#&#8203;341](https://redirect.github.com/dtolnay/thiserror/issues/341),
[#&#8203;344](https://redirect.github.com/dtolnay/thiserror/issues/344))

###
[`v1.0.67`](https://redirect.github.com/dtolnay/thiserror/releases/tag/1.0.67)

[Compare
Source](https://redirect.github.com/dtolnay/thiserror/compare/1.0.66...1.0.67)

- Improve expression syntax support inside format arguments
([#&#8203;335](https://redirect.github.com/dtolnay/thiserror/issues/335),
[#&#8203;337](https://redirect.github.com/dtolnay/thiserror/issues/337),
[#&#8203;339](https://redirect.github.com/dtolnay/thiserror/issues/339),
[#&#8203;340](https://redirect.github.com/dtolnay/thiserror/issues/340))

###
[`v1.0.66`](https://redirect.github.com/dtolnay/thiserror/releases/tag/1.0.66)

[Compare
Source](https://redirect.github.com/dtolnay/thiserror/compare/1.0.65...1.0.66)

- Improve compile error on malformed format attribute
([#&#8203;327](https://redirect.github.com/dtolnay/thiserror/issues/327))

###
[`v1.0.65`](https://redirect.github.com/dtolnay/thiserror/releases/tag/1.0.65)

[Compare
Source](https://redirect.github.com/dtolnay/thiserror/compare/1.0.64...1.0.65)

- Ensure OUT_DIR is left with deterministic contents after build script
execution
([#&#8203;325](https://redirect.github.com/dtolnay/thiserror/issues/325))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 18:34:58 +02:00
Kirill Bulatov
0d9bcbba25 Use vim-like keybindings for splitting out of the file finder (#20680)
Follow-up of https://github.com/zed-industries/zed/pull/20507

Release Notes:

- (breaking Preview) Adjusted file finder split keybindings to be less
conflicting

Co-authored-by: Conrad Irwin <conrad@zed.dev>
2024-11-14 18:32:04 +02:00
Peter Tripp
c650ba4e72 docs: Proto formatter example (#20677) 2024-11-14 11:25:37 -05:00
Marshall Bowers
5fab3ca5ba Format workspace Cargo.toml (#20679)
This PR does some formatting of the workspace `Cargo.toml`.

Release Notes:

- N/A
2024-11-14 11:10:58 -05:00
zachcp
621a200d2f docs: Remove duplicate text in the Clojure page (#20635) 2024-11-14 10:36:43 -05:00
Shiny
2544fad8a4 Fix tab switch behavior for the Sublime Text keymap (#20547)
Don't override tab switching behavior, default has correct behavior.
2024-11-14 09:50:29 -05:00
Piotr Osiewicz
49eb865e8a python: Improve handling of triple-quoted strings (#20664)
Closes #13998

/cc @notpeter would you mind giving this branch a go to see if this is
pleasant to use? This impl is not quite what VSC has, but I think it
feels okay?

In this PR, the sequence goes as follows:
1st keypress: "|"
2nd keypress: ""|
3rd keypress: """|"""

Release Notes:

- Improved handling of triple-quote strings in Python.
2024-11-14 15:12:46 +01:00
Piotr Osiewicz
a650fe0d77 python: Fix detection of Poetry environments (#20669)
We were missing a .configure call, which let to discrepancies with PET
output.

Release Notes:

- Improved detection of Poetry-based environments
2024-11-14 14:54:53 +01:00
Danilo Leal
204a989758 assistant: Add tiny design tweaks to the patch block (#20636)
Adjusting really tiny things, most notably ensuring that the header text
doesn't overflow out of the block.

<img width="600" alt="Screenshot 2024-11-13 at 20 11 08"
src="https://github.com/user-attachments/assets/26656203-92c6-49e5-a732-bae010f96b2d">


Release Notes:

- N/A
2024-11-14 10:53:00 -03:00
Thorsten Ball
776cfe44d7 environment: Log stderr too if command fails to run (#20659)
Release Notes:

- N/A
2024-11-14 14:44:32 +01:00
Thorsten Ball
35798212c4 Update copilot to Copilot.vim 1.41.0 (#20520)
Release Notes:

- Update Copilot's underlying version to [Copilot.vim
1.41.0](8703812380)

Co-authored-by: Antonio <antonio@zed.dev>
2024-11-14 14:44:13 +01:00
Piotr Osiewicz
89f9a506f9 tasks: Add ability to query active toolchains for languages (#20667)
Closes #18649

Release Notes:

- Python tasks now use active toolchain to run.
2024-11-14 14:37:37 +01:00
Nate Butler
04ba75e2e5 Add ui::ContentGroup (#20666)
TL;DR our version of [HIG's
Box](https://developer.apple.com/design/human-interface-guidelines/boxes)

We can't use the name `Box` (because rust) or `ContentBox` (because
taffy/styles/css).

---

This PR introduces the `ContentGroup` component, a flexible container
inspired by HIG's `Box` component. It's designed to hold and organize
various UI elements with options to toggle borders and background fills.

**Example usage**:

```rust
ContentGroup::new()
    .flex_1()
    .items_center()
    .justify_center()
    .h_48()
    .child(Label::new("Flexible ContentBox"))
```

Here are some configurations:

- Default: Includes both border and fill.
- Borderless: No border for a clean look.
- Unfilled: No background fill for a transparent appearance.

**Preview**:

![CleanShot 2024-11-14 at 07 05
15@2x](https://github.com/user-attachments/assets/c838371e-e24f-46f0-94b4-43c078e8f14e)

---

_This PR was written by a large language model with input from the
author._

Release Notes:

- N/A
2024-11-14 08:25:48 -05:00
renovate[bot]
f7b4431659 Update Rust crate libc to v0.2.162 (#20625)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [libc](https://redirect.github.com/rust-lang/libc) |
workspace.dependencies | patch | `0.2.161` -> `0.2.162` |

---

### Release Notes

<details>
<summary>rust-lang/libc (libc)</summary>

###
[`v0.2.162`](https://redirect.github.com/rust-lang/libc/releases/tag/0.2.162)

[Compare
Source](https://redirect.github.com/rust-lang/libc/compare/0.2.161...0.2.162)

##### Added

- Android: fix the alignment of `uc_mcontext` on arm64
[#&#8203;3894](https://redirect.github.com/rust-lang/libc/pull/3894)
- Apple: add `host_cpu_load_info`
[#&#8203;3916](https://redirect.github.com/rust-lang/libc/pull/3916)
- ESP-IDF: add a time flag
[#&#8203;3993](https://redirect.github.com/rust-lang/libc/pull/3993)
- FreeBSD: add the `CLOSE_RANGE_CLOEXEC`
flag[#&#8203;3996](https://redirect.github.com/rust-lang/libc/pull/3996)
- FreeBSD: fix test errors regarding `__gregset_t`
[#&#8203;3995](https://redirect.github.com/rust-lang/libc/pull/3995)
- FreeBSD: fix tests on x86 FreeBSD 15
[#&#8203;3948](https://redirect.github.com/rust-lang/libc/pull/3948)
- FreeBSD: make `ucontext_t` and `mcontext_t` available on all
architectures
[#&#8203;3848](https://redirect.github.com/rust-lang/libc/pull/3848)
- Haiku: add `getentropy`
[#&#8203;3991](https://redirect.github.com/rust-lang/libc/pull/3991)
- Illumos: add `syncfs`
[#&#8203;3990](https://redirect.github.com/rust-lang/libc/pull/3990)
- Illumos: add some recently-added constants
[#&#8203;3999](https://redirect.github.com/rust-lang/libc/pull/3999)
- Linux: add `ioctl` flags
[#&#8203;3960](https://redirect.github.com/rust-lang/libc/pull/3960)
- Linux: add epoll busy polling parameters
[#&#8203;3922](https://redirect.github.com/rust-lang/libc/pull/3922)
- NuttX: add `pthread_[get/set]name_np`
[#&#8203;4003](https://redirect.github.com/rust-lang/libc/pull/4003)
- RTEMS: add `arc4random_buf`
[#&#8203;3989](https://redirect.github.com/rust-lang/libc/pull/3989)
- Trusty OS: add initial support
[#&#8203;3942](https://redirect.github.com/rust-lang/libc/pull/3942)
- WASIp2: expand socket support
[#&#8203;3981](https://redirect.github.com/rust-lang/libc/pull/3981)

##### Fixed

- Emscripten: don't pass `-lc`
[#&#8203;4002](https://redirect.github.com/rust-lang/libc/pull/4002)
- Hurd: change `st_fsid` field to `st_dev`
[#&#8203;3785](https://redirect.github.com/rust-lang/libc/pull/3785)
- Hurd: fix the definition of `utsname`
[#&#8203;3992](https://redirect.github.com/rust-lang/libc/pull/3992)
- Illumos/Solaris: fix `FNM_CASEFOLD` definition
[#&#8203;4004](https://redirect.github.com/rust-lang/libc/pull/4004)
- Solaris: fix all tests
[#&#8203;3864](https://redirect.github.com/rust-lang/libc/pull/3864)

##### Other

- CI: Add loongarch64
[#&#8203;4000](https://redirect.github.com/rust-lang/libc/pull/4000)
- CI: Check that semver files are sorted
[#&#8203;4018](https://redirect.github.com/rust-lang/libc/pull/4018)
- CI: Re-enable the FreeBSD 15 job
[#&#8203;3988](https://redirect.github.com/rust-lang/libc/pull/3988)
- Clean up imports and `extern crate` usage
[#&#8203;3897](https://redirect.github.com/rust-lang/libc/pull/3897)
- Convert `mode_t` constants to octal
[#&#8203;3634](https://redirect.github.com/rust-lang/libc/pull/3634)
- Remove the `wasm32-wasi` target that has been deleted upstream
[#&#8203;4013](https://redirect.github.com/rust-lang/libc/pull/4013)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 12:07:38 +02:00
renovate[bot]
6b9eba2109 Update Rust crate linkme to v0.3.31 (#20626)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [linkme](https://redirect.github.com/dtolnay/linkme) | dependencies |
patch | `0.3.29` -> `0.3.31` |

---

### Release Notes

<details>
<summary>dtolnay/linkme (linkme)</summary>

###
[`v0.3.31`](https://redirect.github.com/dtolnay/linkme/releases/tag/0.3.31)

[Compare
Source](https://redirect.github.com/dtolnay/linkme/compare/0.3.30...0.3.31)

- Prevent `ref_option_ref` pedantic clippy lint from triggering inside
generated code
([#&#8203;103](https://redirect.github.com/dtolnay/linkme/issues/103))
- Implement Debug for DistributedSlice
([#&#8203;105](https://redirect.github.com/dtolnay/linkme/issues/105))

###
[`v0.3.30`](https://redirect.github.com/dtolnay/linkme/releases/tag/0.3.30)

[Compare
Source](https://redirect.github.com/dtolnay/linkme/compare/0.3.29...0.3.30)

- Support Rust 2024 edition
([#&#8203;102](https://redirect.github.com/dtolnay/linkme/issues/102))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 12:07:27 +02:00
renovate[bot]
58e3b788dc Update Rust crate mdbook to v0.4.42 (#20629)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [mdbook](https://redirect.github.com/rust-lang/mdBook) | dependencies
| patch | `0.4.40` -> `0.4.42` |

---

### Release Notes

<details>
<summary>rust-lang/mdBook (mdbook)</summary>

###
[`v0.4.42`](https://redirect.github.com/rust-lang/mdBook/blob/HEAD/CHANGELOG.md#mdBook-0442)

[Compare
Source](https://redirect.github.com/rust-lang/mdBook/compare/v0.4.41...v0.4.42)


[v0.4.41...v0.4.42](https://redirect.github.com/rust-lang/mdBook/compare/v0.4.41...v0.4.42)

##### Fixed

-   Fixed chapter list folding.
[#&#8203;2473](https://redirect.github.com/rust-lang/mdBook/pull/2473)

###
[`v0.4.41`](https://redirect.github.com/rust-lang/mdBook/blob/HEAD/CHANGELOG.md#mdBook-0441)

[Compare
Source](https://redirect.github.com/rust-lang/mdBook/compare/v0.4.40...v0.4.41)


[v0.4.40...v0.4.41](https://redirect.github.com/rust-lang/mdBook/compare/v0.4.40...v0.4.41)

**Note:** If you have a custom `index.hbs` theme file, you will need to
update it to the latest version.

##### Added

-   Added preliminary support for Rust 2024 edition.
[#&#8203;2398](https://redirect.github.com/rust-lang/mdBook/pull/2398)
-   Added a full example of the remove-emphasis preprocessor.
[#&#8203;2464](https://redirect.github.com/rust-lang/mdBook/pull/2464)

##### Changed

-   Adjusted styling of clipboard/play icons.
[#&#8203;2421](https://redirect.github.com/rust-lang/mdBook/pull/2421)
-   Updated to handlebars v6.
[#&#8203;2416](https://redirect.github.com/rust-lang/mdBook/pull/2416)
-   Attr and section rules now have specific code highlighting.
[#&#8203;2448](https://redirect.github.com/rust-lang/mdBook/pull/2448)
- The sidebar is now loaded from a common file, significantly reducing
the book size when there are many chapters.
[#&#8203;2414](https://redirect.github.com/rust-lang/mdBook/pull/2414)
-   Updated dependencies.
[#&#8203;2470](https://redirect.github.com/rust-lang/mdBook/pull/2470)

##### Fixed

-   Improved theme support when JavaScript is disabled.
[#&#8203;2454](https://redirect.github.com/rust-lang/mdBook/pull/2454)
-   Fixed broken themes when localStorage has an invalid theme id.
[#&#8203;2463](https://redirect.github.com/rust-lang/mdBook/pull/2463)
- Adjusted the line-height of superscripts (and footnotes) to avoid
adding extra space between lines.
[#&#8203;2465](https://redirect.github.com/rust-lang/mdBook/pull/2465)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 12:07:17 +02:00
renovate[bot]
9fd971d8c9 Update Rust crate pulldown-cmark to v0.12.2 (#20630)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [pulldown-cmark](https://redirect.github.com/raphlinus/pulldown-cmark)
| workspace.dependencies | patch | `0.12.1` -> `0.12.2` |

---

### Release Notes

<details>
<summary>raphlinus/pulldown-cmark (pulldown-cmark)</summary>

###
[`v0.12.2`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.12.2):
0.12.2

[Compare
Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.12.1...v0.12.2)

#### What's Changed

- Fix compiilation error in fuzzers by
[@&#8203;kdarkhan](https://redirect.github.com/kdarkhan) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/947](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/947)
- Make `fuzz` dir part of the workspace by
[@&#8203;kdarkhan](https://redirect.github.com/kdarkhan) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/948](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/948)
- Fix and improve `bench` by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/950](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/950)
- Reuse a couple hash maps across blocks by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/951](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/951)
- Reuse outer indent between item list, def list, and blockquote by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/952](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/952)
- Add instructions on fixing fuzz build by
[@&#8203;kdarkhan](https://redirect.github.com/kdarkhan) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/953](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/953)
- Account for definition list fixups while popping containers by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/954](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/954)
- Use byte range instead of char count for delim run bounds by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/956](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/956)
- CI improvements by
[@&#8203;kdarkhan](https://redirect.github.com/kdarkhan) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/955](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/955)
- Fix a problem that causes multiple dt's to be parsed by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/958](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/958)
- fix: emit `InlineHtml` for inline HTML inside blockquote instead of
`Html` by [@&#8203;rhysd](https://redirect.github.com/rhysd) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/961](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/961)
- Complete the list of block item bodies by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/962](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/962)
- Implement into_static for CowStr and Event in pulldown-cmark by
[@&#8203;Atreyagaurav](https://redirect.github.com/Atreyagaurav) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/967](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/967)
- Enforce cargo fmt by
[@&#8203;ollpu](https://redirect.github.com/ollpu) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/971](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/971)
- Respect line starts when trimming header endings by
[@&#8203;notriddle](https://redirect.github.com/notriddle) in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/969](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/969)

#### New Contributors

- [@&#8203;Atreyagaurav](https://redirect.github.com/Atreyagaurav) made
their first contribution in
[https://github.com/pulldown-cmark/pulldown-cmark/pull/967](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/967)

**Full Changelog**:
https://github.com/pulldown-cmark/pulldown-cmark/compare/v0.12.1...v0.12.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 12:07:03 +02:00
renovate[bot]
cf7679e6a0 Update Rust crate clap to v4.5.21 (#20620)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [clap](https://redirect.github.com/clap-rs/clap) |
workspace.dependencies | patch | `4.5.20` -> `4.5.21` |

---

### Release Notes

<details>
<summary>clap-rs/clap (clap)</summary>

###
[`v4.5.21`](https://redirect.github.com/clap-rs/clap/blob/HEAD/CHANGELOG.md#4521---2024-11-13)

[Compare
Source](https://redirect.github.com/clap-rs/clap/compare/v4.5.20...v4.5.21)

##### Fixes

- *(parser)* Ensure defaults are filled in on error with
`ignore_errors(true)`

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 11:12:14 +02:00
renovate[bot]
07c0c54c28 Update Rust crate anyhow to v1.0.93 (#20619)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [anyhow](https://redirect.github.com/dtolnay/anyhow) |
workspace.dependencies | patch | `1.0.91` -> `1.0.93` |

---

### Release Notes

<details>
<summary>dtolnay/anyhow (anyhow)</summary>

###
[`v1.0.93`](https://redirect.github.com/dtolnay/anyhow/releases/tag/1.0.93)

[Compare
Source](https://redirect.github.com/dtolnay/anyhow/compare/1.0.92...1.0.93)

-   Update dev-dependencies to `thiserror` v2

###
[`v1.0.92`](https://redirect.github.com/dtolnay/anyhow/releases/tag/1.0.92)

[Compare
Source](https://redirect.github.com/dtolnay/anyhow/compare/1.0.91...1.0.92)

- Support Rust 1.82's `&raw const` and `&raw mut` syntax inside
`ensure!`
([#&#8203;390](https://redirect.github.com/dtolnay/anyhow/issues/390))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMS41IiwidXBkYXRlZEluVmVyIjoiMzkuMTEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-14 11:11:52 +02:00
Max Brunsfeld
093c9cc87b Avoid creating occlusions for editor blocks, since these block mouse wheel events (#20649)
Just block mouse down events, and in the case of the inline assist
prompt, set the default cursor.

Release Notes:

- N/A

Co-authored-by: Richard <richard@zed.dev>
2024-11-13 21:02:54 -08:00
Bret Comnes
6b3c909155 Clarify rustup is requried (#20642)
Clarify that rustup is required to build developer extensions. Developer
extensions fail silently to the logs because rustup isn't found, even
when rust is installed.

Release Notes:

- N/A
2024-11-13 17:20:20 -08:00
Conrad Irwin
7e349e52b1 Don't try and run on armv5/6/7 (#20618)
Updates: #20523

Release Notes:

- SSH Remoting: correctly show an error when SSH'ing into a 32-bit arm
system
2024-11-13 16:18:53 -07:00
Max Brunsfeld
84d17fb191 Fix completions for non-built-in slash commands (#20632)
Release Notes:

- N/A

Co-authored-by: Marshall <marshall@zed.dev>
2024-11-13 15:11:50 -08:00
Max Brunsfeld
d3d408d47d Improve context server lifecycle management (#20622)
This optimizes and fixes bugs in our logic for maintaining a set of
running context servers, based on the combination of the user's
`context_servers` settings and their installed extensions.

Release Notes:

- N/A

---------

Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
2024-11-13 13:55:06 -08:00
Conrad Irwin
6e477bbf56 Don't double-localize menu shortcuts (#20623)
Release Notes:

- Don't have macOS localize our menu shortcuts that we already
localized.
2024-11-13 13:56:56 -07:00
Conrad Irwin
3c2dcf50fa Don't send key equivalents to the input hanlder (#20621)
Release Notes:

- Fix `cmd-backtick` to change windows
2024-11-13 13:42:31 -07:00
David Soria Parra
a15f408f0c anthropic: Remove stable headers (#20595)
The tool and context length headers are now stable and no longer needed.

Release Notes:

- N/A
2024-11-13 15:04:37 -05:00
Axel Carlsson
b1cd9e4d24 vim: Add support for temporary normal mode (ctrl-o) within insert mode (#19454)
Support has been added for the ctrl-o command within insert mode. Ctrl-o
is used to partially enter normal mode for 1 motion to then return back
into insert mode.

Release Notes:

- vim: Added support for `ctrl-o` in insert mode to enter temporary
normal mode

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2024-11-13 12:44:41 -07:00
Marshall Bowers
254ce74036 Extract ExtensionSlashCommand to assistant_slash_command crate (#20617)
This PR extracts the `ExtensionSlashCommand` implementation to the
`assistant_slash_command` crate.

The slash command related methods have been added to the `Extension`
trait. We also create separate data types for the slash command data
within the `extension` crate so that we can talk about them without
depending on the `extension_host` or `assistant_slash_command`.

Release Notes:

- N/A
2024-11-13 14:34:58 -05:00
Kyle Kelley
b913cf2e02 Allow base64 encoded images to be decoded with or without padding (#20616)
The R kernel doesn't use base64 padding whereas the Python kernel (via
matplotlib) sometimes uses padding. We have to use the `base64` crate's
`Indifferent` mode.

/cherry-pick v0.161.x

Release Notes:

- N/A
2024-11-13 11:26:42 -08:00
Antonio Scandurra
92613a8904 Use replace blocks for patches (#20605)
Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
Co-authored-by: Richard <richard@zed.dev>
2024-11-13 18:55:23 +01:00
Conrad Irwin
96deabfb78 Deadkeys 2 (#20612)
Re-land of #20515 with less brokenness

In particular it turns out that for control, the .characters() method
returns the control code. This mostly didn't make a difference, except
when the control code matched tab/enter/escape (for
ctrl-y,ctrl-[/ctrl-c) as we interpreted the key incorrectly.

Secondly, we were setting IME key too aggressively. This led to (in vim
mode) cmd-shift-{ being interpreted as [, so vim would wait for a second
[ before letting you change tab.

Release Notes:

- N/A
2024-11-13 10:42:08 -07:00
Peter Tripp
ad31aacb7a Fix bad quote in script/determine-release-channel (#20613) 2024-11-13 12:41:50 -05:00
Marshall Bowers
a04c2ecff7 Decouple extension Worktree resource from LspAdapterDelegate (#20611)
This PR decouples the extension `Worktree` resource from the
`LspAdapterDelegate`.

We now have a `WorktreeDelegate` trait that corresponds to the methods
on the resource.

We then create a `WorktreeDelegateAdapter` that can wrap an
`LspAdapterDelegate` and implement the `WorktreeDelegate` trait.

Release Notes:

- N/A
2024-11-13 12:24:27 -05:00
Joseph T. Lyons
f96b29ca54 v0.163.x dev 2024-11-13 11:47:52 -05:00
250 changed files with 6890 additions and 6019 deletions

View File

@@ -244,8 +244,8 @@ jobs:
#
# 25 was chosen arbitrarily.
fetch-depth: 25
fetch-tags: true
clean: false
ref: ${{ github.ref }}
- name: Limit target directory size
run: script/clear-target-dir-if-larger-than 100

21
.github/workflows/script_checks.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: Script
on:
pull_request:
paths:
- "script/**"
push:
branches:
- main
jobs:
shellcheck:
name: "ShellCheck Scripts"
if: github.repository_owner == 'zed-industries'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Shellcheck ./scripts
run: |
./script/shellcheck-scripts error

View File

@@ -22,10 +22,14 @@ Antonio Scandurra <me@as-cii.com> <antonio@zed.dev>
Bennet Bo Fenner <bennet@zed.dev>
Bennet Bo Fenner <bennet@zed.dev> <53836821+bennetbo@users.noreply.github.com>
Bennet Bo Fenner <bennet@zed.dev> <bennetbo@gmx.de>
Boris Cherny <boris@anthropic.com>
Boris Cherny <boris@anthropic.com> <boris@performancejs.com>
Chris Hayes <chris+git@hayes.software>
Christian Bergschneider <christian.bergschneider@gmx.de>
Christian Bergschneider <christian.bergschneider@gmx.de> <magiclake@gmx.de>
Conrad Irwin <conrad@zed.dev>
Conrad Irwin <conrad@zed.dev> <conrad.irwin@gmail.com>
Dairon Medina <dairon.medina@gmail.com>
Danilo Leal <danilo@zed.dev>
Danilo Leal <danilo@zed.dev> <67129314+danilo-leal@users.noreply.github.com>
Evren Sen <nervenes@icloud.com>
@@ -35,6 +39,7 @@ Fernando Tagawa <tagawafernando@gmail.com>
Fernando Tagawa <tagawafernando@gmail.com> <fernando.tagawa.gamail.com@gmail.com>
Greg Morenz <greg-morenz@droid.cafe>
Greg Morenz <greg-morenz@droid.cafe> <morenzg@gmail.com>
Ihnat Aŭtuška <autushka.ihnat@gmail.com>
Ivan Žužak <izuzak@gmail.com>
Ivan Žužak <izuzak@gmail.com> <ivan.zuzak@github.com>
Joseph T. Lyons <JosephTLyons@gmail.com>
@@ -61,10 +66,13 @@ Max Brunsfeld <maxbrunsfeld@gmail.com> <max@zed.dev>
Max Linke <maxlinke88@gmail.com>
Max Linke <maxlinke88@gmail.com> <kain88-de@users.noreply.github.com>
Michael Sloan <michael@zed.dev>
Michael Sloan <michael@zed.dev> <mgsloan@gmail.com>
Michael Sloan <michael@zed.dev> <mgsloan@google.com>
Mikayla Maki <mikayla@zed.dev>
Mikayla Maki <mikayla@zed.dev> <mikayla.c.maki@gmail.com>
Mikayla Maki <mikayla@zed.dev> <mikayla.c.maki@icloud.com>
Muhammad Talal Anwar <mail@talal.io>
Muhammad Talal Anwar <mail@talal.io> <talalanwar@outlook.com>
Nate Butler <iamnbutler@gmail.com>
Nate Butler <iamnbutler@gmail.com> <nate@zed.dev>
Nathan Sobo <nathan@zed.dev>
@@ -88,7 +96,11 @@ Robert Clover <git@clo4.net>
Robert Clover <git@clo4.net> <robert@clover.gdn>
Roy Williams <roy.williams.iii@gmail.com>
Roy Williams <roy.williams.iii@gmail.com> <roy@anthropic.com>
Sebastijan Kelnerič <sebastijan.kelneric@sebba.dev>
Sebastijan Kelnerič <sebastijan.kelneric@sebba.dev> <sebastijan.kelneric@vichava.com>
Sergey Onufrienko <sergey@onufrienko.com>
Shish <webmaster@shishnet.org>
Shish <webmaster@shishnet.org> <shish@shishnet.org>
Thorben Kröger <dev@thorben.net>
Thorben Kröger <dev@thorben.net> <thorben.kroeger@hexagon.com>
Thorsten Ball <thorsten@zed.dev>

870
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -148,7 +148,6 @@ members = [
"extensions/haskell",
"extensions/html",
"extensions/lua",
"extensions/ocaml",
"extensions/php",
"extensions/perplexity",
"extensions/prisma",
@@ -369,12 +368,14 @@ indexmap = { version = "1.6.2", features = ["serde"] }
indoc = "2"
itertools = "0.13.0"
jsonwebtoken = "9.3"
jupyter-protocol = { version = "0.2.0" }
jupyter-websocket-client = { version = "0.4.1" }
libc = "0.2"
linkify = "0.10.0"
log = { version = "0.4.16", features = ["kv_unstable_serde", "serde"] }
markup5ever_rcdom = "0.3.0"
nanoid = "0.4"
nbformat = "0.5.0"
nbformat = "0.6.0"
nix = "0.29"
num-format = "0.4.4"
once_cell = "1.19.0"
@@ -389,7 +390,7 @@ pet-core = { git = "https://github.com/microsoft/python-environment-tools.git",
pet-poetry = { git = "https://github.com/microsoft/python-environment-tools.git", rev = "ffcbf3f28c46633abd5448a52b1f396c322e0d6c" }
pet-reporter = { git = "https://github.com/microsoft/python-environment-tools.git", rev = "ffcbf3f28c46633abd5448a52b1f396c322e0d6c" }
postage = { version = "0.5", features = ["futures-traits"] }
pretty_assertions = "1.3.0"
pretty_assertions = { version = "1.3.0", features = ["unstable"] }
profiling = "1"
prost = "0.9"
prost-build = "0.9"
@@ -408,7 +409,7 @@ reqwest = { git = "https://github.com/zed-industries/reqwest.git", rev = "fd110f
"stream",
] }
rsa = "0.9.6"
runtimelib = { version = "0.19.0", default-features = false, features = [
runtimelib = { version = "0.21.0", default-features = false, features = [
"async-dispatcher-runtime",
] }
rustc-demangle = "0.1.23"
@@ -563,45 +564,45 @@ ttf-parser = { opt-level = 3 }
wasmtime-cranelift = { opt-level = 3 }
wasmtime = { opt-level = 3 }
# Build single-source-file crates with cg=1 as it helps make `cargo build` of a whole workspace a bit faster
activity_indicator = {codegen-units = 1}
assets = {codegen-units = 1}
breadcrumbs = {codegen-units = 1}
collections = {codegen-units = 1}
command_palette = {codegen-units = 1}
command_palette_hooks = {codegen-units = 1}
evals = {codegen-units = 1}
extension_cli = {codegen-units = 1}
feature_flags = {codegen-units = 1}
file_icons = {codegen-units = 1}
fsevent = {codegen-units = 1}
image_viewer = {codegen-units = 1}
inline_completion_button = {codegen-units = 1}
install_cli = {codegen-units = 1}
journal = {codegen-units = 1}
menu = {codegen-units = 1}
notifications = {codegen-units = 1}
ollama = {codegen-units = 1}
outline = {codegen-units = 1}
paths = {codegen-units = 1}
prettier = {codegen-units = 1}
project_symbols = {codegen-units = 1}
refineable = {codegen-units = 1}
release_channel = {codegen-units = 1}
reqwest_client = {codegen-units = 1}
rich_text = {codegen-units = 1}
semantic_version = {codegen-units = 1}
session = {codegen-units = 1}
snippet = {codegen-units = 1}
snippets_ui = {codegen-units = 1}
sqlez_macros = {codegen-units = 1}
story = {codegen-units = 1}
supermaven_api = {codegen-units = 1}
telemetry_events = {codegen-units = 1}
theme_selector = {codegen-units = 1}
time_format = {codegen-units = 1}
ui_input = {codegen-units = 1}
vcs_menu = {codegen-units = 1}
zed_actions = {codegen-units = 1}
activity_indicator = { codegen-units = 1 }
assets = { codegen-units = 1 }
breadcrumbs = { codegen-units = 1 }
collections = { codegen-units = 1 }
command_palette = { codegen-units = 1 }
command_palette_hooks = { codegen-units = 1 }
evals = { codegen-units = 1 }
extension_cli = { codegen-units = 1 }
feature_flags = { codegen-units = 1 }
file_icons = { codegen-units = 1 }
fsevent = { codegen-units = 1 }
image_viewer = { codegen-units = 1 }
inline_completion_button = { codegen-units = 1 }
install_cli = { codegen-units = 1 }
journal = { codegen-units = 1 }
menu = { codegen-units = 1 }
notifications = { codegen-units = 1 }
ollama = { codegen-units = 1 }
outline = { codegen-units = 1 }
paths = { codegen-units = 1 }
prettier = { codegen-units = 1 }
project_symbols = { codegen-units = 1 }
refineable = { codegen-units = 1 }
release_channel = { codegen-units = 1 }
reqwest_client = { codegen-units = 1 }
rich_text = { codegen-units = 1 }
semantic_version = { codegen-units = 1 }
session = { codegen-units = 1 }
snippet = { codegen-units = 1 }
snippets_ui = { codegen-units = 1 }
sqlez_macros = { codegen-units = 1 }
story = { codegen-units = 1 }
supermaven_api = { codegen-units = 1 }
telemetry_events = { codegen-units = 1 }
theme_selector = { codegen-units = 1 }
time_format = { codegen-units = 1 }
ui_input = { codegen-units = 1 }
vcs_menu = { codegen-units = 1 }
zed_actions = { codegen-units = 1 }
[profile.release]
debug = "limited"

View File

@@ -251,6 +251,8 @@
"ctrl-pagedown": "pane::ActivateNextItem",
"ctrl-shift-pageup": "pane::SwapItemLeft",
"ctrl-shift-pagedown": "pane::SwapItemRight",
"back": "pane::GoBack",
"forward": "pane::GoForward",
"ctrl-w": "pane::CloseActiveItem",
"ctrl-f4": "pane::CloseActiveItem",
"alt-ctrl-t": ["pane::CloseInactiveItems", { "close_pinned": false }],

View File

@@ -4,9 +4,7 @@
"ctrl-shift-[": "pane::ActivatePrevItem",
"ctrl-shift-]": "pane::ActivateNextItem",
"ctrl-pageup": "pane::ActivatePrevItem",
"ctrl-pagedown": "pane::ActivateNextItem",
"ctrl-tab": "pane::ActivateNextItem",
"ctrl-shift-tab": "pane::ActivatePrevItem"
"ctrl-pagedown": "pane::ActivateNextItem"
}
},
{
@@ -18,6 +16,7 @@
"ctrl-shift-l": "editor::SplitSelectionIntoLines",
"ctrl-shift-a": "editor::SelectLargerSyntaxNode",
"ctrl-shift-d": "editor::DuplicateLineDown",
"alt-f3": "editor::SelectAllMatches", // find_all_under
"f12": "editor::GoToDefinition",
"ctrl-f12": "editor::GoToDefinitionSplit",
"shift-f12": "editor::FindAllReferences",

View File

@@ -4,9 +4,7 @@
"cmd-shift-[": "pane::ActivatePrevItem",
"cmd-shift-]": "pane::ActivateNextItem",
"ctrl-pageup": "pane::ActivatePrevItem",
"ctrl-pagedown": "pane::ActivateNextItem",
"ctrl-tab": "pane::ActivateNextItem",
"ctrl-shift-tab": "pane::ActivatePrevItem"
"ctrl-pagedown": "pane::ActivateNextItem"
}
},
{
@@ -21,6 +19,7 @@
"cmd-shift-l": "editor::SplitSelectionIntoLines",
"cmd-shift-a": "editor::SelectLargerSyntaxNode",
"cmd-shift-d": "editor::DuplicateLineDown",
"ctrl-cmd-g": "editor::SelectAllMatches", // find_all_under
"shift-f12": "editor::FindAllReferences",
"alt-cmd-down": "editor::GoToDefinition",
"ctrl-alt-cmd-down": "editor::GoToDefinitionSplit",

View File

@@ -304,7 +304,8 @@
"ctrl-q": ["vim::PushOperator", { "Literal": {} }],
"ctrl-shift-q": ["vim::PushOperator", { "Literal": {} }],
"ctrl-r": ["vim::PushOperator", "Register"],
"insert": "vim::ToggleReplace"
"insert": "vim::ToggleReplace",
"ctrl-o": "vim::TemporaryNormal"
}
},
{

View File

@@ -1,206 +0,0 @@
<task_description>
The user of a code editor wants to make a change to their codebase.
You must describe the change using the following XML structure:
- <patch> - A group of related code changes.
Child tags:
- <title> (required) - A high-level description of the changes. This should be as short
as possible, possibly using common abbreviations.
- <edit> (1 or more) - An edit to make at a particular range within a file.
Includes the following child tags:
- <path> (required) - The path to the file that will be changed.
- <description> (optional) - An arbitrarily-long comment that describes the purpose
of this edit.
- <old_text> (optional) - An excerpt from the file's current contents that uniquely
identifies a range within the file where the edit should occur. If this tag is not
specified, then the entire file will be used as the range.
- <new_text> (required) - The new text to insert into the file.
- <operation> (required) - The type of change that should occur at the given range
of the file. Must be one of the following values:
- `update`: Replaces the entire range with the new text.
- `insert_before`: Inserts the new text before the range.
- `insert_after`: Inserts new text after the range.
- `create`: Creates a new file with the given path and the new text.
- `delete`: Deletes the specified range from the file.
<guidelines>
- Never provide multiple edits whose ranges intersect each other. Instead, merge them into one edit.
- Prefer multiple edits to smaller, disjoint ranges, rather than one edit to a larger range.
- There's no need to escape angle brackets within XML tags.
- Always ensure imports are added if you're referencing symbols that are not in scope.
</guidelines>
Here are some concrete examples.
<example>
<message role="user">
```rs src/shapes.rs
pub mod rectangle;
pub mod circle;
```
```rs src/shapes/rectangle.rs
pub struct Rectangle {
width: f64,
height: f64,
}
impl Rectangle {
pub fn new(width: f64, height: f64) -> Self {
Rectangle { width, height }
}
}
```
```rs src/shapes/circle.rs
pub struct Circle {
radius: f64,
}
impl Circle {
pub fn new(radius: f64) -> Self {
Circle { radius }
}
}
```
Update all shapes to store their origin as an (x, y) tuple and implement Display.
</message>
<message role="assistant">
We'll need to update both the rectangle and circle modules.
<patch>
<title>Add origins and display impls to shapes</title>
<edit>
<path>src/shapes/rectangle.rs</path>
<description>Add the origin field to Rectangle struct</description>
<operation>insert_after</operation>
<old_text>
pub struct Rectangle {
</old_text>
<new_text>
origin: (f64, f64),
</new_text>
</edit>
<edit>
<path>src/shapes/rectangle.rs</path>
<operation>update</operation>
<old_text>
fn new(width: f64, height: f64) -> Self {
Rectangle { width, height }
}
</old_text>
<new_text>
fn new(origin: (f64, f64), width: f64, height: f64) -> Self {
Rectangle { origin, width, height }
}
</new_text>
</edit>
<edit>
<path>src/shapes/circle.rs</path>
<description>Add the origin field to Circle struct</description>
<operation>insert_after</operation>
<old_text>
pub struct Circle {
radius: f64,
</old_text>
<new_text>
origin: (f64, f64),
</new_text>
</edit>
<edit>
<path>src/shapes/circle.rs</path>
<operation>update</operation>
<old_text>
fn new(radius: f64) -> Self {
Circle { radius }
}
</old_text>
<new_text>
fn new(origin: (f64, f64), radius: f64) -> Self {
Circle { origin, radius }
}
</new_text>
</edit>
</step>
<edit>
<path>src/shapes/rectangle.rs</path>
<operation>insert_before</operation>
<old_text>
struct Rectangle {
</old_text>
<new_text>
use std::fmt;
</new_text>
</edit>
<edit>
<path>src/shapes/rectangle.rs</path>
<description>
Add a manual Display implementation for Rectangle.
Currently, this is the same as a derived Display implementation.
</description>
<operation>insert_after</operation>
<old_text>
Rectangle { width, height }
}
}
</old_text>
<new_text>
impl fmt::Display for Rectangle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.format_struct(f, "Rectangle")
.field("origin", &self.origin)
.field("width", &self.width)
.field("height", &self.height)
.finish()
}
}
</new_text>
</edit>
<edit>
<path>src/shapes/circle.rs</path>
<operation>insert_before</operation>
<old_text>
struct Circle {
</old_text>
<new_text>
use std::fmt;
</new_text>
</edit>
<edit>
<path>src/shapes/circle.rs</path>
<operation>insert_after</operation>
<old_text>
Circle { radius }
}
}
</old_text>
<new_text>
impl fmt::Display for Rectangle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.format_struct(f, "Rectangle")
.field("origin", &self.origin)
.field("width", &self.width)
.field("height", &self.height)
.finish()
}
}
</new_text>
</edit>
</patch>
</message>
</example>
</task_description>

View File

@@ -490,6 +490,9 @@
"version": "2",
// Whether the assistant is enabled.
"enabled": true,
// Whether to show inline hints showing the keybindings to use the inline assistant and the
// assistant panel.
"show_hints": true,
// Whether to show the assistant panel button in the status bar.
"button": true,
// Where to dock the assistant panel. Can be 'left', 'right' or 'bottom'.
@@ -580,7 +583,23 @@
// Settings related to the file finder.
"file_finder": {
// Whether to show file icons in the file finder.
"file_icons": true
"file_icons": true,
// Determines how much space the file finder can take up in relation to the available window width.
// There are 5 possible width values:
//
// 1. Small: This value is essentially a fixed width.
// "modal_width": "small"
// 2. Medium:
// "modal_width": "medium"
// 3. Large:
// "modal_width": "large"
// 4. Extra Large:
// "modal_width": "xlarge"
// 5. Fullscreen: This value removes any horizontal padding, as it consumes the whole viewport width.
// "modal_width": "full"
//
// Default: small
"modal_max_width": "small"
},
// Whether or not to remove any trailing whitespace from lines of a buffer
// before saving it.
@@ -857,15 +876,8 @@
//
"file_types": {
"Plain Text": ["txt"],
"JSON": ["flake.lock"],
"JSONC": [
"**/.zed/**/*.json",
"**/zed/**/*.json",
"**/Zed/**/*.json",
"tsconfig.json",
"pyrightconfig.json"
],
"TOML": ["uv.lock"]
"JSONC": ["**/.zed/**/*.json", "**/zed/**/*.json", "**/Zed/**/*.json"],
"Shell Script": [".env.*"]
},
/// By default use a recent system version of node, or install our own.
/// You can override this to use a version of node that is not in $PATH with:
@@ -1053,13 +1065,11 @@
"api_url": "https://generativelanguage.googleapis.com"
},
"ollama": {
"api_url": "http://localhost:11434",
"low_speed_timeout_in_seconds": 60
"api_url": "http://localhost:11434"
},
"openai": {
"version": "1",
"api_url": "https://api.openai.com/v1",
"low_speed_timeout_in_seconds": 600
"api_url": "https://api.openai.com/v1"
}
},
// Zed's Prettier integration settings.

View File

@@ -1,14 +1,12 @@
mod supported_countries;
use std::time::Duration;
use std::{pin::Pin, str::FromStr};
use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Utc};
use futures::{io::BufReader, stream::BoxStream, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt};
use http_client::http::{HeaderMap, HeaderValue};
use http_client::{AsyncBody, HttpClient, HttpRequestExt, Method, Request as HttpRequest};
use http_client::{AsyncBody, HttpClient, Method, Request as HttpRequest};
use serde::{Deserialize, Serialize};
use std::{pin::Pin, str::FromStr};
use strum::{EnumIter, EnumString};
use thiserror::Error;
use util::ResultExt as _;
@@ -161,10 +159,7 @@ pub async fn complete(
.method(Method::POST)
.uri(uri)
.header("Anthropic-Version", "2023-06-01")
.header(
"Anthropic-Beta",
"tools-2024-04-04,prompt-caching-2024-07-31,max-tokens-3-5-sonnet-2024-07-15",
)
.header("Anthropic-Beta", "prompt-caching-2024-07-31")
.header("X-Api-Key", api_key)
.header("Content-Type", "application/json");
@@ -210,9 +205,8 @@ pub async fn stream_completion(
api_url: &str,
api_key: &str,
request: Request,
low_speed_timeout: Option<Duration>,
) -> Result<BoxStream<'static, Result<Event, AnthropicError>>, AnthropicError> {
stream_completion_with_rate_limit_info(client, api_url, api_key, request, low_speed_timeout)
stream_completion_with_rate_limit_info(client, api_url, api_key, request)
.await
.map(|output| output.0)
}
@@ -264,7 +258,6 @@ pub async fn stream_completion_with_rate_limit_info(
api_url: &str,
api_key: &str,
request: Request,
low_speed_timeout: Option<Duration>,
) -> Result<
(
BoxStream<'static, Result<Event, AnthropicError>>,
@@ -277,7 +270,7 @@ pub async fn stream_completion_with_rate_limit_info(
stream: true,
};
let uri = format!("{api_url}/v1/messages");
let mut request_builder = HttpRequest::builder()
let request_builder = HttpRequest::builder()
.method(Method::POST)
.uri(uri)
.header("Anthropic-Version", "2023-06-01")
@@ -287,9 +280,6 @@ pub async fn stream_completion_with_rate_limit_info(
)
.header("X-Api-Key", api_key)
.header("Content-Type", "application/json");
if let Some(low_speed_timeout) = low_speed_timeout {
request_builder = request_builder.read_timeout(low_speed_timeout);
}
let serialized_request =
serde_json::to_string(&request).context("failed to serialize request")?;
let request = request_builder

View File

@@ -18,6 +18,7 @@ mod terminal_inline_assistant;
mod tool_working_set;
mod tools;
use crate::slash_command::project_command::ProjectSlashCommandFeatureFlag;
pub use crate::slash_command_working_set::{SlashCommandId, SlashCommandWorkingSet};
pub use crate::tool_working_set::{ToolId, ToolWorkingSet};
pub use assistant_panel::{AssistantPanel, AssistantPanelEvent};
@@ -215,23 +216,32 @@ pub fn init(
});
}
if cx.has_flag::<SearchSlashCommandFeatureFlag>() {
cx.spawn(|mut cx| {
let client = client.clone();
async move {
let embedding_provider = CloudEmbeddingProvider::new(client.clone());
let semantic_index = SemanticDb::new(
paths::embeddings_dir().join("semantic-index-db.0.mdb"),
Arc::new(embedding_provider),
&mut cx,
)
.await?;
cx.spawn(|mut cx| {
let client = client.clone();
async move {
let is_search_slash_command_enabled = cx
.update(|cx| cx.wait_for_flag::<SearchSlashCommandFeatureFlag>())?
.await;
let is_project_slash_command_enabled = cx
.update(|cx| cx.wait_for_flag::<ProjectSlashCommandFeatureFlag>())?
.await;
cx.update(|cx| cx.set_global(semantic_index))
if !is_search_slash_command_enabled && !is_project_slash_command_enabled {
return Ok(());
}
})
.detach();
}
let embedding_provider = CloudEmbeddingProvider::new(client.clone());
let semantic_index = SemanticDb::new(
paths::embeddings_dir().join("semantic-index-db.0.mdb"),
Arc::new(embedding_provider),
&mut cx,
)
.await?;
cx.update(|cx| cx.set_global(semantic_index))
}
})
.detach();
context_store::init(&client.clone().into());
prompt_library::init(cx);

View File

@@ -1,5 +1,6 @@
use crate::slash_command::file_command::codeblock_fence_for_path;
use crate::slash_command_working_set::SlashCommandWorkingSet;
use crate::tools::code_edits_tool::{CodeEditsTool, CodeEditsToolInput};
use crate::ToolWorkingSet;
use crate::{
assistant_settings::{AssistantDockPosition, AssistantSettings},
@@ -1480,7 +1481,6 @@ struct ScrollPosition {
}
struct PatchViewState {
footer_block_id: CustomBlockId,
crease_id: CreaseId,
editor: Option<PatchEditorState>,
update_task: Option<Task<()>>,
@@ -1899,47 +1899,111 @@ impl ContextEditor {
let creases = new_tool_uses
.iter()
.map(|tool_use| {
let placeholder = FoldPlaceholder {
render: render_fold_icon_button(
cx.view().downgrade(),
IconName::PocketKnife,
tool_use.name.clone().into(),
),
..Default::default()
};
let render_trailer =
move |_row, _unfold, _cx: &mut WindowContext| Empty.into_any();
if &tool_use.name == CodeEditsTool::TOOL_NAME {
// If this is a Code Edit tool,
match serde_json::from_value::<CodeEditsToolInput>(
tool_use.input.clone(),
) {
Ok(CodeEditsToolInput { title, edits }) => {
let placeholder = FoldPlaceholder {
render: render_fold_icon_button(
cx.view().downgrade(),
IconName::Sparkle,
title.into(),
),
..Default::default()
};
let render_trailer =
move |_row, _unfold, _cx: &mut WindowContext| {
Empty.into_any()
};
let start = buffer
.anchor_in_excerpt(excerpt_id, tool_use.source_range.start)
.unwrap();
let end = buffer
.anchor_in_excerpt(excerpt_id, tool_use.source_range.end)
.unwrap();
let start = buffer
.anchor_in_excerpt(
excerpt_id,
tool_use.source_range.start,
)
.unwrap();
let end = buffer
.anchor_in_excerpt(
excerpt_id,
tool_use.source_range.end,
)
.unwrap();
let buffer_row = MultiBufferRow(start.to_point(&buffer).row);
buffer_rows_to_fold.insert(buffer_row);
let buffer_row =
MultiBufferRow(start.to_point(&buffer).row);
buffer_rows_to_fold.insert(buffer_row);
self.context.update(cx, |context, cx| {
context.insert_content(
Content::ToolUse {
range: tool_use.source_range.clone(),
tool_use: LanguageModelToolUse {
id: tool_use.id.to_string(),
name: tool_use.name.clone(),
input: tool_use.input.clone(),
self.context.update(cx, |context, cx| {
context.insert_content(
Content::ToolUse {
range: tool_use.source_range.clone(),
tool_use: LanguageModelToolUse {
id: tool_use.id.to_string(),
name: tool_use.name.clone(),
input: tool_use.input.clone(),
},
},
cx,
);
});
Crease::inline(
start..end,
placeholder,
fold_toggle("tool-use"),
render_trailer,
)
}
Err(json_err) => {
// TODO gracefully handle malformed JSON (should distinguish from "errored out" vs "not done streaming yet")
todo!();
}
}
} else {
let placeholder = FoldPlaceholder {
render: render_fold_icon_button(
cx.view().downgrade(),
IconName::PocketKnife,
tool_use.name.clone().into(),
),
..Default::default()
};
let render_trailer =
move |_row, _unfold, _cx: &mut WindowContext| Empty.into_any();
let start = buffer
.anchor_in_excerpt(excerpt_id, tool_use.source_range.start)
.unwrap();
let end = buffer
.anchor_in_excerpt(excerpt_id, tool_use.source_range.end)
.unwrap();
let buffer_row = MultiBufferRow(start.to_point(&buffer).row);
buffer_rows_to_fold.insert(buffer_row);
self.context.update(cx, |context, cx| {
context.insert_content(
Content::ToolUse {
range: tool_use.source_range.clone(),
tool_use: LanguageModelToolUse {
id: tool_use.id.to_string(),
name: tool_use.name.clone(),
input: tool_use.input.clone(),
},
},
},
cx,
);
});
cx,
);
});
Crease::new(
start..end,
placeholder,
fold_toggle("tool-use"),
render_trailer,
)
Crease::inline(
start..end,
placeholder,
fold_toggle("tool-use"),
render_trailer,
)
}
})
.collect::<Vec<_>>();
@@ -2032,7 +2096,7 @@ impl ContextEditor {
let end = buffer
.anchor_in_excerpt(excerpt_id, command.source_range.end)
.unwrap();
Crease::new(start..end, placeholder, render_toggle, render_trailer)
Crease::inline(start..end, placeholder, render_toggle, render_trailer)
}),
cx,
);
@@ -2100,7 +2164,7 @@ impl ContextEditor {
let buffer_row = MultiBufferRow(start.to_point(&buffer).row);
let crease = Crease::new(
let crease = Crease::inline(
start..end,
placeholder,
fold_toggle("tool-use"),
@@ -2199,18 +2263,14 @@ impl ContextEditor {
let crease_end = buffer
.anchor_in_excerpt(excerpt_id, invoked_slash_command.range.end)
.unwrap();
let fold_placeholder =
invoked_slash_command_fold_placeholder(command_id, context);
let crease_ids = editor.insert_creases(
[Crease::new(
crease_start..crease_end,
fold_placeholder.clone(),
fold_toggle("invoked-slash-command"),
|_row, _folded, _cx| Empty.into_any(),
)],
cx,
let crease = Crease::inline(
crease_start..crease_end,
invoked_slash_command_fold_placeholder(command_id, context),
fold_toggle("invoked-slash-command"),
|_row, _folded, _cx| Empty.into_any(),
);
editor.fold_ranges([(crease_start..crease_end, fold_placeholder)], false, cx);
let crease_ids = editor.insert_creases([crease.clone()], cx);
editor.fold_creases(vec![crease], false, cx);
entry.insert(crease_ids[0]);
} else {
cx.notify()
@@ -2232,23 +2292,32 @@ impl ContextEditor {
cx: &mut ViewContext<ContextEditor>,
) {
let this = cx.view().downgrade();
let mut removed_crease_ids = Vec::new();
let mut removed_block_ids = HashSet::default();
let mut editors_to_close = Vec::new();
for range in removed {
if let Some(state) = self.patches.remove(range) {
editors_to_close.extend(state.editor.and_then(|state| state.editor.upgrade()));
removed_block_ids.insert(state.footer_block_id);
removed_crease_ids.push(state.crease_id);
}
}
self.editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
let multibuffer = &snapshot.buffer_snapshot;
let (&excerpt_id, _, _) = multibuffer.as_singleton().unwrap();
let mut replaced_blocks = HashMap::default();
let mut removed_crease_ids = Vec::new();
let mut ranges_to_unfold: Vec<Range<Anchor>> = Vec::new();
for range in removed {
if let Some(state) = self.patches.remove(range) {
let patch_start = multibuffer
.anchor_in_excerpt(excerpt_id, range.start)
.unwrap();
let patch_end = multibuffer
.anchor_in_excerpt(excerpt_id, range.end)
.unwrap();
editors_to_close.extend(state.editor.and_then(|state| state.editor.upgrade()));
ranges_to_unfold.push(patch_start..patch_end);
removed_crease_ids.push(state.crease_id);
}
}
editor.unfold_ranges(&ranges_to_unfold, true, false, cx);
editor.remove_creases(removed_crease_ids, cx);
for range in updated {
let Some(patch) = self.context.read(cx).patch_for_range(&range, cx).cloned() else {
continue;
@@ -2261,19 +2330,21 @@ impl ContextEditor {
let patch_end = multibuffer
.anchor_in_excerpt(excerpt_id, patch.range.end)
.unwrap();
let render_block: RenderBlock = Box::new({
let render_block: RenderBlock = Arc::new({
let this = this.clone();
let patch_range = range.clone();
move |cx: &mut BlockContext<'_, '_>| {
let max_width = cx.max_width;
let gutter_width = cx.gutter_dimensions.full_width();
let block_id = cx.block_id;
let selected = cx.selected;
this.update(&mut **cx, |this, cx| {
this.render_patch_footer(
this.render_patch_block(
patch_range.clone(),
max_width,
gutter_width,
block_id,
selected,
cx,
)
})
@@ -2283,25 +2354,16 @@ impl ContextEditor {
}
});
let header_placeholder = FoldPlaceholder {
render: {
let this = this.clone();
let patch_range = range.clone();
Arc::new(move |fold_id, _range, cx| {
this.update(cx, |this, cx| {
this.render_patch_header(patch_range.clone(), fold_id, cx)
})
.ok()
.flatten()
.unwrap_or_else(|| Empty.into_any())
})
},
..Default::default()
};
let height = path_count as u32 + 1;
let crease = Crease::block(
patch_start..patch_end,
height,
BlockStyle::Flex,
render_block.clone(),
);
let should_refold;
if let Some(state) = self.patches.get_mut(&range) {
replaced_blocks.insert(state.footer_block_id, render_block);
if let Some(editor_state) = &state.editor {
if editor_state.opened_patch != patch {
state.update_task = Some({
@@ -2318,33 +2380,11 @@ impl ContextEditor {
should_refold =
snapshot.intersects_fold(patch_start.to_offset(&snapshot.buffer_snapshot));
} else {
let block_ids = editor.insert_blocks(
[BlockProperties {
height: path_count as u32 + 1,
style: BlockStyle::Flex,
render: render_block,
placement: BlockPlacement::Below(patch_start),
priority: 0,
}],
None,
cx,
);
let new_crease_ids = editor.insert_creases(
[Crease::new(
patch_start..patch_end,
header_placeholder.clone(),
fold_toggle("patch-header"),
|_, _, _| Empty.into_any_element(),
)],
cx,
);
let crease_id = editor.insert_creases([crease.clone()], cx)[0];
self.patches.insert(
range.clone(),
PatchViewState {
footer_block_id: block_ids[0],
crease_id: new_crease_ids[0],
crease_id,
editor: None,
update_task: None,
},
@@ -2355,13 +2395,9 @@ impl ContextEditor {
if should_refold {
editor.unfold_ranges(&[patch_start..patch_end], true, false, cx);
editor.fold_ranges([(patch_start..patch_end, header_placeholder)], false, cx);
editor.fold_creases(vec![crease], false, cx);
}
}
editor.remove_creases(removed_crease_ids, cx);
editor.remove_blocks(removed_block_ids, None, cx);
editor.replace_blocks(replaced_blocks, None, cx);
});
for editor in editors_to_close {
@@ -2392,7 +2428,7 @@ impl ContextEditor {
let buffer_row = MultiBufferRow(start.to_point(&buffer).row);
buffer_rows_to_fold.insert(buffer_row);
creases.push(
Crease::new(
Crease::inline(
start..end,
FoldPlaceholder {
render: render_fold_icon_button(
@@ -2681,7 +2717,7 @@ impl ContextEditor {
let mut blocks_to_replace: HashMap<_, RenderBlock> = Default::default();
let render_block = |message: MessageMetadata| -> RenderBlock {
Box::new({
Arc::new({
let context = self.context.clone();
move |cx| {
@@ -3134,7 +3170,7 @@ impl ContextEditor {
crease_title,
cx.view().downgrade(),
);
let crease = Crease::new(
let crease = Crease::inline(
anchor_before..anchor_after,
fold_placeholder,
render_quote_selection_output_toggle,
@@ -3224,31 +3260,29 @@ impl ContextEditor {
&snapshot,
)
.filter_map(|crease| {
if let Some(metadata) = &crease.metadata {
let start = crease
.range
if let Crease::Inline {
range, metadata, ..
} = &crease
{
let metadata = metadata.as_ref()?;
let start = range
.start
.to_offset(&snapshot)
.saturating_sub(selection_start);
let end = crease
.range
let end = range
.end
.to_offset(&snapshot)
.saturating_sub(selection_start);
let range_relative_to_selection = start..end;
if range_relative_to_selection.is_empty() {
None
} else {
Some(SelectedCreaseMetadata {
if !range_relative_to_selection.is_empty() {
return Some(SelectedCreaseMetadata {
range_relative_to_selection,
crease: metadata.clone(),
})
});
}
} else {
None
}
None
})
.collect::<Vec<_>>()
}),
@@ -3329,7 +3363,7 @@ impl ContextEditor {
let buffer_row = MultiBufferRow(start.to_point(&buffer).row);
buffer_rows_to_fold.insert(buffer_row);
Crease::new(
Crease::inline(
start..end,
FoldPlaceholder {
render: render_fold_icon_button(
@@ -3371,7 +3405,8 @@ impl ContextEditor {
self.context.update(cx, |context, cx| {
for image in images {
let Some(render_image) = image.to_image_data(cx).log_err() else {
let Some(render_image) = image.to_image_data(cx.svg_renderer()).log_err()
else {
continue;
};
let image_id = image.id();
@@ -3422,7 +3457,7 @@ impl ContextEditor {
placement: BlockPlacement::Above(anchor),
height: MAX_HEIGHT_IN_LINES,
style: BlockStyle::Sticky,
render: Box::new(move |cx| {
render: Arc::new(move |cx| {
let image_size = size_for_image(
&image,
size(
@@ -3479,33 +3514,13 @@ impl ContextEditor {
.unwrap_or_else(|| Cow::Borrowed(DEFAULT_TAB_TITLE))
}
fn render_patch_header(
&self,
range: Range<text::Anchor>,
_id: FoldId,
cx: &mut ViewContext<Self>,
) -> Option<AnyElement> {
let patch = self.context.read(cx).patch_for_range(&range, cx)?;
let theme = cx.theme().clone();
Some(
h_flex()
.px_1()
.py_0p5()
.border_b_1()
.border_color(theme.status().info_border)
.gap_1()
.child(Icon::new(IconName::Diff).size(IconSize::Small))
.child(Label::new(patch.title.clone()).size(LabelSize::Small))
.into_any(),
)
}
fn render_patch_footer(
fn render_patch_block(
&mut self,
range: Range<text::Anchor>,
max_width: Pixels,
gutter_width: Pixels,
id: BlockId,
selected: bool,
cx: &mut ViewContext<Self>,
) -> Option<AnyElement> {
let snapshot = self.editor.update(cx, |editor, cx| editor.snapshot(cx));
@@ -3516,10 +3531,7 @@ impl ContextEditor {
.anchor_in_excerpt(excerpt_id, range.start)
.unwrap();
if !snapshot.intersects_fold(anchor) {
return None;
}
let theme = cx.theme().clone();
let patch = self.context.read(cx).patch_for_range(&range, cx)?;
let paths = patch
.paths()
@@ -3529,9 +3541,18 @@ impl ContextEditor {
Some(
v_flex()
.id(id)
.pl(gutter_width)
.w(max_width)
.py_2()
.bg(theme.colors().editor_background)
.ml(gutter_width)
.pb_1()
.w(max_width - gutter_width)
.rounded_md()
.border_1()
.border_color(theme.colors().border_variant)
.overflow_hidden()
.hover(|style| style.border_color(theme.colors().text_accent))
.when(selected, |this| {
this.border_color(theme.colors().text_accent)
})
.cursor(CursorStyle::PointingHand)
.on_click(cx.listener(move |this, _, cx| {
this.editor.update(cx, |editor, cx| {
@@ -3541,24 +3562,60 @@ impl ContextEditor {
});
this.focus_active_patch(cx);
}))
.child(
div()
.px_2()
.py_1()
.overflow_hidden()
.text_ellipsis()
.border_b_1()
.border_color(theme.colors().border_variant)
.bg(theme.colors().element_background)
.child(
Label::new(patch.title.clone())
.size(LabelSize::Small)
.color(Color::Muted),
),
)
.children(paths.into_iter().map(|path| {
h_flex()
.pl_1()
.gap_1()
.px_2()
.pt_1()
.gap_1p5()
.child(Icon::new(IconName::File).size(IconSize::Small))
.child(Label::new(path).size(LabelSize::Small))
}))
.when(patch.status == AssistantPatchStatus::Pending, |div| {
div.child(
Label::new("Generating")
.color(Color::Muted)
.size(LabelSize::Small)
.with_animation(
"pulsating-label",
Animation::new(Duration::from_secs(2))
.repeat()
.with_easing(pulsating_between(0.4, 1.)),
|label, delta| label.alpha(delta),
h_flex()
.pt_1()
.px_2()
.gap_1()
.child(
Icon::new(IconName::ArrowCircle)
.size(IconSize::XSmall)
.color(Color::Muted)
.with_animation(
"arrow-circle",
Animation::new(Duration::from_secs(2)).repeat(),
|icon, delta| {
icon.transform(Transformation::rotate(percentage(
delta,
)))
},
),
)
.child(
Label::new("Generating…")
.color(Color::Muted)
.size(LabelSize::Small)
.with_animation(
"pulsating-label",
Animation::new(Duration::from_secs(2))
.repeat()
.with_easing(pulsating_between(0.4, 0.8)),
|label, delta| label.alpha(delta),
),
),
)
})
@@ -3936,7 +3993,7 @@ impl ContextEditor {
.child(
div()
.id("error-message")
.max_h_24()
.max_h_32()
.overflow_y_scroll()
.child(Label::new(error_message.clone())),
)

View File

@@ -35,20 +35,17 @@ pub enum AssistantProviderContentV1 {
OpenAi {
default_model: Option<OpenAiModel>,
api_url: Option<String>,
low_speed_timeout_in_seconds: Option<u64>,
available_models: Option<Vec<OpenAiModel>>,
},
#[serde(rename = "anthropic")]
Anthropic {
default_model: Option<AnthropicModel>,
api_url: Option<String>,
low_speed_timeout_in_seconds: Option<u64>,
},
#[serde(rename = "ollama")]
Ollama {
default_model: Option<OllamaModel>,
api_url: Option<String>,
low_speed_timeout_in_seconds: Option<u64>,
},
}
@@ -63,6 +60,7 @@ pub struct AssistantSettings {
pub inline_alternatives: Vec<LanguageModelSelection>,
pub using_outdated_settings_version: bool,
pub enable_experimental_live_diffs: bool,
pub show_hints: bool,
}
impl AssistantSettings {
@@ -115,47 +113,41 @@ impl AssistantSettingsContent {
if let VersionedAssistantSettingsContent::V1(settings) = settings {
if let Some(provider) = settings.provider.clone() {
match provider {
AssistantProviderContentV1::Anthropic {
api_url,
low_speed_timeout_in_seconds,
..
} => update_settings_file::<AllLanguageModelSettings>(
fs,
cx,
move |content, _| {
if content.anthropic.is_none() {
content.anthropic = Some(AnthropicSettingsContent::Versioned(
VersionedAnthropicSettingsContent::V1(
AnthropicSettingsContentV1 {
api_url,
low_speed_timeout_in_seconds,
available_models: None,
},
),
));
}
},
),
AssistantProviderContentV1::Ollama {
api_url,
low_speed_timeout_in_seconds,
..
} => update_settings_file::<AllLanguageModelSettings>(
fs,
cx,
move |content, _| {
if content.ollama.is_none() {
content.ollama = Some(OllamaSettingsContent {
api_url,
low_speed_timeout_in_seconds,
available_models: None,
});
}
},
),
AssistantProviderContentV1::Anthropic { api_url, .. } => {
update_settings_file::<AllLanguageModelSettings>(
fs,
cx,
move |content, _| {
if content.anthropic.is_none() {
content.anthropic =
Some(AnthropicSettingsContent::Versioned(
VersionedAnthropicSettingsContent::V1(
AnthropicSettingsContentV1 {
api_url,
available_models: None,
},
),
));
}
},
)
}
AssistantProviderContentV1::Ollama { api_url, .. } => {
update_settings_file::<AllLanguageModelSettings>(
fs,
cx,
move |content, _| {
if content.ollama.is_none() {
content.ollama = Some(OllamaSettingsContent {
api_url,
available_models: None,
});
}
},
)
}
AssistantProviderContentV1::OpenAi {
api_url,
low_speed_timeout_in_seconds,
available_models,
..
} => update_settings_file::<AllLanguageModelSettings>(
@@ -188,7 +180,6 @@ impl AssistantSettingsContent {
VersionedOpenAiSettingsContent::V1(
OpenAiSettingsContentV1 {
api_url,
low_speed_timeout_in_seconds,
available_models,
},
),
@@ -212,6 +203,7 @@ impl AssistantSettingsContent {
AssistantSettingsContent::Versioned(settings) => match settings {
VersionedAssistantSettingsContent::V1(settings) => AssistantSettingsContentV2 {
enabled: settings.enabled,
show_hints: None,
button: settings.button,
dock: settings.dock,
default_width: settings.default_width,
@@ -252,6 +244,7 @@ impl AssistantSettingsContent {
},
AssistantSettingsContent::Legacy(settings) => AssistantSettingsContentV2 {
enabled: None,
show_hints: None,
button: settings.button,
dock: settings.dock,
default_width: settings.default_width,
@@ -298,54 +291,41 @@ impl AssistantSettingsContent {
log::warn!("attempted to set zed.dev model on outdated settings");
}
"anthropic" => {
let (api_url, low_speed_timeout_in_seconds) = match &settings.provider {
Some(AssistantProviderContentV1::Anthropic {
api_url,
low_speed_timeout_in_seconds,
..
}) => (api_url.clone(), *low_speed_timeout_in_seconds),
_ => (None, None),
let api_url = match &settings.provider {
Some(AssistantProviderContentV1::Anthropic { api_url, .. }) => {
api_url.clone()
}
_ => None,
};
settings.provider = Some(AssistantProviderContentV1::Anthropic {
default_model: AnthropicModel::from_id(&model).ok(),
api_url,
low_speed_timeout_in_seconds,
});
}
"ollama" => {
let (api_url, low_speed_timeout_in_seconds) = match &settings.provider {
Some(AssistantProviderContentV1::Ollama {
api_url,
low_speed_timeout_in_seconds,
..
}) => (api_url.clone(), *low_speed_timeout_in_seconds),
_ => (None, None),
let api_url = match &settings.provider {
Some(AssistantProviderContentV1::Ollama { api_url, .. }) => {
api_url.clone()
}
_ => None,
};
settings.provider = Some(AssistantProviderContentV1::Ollama {
default_model: Some(ollama::Model::new(&model, None, None)),
api_url,
low_speed_timeout_in_seconds,
});
}
"openai" => {
let (api_url, low_speed_timeout_in_seconds, available_models) =
match &settings.provider {
Some(AssistantProviderContentV1::OpenAi {
api_url,
low_speed_timeout_in_seconds,
available_models,
..
}) => (
api_url.clone(),
*low_speed_timeout_in_seconds,
available_models.clone(),
),
_ => (None, None, None),
};
let (api_url, available_models) = match &settings.provider {
Some(AssistantProviderContentV1::OpenAi {
api_url,
available_models,
..
}) => (api_url.clone(), available_models.clone()),
_ => (None, None),
};
settings.provider = Some(AssistantProviderContentV1::OpenAi {
default_model: OpenAiModel::from_id(&model).ok(),
api_url,
low_speed_timeout_in_seconds,
available_models,
});
}
@@ -377,6 +357,7 @@ impl Default for VersionedAssistantSettingsContent {
fn default() -> Self {
Self::V2(AssistantSettingsContentV2 {
enabled: None,
show_hints: None,
button: None,
dock: None,
default_width: None,
@@ -394,6 +375,11 @@ pub struct AssistantSettingsContentV2 {
///
/// Default: true
enabled: Option<bool>,
/// Whether to show inline hints that show keybindings for inline assistant
/// and assistant panel.
///
/// Default: true
show_hints: Option<bool>,
/// Whether to show the assistant panel button in the status bar.
///
/// Default: true
@@ -528,6 +514,7 @@ impl Settings for AssistantSettings {
let value = value.upgrade();
merge(&mut settings.enabled, value.enabled);
merge(&mut settings.show_hints, value.show_hints);
merge(&mut settings.button, value.button);
merge(&mut settings.dock, value.dock);
merge(
@@ -598,6 +585,7 @@ mod tests {
}),
inline_alternatives: None,
enabled: None,
show_hints: None,
button: None,
dock: None,
default_width: None,

View File

@@ -6,12 +6,14 @@ use crate::ToolWorkingSet;
use crate::{
prompts::PromptBuilder,
slash_command::{file_command::FileCommandMetadata, SlashCommandLine},
AssistantEdit, AssistantPatch, AssistantPatchStatus, MessageId, MessageStatus,
tools::code_edits_tool::CodeEditsTool,
AssistantPatch, MessageId, MessageStatus,
};
use anyhow::{anyhow, Context as _, Result};
use assistant_slash_command::{
SlashCommandContent, SlashCommandEvent, SlashCommandOutputSection, SlashCommandResult,
};
use assistant_tool::Tool;
use client::{self, proto, telemetry::Telemetry};
use clock::ReplicaId;
use collections::{HashMap, HashSet};
@@ -43,7 +45,6 @@ use std::{
iter, mem,
ops::Range,
path::{Path, PathBuf},
str::FromStr as _,
sync::Arc,
time::{Duration, Instant},
};
@@ -561,7 +562,6 @@ pub struct Context {
telemetry: Option<Arc<Telemetry>>,
language_registry: Arc<LanguageRegistry>,
patches: Vec<AssistantPatch>,
xml_tags: Vec<XmlTag>,
project: Option<Model<Project>>,
prompt_builder: Arc<PromptBuilder>,
}
@@ -670,7 +670,6 @@ impl Context {
slash_commands,
tools,
patches: Vec::new(),
xml_tags: Vec::new(),
prompt_builder,
};
@@ -962,7 +961,6 @@ impl Context {
}
if !changed_messages.is_empty() {
self.message_roles_updated(changed_messages, cx);
cx.emit(ContextEvent::MessagesEdited);
cx.notify();
}
@@ -1386,8 +1384,6 @@ impl Context {
let mut removed_parsed_slash_command_ranges = Vec::new();
let mut updated_parsed_slash_commands = Vec::new();
let mut removed_patches = Vec::new();
let mut updated_patches = Vec::new();
while let Some(mut row_range) = row_ranges.next() {
while let Some(next_row_range) = row_ranges.peek() {
if row_range.end >= next_row_range.start {
@@ -1412,13 +1408,6 @@ impl Context {
cx,
);
self.invalidate_pending_slash_commands(&buffer, cx);
self.reparse_patches_in_range(
start..end,
&buffer,
&mut updated_patches,
&mut removed_patches,
cx,
);
}
if !updated_parsed_slash_commands.is_empty()
@@ -1429,13 +1418,6 @@ impl Context {
updated: updated_parsed_slash_commands,
});
}
if !updated_patches.is_empty() || !removed_patches.is_empty() {
cx.emit(ContextEvent::PatchesUpdated {
removed: removed_patches,
updated: updated_patches,
});
}
}
fn reparse_slash_commands_in_range(
@@ -1526,267 +1508,6 @@ impl Context {
}
}
fn reparse_patches_in_range(
&mut self,
range: Range<text::Anchor>,
buffer: &BufferSnapshot,
updated: &mut Vec<Range<text::Anchor>>,
removed: &mut Vec<Range<text::Anchor>>,
cx: &mut ModelContext<Self>,
) {
// Rebuild the XML tags in the edited range.
let intersecting_tags_range =
self.indices_intersecting_buffer_range(&self.xml_tags, range.clone(), cx);
let new_tags = self.parse_xml_tags_in_range(buffer, range.clone(), cx);
self.xml_tags
.splice(intersecting_tags_range.clone(), new_tags);
// Find which patches intersect the changed range.
let intersecting_patches_range =
self.indices_intersecting_buffer_range(&self.patches, range.clone(), cx);
// Reparse all tags after the last unchanged patch before the change.
let mut tags_start_ix = 0;
if let Some(preceding_unchanged_patch) =
self.patches[..intersecting_patches_range.start].last()
{
tags_start_ix = match self.xml_tags.binary_search_by(|tag| {
tag.range
.start
.cmp(&preceding_unchanged_patch.range.end, buffer)
.then(Ordering::Less)
}) {
Ok(ix) | Err(ix) => ix,
};
}
// Rebuild the patches in the range.
let new_patches = self.parse_patches(tags_start_ix, range.end, buffer, cx);
updated.extend(new_patches.iter().map(|patch| patch.range.clone()));
let removed_patches = self.patches.splice(intersecting_patches_range, new_patches);
removed.extend(
removed_patches
.map(|patch| patch.range)
.filter(|range| !updated.contains(&range)),
);
}
fn parse_xml_tags_in_range(
&self,
buffer: &BufferSnapshot,
range: Range<text::Anchor>,
cx: &AppContext,
) -> Vec<XmlTag> {
let mut messages = self.messages(cx).peekable();
let mut tags = Vec::new();
let mut lines = buffer.text_for_range(range).lines();
let mut offset = lines.offset();
while let Some(line) = lines.next() {
while let Some(message) = messages.peek() {
if offset < message.offset_range.end {
break;
} else {
messages.next();
}
}
let is_assistant_message = messages
.peek()
.map_or(false, |message| message.role == Role::Assistant);
if is_assistant_message {
for (start_ix, _) in line.match_indices('<') {
let mut name_start_ix = start_ix + 1;
let closing_bracket_ix = line[start_ix..].find('>').map(|i| start_ix + i);
if let Some(closing_bracket_ix) = closing_bracket_ix {
let end_ix = closing_bracket_ix + 1;
let mut is_open_tag = true;
if line[name_start_ix..closing_bracket_ix].starts_with('/') {
name_start_ix += 1;
is_open_tag = false;
}
let tag_inner = &line[name_start_ix..closing_bracket_ix];
let tag_name_len = tag_inner
.find(|c: char| c.is_whitespace())
.unwrap_or(tag_inner.len());
if let Ok(kind) = XmlTagKind::from_str(&tag_inner[..tag_name_len]) {
tags.push(XmlTag {
range: buffer.anchor_after(offset + start_ix)
..buffer.anchor_before(offset + end_ix),
is_open_tag,
kind,
});
};
}
}
}
offset = lines.offset();
}
tags
}
fn parse_patches(
&mut self,
tags_start_ix: usize,
buffer_end: text::Anchor,
buffer: &BufferSnapshot,
cx: &AppContext,
) -> Vec<AssistantPatch> {
let mut new_patches = Vec::new();
let mut pending_patch = None;
let mut patch_tag_depth = 0;
let mut tags = self.xml_tags[tags_start_ix..].iter().peekable();
'tags: while let Some(tag) = tags.next() {
if tag.range.start.cmp(&buffer_end, buffer).is_gt() && patch_tag_depth == 0 {
break;
}
if tag.kind == XmlTagKind::Patch && tag.is_open_tag {
patch_tag_depth += 1;
let patch_start = tag.range.start;
let mut edits = Vec::<Result<AssistantEdit>>::new();
let mut patch = AssistantPatch {
range: patch_start..patch_start,
title: String::new().into(),
edits: Default::default(),
status: crate::AssistantPatchStatus::Pending,
};
while let Some(tag) = tags.next() {
if tag.kind == XmlTagKind::Patch && !tag.is_open_tag {
patch_tag_depth -= 1;
if patch_tag_depth == 0 {
patch.range.end = tag.range.end;
// Include the line immediately after this <patch> tag if it's empty.
let patch_end_offset = patch.range.end.to_offset(buffer);
let mut patch_end_chars = buffer.chars_at(patch_end_offset);
if patch_end_chars.next() == Some('\n')
&& patch_end_chars.next().map_or(true, |ch| ch == '\n')
{
let messages = self.messages_for_offsets(
[patch_end_offset, patch_end_offset + 1],
cx,
);
if messages.len() == 1 {
patch.range.end = buffer.anchor_before(patch_end_offset + 1);
}
}
edits.sort_unstable_by(|a, b| {
if let (Ok(a), Ok(b)) = (a, b) {
a.path.cmp(&b.path)
} else {
Ordering::Equal
}
});
patch.edits = edits.into();
patch.status = AssistantPatchStatus::Ready;
new_patches.push(patch);
continue 'tags;
}
}
if tag.kind == XmlTagKind::Title && tag.is_open_tag {
let content_start = tag.range.end;
while let Some(tag) = tags.next() {
if tag.kind == XmlTagKind::Title && !tag.is_open_tag {
let content_end = tag.range.start;
patch.title =
trimmed_text_in_range(buffer, content_start..content_end)
.into();
break;
}
}
}
if tag.kind == XmlTagKind::Edit && tag.is_open_tag {
let mut path = None;
let mut old_text = None;
let mut new_text = None;
let mut operation = None;
let mut description = None;
while let Some(tag) = tags.next() {
if tag.kind == XmlTagKind::Edit && !tag.is_open_tag {
edits.push(AssistantEdit::new(
path,
operation,
old_text,
new_text,
description,
));
break;
}
if tag.is_open_tag
&& [
XmlTagKind::Path,
XmlTagKind::OldText,
XmlTagKind::NewText,
XmlTagKind::Operation,
XmlTagKind::Description,
]
.contains(&tag.kind)
{
let kind = tag.kind;
let content_start = tag.range.end;
if let Some(tag) = tags.peek() {
if tag.kind == kind && !tag.is_open_tag {
let tag = tags.next().unwrap();
let content_end = tag.range.start;
let content = trimmed_text_in_range(
buffer,
content_start..content_end,
);
match kind {
XmlTagKind::Path => path = Some(content),
XmlTagKind::Operation => operation = Some(content),
XmlTagKind::OldText => {
old_text = Some(content).filter(|s| !s.is_empty())
}
XmlTagKind::NewText => {
new_text = Some(content).filter(|s| !s.is_empty())
}
XmlTagKind::Description => {
description =
Some(content).filter(|s| !s.is_empty())
}
_ => {}
}
}
}
}
}
}
}
patch.edits = edits.into();
pending_patch = Some(patch);
}
}
if let Some(mut pending_patch) = pending_patch {
let patch_start = pending_patch.range.start.to_offset(buffer);
if let Some(message) = self.message_for_offset(patch_start, cx) {
if message.anchor_range.end == text::Anchor::MAX {
pending_patch.range.end = text::Anchor::MAX;
} else {
let message_end = buffer.anchor_after(message.offset_range.end - 1);
pending_patch.range.end = message_end;
}
} else {
pending_patch.range.end = text::Anchor::MAX;
}
new_patches.push(pending_patch);
}
new_patches
}
pub fn pending_command_for_position(
&mut self,
position: language::Anchor,
@@ -2386,7 +2107,11 @@ impl Context {
});
Some(error.to_string())
} else {
let error_message = error.to_string().trim().to_string();
let error_message = error
.chain()
.map(|err| err.to_string())
.collect::<Vec<_>>()
.join("\n");
cx.emit(ContextEvent::ShowAssistError(SharedString::from(
error_message.clone(),
)));
@@ -2467,9 +2192,22 @@ impl Context {
}
}
let tools = if let RequestType::SuggestEdits = request_type {
vec![{
let tool = CodeEditsTool;
LanguageModelRequestTool {
name: tool.name(),
description: tool.description(),
input_schema: tool.input_schema(),
}
}]
} else {
Vec::new()
};
let mut completion_request = LanguageModelRequest {
messages: Vec::new(),
tools: Vec::new(),
tools,
stop: Vec::new(),
temperature: None,
};
@@ -2542,25 +2280,6 @@ impl Context {
completion_request.messages.push(request_message);
}
if let RequestType::SuggestEdits = request_type {
if let Ok(preamble) = self.prompt_builder.generate_suggest_edits_prompt() {
let last_elem_index = completion_request.messages.len();
completion_request
.messages
.push(LanguageModelRequestMessage {
role: Role::User,
content: vec![MessageContent::Text(preamble)],
cache: false,
});
// The preamble message should be sent right before the last actual user message.
completion_request
.messages
.swap(last_elem_index, last_elem_index.saturating_sub(1));
}
}
completion_request
}
@@ -2584,28 +2303,6 @@ impl Context {
self.update_metadata(*id, cx, |metadata| metadata.role = role);
}
}
self.message_roles_updated(ids, cx);
}
fn message_roles_updated(&mut self, ids: HashSet<MessageId>, cx: &mut ModelContext<Self>) {
let mut ranges = Vec::new();
for message in self.messages(cx) {
if ids.contains(&message.id) {
ranges.push(message.anchor_range.clone());
}
}
let buffer = self.buffer.read(cx).text_snapshot();
let mut updated = Vec::new();
let mut removed = Vec::new();
for range in ranges {
self.reparse_patches_in_range(range, &buffer, &mut updated, &mut removed, cx);
}
if !updated.is_empty() || !removed.is_empty() {
cx.emit(ContextEvent::PatchesUpdated { removed, updated })
}
}
pub fn update_metadata(

View File

@@ -1,11 +1,11 @@
use super::{AssistantEdit, MessageCacheMetadata};
use super::MessageCacheMetadata;
use crate::slash_command_working_set::SlashCommandWorkingSet;
use crate::ToolWorkingSet;
use crate::{
assistant_panel, prompt_library, slash_command::file_command, AssistantEditKind, CacheStatus,
Context, ContextEvent, ContextId, ContextOperation, InvokedSlashCommandId, MessageId,
MessageStatus, PromptBuilder,
};
use crate::{AssistantEdit, ToolWorkingSet};
use anyhow::Result;
use assistant_slash_command::{
ArgumentCompletion, SlashCommand, SlashCommandContent, SlashCommandEvent, SlashCommandOutput,

View File

@@ -24,9 +24,9 @@ use futures::{
join, SinkExt, Stream, StreamExt,
};
use gpui::{
anchored, deferred, point, AnyElement, AppContext, ClickEvent, EventEmitter, FocusHandle,
FocusableView, FontWeight, Global, HighlightStyle, Model, ModelContext, Subscription, Task,
TextStyle, UpdateGlobal, View, ViewContext, WeakView, WindowContext,
anchored, deferred, point, AnyElement, AppContext, ClickEvent, CursorStyle, EventEmitter,
FocusHandle, FocusableView, FontWeight, Global, HighlightStyle, Model, ModelContext,
Subscription, Task, TextStyle, UpdateGlobal, View, ViewContext, WeakView, WindowContext,
};
use language::{Buffer, IndentKind, Point, Selection, TransactionId};
use language_model::{
@@ -460,7 +460,7 @@ impl InlineAssistant {
style: BlockStyle::Sticky,
placement: BlockPlacement::Below(range.end),
height: 0,
render: Box::new(|cx| {
render: Arc::new(|cx| {
v_flex()
.h_full()
.w_full()
@@ -1197,8 +1197,9 @@ impl InlineAssistant {
placement: BlockPlacement::Above(new_row),
height,
style: BlockStyle::Flex,
render: Box::new(move |cx| {
render: Arc::new(move |cx| {
div()
.block_mouse_down()
.bg(cx.theme().status().deleted_background)
.size_full()
.h(height as f32 * cx.line_height())
@@ -1317,7 +1318,7 @@ impl InlineAssistGroup {
fn build_assist_editor_renderer(editor: &View<PromptEditor>) -> RenderBlock {
let editor = editor.clone();
Box::new(move |cx: &mut BlockContext| {
Arc::new(move |cx: &mut BlockContext| {
*editor.read(cx).gutter_dimensions.lock() = *cx.gutter_dimensions;
editor.clone().into_any_element()
})
@@ -1480,6 +1481,8 @@ impl Render for PromptEditor {
h_flex()
.key_context("PromptEditor")
.bg(cx.theme().colors().editor_background)
.block_mouse_down()
.cursor(CursorStyle::Arrow)
.border_y_1()
.border_color(cx.theme().status().info_border)
.size_full()

View File

@@ -310,10 +310,6 @@ impl PromptBuilder {
.render("terminal_assistant_prompt", &context)
}
pub fn generate_suggest_edits_prompt(&self) -> Result<String, RenderError> {
self.handlebars.lock().render("suggest_edits", &())
}
pub fn generate_project_slash_command_prompt(
&self,
context_buffer: String,

View File

@@ -1,2 +1,3 @@
pub mod code_edits_tool;
pub mod context_server_tool;
pub mod now_tool;

View File

@@ -0,0 +1,86 @@
use std::sync::Arc;
use anyhow::{anyhow, Result};
use assistant_tool::Tool;
use gpui::{Task, WeakView, WindowContext};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct CodeEditsToolInput {
/// A high-level description of the code changes. This should be as short as possible, possibly using common abbreviations.
pub title: String,
/// An array of edits to be applied.
pub edits: Vec<Edit>,
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct Edit {
/// The path to the file that this edit will change.
pub path: String,
/// An arbitrarily-long comment that describes the purpose of this edit.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// An excerpt from the file's current contents that uniquely identifies a range within the file where the edit should occur.
#[serde(skip_serializing_if = "Option::is_none")]
pub old_text: Option<String>,
/// The new text to insert into the file.
pub new_text: String,
/// The type of change that should occur at the given range of the file.
pub operation: Operation,
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Operation {
/// Replaces the entire range with the new text.
Update,
/// Inserts the new text before the range.
InsertBefore,
/// Inserts new text after the range.
InsertAfter,
/// Creates a new file with the given path and the new text.
Create,
/// Deletes the specified range from the file.
Delete,
}
pub struct CodeEditsTool;
impl CodeEditsTool {
pub const TOOL_NAME: &str = "zed_code_edits";
}
impl Tool for CodeEditsTool {
fn name(&self) -> String {
Self::TOOL_NAME.to_string()
}
fn description(&self) -> String {
// Anthropic's best practices for tool descriptions:
// https://docs.anthropic.com/en/docs/build-with-claude/tool-use#best-practices-for-tool-definitions
include_str!("edit_tool_description.txt").to_string()
}
fn input_schema(&self) -> serde_json::Value {
let schema = schemars::schema_for!(CodeEditsToolInput);
serde_json::to_value(&schema).unwrap()
}
fn run(
self: Arc<Self>,
input: serde_json::Value,
_workspace: WeakView<workspace::Workspace>,
_cx: &mut WindowContext,
) -> Task<Result<String>> {
let input: CodeEditsToolInput = match serde_json::from_value(input) {
Ok(input) => input,
Err(err) => return Task::ready(Err(anyhow!(err))),
};
let text = format!("The tool returned {:?}.", input);
Task::ready(Ok(text))
}
}

View File

@@ -0,0 +1,15 @@
Describes the specific code changes that should be made to the files in a code base, based on the request the user made.
It should be used when the user requests making changes to the code base, but not when the user is asking an question about information
(including when asking for information about the code base) rather than requesting a change.
The tool will return an array of patches, each of which represents some related modifications to the code base.
Each patch contains a high-level summary of the changes (which will be displayed in the code editor),
as well as an array of specific edits to be made to specific individual files. The code editor will apply each of those edits to the code base, or not, at the discretion of the user of the editor.
Within each patch, the tool will never return multiple edits whose ranges intersect each other. Instead, it will merge them into one edit.
On the other hand, for ranges that do not intersect each other, the tool will prefer multiple edits to smaller ranges over one edit to a larger range.
Whenever edits reference symbols that would be out of scope, the tool will always include earlier edits which add any necessary imports to bring those symbols into scope.
The overall goal is that if the user of the code editor accepts all edits within all patches, the code will end up in a correct state, and
will successfully build and run without any further modifications from the user. It will also have correctly effected the changes to the code base that the user originally requested.

View File

@@ -343,7 +343,7 @@ fn init_test(cx: &mut AppContext) -> Model<ChannelStore> {
release_channel::init(SemanticVersion::default(), cx);
client::init_settings(cx);
let clock = Arc::new(FakeSystemClock::default());
let clock = Arc::new(FakeSystemClock::new());
let http = FakeHttpClient::with_404_response();
let client = Client::new(clock, http.clone(), cx);
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));

View File

@@ -42,7 +42,6 @@ serde_json.workspace = true
settings.workspace = true
sha2.workspace = true
smol.workspace = true
sysinfo.workspace = true
telemetry_events.workspace = true
text.workspace = true
thiserror.workspace = true

View File

@@ -1780,7 +1780,7 @@ mod tests {
let user_id = 5;
let client = cx.update(|cx| {
Client::new(
Arc::new(FakeSystemClock::default()),
Arc::new(FakeSystemClock::new()),
FakeHttpClient::with_404_response(),
cx,
)
@@ -1821,7 +1821,7 @@ mod tests {
let user_id = 5;
let client = cx.update(|cx| {
Client::new(
Arc::new(FakeSystemClock::default()),
Arc::new(FakeSystemClock::new()),
FakeHttpClient::with_404_response(),
cx,
)
@@ -1900,7 +1900,7 @@ mod tests {
let dropped_auth_count = Arc::new(Mutex::new(0));
let client = cx.update(|cx| {
Client::new(
Arc::new(FakeSystemClock::default()),
Arc::new(FakeSystemClock::new()),
FakeHttpClient::with_404_response(),
cx,
)
@@ -1943,7 +1943,7 @@ mod tests {
let user_id = 5;
let client = cx.update(|cx| {
Client::new(
Arc::new(FakeSystemClock::default()),
Arc::new(FakeSystemClock::new()),
FakeHttpClient::with_404_response(),
cx,
)
@@ -2003,7 +2003,7 @@ mod tests {
let user_id = 5;
let client = cx.update(|cx| {
Client::new(
Arc::new(FakeSystemClock::default()),
Arc::new(FakeSystemClock::new()),
FakeHttpClient::with_404_response(),
cx,
)
@@ -2038,7 +2038,7 @@ mod tests {
let user_id = 5;
let client = cx.update(|cx| {
Client::new(
Arc::new(FakeSystemClock::default()),
Arc::new(FakeSystemClock::new()),
FakeHttpClient::with_404_response(),
cx,
)

View File

@@ -2,7 +2,6 @@ mod event_coalescer;
use crate::{ChannelId, TelemetrySettings};
use anyhow::Result;
use chrono::{DateTime, Utc};
use clock::SystemClock;
use collections::{HashMap, HashSet};
use futures::Future;
@@ -15,12 +14,11 @@ use settings::{Settings, SettingsStore};
use sha2::{Digest, Sha256};
use std::fs::File;
use std::io::Write;
use std::time::Instant;
use std::{env, mem, path::PathBuf, sync::Arc, time::Duration};
use sysinfo::{CpuRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System};
use telemetry_events::{
ActionEvent, AppEvent, AssistantEvent, CallEvent, CpuEvent, EditEvent, EditorEvent, Event,
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, ReplEvent,
SettingEvent,
ActionEvent, AppEvent, AssistantEvent, CallEvent, EditEvent, EditorEvent, Event,
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, ReplEvent, SettingEvent,
};
use util::{ResultExt, TryFutureExt};
use worktree::{UpdatedEntriesSet, WorktreeId};
@@ -46,7 +44,7 @@ struct TelemetryState {
flush_events_task: Option<Task<()>>,
log_file: Option<File>,
is_staff: Option<bool>,
first_event_date_time: Option<DateTime<Utc>>,
first_event_date_time: Option<Instant>,
event_coalescer: EventCoalescer,
max_queue_size: usize,
worktree_id_map: WorktreeIdMap,
@@ -293,55 +291,13 @@ impl Telemetry {
state.session_id = Some(session_id);
state.app_version = release_channel::AppVersion::global(cx).to_string();
state.os_name = os_name();
drop(state);
let this = self.clone();
cx.background_executor()
.spawn(async move {
let mut system = System::new_with_specifics(
RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
let refresh_kind = ProcessRefreshKind::new().with_cpu().with_memory();
let current_process = Pid::from_u32(std::process::id());
system.refresh_processes_specifics(
sysinfo::ProcessesToUpdate::Some(&[current_process]),
refresh_kind,
);
// Waiting some amount of time before the first query is important to get a reasonable value
// https://docs.rs/sysinfo/0.29.10/sysinfo/trait.ProcessExt.html#tymethod.cpu_usage
const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(4 * 60);
loop {
smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await;
let current_process = Pid::from_u32(std::process::id());
system.refresh_processes_specifics(
sysinfo::ProcessesToUpdate::Some(&[current_process]),
refresh_kind,
);
let Some(process) = system.process(current_process) else {
log::error!(
"Failed to find own process {current_process:?} in system process table"
);
// TODO: Fire an error telemetry event
return;
};
this.report_memory_event(process.memory(), process.virtual_memory());
this.report_cpu_event(process.cpu_usage(), system.cpus().len() as u32);
}
})
.detach();
}
pub fn metrics_enabled(self: &Arc<Self>) -> bool {
let state = self.state.lock();
let enabled = state.settings.metrics;
drop(state);
return enabled;
enabled
}
pub fn set_authenticated_user_info(
@@ -416,28 +372,6 @@ impl Telemetry {
self.report_event(event)
}
pub fn report_cpu_event(self: &Arc<Self>, usage_as_percentage: f32, core_count: u32) {
let event = Event::Cpu(CpuEvent {
usage_as_percentage,
core_count,
});
self.report_event(event)
}
pub fn report_memory_event(
self: &Arc<Self>,
memory_in_bytes: u64,
virtual_memory_in_bytes: u64,
) {
let event = Event::Memory(MemoryEvent {
memory_in_bytes,
virtual_memory_in_bytes,
});
self.report_event(event)
}
pub fn report_app_event(self: &Arc<Self>, operation: String) -> Event {
let event = Event::App(AppEvent { operation });
@@ -469,7 +403,10 @@ impl Telemetry {
if let Some((start, end, environment)) = period_data {
let event = Event::Edit(EditEvent {
duration: end.timestamp_millis() - start.timestamp_millis(),
duration: end
.saturating_duration_since(start)
.min(Duration::from_secs(60 * 60 * 24))
.as_millis() as i64,
environment: environment.to_string(),
is_via_ssh,
});
@@ -567,9 +504,10 @@ impl Telemetry {
let date_time = self.clock.utc_now();
let milliseconds_since_first_event = match state.first_event_date_time {
Some(first_event_date_time) => {
date_time.timestamp_millis() - first_event_date_time.timestamp_millis()
}
Some(first_event_date_time) => date_time
.saturating_duration_since(first_event_date_time)
.min(Duration::from_secs(60 * 60 * 24))
.as_millis() as i64,
None => {
state.first_event_date_time = Some(date_time);
0
@@ -702,7 +640,6 @@ pub fn calculate_json_checksum(json: &impl AsRef<[u8]>) -> Option<String> {
#[cfg(test)]
mod tests {
use super::*;
use chrono::TimeZone;
use clock::FakeSystemClock;
use gpui::TestAppContext;
use http_client::FakeHttpClient;
@@ -710,9 +647,7 @@ mod tests {
#[gpui::test]
fn test_telemetry_flush_on_max_queue_size(cx: &mut TestAppContext) {
init_test(cx);
let clock = Arc::new(FakeSystemClock::new(
Utc.with_ymd_and_hms(1990, 4, 12, 12, 0, 0).unwrap(),
));
let clock = Arc::new(FakeSystemClock::new());
let http = FakeHttpClient::with_200_response();
let system_id = Some("system_id".to_string());
let installation_id = Some("installation_id".to_string());
@@ -743,7 +678,7 @@ mod tests {
Some(first_date_time)
);
clock.advance(chrono::Duration::milliseconds(100));
clock.advance(Duration::from_millis(100));
let event = telemetry.report_app_event(operation.clone());
assert_eq!(
@@ -759,7 +694,7 @@ mod tests {
Some(first_date_time)
);
clock.advance(chrono::Duration::milliseconds(100));
clock.advance(Duration::from_millis(100));
let event = telemetry.report_app_event(operation.clone());
assert_eq!(
@@ -775,7 +710,7 @@ mod tests {
Some(first_date_time)
);
clock.advance(chrono::Duration::milliseconds(100));
clock.advance(Duration::from_millis(100));
// Adding a 4th event should cause a flush
let event = telemetry.report_app_event(operation.clone());
@@ -796,9 +731,7 @@ mod tests {
cx: &mut TestAppContext,
) {
init_test(cx);
let clock = Arc::new(FakeSystemClock::new(
Utc.with_ymd_and_hms(1990, 4, 12, 12, 0, 0).unwrap(),
));
let clock = Arc::new(FakeSystemClock::new());
let http = FakeHttpClient::with_200_response();
let system_id = Some("system_id".to_string());
let installation_id = Some("installation_id".to_string());

View File

@@ -1,7 +1,6 @@
use std::sync::Arc;
use std::time;
use std::{sync::Arc, time::Instant};
use chrono::{DateTime, Duration, Utc};
use clock::SystemClock;
const COALESCE_TIMEOUT: time::Duration = time::Duration::from_secs(20);
@@ -10,8 +9,8 @@ const SIMULATED_DURATION_FOR_SINGLE_EVENT: time::Duration = time::Duration::from
#[derive(Debug, PartialEq)]
struct PeriodData {
environment: &'static str,
start: DateTime<Utc>,
end: Option<DateTime<Utc>>,
start: Instant,
end: Option<Instant>,
}
pub struct EventCoalescer {
@@ -27,9 +26,8 @@ impl EventCoalescer {
pub fn log_event(
&mut self,
environment: &'static str,
) -> Option<(DateTime<Utc>, DateTime<Utc>, &'static str)> {
) -> Option<(Instant, Instant, &'static str)> {
let log_time = self.clock.utc_now();
let coalesce_timeout = Duration::from_std(COALESCE_TIMEOUT).unwrap();
let Some(state) = &mut self.state else {
self.state = Some(PeriodData {
@@ -43,7 +41,7 @@ impl EventCoalescer {
let period_end = state
.end
.unwrap_or(state.start + SIMULATED_DURATION_FOR_SINGLE_EVENT);
let within_timeout = log_time - period_end < coalesce_timeout;
let within_timeout = log_time - period_end < COALESCE_TIMEOUT;
let environment_is_same = state.environment == environment;
let should_coaelesce = !within_timeout || !environment_is_same;
@@ -70,16 +68,13 @@ impl EventCoalescer {
#[cfg(test)]
mod tests {
use chrono::TimeZone;
use clock::FakeSystemClock;
use super::*;
#[test]
fn test_same_context_exceeding_timeout() {
let clock = Arc::new(FakeSystemClock::new(
Utc.with_ymd_and_hms(1990, 4, 12, 0, 0, 0).unwrap(),
));
let clock = Arc::new(FakeSystemClock::new());
let environment_1 = "environment_1";
let mut event_coalescer = EventCoalescer::new(clock.clone());
@@ -98,7 +93,7 @@ mod tests {
})
);
let within_timeout_adjustment = Duration::from_std(COALESCE_TIMEOUT / 2).unwrap();
let within_timeout_adjustment = COALESCE_TIMEOUT / 2;
// Ensure that many calls within the timeout don't start a new period
for _ in 0..100 {
@@ -118,7 +113,7 @@ mod tests {
}
let period_end = clock.utc_now();
let exceed_timeout_adjustment = Duration::from_std(COALESCE_TIMEOUT * 2).unwrap();
let exceed_timeout_adjustment = COALESCE_TIMEOUT * 2;
// Logging an event exceeding the timeout should start a new period
clock.advance(exceed_timeout_adjustment);
let new_period_start = clock.utc_now();
@@ -137,9 +132,7 @@ mod tests {
#[test]
fn test_different_environment_under_timeout() {
let clock = Arc::new(FakeSystemClock::new(
Utc.with_ymd_and_hms(1990, 4, 12, 0, 0, 0).unwrap(),
));
let clock = Arc::new(FakeSystemClock::new());
let environment_1 = "environment_1";
let mut event_coalescer = EventCoalescer::new(clock.clone());
@@ -158,7 +151,7 @@ mod tests {
})
);
let within_timeout_adjustment = Duration::from_std(COALESCE_TIMEOUT / 2).unwrap();
let within_timeout_adjustment = COALESCE_TIMEOUT / 2;
clock.advance(within_timeout_adjustment);
let period_end = clock.utc_now();
let period_data = event_coalescer.log_event(environment_1);
@@ -193,9 +186,7 @@ mod tests {
#[test]
fn test_switching_environment_while_within_timeout() {
let clock = Arc::new(FakeSystemClock::new(
Utc.with_ymd_and_hms(1990, 4, 12, 0, 0, 0).unwrap(),
));
let clock = Arc::new(FakeSystemClock::new());
let environment_1 = "environment_1";
let mut event_coalescer = EventCoalescer::new(clock.clone());
@@ -214,7 +205,7 @@ mod tests {
})
);
let within_timeout_adjustment = Duration::from_std(COALESCE_TIMEOUT / 2).unwrap();
let within_timeout_adjustment = COALESCE_TIMEOUT / 2;
clock.advance(within_timeout_adjustment);
let period_end = clock.utc_now();
let environment_2 = "environment_2";
@@ -240,9 +231,7 @@ mod tests {
#[test]
fn test_switching_environment_while_exceeding_timeout() {
let clock = Arc::new(FakeSystemClock::new(
Utc.with_ymd_and_hms(1990, 4, 12, 0, 0, 0).unwrap(),
));
let clock = Arc::new(FakeSystemClock::new());
let environment_1 = "environment_1";
let mut event_coalescer = EventCoalescer::new(clock.clone());
@@ -261,7 +250,7 @@ mod tests {
})
);
let exceed_timeout_adjustment = Duration::from_std(COALESCE_TIMEOUT * 2).unwrap();
let exceed_timeout_adjustment = COALESCE_TIMEOUT * 2;
clock.advance(exceed_timeout_adjustment);
let period_end = clock.utc_now();
let environment_2 = "environment_2";

View File

@@ -16,7 +16,6 @@ doctest = false
test-support = ["dep:parking_lot"]
[dependencies]
chrono.workspace = true
parking_lot = { workspace = true, optional = true }
serde.workspace = true
smallvec.workspace = true

View File

@@ -1,21 +1,21 @@
use chrono::{DateTime, Utc};
use std::time::Instant;
pub trait SystemClock: Send + Sync {
/// Returns the current date and time in UTC.
fn utc_now(&self) -> DateTime<Utc>;
fn utc_now(&self) -> Instant;
}
pub struct RealSystemClock;
impl SystemClock for RealSystemClock {
fn utc_now(&self) -> DateTime<Utc> {
Utc::now()
fn utc_now(&self) -> Instant {
Instant::now()
}
}
#[cfg(any(test, feature = "test-support"))]
pub struct FakeSystemClockState {
now: DateTime<Utc>,
now: Instant,
}
#[cfg(any(test, feature = "test-support"))]
@@ -24,36 +24,30 @@ pub struct FakeSystemClock {
state: parking_lot::Mutex<FakeSystemClockState>,
}
#[cfg(any(test, feature = "test-support"))]
impl Default for FakeSystemClock {
fn default() -> Self {
Self::new(Utc::now())
}
}
#[cfg(any(test, feature = "test-support"))]
impl FakeSystemClock {
pub fn new(now: DateTime<Utc>) -> Self {
let state = FakeSystemClockState { now };
pub fn new() -> Self {
let state = FakeSystemClockState {
now: Instant::now(),
};
Self {
state: parking_lot::Mutex::new(state),
}
}
pub fn set_now(&self, now: DateTime<Utc>) {
pub fn set_now(&self, now: Instant) {
self.state.lock().now = now;
}
/// Advances the [`FakeSystemClock`] by the specified [`Duration`](chrono::Duration).
pub fn advance(&self, duration: chrono::Duration) {
pub fn advance(&self, duration: std::time::Duration) {
self.state.lock().now += duration;
}
}
#[cfg(any(test, feature = "test-support"))]
impl SystemClock for FakeSystemClock {
fn utc_now(&self) -> DateTime<Utc> {
fn utc_now(&self) -> Instant {
self.state.lock().now
}
}

View File

@@ -24,6 +24,7 @@ async-stripe.workspace = true
async-tungstenite.workspace = true
aws-config = { version = "1.1.5" }
aws-sdk-s3 = { version = "1.15.0" }
aws-sdk-kinesis = "1.51.0"
axum = { version = "0.6", features = ["json", "headers", "ws"] }
axum-extra = { version = "0.4", features = ["erased-json"] }
base64.workspace = true

View File

@@ -174,6 +174,31 @@ spec:
secretKeyRef:
name: blob-store
key: bucket
- name: KINESIS_ACCESS_KEY
valueFrom:
secretKeyRef:
name: kinesis
key: access_key
- name: KINESIS_SECRET_KEY
valueFrom:
secretKeyRef:
name: kinesis
key: secret_key
- name: KINESIS_STREAM
valueFrom:
secretKeyRef:
name: kinesis
key: stream
- name: KINESIS_REGION
valueFrom:
secretKeyRef:
name: kinesis
key: region
- name: BLOB_STORE_BUCKET
valueFrom:
secretKeyRef:
name: blob-store
key: bucket
- name: CLICKHOUSE_URL
valueFrom:
secretKeyRef:

View File

@@ -11,9 +11,11 @@ use axum::{
routing::post,
Extension, Router, TypedHeader,
};
use chrono::Duration;
use rpc::ExtensionMetadata;
use semantic_version::SemanticVersion;
use serde::{Serialize, Serializer};
use serde::{Deserialize, Serialize, Serializer};
use serde_json::json;
use sha2::{Digest, Sha256};
use std::sync::{Arc, OnceLock};
use telemetry_events::{
@@ -21,6 +23,7 @@ use telemetry_events::{
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, Panic,
ReplEvent, SettingEvent,
};
use util::ResultExt;
use uuid::Uuid;
const CRASH_REPORTS_BUCKET: &str = "zed-crash-reports";
@@ -388,13 +391,6 @@ pub async fn post_events(
country_code_header: Option<TypedHeader<CloudflareIpCountryHeader>>,
body: Bytes,
) -> Result<()> {
let Some(clickhouse_client) = app.clickhouse_client.clone() else {
Err(Error::http(
StatusCode::NOT_IMPLEMENTED,
"not supported".into(),
))?
};
let Some(expected) = calculate_json_checksum(app.clone(), &body) else {
return Err(Error::http(
StatusCode::INTERNAL_SERVER_ERROR,
@@ -416,6 +412,34 @@ pub async fn post_events(
};
let country_code = country_code_header.map(|h| h.to_string());
let first_event_at = chrono::Utc::now()
- chrono::Duration::milliseconds(last_event.milliseconds_since_first_event);
if let Some(kinesis_client) = app.kinesis_client.clone() {
if let Some(stream) = app.config.kinesis_stream.clone() {
let mut request = kinesis_client.put_records().stream_name(stream);
for row in for_snowflake(request_body.clone(), first_event_at, country_code.clone()) {
if let Some(data) = serde_json::to_vec(&row).log_err() {
request = request.records(
aws_sdk_kinesis::types::PutRecordsRequestEntry::builder()
.partition_key(request_body.system_id.clone().unwrap_or_default())
.data(data.into())
.build()
.unwrap(),
);
}
}
request.send().await.log_err();
}
};
let Some(clickhouse_client) = app.clickhouse_client.clone() else {
Err(Error::http(
StatusCode::NOT_IMPLEMENTED,
"not supported".into(),
))?
};
let first_event_at = chrono::Utc::now()
- chrono::Duration::milliseconds(last_event.milliseconds_since_first_event);
@@ -459,20 +483,7 @@ pub async fn post_events(
checksum_matched,
))
}
Event::Cpu(event) => to_upload.cpu_events.push(CpuEventRow::from_event(
event.clone(),
wrapper,
&request_body,
first_event_at,
checksum_matched,
)),
Event::Memory(event) => to_upload.memory_events.push(MemoryEventRow::from_event(
event.clone(),
wrapper,
&request_body,
first_event_at,
checksum_matched,
)),
Event::Cpu(_) | Event::Memory(_) => continue,
Event::App(event) => to_upload.app_events.push(AppEventRow::from_event(
event.clone(),
wrapper,
@@ -923,6 +934,7 @@ pub struct CpuEventRow {
}
impl CpuEventRow {
#[allow(unused)]
fn from_event(
event: CpuEvent,
wrapper: &EventWrapper,
@@ -977,6 +989,7 @@ pub struct MemoryEventRow {
}
impl MemoryEventRow {
#[allow(unused)]
fn from_event(
event: MemoryEvent,
wrapper: &EventWrapper,
@@ -1364,3 +1377,259 @@ pub fn calculate_json_checksum(app: Arc<AppState>, json: &impl AsRef<[u8]>) -> O
summer.update(checksum_seed);
Some(summer.finalize().into_iter().collect())
}
fn for_snowflake(
body: EventRequestBody,
first_event_at: chrono::DateTime<chrono::Utc>,
country_code: Option<String>,
) -> impl Iterator<Item = SnowflakeRow> {
body.events.into_iter().flat_map(move |event| {
let timestamp =
first_event_at + Duration::milliseconds(event.milliseconds_since_first_event);
let (event_type, mut event_properties) = match &event.event {
Event::Editor(e) => (
match e.operation.as_str() {
"open" => "Editor Opened".to_string(),
"save" => "Editor Saved".to_string(),
_ => format!("Unknown Editor Event: {}", e.operation),
},
serde_json::to_value(e).unwrap(),
),
Event::InlineCompletion(e) => (
format!(
"Inline Completion {}",
if e.suggestion_accepted {
"Accepted"
} else {
"Discarded"
}
),
serde_json::to_value(e).unwrap(),
),
Event::Call(e) => {
let event_type = match e.operation.trim() {
"unshare project" => "Project Unshared".to_string(),
"open channel notes" => "Channel Notes Opened".to_string(),
"share project" => "Project Shared".to_string(),
"join channel" => "Channel Joined".to_string(),
"hang up" => "Call Ended".to_string(),
"accept incoming" => "Incoming Call Accepted".to_string(),
"invite" => "Participant Invited".to_string(),
"disable microphone" => "Microphone Disabled".to_string(),
"enable microphone" => "Microphone Enabled".to_string(),
"enable screen share" => "Screen Share Enabled".to_string(),
"disable screen share" => "Screen Share Disabled".to_string(),
"decline incoming" => "Incoming Call Declined".to_string(),
"enable camera" => "Camera Enabled".to_string(),
"disable camera" => "Camera Disabled".to_string(),
_ => format!("Unknown Call Event: {}", e.operation),
};
(event_type, serde_json::to_value(e).unwrap())
}
Event::Assistant(e) => (
match e.phase {
telemetry_events::AssistantPhase::Response => "Assistant Responded".to_string(),
telemetry_events::AssistantPhase::Invoked => "Assistant Invoked".to_string(),
telemetry_events::AssistantPhase::Accepted => {
"Assistant Response Accepted".to_string()
}
telemetry_events::AssistantPhase::Rejected => {
"Assistant Response Rejected".to_string()
}
},
serde_json::to_value(e).unwrap(),
),
Event::Cpu(_) | Event::Memory(_) => return None,
Event::App(e) => {
let mut properties = json!({});
let event_type = match e.operation.trim() {
"extensions: install extension" => "Extension Installed".to_string(),
"open" => "App Opened".to_string(),
"project search: open" => "Project Search Opened".to_string(),
"first open" => {
properties["is_first_open"] = json!(true);
"App First Opened".to_string()
}
"extensions: uninstall extension" => "Extension Uninstalled".to_string(),
"welcome page: close" => "Welcome Page Closed".to_string(),
"open project" => {
properties["is_first_time"] = json!(false);
"Project Opened".to_string()
}
"welcome page: install cli" => "CLI Installed".to_string(),
"project diagnostics: open" => "Project Diagnostics Opened".to_string(),
"extensions page: open" => "Extensions Page Opened".to_string(),
"welcome page: change theme" => "Welcome Theme Changed".to_string(),
"welcome page: toggle metric telemetry" => {
properties["enabled"] = json!(false);
"Welcome Telemetry Toggled".to_string()
}
"welcome page: change keymap" => "Keymap Changed".to_string(),
"welcome page: toggle vim" => {
properties["enabled"] = json!(false);
"Welcome Vim Mode Toggled".to_string()
}
"welcome page: sign in to copilot" => "Welcome Copilot Signed In".to_string(),
"welcome page: toggle diagnostic telemetry" => {
"Welcome Telemetry Toggled".to_string()
}
"welcome page: open" => "Welcome Page Opened".to_string(),
"close" => "App Closed".to_string(),
"markdown preview: open" => "Markdown Preview Opened".to_string(),
"welcome page: open extensions" => "Extensions Page Opened".to_string(),
"open node project" | "open pnpm project" | "open yarn project" => {
properties["project_type"] = json!("node");
properties["is_first_time"] = json!(false);
"Project Opened".to_string()
}
"repl sessions: open" => "REPL Session Started".to_string(),
"welcome page: toggle helix" => {
properties["enabled"] = json!(false);
"Helix Mode Toggled".to_string()
}
"welcome page: edit settings" => {
properties["changed_settings"] = json!([]);
"Settings Edited".to_string()
}
"welcome page: view docs" => "Documentation Viewed".to_string(),
"open ssh project" => {
properties["is_first_time"] = json!(false);
"SSH Project Opened".to_string()
}
"create ssh server" => "SSH Server Created".to_string(),
"create ssh project" => "SSH Project Created".to_string(),
"first open for release channel" => {
properties["is_first_for_channel"] = json!(true);
"App First Opened For Release Channel".to_string()
}
"feature upsell: toggle vim" => {
properties["source"] = json!("Feature Upsell");
"Vim Mode Toggled".to_string()
}
_ => e
.operation
.strip_prefix("feature upsell: viewed docs (")
.and_then(|s| s.strip_suffix(')'))
.map_or_else(
|| format!("Unknown App Event: {}", e.operation),
|docs_url| {
properties["url"] = json!(docs_url);
properties["source"] = json!("Feature Upsell");
"Documentation Viewed".to_string()
},
),
};
(event_type, properties)
}
Event::Setting(e) => (
"Settings Changed".to_string(),
serde_json::to_value(e).unwrap(),
),
Event::Extension(e) => (
"Extension Loaded".to_string(),
serde_json::to_value(e).unwrap(),
),
Event::Edit(e) => (
"Editor Edited".to_string(),
serde_json::to_value(e).unwrap(),
),
Event::Action(e) => (
"Action Invoked".to_string(),
serde_json::to_value(e).unwrap(),
),
Event::Repl(e) => (
"Kernel Status Changed".to_string(),
serde_json::to_value(e).unwrap(),
),
};
if let serde_json::Value::Object(ref mut map) = event_properties {
map.insert("app_version".to_string(), body.app_version.clone().into());
map.insert("os_name".to_string(), body.os_name.clone().into());
map.insert("os_version".to_string(), body.os_version.clone().into());
map.insert("architecture".to_string(), body.architecture.clone().into());
map.insert(
"release_channel".to_string(),
body.release_channel.clone().into(),
);
map.insert("signed_in".to_string(), event.signed_in.into());
if let Some(country_code) = country_code.as_ref() {
map.insert("country_code".to_string(), country_code.clone().into());
}
}
let user_properties = Some(serde_json::json!({
"is_staff": body.is_staff,
"Country": country_code.clone(),
"OS": format!("{} {}", body.os_name, body.os_version.clone().unwrap_or_default()),
"Version": body.app_version.clone(),
}));
Some(SnowflakeRow {
time: timestamp,
user_id: body.metrics_id.clone(),
device_id: body.system_id.clone(),
event_type,
event_properties,
user_properties,
insert_id: Some(Uuid::new_v4().to_string()),
})
})
}
#[derive(Serialize, Deserialize)]
struct SnowflakeRow {
pub time: chrono::DateTime<chrono::Utc>,
pub user_id: Option<String>,
pub device_id: Option<String>,
pub event_type: String,
pub event_properties: serde_json::Value,
pub user_properties: Option<serde_json::Value>,
pub insert_id: Option<String>,
}
#[derive(Serialize, Deserialize)]
struct SnowflakeData {
/// Identifier unique to each Zed installation (differs for stable, preview, dev)
pub installation_id: Option<String>,
/// Identifier unique to each logged in Zed user (randomly generated on first sign in)
/// Identifier unique to each Zed session (differs for each time you open Zed)
pub session_id: Option<String>,
pub metrics_id: Option<String>,
/// True for Zed staff, otherwise false
pub is_staff: Option<bool>,
/// Zed version number
pub app_version: String,
pub os_name: String,
pub os_version: Option<String>,
pub architecture: String,
/// Zed release channel (stable, preview, dev)
pub release_channel: Option<String>,
pub signed_in: bool,
#[serde(flatten)]
pub editor_event: Option<EditorEvent>,
#[serde(flatten)]
pub inline_completion_event: Option<InlineCompletionEvent>,
#[serde(flatten)]
pub call_event: Option<CallEvent>,
#[serde(flatten)]
pub assistant_event: Option<AssistantEvent>,
#[serde(flatten)]
pub cpu_event: Option<CpuEvent>,
#[serde(flatten)]
pub memory_event: Option<MemoryEvent>,
#[serde(flatten)]
pub app_event: Option<AppEvent>,
#[serde(flatten)]
pub setting_event: Option<SettingEvent>,
#[serde(flatten)]
pub extension_event: Option<ExtensionEvent>,
#[serde(flatten)]
pub edit_event: Option<EditEvent>,
#[serde(flatten)]
pub repl_event: Option<ReplEvent>,
#[serde(flatten)]
pub action_event: Option<ActionEvent>,
}

View File

@@ -170,6 +170,10 @@ pub struct Config {
pub blob_store_access_key: Option<String>,
pub blob_store_secret_key: Option<String>,
pub blob_store_bucket: Option<String>,
pub kinesis_region: Option<String>,
pub kinesis_stream: Option<String>,
pub kinesis_access_key: Option<String>,
pub kinesis_secret_key: Option<String>,
pub zed_environment: Arc<str>,
pub openai_api_key: Option<Arc<str>>,
pub google_ai_api_key: Option<Arc<str>>,
@@ -238,6 +242,10 @@ impl Config {
stripe_api_key: None,
supermaven_admin_api_key: None,
user_backfiller_github_access_token: None,
kinesis_region: None,
kinesis_access_key: None,
kinesis_secret_key: None,
kinesis_stream: None,
}
}
}
@@ -276,6 +284,7 @@ pub struct AppState {
pub rate_limiter: Arc<RateLimiter>,
pub executor: Executor,
pub clickhouse_client: Option<::clickhouse::Client>,
pub kinesis_client: Option<::aws_sdk_kinesis::Client>,
pub config: Config,
}
@@ -332,6 +341,11 @@ impl AppState {
.clickhouse_url
.as_ref()
.and_then(|_| build_clickhouse_client(&config).log_err()),
kinesis_client: if config.kinesis_access_key.is_some() {
build_kinesis_client(&config).await.log_err()
} else {
None
},
config,
};
Ok(Arc::new(this))
@@ -381,6 +395,35 @@ async fn build_blob_store_client(config: &Config) -> anyhow::Result<aws_sdk_s3::
Ok(aws_sdk_s3::Client::new(&s3_config))
}
async fn build_kinesis_client(config: &Config) -> anyhow::Result<aws_sdk_kinesis::Client> {
let keys = aws_sdk_s3::config::Credentials::new(
config
.kinesis_access_key
.clone()
.ok_or_else(|| anyhow!("missing kinesis_access_key"))?,
config
.kinesis_secret_key
.clone()
.ok_or_else(|| anyhow!("missing kinesis_secret_key"))?,
None,
None,
"env",
);
let kinesis_config = aws_config::defaults(BehaviorVersion::latest())
.region(Region::new(
config
.kinesis_region
.clone()
.ok_or_else(|| anyhow!("missing blob_store_region"))?,
))
.credentials_provider(keys)
.load()
.await;
Ok(aws_sdk_kinesis::Client::new(&kinesis_config))
}
fn build_clickhouse_client(config: &Config) -> anyhow::Result<::clickhouse::Client> {
Ok(::clickhouse::Client::default()
.with_url(

View File

@@ -267,7 +267,6 @@ async fn perform_completion(
anthropic::ANTHROPIC_API_URL,
api_key,
request,
None,
)
.await
.map_err(|err| match err {
@@ -357,7 +356,6 @@ async fn perform_completion(
open_ai::OPEN_AI_API_URL,
api_key,
serde_json::from_str(params.provider_request.get())?,
None,
)
.await?;
@@ -390,7 +388,6 @@ async fn perform_completion(
google_ai::API_URL,
api_key,
serde_json::from_str(params.provider_request.get())?,
None,
)
.await?;

View File

@@ -3621,7 +3621,6 @@ async fn count_language_model_tokens(
google_ai::API_URL,
api_key,
serde_json::from_str(&request.request)?,
None,
)
.await?
}
@@ -4031,12 +4030,18 @@ async fn get_llm_api_token(
Err(anyhow!("terms of service not accepted"))?
}
let mut account_created_at = user.created_at;
if let Some(github_created_at) = user.github_user_created_at {
account_created_at = account_created_at.min(github_created_at);
}
if Utc::now().naive_utc() - account_created_at < MIN_ACCOUNT_AGE_FOR_LLM_USE {
Err(anyhow!("account too young"))?
let has_llm_subscription = session.has_llm_subscription(&db).await?;
let bypass_account_age_check =
has_llm_subscription || flags.iter().any(|flag| flag == "bypass-account-age-check");
if !bypass_account_age_check {
let mut account_created_at = user.created_at;
if let Some(github_created_at) = user.github_user_created_at {
account_created_at = account_created_at.min(github_created_at);
}
if Utc::now().naive_utc() - account_created_at < MIN_ACCOUNT_AGE_FOR_LLM_USE {
Err(anyhow!("account too young"))?
}
}
let billing_preferences = db.get_billing_preferences(user.id).await?;
@@ -4046,7 +4051,7 @@ async fn get_llm_api_token(
session.is_staff(),
billing_preferences,
has_llm_closed_beta_feature_flag,
session.has_llm_subscription(&db).await?,
has_llm_subscription,
session.current_plan(&db).await?,
&session.app_state.config,
)?;

View File

@@ -1323,11 +1323,8 @@ impl RandomizedTest for ProjectCollaborationTest {
match (host_file, guest_file) {
(Some(host_file), Some(guest_file)) => {
assert_eq!(guest_file.path(), host_file.path());
assert_eq!(guest_file.is_deleted(), host_file.is_deleted());
assert_eq!(
guest_file.mtime(),
host_file.mtime(),
"guest {} mtime does not match host {} for path {:?} in project {}",
assert_eq!(guest_file.disk_state(), host_file.disk_state(),
"guest {} disk_state does not match host {} for path {:?} in project {}",
guest_user_id,
host_user_id,
guest_file.path(),

View File

@@ -168,7 +168,7 @@ impl TestServer {
client::init_settings(cx);
});
let clock = Arc::new(FakeSystemClock::default());
let clock = Arc::new(FakeSystemClock::new());
let http = FakeHttpClient::with_404_response();
let user_id = if let Ok(Some(user)) = self.app_state.db.get_user_by_github_login(name).await
{
@@ -512,6 +512,7 @@ impl TestServer {
rate_limiter: Arc::new(RateLimiter::new(test_db.db().clone())),
executor,
clickhouse_client: None,
kinesis_client: None,
config: Config {
http_port: 0,
database_url: "".into(),
@@ -550,6 +551,10 @@ impl TestServer {
stripe_api_key: None,
supermaven_admin_api_key: None,
user_backfiller_github_access_token: None,
kinesis_region: None,
kinesis_stream: None,
kinesis_access_key: None,
kinesis_secret_key: None,
},
})
}

View File

@@ -23,7 +23,7 @@ use std::{sync::Arc, time::Duration};
use time::{OffsetDateTime, UtcOffset};
use ui::{
prelude::*, Avatar, Button, ContextMenu, IconButton, IconName, KeyBinding, Label, PopoverMenu,
TabBar, Tooltip,
Tab, TabBar, Tooltip,
};
use util::{ResultExt, TryFutureExt};
use workspace::{
@@ -939,7 +939,7 @@ impl Render for ChatPanel {
TabBar::new("chat_header").child(
h_flex()
.w_full()
.h(rems(ui::Tab::CONTAINER_HEIGHT_IN_REMS))
.h(Tab::container_height(cx))
.px_2()
.child(Label::new(
self.active_chat

View File

@@ -2521,7 +2521,7 @@ impl CollabPanel {
.flex()
.w_full()
.when(!channel.is_root_channel(), |el| {
el.on_drag(channel.clone(), move |channel, cx| {
el.on_drag(channel.clone(), move |channel, _, cx| {
cx.new_view(|_| DraggedChannelView {
channel: channel.clone(),
width,

View File

@@ -19,7 +19,9 @@ use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore};
use std::{sync::Arc, time::Duration};
use time::{OffsetDateTime, UtcOffset};
use ui::{h_flex, prelude::*, v_flex, Avatar, Button, Icon, IconButton, IconName, Label, Tooltip};
use ui::{
h_flex, prelude::*, v_flex, Avatar, Button, Icon, IconButton, IconName, Label, Tab, Tooltip,
};
use util::{ResultExt, TryFutureExt};
use workspace::notifications::NotificationId;
use workspace::{
@@ -588,7 +590,7 @@ impl Render for NotificationPanel {
.px_2()
.py_1()
// Match the height of the tab bar so they line up.
.h(rems(ui::Tab::CONTAINER_HEIGHT_IN_REMS))
.h(Tab::container_height(cx))
.border_b_1()
.border_color(cx.theme().colors().border)
.child(Label::new("Notifications"))

View File

@@ -14,7 +14,7 @@ use gpui::{
actions, AppContext, AsyncAppContext, Context, Entity, EntityId, EventEmitter, Global, Model,
ModelContext, Task, WeakModel,
};
use http_client::github::latest_github_release;
use http_client::github::get_release_by_tag_name;
use http_client::HttpClient;
use language::{
language_settings::{all_language_settings, language_settings, InlineCompletionProvider},
@@ -989,12 +989,12 @@ async fn clear_copilot_dir() {
}
async fn get_copilot_lsp(http: Arc<dyn HttpClient>) -> anyhow::Result<PathBuf> {
const SERVER_PATH: &str = "dist/agent.js";
const SERVER_PATH: &str = "dist/language-server.js";
///Check for the latest copilot language server and download it if we haven't already
async fn fetch_latest(http: Arc<dyn HttpClient>) -> anyhow::Result<PathBuf> {
let release =
latest_github_release("zed-industries/copilot", true, false, http.clone()).await?;
get_release_by_tag_name("zed-industries/copilot", "v0.7.0", http.clone()).await?;
let version_dir = &paths::copilot_dir().join(format!("copilot-{}", release.tag_name));
@@ -1229,8 +1229,10 @@ mod tests {
Some(self)
}
fn mtime(&self) -> Option<std::time::SystemTime> {
unimplemented!()
fn disk_state(&self) -> language::DiskState {
language::DiskState::Present {
mtime: std::time::UNIX_EPOCH,
}
}
fn path(&self) -> &Arc<Path> {
@@ -1245,10 +1247,6 @@ mod tests {
unimplemented!()
}
fn is_deleted(&self) -> bool {
unimplemented!()
}
fn as_any(&self) -> &dyn std::any::Any {
unimplemented!()
}

View File

@@ -1,13 +1,13 @@
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::OnceLock;
use std::{sync::Arc, time::Duration};
use anyhow::{anyhow, Result};
use chrono::DateTime;
use fs::Fs;
use futures::{io::BufReader, stream::BoxStream, AsyncBufReadExt, AsyncReadExt, StreamExt};
use gpui::{AppContext, AsyncAppContext, Global};
use http_client::{AsyncBody, HttpClient, HttpRequestExt, Method, Request as HttpRequest};
use http_client::{AsyncBody, HttpClient, Method, Request as HttpRequest};
use paths::home_dir;
use serde::{Deserialize, Serialize};
use settings::watch_config_file;
@@ -254,7 +254,6 @@ impl CopilotChat {
pub async fn stream_completion(
request: Request,
low_speed_timeout: Option<Duration>,
mut cx: AsyncAppContext,
) -> Result<BoxStream<'static, Result<ResponseEvent>>> {
let Some(this) = cx.update(|cx| Self::global(cx)).ok().flatten() else {
@@ -274,8 +273,7 @@ impl CopilotChat {
let token = match api_token {
Some(api_token) if api_token.remaining_seconds() > 5 * 60 => api_token.clone(),
_ => {
let token =
request_api_token(&oauth_token, client.clone(), low_speed_timeout).await?;
let token = request_api_token(&oauth_token, client.clone()).await?;
this.update(&mut cx, |this, cx| {
this.api_token = Some(token.clone());
cx.notify();
@@ -284,25 +282,17 @@ impl CopilotChat {
}
};
stream_completion(client.clone(), token.api_key, request, low_speed_timeout).await
stream_completion(client.clone(), token.api_key, request).await
}
}
async fn request_api_token(
oauth_token: &str,
client: Arc<dyn HttpClient>,
low_speed_timeout: Option<Duration>,
) -> Result<ApiToken> {
let mut request_builder = HttpRequest::builder()
async fn request_api_token(oauth_token: &str, client: Arc<dyn HttpClient>) -> Result<ApiToken> {
let request_builder = HttpRequest::builder()
.method(Method::GET)
.uri(COPILOT_CHAT_AUTH_URL)
.header("Authorization", format!("token {}", oauth_token))
.header("Accept", "application/json");
if let Some(low_speed_timeout) = low_speed_timeout {
request_builder = request_builder.read_timeout(low_speed_timeout);
}
let request = request_builder.body(AsyncBody::empty())?;
let mut response = client.send(request).await?;
@@ -340,9 +330,8 @@ async fn stream_completion(
client: Arc<dyn HttpClient>,
api_key: String,
request: Request,
low_speed_timeout: Option<Duration>,
) -> Result<BoxStream<'static, Result<ResponseEvent>>> {
let mut request_builder = HttpRequest::builder()
let request_builder = HttpRequest::builder()
.method(Method::POST)
.uri(COPILOT_CHAT_COMPLETION_URL)
.header(
@@ -356,9 +345,6 @@ async fn stream_completion(
.header("Content-Type", "application/json")
.header("Copilot-Integration-Id", "vscode-chat");
if let Some(low_speed_timeout) = low_speed_timeout {
request_builder = request_builder.read_timeout(low_speed_timeout);
}
let is_streaming = request.stream;
let request = request_builder.body(AsyncBody::from(serde_json::to_string(&request)?))?;

View File

@@ -32,6 +32,7 @@ use std::{
cmp::Ordering,
mem,
ops::Range,
sync::Arc,
};
use theme::ActiveTheme;
pub use toolbar_controls::ToolbarControls;
@@ -726,6 +727,10 @@ impl Item for ProjectDiagnosticsEditor {
self.excerpts.read(cx).is_dirty(cx)
}
fn has_deleted_file(&self, cx: &AppContext) -> bool {
self.excerpts.read(cx).has_deleted_file(cx)
}
fn has_conflict(&self, cx: &AppContext) -> bool {
self.excerpts.read(cx).has_conflict(cx)
}
@@ -790,10 +795,11 @@ const DIAGNOSTIC_HEADER: &str = "diagnostic header";
fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
let (message, code_ranges) = highlight_diagnostic_message(&diagnostic, None);
let message: SharedString = message;
Box::new(move |cx| {
Arc::new(move |cx| {
let highlight_style: HighlightStyle = cx.theme().colors().text_accent.into();
h_flex()
.id(DIAGNOSTIC_HEADER)
.block_mouse_down()
.h(2. * cx.line_height())
.pl_10()
.pr_5()

View File

@@ -297,6 +297,7 @@ gpui::actions!(
OpenExcerptsSplit,
OpenProposedChangesEditor,
OpenFile,
OpenDocs,
OpenPermalinkToLine,
OpenUrl,
Outdent,

View File

@@ -1,5 +1,3 @@
use std::path::PathBuf;
use anyhow::Context as _;
use gpui::{View, ViewContext, WindowContext};
use language::Language;
@@ -54,9 +52,9 @@ pub fn switch_source_header(
cx.spawn(|_editor, mut cx| async move {
let switch_source_header = switch_source_header_task
.await
.with_context(|| format!("Switch source/header LSP request for path \"{}\" failed", source_file))?;
.with_context(|| format!("Switch source/header LSP request for path \"{source_file}\" failed"))?;
if switch_source_header.0.is_empty() {
log::info!("Clangd returned an empty string when requesting to switch source/header from \"{}\"", source_file);
log::info!("Clangd returned an empty string when requesting to switch source/header from \"{source_file}\"" );
return Ok(());
}
@@ -67,14 +65,17 @@ pub fn switch_source_header(
)
})?;
let path = goto.to_file_path().map_err(|()| {
anyhow::anyhow!("URL conversion to file path failed for \"{goto}\"")
})?;
workspace
.update(&mut cx, |workspace, view_cx| {
workspace.open_abs_path(PathBuf::from(goto.path()), false, view_cx)
workspace.open_abs_path(path, false, view_cx)
})
.with_context(|| {
format!(
"Switch source/header could not open \"{}\" in workspace",
goto.path()
"Switch source/header could not open \"{goto}\" in workspace"
)
})?
.await

View File

@@ -5,6 +5,7 @@ use gpui::{Task, ViewContext};
use crate::Editor;
#[derive(Debug)]
pub struct DebouncedDelay {
task: Option<Task<()>>,
cancel_channel: Option<oneshot::Sender<()>>,

View File

@@ -36,7 +36,7 @@ use block_map::{BlockRow, BlockSnapshot};
use collections::{HashMap, HashSet};
pub use crease_map::*;
pub use fold_map::{Fold, FoldId, FoldPlaceholder, FoldPoint};
use fold_map::{FoldMap, FoldMapWriter, FoldOffset, FoldSnapshot};
use fold_map::{FoldMap, FoldSnapshot};
use gpui::{
AnyElement, Font, HighlightStyle, LineLayout, Model, ModelContext, Pixels, UnderlineStyle,
};
@@ -65,8 +65,8 @@ use std::{
};
use sum_tree::{Bias, TreeMap};
use tab_map::{TabMap, TabSnapshot};
use text::{Edit, LineIndent};
use ui::{div, px, IntoElement, ParentElement, SharedString, Styled, WindowContext};
use text::LineIndent;
use ui::{px, SharedString, WindowContext};
use unicode_segmentation::UnicodeSegmentation;
use wrap_map::{WrapMap, WrapSnapshot};
@@ -197,22 +197,86 @@ impl DisplayMap {
other
.folds_in_range(0..other.buffer_snapshot.len())
.map(|fold| {
(
Crease::simple(
fold.range.to_offset(&other.buffer_snapshot),
fold.placeholder.clone(),
)
}),
})
.collect(),
cx,
);
}
/// Creates folds for the given ranges.
pub fn fold<T: ToOffset>(
/// Creates folds for the given creases.
pub fn fold<T: Clone + ToOffset>(
&mut self,
ranges: impl IntoIterator<Item = (Range<T>, FoldPlaceholder)>,
creases: Vec<Crease<T>>,
cx: &mut ModelContext<Self>,
) {
self.update_fold_map(cx, |fold_map| fold_map.fold(ranges))
let buffer_snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.inlay_map.sync(buffer_snapshot.clone(), edits);
let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
let inline = creases.iter().filter_map(|crease| {
if let Crease::Inline {
range, placeholder, ..
} = crease
{
Some((range.clone(), placeholder.clone()))
} else {
None
}
});
let (snapshot, edits) = fold_map.fold(inline);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
let mut block_map = self.block_map.write(snapshot, edits);
let blocks = creases.into_iter().filter_map(|crease| {
if let Crease::Block {
range,
block_height,
render_block,
block_style,
block_priority,
..
} = crease
{
Some((
range,
render_block,
block_height,
block_style,
block_priority,
))
} else {
None
}
});
block_map.insert(
blocks
.into_iter()
.map(|(range, render, height, style, priority)| {
let start = buffer_snapshot.anchor_before(range.start);
let end = buffer_snapshot.anchor_after(range.end);
BlockProperties {
placement: BlockPlacement::Replace(start..end),
render,
height,
style,
priority,
}
}),
);
}
/// Removes any folds with the given ranges.
@@ -221,26 +285,6 @@ impl DisplayMap {
ranges: impl IntoIterator<Item = Range<T>>,
type_id: TypeId,
cx: &mut ModelContext<Self>,
) {
self.update_fold_map(cx, |fold_map| fold_map.remove_folds(ranges, type_id))
}
/// Removes any folds whose ranges intersect any of the given ranges.
pub fn unfold_intersecting<T: ToOffset>(
&mut self,
ranges: impl IntoIterator<Item = Range<T>>,
inclusive: bool,
cx: &mut ModelContext<Self>,
) {
self.update_fold_map(cx, |fold_map| {
fold_map.unfold_intersecting(ranges, inclusive)
})
}
fn update_fold_map(
&mut self,
cx: &mut ModelContext<Self>,
callback: impl FnOnce(&mut FoldMapWriter) -> (FoldSnapshot, Vec<Edit<FoldOffset>>),
) {
let snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
@@ -252,17 +296,49 @@ impl DisplayMap {
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
let (snapshot, edits) = callback(&mut fold_map);
let (snapshot, edits) = fold_map.remove_folds(ranges, type_id);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.write(snapshot, edits);
}
/// Removes any folds whose ranges intersect any of the given ranges.
pub fn unfold_intersecting<T: ToOffset>(
&mut self,
ranges: impl IntoIterator<Item = Range<T>>,
inclusive: bool,
cx: &mut ModelContext<Self>,
) {
let snapshot = self.buffer.read(cx).snapshot(cx);
let offset_ranges = ranges
.into_iter()
.map(|range| range.start.to_offset(&snapshot)..range.end.to_offset(&snapshot))
.collect::<Vec<_>>();
let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
let (snapshot, edits) =
fold_map.unfold_intersecting(offset_ranges.iter().cloned(), inclusive);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
let mut block_map = self.block_map.write(snapshot, edits);
block_map.remove_intersecting_replace_blocks(offset_ranges, inclusive);
}
pub fn insert_creases(
&mut self,
creases: impl IntoIterator<Item = Crease>,
creases: impl IntoIterator<Item = Crease<Anchor>>,
cx: &mut ModelContext<Self>,
) -> Vec<CreaseId> {
let snapshot = self.buffer.read(cx).snapshot(cx);
@@ -465,11 +541,17 @@ pub struct HighlightStyles {
pub suggestion: Option<HighlightStyle>,
}
#[derive(Clone)]
pub enum ChunkReplacement {
Renderer(ChunkRenderer),
Str(SharedString),
}
pub struct HighlightedChunk<'a> {
pub text: &'a str,
pub style: Option<HighlightStyle>,
pub is_tab: bool,
pub renderer: Option<ChunkRenderer>,
pub replacement: Option<ChunkReplacement>,
}
impl<'a> HighlightedChunk<'a> {
@@ -481,7 +563,7 @@ impl<'a> HighlightedChunk<'a> {
let mut text = self.text;
let style = self.style;
let is_tab = self.is_tab;
let renderer = self.renderer;
let renderer = self.replacement;
iter::from_fn(move || {
let mut prefix_len = 0;
while let Some(&ch) = chars.peek() {
@@ -497,30 +579,33 @@ impl<'a> HighlightedChunk<'a> {
text: prefix,
style,
is_tab,
renderer: renderer.clone(),
replacement: renderer.clone(),
});
}
chars.next();
let (prefix, suffix) = text.split_at(ch.len_utf8());
text = suffix;
if let Some(replacement) = replacement(ch) {
let background = editor_style.status.hint_background;
let underline = editor_style.status.hint;
let invisible_highlight = HighlightStyle {
background_color: Some(editor_style.status.hint_background),
underline: Some(UnderlineStyle {
color: Some(editor_style.status.hint),
thickness: px(1.),
wavy: false,
}),
..Default::default()
};
let invisible_style = if let Some(mut style) = style {
style.highlight(invisible_highlight);
style
} else {
invisible_highlight
};
return Some(HighlightedChunk {
text: prefix,
style: None,
style: Some(invisible_style),
is_tab: false,
renderer: Some(ChunkRenderer {
render: Arc::new(move |_| {
div()
.child(replacement)
.bg(background)
.text_decoration_1()
.text_decoration_color(underline)
.into_any_element()
}),
constrain_width: false,
}),
replacement: Some(ChunkReplacement::Str(replacement.into())),
});
} else {
let invisible_highlight = HighlightStyle {
@@ -543,7 +628,7 @@ impl<'a> HighlightedChunk<'a> {
text: prefix,
style: Some(invisible_style),
is_tab: false,
renderer: renderer.clone(),
replacement: renderer.clone(),
});
}
}
@@ -555,7 +640,7 @@ impl<'a> HighlightedChunk<'a> {
text: remainder,
style,
is_tab,
renderer: renderer.clone(),
replacement: renderer.clone(),
})
} else {
None
@@ -596,7 +681,7 @@ impl DisplaySnapshot {
) -> impl Iterator<Item = Option<MultiBufferRow>> + '_ {
self.block_snapshot
.buffer_rows(BlockRow(start_row.0))
.map(|row| row.map(|row| MultiBufferRow(row.0)))
.map(|row| row.map(MultiBufferRow))
}
pub fn max_buffer_row(&self) -> MultiBufferRow {
@@ -819,7 +904,7 @@ impl DisplaySnapshot {
text: chunk.text,
style: highlight_style,
is_tab: chunk.is_tab,
renderer: chunk.renderer,
replacement: chunk.renderer.map(ChunkReplacement::Renderer),
}
.highlight_invisibles(editor_style)
})
@@ -987,7 +1072,12 @@ impl DisplaySnapshot {
}
pub fn is_line_folded(&self, buffer_row: MultiBufferRow) -> bool {
self.fold_snapshot.is_line_folded(buffer_row)
self.block_snapshot.is_line_replaced(buffer_row)
|| self.fold_snapshot.is_line_folded(buffer_row)
}
pub fn is_line_replaced(&self, buffer_row: MultiBufferRow) -> bool {
self.block_snapshot.is_line_replaced(buffer_row)
}
pub fn is_block_line(&self, display_row: DisplayRow) -> bool {
@@ -1061,19 +1151,42 @@ impl DisplaySnapshot {
.unwrap_or(false)
}
pub fn foldable_range(
&self,
buffer_row: MultiBufferRow,
) -> Option<(Range<Point>, FoldPlaceholder)> {
pub fn crease_for_buffer_row(&self, buffer_row: MultiBufferRow) -> Option<Crease<Point>> {
let start = MultiBufferPoint::new(buffer_row.0, self.buffer_snapshot.line_len(buffer_row));
if let Some(crease) = self
.crease_snapshot
.query_row(buffer_row, &self.buffer_snapshot)
{
Some((
crease.range.to_point(&self.buffer_snapshot),
crease.placeholder.clone(),
))
match crease {
Crease::Inline {
range,
placeholder,
render_toggle,
render_trailer,
metadata,
} => Some(Crease::Inline {
range: range.to_point(&self.buffer_snapshot),
placeholder: placeholder.clone(),
render_toggle: render_toggle.clone(),
render_trailer: render_trailer.clone(),
metadata: metadata.clone(),
}),
Crease::Block {
range,
block_height,
block_style,
render_block,
block_priority,
render_toggle,
} => Some(Crease::Block {
range: range.to_point(&self.buffer_snapshot),
block_height: *block_height,
block_style: *block_style,
render_block: render_block.clone(),
block_priority: *block_priority,
render_toggle: render_toggle.clone(),
}),
}
} else if self.starts_indent(MultiBufferRow(start.row))
&& !self.is_line_folded(MultiBufferRow(start.row))
{
@@ -1110,7 +1223,13 @@ impl DisplaySnapshot {
.line_len(MultiBufferRow(row_before_line_breaks.row)),
);
Some((start..row_before_line_breaks, self.fold_placeholder.clone()))
Some(Crease::Inline {
range: start..row_before_line_breaks,
placeholder: self.fold_placeholder.clone(),
render_toggle: None,
render_trailer: None,
metadata: None,
})
} else {
None
}
@@ -1418,7 +1537,7 @@ pub mod tests {
placement,
style: BlockStyle::Fixed,
height,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority,
}
})
@@ -1457,7 +1576,8 @@ pub mod tests {
map.fold(
ranges
.into_iter()
.map(|range| (range, FoldPlaceholder::test())),
.map(|range| Crease::simple(range, FoldPlaceholder::test()))
.collect(),
cx,
);
});
@@ -1832,7 +1952,7 @@ pub mod tests {
map.update(cx, |map, cx| {
map.fold(
vec![(
vec![Crease::simple(
MultiBufferPoint::new(0, 6)..MultiBufferPoint::new(3, 2),
FoldPlaceholder::test(),
)],
@@ -1922,7 +2042,7 @@ pub mod tests {
),
height: 1,
style: BlockStyle::Sticky,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}],
cx,
@@ -2028,7 +2148,7 @@ pub mod tests {
),
height: 1,
style: BlockStyle::Sticky,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}],
cx,
@@ -2104,7 +2224,7 @@ pub mod tests {
),
height: 4,
style: BlockStyle::Fixed,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}],
cx,
@@ -2253,7 +2373,7 @@ pub mod tests {
map.update(cx, |map, cx| {
map.fold(
vec![(
vec![Crease::simple(
MultiBufferPoint::new(0, 6)..MultiBufferPoint::new(3, 2),
FoldPlaceholder::test(),
)],
@@ -2452,7 +2572,7 @@ pub mod tests {
snapshot.anchor_before(Point::new(2, 0))..snapshot.anchor_after(Point::new(3, 3));
map.crease_map.insert(
[Crease::new(
[Crease::inline(
range,
FoldPlaceholder::test(),
|_row, _status, _toggle, _cx| div(),

View File

@@ -7,7 +7,7 @@ use collections::{Bound, HashMap, HashSet};
use gpui::{AnyElement, EntityId, Pixels, WindowContext};
use language::{Chunk, Patch, Point};
use multi_buffer::{
Anchor, ExcerptId, ExcerptInfo, MultiBufferRow, MultiBufferSnapshot, ToPoint as _,
Anchor, ExcerptId, ExcerptInfo, MultiBufferRow, MultiBufferSnapshot, ToOffset, ToPoint as _,
};
use parking_lot::Mutex;
use std::{
@@ -77,7 +77,7 @@ pub struct BlockRow(pub(super) u32);
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
struct WrapRow(u32);
pub type RenderBlock = Box<dyn Send + FnMut(&mut BlockContext) -> AnyElement>;
pub type RenderBlock = Arc<dyn Send + Sync + Fn(&mut BlockContext) -> AnyElement>;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum BlockPlacement<T> {
@@ -352,6 +352,13 @@ impl Block {
Block::ExcerptBoundary { next_excerpt, .. } => next_excerpt.is_none(),
}
}
fn is_replacement(&self) -> bool {
match self {
Block::Custom(block) => matches!(block.placement, BlockPlacement::Replace(_)),
Block::ExcerptBoundary { .. } => false,
}
}
}
impl Debug for Block {
@@ -1119,6 +1126,64 @@ impl<'a> BlockMapWriter<'a> {
.retain(|id, _| !block_ids.contains(id));
self.0.sync(wrap_snapshot, edits);
}
pub fn remove_intersecting_replace_blocks<T>(
&mut self,
ranges: impl IntoIterator<Item = Range<T>>,
inclusive: bool,
) where
T: ToOffset,
{
let wrap_snapshot = self.0.wrap_snapshot.borrow();
let mut blocks_to_remove = HashSet::default();
for range in ranges {
let range = range.start.to_offset(wrap_snapshot.buffer_snapshot())
..range.end.to_offset(wrap_snapshot.buffer_snapshot());
for block in self.blocks_intersecting_buffer_range(range, inclusive) {
if matches!(block.placement, BlockPlacement::Replace(_)) {
blocks_to_remove.insert(block.id);
}
}
}
drop(wrap_snapshot);
self.remove(blocks_to_remove);
}
fn blocks_intersecting_buffer_range(
&self,
range: Range<usize>,
inclusive: bool,
) -> &[Arc<CustomBlock>] {
let wrap_snapshot = self.0.wrap_snapshot.borrow();
let buffer = wrap_snapshot.buffer_snapshot();
let start_block_ix = match self.0.custom_blocks.binary_search_by(|probe| {
probe
.end()
.to_offset(buffer)
.cmp(&range.start)
.then(if inclusive {
Ordering::Greater
} else {
Ordering::Less
})
}) {
Ok(ix) | Err(ix) => ix,
};
let end_block_ix = match self.0.custom_blocks.binary_search_by(|probe| {
probe
.start()
.to_offset(buffer)
.cmp(&range.end)
.then(if inclusive {
Ordering::Less
} else {
Ordering::Greater
})
}) {
Ok(ix) | Err(ix) => ix,
};
&self.0.custom_blocks[start_block_ix..end_block_ix]
}
}
impl BlockSnapshot {
@@ -1298,6 +1363,21 @@ impl BlockSnapshot {
cursor.item().map_or(false, |t| t.block.is_some())
}
pub(super) fn is_line_replaced(&self, row: MultiBufferRow) -> bool {
let wrap_point = self
.wrap_snapshot
.make_wrap_point(Point::new(row.0, 0), Bias::Left);
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>(&());
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right, &());
cursor.item().map_or(false, |transform| {
if let Some(Block::Custom(block)) = transform.block.as_ref() {
matches!(block.placement, BlockPlacement::Replace(_))
} else {
false
}
})
}
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
cursor.seek(&BlockRow(point.row), Bias::Right, &());
@@ -1515,7 +1595,7 @@ impl<'a> Iterator for BlockChunks<'a> {
}
impl<'a> Iterator for BlockBufferRows<'a> {
type Item = Option<BlockRow>;
type Item = Option<u32>;
fn next(&mut self) -> Option<Self::Item> {
if self.started {
@@ -1538,16 +1618,25 @@ impl<'a> Iterator for BlockBufferRows<'a> {
}
}
if self.transforms.item()?.block.is_none() {
let transform = self.transforms.item()?;
if transform
.block
.as_ref()
.map_or(true, |block| block.is_replacement())
{
self.input_buffer_rows.seek(self.transforms.start().1 .0);
}
}
let transform = self.transforms.item()?;
if transform.block.is_some() {
Some(None)
if let Some(block) = transform.block.as_ref() {
if block.is_replacement() && self.transforms.start().0 == self.output_row {
Some(self.input_buffer_rows.next().unwrap())
} else {
Some(None)
}
} else {
Some(self.input_buffer_rows.next().unwrap().map(BlockRow))
Some(self.input_buffer_rows.next().unwrap())
}
}
}
@@ -1709,21 +1798,21 @@ mod tests {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(1, 0))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(1, 2))),
height: 2,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Below(buffer_snapshot.anchor_after(Point::new(3, 3))),
height: 3,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
]);
@@ -1821,10 +1910,7 @@ mod tests {
);
assert_eq!(
snapshot
.buffer_rows(BlockRow(0))
.map(|row| row.map(|r| r.0))
.collect::<Vec<_>>(),
snapshot.buffer_rows(BlockRow(0)).collect::<Vec<_>>(),
&[
Some(0),
None,
@@ -1960,21 +2046,21 @@ mod tests {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(1, 0))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(1, 2))),
height: 2,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Below(buffer_snapshot.anchor_after(Point::new(3, 3))),
height: 3,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
]);
@@ -2062,14 +2148,14 @@ mod tests {
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(1, 12))),
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
height: 1,
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Below(buffer_snapshot.anchor_after(Point::new(1, 1))),
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
height: 1,
priority: 0,
},
@@ -2109,7 +2195,7 @@ mod tests {
..buffer_snapshot.anchor_before(Point::new(3, 1)),
),
height: 4,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}]);
@@ -2162,14 +2248,14 @@ mod tests {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(1, 3))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Below(buffer_snapshot.anchor_after(Point::new(6, 2))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
]);
@@ -2183,21 +2269,21 @@ mod tests {
style: BlockStyle::Fixed,
placement: BlockPlacement::Below(buffer_snapshot.anchor_after(Point::new(1, 3))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(2, 1))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
BlockProperties {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(buffer_snapshot.anchor_after(Point::new(6, 1))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
},
]);
@@ -2302,7 +2388,7 @@ mod tests {
style: BlockStyle::Fixed,
placement,
height,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}
})
@@ -2321,7 +2407,7 @@ mod tests {
placement: props.placement.clone(),
height: props.height,
style: props.style,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}));
}
@@ -2409,6 +2495,7 @@ mod tests {
let mut expected_buffer_rows = Vec::new();
let mut expected_text = String::new();
let mut expected_block_positions = Vec::new();
let mut expected_replaced_buffer_rows = HashSet::default();
let input_text = wraps_snapshot.text();
// Loop over the input lines, creating (N - 1) empty lines for
@@ -2422,6 +2509,9 @@ mod tests {
let mut block_row = 0;
while let Some((wrap_row, input_line)) = input_text_lines.next() {
let wrap_row = wrap_row as u32;
let multibuffer_row = wraps_snapshot
.to_point(WrapPoint::new(wrap_row, 0), Bias::Left)
.row;
// Create empty lines for the above block
while let Some((placement, block)) = sorted_blocks_iter.peek() {
@@ -2451,30 +2541,33 @@ mod tests {
{
if wrap_row >= replace_range.start.0 {
is_in_replace_block = true;
if wrap_row == replace_range.start.0 {
expected_buffer_rows.push(input_buffer_rows[multibuffer_row as usize]);
}
if wrap_row == replace_range.end.0 {
expected_block_positions.push((block_row, block.id()));
if block.height() > 0 {
let text = "\n".repeat((block.height() - 1) as usize);
if block_row > 0 {
expected_text.push('\n');
}
expected_text.push_str(&text);
for _ in 0..block.height() {
expected_buffer_rows.push(None);
}
block_row += block.height();
let text = "\n".repeat((block.height() - 1) as usize);
if block_row > 0 {
expected_text.push('\n');
}
expected_text.push_str(&text);
for _ in 1..block.height() {
expected_buffer_rows.push(None);
}
block_row += block.height();
sorted_blocks_iter.next();
}
}
}
if !is_in_replace_block {
let buffer_row = input_buffer_rows[wraps_snapshot
.to_point(WrapPoint::new(wrap_row, 0), Bias::Left)
.row as usize];
if is_in_replace_block {
expected_replaced_buffer_rows.insert(MultiBufferRow(multibuffer_row));
} else {
let buffer_row = input_buffer_rows[multibuffer_row as usize];
let soft_wrapped = wraps_snapshot
.to_tab_point(WrapPoint::new(wrap_row, 0))
.column()
@@ -2543,9 +2636,10 @@ mod tests {
assert_eq!(
blocks_snapshot
.buffer_rows(BlockRow(start_row as u32))
.map(|row| row.map(|r| r.0))
.collect::<Vec<_>>(),
&expected_buffer_rows[start_row..]
&expected_buffer_rows[start_row..],
"incorrect buffer_rows starting at row {:?}",
start_row
);
}
@@ -2666,6 +2760,16 @@ mod tests {
block_point.column += c.len_utf8() as u32;
}
}
for buffer_row in 0..=buffer_snapshot.max_point().row {
let buffer_row = MultiBufferRow(buffer_row);
assert_eq!(
blocks_snapshot.is_line_replaced(buffer_row),
expected_replaced_buffer_rows.contains(&buffer_row),
"incorrect is_line_replaced({:?})",
buffer_row
);
}
}
}

View File

@@ -2,12 +2,12 @@ use collections::HashMap;
use gpui::{AnyElement, IntoElement};
use multi_buffer::{Anchor, AnchorRangeExt, MultiBufferRow, MultiBufferSnapshot, ToPoint};
use serde::{Deserialize, Serialize};
use std::{cmp::Ordering, ops::Range, sync::Arc};
use std::{cmp::Ordering, fmt::Debug, ops::Range, sync::Arc};
use sum_tree::{Bias, SeekTarget, SumTree};
use text::Point;
use ui::{IconName, SharedString, WindowContext};
use crate::FoldPlaceholder;
use crate::{BlockStyle, FoldPlaceholder, RenderBlock};
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct CreaseId(usize);
@@ -45,15 +45,15 @@ impl CreaseSnapshot {
&'a self,
row: MultiBufferRow,
snapshot: &'a MultiBufferSnapshot,
) -> Option<&'a Crease> {
) -> Option<&'a Crease<Anchor>> {
let start = snapshot.anchor_before(Point::new(row.0, 0));
let mut cursor = self.creases.cursor::<ItemSummary>(snapshot);
cursor.seek(&start, Bias::Left, snapshot);
while let Some(item) = cursor.item() {
match Ord::cmp(&item.crease.range.start.to_point(snapshot).row, &row.0) {
match Ord::cmp(&item.crease.range().start.to_point(snapshot).row, &row.0) {
Ordering::Less => cursor.next(snapshot),
Ordering::Equal => {
if item.crease.range.start.is_valid(snapshot) {
if item.crease.range().start.is_valid(snapshot) {
return Some(&item.crease);
} else {
cursor.next(snapshot);
@@ -69,7 +69,7 @@ impl CreaseSnapshot {
&'a self,
range: Range<MultiBufferRow>,
snapshot: &'a MultiBufferSnapshot,
) -> impl 'a + Iterator<Item = &'a Crease> {
) -> impl 'a + Iterator<Item = &'a Crease<Anchor>> {
let start = snapshot.anchor_before(Point::new(range.start.0, 0));
let mut cursor = self.creases.cursor::<ItemSummary>(snapshot);
cursor.seek(&start, Bias::Left, snapshot);
@@ -77,8 +77,9 @@ impl CreaseSnapshot {
std::iter::from_fn(move || {
while let Some(item) = cursor.item() {
cursor.next(snapshot);
let crease_start = item.crease.range.start.to_point(snapshot);
let crease_end = item.crease.range.end.to_point(snapshot);
let crease_range = item.crease.range();
let crease_start = crease_range.start.to_point(snapshot);
let crease_end = crease_range.end.to_point(snapshot);
if crease_end.row > range.end.0 {
continue;
}
@@ -99,8 +100,9 @@ impl CreaseSnapshot {
cursor.next(snapshot);
while let Some(item) = cursor.item() {
let start_point = item.crease.range.start.to_point(snapshot);
let end_point = item.crease.range.end.to_point(snapshot);
let crease_range = item.crease.range();
let start_point = crease_range.start.to_point(snapshot);
let end_point = crease_range.end.to_point(snapshot);
results.push((item.id, start_point..end_point));
cursor.next(snapshot);
}
@@ -123,12 +125,22 @@ type RenderTrailerFn =
Arc<dyn Send + Sync + Fn(MultiBufferRow, bool, &mut WindowContext) -> AnyElement>;
#[derive(Clone)]
pub struct Crease {
pub range: Range<Anchor>,
pub placeholder: FoldPlaceholder,
pub render_toggle: RenderToggleFn,
pub render_trailer: RenderTrailerFn,
pub metadata: Option<CreaseMetadata>,
pub enum Crease<T> {
Inline {
range: Range<T>,
placeholder: FoldPlaceholder,
render_toggle: Option<RenderToggleFn>,
render_trailer: Option<RenderTrailerFn>,
metadata: Option<CreaseMetadata>,
},
Block {
range: Range<T>,
block_height: u32,
block_style: BlockStyle,
render_block: RenderBlock,
block_priority: usize,
render_toggle: Option<RenderToggleFn>,
},
}
/// Metadata about a [`Crease`], that is used for serialization.
@@ -138,9 +150,30 @@ pub struct CreaseMetadata {
pub label: SharedString,
}
impl Crease {
pub fn new<RenderToggle, ToggleElement, RenderTrailer, TrailerElement>(
range: Range<Anchor>,
impl<T> Crease<T> {
pub fn simple(range: Range<T>, placeholder: FoldPlaceholder) -> Self {
Crease::Inline {
range,
placeholder,
render_toggle: None,
render_trailer: None,
metadata: None,
}
}
pub fn block(range: Range<T>, height: u32, style: BlockStyle, render: RenderBlock) -> Self {
Self::Block {
range,
block_height: height,
block_style: style,
render_block: render,
block_priority: 0,
render_toggle: None,
}
}
pub fn inline<RenderToggle, ToggleElement, RenderTrailer, TrailerElement>(
range: Range<T>,
placeholder: FoldPlaceholder,
render_toggle: RenderToggle,
render_trailer: RenderTrailer,
@@ -164,37 +197,76 @@ impl Crease {
+ 'static,
TrailerElement: IntoElement,
{
Crease {
Crease::Inline {
range,
placeholder,
render_toggle: Arc::new(move |row, folded, toggle, cx| {
render_toggle: Some(Arc::new(move |row, folded, toggle, cx| {
render_toggle(row, folded, toggle, cx).into_any_element()
}),
render_trailer: Arc::new(move |row, folded, cx| {
})),
render_trailer: Some(Arc::new(move |row, folded, cx| {
render_trailer(row, folded, cx).into_any_element()
}),
})),
metadata: None,
}
}
pub fn with_metadata(mut self, metadata: CreaseMetadata) -> Self {
self.metadata = Some(metadata);
self
pub fn with_metadata(self, metadata: CreaseMetadata) -> Self {
match self {
Crease::Inline {
range,
placeholder,
render_toggle,
render_trailer,
..
} => Crease::Inline {
range,
placeholder,
render_toggle,
render_trailer,
metadata: Some(metadata),
},
Crease::Block { .. } => self,
}
}
pub fn range(&self) -> &Range<T> {
match self {
Crease::Inline { range, .. } => range,
Crease::Block { range, .. } => range,
}
}
}
impl std::fmt::Debug for Crease {
impl<T> std::fmt::Debug for Crease<T>
where
T: Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Crease")
.field("range", &self.range)
.finish()
match self {
Crease::Inline {
range, metadata, ..
} => f
.debug_struct("Crease::Inline")
.field("range", range)
.field("metadata", metadata)
.finish_non_exhaustive(),
Crease::Block {
range,
block_height,
..
} => f
.debug_struct("Crease::Block")
.field("range", range)
.field("height", block_height)
.finish_non_exhaustive(),
}
}
}
#[derive(Clone, Debug)]
struct CreaseItem {
id: CreaseId,
crease: Crease,
crease: Crease<Anchor>,
}
impl CreaseMap {
@@ -204,7 +276,7 @@ impl CreaseMap {
pub fn insert(
&mut self,
creases: impl IntoIterator<Item = Crease>,
creases: impl IntoIterator<Item = Crease<Anchor>>,
snapshot: &MultiBufferSnapshot,
) -> Vec<CreaseId> {
let mut new_ids = Vec::new();
@@ -212,11 +284,12 @@ impl CreaseMap {
let mut new_creases = SumTree::new(snapshot);
let mut cursor = self.snapshot.creases.cursor::<ItemSummary>(snapshot);
for crease in creases {
new_creases.append(cursor.slice(&crease.range, Bias::Left, snapshot), snapshot);
let crease_range = crease.range().clone();
new_creases.append(cursor.slice(&crease_range, Bias::Left, snapshot), snapshot);
let id = self.next_id;
self.next_id.0 += 1;
self.id_to_range.insert(id, crease.range.clone());
self.id_to_range.insert(id, crease_range);
new_creases.push(CreaseItem { crease, id }, snapshot);
new_ids.push(id);
}
@@ -293,7 +366,7 @@ impl sum_tree::Item for CreaseItem {
fn summary(&self, _cx: &MultiBufferSnapshot) -> Self::Summary {
ItemSummary {
range: self.crease.range.clone(),
range: self.crease.range().clone(),
}
}
}
@@ -326,13 +399,13 @@ mod test {
// Insert creases
let creases = [
Crease::new(
Crease::inline(
snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(1, 5)),
FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(),
|_row, _folded, _cx| div(),
),
Crease::new(
Crease::inline(
snapshot.anchor_before(Point::new(3, 0))..snapshot.anchor_after(Point::new(3, 5)),
FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(),
@@ -372,19 +445,19 @@ mod test {
let mut crease_map = CreaseMap::new(&snapshot);
let creases = [
Crease::new(
Crease::inline(
snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(1, 5)),
FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(),
|_row, _folded, _cx| div(),
),
Crease::new(
Crease::inline(
snapshot.anchor_before(Point::new(3, 0))..snapshot.anchor_after(Point::new(3, 5)),
FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(),
|_row, _folded, _cx| div(),
),
Crease::new(
Crease::inline(
snapshot.anchor_before(Point::new(5, 0))..snapshot.anchor_after(Point::new(5, 5)),
FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(),
@@ -402,12 +475,12 @@ mod test {
let range = MultiBufferRow(2)..MultiBufferRow(5);
let creases: Vec<_> = crease_snapshot.creases_in_range(range, &snapshot).collect();
assert_eq!(creases.len(), 1);
assert_eq!(creases[0].range.start.to_point(&snapshot).row, 3);
assert_eq!(creases[0].range().start.to_point(&snapshot).row, 3);
let range = MultiBufferRow(0)..MultiBufferRow(2);
let creases: Vec<_> = crease_snapshot.creases_in_range(range, &snapshot).collect();
assert_eq!(creases.len(), 1);
assert_eq!(creases[0].range.start.to_point(&snapshot).row, 1);
assert_eq!(creases[0].range().start.to_point(&snapshot).row, 1);
let range = MultiBufferRow(6)..MultiBufferRow(7);
let creases: Vec<_> = crease_snapshot.creases_in_range(range, &snapshot).collect();

View File

@@ -540,6 +540,15 @@ pub enum IsVimMode {
No,
}
pub trait ActiveLineTrailerProvider {
fn render_active_line_trailer(
&mut self,
style: &EditorStyle,
focus_handle: &FocusHandle,
cx: &mut WindowContext,
) -> Option<AnyElement>;
}
/// Zed's primary text input `View`, allowing users to edit a [`MultiBuffer`]
///
/// See the [module level documentation](self) for more information.
@@ -667,6 +676,7 @@ pub struct Editor {
next_scroll_position: NextScrollCursorCenterTopBottom,
addons: HashMap<TypeId, Box<dyn Addon>>,
_scroll_cursor_center_top_bottom_task: Task<()>,
active_line_trailer_provider: Option<Box<dyn ActiveLineTrailerProvider>>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
@@ -883,6 +893,7 @@ struct AutocloseRegion {
struct SnippetState {
ranges: Vec<Vec<Range<Anchor>>>,
active_index: usize,
choices: Vec<Option<Vec<String>>>,
}
#[doc(hidden)]
@@ -1000,7 +1011,7 @@ enum ContextMenuOrigin {
GutterIndicator(DisplayRow),
}
#[derive(Clone)]
#[derive(Clone, Debug)]
struct CompletionsMenu {
id: CompletionId,
sort_completions: bool,
@@ -1011,10 +1022,105 @@ struct CompletionsMenu {
matches: Arc<[StringMatch]>,
selected_item: usize,
scroll_handle: UniformListScrollHandle,
selected_completion_documentation_resolve_debounce: Arc<Mutex<DebouncedDelay>>,
selected_completion_documentation_resolve_debounce: Option<Arc<Mutex<DebouncedDelay>>>,
}
impl CompletionsMenu {
fn new(
id: CompletionId,
sort_completions: bool,
initial_position: Anchor,
buffer: Model<Buffer>,
completions: Box<[Completion]>,
) -> Self {
let match_candidates = completions
.iter()
.enumerate()
.map(|(id, completion)| {
StringMatchCandidate::new(
id,
completion.label.text[completion.label.filter_range.clone()].into(),
)
})
.collect();
Self {
id,
sort_completions,
initial_position,
buffer,
completions: Arc::new(RwLock::new(completions)),
match_candidates,
matches: Vec::new().into(),
selected_item: 0,
scroll_handle: UniformListScrollHandle::new(),
selected_completion_documentation_resolve_debounce: Some(Arc::new(Mutex::new(
DebouncedDelay::new(),
))),
}
}
fn new_snippet_choices(
id: CompletionId,
sort_completions: bool,
choices: &Vec<String>,
selection: Range<Anchor>,
buffer: Model<Buffer>,
) -> Self {
let completions = choices
.iter()
.map(|choice| Completion {
old_range: selection.start.text_anchor..selection.end.text_anchor,
new_text: choice.to_string(),
label: CodeLabel {
text: choice.to_string(),
runs: Default::default(),
filter_range: Default::default(),
},
server_id: LanguageServerId(usize::MAX),
documentation: None,
lsp_completion: Default::default(),
confirm: None,
})
.collect();
let match_candidates = choices
.iter()
.enumerate()
.map(|(id, completion)| StringMatchCandidate::new(id, completion.to_string()))
.collect();
let matches = choices
.iter()
.enumerate()
.map(|(id, completion)| StringMatch {
candidate_id: id,
score: 1.,
positions: vec![],
string: completion.clone(),
})
.collect();
Self {
id,
sort_completions,
initial_position: selection.start,
buffer,
completions: Arc::new(RwLock::new(completions)),
match_candidates,
matches,
selected_item: 0,
scroll_handle: UniformListScrollHandle::new(),
selected_completion_documentation_resolve_debounce: Some(Arc::new(Mutex::new(
DebouncedDelay::new(),
))),
}
}
fn suppress_documentation_resolution(mut self) -> Self {
self.selected_completion_documentation_resolve_debounce
.take();
self
}
fn select_first(
&mut self,
provider: Option<&dyn CompletionProvider>,
@@ -1115,6 +1221,12 @@ impl CompletionsMenu {
let Some(provider) = provider else {
return;
};
let Some(documentation_resolve) = self
.selected_completion_documentation_resolve_debounce
.as_ref()
else {
return;
};
let resolve_task = provider.resolve_completions(
self.buffer.clone(),
@@ -1127,15 +1239,13 @@ impl CompletionsMenu {
EditorSettings::get_global(cx).completion_documentation_secondary_query_debounce;
let delay = Duration::from_millis(delay_ms);
self.selected_completion_documentation_resolve_debounce
.lock()
.fire_new(delay, cx, |_, cx| {
cx.spawn(move |this, mut cx| async move {
if let Some(true) = resolve_task.await.log_err() {
this.update(&mut cx, |_, cx| cx.notify()).ok();
}
})
});
documentation_resolve.lock().fire_new(delay, cx, |_, cx| {
cx.spawn(move |this, mut cx| async move {
if let Some(true) = resolve_task.await.log_err() {
this.update(&mut cx, |_, cx| cx.notify()).ok();
}
})
});
}
fn visible(&self) -> bool {
@@ -1418,6 +1528,7 @@ impl CompletionsMenu {
}
}
#[derive(Clone)]
struct AvailableCodeAction {
excerpt_id: ExcerptId,
action: CodeAction,
@@ -2104,6 +2215,7 @@ impl Editor {
addons: HashMap::default(),
_scroll_cursor_center_top_bottom_task: Task::ready(()),
text_style_refinement: None,
active_line_trailer_provider: None,
};
this.tasks_update_task = Some(this.refresh_runnables(cx));
this._subscriptions.extend(project_subscriptions);
@@ -2392,6 +2504,16 @@ impl Editor {
self.refresh_inline_completion(false, false, cx);
}
pub fn set_active_line_trailer_provider<T>(
&mut self,
provider: Option<T>,
_cx: &mut ViewContext<Self>,
) where
T: ActiveLineTrailerProvider + 'static,
{
self.active_line_trailer_provider = provider.map(|provider| Box::new(provider) as Box<_>);
}
pub fn placeholder_text(&self, _cx: &WindowContext) -> Option<&str> {
self.placeholder_text.as_deref()
}
@@ -4386,6 +4508,10 @@ impl Editor {
return;
};
if !self.snippet_stack.is_empty() && self.context_menu.read().as_ref().is_some() {
return;
}
let position = self.selections.newest_anchor().head();
let (buffer, buffer_position) =
if let Some(output) = self.buffer.read(cx).text_anchor_for_position(position, cx) {
@@ -4431,30 +4557,13 @@ impl Editor {
})?;
let completions = completions.await.log_err();
let menu = if let Some(completions) = completions {
let mut menu = CompletionsMenu {
let mut menu = CompletionsMenu::new(
id,
sort_completions,
initial_position: position,
match_candidates: completions
.iter()
.enumerate()
.map(|(id, completion)| {
StringMatchCandidate::new(
id,
completion.label.text[completion.label.filter_range.clone()]
.into(),
)
})
.collect(),
buffer: buffer.clone(),
completions: Arc::new(RwLock::new(completions.into())),
matches: Vec::new().into(),
selected_item: 0,
scroll_handle: UniformListScrollHandle::new(),
selected_completion_documentation_resolve_debounce: Arc::new(Mutex::new(
DebouncedDelay::new(),
)),
};
position,
buffer.clone(),
completions.into(),
);
menu.filter(query.as_deref(), cx.background_executor().clone())
.await;
@@ -4657,7 +4766,11 @@ impl Editor {
self.transact(cx, |this, cx| {
if let Some(mut snippet) = snippet {
snippet.text = text.to_string();
for tabstop in snippet.tabstops.iter_mut().flatten() {
for tabstop in snippet
.tabstops
.iter_mut()
.flat_map(|tabstop| tabstop.ranges.iter_mut())
{
tabstop.start -= common_prefix_len as isize;
tabstop.end -= common_prefix_len as isize;
}
@@ -5693,6 +5806,27 @@ impl Editor {
context_menu
}
fn show_snippet_choices(
&mut self,
choices: &Vec<String>,
selection: Range<Anchor>,
cx: &mut ViewContext<Self>,
) {
if selection.start.buffer_id.is_none() {
return;
}
let buffer_id = selection.start.buffer_id.unwrap();
let buffer = self.buffer().read(cx).buffer(buffer_id);
let id = post_inc(&mut self.next_completion_id);
if let Some(buffer) = buffer {
*self.context_menu.write() = Some(ContextMenu::Completions(
CompletionsMenu::new_snippet_choices(id, true, choices, selection, buffer)
.suppress_documentation_resolution(),
));
}
}
pub fn insert_snippet(
&mut self,
insertion_ranges: &[Range<usize>],
@@ -5702,6 +5836,7 @@ impl Editor {
struct Tabstop<T> {
is_end_tabstop: bool,
ranges: Vec<Range<T>>,
choices: Option<Vec<String>>,
}
let tabstops = self.buffer.update(cx, |buffer, cx| {
@@ -5721,10 +5856,11 @@ impl Editor {
.tabstops
.iter()
.map(|tabstop| {
let is_end_tabstop = tabstop.first().map_or(false, |tabstop| {
let is_end_tabstop = tabstop.ranges.first().map_or(false, |tabstop| {
tabstop.is_empty() && tabstop.start == snippet.text.len() as isize
});
let mut tabstop_ranges = tabstop
.ranges
.iter()
.flat_map(|tabstop_range| {
let mut delta = 0_isize;
@@ -5746,6 +5882,7 @@ impl Editor {
Tabstop {
is_end_tabstop,
ranges: tabstop_ranges,
choices: tabstop.choices.clone(),
}
})
.collect::<Vec<_>>()
@@ -5755,16 +5892,29 @@ impl Editor {
s.select_ranges(tabstop.ranges.iter().cloned());
});
if let Some(choices) = &tabstop.choices {
if let Some(selection) = tabstop.ranges.first() {
self.show_snippet_choices(choices, selection.clone(), cx)
}
}
// If we're already at the last tabstop and it's at the end of the snippet,
// we're done, we don't need to keep the state around.
if !tabstop.is_end_tabstop {
let choices = tabstops
.iter()
.map(|tabstop| tabstop.choices.clone())
.collect();
let ranges = tabstops
.into_iter()
.map(|tabstop| tabstop.ranges)
.collect::<Vec<_>>();
self.snippet_stack.push(SnippetState {
active_index: 0,
ranges,
choices,
});
}
@@ -5839,6 +5989,13 @@ impl Editor {
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.select_anchor_ranges(current_ranges.iter().cloned())
});
if let Some(choices) = &snippet.choices[snippet.active_index] {
if let Some(selection) = current_ranges.first() {
self.show_snippet_choices(&choices, selection.clone(), cx);
}
}
// If snippet state is not at the last tabstop, push it back on the stack
if snippet.active_index + 1 < snippet.ranges.len() {
self.snippet_stack.push(snippet);
@@ -6779,7 +6936,7 @@ impl Editor {
let mut edits = Vec::new();
let mut unfold_ranges = Vec::new();
let mut refold_ranges = Vec::new();
let mut refold_creases = Vec::new();
let selections = self.selections.all::<Point>(cx);
let mut selections = selections.iter().peekable();
@@ -6854,7 +7011,7 @@ impl Editor {
let mut end = fold.range.end.to_point(&buffer);
start.row -= row_delta;
end.row -= row_delta;
refold_ranges.push((start..end, fold.placeholder.clone()));
refold_creases.push(Crease::simple(start..end, fold.placeholder.clone()));
}
}
}
@@ -6870,7 +7027,7 @@ impl Editor {
buffer.edit([(range, text)], None, cx);
}
});
this.fold_ranges(refold_ranges, true, cx);
this.fold_creases(refold_creases, true, cx);
this.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.select(new_selections);
})
@@ -6883,7 +7040,7 @@ impl Editor {
let mut edits = Vec::new();
let mut unfold_ranges = Vec::new();
let mut refold_ranges = Vec::new();
let mut refold_creases = Vec::new();
let selections = self.selections.all::<Point>(cx);
let mut selections = selections.iter().peekable();
@@ -6948,7 +7105,7 @@ impl Editor {
let mut end = fold.range.end.to_point(&buffer);
start.row += row_delta;
end.row += row_delta;
refold_ranges.push((start..end, fold.placeholder.clone()));
refold_creases.push(Crease::simple(start..end, fold.placeholder.clone()));
}
}
}
@@ -6964,7 +7121,7 @@ impl Editor {
buffer.edit([(range, text)], None, cx);
}
});
this.fold_ranges(refold_ranges, true, cx);
this.fold_creases(refold_creases, true, cx);
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections));
});
}
@@ -10421,7 +10578,7 @@ impl Editor {
style: BlockStyle::Flex,
placement: BlockPlacement::Below(range.start),
height: 1,
render: Box::new({
render: Arc::new({
let rename_editor = rename_editor.clone();
move |cx: &mut BlockContext| {
let mut text_style = cx.editor_style.text.clone();
@@ -10431,6 +10588,7 @@ impl Editor {
text_style = text_style.highlight(highlight_style);
}
div()
.block_mouse_down()
.pl(cx.anchor_x)
.child(EditorElement::new(
&rename_editor,
@@ -10894,7 +11052,7 @@ impl Editor {
}
pub fn fold(&mut self, _: &actions::Fold, cx: &mut ViewContext<Self>) {
let mut fold_ranges = Vec::new();
let mut to_fold = Vec::new();
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let selections = self.selections.all_adjusted(cx);
@@ -10906,12 +11064,10 @@ impl Editor {
let mut found = false;
let mut row = range.start.row;
while row <= range.end.row {
if let Some((foldable_range, fold_text)) =
{ display_map.foldable_range(MultiBufferRow(row)) }
{
if let Some(crease) = display_map.crease_for_buffer_row(MultiBufferRow(row)) {
found = true;
row = foldable_range.end.row + 1;
fold_ranges.push((foldable_range, fold_text));
row = crease.range().end.row + 1;
to_fold.push(crease);
} else {
row += 1
}
@@ -10922,11 +11078,9 @@ impl Editor {
}
for row in (0..=range.start.row).rev() {
if let Some((foldable_range, fold_text)) =
display_map.foldable_range(MultiBufferRow(row))
{
if foldable_range.end.row >= buffer_start_row {
fold_ranges.push((foldable_range, fold_text));
if let Some(crease) = display_map.crease_for_buffer_row(MultiBufferRow(row)) {
if crease.range().end.row >= buffer_start_row {
to_fold.push(crease);
if row <= range.start.row {
break;
}
@@ -10935,26 +11089,29 @@ impl Editor {
}
}
self.fold_ranges(fold_ranges, true, cx);
self.fold_creases(to_fold, true, cx);
}
fn fold_at_level(&mut self, fold_at: &FoldAtLevel, cx: &mut ViewContext<Self>) {
let fold_at_level = fold_at.level;
let snapshot = self.buffer.read(cx).snapshot(cx);
let mut fold_ranges = Vec::new();
let mut to_fold = Vec::new();
let mut stack = vec![(0, snapshot.max_buffer_row().0, 1)];
while let Some((mut start_row, end_row, current_level)) = stack.pop() {
while start_row < end_row {
match self.snapshot(cx).foldable_range(MultiBufferRow(start_row)) {
Some(foldable_range) => {
let nested_start_row = foldable_range.0.start.row + 1;
let nested_end_row = foldable_range.0.end.row;
match self
.snapshot(cx)
.crease_for_buffer_row(MultiBufferRow(start_row))
{
Some(crease) => {
let nested_start_row = crease.range().start.row + 1;
let nested_end_row = crease.range().end.row;
if current_level < fold_at_level {
stack.push((nested_start_row, nested_end_row, current_level + 1));
} else if current_level == fold_at_level {
fold_ranges.push(foldable_range);
to_fold.push(crease);
}
start_row = nested_end_row + 1;
@@ -10964,7 +11121,7 @@ impl Editor {
}
}
self.fold_ranges(fold_ranges, true, cx);
self.fold_creases(to_fold, true, cx);
}
pub fn fold_all(&mut self, _: &actions::FoldAll, cx: &mut ViewContext<Self>) {
@@ -10972,16 +11129,18 @@ impl Editor {
let snapshot = self.buffer.read(cx).snapshot(cx);
for row in 0..snapshot.max_buffer_row().0 {
if let Some(foldable_range) = self.snapshot(cx).foldable_range(MultiBufferRow(row)) {
if let Some(foldable_range) =
self.snapshot(cx).crease_for_buffer_row(MultiBufferRow(row))
{
fold_ranges.push(foldable_range);
}
}
self.fold_ranges(fold_ranges, true, cx);
self.fold_creases(fold_ranges, true, cx);
}
pub fn fold_recursive(&mut self, _: &actions::FoldRecursive, cx: &mut ViewContext<Self>) {
let mut fold_ranges = Vec::new();
let mut to_fold = Vec::new();
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let selections = self.selections.all_adjusted(cx);
@@ -10992,11 +11151,9 @@ impl Editor {
if range.start.row != range.end.row {
let mut found = false;
for row in range.start.row..=range.end.row {
if let Some((foldable_range, fold_text)) =
{ display_map.foldable_range(MultiBufferRow(row)) }
{
if let Some(crease) = display_map.crease_for_buffer_row(MultiBufferRow(row)) {
found = true;
fold_ranges.push((foldable_range, fold_text));
to_fold.push(crease);
}
}
if found {
@@ -11005,11 +11162,9 @@ impl Editor {
}
for row in (0..=range.start.row).rev() {
if let Some((foldable_range, fold_text)) =
display_map.foldable_range(MultiBufferRow(row))
{
if foldable_range.end.row >= buffer_start_row {
fold_ranges.push((foldable_range, fold_text));
if let Some(crease) = display_map.crease_for_buffer_row(MultiBufferRow(row)) {
if crease.range().end.row >= buffer_start_row {
to_fold.push(crease);
} else {
break;
}
@@ -11017,21 +11172,21 @@ impl Editor {
}
}
self.fold_ranges(fold_ranges, true, cx);
self.fold_creases(to_fold, true, cx);
}
pub fn fold_at(&mut self, fold_at: &FoldAt, cx: &mut ViewContext<Self>) {
let buffer_row = fold_at.buffer_row;
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
if let Some((fold_range, placeholder)) = display_map.foldable_range(buffer_row) {
if let Some(crease) = display_map.crease_for_buffer_row(buffer_row) {
let autoscroll = self
.selections
.all::<Point>(cx)
.iter()
.any(|selection| fold_range.overlaps(&selection.range()));
.any(|selection| crease.range().overlaps(&selection.range()));
self.fold_ranges([(fold_range, placeholder)], autoscroll, cx);
self.fold_creases(vec![crease], autoscroll, cx);
}
}
@@ -11092,81 +11247,78 @@ impl Editor {
pub fn unfold_all(&mut self, _: &actions::UnfoldAll, cx: &mut ViewContext<Self>) {
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
self.unfold_ranges(
&[Point::zero()..display_map.max_point().to_point(&display_map)],
true,
true,
cx,
);
self.unfold_ranges(&[0..display_map.buffer_snapshot.len()], true, true, cx);
}
pub fn fold_selected_ranges(&mut self, _: &FoldSelectedRanges, cx: &mut ViewContext<Self>) {
let selections = self.selections.all::<Point>(cx);
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let line_mode = self.selections.line_mode;
let ranges = selections.into_iter().map(|s| {
if line_mode {
let start = Point::new(s.start.row, 0);
let end = Point::new(
s.end.row,
display_map
.buffer_snapshot
.line_len(MultiBufferRow(s.end.row)),
);
(start..end, display_map.fold_placeholder.clone())
} else {
(s.start..s.end, display_map.fold_placeholder.clone())
}
});
self.fold_ranges(ranges, true, cx);
let ranges = selections
.into_iter()
.map(|s| {
if line_mode {
let start = Point::new(s.start.row, 0);
let end = Point::new(
s.end.row,
display_map
.buffer_snapshot
.line_len(MultiBufferRow(s.end.row)),
);
Crease::simple(start..end, display_map.fold_placeholder.clone())
} else {
Crease::simple(s.start..s.end, display_map.fold_placeholder.clone())
}
})
.collect::<Vec<_>>();
self.fold_creases(ranges, true, cx);
}
pub fn fold_ranges<T: ToOffset + Clone>(
pub fn fold_creases<T: ToOffset + Clone>(
&mut self,
ranges: impl IntoIterator<Item = (Range<T>, FoldPlaceholder)>,
creases: Vec<Crease<T>>,
auto_scroll: bool,
cx: &mut ViewContext<Self>,
) {
let mut fold_ranges = Vec::new();
if creases.is_empty() {
return;
}
let mut buffers_affected = HashMap::default();
let multi_buffer = self.buffer().read(cx);
for (fold_range, fold_text) in ranges {
for crease in &creases {
if let Some((_, buffer, _)) =
multi_buffer.excerpt_containing(fold_range.start.clone(), cx)
multi_buffer.excerpt_containing(crease.range().start.clone(), cx)
{
buffers_affected.insert(buffer.read(cx).remote_id(), buffer);
};
fold_ranges.push((fold_range, fold_text));
}
let mut ranges = fold_ranges.into_iter().peekable();
if ranges.peek().is_some() {
self.display_map.update(cx, |map, cx| map.fold(ranges, cx));
self.display_map.update(cx, |map, cx| map.fold(creases, cx));
if auto_scroll {
self.request_autoscroll(Autoscroll::fit(), cx);
}
for buffer in buffers_affected.into_values() {
self.sync_expanded_diff_hunks(buffer, cx);
}
cx.notify();
if let Some(active_diagnostics) = self.active_diagnostics.take() {
// Clear diagnostics block when folding a range that contains it.
let snapshot = self.snapshot(cx);
if snapshot.intersects_fold(active_diagnostics.primary_range.start) {
drop(snapshot);
self.active_diagnostics = Some(active_diagnostics);
self.dismiss_diagnostics(cx);
} else {
self.active_diagnostics = Some(active_diagnostics);
}
}
self.scrollbar_marker_state.dirty = true;
if auto_scroll {
self.request_autoscroll(Autoscroll::fit(), cx);
}
for buffer in buffers_affected.into_values() {
self.sync_expanded_diff_hunks(buffer, cx);
}
cx.notify();
if let Some(active_diagnostics) = self.active_diagnostics.take() {
// Clear diagnostics block when folding a range that contains it.
let snapshot = self.snapshot(cx);
if snapshot.intersects_fold(active_diagnostics.primary_range.start) {
drop(snapshot);
self.active_diagnostics = Some(active_diagnostics);
self.dismiss_diagnostics(cx);
} else {
self.active_diagnostics = Some(active_diagnostics);
}
}
self.scrollbar_marker_state.dirty = true;
}
/// Removes any folds whose ranges intersect any of the given ranges.
@@ -11215,6 +11367,7 @@ impl Editor {
}
self.display_map.update(cx, update);
if auto_scroll {
self.request_autoscroll(Autoscroll::fit(), cx);
}
@@ -11317,7 +11470,7 @@ impl Editor {
pub fn insert_creases(
&mut self,
creases: impl IntoIterator<Item = Crease>,
creases: impl IntoIterator<Item = Crease<Anchor>>,
cx: &mut ViewContext<Self>,
) -> Vec<CreaseId> {
self.display_map
@@ -11717,6 +11870,21 @@ impl Editor {
&& self.has_blame_entries(cx)
}
pub fn render_active_line_trailer(
&mut self,
style: &EditorStyle,
cx: &mut WindowContext,
) -> Option<AnyElement> {
if !self.newest_selection_head_on_empty_line(cx) || self.has_active_inline_completion(cx) {
return None;
}
let focus_handle = self.focus_handle.clone();
self.active_line_trailer_provider
.as_mut()?
.render_active_line_trailer(style, &focus_handle, cx)
}
fn has_blame_entries(&self, cx: &mut WindowContext) -> bool {
self.blame()
.map_or(false, |blame| blame.read(cx).has_generated_entries())
@@ -14056,7 +14224,7 @@ impl EditorSnapshot {
}
}
pub fn render_fold_toggle(
pub fn render_crease_toggle(
&self,
buffer_row: MultiBufferRow,
row_contains_cursor: bool,
@@ -14064,34 +14232,38 @@ impl EditorSnapshot {
cx: &mut WindowContext,
) -> Option<AnyElement> {
let folded = self.is_line_folded(buffer_row);
let mut is_foldable = false;
if let Some(crease) = self
.crease_snapshot
.query_row(buffer_row, &self.buffer_snapshot)
{
let toggle_callback = Arc::new(move |folded, cx: &mut WindowContext| {
if folded {
editor.update(cx, |editor, cx| {
editor.fold_at(&crate::FoldAt { buffer_row }, cx)
});
} else {
editor.update(cx, |editor, cx| {
editor.unfold_at(&crate::UnfoldAt { buffer_row }, cx)
});
is_foldable = true;
match crease {
Crease::Inline { render_toggle, .. } | Crease::Block { render_toggle, .. } => {
if let Some(render_toggle) = render_toggle {
let toggle_callback = Arc::new(move |folded, cx: &mut WindowContext| {
if folded {
editor.update(cx, |editor, cx| {
editor.fold_at(&crate::FoldAt { buffer_row }, cx)
});
} else {
editor.update(cx, |editor, cx| {
editor.unfold_at(&crate::UnfoldAt { buffer_row }, cx)
});
}
});
return Some((render_toggle)(buffer_row, folded, toggle_callback, cx));
}
}
});
}
}
Some((crease.render_toggle)(
buffer_row,
folded,
toggle_callback,
cx,
))
} else if folded
|| (self.starts_indent(buffer_row) && (row_contains_cursor || self.gutter_hovered))
{
is_foldable |= self.starts_indent(buffer_row);
if folded || (is_foldable && (row_contains_cursor || self.gutter_hovered)) {
Some(
Disclosure::new(("indent-fold-indicator", buffer_row.0), !folded)
Disclosure::new(("gutter_crease", buffer_row.0), !folded)
.selected(folded)
.on_click(cx.listener_for(&editor, move |this, _e, cx| {
if folded {
@@ -14113,10 +14285,15 @@ impl EditorSnapshot {
cx: &mut WindowContext,
) -> Option<AnyElement> {
let folded = self.is_line_folded(buffer_row);
let crease = self
if let Crease::Inline { render_trailer, .. } = self
.crease_snapshot
.query_row(buffer_row, &self.buffer_snapshot)?;
Some((crease.render_trailer)(buffer_row, folded, cx))
.query_row(buffer_row, &self.buffer_snapshot)?
{
let render_trailer = render_trailer.as_ref()?;
Some(render_trailer(buffer_row, folded, cx))
} else {
None
}
}
}
@@ -14621,7 +14798,7 @@ pub fn diagnostic_block_renderer(
let (text_without_backticks, code_ranges) =
highlight_diagnostic_message(&diagnostic, max_message_rows);
Box::new(move |cx: &mut BlockContext| {
Arc::new(move |cx: &mut BlockContext| {
let group_id: SharedString = cx.block_id.to_string().into();
let mut text_style = cx.text_style().clone();
@@ -14676,6 +14853,7 @@ pub fn diagnostic_block_renderer(
.group(group_id.clone())
.relative()
.size_full()
.block_mouse_down()
.pl(cx.gutter_dimensions.width)
.w(cx.max_width - cx.gutter_dimensions.full_width())
.child(

View File

@@ -596,10 +596,10 @@ fn test_clone(cx: &mut TestAppContext) {
_ = editor.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges(selection_ranges.clone()));
editor.fold_ranges(
[
(Point::new(1, 0)..Point::new(2, 0), FoldPlaceholder::test()),
(Point::new(3, 0)..Point::new(4, 0), FoldPlaceholder::test()),
editor.fold_creases(
vec![
Crease::simple(Point::new(1, 0)..Point::new(2, 0), FoldPlaceholder::test()),
Crease::simple(Point::new(3, 0)..Point::new(4, 0), FoldPlaceholder::test()),
],
true,
cx,
@@ -1283,11 +1283,11 @@ fn test_move_cursor_multibyte(cx: &mut TestAppContext) {
assert_eq!('α'.len_utf8(), 2);
_ = view.update(cx, |view, cx| {
view.fold_ranges(
view.fold_creases(
vec![
(Point::new(0, 6)..Point::new(0, 12), FoldPlaceholder::test()),
(Point::new(1, 2)..Point::new(1, 4), FoldPlaceholder::test()),
(Point::new(2, 4)..Point::new(2, 8), FoldPlaceholder::test()),
Crease::simple(Point::new(0, 6)..Point::new(0, 12), FoldPlaceholder::test()),
Crease::simple(Point::new(1, 2)..Point::new(1, 4), FoldPlaceholder::test()),
Crease::simple(Point::new(2, 4)..Point::new(2, 8), FoldPlaceholder::test()),
],
true,
cx,
@@ -1398,6 +1398,15 @@ fn test_move_cursor_different_line_lengths(cx: &mut TestAppContext) {
view.change_selections(None, cx, |s| {
s.select_display_ranges([empty_range(0, "ⓐⓑⓒⓓⓔ".len())]);
});
// moving above start of document should move selection to start of document,
// but the next move down should still be at the original goal_x
view.move_up(&MoveUp, cx);
assert_eq!(
view.selections.display_ranges(cx),
&[empty_range(0, "".len())]
);
view.move_down(&MoveDown, cx);
assert_eq!(
view.selections.display_ranges(cx),
@@ -1422,6 +1431,25 @@ fn test_move_cursor_different_line_lengths(cx: &mut TestAppContext) {
&[empty_range(4, "ⓐⓑⓒⓓⓔ".len())]
);
// moving past end of document should not change goal_x
view.move_down(&MoveDown, cx);
assert_eq!(
view.selections.display_ranges(cx),
&[empty_range(5, "".len())]
);
view.move_down(&MoveDown, cx);
assert_eq!(
view.selections.display_ranges(cx),
&[empty_range(5, "".len())]
);
view.move_up(&MoveUp, cx);
assert_eq!(
view.selections.display_ranges(cx),
&[empty_range(4, "ⓐⓑⓒⓓⓔ".len())]
);
view.move_up(&MoveUp, cx);
assert_eq!(
view.selections.display_ranges(cx),
@@ -3875,11 +3903,11 @@ fn test_move_line_up_down(cx: &mut TestAppContext) {
build_editor(buffer, cx)
});
_ = view.update(cx, |view, cx| {
view.fold_ranges(
view.fold_creases(
vec![
(Point::new(0, 2)..Point::new(1, 2), FoldPlaceholder::test()),
(Point::new(2, 3)..Point::new(4, 1), FoldPlaceholder::test()),
(Point::new(7, 0)..Point::new(8, 4), FoldPlaceholder::test()),
Crease::simple(Point::new(0, 2)..Point::new(1, 2), FoldPlaceholder::test()),
Crease::simple(Point::new(2, 3)..Point::new(4, 1), FoldPlaceholder::test()),
Crease::simple(Point::new(7, 0)..Point::new(8, 4), FoldPlaceholder::test()),
],
true,
cx,
@@ -3980,7 +4008,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {
style: BlockStyle::Fixed,
placement: BlockPlacement::Below(snapshot.anchor_after(Point::new(2, 0))),
height: 1,
render: Box::new(|_| div().into_any()),
render: Arc::new(|_| div().into_any()),
priority: 0,
}],
Some(Autoscroll::fit()),
@@ -4022,7 +4050,7 @@ async fn test_selections_and_replace_blocks(cx: &mut TestAppContext) {
placement,
height: 4,
style: BlockStyle::Sticky,
render: Box::new(|_| gpui::div().into_any_element()),
render: Arc::new(|_| gpui::div().into_any_element()),
priority: 0,
}],
None,
@@ -4717,11 +4745,11 @@ fn test_split_selection_into_lines(cx: &mut TestAppContext) {
build_editor(buffer, cx)
});
_ = view.update(cx, |view, cx| {
view.fold_ranges(
view.fold_creases(
vec![
(Point::new(0, 2)..Point::new(1, 2), FoldPlaceholder::test()),
(Point::new(2, 3)..Point::new(4, 1), FoldPlaceholder::test()),
(Point::new(7, 0)..Point::new(8, 4), FoldPlaceholder::test()),
Crease::simple(Point::new(0, 2)..Point::new(1, 2), FoldPlaceholder::test()),
Crease::simple(Point::new(2, 3)..Point::new(4, 1), FoldPlaceholder::test()),
Crease::simple(Point::new(7, 0)..Point::new(8, 4), FoldPlaceholder::test()),
],
true,
cx,
@@ -5398,13 +5426,13 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
// Ensure that we keep expanding the selection if the larger selection starts or ends within
// a fold.
editor.update(cx, |view, cx| {
view.fold_ranges(
view.fold_creases(
vec![
(
Crease::simple(
Point::new(0, 21)..Point::new(0, 24),
FoldPlaceholder::test(),
),
(
Crease::simple(
Point::new(3, 20)..Point::new(3, 22),
FoldPlaceholder::test(),
),
@@ -6551,6 +6579,45 @@ async fn test_auto_replace_emoji_shortcode(cx: &mut gpui::TestAppContext) {
});
}
#[gpui::test]
async fn test_snippet_placeholder_choices(cx: &mut gpui::TestAppContext) {
init_test(cx, |_| {});
let (text, insertion_ranges) = marked_text_ranges(
indoc! {"
ˇ
"},
false,
);
let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
_ = editor.update(cx, |editor, cx| {
let snippet = Snippet::parse("type ${1|,i32,u32|} = $2").unwrap();
editor
.insert_snippet(&insertion_ranges, snippet, cx)
.unwrap();
fn assert(editor: &mut Editor, cx: &mut ViewContext<Editor>, marked_text: &str) {
let (expected_text, selection_ranges) = marked_text_ranges(marked_text, false);
assert_eq!(editor.text(cx), expected_text);
assert_eq!(editor.selections.ranges::<usize>(cx), selection_ranges);
}
assert(
editor,
cx,
indoc! {"
type «» =•
"},
);
assert!(editor.context_menu_visible(), "There should be a matches");
});
}
#[gpui::test]
async fn test_snippets(cx: &mut gpui::TestAppContext) {
init_test(cx, |_| {});
@@ -13139,7 +13206,7 @@ fn test_crease_insertion_and_rendering(cx: &mut TestAppContext) {
callback: Arc<dyn Fn(bool, &mut WindowContext) + Send + Sync>,
}
let crease = Crease::new(
let crease = Crease::inline(
range,
FoldPlaceholder::test(),
{
@@ -13158,7 +13225,8 @@ fn test_crease_insertion_and_rendering(cx: &mut TestAppContext) {
editor.insert_creases(Some(crease), cx);
let snapshot = editor.snapshot(cx);
let _div = snapshot.render_fold_toggle(MultiBufferRow(1), false, cx.view().clone(), cx);
let _div =
snapshot.render_crease_toggle(MultiBufferRow(1), false, cx.view().clone(), cx);
snapshot
})
.unwrap();

View File

@@ -16,8 +16,8 @@ use crate::{
items::BufferSearchHighlights,
mouse_context_menu::{self, MenuPosition, MouseContextMenu},
scroll::scroll_amount::ScrollAmount,
BlockId, CodeActionsMenu, CursorShape, CustomBlockId, DisplayPoint, DisplayRow,
DocumentHighlightRead, DocumentHighlightWrite, Editor, EditorMode, EditorSettings,
BlockId, ChunkReplacement, CodeActionsMenu, CursorShape, CustomBlockId, DisplayPoint,
DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, Editor, EditorMode, EditorSettings,
EditorSnapshot, EditorStyle, ExpandExcerpts, FocusedBlock, GutterDimensions, HalfPageDown,
HalfPageUp, HandleInput, HoveredCursor, HoveredHunk, JumpData, LineDown, LineUp, OpenExcerpts,
PageDown, PageUp, Point, RowExt, RowRangeExt, SelectPhase, Selection, SoftWrap, ToPoint,
@@ -34,8 +34,8 @@ use gpui::{
FontId, GlobalElementId, Hitbox, Hsla, InteractiveElement, IntoElement, Length,
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PaintQuad,
ParentElement, Pixels, ScrollDelta, ScrollWheelEvent, ShapedLine, SharedString, Size,
StatefulInteractiveElement, Style, Styled, TextRun, TextStyle, TextStyleRefinement, View,
ViewContext, WeakView, WindowContext,
StatefulInteractiveElement, Style, Styled, TextRun, TextStyleRefinement, View, ViewContext,
WeakView, WindowContext,
};
use gpui::{ClickEvent, Subscription};
use itertools::Itertools;
@@ -1227,9 +1227,9 @@ impl EditorElement {
}
#[allow(clippy::too_many_arguments)]
fn prepaint_gutter_fold_toggles(
fn prepaint_crease_toggles(
&self,
toggles: &mut [Option<AnyElement>],
crease_toggles: &mut [Option<AnyElement>],
line_height: Pixels,
gutter_dimensions: &GutterDimensions,
gutter_settings: crate::editor_settings::Gutter,
@@ -1237,25 +1237,25 @@ impl EditorElement {
gutter_hitbox: &Hitbox,
cx: &mut WindowContext,
) {
for (ix, fold_indicator) in toggles.iter_mut().enumerate() {
if let Some(fold_indicator) = fold_indicator {
for (ix, crease_toggle) in crease_toggles.iter_mut().enumerate() {
if let Some(crease_toggle) = crease_toggle {
debug_assert!(gutter_settings.folds);
let available_space = size(
AvailableSpace::MinContent,
AvailableSpace::Definite(line_height * 0.55),
);
let fold_indicator_size = fold_indicator.layout_as_root(available_space, cx);
let crease_toggle_size = crease_toggle.layout_as_root(available_space, cx);
let position = point(
gutter_dimensions.width - gutter_dimensions.right_padding,
ix as f32 * line_height - (scroll_pixel_position.y % line_height),
);
let centering_offset = point(
(gutter_dimensions.fold_area_width() - fold_indicator_size.width) / 2.,
(line_height - fold_indicator_size.height) / 2.,
(gutter_dimensions.fold_area_width() - crease_toggle_size.width) / 2.,
(line_height - crease_toggle_size.height) / 2.,
);
let origin = gutter_hitbox.origin + position + centering_offset;
fold_indicator.prepaint_as_root(origin, available_space, cx);
crease_toggle.prepaint_as_root(origin, available_space, cx);
}
}
}
@@ -1412,7 +1412,7 @@ impl EditorElement {
}
#[allow(clippy::too_many_arguments)]
fn layout_inline_blame(
fn layout_active_line_trailer(
&self,
display_row: DisplayRow,
display_snapshot: &DisplaySnapshot,
@@ -1424,61 +1424,71 @@ impl EditorElement {
line_height: Pixels,
cx: &mut WindowContext,
) -> Option<AnyElement> {
if !self
let render_inline_blame = self
.editor
.update(cx, |editor, cx| editor.render_git_blame_inline(cx))
{
return None;
}
.update(cx, |editor, cx| editor.render_git_blame_inline(cx));
if render_inline_blame {
let workspace = self
.editor
.read(cx)
.workspace
.as_ref()
.map(|(w, _)| w.clone());
let workspace = self
.editor
.read(cx)
.workspace
.as_ref()
.map(|(w, _)| w.clone());
let display_point = DisplayPoint::new(display_row, 0);
let buffer_row = MultiBufferRow(display_point.to_point(display_snapshot).row);
let display_point = DisplayPoint::new(display_row, 0);
let buffer_row = MultiBufferRow(display_point.to_point(display_snapshot).row);
let blame = self.editor.read(cx).blame.clone()?;
let blame_entry = blame
.update(cx, |blame, cx| {
blame.blame_for_rows([Some(buffer_row)], cx).next()
})
.flatten()?;
let blame = self.editor.read(cx).blame.clone()?;
let blame_entry = blame
.update(cx, |blame, cx| {
blame.blame_for_rows([Some(buffer_row)], cx).next()
})
.flatten()?;
let mut element =
render_inline_blame_entry(&blame, blame_entry, &self.style, workspace, cx);
let mut element =
render_inline_blame_entry(&blame, blame_entry, &self.style, workspace, cx);
let start_y = content_origin.y
+ line_height * (display_row.as_f32() - scroll_pixel_position.y / line_height);
let start_y = content_origin.y
+ line_height * (display_row.as_f32() - scroll_pixel_position.y / line_height);
let start_x = {
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.;
let start_x = {
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.;
let line_end = if let Some(crease_trailer) = crease_trailer {
crease_trailer.bounds.right()
} else {
content_origin.x - scroll_pixel_position.x + line_layout.width
};
let padded_line_end = line_end + em_width * INLINE_BLAME_PADDING_EM_WIDTHS;
let line_end = if let Some(crease_trailer) = crease_trailer {
crease_trailer.bounds.right()
} else {
content_origin.x - scroll_pixel_position.x + line_layout.width
let min_column_in_pixels = ProjectSettings::get_global(cx)
.git
.inline_blame
.and_then(|settings| settings.min_column)
.map(|col| self.column_pixels(col as usize, cx))
.unwrap_or(px(0.));
let min_start = content_origin.x - scroll_pixel_position.x + min_column_in_pixels;
cmp::max(padded_line_end, min_start)
};
let padded_line_end = line_end + em_width * INLINE_BLAME_PADDING_EM_WIDTHS;
let min_column_in_pixels = ProjectSettings::get_global(cx)
.git
.inline_blame
.and_then(|settings| settings.min_column)
.map(|col| self.column_pixels(col as usize, cx))
.unwrap_or(px(0.));
let min_start = content_origin.x - scroll_pixel_position.x + min_column_in_pixels;
let absolute_offset = point(start_x, start_y);
element.prepaint_as_root(absolute_offset, AvailableSpace::min_size(), cx);
cmp::max(padded_line_end, min_start)
};
Some(element)
} else if let Some(mut element) = self.editor.update(cx, |editor, cx| {
editor.render_active_line_trailer(&self.style, cx)
}) {
let start_y = content_origin.y
+ line_height * (display_row.as_f32() - scroll_pixel_position.y / line_height);
let start_x = content_origin.x - scroll_pixel_position.x + em_width;
let absolute_offset = point(start_x, start_y);
element.prepaint_as_root(absolute_offset, AvailableSpace::min_size(), cx);
let absolute_offset = point(start_x, start_y);
element.prepaint_as_root(absolute_offset, AvailableSpace::min_size(), cx);
Some(element)
Some(element)
} else {
None
}
}
#[allow(clippy::too_many_arguments)]
@@ -1915,7 +1925,7 @@ impl EditorElement {
.collect()
}
fn layout_gutter_fold_toggles(
fn layout_crease_toggles(
&self,
rows: Range<DisplayRow>,
buffer_rows: impl IntoIterator<Item = Option<MultiBufferRow>>,
@@ -1934,7 +1944,7 @@ impl EditorElement {
if let Some(multibuffer_row) = row {
let display_row = DisplayRow(rows.start.0 + ix as u32);
let active = active_rows.contains_key(&display_row);
snapshot.render_fold_toggle(
snapshot.render_crease_toggle(
multibuffer_row,
active,
self.editor.clone(),
@@ -2019,7 +2029,7 @@ impl EditorElement {
let chunks = snapshot.highlighted_chunks(rows.clone(), true, style);
LineWithInvisibles::from_chunks(
chunks,
&style.text,
&style,
MAX_LINE_LEN,
rows.len(),
snapshot.mode,
@@ -2122,9 +2132,7 @@ impl EditorElement {
max_width: text_hitbox.size.width.max(*scroll_width),
editor_style: &self.style,
}))
.cursor(CursorStyle::Arrow)
.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
.into_any_element()
.into_any()
}
Block::ExcerptBoundary {
@@ -3354,9 +3362,9 @@ impl EditorElement {
fn paint_gutter_indicators(&self, layout: &mut EditorLayout, cx: &mut WindowContext) {
cx.paint_layer(layout.gutter_hitbox.bounds, |cx| {
cx.with_element_namespace("gutter_fold_toggles", |cx| {
for fold_indicator in layout.gutter_fold_toggles.iter_mut().flatten() {
fold_indicator.paint(cx);
cx.with_element_namespace("crease_toggles", |cx| {
for crease_toggle in layout.crease_toggles.iter_mut().flatten() {
crease_toggle.paint(cx);
}
});
@@ -3456,7 +3464,7 @@ impl EditorElement {
self.paint_lines(&invisible_display_ranges, layout, cx);
self.paint_redactions(layout, cx);
self.paint_cursors(layout, cx);
self.paint_inline_blame(layout, cx);
self.paint_active_line_trailer(layout, cx);
cx.with_element_namespace("crease_trailers", |cx| {
for trailer in layout.crease_trailers.iter_mut().flatten() {
trailer.element.paint(cx);
@@ -3938,10 +3946,10 @@ impl EditorElement {
}
}
fn paint_inline_blame(&mut self, layout: &mut EditorLayout, cx: &mut WindowContext) {
if let Some(mut inline_blame) = layout.inline_blame.take() {
fn paint_active_line_trailer(&mut self, layout: &mut EditorLayout, cx: &mut WindowContext) {
if let Some(mut element) = layout.active_line_trailer.take() {
cx.paint_layer(layout.text_hitbox.bounds, |cx| {
inline_blame.paint(cx);
element.paint(cx);
})
}
}
@@ -4374,7 +4382,7 @@ impl LineWithInvisibles {
#[allow(clippy::too_many_arguments)]
fn from_chunks<'a>(
chunks: impl Iterator<Item = HighlightedChunk<'a>>,
text_style: &TextStyle,
editor_style: &EditorStyle,
max_line_len: usize,
max_line_count: usize,
editor_mode: EditorMode,
@@ -4382,6 +4390,7 @@ impl LineWithInvisibles {
is_row_soft_wrapped: impl Copy + Fn(usize) -> bool,
cx: &mut WindowContext,
) -> Vec<Self> {
let text_style = &editor_style.text;
let mut layouts = Vec::with_capacity(max_line_count);
let mut fragments: SmallVec<[LineFragment; 1]> = SmallVec::new();
let mut line = String::new();
@@ -4400,9 +4409,9 @@ impl LineWithInvisibles {
text: "\n",
style: None,
is_tab: false,
renderer: None,
replacement: None,
}]) {
if let Some(renderer) = highlighted_chunk.renderer {
if let Some(replacement) = highlighted_chunk.replacement {
if !line.is_empty() {
let shaped_line = cx
.text_system()
@@ -4415,42 +4424,71 @@ impl LineWithInvisibles {
styles.clear();
}
let available_width = if renderer.constrain_width {
let chunk = if highlighted_chunk.text == ellipsis.as_ref() {
ellipsis.clone()
} else {
SharedString::from(Arc::from(highlighted_chunk.text))
};
let shaped_line = cx
.text_system()
.shape_line(
chunk,
font_size,
&[text_style.to_run(highlighted_chunk.text.len())],
)
.unwrap();
AvailableSpace::Definite(shaped_line.width)
} else {
AvailableSpace::MinContent
};
match replacement {
ChunkReplacement::Renderer(renderer) => {
let available_width = if renderer.constrain_width {
let chunk = if highlighted_chunk.text == ellipsis.as_ref() {
ellipsis.clone()
} else {
SharedString::from(Arc::from(highlighted_chunk.text))
};
let shaped_line = cx
.text_system()
.shape_line(
chunk,
font_size,
&[text_style.to_run(highlighted_chunk.text.len())],
)
.unwrap();
AvailableSpace::Definite(shaped_line.width)
} else {
AvailableSpace::MinContent
};
let mut element = (renderer.render)(&mut ChunkRendererContext {
context: cx,
max_width: text_width,
});
let line_height = text_style.line_height_in_pixels(cx.rem_size());
let size = element.layout_as_root(
size(available_width, AvailableSpace::Definite(line_height)),
cx,
);
let mut element = (renderer.render)(&mut ChunkRendererContext {
context: cx,
max_width: text_width,
});
let line_height = text_style.line_height_in_pixels(cx.rem_size());
let size = element.layout_as_root(
size(available_width, AvailableSpace::Definite(line_height)),
cx,
);
width += size.width;
len += highlighted_chunk.text.len();
fragments.push(LineFragment::Element {
element: Some(element),
size,
len: highlighted_chunk.text.len(),
});
width += size.width;
len += highlighted_chunk.text.len();
fragments.push(LineFragment::Element {
element: Some(element),
size,
len: highlighted_chunk.text.len(),
});
}
ChunkReplacement::Str(x) => {
let text_style = if let Some(style) = highlighted_chunk.style {
Cow::Owned(text_style.clone().highlight(style))
} else {
Cow::Borrowed(text_style)
};
let run = TextRun {
len: x.len(),
font: text_style.font(),
color: text_style.color,
background_color: text_style.background_color,
underline: text_style.underline,
strikethrough: text_style.strikethrough,
};
let line_layout = cx
.text_system()
.shape_line(x, font_size, &[run])
.unwrap()
.with_len(highlighted_chunk.text.len());
width += line_layout.width;
len += highlighted_chunk.text.len();
fragments.push(LineFragment::Text(line_layout))
}
}
} else {
for (ix, mut line_chunk) in highlighted_chunk.text.split('\n').enumerate() {
if ix > 0 {
@@ -5167,16 +5205,15 @@ impl Element for EditorElement {
cx,
);
let mut gutter_fold_toggles =
cx.with_element_namespace("gutter_fold_toggles", |cx| {
self.layout_gutter_fold_toggles(
start_row..end_row,
buffer_rows.iter().copied(),
&active_rows,
&snapshot,
cx,
)
});
let mut crease_toggles = cx.with_element_namespace("crease_toggles", |cx| {
self.layout_crease_toggles(
start_row..end_row,
buffer_rows.iter().copied(),
&active_rows,
&snapshot,
cx,
)
});
let crease_trailers = cx.with_element_namespace("crease_trailers", |cx| {
self.layout_crease_trailers(buffer_rows.iter().copied(), &snapshot, cx)
});
@@ -5304,14 +5341,14 @@ impl Element for EditorElement {
)
});
let mut inline_blame = None;
let mut active_line_trailer = None;
if let Some(newest_selection_head) = newest_selection_head {
let display_row = newest_selection_head.row();
if (start_row..end_row).contains(&display_row) {
let line_ix = display_row.minus(start_row) as usize;
let line_layout = &line_layouts[line_ix];
let crease_trailer_layout = crease_trailers[line_ix].as_ref();
inline_blame = self.layout_inline_blame(
active_line_trailer = self.layout_active_line_trailer(
display_row,
&snapshot.display_snapshot,
line_layout,
@@ -5556,9 +5593,9 @@ impl Element for EditorElement {
let mouse_context_menu =
self.layout_mouse_context_menu(&snapshot, start_row..end_row, cx);
cx.with_element_namespace("gutter_fold_toggles", |cx| {
self.prepaint_gutter_fold_toggles(
&mut gutter_fold_toggles,
cx.with_element_namespace("crease_toggles", |cx| {
self.prepaint_crease_toggles(
&mut crease_toggles,
line_height,
&gutter_dimensions,
gutter_settings,
@@ -5630,7 +5667,7 @@ impl Element for EditorElement {
line_elements,
line_numbers,
blamed_display_rows,
inline_blame,
active_line_trailer,
blocks,
cursors,
visible_cursors,
@@ -5638,7 +5675,7 @@ impl Element for EditorElement {
mouse_context_menu,
test_indicators,
code_actions_indicator,
gutter_fold_toggles,
crease_toggles,
crease_trailers,
tab_invisible,
space_invisible,
@@ -5671,7 +5708,6 @@ impl Element for EditorElement {
line_height: Some(self.style.text.line_height),
..Default::default()
};
let mouse_position = cx.mouse_position();
let hovered_hunk = layout
.display_hunks
.iter()
@@ -5685,7 +5721,7 @@ impl Element for EditorElement {
} => {
if hunk_hitbox
.as_ref()
.map(|hitbox| hitbox.contains(&mouse_position))
.map(|hitbox| hitbox.is_hovered(cx))
.unwrap_or(false)
{
Some(HoveredHunk {
@@ -5768,7 +5804,7 @@ pub struct EditorLayout {
line_numbers: Vec<Option<ShapedLine>>,
display_hunks: Vec<(DisplayDiffHunk, Option<Hitbox>)>,
blamed_display_rows: Option<Vec<AnyElement>>,
inline_blame: Option<AnyElement>,
active_line_trailer: Option<AnyElement>,
blocks: Vec<BlockLayout>,
highlighted_ranges: Vec<(Range<DisplayPoint>, Hsla)>,
highlighted_gutter_ranges: Vec<(Range<DisplayPoint>, Hsla)>,
@@ -5778,7 +5814,7 @@ pub struct EditorLayout {
selections: Vec<(PlayerColor, Vec<SelectionLayout>)>,
code_actions_indicator: Option<AnyElement>,
test_indicators: Vec<AnyElement>,
gutter_fold_toggles: Vec<Option<AnyElement>>,
crease_toggles: Vec<Option<AnyElement>>,
crease_trailers: Vec<Option<CreaseTrailerLayout>>,
mouse_context_menu: Option<AnyElement>,
tab_invisible: ShapedLine,
@@ -5996,7 +6032,7 @@ fn layout_line(
let chunks = snapshot.highlighted_chunks(row..row + DisplayRow(1), true, style);
LineWithInvisibles::from_chunks(
chunks,
&style.text,
&style,
MAX_LINE_LEN,
1,
snapshot.mode,
@@ -6623,7 +6659,7 @@ mod tests {
style: BlockStyle::Fixed,
placement: BlockPlacement::Above(Anchor::min()),
height: 3,
render: Box::new(|cx| div().h(3. * cx.line_height()).into_any()),
render: Arc::new(|cx| div().h(3. * cx.line_height()).into_any()),
priority: 0,
}],
None,

View File

@@ -425,7 +425,7 @@ impl Editor {
height: 1,
style: BlockStyle::Sticky,
priority: 0,
render: Box::new({
render: Arc::new({
let editor = cx.view().clone();
let hunk = hunk.clone();
@@ -435,6 +435,7 @@ impl Editor {
h_flex()
.id(cx.block_id)
.block_mouse_down()
.h(cx.line_height())
.w_full()
.border_t_1()
@@ -707,12 +708,13 @@ impl Editor {
height,
style: BlockStyle::Flex,
priority: 0,
render: Box::new(move |cx| {
render: Arc::new(move |cx| {
let width = EditorElement::diff_hunk_strip_width(cx.line_height());
let gutter_dimensions = editor.read(cx.context).gutter_dimensions;
h_flex()
.id(cx.block_id)
.block_mouse_down()
.bg(deleted_hunk_color)
.h(height as f32 * cx.line_height())
.w_full()

View File

@@ -16,7 +16,8 @@ use gpui::{
VisualContext, WeakView, WindowContext,
};
use language::{
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, Point, SelectionGoal,
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, DiskState, Point,
SelectionGoal,
};
use lsp::DiagnosticSeverity;
use multi_buffer::AnchorRangeExt;
@@ -635,12 +636,21 @@ impl Item for Editor {
Some(util::truncate_and_trailoff(description, MAX_TAB_TITLE_LEN))
});
// Whether the file was saved in the past but is now deleted.
let was_deleted: bool = self
.buffer()
.read(cx)
.as_singleton()
.and_then(|buffer| buffer.read(cx).file())
.map_or(false, |file| file.disk_state() == DiskState::Deleted);
h_flex()
.gap_2()
.child(
Label::new(self.title(cx).to_string())
.color(label_color)
.italic(params.preview),
.italic(params.preview)
.strikethrough(was_deleted),
)
.when_some(description, |this, description| {
this.child(
@@ -700,6 +710,10 @@ impl Item for Editor {
self.buffer().read(cx).read(cx).is_dirty()
}
fn has_deleted_file(&self, cx: &AppContext) -> bool {
self.buffer().read(cx).read(cx).has_deleted_file()
}
fn has_conflict(&self, cx: &AppContext) -> bool {
self.buffer().read(cx).read(cx).has_conflict()
}

View File

@@ -3,7 +3,7 @@
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
use crate::{scroll::ScrollAnchor, CharKind, DisplayRow, EditorStyle, RowExt, ToOffset, ToPoint};
use gpui::{px, Pixels, WindowTextSystem};
use gpui::{Pixels, WindowTextSystem};
use language::Point;
use multi_buffer::{MultiBufferRow, MultiBufferSnapshot};
use serde::Deserialize;
@@ -120,7 +120,7 @@ pub(crate) fn up_by_rows(
preserve_column_at_start: bool,
text_layout_details: &TextLayoutDetails,
) -> (DisplayPoint, SelectionGoal) {
let mut goal_x = match goal {
let goal_x = match goal {
SelectionGoal::HorizontalPosition(x) => x.into(),
SelectionGoal::WrappedHorizontalPosition((_, x)) => x.into(),
SelectionGoal::HorizontalRange { end, .. } => end.into(),
@@ -138,7 +138,6 @@ pub(crate) fn up_by_rows(
return (start, goal);
} else {
point = DisplayPoint::new(DisplayRow(0), 0);
goal_x = px(0.);
}
let mut clipped_point = map.clip_point(point, Bias::Left);
@@ -159,7 +158,7 @@ pub(crate) fn down_by_rows(
preserve_column_at_end: bool,
text_layout_details: &TextLayoutDetails,
) -> (DisplayPoint, SelectionGoal) {
let mut goal_x = match goal {
let goal_x = match goal {
SelectionGoal::HorizontalPosition(x) => x.into(),
SelectionGoal::WrappedHorizontalPosition((_, x)) => x.into(),
SelectionGoal::HorizontalRange { end, .. } => end.into(),
@@ -174,7 +173,6 @@ pub(crate) fn down_by_rows(
return (start, goal);
} else {
point = map.max_point();
goal_x = map.x_for_display_point(point, text_layout_details)
}
let mut clipped_point = map.clip_point(point, Bias::Right);
@@ -610,7 +608,7 @@ mod tests {
test::{editor_test_context::EditorTestContext, marked_display_snapshot},
Buffer, DisplayMap, DisplayRow, ExcerptRange, FoldPlaceholder, InlayId, MultiBuffer,
};
use gpui::{font, Context as _};
use gpui::{font, px, Context as _};
use language::Capability;
use project::Project;
use settings::SettingsStore;
@@ -977,7 +975,7 @@ mod tests {
),
(
DisplayPoint::new(DisplayRow(2), 0),
SelectionGoal::HorizontalPosition(0.0)
SelectionGoal::HorizontalPosition(col_2_x.0),
),
);
assert_eq!(
@@ -990,7 +988,7 @@ mod tests {
),
(
DisplayPoint::new(DisplayRow(2), 0),
SelectionGoal::HorizontalPosition(0.0)
SelectionGoal::HorizontalPosition(0.0),
),
);
@@ -1059,7 +1057,7 @@ mod tests {
let max_point_x = snapshot
.x_for_display_point(DisplayPoint::new(DisplayRow(7), 2), &text_layout_details);
// Can't move down off the end
// Can't move down off the end, and attempting to do so leaves the selection goal unchanged
assert_eq!(
down(
&snapshot,
@@ -1070,7 +1068,7 @@ mod tests {
),
(
DisplayPoint::new(DisplayRow(7), 2),
SelectionGoal::HorizontalPosition(max_point_x.0)
SelectionGoal::HorizontalPosition(0.0)
),
);
assert_eq!(

View File

@@ -1,3 +1,5 @@
use std::{fs, path::Path};
use anyhow::Context as _;
use gpui::{Context, View, ViewContext, VisualContext, WindowContext};
use language::Language;
@@ -7,7 +9,7 @@ use text::ToPointUtf16;
use crate::{
element::register_action, lsp_ext::find_specific_language_server_in_selection, Editor,
ExpandMacroRecursively,
ExpandMacroRecursively, OpenDocs,
};
const RUST_ANALYZER_NAME: &str = "rust-analyzer";
@@ -24,6 +26,7 @@ pub fn apply_related_actions(editor: &View<Editor>, cx: &mut WindowContext) {
.is_some()
{
register_action(editor, cx, expand_macro_recursively);
register_action(editor, cx, open_docs);
}
}
@@ -94,3 +97,64 @@ pub fn expand_macro_recursively(
})
.detach_and_log_err(cx);
}
pub fn open_docs(editor: &mut Editor, _: &OpenDocs, cx: &mut ViewContext<'_, Editor>) {
if editor.selections.count() == 0 {
return;
}
let Some(project) = &editor.project else {
return;
};
let Some(workspace) = editor.workspace() else {
return;
};
let Some((trigger_anchor, _rust_language, server_to_query, buffer)) =
find_specific_language_server_in_selection(
editor,
cx,
is_rust_language,
RUST_ANALYZER_NAME,
)
else {
return;
};
let project = project.clone();
let buffer_snapshot = buffer.read(cx).snapshot();
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
let open_docs_task = project.update(cx, |project, cx| {
project.request_lsp(
buffer,
project::LanguageServerToQuery::Other(server_to_query),
project::lsp_ext_command::OpenDocs { position },
cx,
)
});
cx.spawn(|_editor, mut cx| async move {
let docs_urls = open_docs_task.await.context("open docs")?;
if docs_urls.is_empty() {
log::debug!("Empty docs urls for position {position:?}");
return Ok(());
} else {
log::debug!("{:?}", docs_urls);
}
workspace.update(&mut cx, |_workspace, cx| {
// Check if the local document exists, otherwise fallback to the online document.
// Open with the default browser.
if let Some(local_url) = docs_urls.local {
if fs::metadata(Path::new(&local_url[8..])).is_ok() {
cx.open_url(&local_url);
return;
}
}
if let Some(web_url) = docs_urls.web {
cx.open_url(&web_url);
}
})
})
.detach_and_log_err(cx);
}

View File

@@ -234,7 +234,16 @@ impl EditorLspTestContext {
..Default::default()
},
Some(tree_sitter_html::language()),
);
)
.with_queries(LanguageQueries {
brackets: Some(Cow::from(indoc! {r#"
("<" @open "/>" @close)
("</" @open ">" @close)
("<" @open ">" @close)
("\"" @open "\"" @close)"#})),
..Default::default()
})
.expect("Could not parse queries");
Self::new(language, Default::default(), cx).await
}

View File

@@ -1,17 +1,20 @@
pub mod extension_builder;
mod extension_manifest;
mod slash_command;
mod types;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use ::lsp::LanguageServerName;
use anyhow::{anyhow, bail, Context as _, Result};
use async_trait::async_trait;
use fs::normalize_path;
use gpui::Task;
use language::LanguageName;
use semantic_version::SemanticVersion;
pub use crate::extension_manifest::*;
pub use crate::slash_command::*;
pub use crate::types::*;
#[async_trait]
pub trait WorktreeDelegate: Send + Sync + 'static {
@@ -34,6 +37,43 @@ pub trait Extension: Send + Sync + 'static {
/// Returns the path to this extension's working directory.
fn work_dir(&self) -> Arc<Path>;
/// Returns a path relative to this extension's working directory.
fn path_from_extension(&self, path: &Path) -> PathBuf {
normalize_path(&self.work_dir().join(path))
}
async fn language_server_command(
&self,
language_server_id: LanguageServerName,
language_name: LanguageName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Command>;
async fn language_server_initialization_options(
&self,
language_server_id: LanguageServerName,
language_name: LanguageName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Option<String>>;
async fn language_server_workspace_configuration(
&self,
language_server_id: LanguageServerName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Option<String>>;
async fn labels_for_completions(
&self,
language_server_id: LanguageServerName,
completions: Vec<Completion>,
) -> Result<Vec<Option<CodeLabel>>>;
async fn labels_for_symbols(
&self,
language_server_id: LanguageServerName,
symbols: Vec<Symbol>,
) -> Result<Vec<Option<CodeLabel>>>;
async fn complete_slash_command_argument(
&self,
command: SlashCommand,
@@ -44,7 +84,7 @@ pub trait Extension: Send + Sync + 'static {
&self,
command: SlashCommand,
arguments: Vec<String>,
resource: Option<Arc<dyn WorktreeDelegate>>,
worktree: Option<Arc<dyn WorktreeDelegate>>,
) -> Result<SlashCommandOutput>;
async fn suggest_docs_packages(&self, provider: Arc<str>) -> Result<Vec<String>>;

View File

@@ -0,0 +1,49 @@
mod lsp;
mod slash_command;
use std::ops::Range;
pub use lsp::*;
pub use slash_command::*;
/// A list of environment variables.
pub type EnvVars = Vec<(String, String)>;
/// A command.
pub struct Command {
/// The command to execute.
pub command: String,
/// The arguments to pass to the command.
pub args: Vec<String>,
/// The environment variables to set for the command.
pub env: EnvVars,
}
/// A label containing some code.
#[derive(Debug, Clone)]
pub struct CodeLabel {
/// The source code to parse with Tree-sitter.
pub code: String,
/// The spans to display in the label.
pub spans: Vec<CodeLabelSpan>,
/// The range of the displayed label to include when filtering.
pub filter_range: Range<usize>,
}
/// A span within a code label.
#[derive(Debug, Clone)]
pub enum CodeLabelSpan {
/// A range into the parsed code.
CodeRange(Range<usize>),
/// A span containing a code literal.
Literal(CodeLabelSpanLiteral),
}
/// A span containing a code literal.
#[derive(Debug, Clone)]
pub struct CodeLabelSpanLiteral {
/// The literal text.
pub text: String,
/// The name of the highlight to use for this literal.
pub highlight_name: Option<String>,
}

View File

@@ -0,0 +1,96 @@
use std::option::Option;
/// An LSP completion.
#[derive(Debug, Clone)]
pub struct Completion {
pub label: String,
pub label_details: Option<CompletionLabelDetails>,
pub detail: Option<String>,
pub kind: Option<CompletionKind>,
pub insert_text_format: Option<InsertTextFormat>,
}
/// The kind of an LSP completion.
#[derive(Debug, Clone, Copy)]
pub enum CompletionKind {
Text,
Method,
Function,
Constructor,
Field,
Variable,
Class,
Interface,
Module,
Property,
Unit,
Value,
Enum,
Keyword,
Snippet,
Color,
File,
Reference,
Folder,
EnumMember,
Constant,
Struct,
Event,
Operator,
TypeParameter,
Other(i32),
}
/// Label details for an LSP completion.
#[derive(Debug, Clone)]
pub struct CompletionLabelDetails {
pub detail: Option<String>,
pub description: Option<String>,
}
/// Defines how to interpret the insert text in a completion item.
#[derive(Debug, Clone, Copy)]
pub enum InsertTextFormat {
PlainText,
Snippet,
Other(i32),
}
/// An LSP symbol.
#[derive(Debug, Clone)]
pub struct Symbol {
pub kind: SymbolKind,
pub name: String,
}
/// The kind of an LSP symbol.
#[derive(Debug, Clone, Copy)]
pub enum SymbolKind {
File,
Module,
Namespace,
Package,
Class,
Method,
Property,
Field,
Constructor,
Enum,
Interface,
Function,
Variable,
Constant,
String,
Number,
Boolean,
Array,
Object,
Key,
Null,
EnumMember,
Struct,
Event,
Operator,
TypeParameter,
Other(i32),
}

View File

@@ -5,7 +5,7 @@ pub mod wasm_host;
#[cfg(test)]
mod extension_store_test;
use crate::{extension_lsp_adapter::ExtensionLspAdapter, wasm_host::wit};
use crate::extension_lsp_adapter::ExtensionLspAdapter;
use anyhow::{anyhow, bail, Context as _, Result};
use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
@@ -1238,13 +1238,9 @@ impl ExtensionStore {
this.registration_hooks.register_lsp_adapter(
language.clone(),
ExtensionLspAdapter {
extension: wasm_extension.clone(),
host: this.wasm_host.clone(),
extension: extension.clone(),
language_server_id: language_server_id.clone(),
config: wit::LanguageServerConfig {
name: language_server_id.0.to_string(),
language_name: language.to_string(),
},
language_name: language.clone(),
},
);
}

View File

@@ -1,15 +1,12 @@
use crate::wasm_host::{
wit::{self, LanguageServerConfig},
WasmExtension, WasmHost,
};
use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result};
use async_trait::async_trait;
use collections::HashMap;
use extension::WorktreeDelegate;
use extension::{Extension, WorktreeDelegate};
use futures::{Future, FutureExt};
use gpui::AsyncAppContext;
use language::{
CodeLabel, HighlightId, Language, LanguageToolchainStore, LspAdapter, LspAdapterDelegate,
CodeLabel, HighlightId, Language, LanguageName, LanguageToolchainStore, LspAdapter,
LspAdapterDelegate,
};
use lsp::{CodeActionKind, LanguageServerBinary, LanguageServerBinaryOptions, LanguageServerName};
use serde::Serialize;
@@ -17,7 +14,6 @@ use serde_json::Value;
use std::ops::Range;
use std::{any::Any, path::PathBuf, pin::Pin, sync::Arc};
use util::{maybe, ResultExt};
use wasmtime_wasi::WasiView as _;
/// An adapter that allows an [`LspAdapterDelegate`] to be used as a [`WorktreeDelegate`].
pub struct WorktreeDelegateAdapter(pub Arc<dyn LspAdapterDelegate>);
@@ -49,16 +45,15 @@ impl WorktreeDelegate for WorktreeDelegateAdapter {
}
pub struct ExtensionLspAdapter {
pub(crate) extension: WasmExtension,
pub(crate) extension: Arc<dyn Extension>,
pub(crate) language_server_id: LanguageServerName,
pub(crate) config: LanguageServerConfig,
pub(crate) host: Arc<WasmHost>,
pub(crate) language_name: LanguageName,
}
#[async_trait(?Send)]
impl LspAdapter for ExtensionLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(self.config.name.clone().into())
self.language_server_id.clone()
}
fn get_language_server_command<'a>(
@@ -69,33 +64,17 @@ impl LspAdapter for ExtensionLspAdapter {
_: &'a mut AsyncAppContext,
) -> Pin<Box<dyn 'a + Future<Output = Result<LanguageServerBinary>>>> {
async move {
let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _;
let command = self
.extension
.call({
let this = self.clone();
|extension, store| {
async move {
let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _;
let resource = store.data_mut().table().push(delegate)?;
let command = extension
.call_language_server_command(
store,
&this.language_server_id,
&this.config,
resource,
)
.await?
.map_err(|e| anyhow!("{}", e))?;
anyhow::Ok(command)
}
.boxed()
}
})
.language_server_command(
self.language_server_id.clone(),
self.language_name.clone(),
delegate,
)
.await?;
let path = self
.host
.path_from_extension(&self.extension.manifest.id, command.command.as_ref());
let path = self.extension.path_from_extension(command.command.as_ref());
// TODO: This should now be done via the `zed::make_file_executable` function in
// Zed extension API, but we're leaving these existing usages in place temporarily
@@ -104,8 +83,8 @@ impl LspAdapter for ExtensionLspAdapter {
// We can remove once the following extension versions no longer see any use:
// - toml@0.0.2
// - zig@0.0.1
if ["toml", "zig"].contains(&self.extension.manifest.id.as_ref())
&& path.starts_with(&self.host.work_dir)
if ["toml", "zig"].contains(&self.extension.manifest().id.as_ref())
&& path.starts_with(&self.extension.work_dir())
{
#[cfg(not(windows))]
{
@@ -153,7 +132,7 @@ impl LspAdapter for ExtensionLspAdapter {
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
let code_action_kinds = self
.extension
.manifest
.manifest()
.language_servers
.get(&self.language_server_id)
.and_then(|server| server.code_action_kinds.clone());
@@ -174,14 +153,14 @@ impl LspAdapter for ExtensionLspAdapter {
//
// We can remove once the following extension versions no longer see any use:
// - php@0.0.1
if self.extension.manifest.id.as_ref() == "php" {
if self.extension.manifest().id.as_ref() == "php" {
return HashMap::from_iter([("PHP".into(), "php".into())]);
}
self.extension
.manifest
.manifest()
.language_servers
.get(&LanguageServerName(self.config.name.clone().into()))
.get(&self.language_server_id)
.map(|server| server.language_ids.clone())
.unwrap_or_default()
}
@@ -190,29 +169,14 @@ impl LspAdapter for ExtensionLspAdapter {
self: Arc<Self>,
delegate: &Arc<dyn LspAdapterDelegate>,
) -> Result<Option<serde_json::Value>> {
let delegate = delegate.clone();
let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _;
let json_options = self
.extension
.call({
let this = self.clone();
|extension, store| {
async move {
let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _;
let resource = store.data_mut().table().push(delegate)?;
let options = extension
.call_language_server_initialization_options(
store,
&this.language_server_id,
&this.config,
resource,
)
.await?
.map_err(|e| anyhow!("{}", e))?;
anyhow::Ok(options)
}
.boxed()
}
})
.language_server_initialization_options(
self.language_server_id.clone(),
self.language_name.clone(),
delegate,
)
.await?;
Ok(if let Some(json_options) = json_options {
serde_json::from_str(&json_options).with_context(|| {
@@ -229,32 +193,14 @@ impl LspAdapter for ExtensionLspAdapter {
_: Arc<dyn LanguageToolchainStore>,
_cx: &mut AsyncAppContext,
) -> Result<Value> {
let delegate = delegate.clone();
let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _;
let json_options: Option<String> = self
.extension
.call({
let this = self.clone();
|extension, store| {
async move {
let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _;
let resource = store.data_mut().table().push(delegate)?;
let options = extension
.call_language_server_workspace_configuration(
store,
&this.language_server_id,
resource,
)
.await?
.map_err(|e| anyhow!("{}", e))?;
anyhow::Ok(options)
}
.boxed()
}
})
.language_server_workspace_configuration(self.language_server_id.clone(), delegate)
.await?;
Ok(if let Some(json_options) = json_options {
serde_json::from_str(&json_options).with_context(|| {
format!("failed to parse initialization_options from extension: {json_options}")
format!("failed to parse workspace_configuration from extension: {json_options}")
})?
} else {
serde_json::json!({})
@@ -268,30 +214,16 @@ impl LspAdapter for ExtensionLspAdapter {
) -> Result<Vec<Option<CodeLabel>>> {
let completions = completions
.iter()
.map(|completion| wit::Completion::from(completion.clone()))
.cloned()
.map(lsp_completion_to_extension)
.collect::<Vec<_>>();
let labels = self
.extension
.call({
let this = self.clone();
|extension, store| {
async move {
extension
.call_labels_for_completions(
store,
&this.language_server_id,
completions,
)
.await?
.map_err(|e| anyhow!("{}", e))
}
.boxed()
}
})
.labels_for_completions(self.language_server_id.clone(), completions)
.await?;
Ok(labels_from_wit(labels, language))
Ok(labels_from_extension(labels, language))
}
async fn labels_for_symbols(
@@ -302,34 +234,29 @@ impl LspAdapter for ExtensionLspAdapter {
let symbols = symbols
.iter()
.cloned()
.map(|(name, kind)| wit::Symbol {
.map(|(name, kind)| extension::Symbol {
name,
kind: kind.into(),
kind: lsp_symbol_kind_to_extension(kind),
})
.collect::<Vec<_>>();
let labels = self
.extension
.call({
let this = self.clone();
|extension, store| {
async move {
extension
.call_labels_for_symbols(store, &this.language_server_id, symbols)
.await?
.map_err(|e| anyhow!("{}", e))
}
.boxed()
}
})
.labels_for_symbols(self.language_server_id.clone(), symbols)
.await?;
Ok(labels_from_wit(labels, language))
Ok(labels_from_extension(
labels
.into_iter()
.map(|label| label.map(Into::into))
.collect(),
language,
))
}
}
fn labels_from_wit(
labels: Vec<Option<wit::CodeLabel>>,
fn labels_from_extension(
labels: Vec<Option<extension::CodeLabel>>,
language: &Arc<Language>,
) -> Vec<Option<CodeLabel>> {
labels
@@ -347,7 +274,7 @@ fn labels_from_wit(
}
fn build_code_label(
label: &wit::CodeLabel,
label: &extension::CodeLabel,
parsed_runs: &[(Range<usize>, HighlightId)],
language: &Arc<Language>,
) -> Option<CodeLabel> {
@@ -356,8 +283,7 @@ fn build_code_label(
for span in &label.spans {
match span {
wit::CodeLabelSpan::CodeRange(range) => {
let range = Range::from(*range);
extension::CodeLabelSpan::CodeRange(range) => {
let code_span = &label.code.get(range.clone())?;
let mut input_ix = range.start;
let mut output_ix = text.len();
@@ -383,7 +309,7 @@ fn build_code_label(
text.push_str(code_span);
}
wit::CodeLabelSpan::Literal(span) => {
extension::CodeLabelSpan::Literal(span) => {
let highlight_id = language
.grammar()
.zip(span.highlight_name.as_ref())
@@ -398,7 +324,7 @@ fn build_code_label(
}
}
let filter_range = Range::from(label.filter_range);
let filter_range = label.filter_range.clone();
text.get(filter_range.clone())?;
Some(CodeLabel {
text,
@@ -407,109 +333,101 @@ fn build_code_label(
})
}
impl From<wit::Range> for Range<usize> {
fn from(range: wit::Range) -> Self {
let start = range.start as usize;
let end = range.end as usize;
start..end
fn lsp_completion_to_extension(value: lsp::CompletionItem) -> extension::Completion {
extension::Completion {
label: value.label,
label_details: value
.label_details
.map(lsp_completion_item_label_details_to_extension),
detail: value.detail,
kind: value.kind.map(lsp_completion_item_kind_to_extension),
insert_text_format: value
.insert_text_format
.map(lsp_insert_text_format_to_extension),
}
}
impl From<lsp::CompletionItem> for wit::Completion {
fn from(value: lsp::CompletionItem) -> Self {
Self {
label: value.label,
label_details: value.label_details.map(Into::into),
detail: value.detail,
kind: value.kind.map(Into::into),
insert_text_format: value.insert_text_format.map(Into::into),
}
fn lsp_completion_item_label_details_to_extension(
value: lsp::CompletionItemLabelDetails,
) -> extension::CompletionLabelDetails {
extension::CompletionLabelDetails {
detail: value.detail,
description: value.description,
}
}
impl From<lsp::CompletionItemLabelDetails> for wit::CompletionLabelDetails {
fn from(value: lsp::CompletionItemLabelDetails) -> Self {
Self {
detail: value.detail,
description: value.description,
}
fn lsp_completion_item_kind_to_extension(
value: lsp::CompletionItemKind,
) -> extension::CompletionKind {
match value {
lsp::CompletionItemKind::TEXT => extension::CompletionKind::Text,
lsp::CompletionItemKind::METHOD => extension::CompletionKind::Method,
lsp::CompletionItemKind::FUNCTION => extension::CompletionKind::Function,
lsp::CompletionItemKind::CONSTRUCTOR => extension::CompletionKind::Constructor,
lsp::CompletionItemKind::FIELD => extension::CompletionKind::Field,
lsp::CompletionItemKind::VARIABLE => extension::CompletionKind::Variable,
lsp::CompletionItemKind::CLASS => extension::CompletionKind::Class,
lsp::CompletionItemKind::INTERFACE => extension::CompletionKind::Interface,
lsp::CompletionItemKind::MODULE => extension::CompletionKind::Module,
lsp::CompletionItemKind::PROPERTY => extension::CompletionKind::Property,
lsp::CompletionItemKind::UNIT => extension::CompletionKind::Unit,
lsp::CompletionItemKind::VALUE => extension::CompletionKind::Value,
lsp::CompletionItemKind::ENUM => extension::CompletionKind::Enum,
lsp::CompletionItemKind::KEYWORD => extension::CompletionKind::Keyword,
lsp::CompletionItemKind::SNIPPET => extension::CompletionKind::Snippet,
lsp::CompletionItemKind::COLOR => extension::CompletionKind::Color,
lsp::CompletionItemKind::FILE => extension::CompletionKind::File,
lsp::CompletionItemKind::REFERENCE => extension::CompletionKind::Reference,
lsp::CompletionItemKind::FOLDER => extension::CompletionKind::Folder,
lsp::CompletionItemKind::ENUM_MEMBER => extension::CompletionKind::EnumMember,
lsp::CompletionItemKind::CONSTANT => extension::CompletionKind::Constant,
lsp::CompletionItemKind::STRUCT => extension::CompletionKind::Struct,
lsp::CompletionItemKind::EVENT => extension::CompletionKind::Event,
lsp::CompletionItemKind::OPERATOR => extension::CompletionKind::Operator,
lsp::CompletionItemKind::TYPE_PARAMETER => extension::CompletionKind::TypeParameter,
_ => extension::CompletionKind::Other(extract_int(value)),
}
}
impl From<lsp::CompletionItemKind> for wit::CompletionKind {
fn from(value: lsp::CompletionItemKind) -> Self {
match value {
lsp::CompletionItemKind::TEXT => Self::Text,
lsp::CompletionItemKind::METHOD => Self::Method,
lsp::CompletionItemKind::FUNCTION => Self::Function,
lsp::CompletionItemKind::CONSTRUCTOR => Self::Constructor,
lsp::CompletionItemKind::FIELD => Self::Field,
lsp::CompletionItemKind::VARIABLE => Self::Variable,
lsp::CompletionItemKind::CLASS => Self::Class,
lsp::CompletionItemKind::INTERFACE => Self::Interface,
lsp::CompletionItemKind::MODULE => Self::Module,
lsp::CompletionItemKind::PROPERTY => Self::Property,
lsp::CompletionItemKind::UNIT => Self::Unit,
lsp::CompletionItemKind::VALUE => Self::Value,
lsp::CompletionItemKind::ENUM => Self::Enum,
lsp::CompletionItemKind::KEYWORD => Self::Keyword,
lsp::CompletionItemKind::SNIPPET => Self::Snippet,
lsp::CompletionItemKind::COLOR => Self::Color,
lsp::CompletionItemKind::FILE => Self::File,
lsp::CompletionItemKind::REFERENCE => Self::Reference,
lsp::CompletionItemKind::FOLDER => Self::Folder,
lsp::CompletionItemKind::ENUM_MEMBER => Self::EnumMember,
lsp::CompletionItemKind::CONSTANT => Self::Constant,
lsp::CompletionItemKind::STRUCT => Self::Struct,
lsp::CompletionItemKind::EVENT => Self::Event,
lsp::CompletionItemKind::OPERATOR => Self::Operator,
lsp::CompletionItemKind::TYPE_PARAMETER => Self::TypeParameter,
_ => Self::Other(extract_int(value)),
}
fn lsp_insert_text_format_to_extension(
value: lsp::InsertTextFormat,
) -> extension::InsertTextFormat {
match value {
lsp::InsertTextFormat::PLAIN_TEXT => extension::InsertTextFormat::PlainText,
lsp::InsertTextFormat::SNIPPET => extension::InsertTextFormat::Snippet,
_ => extension::InsertTextFormat::Other(extract_int(value)),
}
}
impl From<lsp::InsertTextFormat> for wit::InsertTextFormat {
fn from(value: lsp::InsertTextFormat) -> Self {
match value {
lsp::InsertTextFormat::PLAIN_TEXT => Self::PlainText,
lsp::InsertTextFormat::SNIPPET => Self::Snippet,
_ => Self::Other(extract_int(value)),
}
}
}
impl From<lsp::SymbolKind> for wit::SymbolKind {
fn from(value: lsp::SymbolKind) -> Self {
match value {
lsp::SymbolKind::FILE => Self::File,
lsp::SymbolKind::MODULE => Self::Module,
lsp::SymbolKind::NAMESPACE => Self::Namespace,
lsp::SymbolKind::PACKAGE => Self::Package,
lsp::SymbolKind::CLASS => Self::Class,
lsp::SymbolKind::METHOD => Self::Method,
lsp::SymbolKind::PROPERTY => Self::Property,
lsp::SymbolKind::FIELD => Self::Field,
lsp::SymbolKind::CONSTRUCTOR => Self::Constructor,
lsp::SymbolKind::ENUM => Self::Enum,
lsp::SymbolKind::INTERFACE => Self::Interface,
lsp::SymbolKind::FUNCTION => Self::Function,
lsp::SymbolKind::VARIABLE => Self::Variable,
lsp::SymbolKind::CONSTANT => Self::Constant,
lsp::SymbolKind::STRING => Self::String,
lsp::SymbolKind::NUMBER => Self::Number,
lsp::SymbolKind::BOOLEAN => Self::Boolean,
lsp::SymbolKind::ARRAY => Self::Array,
lsp::SymbolKind::OBJECT => Self::Object,
lsp::SymbolKind::KEY => Self::Key,
lsp::SymbolKind::NULL => Self::Null,
lsp::SymbolKind::ENUM_MEMBER => Self::EnumMember,
lsp::SymbolKind::STRUCT => Self::Struct,
lsp::SymbolKind::EVENT => Self::Event,
lsp::SymbolKind::OPERATOR => Self::Operator,
lsp::SymbolKind::TYPE_PARAMETER => Self::TypeParameter,
_ => Self::Other(extract_int(value)),
}
fn lsp_symbol_kind_to_extension(value: lsp::SymbolKind) -> extension::SymbolKind {
match value {
lsp::SymbolKind::FILE => extension::SymbolKind::File,
lsp::SymbolKind::MODULE => extension::SymbolKind::Module,
lsp::SymbolKind::NAMESPACE => extension::SymbolKind::Namespace,
lsp::SymbolKind::PACKAGE => extension::SymbolKind::Package,
lsp::SymbolKind::CLASS => extension::SymbolKind::Class,
lsp::SymbolKind::METHOD => extension::SymbolKind::Method,
lsp::SymbolKind::PROPERTY => extension::SymbolKind::Property,
lsp::SymbolKind::FIELD => extension::SymbolKind::Field,
lsp::SymbolKind::CONSTRUCTOR => extension::SymbolKind::Constructor,
lsp::SymbolKind::ENUM => extension::SymbolKind::Enum,
lsp::SymbolKind::INTERFACE => extension::SymbolKind::Interface,
lsp::SymbolKind::FUNCTION => extension::SymbolKind::Function,
lsp::SymbolKind::VARIABLE => extension::SymbolKind::Variable,
lsp::SymbolKind::CONSTANT => extension::SymbolKind::Constant,
lsp::SymbolKind::STRING => extension::SymbolKind::String,
lsp::SymbolKind::NUMBER => extension::SymbolKind::Number,
lsp::SymbolKind::BOOLEAN => extension::SymbolKind::Boolean,
lsp::SymbolKind::ARRAY => extension::SymbolKind::Array,
lsp::SymbolKind::OBJECT => extension::SymbolKind::Object,
lsp::SymbolKind::KEY => extension::SymbolKind::Key,
lsp::SymbolKind::NULL => extension::SymbolKind::Null,
lsp::SymbolKind::ENUM_MEMBER => extension::SymbolKind::EnumMember,
lsp::SymbolKind::STRUCT => extension::SymbolKind::Struct,
lsp::SymbolKind::EVENT => extension::SymbolKind::Event,
lsp::SymbolKind::OPERATOR => extension::SymbolKind::Operator,
lsp::SymbolKind::TYPE_PARAMETER => extension::SymbolKind::TypeParameter,
_ => extension::SymbolKind::Other(extract_int(value)),
}
}
@@ -536,21 +454,14 @@ fn test_build_code_label() {
.collect::<Vec<_>>();
let label = build_code_label(
&wit::CodeLabel {
&extension::CodeLabel {
spans: vec![
wit::CodeLabelSpan::CodeRange(wit::Range {
start: code.find("pqrs").unwrap() as u32,
end: code.len() as u32,
}),
wit::CodeLabelSpan::CodeRange(wit::Range {
start: code.find(": fn").unwrap() as u32,
end: code.find(" = ").unwrap() as u32,
}),
extension::CodeLabelSpan::CodeRange(code.find("pqrs").unwrap()..code.len()),
extension::CodeLabelSpan::CodeRange(
code.find(": fn").unwrap()..code.find(" = ").unwrap(),
),
],
filter_range: wit::Range {
start: 0,
end: "pqrs.tuv".len() as u32,
},
filter_range: 0.."pqrs.tuv".len(),
code,
},
&code_runs,
@@ -588,21 +499,14 @@ fn test_build_code_label_with_invalid_ranges() {
// A span uses a code range that is invalid because it starts inside of
// a multi-byte character.
let label = build_code_label(
&wit::CodeLabel {
&extension::CodeLabel {
spans: vec![
wit::CodeLabelSpan::CodeRange(wit::Range {
start: code.find('B').unwrap() as u32,
end: code.find(" = ").unwrap() as u32,
}),
wit::CodeLabelSpan::CodeRange(wit::Range {
start: code.find('🏀').unwrap() as u32 + 1,
end: code.len() as u32,
}),
extension::CodeLabelSpan::CodeRange(
code.find('B').unwrap()..code.find(" = ").unwrap(),
),
extension::CodeLabelSpan::CodeRange((code.find('🏀').unwrap() + 1)..code.len()),
],
filter_range: wit::Range {
start: 0,
end: "B".len() as u32,
},
filter_range: 0.."B".len(),
code,
},
&code_runs,
@@ -612,12 +516,14 @@ fn test_build_code_label_with_invalid_ranges() {
// Filter range extends beyond actual text
let label = build_code_label(
&wit::CodeLabel {
spans: vec![wit::CodeLabelSpan::Literal(wit::CodeLabelSpanLiteral {
text: "abc".into(),
highlight_name: Some("type".into()),
})],
filter_range: wit::Range { start: 0, end: 5 },
&extension::CodeLabel {
spans: vec![extension::CodeLabelSpan::Literal(
extension::CodeLabelSpanLiteral {
text: "abc".into(),
highlight_name: Some("type".into()),
},
)],
filter_range: 0..5,
code: String::new(),
},
&code_runs,

View File

@@ -4,8 +4,8 @@ use crate::{ExtensionManifest, ExtensionRegistrationHooks};
use anyhow::{anyhow, bail, Context as _, Result};
use async_trait::async_trait;
use extension::{
KeyValueStoreDelegate, SlashCommand, SlashCommandArgumentCompletion, SlashCommandOutput,
WorktreeDelegate,
CodeLabel, Command, Completion, KeyValueStoreDelegate, SlashCommand,
SlashCommandArgumentCompletion, SlashCommandOutput, Symbol, WorktreeDelegate,
};
use fs::{normalize_path, Fs};
use futures::future::LocalBoxFuture;
@@ -19,6 +19,8 @@ use futures::{
};
use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task};
use http_client::HttpClient;
use language::LanguageName;
use lsp::LanguageServerName;
use node_runtime::NodeRuntime;
use release_channel::ReleaseChannel;
use semantic_version::SemanticVersion;
@@ -65,6 +67,132 @@ impl extension::Extension for WasmExtension {
self.work_dir.clone()
}
async fn language_server_command(
&self,
language_server_id: LanguageServerName,
language_name: LanguageName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Command> {
self.call(|extension, store| {
async move {
let resource = store.data_mut().table().push(worktree)?;
let command = extension
.call_language_server_command(
store,
&language_server_id,
&language_name,
resource,
)
.await?
.map_err(|err| anyhow!("{err}"))?;
Ok(command.into())
}
.boxed()
})
.await
}
async fn language_server_initialization_options(
&self,
language_server_id: LanguageServerName,
language_name: LanguageName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Option<String>> {
self.call(|extension, store| {
async move {
let resource = store.data_mut().table().push(worktree)?;
let options = extension
.call_language_server_initialization_options(
store,
&language_server_id,
&language_name,
resource,
)
.await?
.map_err(|err| anyhow!("{err}"))?;
anyhow::Ok(options)
}
.boxed()
})
.await
}
async fn language_server_workspace_configuration(
&self,
language_server_id: LanguageServerName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Option<String>> {
self.call(|extension, store| {
async move {
let resource = store.data_mut().table().push(worktree)?;
let options = extension
.call_language_server_workspace_configuration(
store,
&language_server_id,
resource,
)
.await?
.map_err(|err| anyhow!("{err}"))?;
anyhow::Ok(options)
}
.boxed()
})
.await
}
async fn labels_for_completions(
&self,
language_server_id: LanguageServerName,
completions: Vec<Completion>,
) -> Result<Vec<Option<CodeLabel>>> {
self.call(|extension, store| {
async move {
let labels = extension
.call_labels_for_completions(
store,
&language_server_id,
completions.into_iter().map(Into::into).collect(),
)
.await?
.map_err(|err| anyhow!("{err}"))?;
Ok(labels
.into_iter()
.map(|label| label.map(Into::into))
.collect())
}
.boxed()
})
.await
}
async fn labels_for_symbols(
&self,
language_server_id: LanguageServerName,
symbols: Vec<Symbol>,
) -> Result<Vec<Option<CodeLabel>>> {
self.call(|extension, store| {
async move {
let labels = extension
.call_labels_for_symbols(
store,
&language_server_id,
symbols.into_iter().map(Into::into).collect(),
)
.await?
.map_err(|err| anyhow!("{err}"))?;
Ok(labels
.into_iter()
.map(|label| label.map(Into::into))
.collect())
}
.boxed()
})
.await
}
async fn complete_slash_command_argument(
&self,
command: SlashCommand,
@@ -255,7 +383,7 @@ impl WasmHost {
Ok(WasmExtension {
manifest: manifest.clone(),
work_dir: this.work_dir.clone().into(),
work_dir: this.work_dir.join(manifest.id.as_ref()).into(),
tx,
zed_api_version,
})
@@ -286,11 +414,6 @@ impl WasmHost {
.build())
}
pub fn path_from_extension(&self, id: &Arc<str>, path: &Path) -> PathBuf {
let extension_work_dir = self.work_dir.join(id.as_ref());
normalize_path(&extension_work_dir.join(path))
}
pub fn writeable_path_from_extension(&self, id: &Arc<str>, path: &Path) -> Result<PathBuf> {
let extension_work_dir = self.work_dir.join(id.as_ref());
let path = normalize_path(&extension_work_dir.join(path));

View File

@@ -4,6 +4,7 @@ mod since_v0_0_6;
mod since_v0_1_0;
mod since_v0_2_0;
use extension::{KeyValueStoreDelegate, WorktreeDelegate};
use language::LanguageName;
use lsp::LanguageServerName;
use release_channel::ReleaseChannel;
use since_v0_2_0 as latest;
@@ -163,7 +164,7 @@ impl Extension {
&self,
store: &mut Store<WasmState>,
language_server_id: &LanguageServerName,
config: &LanguageServerConfig,
language_name: &LanguageName,
resource: Resource<Arc<dyn WorktreeDelegate>>,
) -> Result<Result<Command, String>> {
match self {
@@ -180,11 +181,26 @@ impl Extension {
.await?
.map(|command| command.into())),
Extension::V004(ext) => Ok(ext
.call_language_server_command(store, config, resource)
.call_language_server_command(
store,
&LanguageServerConfig {
name: language_server_id.0.to_string(),
language_name: language_name.to_string(),
},
resource,
)
.await?
.map(|command| command.into())),
Extension::V001(ext) => Ok(ext
.call_language_server_command(store, &config.clone().into(), resource)
.call_language_server_command(
store,
&LanguageServerConfig {
name: language_server_id.0.to_string(),
language_name: language_name.to_string(),
}
.into(),
resource,
)
.await?
.map(|command| command.into())),
}
@@ -194,7 +210,7 @@ impl Extension {
&self,
store: &mut Store<WasmState>,
language_server_id: &LanguageServerName,
config: &LanguageServerConfig,
language_name: &LanguageName,
resource: Resource<Arc<dyn WorktreeDelegate>>,
) -> Result<Result<Option<String>, String>> {
match self {
@@ -223,13 +239,24 @@ impl Extension {
.await
}
Extension::V004(ext) => {
ext.call_language_server_initialization_options(store, config, resource)
.await
ext.call_language_server_initialization_options(
store,
&LanguageServerConfig {
name: language_server_id.0.to_string(),
language_name: language_name.to_string(),
},
resource,
)
.await
}
Extension::V001(ext) => {
ext.call_language_server_initialization_options(
store,
&config.clone().into(),
&LanguageServerConfig {
name: language_server_id.0.to_string(),
language_name: language_name.to_string(),
}
.into(),
resource,
)
.await

View File

@@ -1,4 +1,5 @@
use crate::wasm_host::wit::since_v0_2_0::slash_command::SlashCommandOutputSection;
use crate::wasm_host::wit::{CompletionKind, CompletionLabelDetails, InsertTextFormat, SymbolKind};
use crate::wasm_host::{wit::ToWasmtimeResult, WasmState};
use ::http_client::{AsyncBody, HttpRequestExt};
use ::settings::{Settings, WorktreeId};
@@ -55,6 +56,159 @@ pub fn linker() -> &'static Linker<WasmState> {
LINKER.get_or_init(|| super::new_linker(Extension::add_to_linker))
}
impl From<Range> for std::ops::Range<usize> {
fn from(range: Range) -> Self {
let start = range.start as usize;
let end = range.end as usize;
start..end
}
}
impl From<Command> for extension::Command {
fn from(value: Command) -> Self {
Self {
command: value.command,
args: value.args,
env: value.env,
}
}
}
impl From<CodeLabel> for extension::CodeLabel {
fn from(value: CodeLabel) -> Self {
Self {
code: value.code,
spans: value.spans.into_iter().map(Into::into).collect(),
filter_range: value.filter_range.into(),
}
}
}
impl From<CodeLabelSpan> for extension::CodeLabelSpan {
fn from(value: CodeLabelSpan) -> Self {
match value {
CodeLabelSpan::CodeRange(range) => Self::CodeRange(range.into()),
CodeLabelSpan::Literal(literal) => Self::Literal(literal.into()),
}
}
}
impl From<CodeLabelSpanLiteral> for extension::CodeLabelSpanLiteral {
fn from(value: CodeLabelSpanLiteral) -> Self {
Self {
text: value.text,
highlight_name: value.highlight_name,
}
}
}
impl From<extension::Completion> for Completion {
fn from(value: extension::Completion) -> Self {
Self {
label: value.label,
label_details: value.label_details.map(Into::into),
detail: value.detail,
kind: value.kind.map(Into::into),
insert_text_format: value.insert_text_format.map(Into::into),
}
}
}
impl From<extension::CompletionLabelDetails> for CompletionLabelDetails {
fn from(value: extension::CompletionLabelDetails) -> Self {
Self {
detail: value.detail,
description: value.description,
}
}
}
impl From<extension::CompletionKind> for CompletionKind {
fn from(value: extension::CompletionKind) -> Self {
match value {
extension::CompletionKind::Text => Self::Text,
extension::CompletionKind::Method => Self::Method,
extension::CompletionKind::Function => Self::Function,
extension::CompletionKind::Constructor => Self::Constructor,
extension::CompletionKind::Field => Self::Field,
extension::CompletionKind::Variable => Self::Variable,
extension::CompletionKind::Class => Self::Class,
extension::CompletionKind::Interface => Self::Interface,
extension::CompletionKind::Module => Self::Module,
extension::CompletionKind::Property => Self::Property,
extension::CompletionKind::Unit => Self::Unit,
extension::CompletionKind::Value => Self::Value,
extension::CompletionKind::Enum => Self::Enum,
extension::CompletionKind::Keyword => Self::Keyword,
extension::CompletionKind::Snippet => Self::Snippet,
extension::CompletionKind::Color => Self::Color,
extension::CompletionKind::File => Self::File,
extension::CompletionKind::Reference => Self::Reference,
extension::CompletionKind::Folder => Self::Folder,
extension::CompletionKind::EnumMember => Self::EnumMember,
extension::CompletionKind::Constant => Self::Constant,
extension::CompletionKind::Struct => Self::Struct,
extension::CompletionKind::Event => Self::Event,
extension::CompletionKind::Operator => Self::Operator,
extension::CompletionKind::TypeParameter => Self::TypeParameter,
extension::CompletionKind::Other(value) => Self::Other(value),
}
}
}
impl From<extension::InsertTextFormat> for InsertTextFormat {
fn from(value: extension::InsertTextFormat) -> Self {
match value {
extension::InsertTextFormat::PlainText => Self::PlainText,
extension::InsertTextFormat::Snippet => Self::Snippet,
extension::InsertTextFormat::Other(value) => Self::Other(value),
}
}
}
impl From<extension::Symbol> for Symbol {
fn from(value: extension::Symbol) -> Self {
Self {
kind: value.kind.into(),
name: value.name,
}
}
}
impl From<extension::SymbolKind> for SymbolKind {
fn from(value: extension::SymbolKind) -> Self {
match value {
extension::SymbolKind::File => Self::File,
extension::SymbolKind::Module => Self::Module,
extension::SymbolKind::Namespace => Self::Namespace,
extension::SymbolKind::Package => Self::Package,
extension::SymbolKind::Class => Self::Class,
extension::SymbolKind::Method => Self::Method,
extension::SymbolKind::Property => Self::Property,
extension::SymbolKind::Field => Self::Field,
extension::SymbolKind::Constructor => Self::Constructor,
extension::SymbolKind::Enum => Self::Enum,
extension::SymbolKind::Interface => Self::Interface,
extension::SymbolKind::Function => Self::Function,
extension::SymbolKind::Variable => Self::Variable,
extension::SymbolKind::Constant => Self::Constant,
extension::SymbolKind::String => Self::String,
extension::SymbolKind::Number => Self::Number,
extension::SymbolKind::Boolean => Self::Boolean,
extension::SymbolKind::Array => Self::Array,
extension::SymbolKind::Object => Self::Object,
extension::SymbolKind::Key => Self::Key,
extension::SymbolKind::Null => Self::Null,
extension::SymbolKind::EnumMember => Self::EnumMember,
extension::SymbolKind::Struct => Self::Struct,
extension::SymbolKind::Event => Self::Event,
extension::SymbolKind::Operator => Self::Operator,
extension::SymbolKind::TypeParameter => Self::TypeParameter,
extension::SymbolKind::Other(value) => Self::Other(value),
}
}
}
impl From<extension::SlashCommand> for SlashCommand {
fn from(value: extension::SlashCommand) -> Self {
Self {

View File

@@ -10,11 +10,11 @@ pub use open_path_prompt::OpenPathDelegate;
use collections::HashMap;
use editor::{scroll::Autoscroll, Bias, Editor};
use file_finder_settings::FileFinderSettings;
use file_finder_settings::{FileFinderSettings, FileFinderWidth};
use file_icons::FileIcons;
use fuzzy::{CharBag, PathMatch, PathMatchCandidate};
use gpui::{
actions, rems, Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
actions, Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
FocusableView, KeyContext, Model, Modifiers, ModifiersChangedEvent, ParentElement, Render,
Styled, Task, View, ViewContext, VisualContext, WeakView,
};
@@ -244,6 +244,22 @@ impl FileFinder {
}
})
}
pub fn modal_max_width(
width_setting: Option<FileFinderWidth>,
cx: &mut ViewContext<Self>,
) -> Pixels {
let window_width = cx.viewport_size().width;
let small_width = Pixels(545.);
match width_setting {
None | Some(FileFinderWidth::Small) => small_width,
Some(FileFinderWidth::Full) => window_width,
Some(FileFinderWidth::XLarge) => (window_width - Pixels(512.)).max(small_width),
Some(FileFinderWidth::Large) => (window_width - Pixels(768.)).max(small_width),
Some(FileFinderWidth::Medium) => (window_width - Pixels(1024.)).max(small_width),
}
}
}
impl EventEmitter<DismissEvent> for FileFinder {}
@@ -257,9 +273,13 @@ impl FocusableView for FileFinder {
impl Render for FileFinder {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let key_context = self.picker.read(cx).delegate.key_context(cx);
let file_finder_settings = FileFinderSettings::get_global(cx);
let modal_max_width = Self::modal_max_width(file_finder_settings.modal_max_width, cx);
v_flex()
.key_context(key_context)
.w(rems(34.))
.w(modal_max_width)
.on_modifiers_changed(cx.listener(Self::handle_modifiers_changed))
.on_action(cx.listener(Self::handle_select_prev))
.on_action(cx.listener(Self::handle_open_menu))

View File

@@ -6,6 +6,7 @@ use settings::{Settings, SettingsSources};
#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct FileFinderSettings {
pub file_icons: bool,
pub modal_max_width: Option<FileFinderWidth>,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
@@ -14,6 +15,10 @@ pub struct FileFinderSettingsContent {
///
/// Default: true
pub file_icons: Option<bool>,
/// Determines how much space the file finder can take up in relation to the available window width.
///
/// Default: small
pub modal_max_width: Option<FileFinderWidth>,
}
impl Settings for FileFinderSettings {
@@ -25,3 +30,14 @@ impl Settings for FileFinderSettings {
sources.json_merge()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum FileFinderWidth {
#[default]
Small,
Medium,
Large,
XLarge,
Full,
}

View File

@@ -2,9 +2,8 @@ mod supported_countries;
use anyhow::{anyhow, Result};
use futures::{io::BufReader, stream::BoxStream, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt};
use http_client::{AsyncBody, HttpClient, HttpRequestExt, Method, Request as HttpRequest};
use http_client::{AsyncBody, HttpClient, Method, Request as HttpRequest};
use serde::{Deserialize, Serialize};
use std::time::Duration;
pub use supported_countries::*;
@@ -15,7 +14,6 @@ pub async fn stream_generate_content(
api_url: &str,
api_key: &str,
mut request: GenerateContentRequest,
low_speed_timeout: Option<Duration>,
) -> Result<BoxStream<'static, Result<GenerateContentResponse>>> {
let uri = format!(
"{api_url}/v1beta/models/{model}:streamGenerateContent?alt=sse&key={api_key}",
@@ -23,15 +21,11 @@ pub async fn stream_generate_content(
);
request.model.clear();
let mut request_builder = HttpRequest::builder()
let request_builder = HttpRequest::builder()
.method(Method::POST)
.uri(uri)
.header("Content-Type", "application/json");
if let Some(low_speed_timeout) = low_speed_timeout {
request_builder = request_builder.read_timeout(low_speed_timeout);
};
let request = request_builder.body(AsyncBody::from(serde_json::to_string(&request)?))?;
let mut response = client.send(request).await?;
if response.status().is_success() {
@@ -70,7 +64,6 @@ pub async fn count_tokens(
api_url: &str,
api_key: &str,
request: CountTokensRequest,
low_speed_timeout: Option<Duration>,
) -> Result<CountTokensResponse> {
let uri = format!(
"{}/v1beta/models/gemini-pro:countTokens?key={}",
@@ -78,15 +71,11 @@ pub async fn count_tokens(
);
let request = serde_json::to_string(&request)?;
let mut request_builder = HttpRequest::builder()
let request_builder = HttpRequest::builder()
.method(Method::POST)
.uri(&uri)
.header("Content-Type", "application/json");
if let Some(low_speed_timeout) = low_speed_timeout {
request_builder = request_builder.read_timeout(low_speed_timeout);
}
let http_request = request_builder.body(AsyncBody::from(request))?;
let mut response = client.send(http_request).await?;
let mut text = String::new();

View File

@@ -1,6 +1,4 @@
use gpui::{
div, img, prelude::*, App, AppContext, ImageSource, Render, ViewContext, WindowOptions,
};
use gpui::{div, img, prelude::*, App, AppContext, Render, ViewContext, WindowOptions};
use std::path::PathBuf;
struct GifViewer {
@@ -16,7 +14,7 @@ impl GifViewer {
impl Render for GifViewer {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
div().size_full().child(
img(ImageSource::File(self.gif_path.clone().into()))
img(self.gif_path.clone())
.size_full()
.object_fit(gpui::ObjectFit::Contain)
.id("gif"),

View File

@@ -6,8 +6,8 @@
<circle cx="240" cy="100" r="30" stroke="#dc2626" />
<circle cx="380" cy="100" r="20" stroke="#d97706" />
<circle cx="380" cy="240" r="30" stroke="#06b6d4" />
<circle cx="100" cy="240" r="30" stroke="#3b82f6" />
<circle cx="100" cy="240" r="30" stroke="#3b82f666" />
<circle cx="240" cy="380" r="30" stroke="#7c3aed" />
<circle cx="380" cy="380" r="20" stroke="#c026d3" />
<circle cx="100" cy="380" r="20" stroke="#e11d48" />
</svg>
<circle cx="100" cy="380" r="20" stroke="#e11d4866" />
</svg>

Before

Width:  |  Height:  |  Size: 741 B

After

Width:  |  Height:  |  Size: 746 B

View File

@@ -61,7 +61,7 @@ impl RenderOnce for ImageContainer {
}
struct ImageShowcase {
local_resource: Arc<PathBuf>,
local_resource: Arc<std::path::Path>,
remote_resource: SharedUri,
asset_resource: SharedString,
}
@@ -153,9 +153,10 @@ fn main() {
cx.open_window(window_options, |cx| {
cx.new_view(|_cx| ImageShowcase {
// Relative path to your root project path
local_resource: Arc::new(
PathBuf::from_str("crates/gpui/examples/image/app-icon.png").unwrap(),
),
local_resource: PathBuf::from_str("crates/gpui/examples/image/app-icon.png")
.unwrap()
.into(),
remote_resource: "https://picsum.photos/512/512".into(),
asset_resource: "image/color.svg".into(),

View File

@@ -0,0 +1,214 @@
use std::{path::Path, sync::Arc, time::Duration};
use anyhow::anyhow;
use gpui::{
black, div, img, prelude::*, pulsating_between, px, red, size, Animation, AnimationExt, App,
AppContext, Asset, AssetLogger, AssetSource, Bounds, Hsla, ImageAssetLoader, ImageCacheError,
ImgResourceLoader, Length, Pixels, RenderImage, Resource, SharedString, ViewContext,
WindowBounds, WindowContext, WindowOptions, LOADING_DELAY,
};
struct Assets {}
impl AssetSource for Assets {
fn load(&self, path: &str) -> anyhow::Result<Option<std::borrow::Cow<'static, [u8]>>> {
std::fs::read(path)
.map(Into::into)
.map_err(Into::into)
.map(Some)
}
fn list(&self, path: &str) -> anyhow::Result<Vec<SharedString>> {
Ok(std::fs::read_dir(path)?
.filter_map(|entry| {
Some(SharedString::from(
entry.ok()?.path().to_string_lossy().to_string(),
))
})
.collect::<Vec<_>>())
}
}
const IMAGE: &str = "examples/image/app-icon.png";
#[derive(Copy, Clone, Hash)]
struct LoadImageParameters {
timeout: Duration,
fail: bool,
}
struct LoadImageWithParameters {}
impl Asset for LoadImageWithParameters {
type Source = LoadImageParameters;
type Output = Result<Arc<RenderImage>, ImageCacheError>;
fn load(
parameters: Self::Source,
cx: &mut AppContext,
) -> impl std::future::Future<Output = Self::Output> + Send + 'static {
let timer = cx.background_executor().timer(parameters.timeout);
let data = AssetLogger::<ImageAssetLoader>::load(
Resource::Path(Path::new(IMAGE).to_path_buf().into()),
cx,
);
async move {
timer.await;
if parameters.fail {
log::error!("Intentionally failed to load image");
Err(anyhow!("Failed to load image").into())
} else {
data.await
}
}
}
}
struct ImageLoadingExample {}
impl ImageLoadingExample {
fn loading_element() -> impl IntoElement {
div().size_full().flex_none().p_0p5().rounded_sm().child(
div().size_full().with_animation(
"loading-bg",
Animation::new(Duration::from_secs(3))
.repeat()
.with_easing(pulsating_between(0.04, 0.24)),
move |this, delta| this.bg(black().opacity(delta)),
),
)
}
fn fallback_element() -> impl IntoElement {
let fallback_color: Hsla = black().opacity(0.5);
div().size_full().flex_none().p_0p5().child(
div()
.size_full()
.flex()
.items_center()
.justify_center()
.rounded_sm()
.text_sm()
.text_color(fallback_color)
.border_1()
.border_color(fallback_color)
.child("?"),
)
}
}
impl Render for ImageLoadingExample {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
div().flex().flex_col().size_full().justify_around().child(
div().flex().flex_row().w_full().justify_around().child(
div()
.flex()
.bg(gpui::white())
.size(Length::Definite(Pixels(300.0).into()))
.justify_center()
.items_center()
.child({
let image_source = LoadImageParameters {
timeout: LOADING_DELAY.saturating_sub(Duration::from_millis(25)),
fail: false,
};
// Load within the 'loading delay', should not show loading fallback
img(move |cx: &mut WindowContext| {
cx.use_asset::<LoadImageWithParameters>(&image_source)
})
.id("image-1")
.border_1()
.size_12()
.with_fallback(|| Self::fallback_element().into_any_element())
.border_color(red())
.with_loading(|| Self::loading_element().into_any_element())
.on_click(move |_, cx| {
cx.remove_asset::<LoadImageWithParameters>(&image_source);
})
})
.child({
// Load after a long delay
let image_source = LoadImageParameters {
timeout: Duration::from_secs(5),
fail: false,
};
img(move |cx: &mut WindowContext| {
cx.use_asset::<LoadImageWithParameters>(&image_source)
})
.id("image-2")
.with_fallback(|| Self::fallback_element().into_any_element())
.with_loading(|| Self::loading_element().into_any_element())
.size_12()
.border_1()
.border_color(red())
.on_click(move |_, cx| {
cx.remove_asset::<LoadImageWithParameters>(&image_source);
})
})
.child({
// Fail to load image after a long delay
let image_source = LoadImageParameters {
timeout: Duration::from_secs(5),
fail: true,
};
// Fail to load after a long delay
img(move |cx: &mut WindowContext| {
cx.use_asset::<LoadImageWithParameters>(&image_source)
})
.id("image-3")
.with_fallback(|| Self::fallback_element().into_any_element())
.with_loading(|| Self::loading_element().into_any_element())
.size_12()
.border_1()
.border_color(red())
.on_click(move |_, cx| {
cx.remove_asset::<LoadImageWithParameters>(&image_source);
})
})
.child({
// Ensure that the normal image loader doesn't spam logs
let image_source = Path::new(
"this/file/really/shouldn't/exist/or/won't/be/an/image/I/hope",
)
.to_path_buf();
img(image_source.clone())
.id("image-1")
.border_1()
.size_12()
.with_fallback(|| Self::fallback_element().into_any_element())
.border_color(red())
.with_loading(|| Self::loading_element().into_any_element())
.on_click(move |_, cx| {
cx.remove_asset::<ImgResourceLoader>(&image_source.clone().into());
})
}),
),
)
}
}
fn main() {
env_logger::init();
App::new()
.with_assets(Assets {})
.run(|cx: &mut AppContext| {
let options = WindowOptions {
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
None,
size(px(300.), Pixels(300.)),
cx,
))),
..Default::default()
};
cx.open_window(options, |cx| {
cx.activate(false);
cx.new_view(|_cx| ImageLoadingExample {})
})
.unwrap();
});
}

View File

@@ -581,8 +581,8 @@ impl Render for InputExample {
format!(
"{:} {}",
ks.unparse(),
if let Some(key_char) = ks.key_char.as_ref() {
format!("-> {:?}", key_char)
if let Some(ime_key) = ks.ime_key.as_ref() {
format!("-> {:?}", ime_key)
} else {
"".to_owned()
}

View File

@@ -0,0 +1,199 @@
use gpui::{
canvas, div, point, prelude::*, px, size, App, AppContext, Bounds, MouseDownEvent, Path,
Pixels, Point, Render, ViewContext, WindowOptions,
};
struct PaintingViewer {
default_lines: Vec<Path<Pixels>>,
lines: Vec<Vec<Point<Pixels>>>,
start: Point<Pixels>,
_painting: bool,
}
impl PaintingViewer {
fn new() -> Self {
let mut lines = vec![];
// draw a line
let mut path = Path::new(point(px(50.), px(180.)));
path.line_to(point(px(100.), px(120.)));
// go back to close the path
path.line_to(point(px(100.), px(121.)));
path.line_to(point(px(50.), px(181.)));
lines.push(path);
// draw a lightening bolt ⚡
let mut path = Path::new(point(px(150.), px(200.)));
path.line_to(point(px(200.), px(125.)));
path.line_to(point(px(200.), px(175.)));
path.line_to(point(px(250.), px(100.)));
lines.push(path);
// draw a ⭐
let mut path = Path::new(point(px(350.), px(100.)));
path.line_to(point(px(370.), px(160.)));
path.line_to(point(px(430.), px(160.)));
path.line_to(point(px(380.), px(200.)));
path.line_to(point(px(400.), px(260.)));
path.line_to(point(px(350.), px(220.)));
path.line_to(point(px(300.), px(260.)));
path.line_to(point(px(320.), px(200.)));
path.line_to(point(px(270.), px(160.)));
path.line_to(point(px(330.), px(160.)));
path.line_to(point(px(350.), px(100.)));
lines.push(path);
let square_bounds = Bounds {
origin: point(px(450.), px(100.)),
size: size(px(200.), px(80.)),
};
let height = square_bounds.size.height;
let horizontal_offset = height;
let vertical_offset = px(30.);
let mut path = Path::new(square_bounds.lower_left());
path.curve_to(
square_bounds.origin + point(horizontal_offset, vertical_offset),
square_bounds.origin + point(px(0.0), vertical_offset),
);
path.line_to(square_bounds.upper_right() + point(-horizontal_offset, vertical_offset));
path.curve_to(
square_bounds.lower_right(),
square_bounds.upper_right() + point(px(0.0), vertical_offset),
);
path.line_to(square_bounds.lower_left());
lines.push(path);
Self {
default_lines: lines.clone(),
lines: vec![],
start: point(px(0.), px(0.)),
_painting: false,
}
}
fn clear(&mut self, cx: &mut ViewContext<Self>) {
self.lines.clear();
cx.notify();
}
}
impl Render for PaintingViewer {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let default_lines = self.default_lines.clone();
let lines = self.lines.clone();
div()
.font_family(".SystemUIFont")
.bg(gpui::white())
.size_full()
.p_4()
.flex()
.flex_col()
.child(
div()
.flex()
.gap_2()
.justify_between()
.items_center()
.child("Mouse down any point and drag to draw lines (Hold on shift key to draw straight lines)")
.child(
div()
.id("clear")
.child("Clean up")
.bg(gpui::black())
.text_color(gpui::white())
.active(|this| this.opacity(0.8))
.flex()
.px_3()
.py_1()
.on_click(cx.listener(|this, _, cx| {
this.clear(cx);
})),
),
)
.child(
div()
.size_full()
.child(
canvas(
move |_, _| {},
move |_, _, cx| {
const STROKE_WIDTH: Pixels = px(2.0);
for path in default_lines {
cx.paint_path(path, gpui::black());
}
for points in lines {
let mut path = Path::new(points[0]);
for p in points.iter().skip(1) {
path.line_to(*p);
}
let mut last = points.last().unwrap();
for p in points.iter().rev() {
let mut offset_x = px(0.);
if last.x == p.x {
offset_x = STROKE_WIDTH;
}
path.line_to(point(p.x + offset_x, p.y + STROKE_WIDTH));
last = p;
}
cx.paint_path(path, gpui::black());
}
},
)
.size_full(),
)
.on_mouse_down(
gpui::MouseButton::Left,
cx.listener(|this, ev: &MouseDownEvent, _| {
this._painting = true;
this.start = ev.position;
let path = vec![ev.position];
this.lines.push(path);
}),
)
.on_mouse_move(cx.listener(|this, ev: &gpui::MouseMoveEvent, cx| {
if !this._painting {
return;
}
let is_shifted = ev.modifiers.shift;
let mut pos = ev.position;
// When holding shift, draw a straight line
if is_shifted {
let dx = pos.x - this.start.x;
let dy = pos.y - this.start.y;
if dx.abs() > dy.abs() {
pos.y = this.start.y;
} else {
pos.x = this.start.x;
}
}
if let Some(path) = this.lines.last_mut() {
path.push(pos);
}
cx.notify();
}))
.on_mouse_up(
gpui::MouseButton::Left,
cx.listener(|this, _, _| {
this._painting = false;
}),
),
)
}
}
fn main() {
App::new().run(|cx: &mut AppContext| {
cx.open_window(
WindowOptions {
focus: true,
..Default::default()
},
|cx| cx.new_view(|_| PaintingViewer::new()),
)
.unwrap();
cx.activate(true);
});
}

View File

@@ -740,7 +740,7 @@ impl AppContext {
}
/// Returns the SVG renderer GPUI uses
pub(crate) fn svg_renderer(&self) -> SvgRenderer {
pub fn svg_renderer(&self) -> SvgRenderer {
self.svg_renderer.clone()
}
@@ -1362,7 +1362,7 @@ impl AppContext {
}
/// Remove an asset from GPUI's cache
pub fn remove_cached_asset<A: Asset + 'static>(&mut self, source: &A::Source) {
pub fn remove_asset<A: Asset>(&mut self, source: &A::Source) {
let asset_id = (TypeId::of::<A>(), hash(source));
self.loading_assets.remove(&asset_id);
}
@@ -1371,12 +1371,7 @@ impl AppContext {
///
/// Note that the multiple calls to this method will only result in one `Asset::load` call at a
/// time, and the results of this call will be cached
///
/// This asset will not be cached by default, see [Self::use_cached_asset]
pub fn fetch_asset<A: Asset + 'static>(
&mut self,
source: &A::Source,
) -> (Shared<Task<A::Output>>, bool) {
pub fn fetch_asset<A: Asset>(&mut self, source: &A::Source) -> (Shared<Task<A::Output>>, bool) {
let asset_id = (TypeId::of::<A>(), hash(source));
let mut is_first = false;
let task = self

View File

@@ -1,30 +1,43 @@
use crate::{AppContext, SharedString, SharedUri};
use futures::Future;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::path::PathBuf;
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use std::sync::Arc;
/// An enum representing
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub(crate) enum UriOrPath {
pub enum Resource {
/// This resource is at a given URI
Uri(SharedUri),
Path(Arc<PathBuf>),
/// This resource is at a given path in the file system
Path(Arc<Path>),
/// This resource is embedded in the application binary
Embedded(SharedString),
}
impl From<SharedUri> for UriOrPath {
impl From<SharedUri> for Resource {
fn from(value: SharedUri) -> Self {
Self::Uri(value)
}
}
impl From<Arc<PathBuf>> for UriOrPath {
fn from(value: Arc<PathBuf>) -> Self {
impl From<PathBuf> for Resource {
fn from(value: PathBuf) -> Self {
Self::Path(value.into())
}
}
impl From<Arc<Path>> for Resource {
fn from(value: Arc<Path>) -> Self {
Self::Path(value)
}
}
/// A trait for asynchronous asset loading.
pub trait Asset {
pub trait Asset: 'static {
/// The source of the asset.
type Source: Clone + Hash + Send;
@@ -38,6 +51,31 @@ pub trait Asset {
) -> impl Future<Output = Self::Output> + Send + 'static;
}
/// An asset Loader that logs whatever passes through it
pub enum AssetLogger<T> {
#[doc(hidden)]
_Phantom(PhantomData<T>, &'static dyn crate::seal::Sealed),
}
impl<R: Clone + Send, E: Clone + Send + std::error::Error, T: Asset<Output = Result<R, E>>> Asset
for AssetLogger<T>
{
type Source = T::Source;
type Output = T::Output;
fn load(
source: Self::Source,
cx: &mut AppContext,
) -> impl Future<Output = Self::Output> + Send + 'static {
let load = T::load(source, cx);
async {
load.await
.inspect_err(|e| log::error!("Failed to load asset: {}", e))
}
}
}
/// Use a quick, non-cryptographically secure hash function to get an identifier from data
pub fn hash<T: Hash>(data: &T) -> u64 {
let mut hasher = collections::FxHasher::default();

View File

@@ -22,6 +22,17 @@ pub fn rgba(hex: u32) -> Rgba {
Rgba { r, g, b, a }
}
/// Swap from RGBA with premultiplied alpha to BGRA
pub(crate) fn swap_rgba_pa_to_bgra(color: &mut [u8]) {
color.swap(0, 2);
if color[3] > 0 {
let a = color[3] as f32 / 255.;
color[0] = (color[0] as f32 / a) as u8;
color[1] = (color[1] as f32 / a) as u8;
color[2] = (color[2] as f32 / a) as u8;
}
}
/// An RGBA color
#[derive(PartialEq, Clone, Copy, Default)]
pub struct Rgba {

View File

@@ -443,7 +443,7 @@ impl Interactivity {
pub fn on_drag<T, W>(
&mut self,
value: T,
constructor: impl Fn(&T, &mut WindowContext) -> View<W> + 'static,
constructor: impl Fn(&T, Point<Pixels>, &mut WindowContext) -> View<W> + 'static,
) where
Self: Sized,
T: 'static,
@@ -455,7 +455,9 @@ impl Interactivity {
);
self.drag_listener = Some((
Box::new(value),
Box::new(move |value, cx| constructor(value.downcast_ref().unwrap(), cx).into()),
Box::new(move |value, offset, cx| {
constructor(value.downcast_ref().unwrap(), offset, cx).into()
}),
));
}
@@ -511,7 +513,7 @@ impl Interactivity {
}
/// Block the mouse from interacting with this element or any of its children
/// The imperative API equivalent to [`InteractiveElement::block_mouse`]
/// The imperative API equivalent to [`InteractiveElement::occlude`]
pub fn occlude_mouse(&mut self) {
self.occlude_mouse = true;
}
@@ -874,11 +876,17 @@ pub trait InteractiveElement: Sized {
}
/// Block the mouse from interacting with this element or any of its children
/// The fluent API equivalent to [`Interactivity::block_mouse`]
/// The fluent API equivalent to [`Interactivity::occlude_mouse`]
fn occlude(mut self) -> Self {
self.interactivity().occlude_mouse();
self
}
/// Block the mouse from interacting with this element or any of its children
/// The fluent API equivalent to [`Interactivity::occlude_mouse`]
fn block_mouse_down(mut self) -> Self {
self.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
}
}
/// A trait for elements that want to use the standard GPUI interactivity features
@@ -960,14 +968,15 @@ pub trait StatefulInteractiveElement: InteractiveElement {
/// On drag initiation, this callback will be used to create a new view to render the dragged value for a
/// drag and drop operation. This API should also be used as the equivalent of 'on drag start' with
/// the [`Self::on_drag_move`] API
/// the [`Self::on_drag_move`] API.
/// The callback also has access to the offset of triggering click from the origin of parent element.
/// The fluent API equivalent to [`Interactivity::on_drag`]
///
/// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_drag<T, W>(
mut self,
value: T,
constructor: impl Fn(&T, &mut WindowContext) -> View<W> + 'static,
constructor: impl Fn(&T, Point<Pixels>, &mut WindowContext) -> View<W> + 'static,
) -> Self
where
Self: Sized,
@@ -1050,7 +1059,8 @@ pub(crate) type ScrollWheelListener =
pub(crate) type ClickListener = Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>;
pub(crate) type DragListener = Box<dyn Fn(&dyn Any, &mut WindowContext) -> AnyView + 'static>;
pub(crate) type DragListener =
Box<dyn Fn(&dyn Any, Point<Pixels>, &mut WindowContext) -> AnyView + 'static>;
type DropListener = Box<dyn Fn(&dyn Any, &mut WindowContext) + 'static>;
@@ -1812,7 +1822,8 @@ impl Interactivity {
if let Some((drag_value, drag_listener)) = drag_listener.take() {
*clicked_state.borrow_mut() = ElementClickedState::default();
let cursor_offset = event.position - hitbox.origin;
let drag = (drag_listener)(drag_value.as_ref(), cx);
let drag =
(drag_listener)(drag_value.as_ref(), cursor_offset, cx);
cx.active_drag = Some(AnyDrag {
view: drag,
value: drag_value,
@@ -2372,7 +2383,7 @@ where
/// A wrapper around an element that can store state, produced after assigning an ElementId.
pub struct Stateful<E> {
element: E,
pub(crate) element: E,
}
impl<E> Styled for Stateful<E>

View File

@@ -1,9 +1,11 @@
use crate::{
px, AbsoluteLength, AppContext, Asset, Bounds, DefiniteLength, Element, ElementId,
GlobalElementId, Hitbox, Image, InteractiveElement, Interactivity, IntoElement, LayoutId,
Length, ObjectFit, Pixels, RenderImage, SharedString, SharedUri, StyleRefinement, Styled,
SvgSize, UriOrPath, WindowContext,
px, swap_rgba_pa_to_bgra, AbsoluteLength, AnyElement, AppContext, Asset, AssetLogger, Bounds,
DefiniteLength, Element, ElementId, GlobalElementId, Hitbox, Image, InteractiveElement,
Interactivity, IntoElement, LayoutId, Length, ObjectFit, Pixels, RenderImage, Resource,
SharedString, SharedUri, StyleRefinement, Styled, SvgSize, Task, WindowContext,
};
use anyhow::{anyhow, Result};
use futures::{AsyncReadExt, Future};
use image::{
codecs::gif::GifDecoder, AnimationDecoder, Frame, ImageBuffer, ImageError, ImageFormat,
@@ -11,45 +13,56 @@ use image::{
use smallvec::SmallVec;
use std::{
fs,
io::Cursor,
path::PathBuf,
io::{self, Cursor},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
time::{Duration, Instant},
};
use thiserror::Error;
use util::ResultExt;
use super::{FocusableElement, Stateful, StatefulInteractiveElement};
/// The delay before showing the loading state.
pub const LOADING_DELAY: Duration = Duration::from_millis(200);
/// A type alias to the resource loader that the `img()` element uses.
///
/// Note: that this is only for Resources, like URLs or file paths.
/// Custom loaders, or external images will not use this asset loader
pub type ImgResourceLoader = AssetLogger<ImageAssetLoader>;
/// A source of image content.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone)]
pub enum ImageSource {
/// Image content will be loaded from provided URI at render time.
Uri(SharedUri),
/// Image content will be loaded from the provided file at render time.
File(Arc<PathBuf>),
/// The image content will be loaded from some resource location
Resource(Resource),
/// Cached image data
Render(Arc<RenderImage>),
/// Cached image data
Image(Arc<Image>),
/// Image content will be loaded from Asset at render time.
Embedded(SharedString),
/// A custom loading function to use
Custom(Arc<dyn Fn(&mut WindowContext) -> Option<Result<Arc<RenderImage>, ImageCacheError>>>),
}
fn is_uri(uri: &str) -> bool {
uri.contains("://")
http_client::Uri::from_str(uri).is_ok()
}
impl From<SharedUri> for ImageSource {
fn from(value: SharedUri) -> Self {
Self::Uri(value)
Self::Resource(Resource::Uri(value))
}
}
impl From<&'static str> for ImageSource {
fn from(s: &'static str) -> Self {
impl<'a> From<&'a str> for ImageSource {
fn from(s: &'a str) -> Self {
if is_uri(s) {
Self::Uri(s.into())
Self::Resource(Resource::Uri(s.to_string().into()))
} else {
Self::Embedded(s.into())
Self::Resource(Resource::Embedded(s.to_string().into()))
}
}
}
@@ -57,32 +70,34 @@ impl From<&'static str> for ImageSource {
impl From<String> for ImageSource {
fn from(s: String) -> Self {
if is_uri(&s) {
Self::Uri(s.into())
Self::Resource(Resource::Uri(s.into()))
} else {
Self::Embedded(s.into())
Self::Resource(Resource::Embedded(s.into()))
}
}
}
impl From<SharedString> for ImageSource {
fn from(s: SharedString) -> Self {
if is_uri(&s) {
Self::Uri(s.into())
} else {
Self::Embedded(s)
}
s.as_ref().into()
}
}
impl From<Arc<PathBuf>> for ImageSource {
fn from(value: Arc<PathBuf>) -> Self {
Self::File(value)
impl From<&Path> for ImageSource {
fn from(value: &Path) -> Self {
Self::Resource(value.to_path_buf().into())
}
}
impl From<Arc<Path>> for ImageSource {
fn from(value: Arc<Path>) -> Self {
Self::Resource(value.into())
}
}
impl From<PathBuf> for ImageSource {
fn from(value: PathBuf) -> Self {
Self::File(value.into())
Self::Resource(value.into())
}
}
@@ -98,12 +113,80 @@ impl From<Arc<Image>> for ImageSource {
}
}
impl<F: Fn(&mut WindowContext) -> Option<Result<Arc<RenderImage>, ImageCacheError>> + 'static>
From<F> for ImageSource
{
fn from(value: F) -> Self {
Self::Custom(Arc::new(value))
}
}
/// The style of an image element.
pub struct ImageStyle {
grayscale: bool,
object_fit: ObjectFit,
loading: Option<Box<dyn Fn() -> AnyElement>>,
fallback: Option<Box<dyn Fn() -> AnyElement>>,
}
impl Default for ImageStyle {
fn default() -> Self {
Self {
grayscale: false,
object_fit: ObjectFit::Contain,
loading: None,
fallback: None,
}
}
}
/// Style an image element.
pub trait StyledImage: Sized {
/// Get a mutable [ImageStyle] from the element.
fn image_style(&mut self) -> &mut ImageStyle;
/// Set the image to be displayed in grayscale.
fn grayscale(mut self, grayscale: bool) -> Self {
self.image_style().grayscale = grayscale;
self
}
/// Set the object fit for the image.
fn object_fit(mut self, object_fit: ObjectFit) -> Self {
self.image_style().object_fit = object_fit;
self
}
/// Set the object fit for the image.
fn with_fallback(mut self, fallback: impl Fn() -> AnyElement + 'static) -> Self {
self.image_style().fallback = Some(Box::new(fallback));
self
}
/// Set the object fit for the image.
fn with_loading(mut self, loading: impl Fn() -> AnyElement + 'static) -> Self {
self.image_style().loading = Some(Box::new(loading));
self
}
}
impl StyledImage for Img {
fn image_style(&mut self) -> &mut ImageStyle {
&mut self.style
}
}
impl StyledImage for Stateful<Img> {
fn image_style(&mut self) -> &mut ImageStyle {
&mut self.element.style
}
}
/// An image element.
pub struct Img {
interactivity: Interactivity,
source: ImageSource,
grayscale: bool,
object_fit: ObjectFit,
style: ImageStyle,
}
/// Create a new image element.
@@ -111,8 +194,7 @@ pub fn img(source: impl Into<ImageSource>) -> Img {
Img {
interactivity: Interactivity::default(),
source: source.into(),
grayscale: false,
object_fit: ObjectFit::Contain,
style: ImageStyle::default(),
}
}
@@ -125,16 +207,19 @@ impl Img {
"hdr", "exr", "pbm", "pam", "ppm", "pgm", "ff", "farbfeld", "qoi", "svg",
]
}
}
/// Set the image to be displayed in grayscale.
pub fn grayscale(mut self, grayscale: bool) -> Self {
self.grayscale = grayscale;
self
impl Deref for Stateful<Img> {
type Target = Img;
fn deref(&self) -> &Self::Target {
&self.element
}
/// Set the object fit for the image.
pub fn object_fit(mut self, object_fit: ObjectFit) -> Self {
self.object_fit = object_fit;
self
}
impl DerefMut for Stateful<Img> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.element
}
}
@@ -142,10 +227,17 @@ impl Img {
struct ImgState {
frame_index: usize,
last_frame_time: Option<Instant>,
started_loading: Option<(Instant, Task<()>)>,
}
/// The image layout state between frames
pub struct ImgLayoutState {
frame_index: usize,
replacement: Option<AnyElement>,
}
impl Element for Img {
type RequestLayoutState = usize;
type RequestLayoutState = ImgLayoutState;
type PrepaintState = Option<Hitbox>;
fn id(&self) -> Option<ElementId> {
@@ -157,11 +249,17 @@ impl Element for Img {
global_id: Option<&GlobalElementId>,
cx: &mut WindowContext,
) -> (LayoutId, Self::RequestLayoutState) {
let mut layout_state = ImgLayoutState {
frame_index: 0,
replacement: None,
};
cx.with_optional_element_state(global_id, |state, cx| {
let mut state = state.map(|state| {
state.unwrap_or(ImgState {
frame_index: 0,
last_frame_time: None,
started_loading: None,
})
});
@@ -170,64 +268,105 @@ impl Element for Img {
let layout_id = self
.interactivity
.request_layout(global_id, cx, |mut style, cx| {
if let Some(data) = self.source.use_data(cx) {
if let Some(state) = &mut state {
let frame_count = data.frame_count();
if frame_count > 1 {
let current_time = Instant::now();
if let Some(last_frame_time) = state.last_frame_time {
let elapsed = current_time - last_frame_time;
let frame_duration =
Duration::from(data.delay(state.frame_index));
let mut replacement_id = None;
if elapsed >= frame_duration {
state.frame_index = (state.frame_index + 1) % frame_count;
state.last_frame_time =
Some(current_time - (elapsed - frame_duration));
match self.source.use_data(cx) {
Some(Ok(data)) => {
if let Some(state) = &mut state {
let frame_count = data.frame_count();
if frame_count > 1 {
let current_time = Instant::now();
if let Some(last_frame_time) = state.last_frame_time {
let elapsed = current_time - last_frame_time;
let frame_duration =
Duration::from(data.delay(state.frame_index));
if elapsed >= frame_duration {
state.frame_index =
(state.frame_index + 1) % frame_count;
state.last_frame_time =
Some(current_time - (elapsed - frame_duration));
}
} else {
state.last_frame_time = Some(current_time);
}
}
state.started_loading = None;
}
let image_size = data.size(frame_index);
if let Length::Auto = style.size.width {
style.size.width = match style.size.height {
Length::Definite(DefiniteLength::Absolute(
AbsoluteLength::Pixels(height),
)) => Length::Definite(
px(image_size.width.0 as f32 * height.0
/ image_size.height.0 as f32)
.into(),
),
_ => Length::Definite(px(image_size.width.0 as f32).into()),
};
}
if let Length::Auto = style.size.height {
style.size.height = match style.size.width {
Length::Definite(DefiniteLength::Absolute(
AbsoluteLength::Pixels(width),
)) => Length::Definite(
px(image_size.height.0 as f32 * width.0
/ image_size.width.0 as f32)
.into(),
),
_ => Length::Definite(px(image_size.height.0 as f32).into()),
};
}
if global_id.is_some() && data.frame_count() > 1 {
cx.request_animation_frame();
}
}
Some(_err) => {
if let Some(fallback) = self.style.fallback.as_ref() {
let mut element = fallback();
replacement_id = Some(element.request_layout(cx));
layout_state.replacement = Some(element);
}
if let Some(state) = &mut state {
state.started_loading = None;
}
}
None => {
if let Some(state) = &mut state {
if let Some((started_loading, _)) = state.started_loading {
if started_loading.elapsed() > LOADING_DELAY {
if let Some(loading) = self.style.loading.as_ref() {
let mut element = loading();
replacement_id = Some(element.request_layout(cx));
layout_state.replacement = Some(element);
}
}
} else {
state.last_frame_time = Some(current_time);
let parent_view_id = cx.parent_view_id();
let task = cx.spawn(|mut cx| async move {
cx.background_executor().timer(LOADING_DELAY).await;
cx.update(|cx| {
cx.notify(parent_view_id);
})
.ok();
});
state.started_loading = Some((Instant::now(), task));
}
}
}
let image_size = data.size(frame_index);
if let Length::Auto = style.size.width {
style.size.width = match style.size.height {
Length::Definite(DefiniteLength::Absolute(
AbsoluteLength::Pixels(height),
)) => Length::Definite(
px(image_size.width.0 as f32 * height.0
/ image_size.height.0 as f32)
.into(),
),
_ => Length::Definite(px(image_size.width.0 as f32).into()),
};
}
if let Length::Auto = style.size.height {
style.size.height = match style.size.width {
Length::Definite(DefiniteLength::Absolute(
AbsoluteLength::Pixels(width),
)) => Length::Definite(
px(image_size.height.0 as f32 * width.0
/ image_size.width.0 as f32)
.into(),
),
_ => Length::Definite(px(image_size.height.0 as f32).into()),
};
}
if global_id.is_some() && data.frame_count() > 1 {
cx.request_animation_frame();
}
}
cx.request_layout(style, [])
cx.request_layout(style, replacement_id)
});
((layout_id, frame_index), state)
layout_state.frame_index = frame_index;
((layout_id, layout_state), state)
})
}
@@ -235,18 +374,24 @@ impl Element for Img {
&mut self,
global_id: Option<&GlobalElementId>,
bounds: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState,
request_layout: &mut Self::RequestLayoutState,
cx: &mut WindowContext,
) -> Option<Hitbox> {
) -> Self::PrepaintState {
self.interactivity
.prepaint(global_id, bounds, bounds.size, cx, |_, _, hitbox, _| hitbox)
.prepaint(global_id, bounds, bounds.size, cx, |_, _, hitbox, cx| {
if let Some(replacement) = &mut request_layout.replacement {
replacement.prepaint(cx);
}
hitbox
})
}
fn paint(
&mut self,
global_id: Option<&GlobalElementId>,
bounds: Bounds<Pixels>,
frame_index: &mut Self::RequestLayoutState,
layout_state: &mut Self::RequestLayoutState,
hitbox: &mut Self::PrepaintState,
cx: &mut WindowContext,
) {
@@ -255,29 +400,26 @@ impl Element for Img {
.paint(global_id, bounds, hitbox.as_ref(), cx, |style, cx| {
let corner_radii = style.corner_radii.to_pixels(bounds.size, cx.rem_size());
if let Some(data) = source.use_data(cx) {
let new_bounds = self.object_fit.get_bounds(bounds, data.size(*frame_index));
if let Some(Ok(data)) = source.use_data(cx) {
let new_bounds = self
.style
.object_fit
.get_bounds(bounds, data.size(layout_state.frame_index));
cx.paint_image(
new_bounds,
corner_radii,
data.clone(),
*frame_index,
self.grayscale,
layout_state.frame_index,
self.style.grayscale,
)
.log_err();
} else if let Some(replacement) = &mut layout_state.replacement {
replacement.paint(cx);
}
})
}
}
impl IntoElement for Img {
type Element = Self;
fn into_element(self) -> Self::Element {
self
}
}
impl Styled for Img {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.interactivity.base_style
@@ -290,41 +432,28 @@ impl InteractiveElement for Img {
}
}
impl ImageSource {
pub(crate) fn use_data(&self, cx: &mut WindowContext) -> Option<Arc<RenderImage>> {
match self {
ImageSource::Uri(_) | ImageSource::Embedded(_) | ImageSource::File(_) => {
let uri_or_path: UriOrPath = match self {
ImageSource::Uri(uri) => uri.clone().into(),
ImageSource::File(path) => path.clone().into(),
ImageSource::Embedded(path) => UriOrPath::Embedded(path.clone()),
_ => unreachable!(),
};
impl IntoElement for Img {
type Element = Self;
cx.use_asset::<ImageAsset>(&uri_or_path)?.log_err()
}
ImageSource::Render(data) => Some(data.to_owned()),
ImageSource::Image(data) => cx.use_asset::<ImageDecoder>(data)?.log_err(),
}
fn into_element(self) -> Self::Element {
self
}
}
/// Fetch the data associated with this source, using GPUI's asset caching
pub async fn data(&self, cx: &mut AppContext) -> Option<Arc<RenderImage>> {
impl FocusableElement for Img {}
impl StatefulInteractiveElement for Img {}
impl ImageSource {
pub(crate) fn use_data(
&self,
cx: &mut WindowContext,
) -> Option<Result<Arc<RenderImage>, ImageCacheError>> {
match self {
ImageSource::Uri(_) | ImageSource::Embedded(_) | ImageSource::File(_) => {
let uri_or_path: UriOrPath = match self {
ImageSource::Uri(uri) => uri.clone().into(),
ImageSource::File(path) => path.clone().into(),
ImageSource::Embedded(path) => UriOrPath::Embedded(path.clone()),
_ => unreachable!(),
};
cx.fetch_asset::<ImageAsset>(&uri_or_path).0.await.log_err()
}
ImageSource::Render(data) => Some(data.to_owned()),
ImageSource::Image(data) => cx.fetch_asset::<ImageDecoder>(data).0.await.log_err(),
ImageSource::Resource(resource) => cx.use_asset::<ImgResourceLoader>(&resource),
ImageSource::Custom(loading_fn) => loading_fn(cx),
ImageSource::Render(data) => Some(Ok(data.to_owned())),
ImageSource::Image(data) => cx.use_asset::<AssetLogger<ImageDecoder>>(data),
}
}
}
@@ -334,22 +463,23 @@ enum ImageDecoder {}
impl Asset for ImageDecoder {
type Source = Arc<Image>;
type Output = Result<Arc<RenderImage>, Arc<anyhow::Error>>;
type Output = Result<Arc<RenderImage>, ImageCacheError>;
fn load(
source: Self::Source,
cx: &mut AppContext,
) -> impl Future<Output = Self::Output> + Send + 'static {
let result = source.to_image_data(cx).map_err(Arc::new);
async { result }
let renderer = cx.svg_renderer();
async move { source.to_image_data(renderer).map_err(Into::into) }
}
}
/// An image loader for the GPUI asset system
#[derive(Clone)]
enum ImageAsset {}
pub enum ImageAssetLoader {}
impl Asset for ImageAsset {
type Source = UriOrPath;
impl Asset for ImageAssetLoader {
type Source = Resource;
type Output = Result<Arc<RenderImage>, ImageCacheError>;
fn load(
@@ -363,12 +493,12 @@ impl Asset for ImageAsset {
let asset_source = cx.asset_source().clone();
async move {
let bytes = match source.clone() {
UriOrPath::Path(uri) => fs::read(uri.as_ref())?,
UriOrPath::Uri(uri) => {
Resource::Path(uri) => fs::read(uri.as_ref())?,
Resource::Uri(uri) => {
let mut response = client
.get(uri.as_ref(), ().into(), true)
.await
.map_err(|e| ImageCacheError::Client(Arc::new(e)))?;
.map_err(|e| anyhow!(e))?;
let mut body = Vec::new();
response.body_mut().read_to_end(&mut body).await?;
if !response.status().is_success() {
@@ -383,13 +513,13 @@ impl Asset for ImageAsset {
}
body
}
UriOrPath::Embedded(path) => {
Resource::Embedded(path) => {
let data = asset_source.load(&path).ok().flatten();
if let Some(data) = data {
data.to_vec()
} else {
return Err(ImageCacheError::Asset(
format!("not found: {}", path).into(),
format!("Embedded resource not found: {}", path).into(),
));
}
}
@@ -434,9 +564,8 @@ impl Asset for ImageAsset {
let mut buffer =
ImageBuffer::from_raw(pixmap.width(), pixmap.height(), pixmap.take()).unwrap();
// Convert from RGBA to BGRA.
for pixel in buffer.chunks_exact_mut(4) {
pixel.swap(0, 2);
swap_rgba_pa_to_bgra(pixel);
}
RenderImage::new(SmallVec::from_elem(Frame::new(buffer), 1))
@@ -450,9 +579,9 @@ impl Asset for ImageAsset {
/// An error that can occur when interacting with the image cache.
#[derive(Debug, Error, Clone)]
pub enum ImageCacheError {
/// An error that occurred while fetching an image from a remote source.
#[error("http error: {0}")]
Client(#[from] Arc<anyhow::Error>),
/// Some other kind of error occurred
#[error("error: {0}")]
Other(#[from] Arc<anyhow::Error>),
/// An error that occurred while reading the image from disk.
#[error("IO error: {0}")]
Io(Arc<std::io::Error>),
@@ -477,20 +606,26 @@ pub enum ImageCacheError {
Usvg(Arc<usvg::Error>),
}
impl From<std::io::Error> for ImageCacheError {
fn from(error: std::io::Error) -> Self {
Self::Io(Arc::new(error))
impl From<anyhow::Error> for ImageCacheError {
fn from(value: anyhow::Error) -> Self {
Self::Other(Arc::new(value))
}
}
impl From<ImageError> for ImageCacheError {
fn from(error: ImageError) -> Self {
Self::Image(Arc::new(error))
impl From<io::Error> for ImageCacheError {
fn from(value: io::Error) -> Self {
Self::Io(Arc::new(value))
}
}
impl From<usvg::Error> for ImageCacheError {
fn from(error: usvg::Error) -> Self {
Self::Usvg(Arc::new(error))
fn from(value: usvg::Error) -> Self {
Self::Usvg(Arc::new(value))
}
}
impl From<image::ImageError> for ImageCacheError {
fn from(value: image::ImageError) -> Self {
Self::Image(Arc::new(value))
}
}

View File

@@ -27,11 +27,11 @@ mod test;
mod windows;
use crate::{
point, Action, AnyWindowHandle, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds,
DevicePixels, DispatchEventResult, Font, FontId, FontMetrics, FontRun, ForegroundExecutor,
GPUSpecs, GlyphId, ImageSource, Keymap, LineLayout, Pixels, PlatformInput, Point,
RenderGlyphParams, RenderImage, RenderImageParams, RenderSvgParams, ScaledPixels, Scene,
SharedString, Size, SvgSize, Task, TaskLabel, WindowContext, DEFAULT_WINDOW_SIZE,
point, Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels,
DispatchEventResult, Font, FontId, FontMetrics, FontRun, ForegroundExecutor, GPUSpecs, GlyphId,
ImageSource, Keymap, LineLayout, Pixels, PlatformInput, Point, RenderGlyphParams, RenderImage,
RenderImageParams, RenderSvgParams, ScaledPixels, Scene, SharedString, Size, SvgRenderer,
SvgSize, Task, TaskLabel, WindowContext, DEFAULT_WINDOW_SIZE,
};
use anyhow::{anyhow, Result};
use async_task::Runnable;
@@ -1264,11 +1264,13 @@ impl Image {
/// Use the GPUI `use_asset` API to make this image renderable
pub fn use_render_image(self: Arc<Self>, cx: &mut WindowContext) -> Option<Arc<RenderImage>> {
ImageSource::Image(self).use_data(cx)
ImageSource::Image(self)
.use_data(cx)
.and_then(|result| result.ok())
}
/// Convert the clipboard image to an `ImageData` object.
pub fn to_image_data(&self, cx: &AppContext) -> Result<Arc<RenderImage>> {
pub fn to_image_data(&self, svg_renderer: SvgRenderer) -> Result<Arc<RenderImage>> {
fn frames_for_image(
bytes: &[u8],
format: image::ImageFormat,
@@ -1305,10 +1307,7 @@ impl Image {
ImageFormat::Bmp => frames_for_image(&self.bytes, image::ImageFormat::Bmp)?,
ImageFormat::Tiff => frames_for_image(&self.bytes, image::ImageFormat::Tiff)?,
ImageFormat::Svg => {
// TODO: Fix this
let pixmap = cx
.svg_renderer()
.render_pixmap(&self.bytes, SvgSize::ScaleFactor(1.0))?;
let pixmap = svg_renderer.render_pixmap(&self.bytes, SvgSize::ScaleFactor(1.0))?;
let buffer =
image::ImageBuffer::from_raw(pixmap.width(), pixmap.height(), pixmap.take())

View File

@@ -12,15 +12,14 @@ pub struct Keystroke {
/// e.g. for option-s, key is "s"
pub key: String,
/// key_char is the character that could have been typed when
/// this binding was pressed.
/// e.g. for s this is "s", for option-s "ß", and cmd-s None
pub key_char: Option<String>,
/// ime_key is the character inserted by the IME engine when that key was pressed.
/// e.g. for option-s, ime_key is "ß"
pub ime_key: Option<String>,
}
impl Keystroke {
/// When matching a key we cannot know whether the user intended to type
/// the key_char or the key itself. On some non-US keyboards keys we use in our
/// the ime_key or the key itself. On some non-US keyboards keys we use in our
/// bindings are behind option (for example `$` is typed `alt-ç` on a Czech keyboard),
/// and on some keyboards the IME handler converts a sequence of keys into a
/// specific character (for example `"` is typed as `" space` on a brazilian keyboard).
@@ -28,10 +27,10 @@ impl Keystroke {
/// This method assumes that `self` was typed and `target' is in the keymap, and checks
/// both possibilities for self against the target.
pub(crate) fn should_match(&self, target: &Keystroke) -> bool {
if let Some(key_char) = self
.key_char
if let Some(ime_key) = self
.ime_key
.as_ref()
.filter(|key_char| key_char != &&self.key)
.filter(|ime_key| ime_key != &&self.key)
{
let ime_modifiers = Modifiers {
control: self.modifiers.control,
@@ -39,7 +38,7 @@ impl Keystroke {
..Default::default()
};
if &target.key == key_char && target.modifiers == ime_modifiers {
if &target.key == ime_key && target.modifiers == ime_modifiers {
return true;
}
}
@@ -48,9 +47,9 @@ impl Keystroke {
}
/// key syntax is:
/// [ctrl-][alt-][shift-][cmd-][fn-]key[->key_char]
/// key_char syntax is only used for generating test events,
/// when matching a key with an key_char set will be matched without it.
/// [ctrl-][alt-][shift-][cmd-][fn-]key[->ime_key]
/// ime_key syntax is only used for generating test events,
/// when matching a key with an ime_key set will be matched without it.
pub fn parse(source: &str) -> anyhow::Result<Self> {
let mut control = false;
let mut alt = false;
@@ -58,7 +57,7 @@ impl Keystroke {
let mut platform = false;
let mut function = false;
let mut key = None;
let mut key_char = None;
let mut ime_key = None;
let mut components = source.split('-').peekable();
while let Some(component) = components.next() {
@@ -75,7 +74,7 @@ impl Keystroke {
break;
} else if next.len() > 1 && next.starts_with('>') {
key = Some(String::from(component));
key_char = Some(String::from(&next[1..]));
ime_key = Some(String::from(&next[1..]));
components.next();
} else {
return Err(anyhow!("Invalid keystroke `{}`", source));
@@ -119,7 +118,7 @@ impl Keystroke {
function,
},
key,
key_char: key_char,
ime_key,
})
}
@@ -155,7 +154,7 @@ impl Keystroke {
/// Returns true if this keystroke left
/// the ime system in an incomplete state.
pub fn is_ime_in_progress(&self) -> bool {
self.key_char.is_none()
self.ime_key.is_none()
&& (is_printable_key(&self.key) || self.key.is_empty())
&& !(self.modifiers.platform
|| self.modifiers.control
@@ -163,17 +162,17 @@ impl Keystroke {
|| self.modifiers.alt)
}
/// Returns a new keystroke with the key_char filled.
/// Returns a new keystroke with the ime_key filled.
/// This is used for dispatch_keystroke where we want users to
/// be able to simulate typing "space", etc.
pub fn with_simulated_ime(mut self) -> Self {
if self.key_char.is_none()
if self.ime_key.is_none()
&& !self.modifiers.platform
&& !self.modifiers.control
&& !self.modifiers.function
&& !self.modifiers.alt
{
self.key_char = match self.key.as_str() {
self.ime_key = match self.key.as_str() {
"space" => Some(" ".into()),
"tab" => Some("\t".into()),
"enter" => Some("\n".into()),
@@ -223,6 +222,8 @@ fn is_printable_key(key: &str) -> bool {
| "insert"
| "home"
| "end"
| "back"
| "forward"
| "escape"
)
}

View File

@@ -684,6 +684,8 @@ impl Keystroke {
Keysym::ISO_Left_Tab => "tab".to_owned(),
Keysym::KP_Prior => "pageup".to_owned(),
Keysym::KP_Next => "pagedown".to_owned(),
Keysym::XF86_Back => "back".to_owned(),
Keysym::XF86_Forward => "forward".to_owned(),
Keysym::comma => ",".to_owned(),
Keysym::period => ".".to_owned(),
@@ -740,14 +742,14 @@ impl Keystroke {
}
}
// Ignore control characters (and DEL) for the purposes of key_char
let key_char =
// Ignore control characters (and DEL) for the purposes of ime_key
let ime_key =
(key_utf32 >= 32 && key_utf32 != 127 && !key_utf8.is_empty()).then_some(key_utf8);
Keystroke {
modifiers,
key,
key_char,
ime_key,
}
}

View File

@@ -1208,7 +1208,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
compose.feed(keysym);
match compose.status() {
xkb::Status::Composing => {
keystroke.key_char = None;
keystroke.ime_key = None;
state.pre_edit_text =
compose.utf8().or(Keystroke::underlying_dead_key(keysym));
let pre_edit =
@@ -1220,7 +1220,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
xkb::Status::Composed => {
state.pre_edit_text.take();
keystroke.key_char = compose.utf8();
keystroke.ime_key = compose.utf8();
if let Some(keysym) = compose.keysym() {
keystroke.key = xkb::keysym_get_name(keysym);
}
@@ -1340,7 +1340,7 @@ impl Dispatch<zwp_text_input_v3::ZwpTextInputV3, ()> for WaylandClientStatePtr {
keystroke: Keystroke {
modifiers: Modifiers::default(),
key: commit_text.clone(),
key_char: Some(commit_text),
ime_key: Some(commit_text),
},
is_held: false,
}));

View File

@@ -687,11 +687,11 @@ impl WaylandWindowStatePtr {
}
}
if let PlatformInput::KeyDown(event) = input {
if let Some(key_char) = &event.keystroke.key_char {
if let Some(ime_key) = &event.keystroke.ime_key {
let mut state = self.state.borrow_mut();
if let Some(mut input_handler) = state.input_handler.take() {
drop(state);
input_handler.replace_text_in_range(None, key_char);
input_handler.replace_text_in_range(None, ime_key);
self.state.borrow_mut().input_handler = Some(input_handler);
}
}

View File

@@ -178,7 +178,7 @@ pub struct X11ClientState {
pub(crate) compose_state: Option<xkbc::compose::State>,
pub(crate) pre_edit_text: Option<String>,
pub(crate) composing: bool,
pub(crate) pre_key_char_down: Option<Keystroke>,
pub(crate) pre_ime_key_down: Option<Keystroke>,
pub(crate) cursor_handle: cursor::Handle,
pub(crate) cursor_styles: HashMap<xproto::Window, CursorStyle>,
pub(crate) cursor_cache: HashMap<CursorStyle, xproto::Cursor>,
@@ -446,7 +446,7 @@ impl X11Client {
compose_state,
pre_edit_text: None,
pre_key_char_down: None,
pre_ime_key_down: None,
composing: false,
cursor_handle,
@@ -858,7 +858,7 @@ impl X11Client {
let modifiers = modifiers_from_state(event.state);
state.modifiers = modifiers;
state.pre_key_char_down.take();
state.pre_ime_key_down.take();
let keystroke = {
let code = event.detail.into();
let xkb_state = state.previous_xkb_state.clone();
@@ -880,13 +880,13 @@ impl X11Client {
match compose_state.status() {
xkbc::Status::Composed => {
state.pre_edit_text.take();
keystroke.key_char = compose_state.utf8();
keystroke.ime_key = compose_state.utf8();
if let Some(keysym) = compose_state.keysym() {
keystroke.key = xkbc::keysym_get_name(keysym);
}
}
xkbc::Status::Composing => {
keystroke.key_char = None;
keystroke.ime_key = None;
state.pre_edit_text = compose_state
.utf8()
.or(crate::Keystroke::underlying_dead_key(keysym));
@@ -1156,7 +1156,7 @@ impl X11Client {
match event {
Event::KeyPress(event) | Event::KeyRelease(event) => {
let mut state = self.0.borrow_mut();
state.pre_key_char_down = Some(Keystroke::from_xkb(
state.pre_ime_key_down = Some(Keystroke::from_xkb(
&state.xkb,
state.modifiers,
event.detail.into(),
@@ -1187,11 +1187,11 @@ impl X11Client {
fn xim_handle_commit(&self, window: xproto::Window, text: String) -> Option<()> {
let window = self.get_window(window).unwrap();
let mut state = self.0.borrow_mut();
let keystroke = state.pre_key_char_down.take();
let keystroke = state.pre_ime_key_down.take();
state.composing = false;
drop(state);
if let Some(mut keystroke) = keystroke {
keystroke.key_char = Some(text.clone());
keystroke.ime_key = Some(text.clone());
window.handle_input(PlatformInput::KeyDown(crate::KeyDownEvent {
keystroke,
is_held: false,

View File

@@ -846,9 +846,9 @@ impl X11WindowStatePtr {
if let PlatformInput::KeyDown(event) = input {
let mut state = self.state.borrow_mut();
if let Some(mut input_handler) = state.input_handler.take() {
if let Some(key_char) = &event.keystroke.key_char {
if let Some(ime_key) = &event.keystroke.ime_key {
drop(state);
input_handler.replace_text_in_range(None, key_char);
input_handler.replace_text_in_range(None, ime_key);
state = self.state.borrow_mut();
}
state.input_handler = Some(input_handler);

View File

@@ -245,7 +245,7 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
.charactersIgnoringModifiers()
.to_str()
.to_string();
let mut key_char = None;
let mut ime_key = None;
let first_char = characters.chars().next().map(|ch| ch as u16);
let modifiers = native_event.modifierFlags();
@@ -261,19 +261,13 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
#[allow(non_upper_case_globals)]
let key = match first_char {
Some(SPACE_KEY) => {
key_char = Some(" ".to_string());
ime_key = Some(" ".to_string());
"space".to_string()
}
Some(TAB_KEY) => {
key_char = Some("\t".to_string());
"tab".to_string()
}
Some(ENTER_KEY) | Some(NUMPAD_ENTER_KEY) => {
key_char = Some("\n".to_string());
"enter".to_string()
}
Some(BACKSPACE_KEY) => "backspace".to_string(),
Some(ENTER_KEY) | Some(NUMPAD_ENTER_KEY) => "enter".to_string(),
Some(ESCAPE_KEY) => "escape".to_string(),
Some(TAB_KEY) => "tab".to_string(),
Some(SHIFT_TAB_KEY) => "tab".to_string(),
Some(NSUpArrowFunctionKey) => "up".to_string(),
Some(NSDownArrowFunctionKey) => "down".to_string(),
@@ -341,18 +335,6 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
chars_ignoring_modifiers = chars_with_cmd;
}
if !control && !command && !function {
let mut mods = NO_MOD;
if shift {
mods |= SHIFT_MOD;
}
if alt {
mods |= OPTION_MOD;
}
key_char = Some(chars_for_modified_key(native_event.keyCode(), mods));
}
let mut key = if shift
&& chars_ignoring_modifiers
.chars()
@@ -366,6 +348,20 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
chars_ignoring_modifiers
};
if always_use_cmd_layout || alt {
let mut mods = NO_MOD;
if shift {
mods |= SHIFT_MOD;
}
if alt {
mods |= OPTION_MOD;
}
let alt_key = chars_for_modified_key(native_event.keyCode(), mods);
if alt_key != key {
ime_key = Some(alt_key);
}
};
key
}
};
@@ -379,7 +375,7 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
function,
},
key,
key_char,
ime_key,
}
}

View File

@@ -844,9 +844,7 @@ impl Platform for MacPlatform {
let app: id = msg_send![APP_CLASS, sharedApplication];
let mut state = self.0.lock();
let actions = &mut state.menu_actions;
let menu = self.create_menu_bar(menus, NSWindow::delegate(app), actions, keymap);
drop(state);
app.setMainMenu_(menu);
app.setMainMenu_(self.create_menu_bar(menus, NSWindow::delegate(app), actions, keymap));
}
}

View File

@@ -1,7 +1,8 @@
use crate::{
point, px, size, Bounds, DevicePixels, Font, FontFallbacks, FontFeatures, FontId, FontMetrics,
FontRun, FontStyle, FontWeight, GlyphId, LineLayout, Pixels, PlatformTextSystem, Point,
RenderGlyphParams, Result, ShapedGlyph, ShapedRun, SharedString, Size, SUBPIXEL_VARIANTS,
point, px, size, swap_rgba_pa_to_bgra, Bounds, DevicePixels, Font, FontFallbacks, FontFeatures,
FontId, FontMetrics, FontRun, FontStyle, FontWeight, GlyphId, LineLayout, Pixels,
PlatformTextSystem, Point, RenderGlyphParams, Result, ShapedGlyph, ShapedRun, SharedString,
Size, SUBPIXEL_VARIANTS,
};
use anyhow::anyhow;
use cocoa::appkit::CGFloat;
@@ -418,11 +419,7 @@ impl MacTextSystemState {
if params.is_emoji {
// Convert from RGBA with premultiplied alpha to BGRA with straight alpha.
for pixel in bytes.chunks_exact_mut(4) {
pixel.swap(0, 2);
let a = pixel[3] as f32 / 255.;
pixel[0] = (pixel[0] as f32 / a) as u8;
pixel[1] = (pixel[1] as f32 / a) as u8;
pixel[2] = (pixel[2] as f32 / a) as u8;
swap_rgba_pa_to_bgra(pixel);
}
}

View File

@@ -1283,17 +1283,18 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
}
if event.is_held {
if let Some(key_char) = event.keystroke.key_char.as_ref() {
let handled = with_input_handler(&this, |input_handler| {
if !input_handler.apple_press_and_hold_enabled() {
input_handler.replace_text_in_range(None, &key_char);
return YES;
}
NO
});
if handled == Some(YES) {
let handled = with_input_handler(&this, |input_handler| {
if !input_handler.apple_press_and_hold_enabled() {
input_handler.replace_text_in_range(
None,
&event.keystroke.ime_key.unwrap_or(event.keystroke.key),
);
return YES;
}
NO
});
if handled == Some(YES) {
return YES;
}
}
@@ -1436,7 +1437,7 @@ extern "C" fn cancel_operation(this: &Object, _sel: Sel, _sender: id) {
let keystroke = Keystroke {
modifiers: Default::default(),
key: ".".into(),
key_char: None,
ime_key: None,
};
let event = PlatformInput::KeyDown(KeyDownEvent {
keystroke: keystroke.clone(),

View File

@@ -386,7 +386,7 @@ fn handle_char_msg(
return Some(1);
};
drop(lock);
let key_char = keystroke.key_char.clone();
let ime_key = keystroke.ime_key.clone();
let event = KeyDownEvent {
keystroke,
is_held: lparam.0 & (0x1 << 30) > 0,
@@ -397,7 +397,7 @@ fn handle_char_msg(
if dispatch_event_result.default_prevented || !dispatch_event_result.propagate {
return Some(0);
}
let Some(ime_char) = key_char else {
let Some(ime_char) = ime_key else {
return Some(1);
};
with_input_handler(&state_ptr, |input_handler| {
@@ -1160,6 +1160,8 @@ fn parse_syskeydown_msg_keystroke(wparam: WPARAM) -> Option<Keystroke> {
VK_END => "end",
VK_PRIOR => "pageup",
VK_NEXT => "pagedown",
VK_BROWSER_BACK => "back",
VK_BROWSER_FORWARD => "forward",
VK_ESCAPE => "escape",
VK_INSERT => "insert",
VK_DELETE => "delete",
@@ -1170,7 +1172,7 @@ fn parse_syskeydown_msg_keystroke(wparam: WPARAM) -> Option<Keystroke> {
Some(Keystroke {
modifiers,
key,
key_char: None,
ime_key: None,
})
}
@@ -1196,6 +1198,8 @@ fn parse_keydown_msg_keystroke(wparam: WPARAM) -> Option<KeystrokeOrModifier> {
VK_END => "end",
VK_PRIOR => "pageup",
VK_NEXT => "pagedown",
VK_BROWSER_BACK => "back",
VK_BROWSER_FORWARD => "forward",
VK_ESCAPE => "escape",
VK_INSERT => "insert",
VK_DELETE => "delete",
@@ -1216,7 +1220,7 @@ fn parse_keydown_msg_keystroke(wparam: WPARAM) -> Option<KeystrokeOrModifier> {
return Some(KeystrokeOrModifier::Keystroke(Keystroke {
modifiers,
key: format!("f{}", offset + 1),
key_char: None,
ime_key: None,
}));
};
return None;
@@ -1227,7 +1231,7 @@ fn parse_keydown_msg_keystroke(wparam: WPARAM) -> Option<KeystrokeOrModifier> {
Some(KeystrokeOrModifier::Keystroke(Keystroke {
modifiers,
key,
key_char: None,
ime_key: None,
}))
}
@@ -1249,7 +1253,7 @@ fn parse_char_msg_keystroke(wparam: WPARAM) -> Option<Keystroke> {
Some(Keystroke {
modifiers,
key,
key_char: Some(first_char.to_string()),
ime_key: Some(first_char.to_string()),
})
}
}
@@ -1323,7 +1327,7 @@ fn basic_vkcode_to_string(code: u16, modifiers: Modifiers) -> Option<Keystroke>
Some(Keystroke {
modifiers,
key,
key_char: None,
ime_key: None,
})
}

View File

@@ -647,11 +647,47 @@ impl PlatformWindow for WindowsWindow {
}
fn set_background_appearance(&self, background_appearance: WindowBackgroundAppearance) {
self.0
.state
.borrow_mut()
let mut window_state = self.0.state.borrow_mut();
window_state
.renderer
.update_transparency(background_appearance != WindowBackgroundAppearance::Opaque);
let mut version = unsafe { std::mem::zeroed() };
let status = unsafe { windows::Wdk::System::SystemServices::RtlGetVersion(&mut version) };
if status.is_ok() {
if background_appearance == WindowBackgroundAppearance::Blurred {
if version.dwBuildNumber >= 17763 {
set_window_composition_attribute(window_state.hwnd, Some((0, 0, 0, 10)), 4);
}
} else {
if version.dwBuildNumber >= 17763 {
set_window_composition_attribute(window_state.hwnd, None, 0);
}
}
//Transparent effect might cause some flickering and performance issues due `WS_EX_COMPOSITED` is enabled
//if `WS_EX_COMPOSITED` is removed the window instance won't initiate
if background_appearance == WindowBackgroundAppearance::Transparent {
unsafe {
let current_style = GetWindowLongW(window_state.hwnd, GWL_EXSTYLE);
SetWindowLongW(
window_state.hwnd,
GWL_EXSTYLE,
current_style | WS_EX_LAYERED.0 as i32 | WS_EX_COMPOSITED.0 as i32,
);
SetLayeredWindowAttributes(window_state.hwnd, COLORREF(0), 225, LWA_ALPHA)
.inspect_err(|e| log::error!("Unable to set window to transparent: {e}"))
.ok();
};
} else {
unsafe {
let current_style = GetWindowLongW(window_state.hwnd, GWL_EXSTYLE);
SetWindowLongW(
window_state.hwnd,
GWL_EXSTYLE,
current_style & !WS_EX_LAYERED.0 as i32 & !WS_EX_COMPOSITED.0 as i32,
);
}
}
}
}
fn minimize(&self) {
@@ -932,6 +968,23 @@ struct StyleAndBounds {
cy: i32,
}
#[repr(C)]
struct WINDOWCOMPOSITIONATTRIBDATA {
attrib: u32,
pv_data: *mut std::ffi::c_void,
cb_data: usize,
}
#[repr(C)]
struct AccentPolicy {
accent_state: u32,
accent_flags: u32,
gradient_color: u32,
animation_id: u32,
}
type Color = (u8, u8, u8, u8);
#[derive(Debug, Default, Clone, Copy)]
pub(crate) struct WindowBorderOffset {
width_offset: i32,
@@ -1136,6 +1189,44 @@ fn retrieve_window_placement(
Ok(placement)
}
fn set_window_composition_attribute(hwnd: HWND, color: Option<Color>, state: u32) {
unsafe {
type SetWindowCompositionAttributeType =
unsafe extern "system" fn(HWND, *mut WINDOWCOMPOSITIONATTRIBDATA) -> BOOL;
let module_name = PCSTR::from_raw("user32.dll\0".as_ptr());
let user32 = GetModuleHandleA(module_name);
if user32.is_ok() {
let func_name = PCSTR::from_raw("SetWindowCompositionAttribute\0".as_ptr());
let set_window_composition_attribute: SetWindowCompositionAttributeType =
std::mem::transmute(GetProcAddress(user32.unwrap(), func_name));
let mut color = color.unwrap_or_default();
let is_acrylic = state == 4;
if is_acrylic && color.3 == 0 {
color.3 = 1;
}
let accent = AccentPolicy {
accent_state: state,
accent_flags: if is_acrylic { 0 } else { 2 },
gradient_color: (color.0 as u32)
| ((color.1 as u32) << 8)
| ((color.2 as u32) << 16)
| (color.3 as u32) << 24,
animation_id: 0,
};
let mut data = WINDOWCOMPOSITIONATTRIBDATA {
attrib: 0x13,
pv_data: &accent as *const _ as *mut _,
cb_data: std::mem::size_of::<AccentPolicy>(),
};
let _ = set_window_composition_attribute(hwnd, &mut data as *mut _ as _);
} else {
let _ = user32
.inspect_err(|e| log::error!("Error getting module: {e}"))
.ok();
}
}
}
mod windows_renderer {
use std::{num::NonZeroIsize, sync::Arc};

View File

@@ -5,5 +5,5 @@
pub use crate::{
util::FluentBuilder, BorrowAppContext, BorrowWindow, Context, Element, FocusableElement,
InteractiveElement, IntoElement, ParentElement, Refineable, Render, RenderOnce,
StatefulInteractiveElement, Styled, VisualContext,
StatefulInteractiveElement, Styled, StyledImage, VisualContext,
};

View File

@@ -1,7 +1,7 @@
use crate::{
self as gpui, px, relative, rems, AbsoluteLength, AlignItems, CursorStyle, DefiniteLength,
Fill, FlexDirection, FlexWrap, Font, FontStyle, FontWeight, Hsla, JustifyContent, Length,
SharedString, StyleRefinement, WhiteSpace,
SharedString, StrikethroughStyle, StyleRefinement, WhiteSpace,
};
use crate::{TextStyleRefinement, Truncate};
pub use gpui_macros::{
@@ -12,7 +12,7 @@ pub use gpui_macros::{
use taffy::style::{AlignContent, Display};
/// A trait for elements that can be styled.
/// Use this to opt-in to a CSS-like styling API.
/// Use this to opt-in to a utility CSS-like styling API.
pub trait Styled: Sized {
/// Returns a reference to the style memory of this element.
fn style(&mut self) -> &mut StyleRefinement;
@@ -323,19 +323,23 @@ pub trait Styled: Sized {
self
}
/// Get the text style that has been configured on this element.
/// Returns a mutable reference to the text style that has been configured on this element.
fn text_style(&mut self) -> &mut Option<TextStyleRefinement> {
let style: &mut StyleRefinement = self.style();
&mut style.text
}
/// Set the text color of this element, this value cascades to its child elements.
/// Sets the text color of this element.
///
/// This value cascades to its child elements.
fn text_color(mut self, color: impl Into<Hsla>) -> Self {
self.text_style().get_or_insert_with(Default::default).color = Some(color.into());
self
}
/// Set the font weight of this element, this value cascades to its child elements.
/// Sets the font weight of this element
///
/// This value cascades to its child elements.
fn font_weight(mut self, weight: FontWeight) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -343,7 +347,9 @@ pub trait Styled: Sized {
self
}
/// Set the background color of this element, this value cascades to its child elements.
/// Sets the background color of this element.
///
/// This value cascades to its child elements.
fn text_bg(mut self, bg: impl Into<Hsla>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -351,7 +357,9 @@ pub trait Styled: Sized {
self
}
/// Set the text size of this element, this value cascades to its child elements.
/// Sets the text size of this element.
///
/// This value cascades to its child elements.
fn text_size(mut self, size: impl Into<AbsoluteLength>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -359,8 +367,8 @@ pub trait Styled: Sized {
self
}
/// Set the text size to 'extra small',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
/// Sets the text size to 'extra small'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_xs(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -368,8 +376,8 @@ pub trait Styled: Sized {
self
}
/// Set the text size to 'small',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
/// Sets the text size to 'small'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_sm(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -377,7 +385,8 @@ pub trait Styled: Sized {
self
}
/// Reset the text styling for this element and its children.
/// Sets the text size to 'base'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_base(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -385,8 +394,8 @@ pub trait Styled: Sized {
self
}
/// Set the text size to 'large',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
/// Sets the text size to 'large'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_lg(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -394,8 +403,8 @@ pub trait Styled: Sized {
self
}
/// Set the text size to 'extra large',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
/// Sets the text size to 'extra large'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_xl(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -403,8 +412,8 @@ pub trait Styled: Sized {
self
}
/// Set the text size to 'extra-extra large',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
/// Sets the text size to 'extra extra large'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_2xl(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -412,8 +421,8 @@ pub trait Styled: Sized {
self
}
/// Set the text size to 'extra-extra-extra large',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
/// Sets the text size to 'extra extra extra large'.
/// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
fn text_3xl(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -421,17 +430,8 @@ pub trait Styled: Sized {
self
}
/// Set the font style to 'non-italic',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-style#italicizing-text)
fn non_italic(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
.font_style = Some(FontStyle::Normal);
self
}
/// Set the font style to 'italic',
/// see the [Tailwind Docs](https://tailwindcss.com/docs/font-style#italicizing-text)
/// Sets the font style of the element to italic.
/// [Docs](https://tailwindcss.com/docs/font-style#italicizing-text)
fn italic(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -439,7 +439,29 @@ pub trait Styled: Sized {
self
}
/// Remove the text decoration on this element, this value cascades to its child elements.
/// Sets the font style of the element to normal (not italic).
/// [Docs](https://tailwindcss.com/docs/font-style#italicizing-text)
fn not_italic(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
.font_style = Some(FontStyle::Normal);
self
}
/// Sets the decoration of the text to have a line through it.
/// [Docs](https://tailwindcss.com/docs/text-decoration#setting-the-text-decoration)
fn line_through(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
style.strikethrough = Some(StrikethroughStyle {
thickness: px(1.),
..Default::default()
});
self
}
/// Removes the text decoration on this element.
///
/// This value cascades to its child elements.
fn text_decoration_none(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -447,7 +469,7 @@ pub trait Styled: Sized {
self
}
/// Set the color for the underline on this element
/// Sets the color for the underline on this element
fn text_decoration_color(mut self, color: impl Into<Hsla>) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -455,7 +477,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to a solid line
/// Sets the text decoration style to a solid line.
/// [Docs](https://tailwindcss.com/docs/text-decoration-style)
fn text_decoration_solid(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -463,7 +486,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to a wavy line
/// Sets the text decoration style to a wavy line.
/// [Docs](https://tailwindcss.com/docs/text-decoration-style)
fn text_decoration_wavy(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -471,7 +495,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to be 0 thickness, see the [Tailwind Docs](https://tailwindcss.com/docs/text-decoration-thickness)
/// Sets the text decoration to be 0px thick.
/// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
fn text_decoration_0(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -479,7 +504,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to be 1px thick, see the [Tailwind Docs](https://tailwindcss.com/docs/text-decoration-thickness)
/// Sets the text decoration to be 1px thick.
/// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
fn text_decoration_1(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -487,7 +513,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to be 2px thick, see the [Tailwind Docs](https://tailwindcss.com/docs/text-decoration-thickness)
/// Sets the text decoration to be 2px thick.
/// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
fn text_decoration_2(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -495,7 +522,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to be 4px thick, see the [Tailwind Docs](https://tailwindcss.com/docs/text-decoration-thickness)
/// Sets the text decoration to be 4px thick.
/// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
fn text_decoration_4(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -503,7 +531,8 @@ pub trait Styled: Sized {
self
}
/// Set the underline to be 8px thick, see the [Tailwind Docs](https://tailwindcss.com/docs/text-decoration-thickness)
/// Sets the text decoration to be 8px thick.
/// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
fn text_decoration_8(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default);
let underline = style.underline.get_or_insert_with(Default::default);
@@ -511,7 +540,7 @@ pub trait Styled: Sized {
self
}
/// Change the font family on this element and its children.
/// Sets the font family of this element and its children.
fn font_family(mut self, family_name: impl Into<SharedString>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -519,7 +548,7 @@ pub trait Styled: Sized {
self
}
/// Change the font of this element and its children.
/// Sets the font of this element and its children.
fn font(mut self, font: Font) -> Self {
let Font {
family,
@@ -539,7 +568,7 @@ pub trait Styled: Sized {
self
}
/// Set the line height on this element and its children.
/// Sets the line height of this element and its children.
fn line_height(mut self, line_height: impl Into<DefiniteLength>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -547,20 +576,20 @@ pub trait Styled: Sized {
self
}
/// Set opacity on this element and its children.
/// Sets the opacity of this element and its children.
fn opacity(mut self, opacity: f32) -> Self {
self.style().opacity = Some(opacity);
self
}
/// Draw a debug border around this element.
/// Draws a debug border around this element.
#[cfg(debug_assertions)]
fn debug(mut self) -> Self {
self.style().debug = Some(true);
self
}
/// Draw a debug border on all conforming elements below this element.
/// Draws a debug border on all conforming elements below this element.
#[cfg(debug_assertions)]
fn debug_below(mut self) -> Self {
self.style().debug_below = Some(true);

View File

@@ -10,7 +10,7 @@ pub(crate) struct RenderSvgParams {
}
#[derive(Clone)]
pub(crate) struct SvgRenderer {
pub struct SvgRenderer {
asset_source: Arc<dyn AssetSource>,
}
@@ -24,7 +24,7 @@ impl SvgRenderer {
Self { asset_source }
}
pub fn render(&self, params: &RenderSvgParams) -> Result<Option<Vec<u8>>> {
pub(crate) fn render(&self, params: &RenderSvgParams) -> Result<Option<Vec<u8>>> {
if params.size.is_zero() {
return Err(anyhow!("can't render at a zero size"));
}

View File

@@ -44,6 +44,21 @@ impl ShapedLine {
self.layout.len
}
/// Override the len, useful if you're rendering text a
/// as text b (e.g. rendering invisibles).
pub fn with_len(mut self, len: usize) -> Self {
let layout = self.layout.as_ref();
self.layout = Arc::new(LineLayout {
font_size: layout.font_size,
width: layout.width,
ascent: layout.ascent,
descent: layout.descent,
runs: layout.runs.clone(),
len,
});
self
}
/// Paint the line of text to the window.
pub fn paint(
&self,

View File

@@ -29,7 +29,7 @@ pub struct LineLayout {
}
/// A run of text that has been shaped .
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ShapedRun {
/// The font id for this run
pub font_id: FontId,

View File

@@ -900,7 +900,13 @@ impl<'a> WindowContext<'a> {
/// Indicate that this view has changed, which will invoke any observers and also mark the window as dirty.
/// If this view or any of its ancestors are *cached*, notifying it will cause it or its ancestors to be redrawn.
pub fn notify(&mut self, view_id: EntityId) {
/// Note that this method will always cause a redraw, the entire window is refreshed if view_id is None.
pub fn notify(&mut self, view_id: Option<EntityId>) {
let Some(view_id) = view_id else {
self.refresh();
return;
};
for view_id in self
.window
.rendered_frame
@@ -1165,13 +1171,7 @@ impl<'a> WindowContext<'a> {
/// If called from within a view, it will notify that view on the next frame. Otherwise, it will refresh the entire window.
pub fn request_animation_frame(&self) {
let parent_id = self.parent_view_id();
self.on_next_frame(move |cx| {
if let Some(parent_id) = parent_id {
cx.notify(parent_id)
} else {
cx.refresh()
}
});
self.on_next_frame(move |cx| cx.notify(parent_id));
}
/// Spawn the future returned by the given closure on the application thread pool.
@@ -1982,9 +1982,7 @@ impl<'a> WindowContext<'a> {
///
/// Note that the multiple calls to this method will only result in one `Asset::load` call at a
/// time.
///
/// This asset will not be cached by default, see [Self::use_cached_asset]
pub fn use_asset<A: Asset + 'static>(&mut self, source: &A::Source) -> Option<A::Output> {
pub fn use_asset<A: Asset>(&mut self, source: &A::Source) -> Option<A::Output> {
let (task, is_first) = self.fetch_asset::<A>(source);
task.clone().now_or_never().or_else(|| {
if is_first {
@@ -1994,13 +1992,7 @@ impl<'a> WindowContext<'a> {
|mut cx| async move {
task.await;
cx.on_next_frame(move |cx| {
if let Some(parent_id) = parent_id {
cx.notify(parent_id)
} else {
cx.refresh()
}
});
cx.on_next_frame(move |cx| cx.notify(parent_id));
}
})
.detach();
@@ -2163,6 +2155,9 @@ impl<'a> WindowContext<'a> {
/// A variant of `with_element_state` that allows the element's id to be optional. This is a convenience
/// method for elements where the element id may or may not be assigned. Prefer using `with_element_state`
/// when the element is guaranteed to have an id.
///
/// The first option means 'no ID provided'
/// The second option means 'not yet initialized'
pub fn with_optional_element_state<S, R>(
&mut self,
global_id: Option<&GlobalElementId>,
@@ -3043,7 +3038,7 @@ impl<'a> WindowContext<'a> {
return true;
}
if let Some(input) = keystroke.key_char {
if let Some(input) = keystroke.with_simulated_ime().ime_key {
if let Some(mut input_handler) = self.window.platform_window.take_input_handler() {
input_handler.dispatch_input(&input, self);
self.window.platform_window.set_input_handler(input_handler);
@@ -3055,7 +3050,7 @@ impl<'a> WindowContext<'a> {
}
/// Represent this action as a key binding string, to display in the UI.
pub fn keystroke_text_for(&self, action: &dyn Action) -> String {
pub fn keystroke_text_for_action(&self, action: &dyn Action) -> String {
self.bindings_for_action(action)
.into_iter()
.next()
@@ -3070,6 +3065,26 @@ impl<'a> WindowContext<'a> {
.unwrap_or_else(|| action.name().to_string())
}
/// Represent this action as a key binding string, to display in the UI.
pub fn keystroke_text_for_action_in(
&self,
action: &dyn Action,
focus_handle: &FocusHandle,
) -> String {
self.bindings_for_action_in(action, focus_handle)
.into_iter()
.next()
.map(|binding| {
binding
.keystrokes()
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(" ")
})
.unwrap_or_else(|| action.name().to_string())
}
/// Dispatch a mouse or keyboard event on the window.
#[profiling::function]
pub fn dispatch_event(&mut self, event: PlatformInput) -> DispatchEventResult {
@@ -3252,7 +3267,7 @@ impl<'a> WindowContext<'a> {
if let Some(key) = key {
keystroke = Some(Keystroke {
key: key.to_string(),
key_char: None,
ime_key: None,
modifiers: Modifiers::default(),
});
}
@@ -3467,7 +3482,13 @@ impl<'a> WindowContext<'a> {
if !self.propagate_event {
continue 'replay;
}
if let Some(input) = replay.keystroke.key_char.as_ref().cloned() {
if let Some(input) = replay
.keystroke
.with_simulated_ime()
.ime_key
.as_ref()
.cloned()
{
if let Some(mut input_handler) = self.window.platform_window.take_input_handler() {
input_handler.dispatch_input(&input, self);
self.window.platform_window.set_input_handler(input_handler)
@@ -4227,7 +4248,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
/// Indicate that this view has changed, which will invoke any observers and also mark the window as dirty.
/// If this view or any of its ancestors are *cached*, notifying it will cause it or its ancestors to be redrawn.
pub fn notify(&mut self) {
self.window_cx.notify(self.view.entity_id());
self.window_cx.notify(Some(self.view.entity_id()));
}
/// Register a callback to be invoked when the window is resized.

View File

@@ -13,21 +13,10 @@ use std::fmt;
use std::{
any::type_name,
sync::{Arc, Mutex},
time::Duration,
};
pub use url::Url;
#[derive(Clone, Debug)]
pub struct ReadTimeout(pub Duration);
impl Default for ReadTimeout {
fn default() -> Self {
Self(Duration::from_secs(5))
}
}
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
pub enum RedirectPolicy {
#[default]
NoFollow,
@@ -37,20 +26,11 @@ pub enum RedirectPolicy {
pub struct FollowRedirects(pub bool);
pub trait HttpRequestExt {
/// Set a read timeout on the request.
/// For isahc, this is the low_speed_timeout.
/// For other clients, this is the timeout used for read calls when reading the response.
/// In all cases this prevents servers stalling completely, but allows them to send data slowly.
fn read_timeout(self, timeout: Duration) -> Self;
/// Whether or not to follow redirects
fn follow_redirects(self, follow: RedirectPolicy) -> Self;
}
impl HttpRequestExt for http::request::Builder {
fn read_timeout(self, timeout: Duration) -> Self {
self.extension(ReadTimeout(timeout))
}
fn follow_redirects(self, follow: RedirectPolicy) -> Self {
self.extension(follow)
}

Some files were not shown because too many files have changed in this diff Show More