Detailed changes
@@ -15,6 +15,7 @@ runs:
# will have more fixes & suppression for the standard lint set
run: |
cargo clippy --workspace --all-features --all-targets -- -A clippy::all -D clippy::dbg_macro -D clippy::todo
+ cargo clippy -p gpui
- name: Find modified migrations
shell: bash -euxo pipefail {0}
@@ -18,10 +18,6 @@ runs:
shell: bash -euxo pipefail {0}
run: script/clear-target-dir-if-larger-than 100
- - name: Run check
- shell: bash -euxo pipefail {0}
- run: cargo check --tests --workspace
-
- name: Run tests
shell: bash -euxo pipefail {0}
run: cargo nextest run --workspace --no-fail-fast
@@ -3,36 +3,35 @@ name: Randomized Tests
concurrency: randomized-tests
on:
- push:
- branches:
- - randomized-tests-runner
- # schedule:
- # - cron: '0 * * * *'
+ push:
+ branches:
+ - randomized-tests-runner
+ # schedule:
+ # - cron: '0 * * * *'
env:
- CARGO_TERM_COLOR: always
- CARGO_INCREMENTAL: 0
- RUST_BACKTRACE: 1
- ZED_SERVER_URL: https://zed.dev
- ZED_CLIENT_SECRET_TOKEN: ${{ secrets.ZED_CLIENT_SECRET_TOKEN }}
+ CARGO_TERM_COLOR: always
+ CARGO_INCREMENTAL: 0
+ RUST_BACKTRACE: 1
+ ZED_SERVER_URL: https://zed.dev
jobs:
- tests:
- name: Run randomized tests
- runs-on:
- - self-hosted
- - randomized-tests
- steps:
- - name: Install Node
- uses: actions/setup-node@v3
- with:
- node-version: "18"
+ tests:
+ name: Run randomized tests
+ runs-on:
+ - self-hosted
+ - randomized-tests
+ steps:
+ - name: Install Node
+ uses: actions/setup-node@v3
+ with:
+ node-version: "18"
- - name: Checkout repo
- uses: actions/checkout@v3
- with:
- clean: false
- submodules: "recursive"
+ - name: Checkout repo
+ uses: actions/checkout@v3
+ with:
+ clean: false
+ submodules: "recursive"
- - name: Run randomized tests
- run: script/randomized-test-ci
+ - name: Run randomized tests
+ run: script/randomized-test-ci
@@ -0,0 +1,3 @@
+# Code of Conduct
+
+The Code of Conduct for this repository can be found online at [zed.dev/docs/code-of-conduct](https://zed.dev/docs/code-of-conduct).
@@ -1,25 +1,44 @@
-# CONTRIBUTING
+# Contributing to Zed
Thanks for your interest in contributing to Zed, the collaborative platform that is also a code editor!
-We want to ensure that no one ends up spending time on a pull request that may not be accepted, so we ask that you discuss your ideas with the team and community before starting on a contribution.
+We want to avoid anyone spending time on a pull request that may not be accepted, so we suggest you discuss your ideas with the team and community before starting on major changes. Bug fixes, however, are almost always welcome.
-All activity in Zed communities is subject to our [Code of Conduct](https://docs.zed.dev/community/code-of-conduct). Contributors to Zed must sign our Contributor License Agreement (link coming soon) before their contributions can be merged.
+All activity in Zed forums is subject to our [Code of Conduct](https://docs.zed.dev/community/code-of-conduct). Additionally, contributors must sign our [Contributor License Agreement](https://zed.dev/cla) before their contributions can be merged.
## Contribution ideas
-If you already have an idea of what you'd like to contribute, you can skip this section, otherwise, here are a few resources to help you find something to work on:
+If you're looking for ideas about what to work on, check out:
-- Our public roadmap (link coming soon!) details what features we plan to add to Zed.
-- Our [Top-Ranking Issues issue](https://github.com/zed-industries/community/issues/52) shows the most popular feature requests and issues, as voted on by the community.
+- Our public roadmap (link coming soon!) contains a rough outline of our near-term priorities for Zed.
+- Our [top-ranking issues](https://github.com/zed-industries/community/issues/52) based on votes by the community.
-At the moment, we are generally not looking to extend Zed's language or theme support by directly adding these features to Zed - we really want to build a plugin system to handle making the editor extensible going forward.
+Outside of a handful of extremely popular languages and themes, we are generally not looking to extend Zed's language or theme support by directly building them into Zed. We really want to build a plugin system to handle making the editor extensible going forward. If you are passionate about shipping new languages or themes we suggest contributing to the extension system to help us get there faster.
-If you are passionate about shipping new languages or themes we suggest contributing to the extension system to help us get there faster.
+## Proposing changes
-## Resources
+The best way to propose a change is to [start a discussion on our GitHub repository](https://github.com/zed-industries/zed/discussions).
-### Bird-eye's view of Zed
+First, write a short **problem statement**, which *clearly* and *briefly* describes the problem you want to solve independently from any specific solution. It doesn't need to be long or formal, but it's difficult to consider a solution in absence of a clear understanding of the problem.
+
+Next, write a short **solution proposal**. How can the problem (or set of problems) you have stated above be addressed? What are the pros and cons of your approach? Again, keep it brief and informal. This isn't a specification, but rather a starting point for a conversation.
+
+By effectively engaging with the Zed team and community early in your process, we're better positioned to give you feedback and understand your pull request once you open it. If the first thing we see from you is a big changeset, we're much less likely to respond to it in a timely manner.
+
+## Pair programming
+
+We plan to set aside time each week to pair program with contributors on promising pull requests in Zed. This will be an experiment. We tend to prefer pairing over async code review on our team, and we'd like to see how well it works in an open source setting. If we're finding it difficult to get on the same page with async review, we may ask you to pair with us if you're open to it. The closer a contribution is to the goals outlined in our roadmap, the more likely we'll be to spend time pairing on it.
+
+## Tips to improve the chances of your PR getting reviewed and merged
+
+- Discuss your plans ahead of time with the team
+- Small, focused, incremental pull requests are much easier to review
+- Spend time explaining your changes in the pull request body
+- Add test coverage and documentation
+- Choose tasks that align with our roadmap
+- Pair with us and watch us code to learn the codebase
+
+## Bird-eye's view of Zed
Zed is made up of several smaller crates - let's go over those you're most likely to interact with:
@@ -34,24 +53,3 @@ Zed is made up of several smaller crates - let's go over those you're most likel
- [rpc](/crates/rpc) defines messages to be exchanged with collaboration server.
- [theme](/crates/theme) defines the theme system and provides a default theme.
- [ui](/crates/ui) is a collection of UI components and common patterns used throughout Zed.
-
-### Proposal & Discussion
-
-Before starting on a contribution, we ask that you look to see if there is any existing PRs, or in-Zed discussions about the thing you want to implement. If there is no existing work, find a public channel that is relevant to your contribution, check the channel notes to see which Zed team members typically work in that channel, and post a message in the chat. If you're not sure which channel is best, you can start a discussion, ask a team member or another contributor.
-
-*Please remember contributions not discussed with the team ahead of time likely have a lower chance of being merged or looked at in a timely manner.*
-
-## Implementation & Help
-
-When you start working on your contribution if you find you are struggling with something specific feel free to reach out to the team for help.
-
-Remember the team is more likely to be available to help if you have already discussed your contribution or are working on something that is higher priority, like something on the roadmap or a top-ranking issue.
-
-We're happy to pair with you to help you learn the codebase and get your contribution merged.
-
-**Zed makes heavy use of unit and integration testing, it is highly likely that contributions without any unit tests will be rejected**
-
-Reviewing code in a pull request, after the fact, is hard and tedious - the team generally likes to build trust and review code through pair programming.
-We'd prefer have conversations about the code, through Zed, while it is being written, so decisions can be made in real-time and less time is spent on fixing things after the fact. Ideally, GitHub is only used to merge code that has already been discussed and reviewed in Zed.
-
-Remember that smaller, incremental PRs are easier to review and merge than large PRs.
@@ -1452,7 +1452,7 @@ dependencies = [
[[package]]
name = "collab"
-version = "0.38.0"
+version = "0.40.1"
dependencies = [
"anyhow",
"async-trait",
@@ -1463,6 +1463,7 @@ dependencies = [
"base64 0.13.1",
"call",
"channel",
+ "chrono",
"clap 3.2.25",
"client",
"clock",
@@ -93,6 +93,7 @@ resolver = "2"
anyhow = { version = "1.0.57" }
async-trait = { version = "0.1" }
async-compression = { version = "0.4", features = ["gzip", "futures-io"] }
+chrono = { version = "0.4", features = ["serde"] }
ctor = "0.2.6"
derive_more = { version = "0.99.17" }
env_logger = { version = "0.9" }
@@ -0,0 +1,788 @@
+Copyright 2022 - 2024 Zed Industries, Inc.
+
+
+
+
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+
+ GNU AFFERO GENERAL PUBLIC LICENSE
+ Version 3, 19 November 2007
+
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ Preamble
+
+
+ The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+
+ Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+
+ A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+
+ The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+
+ An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+
+ TERMS AND CONDITIONS
+
+
+ 0. Definitions.
+
+
+ "This License" refers to version 3 of the GNU Affero General Public License.
+
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+
+ 1. Source Code.
+
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+
+ 2. Basic Permissions.
+
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+
+ 4. Conveying Verbatim Copies.
+
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+
+ 5. Conveying Modified Source Versions.
+
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+
+ 6. Conveying Non-Source Forms.
+
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+
+ 7. Additional Terms.
+
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+
+ 8. Termination.
+
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+
+ 9. Acceptance Not Required for Having Copies.
+
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+
+ 11. Patents.
+
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+
+ 12. No Surrender of Others' Freedom.
+
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+
+ 13. Remote Network Interaction; Use with the GNU General Public License.
+
+
+ Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+
+ 14. Revised Versions of this License.
+
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+
+ 15. Disclaimer of Warranty.
+
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+
+ 16. Limitation of Liability.
+
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+
+ 17. Interpretation of Sections 15 and 16.
+
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+
+ END OF TERMS AND CONDITIONS
+
+
+ How to Apply These Terms to Your New Programs
+
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+
+ If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<https://www.gnu.org/licenses/>.
@@ -0,0 +1,222 @@
+Copyright 2022 - 2024 Zed Industries, Inc.
+
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
+
+Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+
+ 1. Definitions.
+
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,674 @@
+GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.
@@ -1,10 +1,3 @@
-# ๐ง TODO ๐ง
-
-- [ ] Add intro
-- [ ] Add link to contributing guide
-- [ ] Add barebones running zed from source instructions
-- [ ] Link out to further dev docs
-
# Zed
[](https://github.com/zed-industries/zed/actions/workflows/ci.yml)
@@ -16,7 +9,11 @@ Welcome to Zed, a high-performance, multiplayer code editor from the creators of
- [Building Zed](./docs/src/developing_zed__building_zed.md)
- [Running Collaboration Locally](./docs/src/developing_zed__local_collaboration.md)
-### Licensing
+## Contributing
+
+See [CONTRIBUTING.md](./CONTRIBUTING.md) for ways you can contribute to Zed.
+
+## Licensing
License information for third party dependencies must be correctly provided for CI to pass.
@@ -1,93 +0,0 @@
-Copyright ยฉ 2017 IBM Corp. with Reserved Font Name "Plex"
-
-This Font Software is licensed under the SIL Open Font License, Version 1.1.
-
-This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-
-
------------------------------------------------------------
-SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
------------------------------------------------------------
-
-PREAMBLE
-The goals of the Open Font License (OFL) are to stimulate worldwide
-development of collaborative font projects, to support the font creation
-efforts of academic and linguistic communities, and to provide a free and
-open framework in which fonts may be shared and improved in partnership
-with others.
-
-The OFL allows the licensed fonts to be used, studied, modified and
-redistributed freely as long as they are not sold by themselves. The
-fonts, including any derivative works, can be bundled, embedded,
-redistributed and/or sold with any software provided that any reserved
-names are not used by derivative works. The fonts and derivatives,
-however, cannot be released under any other type of license. The
-requirement for fonts to remain under this license does not apply
-to any document created using the fonts or their derivatives.
-
-DEFINITIONS
-"Font Software" refers to the set of files released by the Copyright
-Holder(s) under this license and clearly marked as such. This may
-include source files, build scripts and documentation.
-
-"Reserved Font Name" refers to any names specified as such after the
-copyright statement(s).
-
-"Original Version" refers to the collection of Font Software components as
-distributed by the Copyright Holder(s).
-
-"Modified Version" refers to any derivative made by adding to, deleting,
-or substituting -- in part or in whole -- any of the components of the
-Original Version, by changing formats or by porting the Font Software to a
-new environment.
-
-"Author" refers to any designer, engineer, programmer, technical
-writer or other person who contributed to the Font Software.
-
-PERMISSION & CONDITIONS
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Font Software, to use, study, copy, merge, embed, modify,
-redistribute, and sell modified and unmodified copies of the Font
-Software, subject to the following conditions:
-
-1) Neither the Font Software nor any of its individual components,
-in Original or Modified Versions, may be sold by itself.
-
-2) Original or Modified Versions of the Font Software may be bundled,
-redistributed and/or sold with any software, provided that each copy
-contains the above copyright notice and this license. These can be
-included either as stand-alone text files, human-readable headers or
-in the appropriate machine-readable metadata fields within text or
-binary files as long as those fields can be easily viewed by the user.
-
-3) No Modified Version of the Font Software may use the Reserved Font
-Name(s) unless explicit written permission is granted by the corresponding
-Copyright Holder. This restriction only applies to the primary font name as
-presented to the users.
-
-4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
-Software shall not be used to promote, endorse or advertise any
-Modified Version, except to acknowledge the contribution(s) of the
-Copyright Holder(s) and the Author(s) or with their explicit written
-permission.
-
-5) The Font Software, modified or unmodified, in part or in whole,
-must be distributed entirely under this license, and must not be
-distributed under any other license. The requirement for fonts to
-remain under this license does not apply to any document created
-using the Font Software.
-
-TERMINATION
-This license becomes null and void if any of the above conditions are
-not met.
-
-DISCLAIMER
-THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
-OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
-DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
-OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -79,5 +79,11 @@
"cmd-1": "workspace::ToggleLeftDock",
"cmd-6": "diagnostics::Deploy"
}
+ },
+ {
+ "context": "ProjectPanel",
+ "bindings": {
+ "enter": "project_panel::Open"
+ }
}
]
@@ -3,6 +3,8 @@ name = "activity_indicator"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/activity_indicator.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "ai"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/ai.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -1,3 +1,4 @@
+use futures::future::BoxFuture;
use gpui::AppContext;
#[derive(Clone, Debug)]
@@ -9,7 +10,14 @@ pub enum ProviderCredential {
pub trait CredentialProvider: Send + Sync {
fn has_credentials(&self) -> bool;
- fn retrieve_credentials(&self, cx: &mut AppContext) -> ProviderCredential;
- fn save_credentials(&self, cx: &mut AppContext, credential: ProviderCredential);
- fn delete_credentials(&self, cx: &mut AppContext);
+ #[must_use]
+ fn retrieve_credentials(&self, cx: &mut AppContext) -> BoxFuture<ProviderCredential>;
+ #[must_use]
+ fn save_credentials(
+ &self,
+ cx: &mut AppContext,
+ credential: ProviderCredential,
+ ) -> BoxFuture<()>;
+ #[must_use]
+ fn delete_credentials(&self, cx: &mut AppContext) -> BoxFuture<()>;
}
@@ -201,8 +201,10 @@ pub struct OpenAICompletionProvider {
}
impl OpenAICompletionProvider {
- pub fn new(model_name: &str, executor: BackgroundExecutor) -> Self {
- let model = OpenAILanguageModel::load(model_name);
+ pub async fn new(model_name: String, executor: BackgroundExecutor) -> Self {
+ let model = executor
+ .spawn(async move { OpenAILanguageModel::load(&model_name) })
+ .await;
let credential = Arc::new(RwLock::new(ProviderCredential::NoCredentials));
Self {
model,
@@ -220,45 +222,70 @@ impl CredentialProvider for OpenAICompletionProvider {
}
}
- fn retrieve_credentials(&self, cx: &mut AppContext) -> ProviderCredential {
+ fn retrieve_credentials(&self, cx: &mut AppContext) -> BoxFuture<ProviderCredential> {
let existing_credential = self.credential.read().clone();
let retrieved_credential = match existing_credential {
- ProviderCredential::Credentials { .. } => existing_credential.clone(),
+ ProviderCredential::Credentials { .. } => {
+ return async move { existing_credential }.boxed()
+ }
_ => {
if let Some(api_key) = env::var("OPENAI_API_KEY").log_err() {
- ProviderCredential::Credentials { api_key }
- } else if let Some(Some((_, api_key))) =
- cx.read_credentials(OPENAI_API_URL).log_err()
- {
- if let Some(api_key) = String::from_utf8(api_key).log_err() {
- ProviderCredential::Credentials { api_key }
- } else {
- ProviderCredential::NoCredentials
- }
+ async move { ProviderCredential::Credentials { api_key } }.boxed()
} else {
- ProviderCredential::NoCredentials
+ let credentials = cx.read_credentials(OPENAI_API_URL);
+ async move {
+ if let Some(Some((_, api_key))) = credentials.await.log_err() {
+ if let Some(api_key) = String::from_utf8(api_key).log_err() {
+ ProviderCredential::Credentials { api_key }
+ } else {
+ ProviderCredential::NoCredentials
+ }
+ } else {
+ ProviderCredential::NoCredentials
+ }
+ }
+ .boxed()
}
}
};
- *self.credential.write() = retrieved_credential.clone();
- retrieved_credential
+
+ async move {
+ let retrieved_credential = retrieved_credential.await;
+ *self.credential.write() = retrieved_credential.clone();
+ retrieved_credential
+ }
+ .boxed()
}
- fn save_credentials(&self, cx: &mut AppContext, credential: ProviderCredential) {
+ fn save_credentials(
+ &self,
+ cx: &mut AppContext,
+ credential: ProviderCredential,
+ ) -> BoxFuture<()> {
*self.credential.write() = credential.clone();
let credential = credential.clone();
- match credential {
+ let write_credentials = match credential {
ProviderCredential::Credentials { api_key } => {
- cx.write_credentials(OPENAI_API_URL, "Bearer", api_key.as_bytes())
- .log_err();
+ Some(cx.write_credentials(OPENAI_API_URL, "Bearer", api_key.as_bytes()))
+ }
+ _ => None,
+ };
+
+ async move {
+ if let Some(write_credentials) = write_credentials {
+ write_credentials.await.log_err();
}
- _ => {}
}
+ .boxed()
}
- fn delete_credentials(&self, cx: &mut AppContext) {
- cx.delete_credentials(OPENAI_API_URL).log_err();
+ fn delete_credentials(&self, cx: &mut AppContext) -> BoxFuture<()> {
*self.credential.write() = ProviderCredential::NoCredentials;
+ let delete_credentials = cx.delete_credentials(OPENAI_API_URL);
+ async move {
+ delete_credentials.await.log_err();
+ }
+ .boxed()
}
}
@@ -1,6 +1,8 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
+use futures::future::BoxFuture;
use futures::AsyncReadExt;
+use futures::FutureExt;
use gpui::AppContext;
use gpui::BackgroundExecutor;
use isahc::http::StatusCode;
@@ -67,11 +69,14 @@ struct OpenAIEmbeddingUsage {
}
impl OpenAIEmbeddingProvider {
- pub fn new(client: Arc<dyn HttpClient>, executor: BackgroundExecutor) -> Self {
+ pub async fn new(client: Arc<dyn HttpClient>, executor: BackgroundExecutor) -> Self {
let (rate_limit_count_tx, rate_limit_count_rx) = watch::channel_with(None);
let rate_limit_count_tx = Arc::new(Mutex::new(rate_limit_count_tx));
- let model = OpenAILanguageModel::load("text-embedding-ada-002");
+ // Loading the model is expensive, so ensure this runs off the main thread.
+ let model = executor
+ .spawn(async move { OpenAILanguageModel::load("text-embedding-ada-002") })
+ .await;
let credential = Arc::new(RwLock::new(ProviderCredential::NoCredentials));
OpenAIEmbeddingProvider {
@@ -154,46 +159,71 @@ impl CredentialProvider for OpenAIEmbeddingProvider {
_ => false,
}
}
- fn retrieve_credentials(&self, cx: &mut AppContext) -> ProviderCredential {
- let existing_credential = self.credential.read().clone();
+ fn retrieve_credentials(&self, cx: &mut AppContext) -> BoxFuture<ProviderCredential> {
+ let existing_credential = self.credential.read().clone();
let retrieved_credential = match existing_credential {
- ProviderCredential::Credentials { .. } => existing_credential.clone(),
+ ProviderCredential::Credentials { .. } => {
+ return async move { existing_credential }.boxed()
+ }
_ => {
if let Some(api_key) = env::var("OPENAI_API_KEY").log_err() {
- ProviderCredential::Credentials { api_key }
- } else if let Some(Some((_, api_key))) =
- cx.read_credentials(OPENAI_API_URL).log_err()
- {
- if let Some(api_key) = String::from_utf8(api_key).log_err() {
- ProviderCredential::Credentials { api_key }
- } else {
- ProviderCredential::NoCredentials
- }
+ async move { ProviderCredential::Credentials { api_key } }.boxed()
} else {
- ProviderCredential::NoCredentials
+ let credentials = cx.read_credentials(OPENAI_API_URL);
+ async move {
+ if let Some(Some((_, api_key))) = credentials.await.log_err() {
+ if let Some(api_key) = String::from_utf8(api_key).log_err() {
+ ProviderCredential::Credentials { api_key }
+ } else {
+ ProviderCredential::NoCredentials
+ }
+ } else {
+ ProviderCredential::NoCredentials
+ }
+ }
+ .boxed()
}
}
};
- *self.credential.write() = retrieved_credential.clone();
- retrieved_credential
+ async move {
+ let retrieved_credential = retrieved_credential.await;
+ *self.credential.write() = retrieved_credential.clone();
+ retrieved_credential
+ }
+ .boxed()
}
- fn save_credentials(&self, cx: &mut AppContext, credential: ProviderCredential) {
+ fn save_credentials(
+ &self,
+ cx: &mut AppContext,
+ credential: ProviderCredential,
+ ) -> BoxFuture<()> {
*self.credential.write() = credential.clone();
- match credential {
+ let credential = credential.clone();
+ let write_credentials = match credential {
ProviderCredential::Credentials { api_key } => {
- cx.write_credentials(OPENAI_API_URL, "Bearer", api_key.as_bytes())
- .log_err();
+ Some(cx.write_credentials(OPENAI_API_URL, "Bearer", api_key.as_bytes()))
+ }
+ _ => None,
+ };
+
+ async move {
+ if let Some(write_credentials) = write_credentials {
+ write_credentials.await.log_err();
}
- _ => {}
}
+ .boxed()
}
- fn delete_credentials(&self, cx: &mut AppContext) {
- cx.delete_credentials(OPENAI_API_URL).log_err();
+ fn delete_credentials(&self, cx: &mut AppContext) -> BoxFuture<()> {
*self.credential.write() = ProviderCredential::NoCredentials;
+ let delete_credentials = cx.delete_credentials(OPENAI_API_URL);
+ async move {
+ delete_credentials.await.log_err();
+ }
+ .boxed()
}
}
@@ -104,11 +104,22 @@ impl CredentialProvider for FakeEmbeddingProvider {
fn has_credentials(&self) -> bool {
true
}
- fn retrieve_credentials(&self, _cx: &mut AppContext) -> ProviderCredential {
- ProviderCredential::NotNeeded
+
+ fn retrieve_credentials(&self, _cx: &mut AppContext) -> BoxFuture<ProviderCredential> {
+ async { ProviderCredential::NotNeeded }.boxed()
+ }
+
+ fn save_credentials(
+ &self,
+ _cx: &mut AppContext,
+ _credential: ProviderCredential,
+ ) -> BoxFuture<()> {
+ async {}.boxed()
+ }
+
+ fn delete_credentials(&self, _cx: &mut AppContext) -> BoxFuture<()> {
+ async {}.boxed()
}
- fn save_credentials(&self, _cx: &mut AppContext, _credential: ProviderCredential) {}
- fn delete_credentials(&self, _cx: &mut AppContext) {}
}
#[async_trait]
@@ -165,11 +176,22 @@ impl CredentialProvider for FakeCompletionProvider {
fn has_credentials(&self) -> bool {
true
}
- fn retrieve_credentials(&self, _cx: &mut AppContext) -> ProviderCredential {
- ProviderCredential::NotNeeded
+
+ fn retrieve_credentials(&self, _cx: &mut AppContext) -> BoxFuture<ProviderCredential> {
+ async { ProviderCredential::NotNeeded }.boxed()
+ }
+
+ fn save_credentials(
+ &self,
+ _cx: &mut AppContext,
+ _credential: ProviderCredential,
+ ) -> BoxFuture<()> {
+ async {}.boxed()
+ }
+
+ fn delete_credentials(&self, _cx: &mut AppContext) -> BoxFuture<()> {
+ async {}.boxed()
}
- fn save_credentials(&self, _cx: &mut AppContext, _credential: ProviderCredential) {}
- fn delete_credentials(&self, _cx: &mut AppContext) {}
}
impl CompletionProvider for FakeCompletionProvider {
@@ -3,6 +3,8 @@ name = "assets"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "assistant"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/assistant.rs"
@@ -30,7 +32,7 @@ workspace = { path = "../workspace" }
uuid.workspace = true
log.workspace = true
anyhow.workspace = true
-chrono = { version = "0.4", features = ["serde"] }
+chrono.workspace = true
futures.workspace = true
indoc.workspace = true
isahc.workspace = true
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -6,14 +6,12 @@ use crate::{
NewConversation, QuoteSelection, ResetKey, Role, SavedConversation, SavedConversationMetadata,
SavedMessage, Split, ToggleFocus, ToggleIncludeConversation, ToggleRetrieveContext,
};
-
+use ai::prompts::repository_context::PromptCodeSnippet;
use ai::{
auth::ProviderCredential,
completion::{CompletionProvider, CompletionRequest},
providers::open_ai::{OpenAICompletionProvider, OpenAIRequest, RequestMessage},
};
-
-use ai::prompts::repository_context::PromptCodeSnippet;
use anyhow::{anyhow, Result};
use chrono::{DateTime, Local};
use client::telemetry::AssistantKind;
@@ -31,9 +29,9 @@ use fs::Fs;
use futures::StreamExt;
use gpui::{
canvas, div, point, relative, rems, uniform_list, Action, AnyElement, AppContext,
- AsyncWindowContext, AvailableSpace, ClipboardItem, Context, EventEmitter, FocusHandle,
- FocusableView, FontStyle, FontWeight, HighlightStyle, InteractiveElement, IntoElement, Model,
- ModelContext, ParentElement, Pixels, PromptLevel, Render, SharedString,
+ AsyncAppContext, AsyncWindowContext, AvailableSpace, ClipboardItem, Context, EventEmitter,
+ FocusHandle, FocusableView, FontStyle, FontWeight, HighlightStyle, InteractiveElement,
+ IntoElement, Model, ModelContext, ParentElement, Pixels, PromptLevel, Render, SharedString,
StatefulInteractiveElement, Styled, Subscription, Task, TextStyle, UniformListScrollHandle,
View, ViewContext, VisualContext, WeakModel, WeakView, WhiteSpace, WindowContext,
};
@@ -123,6 +121,10 @@ impl AssistantPanel {
.await
.log_err()
.unwrap_or_default();
+ // Defaulting currently to GPT4, allow for this to be set via config.
+ let completion_provider =
+ OpenAICompletionProvider::new("gpt-4".into(), cx.background_executor().clone())
+ .await;
// TODO: deserialize state.
let workspace_handle = workspace.clone();
@@ -156,11 +158,6 @@ impl AssistantPanel {
});
let semantic_index = SemanticIndex::global(cx);
- // Defaulting currently to GPT4, allow for this to be set via config.
- let completion_provider = Arc::new(OpenAICompletionProvider::new(
- "gpt-4",
- cx.background_executor().clone(),
- ));
let focus_handle = cx.focus_handle();
cx.on_focus_in(&focus_handle, Self::focus_in).detach();
@@ -176,7 +173,7 @@ impl AssistantPanel {
zoomed: false,
focus_handle,
toolbar,
- completion_provider,
+ completion_provider: Arc::new(completion_provider),
api_key_editor: None,
languages: workspace.app_state().languages.clone(),
fs: workspace.app_state().fs.clone(),
@@ -221,23 +218,9 @@ impl AssistantPanel {
_: &InlineAssist,
cx: &mut ViewContext<Workspace>,
) {
- let this = if let Some(this) = workspace.panel::<AssistantPanel>(cx) {
- if this.update(cx, |assistant, cx| {
- if !assistant.has_credentials() {
- assistant.load_credentials(cx);
- };
-
- assistant.has_credentials()
- }) {
- this
- } else {
- workspace.focus_panel::<AssistantPanel>(cx);
- return;
- }
- } else {
+ let Some(assistant) = workspace.panel::<AssistantPanel>(cx) else {
return;
};
-
let active_editor = if let Some(active_editor) = workspace
.active_item(cx)
.and_then(|item| item.act_as::<Editor>(cx))
@@ -246,12 +229,32 @@ impl AssistantPanel {
} else {
return;
};
+ let project = workspace.project().clone();
- let project = workspace.project();
+ if assistant.update(cx, |assistant, _| assistant.has_credentials()) {
+ assistant.update(cx, |assistant, cx| {
+ assistant.new_inline_assist(&active_editor, cx, &project)
+ });
+ } else {
+ let assistant = assistant.downgrade();
+ cx.spawn(|workspace, mut cx| async move {
+ assistant
+ .update(&mut cx, |assistant, cx| assistant.load_credentials(cx))?
+ .await;
+ if assistant.update(&mut cx, |assistant, _| assistant.has_credentials())? {
+ assistant.update(&mut cx, |assistant, cx| {
+ assistant.new_inline_assist(&active_editor, cx, &project)
+ })?;
+ } else {
+ workspace.update(&mut cx, |workspace, cx| {
+ workspace.focus_panel::<AssistantPanel>(cx)
+ })?;
+ }
- this.update(cx, |assistant, cx| {
- assistant.new_inline_assist(&active_editor, cx, project)
- });
+ anyhow::Ok(())
+ })
+ .detach_and_log_err(cx)
+ }
}
fn new_inline_assist(
@@ -291,9 +294,6 @@ impl AssistantPanel {
let inline_assist_id = post_inc(&mut self.next_inline_assist_id);
let provider = self.completion_provider.clone();
- // Retrieve Credentials Authenticates the Provider
- provider.retrieve_credentials(cx);
-
let codegen = cx.new_model(|cx| {
Codegen::new(editor.read(cx).buffer().clone(), codegen_kind, provider, cx)
});
@@ -846,11 +846,18 @@ impl AssistantPanel {
api_key: api_key.clone(),
};
- self.completion_provider.save_credentials(cx, credential);
+ let completion_provider = self.completion_provider.clone();
+ cx.spawn(|this, mut cx| async move {
+ cx.update(|cx| completion_provider.save_credentials(cx, credential))?
+ .await;
- self.api_key_editor.take();
- self.focus_handle.focus(cx);
- cx.notify();
+ this.update(&mut cx, |this, cx| {
+ this.api_key_editor.take();
+ this.focus_handle.focus(cx);
+ cx.notify();
+ })
+ })
+ .detach_and_log_err(cx);
}
} else {
cx.propagate();
@@ -858,10 +865,17 @@ impl AssistantPanel {
}
fn reset_credentials(&mut self, _: &ResetKey, cx: &mut ViewContext<Self>) {
- self.completion_provider.delete_credentials(cx);
- self.api_key_editor = Some(build_api_key_editor(cx));
- self.focus_handle.focus(cx);
- cx.notify();
+ let completion_provider = self.completion_provider.clone();
+ cx.spawn(|this, mut cx| async move {
+ cx.update(|cx| completion_provider.delete_credentials(cx))?
+ .await;
+ this.update(&mut cx, |this, cx| {
+ this.api_key_editor = Some(build_api_key_editor(cx));
+ this.focus_handle.focus(cx);
+ cx.notify();
+ })
+ })
+ .detach_and_log_err(cx);
}
fn toggle_zoom(&mut self, _: &workspace::ToggleZoom, cx: &mut ViewContext<Self>) {
@@ -1079,9 +1093,9 @@ impl AssistantPanel {
cx.spawn(|this, mut cx| async move {
let saved_conversation = fs.load(&path).await?;
let saved_conversation = serde_json::from_str(&saved_conversation)?;
- let conversation = cx.new_model(|cx| {
- Conversation::deserialize(saved_conversation, path.clone(), languages, cx)
- })?;
+ let conversation =
+ Conversation::deserialize(saved_conversation, path.clone(), languages, &mut cx)
+ .await?;
this.update(&mut cx, |this, cx| {
// If, by the time we've loaded the conversation, the user has already opened
// the same conversation, we don't want to open it again.
@@ -1108,8 +1122,16 @@ impl AssistantPanel {
self.completion_provider.has_credentials()
}
- fn load_credentials(&mut self, cx: &mut ViewContext<Self>) {
- self.completion_provider.retrieve_credentials(cx);
+ fn load_credentials(&mut self, cx: &mut ViewContext<Self>) -> Task<()> {
+ let completion_provider = self.completion_provider.clone();
+ cx.spawn(|_, mut cx| async move {
+ if let Some(retrieve_credentials) = cx
+ .update(|cx| completion_provider.retrieve_credentials(cx))
+ .log_err()
+ {
+ retrieve_credentials.await;
+ }
+ })
}
}
@@ -1315,11 +1337,16 @@ impl Panel for AssistantPanel {
fn set_active(&mut self, active: bool, cx: &mut ViewContext<Self>) {
if active {
- self.load_credentials(cx);
-
- if self.editors.is_empty() {
- self.new_conversation(cx);
- }
+ let load_credentials = self.load_credentials(cx);
+ cx.spawn(|this, mut cx| async move {
+ load_credentials.await;
+ this.update(&mut cx, |this, cx| {
+ if this.editors.is_empty() {
+ this.new_conversation(cx);
+ }
+ })
+ })
+ .detach_and_log_err(cx);
}
}
@@ -1462,21 +1489,25 @@ impl Conversation {
}
}
- fn deserialize(
+ async fn deserialize(
saved_conversation: SavedConversation,
path: PathBuf,
language_registry: Arc<LanguageRegistry>,
- cx: &mut ModelContext<Self>,
- ) -> Self {
+ cx: &mut AsyncAppContext,
+ ) -> Result<Model<Self>> {
let id = match saved_conversation.id {
Some(id) => Some(id),
None => Some(Uuid::new_v4().to_string()),
};
let model = saved_conversation.model;
let completion_provider: Arc<dyn CompletionProvider> = Arc::new(
- OpenAICompletionProvider::new(model.full_name(), cx.background_executor().clone()),
+ OpenAICompletionProvider::new(
+ model.full_name().into(),
+ cx.background_executor().clone(),
+ )
+ .await,
);
- completion_provider.retrieve_credentials(cx);
+ cx.update(|cx| completion_provider.retrieve_credentials(cx))?;
let markdown = language_registry.language_for_name("Markdown");
let mut message_anchors = Vec::new();
let mut next_message_id = MessageId(0);
@@ -1499,32 +1530,34 @@ impl Conversation {
})
.detach_and_log_err(cx);
buffer
- });
-
- let mut this = Self {
- id,
- message_anchors,
- messages_metadata: saved_conversation.message_metadata,
- next_message_id,
- summary: Some(Summary {
- text: saved_conversation.summary,
- done: true,
- }),
- pending_summary: Task::ready(None),
- completion_count: Default::default(),
- pending_completions: Default::default(),
- token_count: None,
- max_token_count: tiktoken_rs::model::get_context_size(&model.full_name()),
- pending_token_count: Task::ready(None),
- model,
- _subscriptions: vec![cx.subscribe(&buffer, Self::handle_buffer_event)],
- pending_save: Task::ready(Ok(())),
- path: Some(path),
- buffer,
- completion_provider,
- };
- this.count_remaining_tokens(cx);
- this
+ })?;
+
+ cx.new_model(|cx| {
+ let mut this = Self {
+ id,
+ message_anchors,
+ messages_metadata: saved_conversation.message_metadata,
+ next_message_id,
+ summary: Some(Summary {
+ text: saved_conversation.summary,
+ done: true,
+ }),
+ pending_summary: Task::ready(None),
+ completion_count: Default::default(),
+ pending_completions: Default::default(),
+ token_count: None,
+ max_token_count: tiktoken_rs::model::get_context_size(&model.full_name()),
+ pending_token_count: Task::ready(None),
+ model,
+ _subscriptions: vec![cx.subscribe(&buffer, Self::handle_buffer_event)],
+ pending_save: Task::ready(Ok(())),
+ path: Some(path),
+ buffer,
+ completion_provider,
+ };
+ this.count_remaining_tokens(cx);
+ this
+ })
}
fn handle_buffer_event(
@@ -3169,7 +3202,7 @@ mod tests {
use super::*;
use crate::MessageId;
use ai::test::FakeCompletionProvider;
- use gpui::AppContext;
+ use gpui::{AppContext, TestAppContext};
use settings::SettingsStore;
#[gpui::test]
@@ -3487,16 +3520,17 @@ mod tests {
}
#[gpui::test]
- fn test_serialization(cx: &mut AppContext) {
- let settings_store = SettingsStore::test(cx);
+ async fn test_serialization(cx: &mut TestAppContext) {
+ let settings_store = cx.update(SettingsStore::test);
cx.set_global(settings_store);
- init(cx);
+ cx.update(init);
let registry = Arc::new(LanguageRegistry::test());
let completion_provider = Arc::new(FakeCompletionProvider::new());
let conversation =
cx.new_model(|cx| Conversation::new(registry.clone(), cx, completion_provider));
- let buffer = conversation.read(cx).buffer.clone();
- let message_0 = conversation.read(cx).message_anchors[0].id;
+ let buffer = conversation.read_with(cx, |conversation, _| conversation.buffer.clone());
+ let message_0 =
+ conversation.read_with(cx, |conversation, _| conversation.message_anchors[0].id);
let message_1 = conversation.update(cx, |conversation, cx| {
conversation
.insert_message_after(message_0, Role::Assistant, MessageStatus::Done, cx)
@@ -3517,9 +3551,9 @@ mod tests {
.unwrap()
});
buffer.update(cx, |buffer, cx| buffer.undo(cx));
- assert_eq!(buffer.read(cx).text(), "a\nb\nc\n");
+ assert_eq!(buffer.read_with(cx, |buffer, _| buffer.text()), "a\nb\nc\n");
assert_eq!(
- messages(&conversation, cx),
+ cx.read(|cx| messages(&conversation, cx)),
[
(message_0, Role::User, 0..2),
(message_1.id, Role::Assistant, 2..6),
@@ -3527,18 +3561,22 @@ mod tests {
]
);
- let deserialized_conversation = cx.new_model(|cx| {
- Conversation::deserialize(
- conversation.read(cx).serialize(cx),
- Default::default(),
- registry.clone(),
- cx,
- )
- });
- let deserialized_buffer = deserialized_conversation.read(cx).buffer.clone();
- assert_eq!(deserialized_buffer.read(cx).text(), "a\nb\nc\n");
+ let deserialized_conversation = Conversation::deserialize(
+ conversation.read_with(cx, |conversation, cx| conversation.serialize(cx)),
+ Default::default(),
+ registry.clone(),
+ &mut cx.to_async(),
+ )
+ .await
+ .unwrap();
+ let deserialized_buffer =
+ deserialized_conversation.read_with(cx, |conversation, _| conversation.buffer.clone());
+ assert_eq!(
+ deserialized_buffer.read_with(cx, |buffer, _| buffer.text()),
+ "a\nb\nc\n"
+ );
assert_eq!(
- messages(&deserialized_conversation, cx),
+ cx.read(|cx| messages(&deserialized_conversation, cx)),
[
(message_0, Role::User, 0..2),
(message_1.id, Role::Assistant, 2..6),
@@ -3,6 +3,8 @@ name = "audio"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/audio.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "auto_update"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/auto_update.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -1,7 +1,7 @@
mod update_notification;
use anyhow::{anyhow, Context, Result};
-use client::{Client, TelemetrySettings, ZED_APP_PATH, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN};
+use client::{Client, TelemetrySettings, ZED_APP_PATH, ZED_APP_VERSION};
use db::kvp::KEY_VALUE_STORE;
use db::RELEASE_CHANNEL;
use gpui::{
@@ -248,9 +248,7 @@ impl AutoUpdater {
)
})?;
- let mut url_string = format!(
- "{server_url}/api/releases/latest?token={ZED_SECRET_CLIENT_TOKEN}&asset=Zed.dmg"
- );
+ let mut url_string = format!("{server_url}/api/releases/latest?asset=Zed.dmg");
cx.update(|cx| {
if let Some(param) = cx
.try_global::<ReleaseChannel>()
@@ -3,6 +3,8 @@ name = "breadcrumbs"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/breadcrumbs.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "call"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/call.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "channel"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/channel.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "cli"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/cli.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "client"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/client.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -68,7 +68,6 @@ lazy_static! {
std::env::var("ZED_ALWAYS_ACTIVE").map_or(false, |e| e.len() > 0);
}
-pub const ZED_SECRET_CLIENT_TOKEN: &str = "618033988749894";
pub const INITIAL_RECONNECTION_DELAY: Duration = Duration::from_millis(100);
pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(5);
@@ -701,8 +700,8 @@ impl Client {
}
}
- pub fn has_keychain_credentials(&self, cx: &AsyncAppContext) -> bool {
- read_credentials_from_keychain(cx).is_some()
+ pub async fn has_keychain_credentials(&self, cx: &AsyncAppContext) -> bool {
+ read_credentials_from_keychain(cx).await.is_some()
}
#[async_recursion(?Send)]
@@ -733,7 +732,7 @@ impl Client {
let mut read_from_keychain = false;
let mut credentials = self.state.read().credentials.clone();
if credentials.is_none() && try_keychain {
- credentials = read_credentials_from_keychain(cx);
+ credentials = read_credentials_from_keychain(cx).await;
read_from_keychain = credentials.is_some();
}
if credentials.is_none() {
@@ -771,7 +770,7 @@ impl Client {
Ok(conn) => {
self.state.write().credentials = Some(credentials.clone());
if !read_from_keychain && IMPERSONATE_LOGIN.is_none() {
- write_credentials_to_keychain(credentials, cx).log_err();
+ write_credentials_to_keychain(credentials, cx).await.log_err();
}
futures::select_biased! {
@@ -785,7 +784,7 @@ impl Client {
Err(EstablishConnectionError::Unauthorized) => {
self.state.write().credentials.take();
if read_from_keychain {
- delete_credentials_from_keychain(cx).log_err();
+ delete_credentials_from_keychain(cx).await.log_err();
self.set_status(Status::SignedOut, cx);
self.authenticate_and_connect(false, cx).await
} else {
@@ -1351,14 +1350,16 @@ impl Client {
}
}
-fn read_credentials_from_keychain(cx: &AsyncAppContext) -> Option<Credentials> {
+async fn read_credentials_from_keychain(cx: &AsyncAppContext) -> Option<Credentials> {
if IMPERSONATE_LOGIN.is_some() {
return None;
}
let (user_id, access_token) = cx
- .update(|cx| cx.read_credentials(&ZED_SERVER_URL).log_err().flatten())
- .ok()??;
+ .update(|cx| cx.read_credentials(&ZED_SERVER_URL))
+ .log_err()?
+ .await
+ .log_err()??;
Some(Credentials {
user_id: user_id.parse().ok()?,
@@ -1366,7 +1367,10 @@ fn read_credentials_from_keychain(cx: &AsyncAppContext) -> Option<Credentials> {
})
}
-fn write_credentials_to_keychain(credentials: Credentials, cx: &AsyncAppContext) -> Result<()> {
+async fn write_credentials_to_keychain(
+ credentials: Credentials,
+ cx: &AsyncAppContext,
+) -> Result<()> {
cx.update(move |cx| {
cx.write_credentials(
&ZED_SERVER_URL,
@@ -1374,10 +1378,12 @@ fn write_credentials_to_keychain(credentials: Credentials, cx: &AsyncAppContext)
credentials.access_token.as_bytes(),
)
})?
+ .await
}
-fn delete_credentials_from_keychain(cx: &AsyncAppContext) -> Result<()> {
+async fn delete_credentials_from_keychain(cx: &AsyncAppContext) -> Result<()> {
cx.update(move |cx| cx.delete_credentials(&ZED_SERVER_URL))?
+ .await
}
const WORKTREE_URL_PREFIX: &str = "zed://worktrees/";
@@ -1,6 +1,6 @@
mod event_coalescer;
-use crate::{TelemetrySettings, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL};
+use crate::{TelemetrySettings, ZED_SERVER_URL};
use chrono::{DateTime, Utc};
use futures::Future;
use gpui::{AppContext, AppMetadata, BackgroundExecutor, Task};
@@ -51,7 +51,6 @@ lazy_static! {
#[derive(Serialize, Debug)]
struct EventRequestBody {
- token: &'static str,
installation_id: Option<Arc<str>>,
session_id: Option<Arc<str>>,
is_staff: Option<bool>,
@@ -527,7 +526,6 @@ impl Telemetry {
{
let state = this.state.lock();
let request_body = EventRequestBody {
- token: ZED_SECRET_CLIENT_TOKEN,
installation_id: state.installation_id.clone(),
session_id: state.session_id.clone(),
is_staff: state.is_staff.clone(),
@@ -146,7 +146,13 @@ impl UserStore {
}),
_maintain_current_user: cx.spawn(|this, mut cx| async move {
let mut status = client.status();
+ let weak = Arc::downgrade(&client);
+ drop(client);
while let Some(status) = status.next().await {
+ // if the client is dropped, the app is shutting down.
+ let Some(client) = weak.upgrade() else {
+ return Ok(());
+ };
match status {
Status::Connected { .. } => {
if let Some(user_id) = client.user_id() {
@@ -3,6 +3,8 @@ name = "clock"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/clock.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,8 +3,10 @@ authors = ["Nathan Sobo <nathan@zed.dev>"]
default-run = "collab"
edition = "2021"
name = "collab"
-version = "0.38.0"
+version = "0.40.1"
publish = false
+license = "AGPL-3.0-only"
+
[[bin]]
name = "collab"
@@ -27,6 +29,7 @@ axum = { version = "0.5", features = ["json", "headers", "ws"] }
axum-extra = { version = "0.3", features = ["erased-json"] }
base64 = "0.13"
clap = { version = "3.1", features = ["derive"], optional = true }
+chrono.workspace = true
dashmap = "5.4"
envy = "0.4.2"
futures.workspace = true
@@ -0,0 +1 @@
+../../LICENSE-AGPL
@@ -7,7 +7,7 @@ CREATE TABLE "users" (
"invite_count" INTEGER NOT NULL DEFAULT 0,
"inviter_id" INTEGER REFERENCES users (id),
"connected_once" BOOLEAN NOT NULL DEFAULT false,
- "created_at" TIMESTAMP NOT NULL DEFAULT now,
+ "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"metrics_id" TEXT,
"github_user_id" INTEGER
);
@@ -196,7 +196,8 @@ CREATE TABLE "channels" (
"name" VARCHAR NOT NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"visibility" VARCHAR NOT NULL,
- "parent_path" TEXT
+ "parent_path" TEXT,
+ "requires_zed_cla" BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE INDEX "index_channels_on_parent_path" ON "channels" ("parent_path");
@@ -344,3 +345,9 @@ CREATE INDEX
"index_notifications_on_recipient_id_is_read_kind_entity_id"
ON "notifications"
("recipient_id", "is_read", "kind", "entity_id");
+
+CREATE TABLE contributors (
+ user_id INTEGER REFERENCES users(id),
+ signed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (user_id)
+);
@@ -0,0 +1,5 @@
+CREATE TABLE contributors (
+ user_id INTEGER REFERENCES users(id),
+ signed_at TIMESTAMP NOT NULL DEFAULT NOW(),
+ PRIMARY KEY (user_id)
+);
@@ -0,0 +1 @@
+ALTER TABLE "channels" ADD COLUMN "requires_zed_cla" BOOLEAN NOT NULL DEFAULT FALSE;
@@ -1,6 +1,6 @@
use crate::{
auth,
- db::{User, UserId},
+ db::{ContributorSelector, User, UserId},
rpc, AppState, Error, Result,
};
use anyhow::anyhow;
@@ -14,6 +14,7 @@ use axum::{
Extension, Json, Router,
};
use axum_extra::response::ErasedJson;
+use chrono::SecondsFormat;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tower::ServiceBuilder;
@@ -25,6 +26,8 @@ pub fn routes(rpc_server: Arc<rpc::Server>, state: Arc<AppState>) -> Router<Body
.route("/users/:id/access_tokens", post(create_access_token))
.route("/panic", post(trace_panic))
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
+ .route("/contributors", get(get_contributors).post(add_contributor))
+ .route("/contributor", get(check_is_contributor))
.layer(
ServiceBuilder::new()
.layer(Extension(state))
@@ -88,8 +91,7 @@ async fn get_authenticated_user(
params.github_user_id,
params.github_email.as_deref(),
)
- .await?
- .ok_or_else(|| Error::Http(StatusCode::NOT_FOUND, "user not found".into()))?;
+ .await?;
let metrics_id = app.db.get_user_metrics_id(user.id).await?;
return Ok(Json(AuthenticatedUserResponse { user, metrics_id }));
}
@@ -133,6 +135,65 @@ async fn get_rpc_server_snapshot(
Ok(ErasedJson::pretty(rpc_server.snapshot().await))
}
+async fn get_contributors(Extension(app): Extension<Arc<AppState>>) -> Result<Json<Vec<String>>> {
+ Ok(Json(app.db.get_contributors().await?))
+}
+
+#[derive(Debug, Deserialize)]
+struct CheckIsContributorParams {
+ github_user_id: Option<i32>,
+ github_login: Option<String>,
+}
+
+impl CheckIsContributorParams {
+ fn as_contributor_selector(self) -> Result<ContributorSelector> {
+ if let Some(github_user_id) = self.github_user_id {
+ return Ok(ContributorSelector::GitHubUserId { github_user_id });
+ }
+
+ if let Some(github_login) = self.github_login {
+ return Ok(ContributorSelector::GitHubLogin { github_login });
+ }
+
+ Err(anyhow!(
+ "must be one of `github_user_id` or `github_login`."
+ ))?
+ }
+}
+
+#[derive(Debug, Serialize)]
+struct CheckIsContributorResponse {
+ signed_at: Option<String>,
+}
+
+async fn check_is_contributor(
+ Extension(app): Extension<Arc<AppState>>,
+ Query(params): Query<CheckIsContributorParams>,
+) -> Result<Json<CheckIsContributorResponse>> {
+ let params = params.as_contributor_selector()?;
+ Ok(Json(CheckIsContributorResponse {
+ signed_at: app
+ .db
+ .get_contributor_sign_timestamp(¶ms)
+ .await?
+ .map(|ts| ts.and_utc().to_rfc3339_opts(SecondsFormat::Millis, true)),
+ }))
+}
+
+async fn add_contributor(
+ Json(params): Json<AuthenticatedUserParams>,
+ Extension(app): Extension<Arc<AppState>>,
+) -> Result<()> {
+ Ok(app
+ .db
+ .add_contributor(
+ ¶ms.github_login,
+ params.github_user_id,
+ params.github_email.as_deref(),
+ )
+ .await?)
+}
+
#[derive(Deserialize)]
struct CreateAccessTokenQueryParams {
public_key: String,
@@ -44,6 +44,7 @@ use tables::*;
use tokio::sync::{Mutex, OwnedMutexGuard};
pub use ids::*;
+pub use queries::contributors::ContributorSelector;
pub use sea_orm::ConnectOptions;
pub use tables::user::Model as User;
@@ -173,6 +173,14 @@ impl ChannelRole {
Banned => false,
}
}
+
+ pub fn requires_cla(&self) -> bool {
+ use ChannelRole::*;
+ match self {
+ Admin | Member => true,
+ Banned | Guest => false,
+ }
+ }
}
impl From<proto::ChannelRole> for ChannelRole {
@@ -4,6 +4,7 @@ pub mod access_tokens;
pub mod buffers;
pub mod channels;
pub mod contacts;
+pub mod contributors;
pub mod messages;
pub mod notifications;
pub mod projects;
@@ -67,6 +67,7 @@ impl Database {
.as_ref()
.map_or(String::new(), |parent| parent.path()),
),
+ requires_zed_cla: ActiveValue::NotSet,
}
.insert(&*tx)
.await?;
@@ -261,6 +262,22 @@ impl Database {
.await
}
+ #[cfg(test)]
+ pub async fn set_channel_requires_zed_cla(
+ &self,
+ channel_id: ChannelId,
+ requires_zed_cla: bool,
+ ) -> Result<()> {
+ self.transaction(move |tx| async move {
+ let channel = self.get_channel_internal(channel_id, &*tx).await?;
+ let mut model = channel.into_active_model();
+ model.requires_zed_cla = ActiveValue::Set(requires_zed_cla);
+ model.update(&*tx).await?;
+ Ok(())
+ })
+ .await
+ }
+
/// Deletes the channel with the specified ID.
pub async fn delete_channel(
&self,
@@ -0,0 +1,94 @@
+use super::*;
+
+#[derive(Debug)]
+pub enum ContributorSelector {
+ GitHubUserId { github_user_id: i32 },
+ GitHubLogin { github_login: String },
+}
+
+impl Database {
+ /// Retrieves the GitHub logins of all users who have signed the CLA.
+ pub async fn get_contributors(&self) -> Result<Vec<String>> {
+ self.transaction(|tx| async move {
+ #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
+ enum QueryGithubLogin {
+ GithubLogin,
+ }
+
+ Ok(contributor::Entity::find()
+ .inner_join(user::Entity)
+ .order_by_asc(contributor::Column::SignedAt)
+ .select_only()
+ .column(user::Column::GithubLogin)
+ .into_values::<_, QueryGithubLogin>()
+ .all(&*tx)
+ .await?)
+ })
+ .await
+ }
+
+ /// Records that a given user has signed the CLA.
+ pub async fn get_contributor_sign_timestamp(
+ &self,
+ selector: &ContributorSelector,
+ ) -> Result<Option<DateTime>> {
+ self.transaction(|tx| async move {
+ let condition = match selector {
+ ContributorSelector::GitHubUserId { github_user_id } => {
+ user::Column::GithubUserId.eq(*github_user_id)
+ }
+ ContributorSelector::GitHubLogin { github_login } => {
+ user::Column::GithubLogin.eq(github_login)
+ }
+ };
+
+ if let Some(user) = user::Entity::find().filter(condition).one(&*tx).await? {
+ if user.admin {
+ return Ok(Some(user.created_at));
+ }
+
+ if let Some(contributor) =
+ contributor::Entity::find_by_id(user.id).one(&*tx).await?
+ {
+ return Ok(Some(contributor.signed_at));
+ }
+ }
+
+ Ok(None)
+ })
+ .await
+ }
+
+ /// Records that a given user has signed the CLA.
+ pub async fn add_contributor(
+ &self,
+ github_login: &str,
+ github_user_id: Option<i32>,
+ github_email: Option<&str>,
+ ) -> Result<()> {
+ self.transaction(|tx| async move {
+ let user = self
+ .get_or_create_user_by_github_account_tx(
+ github_login,
+ github_user_id,
+ github_email,
+ &*tx,
+ )
+ .await?;
+
+ contributor::Entity::insert(contributor::ActiveModel {
+ user_id: ActiveValue::Set(user.id),
+ signed_at: ActiveValue::NotSet,
+ })
+ .on_conflict(
+ OnConflict::column(contributor::Column::UserId)
+ .do_nothing()
+ .to_owned(),
+ )
+ .exec_without_returning(&*tx)
+ .await?;
+ Ok(())
+ })
+ .await
+ }
+}
@@ -1029,6 +1029,11 @@ impl Database {
.await?
.ok_or_else(|| anyhow!("only admins can set participant role"))?;
+ if role.requires_cla() {
+ self.check_user_has_signed_cla(user_id, room_id, &*tx)
+ .await?;
+ }
+
let result = room_participant::Entity::update_many()
.filter(
Condition::all()
@@ -1050,6 +1055,45 @@ impl Database {
.await
}
+ async fn check_user_has_signed_cla(
+ &self,
+ user_id: UserId,
+ room_id: RoomId,
+ tx: &DatabaseTransaction,
+ ) -> Result<()> {
+ let channel = room::Entity::find_by_id(room_id)
+ .one(&*tx)
+ .await?
+ .ok_or_else(|| anyhow!("could not find room"))?
+ .find_related(channel::Entity)
+ .one(&*tx)
+ .await?;
+
+ if let Some(channel) = channel {
+ let requires_zed_cla = channel.requires_zed_cla
+ || channel::Entity::find()
+ .filter(
+ channel::Column::Id
+ .is_in(channel.ancestors())
+ .and(channel::Column::RequiresZedCla.eq(true)),
+ )
+ .count(&*tx)
+ .await?
+ > 0;
+ if requires_zed_cla {
+ if contributor::Entity::find()
+ .filter(contributor::Column::UserId.eq(user_id))
+ .one(&*tx)
+ .await?
+ .is_none()
+ {
+ Err(anyhow!("user has not signed the Zed CLA"))?;
+ }
+ }
+ }
+ Ok(())
+ }
+
pub async fn connection_lost(&self, connection: ConnectionId) -> Result<()> {
self.transaction(|tx| async move {
self.room_connection_lost(connection, &*tx).await?;
@@ -74,51 +74,68 @@ impl Database {
github_login: &str,
github_user_id: Option<i32>,
github_email: Option<&str>,
- ) -> Result<Option<User>> {
+ ) -> Result<User> {
self.transaction(|tx| async move {
- let tx = &*tx;
- if let Some(github_user_id) = github_user_id {
- if let Some(user_by_github_user_id) = user::Entity::find()
- .filter(user::Column::GithubUserId.eq(github_user_id))
- .one(tx)
- .await?
- {
- let mut user_by_github_user_id = user_by_github_user_id.into_active_model();
- user_by_github_user_id.github_login = ActiveValue::set(github_login.into());
- Ok(Some(user_by_github_user_id.update(tx).await?))
- } else if let Some(user_by_github_login) = user::Entity::find()
- .filter(user::Column::GithubLogin.eq(github_login))
- .one(tx)
- .await?
- {
- let mut user_by_github_login = user_by_github_login.into_active_model();
- user_by_github_login.github_user_id = ActiveValue::set(Some(github_user_id));
- Ok(Some(user_by_github_login.update(tx).await?))
- } else {
- let user = user::Entity::insert(user::ActiveModel {
- email_address: ActiveValue::set(github_email.map(|email| email.into())),
- github_login: ActiveValue::set(github_login.into()),
- github_user_id: ActiveValue::set(Some(github_user_id)),
- admin: ActiveValue::set(false),
- invite_count: ActiveValue::set(0),
- invite_code: ActiveValue::set(None),
- metrics_id: ActiveValue::set(Uuid::new_v4()),
- ..Default::default()
- })
- .exec_with_returning(&*tx)
- .await?;
- Ok(Some(user))
- }
- } else {
- Ok(user::Entity::find()
- .filter(user::Column::GithubLogin.eq(github_login))
- .one(tx)
- .await?)
- }
+ self.get_or_create_user_by_github_account_tx(
+ github_login,
+ github_user_id,
+ github_email,
+ &*tx,
+ )
+ .await
})
.await
}
+ pub async fn get_or_create_user_by_github_account_tx(
+ &self,
+ github_login: &str,
+ github_user_id: Option<i32>,
+ github_email: Option<&str>,
+ tx: &DatabaseTransaction,
+ ) -> Result<User> {
+ if let Some(github_user_id) = github_user_id {
+ if let Some(user_by_github_user_id) = user::Entity::find()
+ .filter(user::Column::GithubUserId.eq(github_user_id))
+ .one(tx)
+ .await?
+ {
+ let mut user_by_github_user_id = user_by_github_user_id.into_active_model();
+ user_by_github_user_id.github_login = ActiveValue::set(github_login.into());
+ Ok(user_by_github_user_id.update(tx).await?)
+ } else if let Some(user_by_github_login) = user::Entity::find()
+ .filter(user::Column::GithubLogin.eq(github_login))
+ .one(tx)
+ .await?
+ {
+ let mut user_by_github_login = user_by_github_login.into_active_model();
+ user_by_github_login.github_user_id = ActiveValue::set(Some(github_user_id));
+ Ok(user_by_github_login.update(tx).await?)
+ } else {
+ let user = user::Entity::insert(user::ActiveModel {
+ email_address: ActiveValue::set(github_email.map(|email| email.into())),
+ github_login: ActiveValue::set(github_login.into()),
+ github_user_id: ActiveValue::set(Some(github_user_id)),
+ admin: ActiveValue::set(false),
+ invite_count: ActiveValue::set(0),
+ invite_code: ActiveValue::set(None),
+ metrics_id: ActiveValue::set(Uuid::new_v4()),
+ ..Default::default()
+ })
+ .exec_with_returning(&*tx)
+ .await?;
+ Ok(user)
+ }
+ } else {
+ let user = user::Entity::find()
+ .filter(user::Column::GithubLogin.eq(github_login))
+ .one(tx)
+ .await?
+ .ok_or_else(|| anyhow!("no such user {}", github_login))?;
+ Ok(user)
+ }
+ }
+
/// get_all_users returns the next page of users. To get more call again with
/// the same limit and the page incremented by 1.
pub async fn get_all_users(&self, page: u32, limit: u32) -> Result<Vec<User>> {
@@ -9,6 +9,7 @@ pub mod channel_member;
pub mod channel_message;
pub mod channel_message_mention;
pub mod contact;
+pub mod contributor;
pub mod feature_flag;
pub mod follower;
pub mod language_server;
@@ -9,6 +9,7 @@ pub struct Model {
pub name: String,
pub visibility: ChannelVisibility,
pub parent_path: String,
+ pub requires_zed_cla: bool,
}
impl Model {
@@ -0,0 +1,30 @@
+use crate::db::UserId;
+use sea_orm::entity::prelude::*;
+use serde::Serialize;
+
+/// A user who has signed the CLA.
+#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel, Serialize)]
+#[sea_orm(table_name = "contributors")]
+pub struct Model {
+ #[sea_orm(primary_key)]
+ pub user_id: UserId,
+ pub signed_at: DateTime,
+}
+
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+pub enum Relation {
+ #[sea_orm(
+ belongs_to = "super::user::Entity",
+ from = "Column::UserId",
+ to = "super::user::Column::Id"
+ )]
+ User,
+}
+
+impl ActiveModelBehavior for ActiveModel {}
+
+impl Related<super::user::Entity> for Entity {
+ fn to() -> RelationDef {
+ Relation::User.def()
+ }
+}
@@ -17,6 +17,7 @@ pub struct Model {
pub inviter_id: Option<UserId>,
pub connected_once: bool,
pub metrics_id: Uuid,
+ pub created_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
@@ -31,6 +32,8 @@ pub enum Relation {
ChannelMemberships,
#[sea_orm(has_many = "super::user_feature::Entity")]
UserFeatures,
+ #[sea_orm(has_one = "super::contributor::Entity")]
+ Contributor,
}
impl Related<super::access_token::Entity> for Entity {
@@ -1,5 +1,6 @@
mod buffer_tests;
mod channel_tests;
+mod contributor_tests;
mod db_tests;
mod feature_flag_tests;
mod message_tests;
@@ -0,0 +1,37 @@
+use super::Database;
+use crate::{db::NewUserParams, test_both_dbs};
+use std::sync::Arc;
+
+test_both_dbs!(
+ test_contributors,
+ test_contributors_postgres,
+ test_contributors_sqlite
+);
+
+async fn test_contributors(db: &Arc<Database>) {
+ db.create_user(
+ &format!("user1@example.com"),
+ false,
+ NewUserParams {
+ github_login: format!("user1"),
+ github_user_id: 1,
+ },
+ )
+ .await
+ .unwrap()
+ .user_id;
+
+ assert_eq!(db.get_contributors().await.unwrap(), Vec::<String>::new());
+
+ db.add_contributor("user1", Some(1), None).await.unwrap();
+ assert_eq!(
+ db.get_contributors().await.unwrap(),
+ vec!["user1".to_string()]
+ );
+
+ db.add_contributor("user2", Some(2), None).await.unwrap();
+ assert_eq!(
+ db.get_contributors().await.unwrap(),
+ vec!["user1".to_string(), "user2".to_string()]
+ );
+}
@@ -31,44 +31,42 @@ async fn test_get_users(db: &Arc<Database>) {
}
assert_eq!(
- db.get_users_by_ids(user_ids.clone()).await.unwrap(),
+ db.get_users_by_ids(user_ids.clone())
+ .await
+ .unwrap()
+ .into_iter()
+ .map(|user| (
+ user.id,
+ user.github_login,
+ user.github_user_id,
+ user.email_address
+ ))
+ .collect::<Vec<_>>(),
vec![
- User {
- id: user_ids[0],
- github_login: "user1".to_string(),
- github_user_id: Some(1),
- email_address: Some("user1@example.com".to_string()),
- admin: false,
- metrics_id: user_metric_ids[0].parse().unwrap(),
- ..Default::default()
- },
- User {
- id: user_ids[1],
- github_login: "user2".to_string(),
- github_user_id: Some(2),
- email_address: Some("user2@example.com".to_string()),
- admin: false,
- metrics_id: user_metric_ids[1].parse().unwrap(),
- ..Default::default()
- },
- User {
- id: user_ids[2],
- github_login: "user3".to_string(),
- github_user_id: Some(3),
- email_address: Some("user3@example.com".to_string()),
- admin: false,
- metrics_id: user_metric_ids[2].parse().unwrap(),
- ..Default::default()
- },
- User {
- id: user_ids[3],
- github_login: "user4".to_string(),
- github_user_id: Some(4),
- email_address: Some("user4@example.com".to_string()),
- admin: false,
- metrics_id: user_metric_ids[3].parse().unwrap(),
- ..Default::default()
- }
+ (
+ user_ids[0],
+ "user1".to_string(),
+ Some(1),
+ Some("user1@example.com".to_string()),
+ ),
+ (
+ user_ids[1],
+ "user2".to_string(),
+ Some(2),
+ Some("user2@example.com".to_string()),
+ ),
+ (
+ user_ids[2],
+ "user3".to_string(),
+ Some(3),
+ Some("user3@example.com".to_string()),
+ ),
+ (
+ user_ids[3],
+ "user4".to_string(),
+ Some(4),
+ Some("user4@example.com".to_string()),
+ )
]
);
}
@@ -80,18 +78,17 @@ test_both_dbs!(
);
async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
- let user_id1 = db
- .create_user(
- "user1@example.com",
- false,
- NewUserParams {
- github_login: "login1".into(),
- github_user_id: 101,
- },
- )
- .await
- .unwrap()
- .user_id;
+ db.create_user(
+ "user1@example.com",
+ false,
+ NewUserParams {
+ github_login: "login1".into(),
+ github_user_id: 101,
+ },
+ )
+ .await
+ .unwrap()
+ .user_id;
let user_id2 = db
.create_user(
"user2@example.com",
@@ -105,25 +102,9 @@ async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
.unwrap()
.user_id;
- let user = db
- .get_or_create_user_by_github_account("login1", None, None)
- .await
- .unwrap()
- .unwrap();
- assert_eq!(user.id, user_id1);
- assert_eq!(&user.github_login, "login1");
- assert_eq!(user.github_user_id, Some(101));
-
- assert!(db
- .get_or_create_user_by_github_account("non-existent-login", None, None)
- .await
- .unwrap()
- .is_none());
-
let user = db
.get_or_create_user_by_github_account("the-new-login2", Some(102), None)
.await
- .unwrap()
.unwrap();
assert_eq!(user.id, user_id2);
assert_eq!(&user.github_login, "the-new-login2");
@@ -132,7 +113,6 @@ async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
let user = db
.get_or_create_user_by_github_account("login3", Some(103), Some("user3@example.com"))
.await
- .unwrap()
.unwrap();
assert_eq!(&user.github_login, "login3");
assert_eq!(user.github_user_id, Some(103));
@@ -1,4 +1,4 @@
-use crate::tests::TestServer;
+use crate::{db::ChannelId, tests::TestServer};
use call::ActiveCall;
use editor::Editor;
use gpui::{BackgroundExecutor, TestAppContext};
@@ -159,3 +159,103 @@ async fn test_channel_guest_promotion(cx_a: &mut TestAppContext, cx_b: &mut Test
.await
.is_err());
}
+
+#[gpui::test]
+async fn test_channel_requires_zed_cla(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
+ let mut server = TestServer::start(cx_a.executor()).await;
+
+ server
+ .app_state
+ .db
+ .get_or_create_user_by_github_account("user_b", Some(100), None)
+ .await
+ .unwrap();
+
+ let client_a = server.create_client(cx_a, "user_a").await;
+ let client_b = server.create_client(cx_b, "user_b").await;
+ let active_call_a = cx_a.read(ActiveCall::global);
+ let active_call_b = cx_b.read(ActiveCall::global);
+
+ // Create a parent channel that requires the Zed CLA
+ let parent_channel_id = server
+ .make_channel("the-channel", None, (&client_a, cx_a), &mut [])
+ .await;
+ server
+ .app_state
+ .db
+ .set_channel_requires_zed_cla(ChannelId::from_proto(parent_channel_id), true)
+ .await
+ .unwrap();
+
+ // Create a public channel that is a child of the parent channel.
+ let channel_id = client_a
+ .channel_store()
+ .update(cx_a, |store, cx| {
+ store.create_channel("the-sub-channel", Some(parent_channel_id), cx)
+ })
+ .await
+ .unwrap();
+ client_a
+ .channel_store()
+ .update(cx_a, |store, cx| {
+ store.set_channel_visibility(channel_id, proto::ChannelVisibility::Public, cx)
+ })
+ .await
+ .unwrap();
+
+ // Users A and B join the channel. B is a guest.
+ active_call_a
+ .update(cx_a, |call, cx| call.join_channel(channel_id, cx))
+ .await
+ .unwrap();
+ active_call_b
+ .update(cx_b, |call, cx| call.join_channel(channel_id, cx))
+ .await
+ .unwrap();
+ cx_a.run_until_parked();
+ let room_b = cx_b
+ .read(ActiveCall::global)
+ .update(cx_b, |call, _| call.room().unwrap().clone());
+ assert!(room_b.read_with(cx_b, |room, _| room.read_only()));
+
+ // A tries to grant write access to B, but cannot because B has not
+ // yet signed the zed CLA.
+ active_call_a
+ .update(cx_a, |call, cx| {
+ call.room().unwrap().update(cx, |room, cx| {
+ room.set_participant_role(
+ client_b.user_id().unwrap(),
+ proto::ChannelRole::Member,
+ cx,
+ )
+ })
+ })
+ .await
+ .unwrap_err();
+ cx_a.run_until_parked();
+ assert!(room_b.read_with(cx_b, |room, _| room.read_only()));
+
+ // User B signs the zed CLA.
+ server
+ .app_state
+ .db
+ .add_contributor("user_b", Some(100), None)
+ .await
+ .unwrap();
+
+ // A can now grant write access to B.
+ active_call_a
+ .update(cx_a, |call, cx| {
+ call.room().unwrap().update(cx, |room, cx| {
+ room.set_participant_role(
+ client_b.user_id().unwrap(),
+ proto::ChannelRole::Member,
+ cx,
+ )
+ })
+ })
+ .await
+ .unwrap();
+ cx_a.run_until_parked();
+ assert!(room_b.read_with(cx_b, |room, _| !room.read_only()));
+}
@@ -43,6 +43,7 @@ pub struct TestServer {
pub app_state: Arc<AppState>,
pub test_live_kit_server: Arc<live_kit_client::TestServer>,
server: Arc<Server>,
+ next_github_user_id: i32,
connection_killers: Arc<Mutex<HashMap<PeerId, Arc<AtomicBool>>>>,
forbid_connections: Arc<AtomicBool>,
_test_db: TestDb,
@@ -108,6 +109,7 @@ impl TestServer {
server,
connection_killers: Default::default(),
forbid_connections: Default::default(),
+ next_github_user_id: 0,
_test_db: test_db,
test_live_kit_server: live_kit_server,
}
@@ -157,6 +159,8 @@ impl TestServer {
{
user.id
} else {
+ let github_user_id = self.next_github_user_id;
+ self.next_github_user_id += 1;
self.app_state
.db
.create_user(
@@ -164,7 +168,7 @@ impl TestServer {
false,
NewUserParams {
github_login: name.into(),
- github_user_id: 0,
+ github_user_id,
},
)
.await
@@ -742,9 +746,9 @@ impl TestClient {
let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
let view = window.root_view(cx).unwrap();
- let cx = Box::new(VisualTestContext::from_window(*window.deref(), cx));
+ let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
// it might be nice to try and cleanup these at the end of each test.
- (view, Box::leak(cx))
+ (view, cx)
}
}
@@ -3,6 +3,8 @@ name = "collab_ui"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/collab_ui.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -10,10 +10,11 @@ use gpui::{
WeakView,
};
use picker::{Picker, PickerDelegate};
+use rpc::proto::channel_member;
use std::sync::Arc;
use ui::{prelude::*, Avatar, Checkbox, ContextMenu, ListItem, ListItemSpacing};
use util::TryFutureExt;
-use workspace::ModalView;
+use workspace::{notifications::NotifyTaskExt, ModalView};
actions!(
channel_modal,
@@ -347,15 +348,13 @@ impl PickerDelegate for ChannelModalDelegate {
}
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) {
- if let Some((selected_user, role)) = self.user_at_index(self.selected_index) {
+ if let Some(selected_user) = self.user_at_index(self.selected_index) {
if Some(selected_user.id) == self.user_store.read(cx).current_user().map(|user| user.id)
{
return;
}
match self.mode {
- Mode::ManageMembers => {
- self.show_context_menu(selected_user, role.unwrap_or(ChannelRole::Member), cx)
- }
+ Mode::ManageMembers => self.show_context_menu(self.selected_index, cx),
Mode::InviteMembers => match self.member_status(selected_user.id, cx) {
Some(proto::channel_member::Kind::Invitee) => {
self.remove_member(selected_user.id, cx);
@@ -385,7 +384,8 @@ impl PickerDelegate for ChannelModalDelegate {
selected: bool,
cx: &mut ViewContext<Picker<Self>>,
) -> Option<Self::ListItem> {
- let (user, role) = self.user_at_index(ix)?;
+ let user = self.user_at_index(ix)?;
+ let membership = self.member_at_index(ix);
let request_status = self.member_status(user.id, cx);
let is_me = self.user_store.read(cx).current_user().map(|user| user.id) == Some(user.id);
@@ -402,11 +402,15 @@ impl PickerDelegate for ChannelModalDelegate {
.children(
if request_status == Some(proto::channel_member::Kind::Invitee) {
Some(Label::new("Invited"))
+ } else if membership.map(|m| m.kind)
+ == Some(channel_member::Kind::AncestorMember)
+ {
+ Some(Label::new("Parent"))
} else {
None
},
)
- .children(match role {
+ .children(match membership.map(|m| m.role) {
Some(ChannelRole::Admin) => Some(Label::new("Admin")),
Some(ChannelRole::Guest) => Some(Label::new("Guest")),
_ => None,
@@ -419,7 +423,7 @@ impl PickerDelegate for ChannelModalDelegate {
if let (Some((menu, _)), true) = (&self.context_menu, selected) {
Some(
overlay()
- .anchor(gpui::AnchorCorner::TopLeft)
+ .anchor(gpui::AnchorCorner::TopRight)
.child(menu.clone()),
)
} else {
@@ -458,16 +462,19 @@ impl ChannelModalDelegate {
})
}
- fn user_at_index(&self, ix: usize) -> Option<(Arc<User>, Option<ChannelRole>)> {
+ fn member_at_index(&self, ix: usize) -> Option<&ChannelMembership> {
+ self.matching_member_indices
+ .get(ix)
+ .and_then(|ix| self.members.get(*ix))
+ }
+
+ fn user_at_index(&self, ix: usize) -> Option<Arc<User>> {
match self.mode {
Mode::ManageMembers => self.matching_member_indices.get(ix).and_then(|ix| {
let channel_membership = self.members.get(*ix)?;
- Some((
- channel_membership.user.clone(),
- Some(channel_membership.role),
- ))
+ Some(channel_membership.user.clone())
}),
- Mode::InviteMembers => Some((self.matching_users.get(ix).cloned()?, None)),
+ Mode::InviteMembers => self.matching_users.get(ix).cloned(),
}
}
@@ -491,7 +498,7 @@ impl ChannelModalDelegate {
cx.notify();
})
})
- .detach_and_log_err(cx);
+ .detach_and_notify_err(cx);
Some(())
}
@@ -523,7 +530,7 @@ impl ChannelModalDelegate {
cx.notify();
})
})
- .detach_and_log_err(cx);
+ .detach_and_notify_err(cx);
Some(())
}
@@ -549,19 +556,66 @@ impl ChannelModalDelegate {
cx.notify();
})
})
- .detach_and_log_err(cx);
+ .detach_and_notify_err(cx);
}
- fn show_context_menu(
- &mut self,
- user: Arc<User>,
- role: ChannelRole,
- cx: &mut ViewContext<Picker<Self>>,
- ) {
- let user_id = user.id;
+ fn show_context_menu(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>) {
+ let Some(membership) = self.member_at_index(ix) else {
+ return;
+ };
+ if membership.kind == proto::channel_member::Kind::AncestorMember {
+ return;
+ }
+ let user_id = membership.user.id;
let picker = cx.view().clone();
let context_menu = ContextMenu::build(cx, |mut menu, _cx| {
- menu = menu.entry("Remove Member", None, {
+ if membership.kind == channel_member::Kind::AncestorMember {
+ return menu.entry("Inherited membership", None, |_| {});
+ };
+
+ let role = membership.role;
+
+ if role == ChannelRole::Admin || role == ChannelRole::Member {
+ let picker = picker.clone();
+ menu = menu.entry("Demote to Guest", None, move |cx| {
+ picker.update(cx, |picker, cx| {
+ picker
+ .delegate
+ .set_user_role(user_id, ChannelRole::Guest, cx);
+ })
+ });
+ }
+
+ if role == ChannelRole::Admin || role == ChannelRole::Guest {
+ let picker = picker.clone();
+ let label = if role == ChannelRole::Guest {
+ "Promote to Member"
+ } else {
+ "Demote to Member"
+ };
+
+ menu = menu.entry(label, None, move |cx| {
+ picker.update(cx, |picker, cx| {
+ picker
+ .delegate
+ .set_user_role(user_id, ChannelRole::Member, cx);
+ })
+ });
+ }
+
+ if role == ChannelRole::Member || role == ChannelRole::Guest {
+ let picker = picker.clone();
+ menu = menu.entry("Promote to Admin", None, move |cx| {
+ picker.update(cx, |picker, cx| {
+ picker
+ .delegate
+ .set_user_role(user_id, ChannelRole::Admin, cx);
+ })
+ });
+ };
+
+ menu = menu.separator();
+ menu = menu.entry("Remove from Channel", None, {
let picker = picker.clone();
move |cx| {
picker.update(cx, |picker, cx| {
@@ -569,30 +623,6 @@ impl ChannelModalDelegate {
})
}
});
-
- let picker = picker.clone();
- match role {
- ChannelRole::Admin => {
- menu = menu.entry("Revoke Admin", None, move |cx| {
- picker.update(cx, |picker, cx| {
- picker
- .delegate
- .set_user_role(user_id, ChannelRole::Member, cx);
- })
- });
- }
- ChannelRole::Member => {
- menu = menu.entry("Make Admin", None, move |cx| {
- picker.update(cx, |picker, cx| {
- picker
- .delegate
- .set_user_role(user_id, ChannelRole::Admin, cx);
- })
- });
- }
- _ => {}
- };
-
menu
});
cx.focus_view(&context_menu);
@@ -3,6 +3,8 @@ name = "collections"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
+
[lib]
path = "src/collections.rs"
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -3,6 +3,8 @@ name = "color"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[features]
default = []
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "command_palette"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/command_palette.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "copilot"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/copilot.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "copilot_ui"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/copilot_ui.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "db"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/db.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "diagnostics"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/diagnostics.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -1603,6 +1603,7 @@ mod tests {
gutter_width: px(0.),
line_height: px(0.),
em_width: px(0.),
+ max_width: px(0.),
block_id: ix,
view: editor_view,
editor_style: &editor::EditorStyle::default(),
@@ -3,6 +3,8 @@ name = "editor"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/editor.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -84,6 +84,7 @@ pub struct BlockContext<'a, 'b> {
pub context: &'b mut ElementContext<'a>,
pub view: View<Editor>,
pub anchor_x: Pixels,
+ pub max_width: Pixels,
pub gutter_width: Pixels,
pub gutter_padding: Pixels,
pub em_width: Pixels,
@@ -281,7 +281,7 @@ pub enum SelectPhase {
Update {
position: DisplayPoint,
goal_column: u32,
- scroll_position: gpui::Point<f32>,
+ scroll_delta: gpui::Point<f32>,
},
End,
}
@@ -1928,8 +1928,8 @@ impl Editor {
SelectPhase::Update {
position,
goal_column,
- scroll_position,
- } => self.update_selection(position, goal_column, scroll_position, cx),
+ scroll_delta,
+ } => self.update_selection(position, goal_column, scroll_delta, cx),
SelectPhase::End => self.end_selection(cx),
}
}
@@ -2063,7 +2063,7 @@ impl Editor {
&mut self,
position: DisplayPoint,
goal_column: u32,
- scroll_position: gpui::Point<f32>,
+ scroll_delta: gpui::Point<f32>,
cx: &mut ViewContext<Self>,
) {
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
@@ -2152,7 +2152,7 @@ impl Editor {
return;
}
- self.set_scroll_position(scroll_position, cx);
+ self.apply_scroll_delta(scroll_delta, cx);
cx.notify();
}
@@ -9593,31 +9593,33 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, _is_valid: bool) -> Ren
let (text_without_backticks, code_ranges) = highlight_diagnostic_message(&diagnostic);
Arc::new(move |cx: &mut BlockContext| {
- let color = Some(cx.theme().colors().text_accent);
let group_id: SharedString = cx.block_id.to_string().into();
- // TODO: Nate: We should tint the background of the block with the severity color
- // We need to extend the theme before we can do this
+
+ let mut text_style = cx.text_style().clone();
+ text_style.color = diagnostic_style(diagnostic.severity, true, cx.theme().status());
+
h_flex()
.id(cx.block_id)
.group(group_id.clone())
.relative()
- .pl(cx.anchor_x)
.size_full()
- .gap_2()
- .child(
+ .pl(cx.gutter_width)
+ .w(cx.max_width + cx.gutter_width)
+ .child(div().flex().w(cx.anchor_x - cx.gutter_width).flex_shrink())
+ .child(div().flex().flex_shrink_0().child(
StyledText::new(text_without_backticks.clone()).with_highlights(
- &cx.text_style(),
+ &text_style,
code_ranges.iter().map(|range| {
(
range.clone(),
HighlightStyle {
- color,
+ font_weight: Some(FontWeight::BOLD),
..Default::default()
},
)
}),
),
- )
+ ))
.child(
IconButton::new(("copy-block", cx.block_id), IconName::Copy)
.icon_color(Color::Muted)
@@ -531,8 +531,7 @@ impl EditorElement {
SelectPhase::Update {
position: point_for_position.previous_valid,
goal_column: point_for_position.exact_unclipped.column(),
- scroll_position: (position_map.snapshot.scroll_position() + scroll_delta)
- .clamp(&gpui::Point::default(), &position_map.scroll_max),
+ scroll_delta,
},
cx,
);
@@ -2075,6 +2074,7 @@ impl EditorElement {
&snapshot,
bounds.size.width,
scroll_width,
+ text_width,
gutter_dimensions.padding,
gutter_dimensions.width,
em_width,
@@ -2153,14 +2153,18 @@ impl EditorElement {
.max(MIN_POPOVER_LINE_HEIGHT * line_height), // Apply minimum height of 4 lines
);
- let hover = editor.hover_state.render(
+ let hover = if context_menu.is_some() {
+ None
+ } else {
+ editor.hover_state.render(
&snapshot,
&style,
visible_rows,
max_size,
editor.workspace.as_ref().map(|(w, _)| w.clone()),
cx,
- );
+ )
+ };
let editor_view = cx.view().clone();
let fold_indicators = cx.with_element_context(|cx| {
@@ -2257,6 +2261,7 @@ impl EditorElement {
snapshot: &EditorSnapshot,
editor_width: Pixels,
scroll_width: Pixels,
+ text_width: Pixels,
gutter_padding: Pixels,
gutter_width: Pixels,
em_width: Pixels,
@@ -2306,6 +2311,7 @@ impl EditorElement {
gutter_width,
em_width,
block_id,
+ max_width: scroll_width.max(text_width),
view: editor_view.clone(),
editor_style: &self.style,
})
@@ -394,6 +394,26 @@ async fn parse_blocks(
}
}
+ let leading_space = text.chars().take_while(|c| c.is_whitespace()).count();
+ if leading_space > 0 {
+ highlights = highlights
+ .into_iter()
+ .map(|(range, style)| {
+ (
+ range.start.saturating_sub(leading_space)
+ ..range.end.saturating_sub(leading_space),
+ style,
+ )
+ })
+ .collect();
+ region_ranges = region_ranges
+ .into_iter()
+ .map(|range| {
+ range.start.saturating_sub(leading_space)..range.end.saturating_sub(leading_space)
+ })
+ .collect();
+ }
+
ParsedMarkdown {
text: text.trim().to_string(),
highlights,
@@ -277,7 +277,7 @@ impl FollowableItem for Editor {
.extend(ids.iter().map(ExcerptId::to_proto));
true
}
- EditorEvent::ScrollPositionChanged { .. } => {
+ EditorEvent::ScrollPositionChanged { autoscroll, .. } if !autoscroll => {
let scroll_anchor = self.scroll_manager.anchor();
update.scroll_top_anchor = Some(serialize_anchor(&scroll_anchor.anchor));
update.scroll_x = scroll_anchor.offset.x;
@@ -202,7 +202,7 @@ impl ScrollManager {
ScrollAnchor {
anchor: top_anchor,
offset: point(
- scroll_position.x,
+ scroll_position.x.max(0.),
scroll_position.y - top_anchor.to_display_point(&map).row() as f32,
),
},
@@ -327,6 +327,16 @@ impl Editor {
}
}
+ pub fn apply_scroll_delta(
+ &mut self,
+ scroll_delta: gpui::Point<f32>,
+ cx: &mut ViewContext<Self>,
+ ) {
+ let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
+ let position = self.scroll_manager.anchor.scroll_position(&display_map) + scroll_delta;
+ self.set_scroll_position_taking_display_map(position, true, false, display_map, cx);
+ }
+
pub fn set_scroll_position(
&mut self,
scroll_position: gpui::Point<f32>,
@@ -343,12 +353,22 @@ impl Editor {
cx: &mut ViewContext<Self>,
) {
let map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
+ self.set_scroll_position_taking_display_map(scroll_position, local, autoscroll, map, cx);
+ }
+ fn set_scroll_position_taking_display_map(
+ &mut self,
+ scroll_position: gpui::Point<f32>,
+ local: bool,
+ autoscroll: bool,
+ display_map: DisplaySnapshot,
+ cx: &mut ViewContext<Self>,
+ ) {
hide_hover(self, cx);
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
self.scroll_manager.set_scroll_position(
scroll_position,
- &map,
+ &display_map,
local,
autoscroll,
workspace_id,
@@ -3,6 +3,8 @@ name = "feature_flags"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/feature_flags.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "feedback"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/feedback.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -2,7 +2,7 @@ use std::{ops::RangeInclusive, sync::Arc, time::Duration};
use anyhow::{anyhow, bail};
use bitflags::bitflags;
-use client::{Client, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL};
+use client::{Client, ZED_SERVER_URL};
use db::kvp::KEY_VALUE_STORE;
use editor::{Editor, EditorEvent};
use futures::AsyncReadExt;
@@ -46,7 +46,6 @@ struct FeedbackRequestBody<'a> {
installation_id: Option<Arc<str>>,
system_specs: SystemSpecs,
is_staff: bool,
- token: &'a str,
}
bitflags! {
@@ -305,7 +304,6 @@ impl FeedbackModal {
installation_id,
system_specs,
is_staff: is_staff.unwrap_or(false),
- token: ZED_SECRET_CLIENT_TOKEN,
};
let json_bytes = serde_json::to_vec(&request)?;
let request = Request::post(feedback_endpoint)
@@ -3,6 +3,8 @@ name = "file_finder"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/file_finder.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -1,3 +1,6 @@
+#[cfg(test)]
+mod file_finder_tests;
+
use collections::HashMap;
use editor::{scroll::Autoscroll, Bias, Editor};
use fuzzy::{CharBag, PathMatch, PathMatchCandidate};
@@ -112,11 +115,13 @@ impl FileFinder {
}
impl EventEmitter<DismissEvent> for FileFinder {}
+
impl FocusableView for FileFinder {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
self.picker.focus_handle(cx)
}
}
+
impl Render for FileFinder {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
v_flex().w(rems(34.)).child(self.picker.clone())
@@ -352,10 +357,15 @@ impl FileFinderDelegate {
let include_root_name = worktrees.len() > 1;
let candidate_sets = worktrees
.into_iter()
- .map(|worktree| PathMatchCandidateSet {
- snapshot: worktree.read(cx).snapshot(),
- include_ignored: true,
- include_root_name,
+ .map(|worktree| {
+ let worktree = worktree.read(cx);
+ PathMatchCandidateSet {
+ snapshot: worktree.snapshot(),
+ include_ignored: worktree
+ .root_entry()
+ .map_or(false, |entry| entry.is_ignored),
+ include_root_name,
+ }
})
.collect::<Vec<_>>();
@@ -377,6 +387,7 @@ impl FileFinderDelegate {
let did_cancel = cancel_flag.load(atomic::Ordering::Relaxed);
picker
.update(&mut cx, |picker, cx| {
+ picker.delegate.selected_index.take();
picker
.delegate
.set_search_matches(search_id, did_cancel, query, matches, cx)
@@ -615,6 +626,7 @@ impl PickerDelegate for FileFinderDelegate {
if raw_query.is_empty() {
let project = self.project.read(cx);
self.latest_search_id = post_inc(&mut self.search_count);
+ self.selected_index.take();
self.matches = Matches {
history: self
.history_items
@@ -793,1324 +805,3 @@ impl PickerDelegate for FileFinderDelegate {
)
}
}
-
-#[cfg(test)]
-mod tests {
- use std::{assert_eq, path::Path, time::Duration};
-
- use super::*;
- use editor::Editor;
- use gpui::{Entity, TestAppContext, VisualTestContext};
- use menu::{Confirm, SelectNext};
- use serde_json::json;
- use workspace::{AppState, Workspace};
-
- #[ctor::ctor]
- fn init_logger() {
- if std::env::var("RUST_LOG").is_ok() {
- env_logger::init();
- }
- }
-
- #[gpui::test]
- async fn test_matching_paths(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/root",
- json!({
- "a": {
- "banana": "",
- "bandana": "",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
-
- let (picker, workspace, cx) = build_find_picker(project, cx);
-
- cx.simulate_input("bna");
- picker.update(cx, |picker, _| {
- assert_eq!(picker.delegate.matches.len(), 2);
- });
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
- cx.read(|cx| {
- let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
- assert_eq!(active_editor.read(cx).title(cx), "bandana");
- });
-
- for bandana_query in [
- "bandana",
- " bandana",
- "bandana ",
- " bandana ",
- " ndan ",
- " band ",
- ] {
- picker
- .update(cx, |picker, cx| {
- picker
- .delegate
- .update_matches(bandana_query.to_string(), cx)
- })
- .await;
- picker.update(cx, |picker, _| {
- assert_eq!(
- picker.delegate.matches.len(),
- 1,
- "Wrong number of matches for bandana query '{bandana_query}'"
- );
- });
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
- cx.read(|cx| {
- let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
- assert_eq!(
- active_editor.read(cx).title(cx),
- "bandana",
- "Wrong match for bandana query '{bandana_query}'"
- );
- });
- }
- }
-
- #[gpui::test]
- async fn test_absolute_paths(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/root",
- json!({
- "a": {
- "file1.txt": "",
- "b": {
- "file2.txt": "",
- },
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
-
- let (picker, workspace, cx) = build_find_picker(project, cx);
-
- let matching_abs_path = "/root/a/b/file2.txt";
- picker
- .update(cx, |picker, cx| {
- picker
- .delegate
- .update_matches(matching_abs_path.to_string(), cx)
- })
- .await;
- picker.update(cx, |picker, _| {
- assert_eq!(
- collect_search_results(picker),
- vec![PathBuf::from("a/b/file2.txt")],
- "Matching abs path should be the only match"
- )
- });
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
- cx.read(|cx| {
- let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
- assert_eq!(active_editor.read(cx).title(cx), "file2.txt");
- });
-
- let mismatching_abs_path = "/root/a/b/file1.txt";
- picker
- .update(cx, |picker, cx| {
- picker
- .delegate
- .update_matches(mismatching_abs_path.to_string(), cx)
- })
- .await;
- picker.update(cx, |picker, _| {
- assert_eq!(
- collect_search_results(picker),
- Vec::<PathBuf>::new(),
- "Mismatching abs path should produce no matches"
- )
- });
- }
-
- #[gpui::test]
- async fn test_complex_path(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/root",
- json!({
- "ๅ
ถไป": {
- "Sๆฐๆฎ่กจๆ ผ": {
- "task.xlsx": "some content",
- },
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
-
- let (picker, workspace, cx) = build_find_picker(project, cx);
-
- cx.simulate_input("t");
- picker.update(cx, |picker, _| {
- assert_eq!(picker.delegate.matches.len(), 1);
- assert_eq!(
- collect_search_results(picker),
- vec![PathBuf::from("ๅ
ถไป/Sๆฐๆฎ่กจๆ ผ/task.xlsx")],
- )
- });
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
- cx.read(|cx| {
- let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
- assert_eq!(active_editor.read(cx).title(cx), "task.xlsx");
- });
- }
-
- #[gpui::test]
- async fn test_row_column_numbers_query_inside_file(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
-
- let first_file_name = "first.rs";
- let first_file_contents = "// First Rust file";
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- first_file_name: first_file_contents,
- "second.rs": "// Second Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
-
- let (picker, workspace, cx) = build_find_picker(project, cx);
-
- let file_query = &first_file_name[..3];
- let file_row = 1;
- let file_column = 3;
- assert!(file_column <= first_file_contents.len());
- let query_inside_file = format!("{file_query}:{file_row}:{file_column}");
- picker
- .update(cx, |finder, cx| {
- finder
- .delegate
- .update_matches(query_inside_file.to_string(), cx)
- })
- .await;
- picker.update(cx, |finder, _| {
- let finder = &finder.delegate;
- assert_eq!(finder.matches.len(), 1);
- let latest_search_query = finder
- .latest_search_query
- .as_ref()
- .expect("Finder should have a query after the update_matches call");
- assert_eq!(latest_search_query.path_like.raw_query, query_inside_file);
- assert_eq!(
- latest_search_query.path_like.file_query_end,
- Some(file_query.len())
- );
- assert_eq!(latest_search_query.row, Some(file_row));
- assert_eq!(latest_search_query.column, Some(file_column as u32));
- });
-
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
-
- let editor = cx.update(|cx| workspace.read(cx).active_item_as::<Editor>(cx).unwrap());
- cx.executor().advance_clock(Duration::from_secs(2));
-
- editor.update(cx, |editor, cx| {
- let all_selections = editor.selections.all_adjusted(cx);
- assert_eq!(
- all_selections.len(),
- 1,
- "Expected to have 1 selection (caret) after file finder confirm, but got: {all_selections:?}"
- );
- let caret_selection = all_selections.into_iter().next().unwrap();
- assert_eq!(caret_selection.start, caret_selection.end,
- "Caret selection should have its start and end at the same position");
- assert_eq!(file_row, caret_selection.start.row + 1,
- "Query inside file should get caret with the same focus row");
- assert_eq!(file_column, caret_selection.start.column as usize + 1,
- "Query inside file should get caret with the same focus column");
- });
- }
-
- #[gpui::test]
- async fn test_row_column_numbers_query_outside_file(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
-
- let first_file_name = "first.rs";
- let first_file_contents = "// First Rust file";
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- first_file_name: first_file_contents,
- "second.rs": "// Second Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
-
- let (picker, workspace, cx) = build_find_picker(project, cx);
-
- let file_query = &first_file_name[..3];
- let file_row = 200;
- let file_column = 300;
- assert!(file_column > first_file_contents.len());
- let query_outside_file = format!("{file_query}:{file_row}:{file_column}");
- picker
- .update(cx, |picker, cx| {
- picker
- .delegate
- .update_matches(query_outside_file.to_string(), cx)
- })
- .await;
- picker.update(cx, |finder, _| {
- let delegate = &finder.delegate;
- assert_eq!(delegate.matches.len(), 1);
- let latest_search_query = delegate
- .latest_search_query
- .as_ref()
- .expect("Finder should have a query after the update_matches call");
- assert_eq!(latest_search_query.path_like.raw_query, query_outside_file);
- assert_eq!(
- latest_search_query.path_like.file_query_end,
- Some(file_query.len())
- );
- assert_eq!(latest_search_query.row, Some(file_row));
- assert_eq!(latest_search_query.column, Some(file_column as u32));
- });
-
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
-
- let editor = cx.update(|cx| workspace.read(cx).active_item_as::<Editor>(cx).unwrap());
- cx.executor().advance_clock(Duration::from_secs(2));
-
- editor.update(cx, |editor, cx| {
- let all_selections = editor.selections.all_adjusted(cx);
- assert_eq!(
- all_selections.len(),
- 1,
- "Expected to have 1 selection (caret) after file finder confirm, but got: {all_selections:?}"
- );
- let caret_selection = all_selections.into_iter().next().unwrap();
- assert_eq!(caret_selection.start, caret_selection.end,
- "Caret selection should have its start and end at the same position");
- assert_eq!(0, caret_selection.start.row,
- "Excessive rows (as in query outside file borders) should get trimmed to last file row");
- assert_eq!(first_file_contents.len(), caret_selection.start.column as usize,
- "Excessive columns (as in query outside file borders) should get trimmed to selected row's last column");
- });
- }
-
- #[gpui::test]
- async fn test_matching_cancellation(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/dir",
- json!({
- "hello": "",
- "goodbye": "",
- "halogen-light": "",
- "happiness": "",
- "height": "",
- "hi": "",
- "hiccup": "",
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/dir".as_ref()], cx).await;
-
- let (picker, _, cx) = build_find_picker(project, cx);
-
- let query = test_path_like("hi");
- picker
- .update(cx, |picker, cx| {
- picker.delegate.spawn_search(query.clone(), cx)
- })
- .await;
-
- picker.update(cx, |picker, _cx| {
- assert_eq!(picker.delegate.matches.len(), 5)
- });
-
- picker.update(cx, |picker, cx| {
- let delegate = &mut picker.delegate;
- assert!(
- delegate.matches.history.is_empty(),
- "Search matches expected"
- );
- let matches = delegate.matches.search.clone();
-
- // Simulate a search being cancelled after the time limit,
- // returning only a subset of the matches that would have been found.
- drop(delegate.spawn_search(query.clone(), cx));
- delegate.set_search_matches(
- delegate.latest_search_id,
- true, // did-cancel
- query.clone(),
- vec![matches[1].clone(), matches[3].clone()],
- cx,
- );
-
- // Simulate another cancellation.
- drop(delegate.spawn_search(query.clone(), cx));
- delegate.set_search_matches(
- delegate.latest_search_id,
- true, // did-cancel
- query.clone(),
- vec![matches[0].clone(), matches[2].clone(), matches[3].clone()],
- cx,
- );
-
- assert!(
- delegate.matches.history.is_empty(),
- "Search matches expected"
- );
- assert_eq!(delegate.matches.search.as_slice(), &matches[0..4]);
- });
- }
-
- #[gpui::test]
- async fn test_ignored_root(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/ancestor",
- json!({
- ".gitignore": "ignored-root",
- "ignored-root": {
- "happiness": "",
- "height": "",
- "hi": "",
- "hiccup": "",
- },
- "tracked-root": {
- ".gitignore": "height",
- "happiness": "",
- "height": "",
- "hi": "",
- "hiccup": "",
- },
- }),
- )
- .await;
-
- let project = Project::test(
- app_state.fs.clone(),
- [
- "/ancestor/tracked-root".as_ref(),
- "/ancestor/ignored-root".as_ref(),
- ],
- cx,
- )
- .await;
-
- let (picker, _, cx) = build_find_picker(project, cx);
-
- picker
- .update(cx, |picker, cx| {
- picker.delegate.spawn_search(test_path_like("hi"), cx)
- })
- .await;
- picker.update(cx, |picker, _| {
- assert_eq!(
- collect_search_results(picker),
- vec![
- PathBuf::from("ignored-root/happiness"),
- PathBuf::from("ignored-root/height"),
- PathBuf::from("ignored-root/hi"),
- PathBuf::from("ignored-root/hiccup"),
- PathBuf::from("tracked-root/happiness"),
- PathBuf::from("tracked-root/height"),
- PathBuf::from("tracked-root/hi"),
- PathBuf::from("tracked-root/hiccup"),
- ],
- "All files in all roots (including gitignored) should be searched"
- )
- });
- }
-
- #[gpui::test]
- async fn test_ignored_files(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/root",
- json!({
- ".git": {},
- ".gitignore": "ignored_a\n.env\n",
- "a": {
- "banana_env": "11",
- "bandana_env": "12",
- },
- "ignored_a": {
- "ignored_banana_env": "21",
- "ignored_bandana_env": "22",
- "ignored_nested": {
- "ignored_nested_banana_env": "31",
- "ignored_nested_bandana_env": "32",
- },
- },
- ".env": "something",
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
-
- let (picker, workspace, cx) = build_find_picker(project, cx);
-
- cx.simulate_input("env");
- picker.update(cx, |picker, _| {
- assert_eq!(
- collect_search_results(picker),
- vec![
- PathBuf::from(".env"),
- PathBuf::from("a/banana_env"),
- PathBuf::from("a/bandana_env"),
- ],
- "Root gitignored files and all non-gitignored files should be searched"
- )
- });
-
- let _ = workspace
- .update(cx, |workspace, cx| {
- workspace.open_abs_path(
- PathBuf::from("/root/ignored_a/ignored_banana_env"),
- true,
- cx,
- )
- })
- .await
- .unwrap();
- cx.run_until_parked();
- cx.simulate_input("env");
- picker.update(cx, |picker, _| {
- assert_eq!(
- collect_search_results(picker),
- vec![
- PathBuf::from(".env"),
- PathBuf::from("a/banana_env"),
- PathBuf::from("a/bandana_env"),
- PathBuf::from("ignored_a/ignored_banana_env"),
- PathBuf::from("ignored_a/ignored_bandana_env"),
- ],
- "Root gitignored dir got listed and its entries got into worktree, but all gitignored dirs below it were not listed. Old entries + new listed gitignored entries should be searched"
- )
- });
- }
-
- #[gpui::test]
- async fn test_single_file_worktrees(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree("/root", json!({ "the-parent-dir": { "the-file": "" } }))
- .await;
-
- let project = Project::test(
- app_state.fs.clone(),
- ["/root/the-parent-dir/the-file".as_ref()],
- cx,
- )
- .await;
-
- let (picker, _, cx) = build_find_picker(project, cx);
-
- // Even though there is only one worktree, that worktree's filename
- // is included in the matching, because the worktree is a single file.
- picker
- .update(cx, |picker, cx| {
- picker.delegate.spawn_search(test_path_like("thf"), cx)
- })
- .await;
- cx.read(|cx| {
- let picker = picker.read(cx);
- let delegate = &picker.delegate;
- assert!(
- delegate.matches.history.is_empty(),
- "Search matches expected"
- );
- let matches = delegate.matches.search.clone();
- assert_eq!(matches.len(), 1);
-
- let (file_name, file_name_positions, full_path, full_path_positions) =
- delegate.labels_for_path_match(&matches[0]);
- assert_eq!(file_name, "the-file");
- assert_eq!(file_name_positions, &[0, 1, 4]);
- assert_eq!(full_path, "the-file");
- assert_eq!(full_path_positions, &[0, 1, 4]);
- });
-
- // Since the worktree root is a file, searching for its name followed by a slash does
- // not match anything.
- picker
- .update(cx, |f, cx| {
- f.delegate.spawn_search(test_path_like("thf/"), cx)
- })
- .await;
- picker.update(cx, |f, _| assert_eq!(f.delegate.matches.len(), 0));
- }
-
- #[gpui::test]
- async fn test_path_distance_ordering(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/root",
- json!({
- "dir1": { "a.txt": "" },
- "dir2": {
- "a.txt": "",
- "b.txt": ""
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
-
- let worktree_id = cx.read(|cx| {
- let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
- assert_eq!(worktrees.len(), 1);
- WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
- });
-
- // When workspace has an active item, sort items which are closer to that item
- // first when they have the same name. In this case, b.txt is closer to dir2's a.txt
- // so that one should be sorted earlier
- let b_path = ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("dir2/b.txt")),
- };
- workspace
- .update(cx, |workspace, cx| {
- workspace.open_path(b_path, None, true, cx)
- })
- .await
- .unwrap();
- let finder = open_file_picker(&workspace, cx);
- finder
- .update(cx, |f, cx| {
- f.delegate.spawn_search(test_path_like("a.txt"), cx)
- })
- .await;
-
- finder.update(cx, |f, _| {
- let delegate = &f.delegate;
- assert!(
- delegate.matches.history.is_empty(),
- "Search matches expected"
- );
- let matches = delegate.matches.search.clone();
- assert_eq!(matches[0].path.as_ref(), Path::new("dir2/a.txt"));
- assert_eq!(matches[1].path.as_ref(), Path::new("dir1/a.txt"));
- });
- }
-
- #[gpui::test]
- async fn test_search_worktree_without_files(cx: &mut TestAppContext) {
- let app_state = init_test(cx);
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/root",
- json!({
- "dir1": {},
- "dir2": {
- "dir3": {}
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
- let (picker, _workspace, cx) = build_find_picker(project, cx);
-
- picker
- .update(cx, |f, cx| {
- f.delegate.spawn_search(test_path_like("dir"), cx)
- })
- .await;
- cx.read(|cx| {
- let finder = picker.read(cx);
- assert_eq!(finder.delegate.matches.len(), 0);
- });
- }
-
- #[gpui::test]
- async fn test_query_history(cx: &mut gpui::TestAppContext) {
- let app_state = init_test(cx);
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- "first.rs": "// First Rust file",
- "second.rs": "// Second Rust file",
- "third.rs": "// Third Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
- let worktree_id = cx.read(|cx| {
- let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
- assert_eq!(worktrees.len(), 1);
- WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
- });
-
- // Open and close panels, getting their history items afterwards.
- // Ensure history items get populated with opened items, and items are kept in a certain order.
- // The history lags one opened buffer behind, since it's updated in the search panel only on its reopen.
- //
- // TODO: without closing, the opened items do not propagate their history changes for some reason
- // it does work in real app though, only tests do not propagate.
- workspace.update(cx, |_, cx| cx.focused());
-
- let initial_history = open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
- assert!(
- initial_history.is_empty(),
- "Should have no history before opening any files"
- );
-
- let history_after_first =
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
- assert_eq!(
- history_after_first,
- vec![FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/first.rs")),
- },
- Some(PathBuf::from("/src/test/first.rs"))
- )],
- "Should show 1st opened item in the history when opening the 2nd item"
- );
-
- let history_after_second =
- open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
- assert_eq!(
- history_after_second,
- vec![
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/second.rs")),
- },
- Some(PathBuf::from("/src/test/second.rs"))
- ),
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/first.rs")),
- },
- Some(PathBuf::from("/src/test/first.rs"))
- ),
- ],
- "Should show 1st and 2nd opened items in the history when opening the 3rd item. \
- 2nd item should be the first in the history, as the last opened."
- );
-
- let history_after_third =
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
- assert_eq!(
- history_after_third,
- vec![
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/third.rs")),
- },
- Some(PathBuf::from("/src/test/third.rs"))
- ),
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/second.rs")),
- },
- Some(PathBuf::from("/src/test/second.rs"))
- ),
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/first.rs")),
- },
- Some(PathBuf::from("/src/test/first.rs"))
- ),
- ],
- "Should show 1st, 2nd and 3rd opened items in the history when opening the 2nd item again. \
- 3rd item should be the first in the history, as the last opened."
- );
-
- let history_after_second_again =
- open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
- assert_eq!(
- history_after_second_again,
- vec![
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/second.rs")),
- },
- Some(PathBuf::from("/src/test/second.rs"))
- ),
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/third.rs")),
- },
- Some(PathBuf::from("/src/test/third.rs"))
- ),
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/first.rs")),
- },
- Some(PathBuf::from("/src/test/first.rs"))
- ),
- ],
- "Should show 1st, 2nd and 3rd opened items in the history when opening the 3rd item again. \
- 2nd item, as the last opened, 3rd item should go next as it was opened right before."
- );
- }
-
- #[gpui::test]
- async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
- let app_state = init_test(cx);
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- "first.rs": "// First Rust file",
- "second.rs": "// Second Rust file",
- }
- }),
- )
- .await;
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/external-src",
- json!({
- "test": {
- "third.rs": "// Third Rust file",
- "fourth.rs": "// Fourth Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
- cx.update(|cx| {
- project.update(cx, |project, cx| {
- project.find_or_create_local_worktree("/external-src", false, cx)
- })
- })
- .detach();
- cx.background_executor.run_until_parked();
-
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
- let worktree_id = cx.read(|cx| {
- let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
- assert_eq!(worktrees.len(), 1,);
-
- WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
- });
- workspace
- .update(cx, |workspace, cx| {
- workspace.open_abs_path(PathBuf::from("/external-src/test/third.rs"), false, cx)
- })
- .detach();
- cx.background_executor.run_until_parked();
- let external_worktree_id = cx.read(|cx| {
- let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
- assert_eq!(
- worktrees.len(),
- 2,
- "External file should get opened in a new worktree"
- );
-
- WorktreeId::from_usize(
- worktrees
- .into_iter()
- .find(|worktree| {
- worktree.entity_id().as_u64() as usize != worktree_id.to_usize()
- })
- .expect("New worktree should have a different id")
- .entity_id()
- .as_u64() as usize,
- )
- });
- cx.dispatch_action(workspace::CloseActiveItem { save_intent: None });
-
- let initial_history_items =
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
- assert_eq!(
- initial_history_items,
- vec![FoundPath::new(
- ProjectPath {
- worktree_id: external_worktree_id,
- path: Arc::from(Path::new("")),
- },
- Some(PathBuf::from("/external-src/test/third.rs"))
- )],
- "Should show external file with its full path in the history after it was open"
- );
-
- let updated_history_items =
- open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
- assert_eq!(
- updated_history_items,
- vec![
- FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/second.rs")),
- },
- Some(PathBuf::from("/src/test/second.rs"))
- ),
- FoundPath::new(
- ProjectPath {
- worktree_id: external_worktree_id,
- path: Arc::from(Path::new("")),
- },
- Some(PathBuf::from("/external-src/test/third.rs"))
- ),
- ],
- "Should keep external file with history updates",
- );
- }
-
- #[gpui::test]
- async fn test_toggle_panel_new_selections(cx: &mut gpui::TestAppContext) {
- let app_state = init_test(cx);
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- "first.rs": "// First Rust file",
- "second.rs": "// Second Rust file",
- "third.rs": "// Third Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
-
- // generate some history to select from
- open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
- cx.executor().run_until_parked();
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
- open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
- let current_history =
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
-
- for expected_selected_index in 0..current_history.len() {
- cx.dispatch_action(Toggle);
- let picker = active_file_picker(&workspace, cx);
- let selected_index = picker.update(cx, |picker, _| picker.delegate.selected_index());
- assert_eq!(
- selected_index, expected_selected_index,
- "Should select the next item in the history"
- );
- }
-
- cx.dispatch_action(Toggle);
- let selected_index = workspace.update(cx, |workspace, cx| {
- workspace
- .active_modal::<FileFinder>(cx)
- .unwrap()
- .read(cx)
- .picker
- .read(cx)
- .delegate
- .selected_index()
- });
- assert_eq!(
- selected_index, 0,
- "Should wrap around the history and start all over"
- );
- }
-
- #[gpui::test]
- async fn test_search_preserves_history_items(cx: &mut gpui::TestAppContext) {
- let app_state = init_test(cx);
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- "first.rs": "// First Rust file",
- "second.rs": "// Second Rust file",
- "third.rs": "// Third Rust file",
- "fourth.rs": "// Fourth Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
- let worktree_id = cx.read(|cx| {
- let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
- assert_eq!(worktrees.len(), 1,);
-
- WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
- });
-
- // generate some history to select from
- open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
- open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
-
- let finder = open_file_picker(&workspace, cx);
- let first_query = "f";
- finder
- .update(cx, |finder, cx| {
- finder.delegate.update_matches(first_query.to_string(), cx)
- })
- .await;
- finder.update(cx, |finder, _| {
- let delegate = &finder.delegate;
- assert_eq!(delegate.matches.history.len(), 1, "Only one history item contains {first_query}, it should be present and others should be filtered out");
- let history_match = delegate.matches.history.first().unwrap();
- assert!(history_match.1.is_some(), "Should have path matches for history items after querying");
- assert_eq!(history_match.0, FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/first.rs")),
- },
- Some(PathBuf::from("/src/test/first.rs"))
- ));
- assert_eq!(delegate.matches.search.len(), 1, "Only one non-history item contains {first_query}, it should be present");
- assert_eq!(delegate.matches.search.first().unwrap().path.as_ref(), Path::new("test/fourth.rs"));
- });
-
- let second_query = "fsdasdsa";
- let finder = active_file_picker(&workspace, cx);
- finder
- .update(cx, |finder, cx| {
- finder.delegate.update_matches(second_query.to_string(), cx)
- })
- .await;
- finder.update(cx, |finder, _| {
- let delegate = &finder.delegate;
- assert!(
- delegate.matches.history.is_empty(),
- "No history entries should match {second_query}"
- );
- assert!(
- delegate.matches.search.is_empty(),
- "No search entries should match {second_query}"
- );
- });
-
- let first_query_again = first_query;
-
- let finder = active_file_picker(&workspace, cx);
- finder
- .update(cx, |finder, cx| {
- finder
- .delegate
- .update_matches(first_query_again.to_string(), cx)
- })
- .await;
- finder.update(cx, |finder, _| {
- let delegate = &finder.delegate;
- assert_eq!(delegate.matches.history.len(), 1, "Only one history item contains {first_query_again}, it should be present and others should be filtered out, even after non-matching query");
- let history_match = delegate.matches.history.first().unwrap();
- assert!(history_match.1.is_some(), "Should have path matches for history items after querying");
- assert_eq!(history_match.0, FoundPath::new(
- ProjectPath {
- worktree_id,
- path: Arc::from(Path::new("test/first.rs")),
- },
- Some(PathBuf::from("/src/test/first.rs"))
- ));
- assert_eq!(delegate.matches.search.len(), 1, "Only one non-history item contains {first_query_again}, it should be present, even after non-matching query");
- assert_eq!(delegate.matches.search.first().unwrap().path.as_ref(), Path::new("test/fourth.rs"));
- });
- }
-
- #[gpui::test]
- async fn test_history_items_vs_very_good_external_match(cx: &mut gpui::TestAppContext) {
- let app_state = init_test(cx);
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "collab_ui": {
- "first.rs": "// First Rust file",
- "second.rs": "// Second Rust file",
- "third.rs": "// Third Rust file",
- "collab_ui.rs": "// Fourth Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
- // generate some history to select from
- open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
- open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
- open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
-
- let finder = open_file_picker(&workspace, cx);
- let query = "collab_ui";
- cx.simulate_input(query);
- finder.update(cx, |finder, _| {
- let delegate = &finder.delegate;
- assert!(
- delegate.matches.history.is_empty(),
- "History items should not math query {query}, they should be matched by name only"
- );
-
- let search_entries = delegate
- .matches
- .search
- .iter()
- .map(|path_match| path_match.path.to_path_buf())
- .collect::<Vec<_>>();
- assert_eq!(
- search_entries,
- vec![
- PathBuf::from("collab_ui/collab_ui.rs"),
- PathBuf::from("collab_ui/third.rs"),
- PathBuf::from("collab_ui/first.rs"),
- PathBuf::from("collab_ui/second.rs"),
- ],
- "Despite all search results having the same directory name, the most matching one should be on top"
- );
- });
- }
-
- #[gpui::test]
- async fn test_nonexistent_history_items_not_shown(cx: &mut gpui::TestAppContext) {
- let app_state = init_test(cx);
-
- app_state
- .fs
- .as_fake()
- .insert_tree(
- "/src",
- json!({
- "test": {
- "first.rs": "// First Rust file",
- "nonexistent.rs": "// Second Rust file",
- "third.rs": "// Third Rust file",
- }
- }),
- )
- .await;
-
- let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); // generate some history to select from
- open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
- open_close_queried_buffer("non", 1, "nonexistent.rs", &workspace, cx).await;
- open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
- open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
-
- let picker = open_file_picker(&workspace, cx);
- cx.simulate_input("rs");
-
- picker.update(cx, |finder, _| {
- let history_entries = finder.delegate
- .matches
- .history
- .iter()
- .map(|(_, path_match)| path_match.as_ref().expect("should have a path match").path.to_path_buf())
- .collect::<Vec<_>>();
- assert_eq!(
- history_entries,
- vec![
- PathBuf::from("test/first.rs"),
- PathBuf::from("test/third.rs"),
- ],
- "Should have all opened files in the history, except the ones that do not exist on disk"
- );
- });
- }
-
- async fn open_close_queried_buffer(
- input: &str,
- expected_matches: usize,
- expected_editor_title: &str,
- workspace: &View<Workspace>,
- cx: &mut gpui::VisualTestContext,
- ) -> Vec<FoundPath> {
- let picker = open_file_picker(&workspace, cx);
- cx.simulate_input(input);
-
- let history_items = picker.update(cx, |finder, _| {
- assert_eq!(
- finder.delegate.matches.len(),
- expected_matches,
- "Unexpected number of matches found for query {input}"
- );
- finder.delegate.history_items.clone()
- });
-
- cx.dispatch_action(SelectNext);
- cx.dispatch_action(Confirm);
-
- cx.read(|cx| {
- let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
- let active_editor_title = active_editor.read(cx).title(cx);
- assert_eq!(
- expected_editor_title, active_editor_title,
- "Unexpected editor title for query {input}"
- );
- });
-
- cx.dispatch_action(workspace::CloseActiveItem { save_intent: None });
-
- history_items
- }
-
- fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {
- cx.update(|cx| {
- let state = AppState::test(cx);
- theme::init(theme::LoadThemes::JustBase, cx);
- language::init(cx);
- super::init(cx);
- editor::init(cx);
- workspace::init_settings(cx);
- Project::init_settings(cx);
- state
- })
- }
-
- fn test_path_like(test_str: &str) -> PathLikeWithPosition<FileSearchQuery> {
- PathLikeWithPosition::parse_str(test_str, |path_like_str| {
- Ok::<_, std::convert::Infallible>(FileSearchQuery {
- raw_query: test_str.to_owned(),
- file_query_end: if path_like_str == test_str {
- None
- } else {
- Some(path_like_str.len())
- },
- })
- })
- .unwrap()
- }
-
- fn build_find_picker(
- project: Model<Project>,
- cx: &mut TestAppContext,
- ) -> (
- View<Picker<FileFinderDelegate>>,
- View<Workspace>,
- &mut VisualTestContext,
- ) {
- let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
- let picker = open_file_picker(&workspace, cx);
- (picker, workspace, cx)
- }
-
- #[track_caller]
- fn open_file_picker(
- workspace: &View<Workspace>,
- cx: &mut VisualTestContext,
- ) -> View<Picker<FileFinderDelegate>> {
- cx.dispatch_action(Toggle);
- active_file_picker(workspace, cx)
- }
-
- #[track_caller]
- fn active_file_picker(
- workspace: &View<Workspace>,
- cx: &mut VisualTestContext,
- ) -> View<Picker<FileFinderDelegate>> {
- workspace.update(cx, |workspace, cx| {
- workspace
- .active_modal::<FileFinder>(cx)
- .unwrap()
- .read(cx)
- .picker
- .clone()
- })
- }
-
- fn collect_search_results(picker: &Picker<FileFinderDelegate>) -> Vec<PathBuf> {
- let matches = &picker.delegate.matches;
- assert!(
- matches.history.is_empty(),
- "Should have no history matches, but got: {:?}",
- matches.history
- );
- let mut results = matches
- .search
- .iter()
- .map(|path_match| Path::new(path_match.path_prefix.as_ref()).join(&path_match.path))
- .collect::<Vec<_>>();
- results.sort();
- results
- }
-}
@@ -0,0 +1,1227 @@
+use std::{assert_eq, path::Path, time::Duration};
+
+use super::*;
+use editor::Editor;
+use gpui::{Entity, TestAppContext, VisualTestContext};
+use menu::{Confirm, SelectNext};
+use serde_json::json;
+use workspace::{AppState, Workspace};
+
+#[ctor::ctor]
+fn init_logger() {
+ if std::env::var("RUST_LOG").is_ok() {
+ env_logger::init();
+ }
+}
+
+#[gpui::test]
+async fn test_matching_paths(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/root",
+ json!({
+ "a": {
+ "banana": "",
+ "bandana": "",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
+
+ let (picker, workspace, cx) = build_find_picker(project, cx);
+
+ cx.simulate_input("bna");
+ picker.update(cx, |picker, _| {
+ assert_eq!(picker.delegate.matches.len(), 2);
+ });
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ assert_eq!(active_editor.read(cx).title(cx), "bandana");
+ });
+
+ for bandana_query in [
+ "bandana",
+ " bandana",
+ "bandana ",
+ " bandana ",
+ " ndan ",
+ " band ",
+ ] {
+ picker
+ .update(cx, |picker, cx| {
+ picker
+ .delegate
+ .update_matches(bandana_query.to_string(), cx)
+ })
+ .await;
+ picker.update(cx, |picker, _| {
+ assert_eq!(
+ picker.delegate.matches.len(),
+ 1,
+ "Wrong number of matches for bandana query '{bandana_query}'"
+ );
+ });
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ assert_eq!(
+ active_editor.read(cx).title(cx),
+ "bandana",
+ "Wrong match for bandana query '{bandana_query}'"
+ );
+ });
+ }
+}
+
+#[gpui::test]
+async fn test_absolute_paths(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/root",
+ json!({
+ "a": {
+ "file1.txt": "",
+ "b": {
+ "file2.txt": "",
+ },
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
+
+ let (picker, workspace, cx) = build_find_picker(project, cx);
+
+ let matching_abs_path = "/root/a/b/file2.txt";
+ picker
+ .update(cx, |picker, cx| {
+ picker
+ .delegate
+ .update_matches(matching_abs_path.to_string(), cx)
+ })
+ .await;
+ picker.update(cx, |picker, _| {
+ assert_eq!(
+ collect_search_results(picker),
+ vec![PathBuf::from("a/b/file2.txt")],
+ "Matching abs path should be the only match"
+ )
+ });
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ assert_eq!(active_editor.read(cx).title(cx), "file2.txt");
+ });
+
+ let mismatching_abs_path = "/root/a/b/file1.txt";
+ picker
+ .update(cx, |picker, cx| {
+ picker
+ .delegate
+ .update_matches(mismatching_abs_path.to_string(), cx)
+ })
+ .await;
+ picker.update(cx, |picker, _| {
+ assert_eq!(
+ collect_search_results(picker),
+ Vec::<PathBuf>::new(),
+ "Mismatching abs path should produce no matches"
+ )
+ });
+}
+
+#[gpui::test]
+async fn test_complex_path(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/root",
+ json!({
+ "ๅ
ถไป": {
+ "Sๆฐๆฎ่กจๆ ผ": {
+ "task.xlsx": "some content",
+ },
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
+
+ let (picker, workspace, cx) = build_find_picker(project, cx);
+
+ cx.simulate_input("t");
+ picker.update(cx, |picker, _| {
+ assert_eq!(picker.delegate.matches.len(), 1);
+ assert_eq!(
+ collect_search_results(picker),
+ vec![PathBuf::from("ๅ
ถไป/Sๆฐๆฎ่กจๆ ผ/task.xlsx")],
+ )
+ });
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ assert_eq!(active_editor.read(cx).title(cx), "task.xlsx");
+ });
+}
+
+#[gpui::test]
+async fn test_row_column_numbers_query_inside_file(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+
+ let first_file_name = "first.rs";
+ let first_file_contents = "// First Rust file";
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ first_file_name: first_file_contents,
+ "second.rs": "// Second Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+
+ let (picker, workspace, cx) = build_find_picker(project, cx);
+
+ let file_query = &first_file_name[..3];
+ let file_row = 1;
+ let file_column = 3;
+ assert!(file_column <= first_file_contents.len());
+ let query_inside_file = format!("{file_query}:{file_row}:{file_column}");
+ picker
+ .update(cx, |finder, cx| {
+ finder
+ .delegate
+ .update_matches(query_inside_file.to_string(), cx)
+ })
+ .await;
+ picker.update(cx, |finder, _| {
+ let finder = &finder.delegate;
+ assert_eq!(finder.matches.len(), 1);
+ let latest_search_query = finder
+ .latest_search_query
+ .as_ref()
+ .expect("Finder should have a query after the update_matches call");
+ assert_eq!(latest_search_query.path_like.raw_query, query_inside_file);
+ assert_eq!(
+ latest_search_query.path_like.file_query_end,
+ Some(file_query.len())
+ );
+ assert_eq!(latest_search_query.row, Some(file_row));
+ assert_eq!(latest_search_query.column, Some(file_column as u32));
+ });
+
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+
+ let editor = cx.update(|cx| workspace.read(cx).active_item_as::<Editor>(cx).unwrap());
+ cx.executor().advance_clock(Duration::from_secs(2));
+
+ editor.update(cx, |editor, cx| {
+ let all_selections = editor.selections.all_adjusted(cx);
+ assert_eq!(
+ all_selections.len(),
+ 1,
+ "Expected to have 1 selection (caret) after file finder confirm, but got: {all_selections:?}"
+ );
+ let caret_selection = all_selections.into_iter().next().unwrap();
+ assert_eq!(caret_selection.start, caret_selection.end,
+ "Caret selection should have its start and end at the same position");
+ assert_eq!(file_row, caret_selection.start.row + 1,
+ "Query inside file should get caret with the same focus row");
+ assert_eq!(file_column, caret_selection.start.column as usize + 1,
+ "Query inside file should get caret with the same focus column");
+ });
+}
+
+#[gpui::test]
+async fn test_row_column_numbers_query_outside_file(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+
+ let first_file_name = "first.rs";
+ let first_file_contents = "// First Rust file";
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ first_file_name: first_file_contents,
+ "second.rs": "// Second Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+
+ let (picker, workspace, cx) = build_find_picker(project, cx);
+
+ let file_query = &first_file_name[..3];
+ let file_row = 200;
+ let file_column = 300;
+ assert!(file_column > first_file_contents.len());
+ let query_outside_file = format!("{file_query}:{file_row}:{file_column}");
+ picker
+ .update(cx, |picker, cx| {
+ picker
+ .delegate
+ .update_matches(query_outside_file.to_string(), cx)
+ })
+ .await;
+ picker.update(cx, |finder, _| {
+ let delegate = &finder.delegate;
+ assert_eq!(delegate.matches.len(), 1);
+ let latest_search_query = delegate
+ .latest_search_query
+ .as_ref()
+ .expect("Finder should have a query after the update_matches call");
+ assert_eq!(latest_search_query.path_like.raw_query, query_outside_file);
+ assert_eq!(
+ latest_search_query.path_like.file_query_end,
+ Some(file_query.len())
+ );
+ assert_eq!(latest_search_query.row, Some(file_row));
+ assert_eq!(latest_search_query.column, Some(file_column as u32));
+ });
+
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+
+ let editor = cx.update(|cx| workspace.read(cx).active_item_as::<Editor>(cx).unwrap());
+ cx.executor().advance_clock(Duration::from_secs(2));
+
+ editor.update(cx, |editor, cx| {
+ let all_selections = editor.selections.all_adjusted(cx);
+ assert_eq!(
+ all_selections.len(),
+ 1,
+ "Expected to have 1 selection (caret) after file finder confirm, but got: {all_selections:?}"
+ );
+ let caret_selection = all_selections.into_iter().next().unwrap();
+ assert_eq!(caret_selection.start, caret_selection.end,
+ "Caret selection should have its start and end at the same position");
+ assert_eq!(0, caret_selection.start.row,
+ "Excessive rows (as in query outside file borders) should get trimmed to last file row");
+ assert_eq!(first_file_contents.len(), caret_selection.start.column as usize,
+ "Excessive columns (as in query outside file borders) should get trimmed to selected row's last column");
+ });
+}
+
+#[gpui::test]
+async fn test_matching_cancellation(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/dir",
+ json!({
+ "hello": "",
+ "goodbye": "",
+ "halogen-light": "",
+ "happiness": "",
+ "height": "",
+ "hi": "",
+ "hiccup": "",
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/dir".as_ref()], cx).await;
+
+ let (picker, _, cx) = build_find_picker(project, cx);
+
+ let query = test_path_like("hi");
+ picker
+ .update(cx, |picker, cx| {
+ picker.delegate.spawn_search(query.clone(), cx)
+ })
+ .await;
+
+ picker.update(cx, |picker, _cx| {
+ assert_eq!(picker.delegate.matches.len(), 5)
+ });
+
+ picker.update(cx, |picker, cx| {
+ let delegate = &mut picker.delegate;
+ assert!(
+ delegate.matches.history.is_empty(),
+ "Search matches expected"
+ );
+ let matches = delegate.matches.search.clone();
+
+ // Simulate a search being cancelled after the time limit,
+ // returning only a subset of the matches that would have been found.
+ drop(delegate.spawn_search(query.clone(), cx));
+ delegate.set_search_matches(
+ delegate.latest_search_id,
+ true, // did-cancel
+ query.clone(),
+ vec![matches[1].clone(), matches[3].clone()],
+ cx,
+ );
+
+ // Simulate another cancellation.
+ drop(delegate.spawn_search(query.clone(), cx));
+ delegate.set_search_matches(
+ delegate.latest_search_id,
+ true, // did-cancel
+ query.clone(),
+ vec![matches[0].clone(), matches[2].clone(), matches[3].clone()],
+ cx,
+ );
+
+ assert!(
+ delegate.matches.history.is_empty(),
+ "Search matches expected"
+ );
+ assert_eq!(delegate.matches.search.as_slice(), &matches[0..4]);
+ });
+}
+
+#[gpui::test]
+async fn test_ignored_root(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/ancestor",
+ json!({
+ ".gitignore": "ignored-root",
+ "ignored-root": {
+ "happiness": "",
+ "height": "",
+ "hi": "",
+ "hiccup": "",
+ },
+ "tracked-root": {
+ ".gitignore": "height",
+ "happiness": "",
+ "height": "",
+ "hi": "",
+ "hiccup": "",
+ },
+ }),
+ )
+ .await;
+
+ let project = Project::test(
+ app_state.fs.clone(),
+ [
+ "/ancestor/tracked-root".as_ref(),
+ "/ancestor/ignored-root".as_ref(),
+ ],
+ cx,
+ )
+ .await;
+
+ let (picker, _, cx) = build_find_picker(project, cx);
+
+ picker
+ .update(cx, |picker, cx| {
+ picker.delegate.spawn_search(test_path_like("hi"), cx)
+ })
+ .await;
+ picker.update(cx, |picker, _| assert_eq!(picker.delegate.matches.len(), 7));
+}
+
+#[gpui::test]
+async fn test_single_file_worktrees(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree("/root", json!({ "the-parent-dir": { "the-file": "" } }))
+ .await;
+
+ let project = Project::test(
+ app_state.fs.clone(),
+ ["/root/the-parent-dir/the-file".as_ref()],
+ cx,
+ )
+ .await;
+
+ let (picker, _, cx) = build_find_picker(project, cx);
+
+ // Even though there is only one worktree, that worktree's filename
+ // is included in the matching, because the worktree is a single file.
+ picker
+ .update(cx, |picker, cx| {
+ picker.delegate.spawn_search(test_path_like("thf"), cx)
+ })
+ .await;
+ cx.read(|cx| {
+ let picker = picker.read(cx);
+ let delegate = &picker.delegate;
+ assert!(
+ delegate.matches.history.is_empty(),
+ "Search matches expected"
+ );
+ let matches = delegate.matches.search.clone();
+ assert_eq!(matches.len(), 1);
+
+ let (file_name, file_name_positions, full_path, full_path_positions) =
+ delegate.labels_for_path_match(&matches[0]);
+ assert_eq!(file_name, "the-file");
+ assert_eq!(file_name_positions, &[0, 1, 4]);
+ assert_eq!(full_path, "the-file");
+ assert_eq!(full_path_positions, &[0, 1, 4]);
+ });
+
+ // Since the worktree root is a file, searching for its name followed by a slash does
+ // not match anything.
+ picker
+ .update(cx, |f, cx| {
+ f.delegate.spawn_search(test_path_like("thf/"), cx)
+ })
+ .await;
+ picker.update(cx, |f, _| assert_eq!(f.delegate.matches.len(), 0));
+}
+
+#[gpui::test]
+async fn test_path_distance_ordering(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/root",
+ json!({
+ "dir1": { "a.txt": "" },
+ "dir2": {
+ "a.txt": "",
+ "b.txt": ""
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+
+ let worktree_id = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
+ assert_eq!(worktrees.len(), 1);
+ WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
+ });
+
+ // When workspace has an active item, sort items which are closer to that item
+ // first when they have the same name. In this case, b.txt is closer to dir2's a.txt
+ // so that one should be sorted earlier
+ let b_path = ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("dir2/b.txt")),
+ };
+ workspace
+ .update(cx, |workspace, cx| {
+ workspace.open_path(b_path, None, true, cx)
+ })
+ .await
+ .unwrap();
+ let finder = open_file_picker(&workspace, cx);
+ finder
+ .update(cx, |f, cx| {
+ f.delegate.spawn_search(test_path_like("a.txt"), cx)
+ })
+ .await;
+
+ finder.update(cx, |f, _| {
+ let delegate = &f.delegate;
+ assert!(
+ delegate.matches.history.is_empty(),
+ "Search matches expected"
+ );
+ let matches = delegate.matches.search.clone();
+ assert_eq!(matches[0].path.as_ref(), Path::new("dir2/a.txt"));
+ assert_eq!(matches[1].path.as_ref(), Path::new("dir1/a.txt"));
+ });
+}
+
+#[gpui::test]
+async fn test_search_worktree_without_files(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/root",
+ json!({
+ "dir1": {},
+ "dir2": {
+ "dir3": {}
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
+ let (picker, _workspace, cx) = build_find_picker(project, cx);
+
+ picker
+ .update(cx, |f, cx| {
+ f.delegate.spawn_search(test_path_like("dir"), cx)
+ })
+ .await;
+ cx.read(|cx| {
+ let finder = picker.read(cx);
+ assert_eq!(finder.delegate.matches.len(), 0);
+ });
+}
+
+#[gpui::test]
+async fn test_query_history(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ "first.rs": "// First Rust file",
+ "second.rs": "// Second Rust file",
+ "third.rs": "// Third Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+ let worktree_id = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
+ assert_eq!(worktrees.len(), 1);
+ WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
+ });
+
+ // Open and close panels, getting their history items afterwards.
+ // Ensure history items get populated with opened items, and items are kept in a certain order.
+ // The history lags one opened buffer behind, since it's updated in the search panel only on its reopen.
+ //
+ // TODO: without closing, the opened items do not propagate their history changes for some reason
+ // it does work in real app though, only tests do not propagate.
+ workspace.update(cx, |_, cx| cx.focused());
+
+ let initial_history = open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+ assert!(
+ initial_history.is_empty(),
+ "Should have no history before opening any files"
+ );
+
+ let history_after_first =
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+ assert_eq!(
+ history_after_first,
+ vec![FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/first.rs")),
+ },
+ Some(PathBuf::from("/src/test/first.rs"))
+ )],
+ "Should show 1st opened item in the history when opening the 2nd item"
+ );
+
+ let history_after_second =
+ open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
+ assert_eq!(
+ history_after_second,
+ vec![
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/second.rs")),
+ },
+ Some(PathBuf::from("/src/test/second.rs"))
+ ),
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/first.rs")),
+ },
+ Some(PathBuf::from("/src/test/first.rs"))
+ ),
+ ],
+ "Should show 1st and 2nd opened items in the history when opening the 3rd item. \
+ 2nd item should be the first in the history, as the last opened."
+ );
+
+ let history_after_third =
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+ assert_eq!(
+ history_after_third,
+ vec![
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/third.rs")),
+ },
+ Some(PathBuf::from("/src/test/third.rs"))
+ ),
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/second.rs")),
+ },
+ Some(PathBuf::from("/src/test/second.rs"))
+ ),
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/first.rs")),
+ },
+ Some(PathBuf::from("/src/test/first.rs"))
+ ),
+ ],
+ "Should show 1st, 2nd and 3rd opened items in the history when opening the 2nd item again. \
+ 3rd item should be the first in the history, as the last opened."
+ );
+
+ let history_after_second_again =
+ open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
+ assert_eq!(
+ history_after_second_again,
+ vec![
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/second.rs")),
+ },
+ Some(PathBuf::from("/src/test/second.rs"))
+ ),
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/third.rs")),
+ },
+ Some(PathBuf::from("/src/test/third.rs"))
+ ),
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/first.rs")),
+ },
+ Some(PathBuf::from("/src/test/first.rs"))
+ ),
+ ],
+ "Should show 1st, 2nd and 3rd opened items in the history when opening the 3rd item again. \
+ 2nd item, as the last opened, 3rd item should go next as it was opened right before."
+ );
+}
+
+#[gpui::test]
+async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ "first.rs": "// First Rust file",
+ "second.rs": "// Second Rust file",
+ }
+ }),
+ )
+ .await;
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/external-src",
+ json!({
+ "test": {
+ "third.rs": "// Third Rust file",
+ "fourth.rs": "// Fourth Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+ cx.update(|cx| {
+ project.update(cx, |project, cx| {
+ project.find_or_create_local_worktree("/external-src", false, cx)
+ })
+ })
+ .detach();
+ cx.background_executor.run_until_parked();
+
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+ let worktree_id = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
+ assert_eq!(worktrees.len(), 1,);
+
+ WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
+ });
+ workspace
+ .update(cx, |workspace, cx| {
+ workspace.open_abs_path(PathBuf::from("/external-src/test/third.rs"), false, cx)
+ })
+ .detach();
+ cx.background_executor.run_until_parked();
+ let external_worktree_id = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
+ assert_eq!(
+ worktrees.len(),
+ 2,
+ "External file should get opened in a new worktree"
+ );
+
+ WorktreeId::from_usize(
+ worktrees
+ .into_iter()
+ .find(|worktree| worktree.entity_id().as_u64() as usize != worktree_id.to_usize())
+ .expect("New worktree should have a different id")
+ .entity_id()
+ .as_u64() as usize,
+ )
+ });
+ cx.dispatch_action(workspace::CloseActiveItem { save_intent: None });
+
+ let initial_history_items =
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+ assert_eq!(
+ initial_history_items,
+ vec![FoundPath::new(
+ ProjectPath {
+ worktree_id: external_worktree_id,
+ path: Arc::from(Path::new("")),
+ },
+ Some(PathBuf::from("/external-src/test/third.rs"))
+ )],
+ "Should show external file with its full path in the history after it was open"
+ );
+
+ let updated_history_items =
+ open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+ assert_eq!(
+ updated_history_items,
+ vec![
+ FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/second.rs")),
+ },
+ Some(PathBuf::from("/src/test/second.rs"))
+ ),
+ FoundPath::new(
+ ProjectPath {
+ worktree_id: external_worktree_id,
+ path: Arc::from(Path::new("")),
+ },
+ Some(PathBuf::from("/external-src/test/third.rs"))
+ ),
+ ],
+ "Should keep external file with history updates",
+ );
+}
+
+#[gpui::test]
+async fn test_toggle_panel_new_selections(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ "first.rs": "// First Rust file",
+ "second.rs": "// Second Rust file",
+ "third.rs": "// Third Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+
+ // generate some history to select from
+ open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+ cx.executor().run_until_parked();
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+ open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
+ let current_history = open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+
+ for expected_selected_index in 0..current_history.len() {
+ cx.dispatch_action(Toggle);
+ let picker = active_file_picker(&workspace, cx);
+ let selected_index = picker.update(cx, |picker, _| picker.delegate.selected_index());
+ assert_eq!(
+ selected_index, expected_selected_index,
+ "Should select the next item in the history"
+ );
+ }
+
+ cx.dispatch_action(Toggle);
+ let selected_index = workspace.update(cx, |workspace, cx| {
+ workspace
+ .active_modal::<FileFinder>(cx)
+ .unwrap()
+ .read(cx)
+ .picker
+ .read(cx)
+ .delegate
+ .selected_index()
+ });
+ assert_eq!(
+ selected_index, 0,
+ "Should wrap around the history and start all over"
+ );
+}
+
+#[gpui::test]
+async fn test_search_preserves_history_items(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ "first.rs": "// First Rust file",
+ "second.rs": "// Second Rust file",
+ "third.rs": "// Third Rust file",
+ "fourth.rs": "// Fourth Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+ let worktree_id = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
+ assert_eq!(worktrees.len(), 1,);
+
+ WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize)
+ });
+
+ // generate some history to select from
+ open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+ open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+
+ let finder = open_file_picker(&workspace, cx);
+ let first_query = "f";
+ finder
+ .update(cx, |finder, cx| {
+ finder.delegate.update_matches(first_query.to_string(), cx)
+ })
+ .await;
+ finder.update(cx, |finder, _| {
+ let delegate = &finder.delegate;
+ assert_eq!(delegate.matches.history.len(), 1, "Only one history item contains {first_query}, it should be present and others should be filtered out");
+ let history_match = delegate.matches.history.first().unwrap();
+ assert!(history_match.1.is_some(), "Should have path matches for history items after querying");
+ assert_eq!(history_match.0, FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/first.rs")),
+ },
+ Some(PathBuf::from("/src/test/first.rs"))
+ ));
+ assert_eq!(delegate.matches.search.len(), 1, "Only one non-history item contains {first_query}, it should be present");
+ assert_eq!(delegate.matches.search.first().unwrap().path.as_ref(), Path::new("test/fourth.rs"));
+ });
+
+ let second_query = "fsdasdsa";
+ let finder = active_file_picker(&workspace, cx);
+ finder
+ .update(cx, |finder, cx| {
+ finder.delegate.update_matches(second_query.to_string(), cx)
+ })
+ .await;
+ finder.update(cx, |finder, _| {
+ let delegate = &finder.delegate;
+ assert!(
+ delegate.matches.history.is_empty(),
+ "No history entries should match {second_query}"
+ );
+ assert!(
+ delegate.matches.search.is_empty(),
+ "No search entries should match {second_query}"
+ );
+ });
+
+ let first_query_again = first_query;
+
+ let finder = active_file_picker(&workspace, cx);
+ finder
+ .update(cx, |finder, cx| {
+ finder
+ .delegate
+ .update_matches(first_query_again.to_string(), cx)
+ })
+ .await;
+ finder.update(cx, |finder, _| {
+ let delegate = &finder.delegate;
+ assert_eq!(delegate.matches.history.len(), 1, "Only one history item contains {first_query_again}, it should be present and others should be filtered out, even after non-matching query");
+ let history_match = delegate.matches.history.first().unwrap();
+ assert!(history_match.1.is_some(), "Should have path matches for history items after querying");
+ assert_eq!(history_match.0, FoundPath::new(
+ ProjectPath {
+ worktree_id,
+ path: Arc::from(Path::new("test/first.rs")),
+ },
+ Some(PathBuf::from("/src/test/first.rs"))
+ ));
+ assert_eq!(delegate.matches.search.len(), 1, "Only one non-history item contains {first_query_again}, it should be present, even after non-matching query");
+ assert_eq!(delegate.matches.search.first().unwrap().path.as_ref(), Path::new("test/fourth.rs"));
+ });
+}
+
+#[gpui::test]
+async fn test_history_items_vs_very_good_external_match(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "collab_ui": {
+ "first.rs": "// First Rust file",
+ "second.rs": "// Second Rust file",
+ "third.rs": "// Third Rust file",
+ "collab_ui.rs": "// Fourth Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+ // generate some history to select from
+ open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+ open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
+ open_close_queried_buffer("sec", 1, "second.rs", &workspace, cx).await;
+
+ let finder = open_file_picker(&workspace, cx);
+ let query = "collab_ui";
+ cx.simulate_input(query);
+ finder.update(cx, |finder, _| {
+ let delegate = &finder.delegate;
+ assert!(
+ delegate.matches.history.is_empty(),
+ "History items should not math query {query}, they should be matched by name only"
+ );
+
+ let search_entries = delegate
+ .matches
+ .search
+ .iter()
+ .map(|path_match| path_match.path.to_path_buf())
+ .collect::<Vec<_>>();
+ assert_eq!(
+ search_entries,
+ vec![
+ PathBuf::from("collab_ui/collab_ui.rs"),
+ PathBuf::from("collab_ui/third.rs"),
+ PathBuf::from("collab_ui/first.rs"),
+ PathBuf::from("collab_ui/second.rs"),
+ ],
+ "Despite all search results having the same directory name, the most matching one should be on top"
+ );
+ });
+}
+
+#[gpui::test]
+async fn test_nonexistent_history_items_not_shown(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ "/src",
+ json!({
+ "test": {
+ "first.rs": "// First Rust file",
+ "nonexistent.rs": "// Second Rust file",
+ "third.rs": "// Third Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); // generate some history to select from
+ open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+ open_close_queried_buffer("non", 1, "nonexistent.rs", &workspace, cx).await;
+ open_close_queried_buffer("thi", 1, "third.rs", &workspace, cx).await;
+ open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
+
+ let picker = open_file_picker(&workspace, cx);
+ cx.simulate_input("rs");
+
+ picker.update(cx, |finder, _| {
+ let history_entries = finder.delegate
+ .matches
+ .history
+ .iter()
+ .map(|(_, path_match)| path_match.as_ref().expect("should have a path match").path.to_path_buf())
+ .collect::<Vec<_>>();
+ assert_eq!(
+ history_entries,
+ vec![
+ PathBuf::from("test/first.rs"),
+ PathBuf::from("test/third.rs"),
+ ],
+ "Should have all opened files in the history, except the ones that do not exist on disk"
+ );
+ });
+}
+
+async fn open_close_queried_buffer(
+ input: &str,
+ expected_matches: usize,
+ expected_editor_title: &str,
+ workspace: &View<Workspace>,
+ cx: &mut gpui::VisualTestContext,
+) -> Vec<FoundPath> {
+ let picker = open_file_picker(&workspace, cx);
+ cx.simulate_input(input);
+
+ let history_items = picker.update(cx, |finder, _| {
+ assert_eq!(
+ finder.delegate.matches.len(),
+ expected_matches,
+ "Unexpected number of matches found for query {input}"
+ );
+ finder.delegate.history_items.clone()
+ });
+
+ cx.dispatch_action(SelectNext);
+ cx.dispatch_action(Confirm);
+
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ let active_editor_title = active_editor.read(cx).title(cx);
+ assert_eq!(
+ expected_editor_title, active_editor_title,
+ "Unexpected editor title for query {input}"
+ );
+ });
+
+ cx.dispatch_action(workspace::CloseActiveItem { save_intent: None });
+
+ history_items
+}
+
+fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {
+ cx.update(|cx| {
+ let state = AppState::test(cx);
+ theme::init(theme::LoadThemes::JustBase, cx);
+ language::init(cx);
+ super::init(cx);
+ editor::init(cx);
+ workspace::init_settings(cx);
+ Project::init_settings(cx);
+ state
+ })
+}
+
+fn test_path_like(test_str: &str) -> PathLikeWithPosition<FileSearchQuery> {
+ PathLikeWithPosition::parse_str(test_str, |path_like_str| {
+ Ok::<_, std::convert::Infallible>(FileSearchQuery {
+ raw_query: test_str.to_owned(),
+ file_query_end: if path_like_str == test_str {
+ None
+ } else {
+ Some(path_like_str.len())
+ },
+ })
+ })
+ .unwrap()
+}
+
+fn build_find_picker(
+ project: Model<Project>,
+ cx: &mut TestAppContext,
+) -> (
+ View<Picker<FileFinderDelegate>>,
+ View<Workspace>,
+ &mut VisualTestContext,
+) {
+ let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
+ let picker = open_file_picker(&workspace, cx);
+ (picker, workspace, cx)
+}
+
+#[track_caller]
+fn open_file_picker(
+ workspace: &View<Workspace>,
+ cx: &mut VisualTestContext,
+) -> View<Picker<FileFinderDelegate>> {
+ cx.dispatch_action(Toggle);
+ active_file_picker(workspace, cx)
+}
+
+#[track_caller]
+fn active_file_picker(
+ workspace: &View<Workspace>,
+ cx: &mut VisualTestContext,
+) -> View<Picker<FileFinderDelegate>> {
+ workspace.update(cx, |workspace, cx| {
+ workspace
+ .active_modal::<FileFinder>(cx)
+ .unwrap()
+ .read(cx)
+ .picker
+ .clone()
+ })
+}
+
+fn collect_search_results(picker: &Picker<FileFinderDelegate>) -> Vec<PathBuf> {
+ let matches = &picker.delegate.matches;
+ assert!(
+ matches.history.is_empty(),
+ "Should have no history matches, but got: {:?}",
+ matches.history
+ );
+ let mut results = matches
+ .search
+ .iter()
+ .map(|path_match| Path::new(path_match.path_prefix.as_ref()).join(&path_match.path))
+ .collect::<Vec<_>>();
+ results.sort();
+ results
+}
@@ -3,6 +3,8 @@ name = "fs"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/fs.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -5,6 +5,7 @@ license = "MIT"
edition = "2021"
publish = false
+
[lib]
path = "src/fsevent.rs"
doctest = false
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "fuzzy"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/fuzzy.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "git"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/git.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "go_to_line"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/go_to_line.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -5,6 +5,8 @@ edition = "2021"
authors = ["Nathan Sobo <nathan@zed.dev>"]
description = "Zed's GPU-accelerated UI framework"
publish = false
+license = "Apache-2.0"
+
[features]
test-support = ["backtrace", "dhat", "env_logger", "collections/test-support", "util/test-support"]
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -0,0 +1,40 @@
+# Welcome to GPUI!
+
+GPUI is a hybrid immediate and retained mode, GPU accelerated, UI framework
+for Rust, designed to support a wide variety of applications.
+
+## Getting Started
+
+GPUI is still in active development as we work on the Zed code editor and isn't yet on crates.io. You'll also need to use the latest version of stable rust and be on macOS. Add the following to your Cargo.toml:
+
+```
+gpui = { git = "https://github.com/zed-industries/zed" }
+```
+
+Everything in GPUI starts with an `App`. You can create one with `App::new()`, and kick off your application by passing a callback to `App::run()`. Inside this callback, you can create a new window with `AppContext::open_window()`, and register your first root view. See [gpui.rs](https://www.gpui.rs/) for a complete example.
+
+## The Big Picture
+
+GPUI offers three different registers(https://en.wikipedia.org/wiki/Register_(sociolinguistics)) depending on your needs:
+
+- State management and communication with Models. Whenever you need to store application state that communicates between different parts of your application, you'll want to use GPUI's models. Models are owned by GPUI and are only accessible through an owned smart pointer similar to an `Rc`. See the `app::model_context` module for more information.
+
+- High level, declarative UI with Views. All UI in GPUI starts with a View. A view is simply a model that can be rendered, via the `Render` trait. At the start of each frame, GPUI will call this render method on the root view of a given window. Views build a tree of `elements`, lay them out and style them with a tailwind-style API, and then give them to GPUI to turn into pixels. See the `div` element for an all purpose swiss-army knife of rendering.
+
+- Low level, imperative UI with Elements. Elements are the building blocks of UI in GPUI, and they provide a nice wrapper around an imperative API that provides as much flexibility and control as you need. Elements have total control over how they and their child elements are rendered and and can be used for making efficient views into large lists, implement custom layouting for a code editor, and anything else you can think of. See the `element` module for more information.
+
+Each of these registers has one or more corresponding contexts that can be accessed from all GPUI services. This context is your main interface to GPUI, and is used extensively throughout the framework.
+
+## Other Resources
+
+In addition to the systems above, GPUI provides a range of smaller services that are useful for building complex applications:
+
+- Actions are user-defined structs that are used for converting keystrokes into logical operations in your UI. Use this for implementing keyboard shortcuts, such as cmd-q. See the `action` module for more information.
+
+- Platform services, such as `quit the app` or `open a URL` are available as methods on the `app::AppContext`.
+
+- An async executor that is integrated with the platform's event loop. See the `executor` module for more information.,
+
+- The `[gpui::test]` macro provides a convenient way to write tests for your GPUI applications. Tests also have their own kind of context, a `TestAppContext` which provides ways of simulating common platform input. See `app::test_context` and `test` modules for more details.
+
+Currently, the best way to learn about these APIs is to read the Zed source code, ask us about it at a fireside hack, or drop a question in the [Zed Discord](https://discord.gg/U4qhCEhMXP). We're working on improving the documentation, creating more examples, and will be publishing more guides to GPUI on our [blog](https://zed.dev/blog).
@@ -25,13 +25,12 @@ use crate::{
use anyhow::{anyhow, Result};
use collections::{FxHashMap, FxHashSet, VecDeque};
use futures::{channel::oneshot, future::LocalBoxFuture, Future};
-use parking_lot::Mutex;
+
use slotmap::SlotMap;
use std::{
any::{type_name, TypeId},
cell::{Ref, RefCell, RefMut},
marker::PhantomData,
- mem,
ops::{Deref, DerefMut},
path::{Path, PathBuf},
rc::{Rc, Weak},
@@ -109,6 +108,7 @@ pub struct App(Rc<AppCell>);
/// configured, you'll start the app with `App::run`.
impl App {
/// Builds an app with the given asset source.
+ #[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(AppContext::new(
current_platform(),
@@ -224,7 +224,7 @@ pub struct AppContext {
pub(crate) entities: EntityMap,
pub(crate) new_view_observers: SubscriberSet<TypeId, NewViewListener>,
pub(crate) windows: SlotMap<WindowId, Option<Window>>,
- pub(crate) keymap: Arc<Mutex<Keymap>>,
+ pub(crate) keymap: Rc<RefCell<Keymap>>,
pub(crate) global_action_listeners:
FxHashMap<TypeId, Vec<Rc<dyn Fn(&dyn Any, DispatchPhase, &mut Self)>>>,
pending_effects: VecDeque<Effect>,
@@ -242,6 +242,7 @@ pub struct AppContext {
}
impl AppContext {
+ #[allow(clippy::new_ret_no_self)]
pub(crate) fn new(
platform: Rc<dyn Platform>,
asset_source: Arc<dyn AssetSource>,
@@ -285,7 +286,7 @@ impl AppContext {
entities,
new_view_observers: SubscriberSet::new(),
windows: SlotMap::with_key(),
- keymap: Arc::new(Mutex::new(Keymap::default())),
+ keymap: Rc::new(RefCell::new(Keymap::default())),
global_action_listeners: FxHashMap::default(),
pending_effects: VecDeque::new(),
pending_notifications: FxHashSet::default(),
@@ -522,17 +523,22 @@ impl AppContext {
}
/// Writes credentials to the platform keychain.
- pub fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Result<()> {
+ pub fn write_credentials(
+ &self,
+ url: &str,
+ username: &str,
+ password: &[u8],
+ ) -> Task<Result<()>> {
self.platform.write_credentials(url, username, password)
}
/// Reads credentials from the platform keychain.
- pub fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>> {
+ pub fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>> {
self.platform.read_credentials(url)
}
/// Deletes credentials from the platform keychain.
- pub fn delete_credentials(&self, url: &str) -> Result<()> {
+ pub fn delete_credentials(&self, url: &str) -> Task<Result<()>> {
self.platform.delete_credentials(url)
}
@@ -763,7 +769,7 @@ impl AppContext {
/// so it can be held across `await` points.
pub fn to_async(&self) -> AsyncAppContext {
AsyncAppContext {
- app: unsafe { mem::transmute(self.this.clone()) },
+ app: self.this.clone(),
background_executor: self.background_executor.clone(),
foreground_executor: self.foreground_executor.clone(),
}
@@ -996,13 +1002,13 @@ impl AppContext {
/// Register key bindings.
pub fn bind_keys(&mut self, bindings: impl IntoIterator<Item = KeyBinding>) {
- self.keymap.lock().add_bindings(bindings);
+ self.keymap.borrow_mut().add_bindings(bindings);
self.pending_effects.push_back(Effect::Refresh);
}
/// Clear all key bindings in the app.
pub fn clear_key_bindings(&mut self) {
- self.keymap.lock().clear();
+ self.keymap.borrow_mut().clear();
self.pending_effects.push_back(Effect::Refresh);
}
@@ -1106,7 +1112,7 @@ impl AppContext {
/// Sets the menu bar for this application. This will replace any existing menu bar.
pub fn set_menus(&mut self, menus: Vec<Menu>) {
- self.platform.set_menus(menus, &self.keymap.lock());
+ self.platform.set_menus(menus, &self.keymap.borrow());
}
/// Dispatch an action to the currently active window or global action handler
@@ -154,6 +154,7 @@ impl AsyncAppContext {
}
/// Reads the global state of the specified type, passing it to the given callback.
+ ///
/// Panics if no global state of the specified type has been assigned.
/// Returns an error if the `AppContext` has been dropped.
pub fn read_global<G: 'static, R>(&self, read: impl FnOnce(&G, &AppContext) -> R) -> Result<R> {
@@ -166,7 +167,10 @@ impl AsyncAppContext {
}
/// Reads the global state of the specified type, passing it to the given callback.
- /// Similar to [read_global], but returns an error instead of panicking if no state of the specified type has been assigned.
+ ///
+ /// Similar to [`AsyncAppContext::read_global`], but returns an error instead of panicking
+ /// if no state of the specified type has been assigned.
+ ///
/// Returns an error if no state of the specified type has been assigned the `AppContext` has been dropped.
pub fn try_read_global<G: 'static, R>(
&self,
@@ -212,12 +216,12 @@ impl AsyncWindowContext {
self.window
}
- /// A convenience method for [WindowContext::update()]
+ /// A convenience method for [`AppContext::update_window`].
pub fn update<R>(&mut self, update: impl FnOnce(&mut WindowContext) -> R) -> Result<R> {
self.app.update_window(self.window, |_, cx| update(cx))
}
- /// A convenience method for [WindowContext::update()]
+ /// A convenience method for [`AppContext::update_window`].
pub fn update_root<R>(
&mut self,
update: impl FnOnce(AnyView, &mut WindowContext) -> R,
@@ -225,12 +229,12 @@ impl AsyncWindowContext {
self.app.update_window(self.window, update)
}
- /// A convenience method for [WindowContext::on_next_frame()]
+ /// A convenience method for [`WindowContext::on_next_frame`].
pub fn on_next_frame(&mut self, f: impl FnOnce(&mut WindowContext) + 'static) {
self.window.update(self, |_, cx| cx.on_next_frame(f)).ok();
}
- /// A convenience method for [AppContext::global()]
+ /// A convenience method for [`AppContext::global`].
pub fn read_global<G: 'static, R>(
&mut self,
read: impl FnOnce(&G, &WindowContext) -> R,
@@ -238,7 +242,7 @@ impl AsyncWindowContext {
self.window.update(self, |_, cx| read(cx.global(), cx))
}
- /// A convenience method for [AppContext::update_global()]
+ /// A convenience method for [`AppContext::update_global`].
/// for updating the global state of the specified type.
pub fn update_global<G, R>(
&mut self,
@@ -242,7 +242,7 @@ impl Clone for AnyModel {
assert_ne!(prev_count, 0, "Detected over-release of a model.");
}
- let this = Self {
+ Self {
entity_id: self.entity_id,
entity_type: self.entity_type,
entity_map: self.entity_map.clone(),
@@ -254,8 +254,7 @@ impl Clone for AnyModel {
.write()
.leak_detector
.handle_created(self.entity_id),
- };
- this
+ }
}
}
@@ -42,7 +42,8 @@ impl<'a, T: 'static> ModelContext<'a, T> {
self.model_state.clone()
}
- /// Arranges for the given function to be called whenever [ModelContext::notify] or [ViewContext::notify] is called with the given model or view.
+ /// Arranges for the given function to be called whenever [`ModelContext::notify`] or
+ /// [`ViewContext::notify`](crate::ViewContext::notify) is called with the given model or view.
pub fn observe<W, E>(
&mut self,
entity: &E,
@@ -150,7 +151,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
}
/// Arrange for the given function to be invoked whenever the application is quit.
- /// The future returned from this callback will be polled for up to [gpui::SHUTDOWN_TIMEOUT] until the app fully quits.
+ /// The future returned from this callback will be polled for up to [crate::SHUTDOWN_TIMEOUT] until the app fully quits.
pub fn on_app_quit<Fut>(
&mut self,
mut on_quit: impl FnMut(&mut T, &mut ModelContext<T>) -> Fut + 'static,
@@ -7,7 +7,7 @@ use crate::{
};
use anyhow::{anyhow, bail};
use futures::{Stream, StreamExt};
-use std::{future::Future, ops::Deref, rc::Rc, sync::Arc, time::Duration};
+use std::{cell::RefCell, future::Future, ops::Deref, rc::Rc, sync::Arc, time::Duration};
/// A TestAppContext is provided to tests created with `#[gpui::test]`, it provides
/// an implementation of `Context` with additional methods that are useful in tests.
@@ -24,6 +24,7 @@ pub struct TestAppContext {
test_platform: Rc<TestPlatform>,
text_system: Arc<TextSystem>,
fn_name: Option<&'static str>,
+ on_quit: Rc<RefCell<Vec<Box<dyn FnOnce() + 'static>>>>,
}
impl Context for TestAppContext {
@@ -101,6 +102,7 @@ impl TestAppContext {
test_platform: platform,
text_system,
fn_name,
+ on_quit: Rc::new(RefCell::new(Vec::default())),
}
}
@@ -119,11 +121,18 @@ impl TestAppContext {
Self::new(self.dispatcher.clone(), self.fn_name)
}
- /// Simulates quitting the app.
+ /// Called by the test helper to end the test.
+ /// public so the macro can call it.
pub fn quit(&self) {
+ self.on_quit.borrow_mut().drain(..).for_each(|f| f());
self.app.borrow_mut().shutdown();
}
+ /// Register cleanup to run when the test ends.
+ pub fn on_quit(&mut self, f: impl FnOnce() + 'static) {
+ self.on_quit.borrow_mut().push(Box::new(f));
+ }
+
/// Schedules all windows to be redrawn on the next effect cycle.
pub fn refresh(&mut self) -> Result<()> {
let mut app = self.app.borrow_mut();
@@ -169,10 +178,9 @@ impl TestAppContext {
let mut cx = self.app.borrow_mut();
let window = cx.open_window(WindowOptions::default(), |cx| cx.new_view(|_| ()));
drop(cx);
- let cx = Box::new(VisualTestContext::from_window(*window.deref(), self));
+ let cx = VisualTestContext::from_window(*window.deref(), self).as_mut();
cx.run_until_parked();
- // it might be nice to try and cleanup these at the end of each test.
- Box::leak(cx)
+ cx
}
/// Adds a new window, and returns its root view and a `VisualTestContext` which can be used
@@ -187,10 +195,11 @@ impl TestAppContext {
let window = cx.open_window(WindowOptions::default(), |cx| cx.new_view(build_window));
drop(cx);
let view = window.root_view(self).unwrap();
- let cx = Box::new(VisualTestContext::from_window(*window.deref(), self));
+ let cx = VisualTestContext::from_window(*window.deref(), self).as_mut();
cx.run_until_parked();
+
// it might be nice to try and cleanup these at the end of each test.
- (view, Box::leak(cx))
+ (view, cx)
}
/// returns the TextSystem
@@ -695,6 +704,20 @@ impl<'a> VisualTestContext {
false
}
}
+
+ /// Get an &mut VisualTestContext (which is mostly what you need to pass to other methods).
+ /// This method internally retains the VisualTestContext until the end of the test.
+ pub fn as_mut(self) -> &'static mut Self {
+ let ptr = Box::into_raw(Box::new(self));
+ // safety: on_quit will be called after the test has finished.
+ // the executor will ensure that all tasks related to the test have stopped.
+ // so there is no way for cx to be accessed after on_quit is called.
+ let cx = Box::leak(unsafe { Box::from_raw(ptr) });
+ cx.on_quit(move || unsafe {
+ drop(Box::from_raw(ptr));
+ });
+ cx
+ }
}
impl Context for VisualTestContext {
@@ -44,6 +44,14 @@ impl Arena {
}
}
+ pub fn len(&self) -> usize {
+ self.offset as usize - self.start as usize
+ }
+
+ pub fn capacity(&self) -> usize {
+ self.end as usize - self.start as usize
+ }
+
pub fn clear(&mut self) {
self.valid.set(false);
self.valid = Rc::new(Cell::new(true));
@@ -3,11 +3,11 @@ use serde::de::{self, Deserialize, Deserializer, Visitor};
use std::fmt;
/// Convert an RGB hex color code number to a color type
-pub fn rgb<C: From<Rgba>>(hex: u32) -> C {
+pub fn rgb(hex: u32) -> Rgba {
let r = ((hex >> 16) & 0xFF) as f32 / 255.0;
let g = ((hex >> 8) & 0xFF) as f32 / 255.0;
let b = (hex & 0xFF) as f32 / 255.0;
- Rgba { r, g, b, a: 1.0 }.into()
+ Rgba { r, g, b, a: 1.0 }
}
/// Convert an RGBA hex color code number to [`Rgba`]
@@ -40,7 +40,6 @@ impl fmt::Debug for Rgba {
impl Rgba {
/// Create a new [`Rgba`] color by blending this and another color together
- /// TODO!(docs): find the source for this algorithm
pub fn blend(&self, other: Rgba) -> Self {
if other.a >= 1.0 {
other
@@ -203,20 +202,16 @@ impl PartialEq for Hsla {
impl PartialOrd for Hsla {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- // SAFETY: The total ordering relies on this always being Some()
- Some(
- self.h
- .total_cmp(&other.h)
- .then(self.s.total_cmp(&other.s))
- .then(self.l.total_cmp(&other.l).then(self.a.total_cmp(&other.a))),
- )
+ Some(self.cmp(other))
}
}
impl Ord for Hsla {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
- // SAFETY: The partial comparison is a total comparison
- unsafe { self.partial_cmp(other).unwrap_unchecked() }
+ self.h
+ .total_cmp(&other.h)
+ .then(self.s.total_cmp(&other.s))
+ .then(self.l.total_cmp(&other.l).then(self.a.total_cmp(&other.a)))
}
}
@@ -133,8 +133,25 @@ pub trait Render: 'static + Sized {
}
impl Render for () {
- fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
- ()
+ fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {}
+}
+
+/// A quick way to create a [`Render`]able view without having to define a new type.
+#[cfg(any(test, feature = "test-support"))]
+pub struct TestView(Box<dyn FnMut(&mut ViewContext<TestView>) -> AnyElement>);
+
+#[cfg(any(test, feature = "test-support"))]
+impl TestView {
+ /// Construct a TestView from a render closure.
+ pub fn new<F: FnMut(&mut ViewContext<TestView>) -> AnyElement + 'static>(f: F) -> Self {
+ Self(Box::new(f))
+ }
+}
+
+#[cfg(any(test, feature = "test-support"))]
+impl Render for TestView {
+ fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
+ (self.0)(cx)
}
}
@@ -1,7 +1,7 @@
//! Div is the central, reusable element that most GPUI trees will be built from.
//! It functions as a container for other elements, and provides a number of
//! useful features for laying out and styling its children as well as binding
-//! mouse events and action handlers. It is meant to be similar to the HTML <div>
+//! mouse events and action handlers. It is meant to be similar to the HTML `<div>`
//! element, but for GPUI.
//!
//! # Build your own div
@@ -14,13 +14,6 @@
//! as several associated traits. Together, these provide the full suite of Dom-like events
//! and Tailwind-like styling that you can use to build your own custom elements. Div is
//! constructed by combining these two systems into an all-in-one element.
-//!
-//! # Capturing and bubbling
-//!
-//! Note that while event dispatch in GPUI uses similar names and concepts to the web
-//! even API, the details are very different. See the documentation in [TODO!(docs)
-//! DOCUMENT EVENT DISPATCH SOMEWHERE IN WINDOW CONTEXT] for more details
-//!
use crate::{
point, px, size, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, Bounds,
@@ -85,7 +78,7 @@ impl Interactivity {
/// Bind the given callback to the mouse down event for the given mouse button, during the bubble phase
/// The imperative API equivalent of [`InteractiveElement::on_mouse_down`]
///
- /// See [`ViewContext::listener()`] to get access to the view state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to the view state from this callback.
pub fn on_mouse_down(
&mut self,
button: MouseButton,
@@ -105,7 +98,7 @@ impl Interactivity {
/// Bind the given callback to the mouse down event for any button, during the capture phase
/// The imperative API equivalent of [`InteractiveElement::capture_any_mouse_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn capture_any_mouse_down(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -119,9 +112,9 @@ impl Interactivity {
}
/// Bind the given callback to the mouse down event for any button, during the bubble phase
- /// the imperative API equivalent to [`InteractiveElement::on_any_mouse_down()`]
+ /// the imperative API equivalent to [`InteractiveElement::on_any_mouse_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_any_mouse_down(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -135,9 +128,9 @@ impl Interactivity {
}
/// Bind the given callback to the mouse up event for the given button, during the bubble phase
- /// the imperative API equivalent to [`InteractiveElement::on_mouse_up()`]
+ /// the imperative API equivalent to [`InteractiveElement::on_mouse_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_mouse_up(
&mut self,
button: MouseButton,
@@ -155,9 +148,9 @@ impl Interactivity {
}
/// Bind the given callback to the mouse up event for any button, during the capture phase
- /// the imperative API equivalent to [`InteractiveElement::capture_any_mouse_up()`]
+ /// the imperative API equivalent to [`InteractiveElement::capture_any_mouse_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn capture_any_mouse_up(
&mut self,
listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,
@@ -171,9 +164,9 @@ impl Interactivity {
}
/// Bind the given callback to the mouse up event for any button, during the bubble phase
- /// the imperative API equivalent to [`InteractiveElement::on_any_mouse_up()`]
+ /// the imperative API equivalent to [`Interactivity::on_any_mouse_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_any_mouse_up(
&mut self,
listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,
@@ -188,9 +181,9 @@ impl Interactivity {
/// Bind the given callback to the mouse down event, on any button, during the capture phase,
/// when the mouse is outside of the bounds of this element.
- /// The imperative API equivalent to [`InteractiveElement::on_mouse_down_out()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_mouse_down_out`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_mouse_down_out(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -206,9 +199,9 @@ impl Interactivity {
/// Bind the given callback to the mouse up event, for the given button, during the capture phase,
/// when the mouse is outside of the bounds of this element.
- /// The imperative API equivalent to [`InteractiveElement::on_mouse_up_out()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_mouse_up_out`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_mouse_up_out(
&mut self,
button: MouseButton,
@@ -226,9 +219,9 @@ impl Interactivity {
}
/// Bind the given callback to the mouse move event, during the bubble phase
- /// The imperative API equivalent to [`InteractiveElement::on_mouse_move()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_mouse_move`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_mouse_move(
&mut self,
listener: impl Fn(&MouseMoveEvent, &mut WindowContext) + 'static,
@@ -245,9 +238,9 @@ impl Interactivity {
/// will be called for all move events, inside or outside of this element, as long as the
/// drag was started with this element under the mouse. Useful for implementing draggable
/// UIs that don't conform to a drag and drop style interaction, like resizing.
- /// The imperative API equivalent to [`InteractiveElement::on_drag_move()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_drag_move`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_drag_move<T>(
&mut self,
listener: impl Fn(&DragMoveEvent<T>, &mut WindowContext) + 'static,
@@ -275,9 +268,9 @@ impl Interactivity {
}
/// Bind the given callback to scroll wheel events during the bubble phase
- /// The imperative API equivalent to [`InteractiveElement::on_scroll_wheel()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_scroll_wheel`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_scroll_wheel(
&mut self,
listener: impl Fn(&ScrollWheelEvent, &mut WindowContext) + 'static,
@@ -291,9 +284,9 @@ impl Interactivity {
}
/// Bind the given callback to an action dispatch during the capture phase
- /// The imperative API equivalent to [`InteractiveElement::capture_action()`]
+ /// The imperative API equivalent to [`InteractiveElement::capture_action`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn capture_action<A: Action>(
&mut self,
listener: impl Fn(&A, &mut WindowContext) + 'static,
@@ -310,9 +303,9 @@ impl Interactivity {
}
/// Bind the given callback to an action dispatch during the bubble phase
- /// The imperative API equivalent to [`InteractiveElement::on_action()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_action`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_action<A: Action>(&mut self, listener: impl Fn(&A, &mut WindowContext) + 'static) {
self.action_listeners.push((
TypeId::of::<A>(),
@@ -328,9 +321,9 @@ impl Interactivity {
/// Bind the given callback to an action dispatch, based on a dynamic action parameter
/// instead of a type parameter. Useful for component libraries that want to expose
/// action bindings to their users.
- /// The imperative API equivalent to [`InteractiveElement::on_boxed_action()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_boxed_action`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_boxed_action(
&mut self,
action: &dyn Action,
@@ -348,9 +341,9 @@ impl Interactivity {
}
/// Bind the given callback to key down events during the bubble phase
- /// The imperative API equivalent to [`InteractiveElement::on_key_down()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_key_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_key_down(&mut self, listener: impl Fn(&KeyDownEvent, &mut WindowContext) + 'static) {
self.key_down_listeners
.push(Box::new(move |event, phase, cx| {
@@ -361,9 +354,9 @@ impl Interactivity {
}
/// Bind the given callback to key down events during the capture phase
- /// The imperative API equivalent to [`InteractiveElement::capture_key_down()`]
+ /// The imperative API equivalent to [`InteractiveElement::capture_key_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn capture_key_down(
&mut self,
listener: impl Fn(&KeyDownEvent, &mut WindowContext) + 'static,
@@ -377,9 +370,9 @@ impl Interactivity {
}
/// Bind the given callback to key up events during the bubble phase
- /// The imperative API equivalent to [`InteractiveElement::on_key_up()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_key_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_key_up(&mut self, listener: impl Fn(&KeyUpEvent, &mut WindowContext) + 'static) {
self.key_up_listeners
.push(Box::new(move |event, phase, cx| {
@@ -390,9 +383,9 @@ impl Interactivity {
}
/// Bind the given callback to key up events during the capture phase
- /// The imperative API equivalent to [`InteractiveElement::on_key_up()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_key_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn capture_key_up(&mut self, listener: impl Fn(&KeyUpEvent, &mut WindowContext) + 'static) {
self.key_up_listeners
.push(Box::new(move |event, phase, cx| {
@@ -403,9 +396,9 @@ impl Interactivity {
}
/// Bind the given callback to drop events of the given type, whether or not the drag started on this element
- /// The imperative API equivalent to [`InteractiveElement::on_drop()`]
+ /// The imperative API equivalent to [`InteractiveElement::on_drop`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_drop<T: 'static>(&mut self, listener: impl Fn(&T, &mut WindowContext) + 'static) {
self.drop_listeners.push((
TypeId::of::<T>(),
@@ -416,15 +409,15 @@ impl Interactivity {
}
/// Use the given predicate to determine whether or not a drop event should be dispatched to this element
- /// The imperative API equivalent to [`InteractiveElement::can_drop()`]
+ /// The imperative API equivalent to [`InteractiveElement::can_drop`]
pub fn can_drop(&mut self, predicate: impl Fn(&dyn Any, &mut WindowContext) -> bool + 'static) {
self.can_drop_predicate = Some(Box::new(predicate));
}
/// Bind the given callback to click events of this element
- /// The imperative API equivalent to [`InteractiveElement::on_click()`]
+ /// The imperative API equivalent to [`StatefulInteractiveElement::on_click`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_click(&mut self, listener: impl Fn(&ClickEvent, &mut WindowContext) + 'static)
where
Self: Sized,
@@ -435,10 +428,10 @@ impl Interactivity {
/// 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 imperative API equivalent to [`InteractiveElement::on_drag()`]
+ /// the [`Self::on_drag_move`] API
+ /// The imperative API equivalent to [`StatefulInteractiveElement::on_drag`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_drag<T, W>(
&mut self,
value: T,
@@ -460,9 +453,9 @@ impl Interactivity {
/// Bind the given callback on the hover start and end events of this element. Note that the boolean
/// passed to the callback is true when the hover starts and false when it ends.
- /// The imperative API equivalent to [`InteractiveElement::on_drag()`]
+ /// The imperative API equivalent to [`StatefulInteractiveElement::on_drag`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
pub fn on_hover(&mut self, listener: impl Fn(&bool, &mut WindowContext) + 'static)
where
Self: Sized,
@@ -475,7 +468,7 @@ impl Interactivity {
}
/// Use the given callback to construct a new tooltip view when the mouse hovers over this element.
- /// The imperative API equivalent to [`InteractiveElement::tooltip()`]
+ /// The imperative API equivalent to [`InteractiveElement::tooltip`]
pub fn tooltip(&mut self, build_tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static)
where
Self: Sized,
@@ -488,7 +481,7 @@ impl Interactivity {
}
/// Block the mouse from interacting with this element or any of it's children
- /// The imperative API equivalent to [`InteractiveElement::block_mouse()`]
+ /// The imperative API equivalent to [`InteractiveElement::block_mouse`]
pub fn block_mouse(&mut self) {
self.block_mouse = true;
}
@@ -559,9 +552,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to the mouse down event for the given mouse button,
- /// the fluent API equivalent to [`Interactivity::on_mouse_down()`]
+ /// the fluent API equivalent to [`Interactivity::on_mouse_down`]
///
- /// See [`ViewContext::listener()`] to get access to the view state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to the view state from this callback.
fn on_mouse_down(
mut self,
button: MouseButton,
@@ -573,7 +566,7 @@ pub trait InteractiveElement: Sized {
#[cfg(any(test, feature = "test-support"))]
/// Set a key that can be used to look up this element's bounds
- /// in the [`VisualTestContext::debug_bounds()`] map
+ /// in the [`VisualTestContext::debug_bounds`] map
/// This is a noop in release builds
fn debug_selector(mut self, f: impl FnOnce() -> String) -> Self {
self.interactivity().debug_selector = Some(f());
@@ -582,7 +575,7 @@ pub trait InteractiveElement: Sized {
#[cfg(not(any(test, feature = "test-support")))]
/// Set a key that can be used to look up this element's bounds
- /// in the [`VisualTestContext::debug_bounds()`] map
+ /// in the [`VisualTestContext::debug_bounds`] map
/// This is a noop in release builds
#[inline]
fn debug_selector(self, _: impl FnOnce() -> String) -> Self {
@@ -590,9 +583,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to the mouse down event for any button, during the capture phase
- /// the fluent API equivalent to [`Interactivity::capture_any_mouse_down()`]
+ /// the fluent API equivalent to [`Interactivity::capture_any_mouse_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn capture_any_mouse_down(
mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -602,9 +595,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to the mouse down event for any button, during the capture phase
- /// the fluent API equivalent to [`Interactivity::on_any_mouse_down()`]
+ /// the fluent API equivalent to [`Interactivity::on_any_mouse_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_any_mouse_down(
mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -614,9 +607,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to the mouse up event for the given button, during the bubble phase
- /// the fluent API equivalent to [`Interactivity::on_mouse_up()`]
+ /// the fluent API equivalent to [`Interactivity::on_mouse_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_mouse_up(
mut self,
button: MouseButton,
@@ -627,9 +620,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to the mouse up event for any button, during the capture phase
- /// the fluent API equivalent to [`Interactivity::capture_any_mouse_up()`]
+ /// the fluent API equivalent to [`Interactivity::capture_any_mouse_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn capture_any_mouse_up(
mut self,
listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,
@@ -640,9 +633,9 @@ pub trait InteractiveElement: Sized {
/// Bind the given callback to the mouse down event, on any button, during the capture phase,
/// when the mouse is outside of the bounds of this element.
- /// The fluent API equivalent to [`Interactivity::on_mouse_down_out()`]
+ /// The fluent API equivalent to [`Interactivity::on_mouse_down_out`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_mouse_down_out(
mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -653,9 +646,9 @@ pub trait InteractiveElement: Sized {
/// Bind the given callback to the mouse up event, for the given button, during the capture phase,
/// when the mouse is outside of the bounds of this element.
- /// The fluent API equivalent to [`Interactivity::on_mouse_up_out()`]
+ /// The fluent API equivalent to [`Interactivity::on_mouse_up_out`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_mouse_up_out(
mut self,
button: MouseButton,
@@ -666,9 +659,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to the mouse move event, during the bubble phase
- /// The fluent API equivalent to [`Interactivity::on_mouse_move()`]
+ /// The fluent API equivalent to [`Interactivity::on_mouse_move`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_mouse_move(
mut self,
listener: impl Fn(&MouseMoveEvent, &mut WindowContext) + 'static,
@@ -681,9 +674,9 @@ pub trait InteractiveElement: Sized {
/// will be called for all move events, inside or outside of this element, as long as the
/// drag was started with this element under the mouse. Useful for implementing draggable
/// UIs that don't conform to a drag and drop style interaction, like resizing.
- /// The fluent API equivalent to [`Interactivity::on_drag_move()`]
+ /// The fluent API equivalent to [`Interactivity::on_drag_move`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_drag_move<T: 'static>(
mut self,
listener: impl Fn(&DragMoveEvent<T>, &mut WindowContext) + 'static,
@@ -696,9 +689,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to scroll wheel events during the bubble phase
- /// The fluent API equivalent to [`Interactivity::on_scroll_wheel()`]
+ /// The fluent API equivalent to [`Interactivity::on_scroll_wheel`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_scroll_wheel(
mut self,
listener: impl Fn(&ScrollWheelEvent, &mut WindowContext) + 'static,
@@ -708,9 +701,9 @@ pub trait InteractiveElement: Sized {
}
/// Capture the given action, before normal action dispatch can fire
- /// The fluent API equivalent to [`Interactivity::on_scroll_wheel()`]
+ /// The fluent API equivalent to [`Interactivity::on_scroll_wheel`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn capture_action<A: Action>(
mut self,
listener: impl Fn(&A, &mut WindowContext) + 'static,
@@ -720,9 +713,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to an action dispatch during the bubble phase
- /// The fluent API equivalent to [`Interactivity::on_action()`]
+ /// The fluent API equivalent to [`Interactivity::on_action`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_action<A: Action>(mut self, listener: impl Fn(&A, &mut WindowContext) + 'static) -> Self {
self.interactivity().on_action(listener);
self
@@ -731,9 +724,9 @@ pub trait InteractiveElement: Sized {
/// Bind the given callback to an action dispatch, based on a dynamic action parameter
/// instead of a type parameter. Useful for component libraries that want to expose
/// action bindings to their users.
- /// The fluent API equivalent to [`Interactivity::on_boxed_action()`]
+ /// The fluent API equivalent to [`Interactivity::on_boxed_action`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_boxed_action(
mut self,
action: &dyn Action,
@@ -744,9 +737,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to key down events during the bubble phase
- /// The fluent API equivalent to [`Interactivity::on_key_down()`]
+ /// The fluent API equivalent to [`Interactivity::on_key_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_key_down(
mut self,
listener: impl Fn(&KeyDownEvent, &mut WindowContext) + 'static,
@@ -756,9 +749,9 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to key down events during the capture phase
- /// The fluent API equivalent to [`Interactivity::capture_key_down()`]
+ /// The fluent API equivalent to [`Interactivity::capture_key_down`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn capture_key_down(
mut self,
listener: impl Fn(&KeyDownEvent, &mut WindowContext) + 'static,
@@ -768,18 +761,18 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to key up events during the bubble phase
- /// The fluent API equivalent to [`Interactivity::on_key_up()`]
+ /// The fluent API equivalent to [`Interactivity::on_key_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_key_up(mut self, listener: impl Fn(&KeyUpEvent, &mut WindowContext) + 'static) -> Self {
self.interactivity().on_key_up(listener);
self
}
/// Bind the given callback to key up events during the capture phase
- /// The fluent API equivalent to [`Interactivity::capture_key_up()`]
+ /// The fluent API equivalent to [`Interactivity::capture_key_up`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn capture_key_up(
mut self,
listener: impl Fn(&KeyUpEvent, &mut WindowContext) + 'static,
@@ -813,16 +806,16 @@ pub trait InteractiveElement: Sized {
}
/// Bind the given callback to drop events of the given type, whether or not the drag started on this element
- /// The fluent API equivalent to [`Interactivity::on_drop()`]
+ /// The fluent API equivalent to [`Interactivity::on_drop`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_drop<T: 'static>(mut self, listener: impl Fn(&T, &mut WindowContext) + 'static) -> Self {
self.interactivity().on_drop(listener);
self
}
/// Use the given predicate to determine whether or not a drop event should be dispatched to this element
- /// The fluent API equivalent to [`Interactivity::can_drop()`]
+ /// The fluent API equivalent to [`Interactivity::can_drop`]
fn can_drop(
mut self,
predicate: impl Fn(&dyn Any, &mut WindowContext) -> bool + 'static,
@@ -832,7 +825,7 @@ pub trait InteractiveElement: Sized {
}
/// Block the mouse from interacting with this element or any of it's children
- /// The fluent API equivalent to [`Interactivity::block_mouse()`]
+ /// The fluent API equivalent to [`Interactivity::block_mouse`]
fn block_mouse(mut self) -> Self {
self.interactivity().block_mouse();
self
@@ -899,9 +892,9 @@ pub trait StatefulInteractiveElement: InteractiveElement {
}
/// Bind the given callback to click events of this element
- /// The fluent API equivalent to [`Interactivity::on_click()`]
+ /// The fluent API equivalent to [`Interactivity::on_click`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_click(mut self, listener: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self
where
Self: Sized,
@@ -912,10 +905,10 @@ 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 fluent API equivalent to [`Interactivity::on_drag()`]
+ /// the [`Self::on_drag_move`] API
+ /// The fluent API equivalent to [`Interactivity::on_drag`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// 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,
@@ -932,9 +925,9 @@ pub trait StatefulInteractiveElement: InteractiveElement {
/// Bind the given callback on the hover start and end events of this element. Note that the boolean
/// passed to the callback is true when the hover starts and false when it ends.
- /// The fluent API equivalent to [`Interactivity::on_hover()`]
+ /// The fluent API equivalent to [`Interactivity::on_hover`]
///
- /// See [`ViewContext::listener()`] to get access to a view's state from this callback
+ /// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
fn on_hover(mut self, listener: impl Fn(&bool, &mut WindowContext) + 'static) -> Self
where
Self: Sized,
@@ -944,7 +937,7 @@ pub trait StatefulInteractiveElement: InteractiveElement {
}
/// Use the given callback to construct a new tooltip view when the mouse hovers over this element.
- /// The fluent API equivalent to [`Interactivity::tooltip()`]
+ /// The fluent API equivalent to [`Interactivity::tooltip`]
fn tooltip(mut self, build_tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self
where
Self: Sized,
@@ -1008,10 +1001,9 @@ pub(crate) type ActionListener = Box<dyn Fn(&dyn Any, DispatchPhase, &mut Window
#[track_caller]
pub fn div() -> Div {
#[cfg(debug_assertions)]
- let interactivity = {
- let mut interactivity = Interactivity::default();
- interactivity.location = Some(*core::panic::Location::caller());
- interactivity
+ let interactivity = Interactivity {
+ location: Some(*core::panic::Location::caller()),
+ ..Default::default()
};
#[cfg(not(debug_assertions))]
@@ -104,7 +104,7 @@ impl Element for Img {
cx.with_z_index(1, |cx| {
match source {
ImageSource::Uri(uri) => {
- let image_future = cx.image_cache.get(uri.clone());
+ let image_future = cx.image_cache.get(uri.clone(), cx);
if let Some(data) = image_future
.clone()
.now_or_never()
@@ -222,7 +222,7 @@ impl OverlayPositionMode {
) -> (Point<Pixels>, Bounds<Pixels>) {
match self {
OverlayPositionMode::Window => {
- let anchor_position = anchor_position.unwrap_or_else(|| bounds.origin);
+ let anchor_position = anchor_position.unwrap_or(bounds.origin);
let bounds = anchor_corner.get_bounds(anchor_position, size);
(anchor_position, bounds)
}
@@ -46,6 +46,18 @@ impl IntoElement for &'static str {
}
}
+impl IntoElement for String {
+ type Element = SharedString;
+
+ fn element_id(&self) -> Option<ElementId> {
+ None
+ }
+
+ fn into_element(self) -> Self::Element {
+ self.into()
+ }
+}
+
impl Element for SharedString {
type State = TextState;
@@ -181,7 +181,7 @@ impl Element for UniformList {
let shared_scroll_offset = element_state
.interactive
.scroll_offset
- .get_or_insert_with(|| Rc::default())
+ .get_or_insert_with(Rc::default)
.clone();
let item_height = self.measure_item(Some(padded_bounds.size.width), cx).height;
@@ -1,3 +1,7 @@
+//! The GPUI geometry module is a collection of types and traits that
+//! can be used to describe common units, concepts, and the relationships
+//! between them.
+
use core::fmt::Debug;
use derive_more::{Add, AddAssign, Div, DivAssign, Mul, Neg, Sub, SubAssign};
use refineable::Refineable;
@@ -8,13 +12,17 @@ use std::{
ops::{Add, Div, Mul, MulAssign, Sub},
};
+/// An axis along which a measurement can be made.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Axis {
+ /// The y axis, or up and down
Vertical,
+ /// The x axis, or left and right
Horizontal,
}
impl Axis {
+ /// Swap this axis to the opposite axis.
pub fn invert(&self) -> Self {
match self {
Axis::Vertical => Axis::Horizontal,
@@ -23,11 +31,15 @@ impl Axis {
}
}
+/// A trait for accessing the given unit along a certain axis.
pub trait Along {
+ /// The unit associated with this type
type Unit;
+ /// Returns the unit along the given axis.
fn along(&self, axis: Axis) -> Self::Unit;
+ /// Applies the given function to the unit along the given axis and returns a new value.
fn apply_along(&self, axis: Axis, f: impl FnOnce(Self::Unit) -> Self::Unit) -> Self;
}
@@ -47,7 +59,9 @@ pub trait Along {
#[refineable(Debug)]
#[repr(C)]
pub struct Point<T: Default + Clone + Debug> {
+ /// The x coordinate of the point.
pub x: T,
+ /// The y coordinate of the point.
pub y: T,
}
@@ -334,7 +348,9 @@ impl<T: Clone + Default + Debug> Clone for Point<T> {
#[refineable(Debug)]
#[repr(C)]
pub struct Size<T: Clone + Default + Debug> {
+ /// The width component of the size.
pub width: T,
+ /// The height component of the size.
pub height: T,
}
@@ -640,7 +656,9 @@ impl Size<Length> {
#[refineable(Debug)]
#[repr(C)]
pub struct Bounds<T: Clone + Default + Debug> {
+ /// The origin point of this area.
pub origin: Point<T>,
+ /// The size of the rectangle.
pub size: Size<T>,
}
@@ -1192,9 +1210,13 @@ impl<T: Clone + Debug + Copy + Default> Copy for Bounds<T> {}
#[refineable(Debug)]
#[repr(C)]
pub struct Edges<T: Clone + Default + Debug> {
+ /// The size of the top edge.
pub top: T,
+ /// The size of the right edge.
pub right: T,
+ /// The size of the bottom edge.
pub bottom: T,
+ /// The size of the left edge.
pub left: T,
}
@@ -1600,9 +1622,13 @@ impl From<f32> for Edges<Pixels> {
#[refineable(Debug)]
#[repr(C)]
pub struct Corners<T: Clone + Default + Debug> {
+ /// The value associated with the top left corner.
pub top_left: T,
+ /// The value associated with the top right corner.
pub top_right: T,
+ /// The value associated with the bottom right corner.
pub bottom_right: T,
+ /// The value associated with the bottom left corner.
pub bottom_left: T,
}
@@ -2020,13 +2046,13 @@ impl Eq for Pixels {}
impl PartialOrd for Pixels {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
- self.0.partial_cmp(&other.0)
+ Some(self.cmp(other))
}
}
impl Ord for Pixels {
fn cmp(&self, other: &Self) -> cmp::Ordering {
- self.partial_cmp(other).unwrap()
+ self.0.total_cmp(&other.0)
}
}
@@ -1,30 +1,67 @@
//! # Welcome to GPUI!
//!
//! GPUI is a hybrid immediate and retained mode, GPU accelerated, UI framework
-//! for Rust, designed to support a wide variety of applications. GPUI is currently
-//! being actively developed and improved for the [Zed code editor](https://zed.dev/), and new versions
-//! will have breaking changes. You'll probably need to use the latest stable version
-//! of rust to use GPUI.
+//! for Rust, designed to support a wide variety of applications.
//!
-//! # Getting started with GPUI
+//! ## Getting Started
//!
-//! TODO!(docs): Write a code sample showing how to create a window and render a simple
-//! div
+//! GPUI is still in active development as we work on the Zed code editor and isn't yet on crates.io.
+//! You'll also need to use the latest version of stable rust and be on macOS. Add the following to your
+//! Cargo.toml:
//!
-//! # Drawing interesting things
+//! ```
+//! gpui = { git = "https://github.com/zed-industries/zed" }
+//! ```
//!
-//! TODO!(docs): Expand demo to show how to draw a more interesting scene, with
-//! a counter to store state and a button to increment it.
+//! Everything in GPUI starts with an [`App`]. You can create one with [`App::new`], and
+//! kick off your application by passing a callback to [`App::run`]. Inside this callback,
+//! you can create a new window with [`AppContext::open_window`], and register your first root
+//! view. See [gpui.rs](https://www.gpui.rs/) for a complete example.
//!
-//! # Interacting with your application state
+//! ## The Big Picture
//!
-//! TODO!(docs): Expand demo to show GPUI entity interactions, like subscriptions and entities
-//! maybe make a network request to show async stuff?
+//! GPUI offers three different [registers](https://en.wikipedia.org/wiki/Register_(sociolinguistics)) depending on your needs:
//!
-//! # Conclusion
+//! - State management and communication with Models. Whenever you need to store application state
+//! that communicates between different parts of your application, you'll want to use GPUI's
+//! models. Models are owned by GPUI and are only accessible through an owned smart pointer
+//! similar to an [`Rc`]. See the [`app::model_context`] module for more information.
//!
-//! TODO!(docs): Wrap up with a conclusion and links to other places? Zed / GPUI website?
-//! Discord for chatting about it? Other tutorials or references?
+//! - High level, declarative UI with Views. All UI in GPUI starts with a View. A view is simply
+//! a model that can be rendered, via the [`Render`] trait. At the start of each frame, GPUI
+//! will call this render method on the root view of a given window. Views build a tree of
+//! `elements`, lay them out and style them with a tailwind-style API, and then give them to
+//! GPUI to turn into pixels. See the [`elements::Div`] element for an all purpose swiss-army
+//! knife for UI.
+//!
+//! - Low level, imperative UI with Elements. Elements are the building blocks of UI in GPUI, and they
+//! provide a nice wrapper around an imperative API that provides as much flexibility and control as
+//! you need. Elements have total control over how they and their child elements are rendered and and
+//! can be used for making efficient views into large lists, implement custom layouting for a code editor,
+//! and anything else you can think of. See the [`element`] module for more information.
+//!
+//! Each of these registers has one or more corresponding contexts that can be accessed from all GPUI services.
+//! This context is your main interface to GPUI, and is used extensively throughout the framework.
+//!
+//! ## Other Resources
+//!
+//! In addition to the systems above, GPUI provides a range of smaller services that are useful for building
+//! complex applications:
+//!
+//! - Actions are user-defined structs that are used for converting keystrokes into logical operations in your UI.
+//! Use this for implementing keyboard shortcuts, such as cmd-q. See the [`action`] module for more information.
+//! - Platform services, such as `quit the app` or `open a URL` are available as methods on the [`app::AppContext`].
+//! - An async executor that is integrated with the platform's event loop. See the [`executor`] module for more information.,
+//! - The [gpui::test] macro provides a convenient way to write tests for your GPUI applications. Tests also have their
+//! own kind of context, a [`TestAppContext`] which provides ways of simulating common platform input. See [`app::test_context`]
+//! and [`test`] modules for more details.
+//!
+//! Currently, the best way to learn about these APIs is to read the Zed source code, ask us about it at a fireside hack, or drop
+//! a question in the [Zed Discord](https://discord.gg/U4qhCEhMXP). We're working on improving the documentation, creating more examples,
+//! and will be publishing more guides to GPUI on our [blog](https://zed.dev/blog).
+
+#![deny(missing_docs)]
+#![allow(clippy::type_complexity)]
#[macro_use]
mod action;
@@ -1,9 +1,6 @@
-use crate::{ImageData, ImageId, SharedUrl};
+use crate::{AppContext, ImageData, ImageId, SharedUrl, Task};
use collections::HashMap;
-use futures::{
- future::{BoxFuture, Shared},
- AsyncReadExt, FutureExt, TryFutureExt,
-};
+use futures::{future::Shared, AsyncReadExt, FutureExt, TryFutureExt};
use image::ImageError;
use parking_lot::Mutex;
use std::sync::Arc;
@@ -44,10 +41,10 @@ impl From<ImageError> for Error {
pub(crate) struct ImageCache {
client: Arc<dyn HttpClient>,
- images: Arc<Mutex<HashMap<SharedUrl, FetchImageFuture>>>,
+ images: Arc<Mutex<HashMap<SharedUrl, FetchImageTask>>>,
}
-type FetchImageFuture = Shared<BoxFuture<'static, Result<Arc<ImageData>, Error>>>;
+type FetchImageTask = Shared<Task<Result<Arc<ImageData>, Error>>>;
impl ImageCache {
pub fn new(client: Arc<dyn HttpClient>) -> Self {
@@ -57,10 +54,7 @@ impl ImageCache {
}
}
- pub fn get(
- &self,
- uri: impl Into<SharedUrl>,
- ) -> Shared<BoxFuture<'static, Result<Arc<ImageData>, Error>>> {
+ pub fn get(&self, uri: impl Into<SharedUrl>, cx: &AppContext) -> FetchImageTask {
let uri = uri.into();
let mut images = self.images.lock();
@@ -68,36 +62,39 @@ impl ImageCache {
Some(future) => future.clone(),
None => {
let client = self.client.clone();
- let future = {
- let uri = uri.clone();
- async move {
- let mut response = client.get(uri.as_ref(), ().into(), true).await?;
- let mut body = Vec::new();
- response.body_mut().read_to_end(&mut body).await?;
+ let future = cx
+ .background_executor()
+ .spawn(
+ {
+ let uri = uri.clone();
+ async move {
+ let mut response =
+ client.get(uri.as_ref(), ().into(), true).await?;
+ let mut body = Vec::new();
+ response.body_mut().read_to_end(&mut body).await?;
- if !response.status().is_success() {
- return Err(Error::BadStatus {
- status: response.status(),
- body: String::from_utf8_lossy(&body).into_owned(),
- });
- }
-
- let format = image::guess_format(&body)?;
- let image =
- image::load_from_memory_with_format(&body, format)?.into_bgra8();
- Ok(Arc::new(ImageData::new(image)))
- }
- }
- .map_err({
- let uri = uri.clone();
+ if !response.status().is_success() {
+ return Err(Error::BadStatus {
+ status: response.status(),
+ body: String::from_utf8_lossy(&body).into_owned(),
+ });
+ }
- move |error| {
- log::log!(log::Level::Error, "{:?} {:?}", &uri, &error);
- error
- }
- })
- .boxed()
- .shared();
+ let format = image::guess_format(&body)?;
+ let image = image::load_from_memory_with_format(&body, format)?
+ .into_bgra8();
+ Ok(Arc::new(ImageData::new(image)))
+ }
+ }
+ .map_err({
+ let uri = uri.clone();
+ move |error| {
+ log::log!(log::Level::Error, "{:?} {:?}", &uri, &error);
+ error
+ }
+ }),
+ )
+ .shared();
images.insert(uri, future.clone());
future
@@ -343,7 +343,7 @@ impl ExternalPaths {
impl Render for ExternalPaths {
fn render(&mut self, _: &mut ViewContext<Self>) -> impl IntoElement {
- () // Intentionally left empty because the platform will render icons for the dragged files
+ // Intentionally left empty because the platform will render icons for the dragged files
}
}
@@ -54,15 +54,24 @@ use crate::{
KeyContext, Keymap, KeymatchResult, Keystroke, KeystrokeMatcher, WindowContext,
};
use collections::FxHashMap;
-use parking_lot::Mutex;
use smallvec::{smallvec, SmallVec};
use std::{
any::{Any, TypeId},
+ cell::RefCell,
mem,
rc::Rc,
- sync::Arc,
};
+/// KeymatchMode controls how keybindings are resolved in the case of conflicting pending keystrokes.
+/// When `Sequenced`, gpui will wait for 1s for sequences to complete.
+/// When `Immediate`, gpui will immediately resolve the keybinding.
+#[derive(Default, PartialEq)]
+pub enum KeymatchMode {
+ #[default]
+ Sequenced,
+ Immediate,
+}
+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub(crate) struct DispatchNodeId(usize);
@@ -73,8 +82,9 @@ pub(crate) struct DispatchTree {
focusable_node_ids: FxHashMap<FocusId, DispatchNodeId>,
view_node_ids: FxHashMap<EntityId, DispatchNodeId>,
keystroke_matchers: FxHashMap<SmallVec<[KeyContext; 4]>, KeystrokeMatcher>,
- keymap: Arc<Mutex<Keymap>>,
+ keymap: Rc<RefCell<Keymap>>,
action_registry: Rc<ActionRegistry>,
+ pub(crate) keymatch_mode: KeymatchMode,
}
#[derive(Default)]
@@ -96,7 +106,7 @@ pub(crate) struct DispatchActionListener {
}
impl DispatchTree {
- pub fn new(keymap: Arc<Mutex<Keymap>>, action_registry: Rc<ActionRegistry>) -> Self {
+ pub fn new(keymap: Rc<RefCell<Keymap>>, action_registry: Rc<ActionRegistry>) -> Self {
Self {
node_stack: Vec::new(),
context_stack: Vec::new(),
@@ -106,6 +116,7 @@ impl DispatchTree {
keystroke_matchers: FxHashMap::default(),
keymap,
action_registry,
+ keymatch_mode: KeymatchMode::Sequenced,
}
}
@@ -116,6 +127,7 @@ impl DispatchTree {
self.focusable_node_ids.clear();
self.view_node_ids.clear();
self.keystroke_matchers.clear();
+ self.keymatch_mode = KeymatchMode::Sequenced;
}
pub fn push_node(
@@ -307,7 +319,7 @@ impl DispatchTree {
action: &dyn Action,
context_stack: &Vec<KeyContext>,
) -> Vec<KeyBinding> {
- let keymap = self.keymap.lock();
+ let keymap = self.keymap.borrow();
keymap
.bindings_for_action(action)
.filter(|binding| {
@@ -440,9 +452,7 @@ impl DispatchTree {
#[cfg(test)]
mod tests {
- use std::{rc::Rc, sync::Arc};
-
- use parking_lot::Mutex;
+ use std::{cell::RefCell, rc::Rc};
use crate::{Action, ActionRegistry, DispatchTree, KeyBinding, KeyContext, Keymap};
@@ -496,7 +506,7 @@ mod tests {
registry.load_action::<TestAction>();
- let keymap = Arc::new(Mutex::new(keymap));
+ let keymap = Rc::new(RefCell::new(keymap));
let tree = DispatchTree::new(keymap, Rc::new(registry));
@@ -1,4 +1,12 @@
-use crate::{Action, KeyBinding, KeyBindingContextPredicate, KeyContext, Keystroke, NoAction};
+mod binding;
+mod context;
+mod matcher;
+
+pub use binding::*;
+pub use context::*;
+pub(crate) use matcher::*;
+
+use crate::{Action, Keystroke, NoAction};
use collections::HashSet;
use smallvec::SmallVec;
use std::{
@@ -267,8 +267,8 @@ impl KeyBindingContextPredicate {
'(' => {
source = skip_whitespace(&source[1..]);
let (predicate, rest) = Self::parse_expr(source, 0)?;
- if rest.starts_with(')') {
- source = skip_whitespace(&rest[1..]);
+ if let Some(stripped) = rest.strip_prefix(')') {
+ source = skip_whitespace(stripped);
Ok((predicate, source))
} else {
Err(anyhow!("expected a ')'"))
@@ -1,11 +1,10 @@
use crate::{KeyBinding, KeyContext, Keymap, KeymapVersion, Keystroke};
-use parking_lot::Mutex;
use smallvec::SmallVec;
-use std::sync::Arc;
+use std::{cell::RefCell, rc::Rc};
pub(crate) struct KeystrokeMatcher {
pending_keystrokes: Vec<Keystroke>,
- keymap: Arc<Mutex<Keymap>>,
+ keymap: Rc<RefCell<Keymap>>,
keymap_version: KeymapVersion,
}
@@ -15,8 +14,8 @@ pub struct KeymatchResult {
}
impl KeystrokeMatcher {
- pub fn new(keymap: Arc<Mutex<Keymap>>) -> Self {
- let keymap_version = keymap.lock().version();
+ pub fn new(keymap: Rc<RefCell<Keymap>>) -> Self {
+ let keymap_version = keymap.borrow().version();
Self {
pending_keystrokes: Vec::new(),
keymap_version,
@@ -42,7 +41,8 @@ impl KeystrokeMatcher {
keystroke: &Keystroke,
context_stack: &[KeyContext],
) -> KeymatchResult {
- let keymap = self.keymap.lock();
+ let keymap = self.keymap.borrow();
+
// Clear pending keystrokes if the keymap has changed since the last matched keystroke.
if keymap.version() != self.keymap_version {
self.keymap_version = keymap.version();
@@ -72,7 +72,7 @@ impl KeystrokeMatcher {
}
}
- if bindings.len() == 0 && pending_key.is_none() && self.pending_keystrokes.len() > 0 {
+ if bindings.is_empty() && pending_key.is_none() && !self.pending_keystrokes.is_empty() {
drop(keymap);
self.pending_keystrokes.remove(0);
return self.match_keystroke(keystroke, context_stack);
@@ -1,9 +0,0 @@
-mod binding;
-mod context;
-mod keymap;
-mod matcher;
-
-pub use binding::*;
-pub use context::*;
-pub use keymap::*;
-pub(crate) use matcher::*;
@@ -9,7 +9,7 @@ use crate::{
Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels, Font,
FontId, FontMetrics, FontRun, ForegroundExecutor, GlobalPixels, GlyphId, Keymap, LineLayout,
Pixels, PlatformInput, Point, RenderGlyphParams, RenderImageParams, RenderSvgParams, Result,
- Scene, SharedString, Size, TaskLabel, WindowContext,
+ Scene, SharedString, Size, Task, TaskLabel, WindowContext,
};
use anyhow::anyhow;
use async_task::Runnable;
@@ -108,9 +108,9 @@ pub(crate) trait Platform: 'static {
fn write_to_clipboard(&self, item: ClipboardItem);
fn read_from_clipboard(&self) -> Option<ClipboardItem>;
- fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Result<()>;
- fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>>;
- fn delete_credentials(&self, url: &str) -> Result<()>;
+ fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Task<Result<()>>;
+ fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>>;
+ fn delete_credentials(&self, url: &str) -> Task<Result<()>>;
}
/// A handle to a platform's display, e.g. a monitor or laptop screen.
@@ -397,7 +397,7 @@ impl PlatformInputHandler {
let Some(range) = self.handler.selected_text_range(cx) else {
return;
};
- self.handler.replace_text_in_range(Some(range), &input, cx);
+ self.handler.replace_text_in_range(Some(range), input, cx);
}
}
@@ -3,7 +3,7 @@ use crate::{
Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId,
ForegroundExecutor, Keymap, MacDispatcher, MacDisplay, MacDisplayLinker, MacTextSystem,
MacWindow, Menu, MenuItem, PathPromptOptions, Platform, PlatformDisplay, PlatformInput,
- PlatformTextSystem, PlatformWindow, Result, SemanticVersion, WindowOptions,
+ PlatformTextSystem, PlatformWindow, Result, SemanticVersion, Task, WindowOptions,
};
use anyhow::anyhow;
use block::ConcreteBlock;
@@ -856,104 +856,115 @@ impl Platform for MacPlatform {
}
}
- fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Result<()> {
- let url = CFString::from(url);
- let username = CFString::from(username);
- let password = CFData::from_buffer(password);
-
- unsafe {
- use security::*;
-
- // First, check if there are already credentials for the given server. If so, then
- // update the username and password.
- let mut verb = "updating";
- let mut query_attrs = CFMutableDictionary::with_capacity(2);
- query_attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
- query_attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
-
- let mut attrs = CFMutableDictionary::with_capacity(4);
- attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
- attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
- attrs.set(kSecAttrAccount as *const _, username.as_CFTypeRef());
- attrs.set(kSecValueData as *const _, password.as_CFTypeRef());
-
- let mut status = SecItemUpdate(
- query_attrs.as_concrete_TypeRef(),
- attrs.as_concrete_TypeRef(),
- );
+ fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Task<Result<()>> {
+ let url = url.to_string();
+ let username = username.to_string();
+ let password = password.to_vec();
+ self.background_executor().spawn(async move {
+ unsafe {
+ use security::*;
+
+ let url = CFString::from(url.as_str());
+ let username = CFString::from(username.as_str());
+ let password = CFData::from_buffer(&password);
+
+ // First, check if there are already credentials for the given server. If so, then
+ // update the username and password.
+ let mut verb = "updating";
+ let mut query_attrs = CFMutableDictionary::with_capacity(2);
+ query_attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
+ query_attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
+
+ let mut attrs = CFMutableDictionary::with_capacity(4);
+ attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
+ attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
+ attrs.set(kSecAttrAccount as *const _, username.as_CFTypeRef());
+ attrs.set(kSecValueData as *const _, password.as_CFTypeRef());
+
+ let mut status = SecItemUpdate(
+ query_attrs.as_concrete_TypeRef(),
+ attrs.as_concrete_TypeRef(),
+ );
- // If there were no existing credentials for the given server, then create them.
- if status == errSecItemNotFound {
- verb = "creating";
- status = SecItemAdd(attrs.as_concrete_TypeRef(), ptr::null_mut());
- }
+ // If there were no existing credentials for the given server, then create them.
+ if status == errSecItemNotFound {
+ verb = "creating";
+ status = SecItemAdd(attrs.as_concrete_TypeRef(), ptr::null_mut());
+ }
- if status != errSecSuccess {
- return Err(anyhow!("{} password failed: {}", verb, status));
+ if status != errSecSuccess {
+ return Err(anyhow!("{} password failed: {}", verb, status));
+ }
}
- }
- Ok(())
- }
-
- fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>> {
- let url = CFString::from(url);
- let cf_true = CFBoolean::true_value().as_CFTypeRef();
+ Ok(())
+ })
+ }
+
+ fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>> {
+ let url = url.to_string();
+ self.background_executor().spawn(async move {
+ let url = CFString::from(url.as_str());
+ let cf_true = CFBoolean::true_value().as_CFTypeRef();
+
+ unsafe {
+ use security::*;
+
+ // Find any credentials for the given server URL.
+ let mut attrs = CFMutableDictionary::with_capacity(5);
+ attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
+ attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
+ attrs.set(kSecReturnAttributes as *const _, cf_true);
+ attrs.set(kSecReturnData as *const _, cf_true);
+
+ let mut result = CFTypeRef::from(ptr::null());
+ let status = SecItemCopyMatching(attrs.as_concrete_TypeRef(), &mut result);
+ match status {
+ security::errSecSuccess => {}
+ security::errSecItemNotFound | security::errSecUserCanceled => return Ok(None),
+ _ => return Err(anyhow!("reading password failed: {}", status)),
+ }
- unsafe {
- use security::*;
-
- // Find any credentials for the given server URL.
- let mut attrs = CFMutableDictionary::with_capacity(5);
- attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
- attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
- attrs.set(kSecReturnAttributes as *const _, cf_true);
- attrs.set(kSecReturnData as *const _, cf_true);
-
- let mut result = CFTypeRef::from(ptr::null());
- let status = SecItemCopyMatching(attrs.as_concrete_TypeRef(), &mut result);
- match status {
- security::errSecSuccess => {}
- security::errSecItemNotFound | security::errSecUserCanceled => return Ok(None),
- _ => return Err(anyhow!("reading password failed: {}", status)),
+ let result = CFType::wrap_under_create_rule(result)
+ .downcast::<CFDictionary>()
+ .ok_or_else(|| anyhow!("keychain item was not a dictionary"))?;
+ let username = result
+ .find(kSecAttrAccount as *const _)
+ .ok_or_else(|| anyhow!("account was missing from keychain item"))?;
+ let username = CFType::wrap_under_get_rule(*username)
+ .downcast::<CFString>()
+ .ok_or_else(|| anyhow!("account was not a string"))?;
+ let password = result
+ .find(kSecValueData as *const _)
+ .ok_or_else(|| anyhow!("password was missing from keychain item"))?;
+ let password = CFType::wrap_under_get_rule(*password)
+ .downcast::<CFData>()
+ .ok_or_else(|| anyhow!("password was not a string"))?;
+
+ Ok(Some((username.to_string(), password.bytes().to_vec())))
}
-
- let result = CFType::wrap_under_create_rule(result)
- .downcast::<CFDictionary>()
- .ok_or_else(|| anyhow!("keychain item was not a dictionary"))?;
- let username = result
- .find(kSecAttrAccount as *const _)
- .ok_or_else(|| anyhow!("account was missing from keychain item"))?;
- let username = CFType::wrap_under_get_rule(*username)
- .downcast::<CFString>()
- .ok_or_else(|| anyhow!("account was not a string"))?;
- let password = result
- .find(kSecValueData as *const _)
- .ok_or_else(|| anyhow!("password was missing from keychain item"))?;
- let password = CFType::wrap_under_get_rule(*password)
- .downcast::<CFData>()
- .ok_or_else(|| anyhow!("password was not a string"))?;
-
- Ok(Some((username.to_string(), password.bytes().to_vec())))
- }
+ })
}
- fn delete_credentials(&self, url: &str) -> Result<()> {
- let url = CFString::from(url);
+ fn delete_credentials(&self, url: &str) -> Task<Result<()>> {
+ let url = url.to_string();
- unsafe {
- use security::*;
+ self.background_executor().spawn(async move {
+ unsafe {
+ use security::*;
- let mut query_attrs = CFMutableDictionary::with_capacity(2);
- query_attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
- query_attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
+ let url = CFString::from(url.as_str());
+ let mut query_attrs = CFMutableDictionary::with_capacity(2);
+ query_attrs.set(kSecClass as *const _, kSecClassInternetPassword as *const _);
+ query_attrs.set(kSecAttrServer as *const _, url.as_CFTypeRef());
- let status = SecItemDelete(query_attrs.as_concrete_TypeRef());
+ let status = SecItemDelete(query_attrs.as_concrete_TypeRef());
- if status != errSecSuccess {
- return Err(anyhow!("delete password failed: {}", status));
+ if status != errSecSuccess {
+ return Err(anyhow!("delete password failed: {}", status));
+ }
}
- }
- Ok(())
+ Ok(())
+ })
}
}
@@ -81,13 +81,11 @@ impl PlatformTextSystem for MacTextSystem {
fn all_font_names(&self) -> Vec<String> {
let collection = core_text::font_collection::create_for_all_families();
let Some(descriptors) = collection.get_descriptors() else {
- return vec![];
+ return Vec::new();
};
let mut names = BTreeSet::new();
for descriptor in descriptors.into_iter() {
- names.insert(descriptor.font_name());
- names.insert(descriptor.family_name());
- names.insert(descriptor.style_name());
+ names.extend(lenient_font_attributes::family_name(&descriptor));
}
if let Ok(fonts_in_memory) = self.0.read().memory_source.all_families() {
names.extend(fonts_in_memory);
@@ -145,7 +143,7 @@ impl PlatformTextSystem for MacTextSystem {
fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>> {
Ok(self.0.read().fonts[font_id.0]
- .typographic_bounds(glyph_id.into())?
+ .typographic_bounds(glyph_id.0)?
.into())
}
@@ -223,11 +221,11 @@ impl MacTextSystemState {
}
fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>> {
- Ok(self.fonts[font_id.0].advance(glyph_id.into())?.into())
+ Ok(self.fonts[font_id.0].advance(glyph_id.0)?.into())
}
fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId> {
- self.fonts[font_id.0].glyph_for_char(ch).map(Into::into)
+ self.fonts[font_id.0].glyph_for_char(ch).map(GlyphId)
}
fn id_for_native_font(&mut self, requested_font: CTFont) -> FontId {
@@ -261,7 +259,7 @@ impl MacTextSystemState {
let scale = Transform2F::from_scale(params.scale_factor);
Ok(font
.raster_bounds(
- params.glyph_id.into(),
+ params.glyph_id.0,
params.font_size.into(),
scale,
HintingOptions::None,
@@ -336,7 +334,7 @@ impl MacTextSystemState {
.native_font()
.clone_with_font_size(f32::from(params.font_size) as CGFloat)
.draw_glyphs(
- &[u32::from(params.glyph_id) as CGGlyph],
+ &[params.glyph_id.0 as CGGlyph],
&[CGPoint::new(
(subpixel_shift.x / params.scale_factor) as CGFloat,
(subpixel_shift.y / params.scale_factor) as CGFloat,
@@ -421,7 +419,7 @@ impl MacTextSystemState {
let glyph_utf16_ix = usize::try_from(*glyph_utf16_ix).unwrap();
ix_converter.advance_to_utf16_ix(glyph_utf16_ix);
glyphs.push(ShapedGlyph {
- id: (*glyph_id).into(),
+ id: GlyphId(*glyph_id as u32),
position: point(position.x as f32, position.y as f32).map(px),
index: ix_converter.utf8_ix,
is_emoji: self.is_emoji(font_id),
@@ -612,9 +610,48 @@ impl From<FontStyle> for FontkitStyle {
}
}
+// Some fonts may have no attributest despite `core_text` requiring them (and panicking).
+// This is the same version as `core_text` has without `expect` calls.
+mod lenient_font_attributes {
+ use core_foundation::{
+ base::{CFRetain, CFType, TCFType},
+ string::{CFString, CFStringRef},
+ };
+ use core_text::font_descriptor::{
+ kCTFontFamilyNameAttribute, CTFontDescriptor, CTFontDescriptorCopyAttribute,
+ };
+
+ pub fn family_name(descriptor: &CTFontDescriptor) -> Option<String> {
+ unsafe { get_string_attribute(descriptor, kCTFontFamilyNameAttribute) }
+ }
+
+ fn get_string_attribute(
+ descriptor: &CTFontDescriptor,
+ attribute: CFStringRef,
+ ) -> Option<String> {
+ unsafe {
+ let value = CTFontDescriptorCopyAttribute(descriptor.as_concrete_TypeRef(), attribute);
+ if value.is_null() {
+ return None;
+ }
+
+ let value = CFType::wrap_under_create_rule(value);
+ assert!(value.instance_of::<CFString>());
+ let s = wrap_under_get_rule(value.as_CFTypeRef() as CFStringRef);
+ Some(s.to_string())
+ }
+ }
+
+ unsafe fn wrap_under_get_rule(reference: CFStringRef) -> CFString {
+ assert!(!reference.is_null(), "Attempted to create a NULL object.");
+ let reference = CFRetain(reference as *const ::std::os::raw::c_void) as CFStringRef;
+ TCFType::wrap_under_create_rule(reference)
+ }
+}
+
#[cfg(test)]
mod tests {
- use crate::{font, px, FontRun, MacTextSystem, PlatformTextSystem};
+ use crate::{font, px, FontRun, GlyphId, MacTextSystem, PlatformTextSystem};
#[test]
fn test_wrap_line() {
@@ -653,8 +690,8 @@ mod tests {
assert_eq!(layout.len, line.len());
assert_eq!(layout.runs.len(), 1);
assert_eq!(layout.runs[0].glyphs.len(), 2);
- assert_eq!(layout.runs[0].glyphs[0].id, 68u32.into()); // a
- // There's no glyph for \u{feff}
- assert_eq!(layout.runs[0].glyphs[1].id, 69u32.into()); // b
+ assert_eq!(layout.runs[0].glyphs[0].id, GlyphId(68u32)); // a
+ // There's no glyph for \u{feff}
+ assert_eq!(layout.runs[0].glyphs[1].id, GlyphId(69u32)); // b
}
}
@@ -1,6 +1,7 @@
use crate::{
AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId, ForegroundExecutor,
- Keymap, Platform, PlatformDisplay, PlatformTextSystem, TestDisplay, TestWindow, WindowOptions,
+ Keymap, Platform, PlatformDisplay, PlatformTextSystem, Task, TestDisplay, TestWindow,
+ WindowOptions,
};
use anyhow::{anyhow, Result};
use collections::VecDeque;
@@ -280,16 +281,16 @@ impl Platform for TestPlatform {
self.current_clipboard_item.lock().clone()
}
- fn write_credentials(&self, _url: &str, _username: &str, _password: &[u8]) -> Result<()> {
- Ok(())
+ fn write_credentials(&self, _url: &str, _username: &str, _password: &[u8]) -> Task<Result<()>> {
+ Task::ready(Ok(()))
}
- fn read_credentials(&self, _url: &str) -> Result<Option<(String, Vec<u8>)>> {
- Ok(None)
+ fn read_credentials(&self, _url: &str) -> Task<Result<Option<(String, Vec<u8>)>>> {
+ Task::ready(Ok(None))
}
- fn delete_credentials(&self, _url: &str) -> Result<()> {
- Ok(())
+ fn delete_credentials(&self, _url: &str) -> Task<Result<()>> {
+ Task::ready(Ok(()))
}
fn double_click_interval(&self) -> std::time::Duration {
@@ -39,6 +39,7 @@ impl From<ViewId> for EntityId {
#[derive(Default)]
pub(crate) struct Scene {
+ last_layer: Option<(StackingOrder, LayerId)>,
layers_by_order: BTreeMap<StackingOrder, LayerId>,
orders_by_layer: BTreeMap<LayerId, StackingOrder>,
pub(crate) shadows: Vec<Shadow>,
@@ -52,6 +53,7 @@ pub(crate) struct Scene {
impl Scene {
pub fn clear(&mut self) {
+ self.last_layer = None;
self.layers_by_order.clear();
self.orders_by_layer.clear();
self.shadows.clear();
@@ -139,14 +141,22 @@ impl Scene {
}
fn layer_id_for_order(&mut self, order: &StackingOrder) -> LayerId {
- if let Some(layer_id) = self.layers_by_order.get(order) {
+ if let Some((last_order, last_layer_id)) = self.last_layer.as_ref() {
+ if order == last_order {
+ return *last_layer_id;
+ }
+ }
+
+ let layer_id = if let Some(layer_id) = self.layers_by_order.get(order) {
*layer_id
} else {
let next_id = self.layers_by_order.len() as LayerId;
self.layers_by_order.insert(order.clone(), next_id);
self.orders_by_layer.insert(next_id, order.clone());
next_id
- }
+ };
+ self.last_layer = Some((order.clone(), layer_id));
+ layer_id
}
pub fn reuse_views(&mut self, views: &FxHashSet<EntityId>, prev_scene: &mut Self) {
@@ -4,7 +4,7 @@ use std::{borrow::Borrow, sync::Arc};
use util::arc_cow::ArcCow;
/// A shared string is an immutable string that can be cheaply cloned in GPUI
-/// tasks. Essentially an abstraction over an Arc<str> and &'static str,
+/// tasks. Essentially an abstraction over an `Arc<str>` and `&'static str`,
#[derive(Deref, DerefMut, Eq, PartialEq, Hash, Clone)]
pub struct SharedString(ArcCow<'static, str>);
@@ -7,7 +7,7 @@ use crate::{
SizeRefinement, Styled, TextRun,
};
use collections::HashSet;
-use refineable::{Cascade, Refineable};
+use refineable::Refineable;
use smallvec::SmallVec;
pub use taffy::style::{
AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, JustifyContent,
@@ -15,10 +15,12 @@ pub use taffy::style::{
};
#[cfg(debug_assertions)]
+/// Use this struct for interfacing with the 'debug_below' styling from your own elements.
+/// If a parent element has this style set on it, then this struct will be set as a global in
+/// GPUI.
pub struct DebugBelow;
-pub type StyleCascade = Cascade<Style>;
-
+/// The CSS styling that can be applied to an element via the `Styled` trait
#[derive(Clone, Refineable, Debug)]
#[refineable(Debug)]
pub struct Style {
@@ -104,16 +106,20 @@ pub struct Style {
/// Box Shadow of the element
pub box_shadow: SmallVec<[BoxShadow; 2]>,
- /// TEXT
+ /// The text style of this element
pub text: TextStyleRefinement,
/// The mouse cursor style shown when the mouse pointer is over an element.
pub mouse_cursor: Option<CursorStyle>,
+ /// The z-index to set for this element
pub z_index: Option<u16>,
+ /// Whether to draw a red debugging outline around this element
#[cfg(debug_assertions)]
pub debug: bool,
+
+ /// Whether to draw a red debugging outline around this element and all of it's conforming children
#[cfg(debug_assertions)]
pub debug_below: bool,
}
@@ -124,40 +130,71 @@ impl Styled for StyleRefinement {
}
}
+/// The value of the visibility property, similar to the CSS property `visibility`
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)]
pub enum Visibility {
+ /// The element should be drawn as normal.
#[default]
Visible,
+ /// The element should not be drawn, but should still take up space in the layout.
Hidden,
}
+/// The possible values of the box-shadow property
#[derive(Clone, Debug)]
pub struct BoxShadow {
+ /// What color should the shadow have?
pub color: Hsla,
+ /// How should it be offset from it's element?
pub offset: Point<Pixels>,
+ /// How much should the shadow be blurred?
pub blur_radius: Pixels,
+ /// How much should the shadow spread?
pub spread_radius: Pixels,
}
+/// How to handle whitespace in text
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum WhiteSpace {
+ /// Normal line wrapping when text overflows the width of the element
#[default]
Normal,
+ /// No line wrapping, text will overflow the width of the element
Nowrap,
}
+/// The properties that can be used to style text in GPUI
#[derive(Refineable, Clone, Debug, PartialEq)]
#[refineable(Debug)]
pub struct TextStyle {
+ /// The color of the text
pub color: Hsla,
+
+ /// The font family to use
pub font_family: SharedString,
+
+ /// The font features to use
pub font_features: FontFeatures,
+
+ /// The font size to use, in pixels or rems.
pub font_size: AbsoluteLength,
+
+ /// The line height to use, in pixels or fractions
pub line_height: DefiniteLength,
+
+ /// The font weight, e.g. bold
pub font_weight: FontWeight,
+
+ /// The font style, e.g. italic
pub font_style: FontStyle,
+
+ /// The background color of the text
pub background_color: Option<Hsla>,
+
+ /// The underline style of the text
pub underline: Option<UnderlineStyle>,
+
+ /// How to handle whitespace in the text
pub white_space: WhiteSpace,
}
@@ -180,6 +217,7 @@ impl Default for TextStyle {
}
impl TextStyle {
+ /// Create a new text style with the given highlighting applied.
pub fn highlight(mut self, style: impl Into<HighlightStyle>) -> Self {
let style = style.into();
if let Some(weight) = style.font_weight {
@@ -208,6 +246,7 @@ impl TextStyle {
self
}
+ /// Get the font configured for this text style.
pub fn font(&self) -> Font {
Font {
family: self.font_family.clone(),
@@ -222,6 +261,7 @@ impl TextStyle {
self.line_height.to_pixels(self.font_size, rem_size).round()
}
+ /// Convert this text style into a [`TextRun`], for the given length of the text.
pub fn to_run(&self, len: usize) -> TextRun {
TextRun {
len,
@@ -238,19 +278,33 @@ impl TextStyle {
}
}
+/// A highlight style to apply, similar to a `TextStyle` except
+/// for a single font, uniformly sized and spaced text.
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct HighlightStyle {
+ /// The color of the text
pub color: Option<Hsla>,
+
+ /// The font weight, e.g. bold
pub font_weight: Option<FontWeight>,
+
+ /// The font style, e.g. italic
pub font_style: Option<FontStyle>,
+
+ /// The background color of the text
pub background_color: Option<Hsla>,
+
+ /// The underline style of the text
pub underline: Option<UnderlineStyle>,
+
+ /// Similar to the CSS `opacity` property, this will cause the text to be less vibrant.
pub fade_out: Option<f32>,
}
impl Eq for HighlightStyle {}
impl Style {
+ /// Get the text style in this element style.
pub fn text_style(&self) -> Option<&TextStyleRefinement> {
if self.text.is_some() {
Some(&self.text)
@@ -259,6 +313,8 @@ impl Style {
}
}
+ /// Get the content mask for this element style, based on the given bounds.
+ /// If the element does not hide it's overflow, this will return `None`.
pub fn overflow_mask(
&self,
bounds: Bounds<Pixels>,
@@ -480,20 +536,29 @@ impl Default for Style {
}
}
+/// The properties that can be applied to an underline.
#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq)]
#[refineable(Debug)]
pub struct UnderlineStyle {
+ /// The thickness of the underline.
pub thickness: Pixels,
+
+ /// The color of the underline.
pub color: Option<Hsla>,
+
+ /// Whether the underline should be wavy, like in a spell checker.
pub wavy: bool,
}
+/// The kinds of fill that can be applied to a shape.
#[derive(Clone, Debug)]
pub enum Fill {
+ /// A solid color fill.
Color(Hsla),
}
impl Fill {
+ /// Unwrap this fill into a solid color, if it is one.
pub fn color(&self) -> Option<Hsla> {
match self {
Fill::Color(color) => Some(*color),
@@ -539,6 +604,8 @@ impl From<&TextStyle> for HighlightStyle {
}
impl HighlightStyle {
+ /// Blend this highlight style with another.
+ /// Non-continuous properties, like font_weight and font_style, are overwritten.
pub fn highlight(&mut self, other: HighlightStyle) {
match (self.color, other.color) {
(Some(self_color), Some(other_color)) => {
@@ -612,6 +679,7 @@ impl From<Rgba> for HighlightStyle {
}
}
+/// Combine and merge the highlights and ranges in the two iterators.
pub fn combine_highlights(
a: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
b: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
@@ -7,17 +7,21 @@ use crate::{BoxShadow, TextStyleRefinement};
use smallvec::{smallvec, SmallVec};
use taffy::style::{Display, Overflow};
+/// A trait for elements that can be styled.
+/// Use this to opt-in to a CSS-like styling API.
pub trait Styled: Sized {
+ /// Returns a reference to the style memory of this element.
fn style(&mut self) -> &mut StyleRefinement;
gpui_macros::style_helpers!();
+ /// Set the z-index of this element.
fn z_index(mut self, z_index: u16) -> Self {
self.style().z_index = Some(z_index);
self
}
- /// Sets the size of the element to the full width and height.
+ /// Sets the size of the element to sthe full width and height.
fn full(mut self) -> Self {
self.style().size.width = Some(relative(1.).into());
self.style().size.height = Some(relative(1.).into());
@@ -88,6 +92,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the cursor style when hovering over this element
fn cursor(mut self, cursor: CursorStyle) -> Self {
self.style().mouse_cursor = Some(cursor);
self
@@ -511,16 +516,19 @@ pub trait Styled: Sized {
self
}
+ /// Get 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 it's 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 it's child elements.
fn font_weight(mut self, weight: FontWeight) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -528,6 +536,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the background color of this element, this value cascades to it's child elements.
fn text_bg(mut self, bg: impl Into<Hsla>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -535,6 +544,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the text size of this element, this value cascades to it's child elements.
fn text_size(mut self, size: impl Into<AbsoluteLength>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -542,6 +552,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)
fn text_xs(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -549,6 +561,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)
fn text_sm(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -556,6 +570,7 @@ pub trait Styled: Sized {
self
}
+ /// Reset the text styling for this element and it's children.
fn text_base(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -563,6 +578,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)
fn text_lg(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -570,6 +587,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)
fn text_xl(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -577,6 +596,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)
fn text_2xl(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -584,6 +605,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)
fn text_3xl(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -591,6 +614,7 @@ pub trait Styled: Sized {
self
}
+ /// Remove the text decoration on this element, this value cascades to it's child elements.
fn text_decoration_none(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -598,6 +622,7 @@ pub trait Styled: Sized {
self
}
+ /// Set 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);
@@ -605,6 +630,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to a solid line
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);
@@ -612,6 +638,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to a wavy line
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);
@@ -619,6 +646,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to be 0 thickness, see the [Tailwind 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);
@@ -626,6 +654,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to be 1px thick, see the [Tailwind 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);
@@ -633,6 +662,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to be 2px thick, see the [Tailwind 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);
@@ -640,6 +670,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to be 4px thick, see the [Tailwind 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);
@@ -647,6 +678,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the underline to be 8px thick, see the [Tailwind 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);
@@ -654,6 +686,7 @@ pub trait Styled: Sized {
self
}
+ /// Change the font on this element and it's children.
fn font(mut self, family_name: impl Into<SharedString>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -661,6 +694,7 @@ pub trait Styled: Sized {
self
}
+ /// Set the line height on this element and it's children.
fn line_height(mut self, line_height: impl Into<DefiniteLength>) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
@@ -668,12 +702,14 @@ pub trait Styled: Sized {
self
}
+ /// Draw 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.
#[cfg(debug_assertions)]
fn debug_below(mut self) -> Self {
self.style().debug_below = Some(true);
@@ -41,7 +41,6 @@ where
/// are inert, meaning that they won't be listed when calling `[SubscriberSet::remove]` or `[SubscriberSet::retain]`.
/// This method returns a tuple of a [`Subscription`] and an `impl FnOnce`, and you can use the latter
/// to activate the [`Subscription`].
- #[must_use]
pub fn insert(
&self,
emitter_key: EmitterKey,
@@ -12,22 +12,16 @@ use taffy::{
Taffy,
};
+type NodeMeasureFn =
+ Box<dyn FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut WindowContext) -> Size<Pixels>>;
+
pub struct TaffyLayoutEngine {
taffy: Taffy,
styles: FxHashMap<LayoutId, Style>,
children_to_parents: FxHashMap<LayoutId, LayoutId>,
absolute_layout_bounds: FxHashMap<LayoutId, Bounds<Pixels>>,
computed_layouts: FxHashSet<LayoutId>,
- nodes_to_measure: FxHashMap<
- LayoutId,
- Box<
- dyn FnMut(
- Size<Option<Pixels>>,
- Size<AvailableSpace>,
- &mut WindowContext,
- ) -> Size<Pixels>,
- >,
- >,
+ nodes_to_measure: FxHashMap<LayoutId, NodeMeasureFn>,
}
static EXPECT_MESSAGE: &str = "we should avoid taffy layout errors by construction if possible";
@@ -26,19 +26,22 @@ use std::{
sync::Arc,
};
+/// An opaque identifier for a specific font.
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
#[repr(C)]
pub struct FontId(pub usize);
+/// An opaque identifier for a specific font family.
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
pub struct FontFamilyId(pub usize);
pub(crate) const SUBPIXEL_VARIANTS: u8 = 4;
+/// The GPUI text layout and rendering sub system.
pub struct TextSystem {
line_layout_cache: Arc<LineLayoutCache>,
platform_text_system: Arc<dyn PlatformTextSystem>,
- font_ids_by_font: RwLock<FxHashMap<Font, FontId>>,
+ font_ids_by_font: RwLock<FxHashMap<Font, Result<FontId>>>,
font_metrics: RwLock<FxHashMap<FontId, FontMetrics>>,
raster_bounds: RwLock<FxHashMap<RenderGlyphParams, Bounds<DevicePixels>>>,
wrapper_pool: Mutex<FxHashMap<FontIdWithSize, Vec<LineWrapper>>>,
@@ -65,13 +68,14 @@ impl TextSystem {
}
}
+ /// Get a list of all available font names from the operating system.
pub fn all_font_names(&self) -> Vec<String> {
let mut names: BTreeSet<_> = self
.platform_text_system
.all_font_names()
.into_iter()
.collect();
- names.extend(self.platform_text_system.all_font_families().into_iter());
+ names.extend(self.platform_text_system.all_font_families());
names.extend(
self.fallback_font_stack
.iter()
@@ -79,18 +83,34 @@ impl TextSystem {
);
names.into_iter().collect()
}
+
+ /// Add a font's data to the text system.
pub fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()> {
self.platform_text_system.add_fonts(fonts)
}
+ /// Get the FontId for the configure font family and style.
pub fn font_id(&self, font: &Font) -> Result<FontId> {
- let font_id = self.font_ids_by_font.read().get(font).copied();
+ fn clone_font_id_result(font_id: &Result<FontId>) -> Result<FontId> {
+ match font_id {
+ Ok(font_id) => Ok(*font_id),
+ Err(err) => Err(anyhow!("{}", err)),
+ }
+ }
+
+ let font_id = self
+ .font_ids_by_font
+ .read()
+ .get(font)
+ .map(clone_font_id_result);
if let Some(font_id) = font_id {
- Ok(font_id)
+ font_id
} else {
- let font_id = self.platform_text_system.font_id(font)?;
- self.font_ids_by_font.write().insert(font.clone(), font_id);
- Ok(font_id)
+ let font_id = self.platform_text_system.font_id(font);
+ self.font_ids_by_font
+ .write()
+ .insert(font.clone(), clone_font_id_result(&font_id));
+ font_id
}
}
@@ -120,10 +140,14 @@ impl TextSystem {
);
}
+ /// Get the bounding box for the given font and font size.
+ /// A font's bounding box is the smallest rectangle that could enclose all glyphs
+ /// in the font. superimposed over one another.
pub fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels> {
self.read_metrics(font_id, |metrics| metrics.bounding_box(font_size))
}
+ /// Get the typographic bounds for the given character, in the given font and size.
pub fn typographic_bounds(
&self,
font_id: FontId,
@@ -142,6 +166,7 @@ impl TextSystem {
}))
}
+ /// Get the advance width for the given character, in the given font and size.
pub fn advance(&self, font_id: FontId, font_size: Pixels, ch: char) -> Result<Size<Pixels>> {
let glyph_id = self
.platform_text_system
@@ -153,26 +178,35 @@ impl TextSystem {
Ok(result * font_size)
}
+ /// Get the number of font size units per 'em square',
+ /// Per MDN: "an abstract square whose height is the intended distance between
+ /// lines of type in the same type size"
pub fn units_per_em(&self, font_id: FontId) -> u32 {
self.read_metrics(font_id, |metrics| metrics.units_per_em)
}
+ /// Get the height of a capital letter in the given font and size.
pub fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels {
self.read_metrics(font_id, |metrics| metrics.cap_height(font_size))
}
+ /// Get the height of the x character in the given font and size.
pub fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels {
self.read_metrics(font_id, |metrics| metrics.x_height(font_size))
}
+ /// Get the recommended distance from the baseline for the given font
pub fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels {
self.read_metrics(font_id, |metrics| metrics.ascent(font_size))
}
+ /// Get the recommended distance below the baseline for the given font,
+ /// in single spaced text.
pub fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels {
self.read_metrics(font_id, |metrics| metrics.descent(font_size))
}
+ /// Get the recommended baseline offset for the given font and line height.
pub fn baseline_offset(
&self,
font_id: FontId,
@@ -199,10 +233,14 @@ impl TextSystem {
}
}
- pub fn with_view<R>(&self, view_id: EntityId, f: impl FnOnce() -> R) -> R {
+ pub(crate) fn with_view<R>(&self, view_id: EntityId, f: impl FnOnce() -> R) -> R {
self.line_layout_cache.with_view(view_id, f)
}
+ /// Layout the given line of text, at the given font_size.
+ /// Subsets of the line can be styled independently with the `runs` parameter.
+ /// Generally, you should prefer to use `TextLayout::shape_line` instead, which
+ /// can be painted directly.
pub fn layout_line(
&self,
text: &str,
@@ -234,6 +272,12 @@ impl TextSystem {
Ok(layout)
}
+ /// Shape the given line, at the given font_size, for painting to the screen.
+ /// Subsets of the line can be styled independently with the `runs` parameter.
+ ///
+ /// Note that this method can only shape a single line of text. It will panic
+ /// if the text contains newlines. If you need to shape multiple lines of text,
+ /// use `TextLayout::shape_text` instead.
pub fn shape_line(
&self,
text: SharedString,
@@ -273,6 +317,9 @@ impl TextSystem {
})
}
+ /// Shape a multi line string of text, at the given font_size, for painting to the screen.
+ /// Subsets of the text can be styled independently with the `runs` parameter.
+ /// If `wrap_width` is provided, the line breaks will be adjusted to fit within the given width.
pub fn shape_text(
&self,
text: SharedString,
@@ -381,6 +428,7 @@ impl TextSystem {
self.line_layout_cache.finish_frame(reused_views)
}
+ /// Returns a handle to a line wrapper, for the given font and font size.
pub fn line_wrapper(self: &Arc<Self>, font: Font, font_size: Pixels) -> LineWrapperHandle {
let lock = &mut self.wrapper_pool.lock();
let font_id = self.resolve_font(&font);
@@ -397,7 +445,8 @@ impl TextSystem {
}
}
- pub fn raster_bounds(&self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
+ /// Get the rasterized size and location of a specific, rendered glyph.
+ pub(crate) fn raster_bounds(&self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
let raster_bounds = self.raster_bounds.upgradable_read();
if let Some(bounds) = raster_bounds.get(params) {
Ok(*bounds)
@@ -409,7 +458,7 @@ impl TextSystem {
}
}
- pub fn rasterize_glyph(
+ pub(crate) fn rasterize_glyph(
&self,
params: &RenderGlyphParams,
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
@@ -425,6 +474,7 @@ struct FontIdWithSize {
font_size: Pixels,
}
+/// A handle into the text system, which can be used to compute the wrapped layout of text
pub struct LineWrapperHandle {
wrapper: Option<LineWrapper>,
text_system: Arc<TextSystem>,
@@ -517,40 +567,28 @@ impl Display for FontStyle {
}
}
+/// A styled run of text, for use in [`TextLayout`].
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TextRun {
- // number of utf8 bytes
+ /// A number of utf8 bytes
pub len: usize,
+ /// The font to use for this run.
pub font: Font,
+ /// The color
pub color: Hsla,
+ /// The background color (if any)
pub background_color: Option<Hsla>,
+ /// The underline style (if any)
pub underline: Option<UnderlineStyle>,
}
+/// An identifier for a specific glyph, as returned by [`TextSystem::layout_line`].
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[repr(C)]
-pub struct GlyphId(u32);
-
-impl From<GlyphId> for u32 {
- fn from(value: GlyphId) -> Self {
- value.0
- }
-}
-
-impl From<u16> for GlyphId {
- fn from(num: u16) -> Self {
- GlyphId(num as u32)
- }
-}
-
-impl From<u32> for GlyphId {
- fn from(num: u32) -> Self {
- GlyphId(num)
- }
-}
+pub struct GlyphId(pub(crate) u32);
#[derive(Clone, Debug, PartialEq)]
-pub struct RenderGlyphParams {
+pub(crate) struct RenderGlyphParams {
pub(crate) font_id: FontId,
pub(crate) glyph_id: GlyphId,
pub(crate) font_size: Pixels,
@@ -571,6 +609,7 @@ impl Hash for RenderGlyphParams {
}
}
+/// The parameters for rendering an emoji glyph.
#[derive(Clone, Debug, PartialEq)]
pub struct RenderEmojiParams {
pub(crate) font_id: FontId,
@@ -590,14 +629,23 @@ impl Hash for RenderEmojiParams {
}
}
+/// The configuration details for identifying a specific font.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Font {
+ /// The font family name.
pub family: SharedString,
+
+ /// The font features to use.
pub features: FontFeatures,
+
+ /// The font weight.
pub weight: FontWeight,
+
+ /// The font style.
pub style: FontStyle,
}
+/// Get a [`Font`] for a given name.
pub fn font(family: impl Into<SharedString>) -> Font {
Font {
family: family.into(),
@@ -608,10 +656,17 @@ pub fn font(family: impl Into<SharedString>) -> Font {
}
impl Font {
+ /// Set this Font to be bold
pub fn bold(mut self) -> Self {
self.weight = FontWeight::BOLD;
self
}
+
+ /// Set this Font to be italic
+ pub fn italic(mut self) -> Self {
+ self.style = FontStyle::Italic;
+ self
+ }
}
/// A struct for storing font metrics.
@@ -5,6 +5,8 @@ use schemars::{
macro_rules! create_definitions {
($($(#[$meta:meta])* ($name:ident, $idx:expr)),* $(,)?) => {
+
+ /// The OpenType features that can be configured for a given font.
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)]
pub struct FontFeatures {
enabled: u64,
@@ -13,6 +15,7 @@ macro_rules! create_definitions {
impl FontFeatures {
$(
+ /// Get the current value of the corresponding OpenType feature
pub fn $name(&self) -> Option<bool> {
if (self.enabled & (1 << $idx)) != 0 {
Some(true)
@@ -6,29 +6,41 @@ use derive_more::{Deref, DerefMut};
use smallvec::SmallVec;
use std::sync::Arc;
+/// Set the text decoration for a run of text.
#[derive(Debug, Clone)]
pub struct DecorationRun {
+ /// The length of the run in utf-8 bytes.
pub len: u32,
+
+ /// The color for this run
pub color: Hsla,
+
+ /// The background color for this run
pub background_color: Option<Hsla>,
+
+ /// The underline style for this run
pub underline: Option<UnderlineStyle>,
}
+/// A line of text that has been shaped and decorated.
#[derive(Clone, Default, Debug, Deref, DerefMut)]
pub struct ShapedLine {
#[deref]
#[deref_mut]
pub(crate) layout: Arc<LineLayout>,
+ /// The text that was shaped for this line.
pub text: SharedString,
pub(crate) decoration_runs: SmallVec<[DecorationRun; 32]>,
}
impl ShapedLine {
/// The length of the line in utf-8 bytes.
+ #[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.layout.len
}
+ /// Paint the line of text to the window.
pub fn paint(
&self,
origin: Point<Pixels>,
@@ -48,20 +60,25 @@ impl ShapedLine {
}
}
+/// A line of text that has been shaped, decorated, and wrapped by the text layout system.
#[derive(Clone, Default, Debug, Deref, DerefMut)]
pub struct WrappedLine {
#[deref]
#[deref_mut]
pub(crate) layout: Arc<WrappedLineLayout>,
+ /// The text that was shaped for this line.
pub text: SharedString,
pub(crate) decoration_runs: SmallVec<[DecorationRun; 32]>,
}
impl WrappedLine {
+ /// The length of the underlying, unwrapped layout, in utf-8 bytes.
+ #[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.layout.len()
}
+ /// Paint this line of text to the window.
pub fn paint(
&self,
origin: Point<Pixels>,
@@ -8,31 +8,50 @@ use std::{
sync::Arc,
};
+/// A laid out and styled line of text
#[derive(Default, Debug)]
pub struct LineLayout {
+ /// The font size for this line
pub font_size: Pixels,
+ /// The width of the line
pub width: Pixels,
+ /// The ascent of the line
pub ascent: Pixels,
+ /// The descent of the line
pub descent: Pixels,
+ /// The shaped runs that make up this line
pub runs: Vec<ShapedRun>,
+ /// The length of the line in utf-8 bytes
pub len: usize,
}
+/// A run of text that has been shaped .
#[derive(Debug)]
pub struct ShapedRun {
+ /// The font id for this run
pub font_id: FontId,
+ /// The glyphs that make up this run
pub glyphs: SmallVec<[ShapedGlyph; 8]>,
}
+/// A single glyph, ready to paint.
#[derive(Clone, Debug)]
pub struct ShapedGlyph {
+ /// The ID for this glyph, as determined by the text system.
pub id: GlyphId,
+
+ /// The position of this glyph in it's containing line.
pub position: Point<Pixels>,
+
+ /// The index of this glyph in the original text.
pub index: usize,
+
+ /// Whether this glyph is an emoji
pub is_emoji: bool,
}
impl LineLayout {
+ /// The index for the character at the given x coordinate
pub fn index_for_x(&self, x: Pixels) -> Option<usize> {
if x >= self.width {
None
@@ -71,6 +90,7 @@ impl LineLayout {
self.len
}
+ /// The x position of the character at the given index
pub fn x_for_index(&self, index: usize) -> Pixels {
for run in &self.runs {
for glyph in &run.glyphs {
@@ -148,30 +168,44 @@ impl LineLayout {
}
}
+/// A line of text that has been wrapped to fit a given width
#[derive(Default, Debug)]
pub struct WrappedLineLayout {
+ /// The line layout, pre-wrapping.
pub unwrapped_layout: Arc<LineLayout>,
+
+ /// The boundaries at which the line was wrapped
pub wrap_boundaries: SmallVec<[WrapBoundary; 1]>,
+
+ /// The width of the line, if it was wrapped
pub wrap_width: Option<Pixels>,
}
+/// A boundary at which a line was wrapped
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct WrapBoundary {
+ /// The index in the run just before the line was wrapped
pub run_ix: usize,
+ /// The index of the glyph just before the line was wrapped
pub glyph_ix: usize,
}
impl WrappedLineLayout {
+ /// The length of the underlying text, in utf8 bytes.
+ #[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.unwrapped_layout.len
}
+ /// The width of this line, in pixels, whether or not it was wrapped.
pub fn width(&self) -> Pixels {
self.wrap_width
.unwrap_or(Pixels::MAX)
.min(self.unwrapped_layout.width)
}
+ /// The size of the whole wrapped text, for the given line_height.
+ /// can span multiple lines if there are multiple wrap boundaries.
pub fn size(&self, line_height: Pixels) -> Size<Pixels> {
Size {
width: self.width(),
@@ -179,26 +213,32 @@ impl WrappedLineLayout {
}
}
+ /// The ascent of a line in this layout
pub fn ascent(&self) -> Pixels {
self.unwrapped_layout.ascent
}
+ /// The descent of a line in this layout
pub fn descent(&self) -> Pixels {
self.unwrapped_layout.descent
}
+ /// The wrap boundaries in this layout
pub fn wrap_boundaries(&self) -> &[WrapBoundary] {
&self.wrap_boundaries
}
+ /// The font size of this layout
pub fn font_size(&self) -> Pixels {
self.unwrapped_layout.font_size
}
+ /// The runs in this layout, sans wrapping
pub fn runs(&self) -> &[ShapedRun] {
&self.unwrapped_layout.runs
}
+ /// The index corresponding to a given position in this layout for the given line height.
pub fn index_for_position(
&self,
position: Point<Pixels>,
@@ -376,6 +416,7 @@ impl LineLayoutCache {
}
}
+/// A run of text with a single font.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct FontRun {
pub(crate) len: usize,
@@ -2,6 +2,7 @@ use crate::{px, FontId, FontRun, Pixels, PlatformTextSystem};
use collections::HashMap;
use std::{iter, sync::Arc};
+/// The GPUI line wrapper, used to wrap lines of text to a given width.
pub struct LineWrapper {
platform_text_system: Arc<dyn PlatformTextSystem>,
pub(crate) font_id: FontId,
@@ -11,6 +12,7 @@ pub struct LineWrapper {
}
impl LineWrapper {
+ /// The maximum indent that can be applied to a line.
pub const MAX_INDENT: u32 = 256;
pub(crate) fn new(
@@ -27,6 +29,7 @@ impl LineWrapper {
}
}
+ /// Wrap a line of text to the given width with this wrapper's font and font size.
pub fn wrap_line<'a>(
&'a mut self,
line: &'a str,
@@ -122,9 +125,12 @@ impl LineWrapper {
}
}
+/// A boundary between two lines of text.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Boundary {
+ /// The index of the last character in a line
pub ix: usize,
+ /// The indent of the next line.
pub next_indent: u32,
}
@@ -2,11 +2,12 @@ use crate::{
px, size, transparent_black, Action, AnyDrag, AnyView, AppContext, Arena, AsyncWindowContext,
AvailableSpace, Bounds, Context, Corners, CursorStyle, DispatchActionListener, DispatchNodeId,
DispatchTree, DisplayId, Edges, Effect, Entity, EntityId, EventEmitter, FileDropEvent, Flatten,
- GlobalElementId, Hsla, KeyBinding, KeyContext, KeyDownEvent, KeyMatch, KeymatchResult,
- Keystroke, KeystrokeEvent, Model, ModelContext, Modifiers, MouseButton, MouseMoveEvent,
- MouseUpEvent, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput, PlatformWindow, Point,
- PromptLevel, Render, ScaledPixels, SharedString, Size, SubscriberSet, Subscription,
- TaffyLayoutEngine, Task, View, VisualContext, WeakView, WindowBounds, WindowOptions,
+ GlobalElementId, Hsla, KeyBinding, KeyContext, KeyDownEvent, KeyMatch, KeymatchMode,
+ KeymatchResult, Keystroke, KeystrokeEvent, Model, ModelContext, Modifiers, MouseButton,
+ MouseMoveEvent, MouseUpEvent, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,
+ PlatformWindow, Point, PromptLevel, Render, ScaledPixels, SharedString, Size, SubscriberSet,
+ Subscription, TaffyLayoutEngine, Task, View, VisualContext, WeakView, WindowBounds,
+ WindowOptions,
};
use anyhow::{anyhow, Context as _, Result};
use collections::FxHashSet;
@@ -93,6 +94,7 @@ type AnyObserver = Box<dyn FnMut(&mut WindowContext) -> bool + 'static>;
type AnyWindowFocusListener = Box<dyn FnMut(&FocusEvent, &mut WindowContext) -> bool + 'static>;
+#[derive(Debug)]
struct FocusEvent {
previous_focus_path: SmallVec<[FocusId; 8]>,
current_focus_path: SmallVec<[FocusId; 8]>,
@@ -104,7 +106,7 @@ slotmap::new_key_type! {
}
thread_local! {
- pub(crate) static ELEMENT_ARENA: RefCell<Arena> = RefCell::new(Arena::new(4 * 1024 * 1024));
+ pub(crate) static ELEMENT_ARENA: RefCell<Arena> = RefCell::new(Arena::new(8 * 1024 * 1024));
}
impl FocusId {
@@ -877,14 +879,27 @@ impl<'a> WindowContext<'a> {
pub(crate) fn was_top_layer_under_active_drag(
&self,
point: &Point<Pixels>,
- level: &StackingOrder,
+ layer: &StackingOrder,
) -> bool {
- for (opaque_level, _, bounds) in self.window.rendered_frame.depth_map.iter() {
- if level >= opaque_level {
- break;
+ // Precondition: the depth map is ordered from topmost to bottomost.
+
+ for (opaque_layer, _, bounds) in self.window.rendered_frame.depth_map.iter() {
+ if layer >= opaque_layer {
+ // The queried layer is either above or is the same as the this opaque layer.
+ // Anything after this point is guaranteed to be below the queried layer.
+ return true;
}
- if opaque_level
+ if !bounds.contains(point) {
+ // This opaque layer is above the queried layer but it doesn't contain
+ // the given position, so we can ignore it even if it's above.
+ continue;
+ }
+
+ // All normal content is rendered with a base z-index of 0, we know that if the root of this opaque layer
+ // equals `ACTIVE_DRAG_Z_INDEX` then it must be the drag layer and we can ignore it as we are
+ // looking to see if the queried layer was the topmost underneath the drag layer.
+ if opaque_layer
.first()
.map(|c| c.z_index == ACTIVE_DRAG_Z_INDEX)
.unwrap_or(false)
@@ -892,10 +907,21 @@ impl<'a> WindowContext<'a> {
continue;
}
- if bounds.contains(point) {
+ // At this point, we've established that this opaque layer is on top of the queried layer
+ // and contains the position:
+ // - If the opaque layer is an extension of the queried layer, we don't want
+ // to consider the opaque layer to be on top and so we ignore it.
+ // - Else, we will bail early and say that the queried layer wasn't the top one.
+ let opaque_layer_is_extension_of_queried_layer = opaque_layer.len() >= layer.len()
+ && opaque_layer
+ .iter()
+ .zip(layer.iter())
+ .all(|(a, b)| a.z_index == b.z_index);
+ if !opaque_layer_is_extension_of_queried_layer {
return false;
}
}
+
true
}
@@ -1005,7 +1031,13 @@ impl<'a> WindowContext<'a> {
self.window
.next_frame
.finish(&mut self.window.rendered_frame);
- ELEMENT_ARENA.with_borrow_mut(|element_arena| element_arena.clear());
+ ELEMENT_ARENA.with_borrow_mut(|element_arena| {
+ let percentage = (element_arena.len() as f32 / element_arena.capacity() as f32) * 100.;
+ if percentage >= 80. {
+ log::warn!("elevated element arena occupation: {}.", percentage);
+ }
+ element_arena.clear();
+ });
let previous_focus_path = self.window.rendered_frame.focus_path();
let previous_window_active = self.window.rendered_frame.window_active;
@@ -1214,12 +1246,21 @@ impl<'a> WindowContext<'a> {
.dispatch_path(node_id);
if let Some(key_down_event) = event.downcast_ref::<KeyDownEvent>() {
- let KeymatchResult { bindings, pending } = self
+ let KeymatchResult {
+ bindings,
+ mut pending,
+ } = self
.window
.rendered_frame
.dispatch_tree
.dispatch_key(&key_down_event.keystroke, &dispatch_path);
+ if self.window.rendered_frame.dispatch_tree.keymatch_mode == KeymatchMode::Immediate
+ && !bindings.is_empty()
+ {
+ pending = false;
+ }
+
if pending {
let mut currently_pending = self.window.pending_input.take().unwrap_or_default();
if currently_pending.focus.is_some() && currently_pending.focus != self.window.focus
@@ -1257,7 +1298,7 @@ impl<'a> WindowContext<'a> {
} else if let Some(currently_pending) = self.window.pending_input.take() {
if bindings
.iter()
- .all(|binding| !currently_pending.used_by_binding(&binding))
+ .all(|binding| !currently_pending.used_by_binding(binding))
{
self.replay_pending_input(currently_pending)
}
@@ -1981,11 +2022,12 @@ impl<'a, V: 'static> ViewContext<'a, V> {
}
}
+ // Always emit a notify effect, so that handlers fire correctly
+ self.window_cx.app.push_effect(Effect::Notify {
+ emitter: self.view.model.entity_id,
+ });
if !self.window.drawing {
self.window_cx.window.dirty = true;
- self.window_cx.app.push_effect(Effect::Notify {
- emitter: self.view.model.entity_id,
- });
}
}
@@ -2560,7 +2602,7 @@ impl Display for ElementId {
ElementId::View(entity_id) => write!(f, "view-{}", entity_id)?,
ElementId::Integer(ix) => write!(f, "{}", ix)?,
ElementId::Name(name) => write!(f, "{}", name)?,
- ElementId::FocusHandle(__) => write!(f, "FocusHandle")?,
+ ElementId::FocusHandle(_) => write!(f, "FocusHandle")?,
ElementId::NamedInteger(s, i) => write!(f, "{}-{}", s, i)?,
}
@@ -2635,7 +2677,7 @@ impl From<(&'static str, u64)> for ElementId {
}
/// A rectangle to be rendered in the window at the given position and size.
-/// Passed as an argument [`WindowContext::paint_quad`].
+/// Passed as an argument [`ElementContext::paint_quad`].
#[derive(Clone)]
pub struct PaintQuad {
bounds: Bounds<Pixels>,
@@ -2717,3 +2759,59 @@ pub fn outline(bounds: impl Into<Bounds<Pixels>>, border_color: impl Into<Hsla>)
border_color: border_color.into(),
}
}
+
+#[cfg(test)]
+mod test {
+
+ use std::{cell::RefCell, rc::Rc};
+
+ use crate::{
+ self as gpui, div, FocusHandle, InteractiveElement, IntoElement, Render, TestAppContext,
+ ViewContext, VisualContext,
+ };
+
+ #[gpui::test]
+ fn test_notify_on_focus(cx: &mut TestAppContext) {
+ struct TestFocusView {
+ handle: FocusHandle,
+ }
+
+ impl Render for TestFocusView {
+ fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
+ div().id("test").track_focus(&self.handle)
+ }
+ }
+
+ let notify_counter = Rc::new(RefCell::new(0));
+
+ let (notify_producer, cx) = cx.add_window_view(|cx| {
+ cx.activate_window();
+ let handle = cx.focus_handle();
+
+ cx.on_focus(&handle, |_, cx| {
+ cx.notify();
+ })
+ .detach();
+
+ TestFocusView { handle }
+ });
+
+ let focus_handle = cx.update(|cx| notify_producer.read(cx).handle.clone());
+
+ let _notify_consumer = cx.new_view({
+ |cx| {
+ let notify_counter = notify_counter.clone();
+ cx.observe(¬ify_producer, move |_, _, _| {
+ *notify_counter.borrow_mut() += 1;
+ })
+ .detach();
+ }
+ });
+
+ cx.update(|cx| {
+ cx.focus(&focus_handle);
+ });
+
+ assert_eq!(*notify_counter.borrow(), 1);
+ }
+}
@@ -1,3 +1,17 @@
+//! The element context is the main interface for interacting with the frame during a paint.
+//!
+//! Elements are hierarchical and with a few exceptions the context accumulates state in a stack
+//! as it processes all of the elements in the frame. The methods that interact with this stack
+//! are generally marked with `with_*`, and take a callback to denote the region of code that
+//! should be executed with that state.
+//!
+//! The other main interface is the `paint_*` family of methods, which push basic drawing commands
+//! to the GPU. Everything in a GPUI app is drawn with these methods.
+//!
+//! There are also several internal methods that GPUI uses, such as [`ElementContext::with_element_state`]
+//! to call the paint and layout methods on elements. These have been included as they're often useful
+//! for taking manual control of the layouting or painting of specialized elements.
+
use std::{
any::{Any, TypeId},
borrow::{Borrow, BorrowMut, Cow},
@@ -17,11 +31,11 @@ use crate::{
prelude::*, size, AnyTooltip, AppContext, AvailableSpace, Bounds, BoxShadow, ContentMask,
Corners, CursorStyle, DevicePixels, DispatchPhase, DispatchTree, ElementId, ElementStateBox,
EntityId, FocusHandle, FocusId, FontId, GlobalElementId, GlyphId, Hsla, ImageData,
- InputHandler, IsZero, KeyContext, KeyEvent, LayoutId, MonochromeSprite, MouseEvent, PaintQuad,
- Path, Pixels, PlatformInputHandler, Point, PolychromeSprite, Quad, RenderGlyphParams,
- RenderImageParams, RenderSvgParams, Scene, Shadow, SharedString, Size, StackingContext,
- StackingOrder, Style, Surface, TextStyleRefinement, Underline, UnderlineStyle, Window,
- WindowContext, SUBPIXEL_VARIANTS,
+ InputHandler, IsZero, KeyContext, KeyEvent, KeymatchMode, LayoutId, MonochromeSprite,
+ MouseEvent, PaintQuad, Path, Pixels, PlatformInputHandler, Point, PolychromeSprite, Quad,
+ RenderGlyphParams, RenderImageParams, RenderSvgParams, Scene, Shadow, SharedString, Size,
+ StackingContext, StackingOrder, Style, Surface, TextStyleRefinement, Underline, UnderlineStyle,
+ Window, WindowContext, SUBPIXEL_VARIANTS,
};
type AnyMouseListener = Box<dyn FnMut(&dyn Any, DispatchPhase, &mut ElementContext) + 'static>;
@@ -153,6 +167,9 @@ pub struct ElementContext<'a> {
}
impl<'a> WindowContext<'a> {
+ /// Convert this window context into an ElementContext in this callback.
+ /// If you need to use this method, you're probably intermixing the imperative
+ /// and declarative APIs, which is not recommended.
pub fn with_element_context<R>(&mut self, f: impl FnOnce(&mut ElementContext) -> R) -> R {
f(&mut ElementContext {
cx: WindowContext::new(self.app, self.window),
@@ -338,6 +355,8 @@ impl<'a> ElementContext<'a> {
self.window.next_frame.next_stacking_order_id = next_stacking_order_id;
}
+ /// Push a text style onto the stack, and call a function with that style active.
+ /// Use [`AppContext::text_style`] to get the current, combined text style.
pub fn with_text_style<F, R>(&mut self, style: Option<TextStyleRefinement>, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
@@ -637,7 +656,7 @@ impl<'a> ElementContext<'a> {
/// Paint one or more quads into the scene for the next frame at the current stacking context.
/// Quads are colored rectangular regions with an optional background, border, and corner radius.
- /// see [`fill`], [`outline`], and [`quad`] to construct this type.
+ /// see [`fill`](crate::fill), [`outline`](crate::outline), and [`quad`](crate::quad) to construct this type.
pub fn paint_quad(&mut self, quad: PaintQuad) {
let scale_factor = self.scale_factor();
let content_mask = self.content_mask();
@@ -712,8 +731,12 @@ impl<'a> ElementContext<'a> {
);
}
- /// Paint a monochrome (non-emoji) glyph into the scene for the next frame at the current z-index.
+ /// Paints a monochrome (non-emoji) glyph into the scene for the next frame at the current z-index.
+ ///
/// The y component of the origin is the baseline of the glyph.
+ /// You should generally prefer to use the [`ShapedLine::paint`](crate::ShapedLine::paint) or
+ /// [`WrappedLine::paint`](crate::WrappedLine::paint) methods in the [`TextSystem`](crate::TextSystem).
+ /// This method is only useful if you need to paint a single glyph that has already been shaped.
pub fn paint_glyph(
&mut self,
origin: Point<Pixels>,
@@ -769,8 +792,12 @@ impl<'a> ElementContext<'a> {
Ok(())
}
- /// Paint an emoji glyph into the scene for the next frame at the current z-index.
+ /// Paints an emoji glyph into the scene for the next frame at the current z-index.
+ ///
/// The y component of the origin is the baseline of the glyph.
+ /// You should generally prefer to use the [`ShapedLine::paint`](crate::ShapedLine::paint) or
+ /// [`WrappedLine::paint`](crate::WrappedLine::paint) methods in the [`TextSystem`](crate::TextSystem).
+ /// This method is only useful if you need to paint a single emoji that has already been shaped.
pub fn paint_emoji(
&mut self,
origin: Point<Pixels>,
@@ -979,9 +1006,8 @@ impl<'a> ElementContext<'a> {
self.window.layout_engine = Some(layout_engine);
}
- /// Obtain the bounds computed for the given LayoutId relative to the window. This method should not
- /// be invoked until the paint phase begins, and will usually be invoked by GPUI itself automatically
- /// in order to pass your element its `Bounds` automatically.
+ /// Obtain the bounds computed for the given LayoutId relative to the window. This method will usually be invoked by
+ /// GPUI itself automatically in order to pass your element its `Bounds` automatically.
pub fn layout_bounds(&mut self, layout_id: LayoutId) -> Bounds<Pixels> {
let mut bounds = self
.window
@@ -1040,7 +1066,7 @@ impl<'a> ElementContext<'a> {
let text_system = self.text_system().clone();
text_system.with_view(view_id, || {
if self.window.next_frame.view_stack.last() == Some(&view_id) {
- return f(self);
+ f(self)
} else {
self.window.next_frame.view_stack.push(view_id);
let result = f(self);
@@ -1056,7 +1082,7 @@ impl<'a> ElementContext<'a> {
let text_system = self.text_system().clone();
text_system.with_view(view_id, || {
if self.window.next_frame.view_stack.last() == Some(&view_id) {
- return f(self);
+ f(self)
} else {
self.window.next_frame.view_stack.push(view_id);
self.window
@@ -1090,6 +1116,15 @@ impl<'a> ElementContext<'a> {
}
}
+ /// keymatch mode immediate instructs GPUI to prefer shorter action bindings.
+ /// In the case that you have a keybinding of `"cmd-k": "terminal::Clear"` and
+ /// `"cmd-k left": "workspace::MoveLeft"`, GPUI will by default wait for 1s after
+ /// you type cmd-k to see if you're going to type left.
+ /// This is problematic in the terminal
+ pub fn keymatch_mode_immediate(&mut self) {
+ self.window.next_frame.dispatch_tree.keymatch_mode = KeymatchMode::Immediate;
+ }
+
/// Register a mouse event listener on the window for the next frame. The type of event
/// is determined by the first parameter of the given listener. When the next frame is rendered
/// the listener will be cleared.
@@ -3,6 +3,8 @@ name = "gpui_macros"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
+
[lib]
path = "src/gpui_macros.rs"
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -3,6 +3,8 @@ name = "install_cli"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/install_cli.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "journal"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/journal.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "language"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/language.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -23,7 +23,7 @@ use async_trait::async_trait;
use collections::{HashMap, HashSet};
use futures::{
channel::{mpsc, oneshot},
- future::{BoxFuture, Shared},
+ future::Shared,
FutureExt, TryFutureExt as _,
};
use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task};
@@ -216,11 +216,7 @@ impl CachedLspAdapter {
self.adapter.code_action_kinds()
}
- pub fn workspace_configuration(
- &self,
- workspace_root: &Path,
- cx: &mut AppContext,
- ) -> BoxFuture<'static, Value> {
+ pub fn workspace_configuration(&self, workspace_root: &Path, cx: &mut AppContext) -> Value {
self.adapter.workspace_configuration(workspace_root, cx)
}
@@ -345,8 +341,8 @@ pub trait LspAdapter: 'static + Send + Sync {
None
}
- fn workspace_configuration(&self, _: &Path, _: &mut AppContext) -> BoxFuture<'static, Value> {
- futures::future::ready(serde_json::json!({})).boxed()
+ fn workspace_configuration(&self, _: &Path, _: &mut AppContext) -> Value {
+ serde_json::json!({})
}
/// Returns a list of code actions supported by a given LspAdapter
@@ -3,6 +3,8 @@ name = "language_selector"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/language_selector.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "language_tools"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/language_tools.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2021"
description = "Bindings to LiveKit Swift client SDK"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/live_kit_client.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2021"
description = "SDK for the LiveKit server API"
publish = false
+license = "AGPL-3.0-only"
+
[lib]
path = "src/live_kit_server.rs"
@@ -0,0 +1 @@
+../../LICENSE-AGPL
@@ -3,6 +3,8 @@ name = "lsp"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/lsp.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "media"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
+
[lib]
path = "src/media.rs"
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -108,6 +108,9 @@ pub mod core_video {
impl_CFTypeDescription!(CVMetalTextureCache);
impl CVMetalTextureCache {
+ /// # Safety
+ ///
+ /// metal_device must be valid according to CVMetalTextureCacheCreate
pub unsafe fn new(metal_device: *mut MTLDevice) -> Result<Self> {
let mut this = ptr::null();
let result = CVMetalTextureCacheCreate(
@@ -124,6 +127,9 @@ pub mod core_video {
}
}
+ /// # Safety
+ ///
+ /// The arguments to this function must be valid according to CVMetalTextureCacheCreateTextureFromImage
pub unsafe fn create_texture_from_image(
&self,
source: CVImageBufferRef,
@@ -434,6 +440,12 @@ pub mod video_toolbox {
impl_CFTypeDescription!(VTCompressionSession);
impl VTCompressionSession {
+ /// Create a new compression session.
+ ///
+ /// # Safety
+ ///
+ /// The callback must be a valid function pointer. and the callback_data must be valid
+ /// in whatever terms that callback expects.
pub unsafe fn new(
width: usize,
height: usize,
@@ -465,6 +477,9 @@ pub mod video_toolbox {
}
}
+ /// # Safety
+ ///
+ /// The arguments to this function must be valid according to VTCompressionSessionEncodeFrame
pub unsafe fn encode_frame(
&self,
buffer: CVImageBufferRef,
@@ -3,6 +3,8 @@ name = "menu"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/menu.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "multi_buffer"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/multi_buffer.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "node_runtime"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/node_runtime.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "notifications"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/notification_store.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "outline"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/outline.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "picker"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/picker.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -5,7 +5,7 @@ use gpui::{
View, ViewContext, WindowContext,
};
use std::sync::Arc;
-use ui::{prelude::*, v_flex, Color, Divider, Label, ListItem, ListItemSpacing, ListSeparator};
+use ui::{prelude::*, v_flex, Color, Divider, Label, ListItem, ListItemSpacing};
use workspace::ModalView;
pub struct Picker<D: PickerDelegate> {
@@ -296,7 +296,12 @@ impl<D: PickerDelegate> Render for Picker<D> {
ix,
ix == selected_index,
cx,
- )).when(separators_after_indices.contains(&ix), |picker| picker.child(ListSeparator))
+ )).when(separators_after_indices.contains(&ix), |picker| {
+ picker
+ .border_color(cx.theme().colors().border_variant)
+ .border_b_1()
+ .pb(px(-1.0))
+ })
})
.collect()
}
@@ -3,6 +3,8 @@ name = "plugin"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[dependencies]
serde.workspace = true
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "plugin_macros"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
proc-macro = true
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "plugin_runtime"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[dependencies]
wasmtime = "2.0"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "prettier"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/prettier.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "project"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/project.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -16,7 +16,7 @@ use language::{
language_settings::{Formatter, LanguageSettings},
Buffer, Language, LanguageServerName, LocalFile,
};
-use lsp::LanguageServerId;
+use lsp::{LanguageServer, LanguageServerId};
use node_runtime::NodeRuntime;
use prettier::Prettier;
use util::{paths::DEFAULT_PRETTIER_DIR, ResultExt, TryFutureExt};
@@ -212,6 +212,10 @@ impl PrettierInstance {
},
})
}
+
+ pub async fn server(&self) -> Option<Arc<LanguageServer>> {
+ self.prettier.clone()?.await.ok()?.server().cloned()
+ }
}
fn start_default_prettier(
@@ -632,7 +632,7 @@ impl Project {
let copilot_lsp_subscription =
Copilot::global(cx).map(|copilot| subscribe_for_copilot_events(&copilot, cx));
Self {
- worktrees: Default::default(),
+ worktrees: Vec::new(),
buffer_ordered_messages_tx: tx,
collaborators: Default::default(),
next_buffer_id: 0,
@@ -664,7 +664,7 @@ impl Project {
next_diagnostic_group_id: Default::default(),
supplementary_language_servers: HashMap::default(),
language_servers: Default::default(),
- language_server_ids: Default::default(),
+ language_server_ids: HashMap::default(),
language_server_statuses: Default::default(),
last_workspace_edits_by_language_server: Default::default(),
buffers_being_formatted: Default::default(),
@@ -752,7 +752,7 @@ impl Project {
},
supplementary_language_servers: HashMap::default(),
language_servers: Default::default(),
- language_server_ids: Default::default(),
+ language_server_ids: HashMap::default(),
language_server_statuses: response
.payload
.language_servers
@@ -2700,7 +2700,7 @@ impl Project {
});
cx.spawn(move |this, mut cx| async move {
- while let Some(_) = settings_changed_rx.next().await {
+ while let Some(()) = settings_changed_rx.next().await {
let servers: Vec<_> = this.update(&mut cx, |this, _| {
this.language_servers
.values()
@@ -2714,9 +2714,8 @@ impl Project {
})?;
for (adapter, server) in servers {
- let workspace_config = cx
- .update(|cx| adapter.workspace_configuration(server.root_path(), cx))?
- .await;
+ let workspace_config =
+ cx.update(|cx| adapter.workspace_configuration(server.root_path(), cx))?;
server
.notify::<lsp::notification::DidChangeConfiguration>(
lsp::DidChangeConfigurationParams {
@@ -3020,9 +3019,8 @@ impl Project {
server_id: LanguageServerId,
cx: &mut AsyncAppContext,
) -> Result<Arc<LanguageServer>> {
- let workspace_config = cx
- .update(|cx| adapter.workspace_configuration(worktree_path, cx))?
- .await;
+ let workspace_config =
+ cx.update(|cx| adapter.workspace_configuration(worktree_path, cx))?;
let language_server = pending_server.task.await?;
language_server
@@ -3056,9 +3054,8 @@ impl Project {
let adapter = adapter.clone();
let worktree_path = worktree_path.clone();
async move {
- let workspace_config = cx
- .update(|cx| adapter.workspace_configuration(&worktree_path, cx))?
- .await;
+ let workspace_config =
+ cx.update(|cx| adapter.workspace_configuration(&worktree_path, cx))?;
Ok(params
.items
.into_iter()
@@ -3906,7 +3903,7 @@ impl Project {
source: diagnostic.source.clone(),
code: code.clone(),
severity: diagnostic.severity.unwrap_or(DiagnosticSeverity::ERROR),
- message: diagnostic.message.clone(),
+ message: diagnostic.message.trim().to_string(),
group_id,
is_primary: true,
is_disk_based,
@@ -3923,7 +3920,7 @@ impl Project {
source: diagnostic.source.clone(),
code: code.clone(),
severity: DiagnosticSeverity::INFORMATION,
- message: info.message.clone(),
+ message: info.message.trim().to_string(),
group_id,
is_primary: false,
is_disk_based,
@@ -6370,6 +6367,55 @@ impl Project {
}
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext<Self>) {
+ let mut servers_to_remove = HashMap::default();
+ let mut servers_to_preserve = HashSet::default();
+ for ((worktree_id, server_name), &server_id) in &self.language_server_ids {
+ if worktree_id == &id_to_remove {
+ servers_to_remove.insert(server_id, server_name.clone());
+ } else {
+ servers_to_preserve.insert(server_id);
+ }
+ }
+ servers_to_remove.retain(|server_id, _| !servers_to_preserve.contains(server_id));
+ for (server_id_to_remove, server_name) in servers_to_remove {
+ self.language_server_ids
+ .remove(&(id_to_remove, server_name));
+ self.language_server_statuses.remove(&server_id_to_remove);
+ self.last_workspace_edits_by_language_server
+ .remove(&server_id_to_remove);
+ self.language_servers.remove(&server_id_to_remove);
+ cx.emit(Event::LanguageServerRemoved(server_id_to_remove));
+ }
+
+ let mut prettier_instances_to_clean = FuturesUnordered::new();
+ if let Some(prettier_paths) = self.prettiers_per_worktree.remove(&id_to_remove) {
+ for path in prettier_paths.iter().flatten() {
+ if let Some(prettier_instance) = self.prettier_instances.remove(path) {
+ prettier_instances_to_clean.push(async move {
+ prettier_instance
+ .server()
+ .await
+ .map(|server| server.server_id())
+ });
+ }
+ }
+ }
+ cx.spawn(|project, mut cx| async move {
+ while let Some(prettier_server_id) = prettier_instances_to_clean.next().await {
+ if let Some(prettier_server_id) = prettier_server_id {
+ project
+ .update(&mut cx, |project, cx| {
+ project
+ .supplementary_language_servers
+ .remove(&prettier_server_id);
+ cx.emit(Event::LanguageServerRemoved(prettier_server_id));
+ })
+ .ok();
+ }
+ }
+ })
+ .detach();
+
self.worktrees.retain(|worktree| {
if let Some(worktree) = worktree.upgrade() {
let id = worktree.read(cx).id();
@@ -3,6 +3,8 @@ name = "project_panel"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/project_panel.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -1352,6 +1352,8 @@ impl ProjectPanel {
})
.unwrap_or(if is_selected {
Color::Default
+ } else if details.is_ignored {
+ Color::Disabled
} else {
Color::Muted
});
@@ -3,6 +3,8 @@ name = "project_symbols"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/project_symbols.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "quick_action_bar"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/quick_action_bar.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "recent_projects"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/recent_projects.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "refineable"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
+
[lib]
path = "src/refineable.rs"
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -3,6 +3,7 @@ name = "derive_refineable"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
[lib]
path = "src/derive_refineable.rs"
@@ -0,0 +1 @@
+../../../LICENSE-APACHE
@@ -245,10 +245,14 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
}
let gen = quote! {
+ /// A refinable version of [`#ident`], see that documentation for details.
#[derive(Clone)]
#derive_stream
pub struct #refinement_ident #impl_generics {
- #( #field_visibilities #field_names: #wrapped_types ),*
+ #(
+ #[allow(missing_docs)]
+ #field_visibilities #field_names: #wrapped_types
+ ),*
}
impl #impl_generics Refineable for #ident #ty_generics
@@ -304,6 +308,7 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
impl #impl_generics #refinement_ident #ty_generics
#where_clause
{
+ /// Returns `true` if all fields are `Some`
pub fn is_some(&self) -> bool {
#(
if self.#field_names.is_some() {
@@ -3,6 +3,8 @@ name = "rich_text"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/rich_text.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "rope"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/rope.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -4,6 +4,8 @@ edition = "2021"
name = "rpc"
version = "0.1.0"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/rpc.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "search"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/search.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -396,8 +396,8 @@ impl ToolbarItemView for BufferSearchBar {
{
let this = cx.view().downgrade();
- searchable_item_handle
- .subscribe_to_search_events(
+ self.active_searchable_item_subscription =
+ Some(searchable_item_handle.subscribe_to_search_events(
cx,
Box::new(move |search_event, cx| {
if let Some(this) = this.upgrade() {
@@ -406,8 +406,7 @@ impl ToolbarItemView for BufferSearchBar {
});
}
}),
- )
- .detach();
+ ));
self.active_searchable_item = Some(searchable_item_handle);
let _ = self.update_matches(cx);
@@ -3,6 +3,8 @@ name = "semantic_index"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/semantic_index.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -90,13 +90,12 @@ pub fn init(
.detach();
cx.spawn(move |cx| async move {
+ let embedding_provider =
+ OpenAIEmbeddingProvider::new(http_client, cx.background_executor().clone()).await;
let semantic_index = SemanticIndex::new(
fs,
db_file_path,
- Arc::new(OpenAIEmbeddingProvider::new(
- http_client,
- cx.background_executor().clone(),
- )),
+ Arc::new(embedding_provider),
language_registry,
cx.clone(),
)
@@ -279,14 +278,22 @@ impl SemanticIndex {
.map(|semantic_index| semantic_index.clone())
}
- pub fn authenticate(&mut self, cx: &mut AppContext) -> bool {
+ pub fn authenticate(&mut self, cx: &mut AppContext) -> Task<bool> {
if !self.embedding_provider.has_credentials() {
- self.embedding_provider.retrieve_credentials(cx);
+ let embedding_provider = self.embedding_provider.clone();
+ cx.spawn(|cx| async move {
+ if let Some(retrieve_credentials) = cx
+ .update(|cx| embedding_provider.retrieve_credentials(cx))
+ .log_err()
+ {
+ retrieve_credentials.await;
+ }
+
+ embedding_provider.has_credentials()
+ })
} else {
- return true;
+ Task::ready(true)
}
-
- self.embedding_provider.has_credentials()
}
pub fn is_authenticated(&self) -> bool {
@@ -1006,12 +1013,26 @@ impl SemanticIndex {
project: Model<Project>,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
- if !self.is_authenticated() {
- if !self.authenticate(cx) {
- return Task::ready(Err(anyhow!("user is not authenticated")));
- }
+ if self.is_authenticated() {
+ self.index_project_internal(project, cx)
+ } else {
+ let authenticate = self.authenticate(cx);
+ cx.spawn(|this, mut cx| async move {
+ if authenticate.await {
+ this.update(&mut cx, |this, cx| this.index_project_internal(project, cx))?
+ .await
+ } else {
+ Err(anyhow!("user is not authenticated"))
+ }
+ })
}
+ }
+ fn index_project_internal(
+ &mut self,
+ project: Model<Project>,
+ cx: &mut ModelContext<Self>,
+ ) -> Task<Result<()>> {
if !self.projects.contains_key(&project.downgrade()) {
let subscription = cx.subscribe(&project, |this, project, event, cx| match event {
project::Event::WorktreeAdded | project::Event::WorktreeRemoved(_) => {
@@ -3,6 +3,8 @@ name = "settings"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/settings.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "snippet"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/snippet.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "sqlez"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[dependencies]
anyhow.workspace = true
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "sqlez_macros"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/sqlez_macros.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "story"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "storybook"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[[bin]]
name = "storybook"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -1,4 +1,4 @@
-use gpui::{px, rgb, Div, Hsla, IntoElement, Render, RenderOnce};
+use gpui::{px, rgb, Div, IntoElement, Render, RenderOnce};
use story::Story;
use ui::prelude::*;
@@ -51,22 +51,22 @@ trait Styles: Styled + Sized {
self.absolute()
.w(px(150.))
.h(px(50.))
- .text_color(rgb::<Hsla>(0x000000))
+ .text_color(rgb(0x000000))
}
fn blue(self) -> Self {
- self.bg(rgb::<Hsla>(0xe5e8fc))
+ self.bg(rgb(0xe5e8fc))
.border_5()
- .border_color(rgb::<Hsla>(0x112382))
+ .border_color(rgb(0x112382))
.line_height(px(55.))
// HACK: Simulate `text-align: center`.
.pl(px(24.))
}
fn red(self) -> Self {
- self.bg(rgb::<Hsla>(0xfce5e7))
+ self.bg(rgb(0xfce5e7))
.border_5()
- .border_color(rgb::<Hsla>(0xe3a1a7))
+ .border_color(rgb(0xe3a1a7))
// HACK: Simulate `text-align: center`.
.pl(px(8.))
}
@@ -92,10 +92,10 @@ impl RenderOnce for ZIndexExample {
.left(px(15.))
.w(px(180.))
.h(px(230.))
- .bg(rgb::<Hsla>(0xfcfbe5))
- .text_color(rgb::<Hsla>(0x000000))
+ .bg(rgb(0xfcfbe5))
+ .text_color(rgb(0x000000))
.border_5()
- .border_color(rgb::<Hsla>(0xe3e0a1))
+ .border_color(rgb(0xe3e0a1))
.line_height(px(215.))
// HACK: Simulate `text-align: center`.
.pl(px(24.))
@@ -3,6 +3,8 @@ name = "sum_tree"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
+
[lib]
path = "src/sum_tree.rs"
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -3,6 +3,8 @@ name = "terminal"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/terminal.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "terminal_view"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/terminal_view.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -762,6 +762,7 @@ impl Element for TerminalElement {
self.interactivity
.paint(bounds, bounds.size, state, cx, |_, _, cx| {
cx.handle_input(&self.focus, terminal_input_handler);
+ cx.keymatch_mode_immediate();
cx.on_key_event({
let this = self.terminal.clone();
@@ -3,6 +3,8 @@ name = "text"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/text.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "theme"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[features]
default = []
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -261,7 +261,7 @@ mod tests {
fn override_a_single_theme_color() {
let mut colors = ThemeColors::light();
- let magenta: Hsla = gpui::rgb(0xff00ff);
+ let magenta: Hsla = gpui::rgb(0xff00ff).into();
assert_ne!(colors.text, magenta);
@@ -279,8 +279,8 @@ mod tests {
fn override_multiple_theme_colors() {
let mut colors = ThemeColors::light();
- let magenta: Hsla = gpui::rgb(0xff00ff);
- let green: Hsla = gpui::rgb(0x00ff00);
+ let magenta: Hsla = gpui::rgb(0xff00ff).into();
+ let green: Hsla = gpui::rgb(0x00ff00).into();
assert_ne!(colors.text, magenta);
assert_ne!(colors.background, green);
@@ -305,7 +305,7 @@ mod tests {
}))
.unwrap();
- assert_eq!(colors.background, Some(gpui::rgb(0xff00ff)));
- assert_eq!(colors.text, Some(gpui::rgb(0xff0000)));
+ assert_eq!(colors.background, Some(gpui::rgb(0xff00ff).into()));
+ assert_eq!(colors.text, Some(gpui::rgb(0xff0000).into()));
}
}
@@ -3,6 +3,8 @@ name = "theme_importer"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[dependencies]
any_ascii = "0.3.2"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "theme_selector"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/theme_selector.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "ui"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
name = "ui"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "util"
version = "0.1.0"
edition = "2021"
publish = false
+license = "Apache-2.0"
+
[lib]
path = "src/util.rs"
@@ -0,0 +1 @@
+../../LICENSE-APACHE
@@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+license = "GPL-3.0-only"
+
[dependencies]
fuzzy = { path = "../fuzzy"}
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "vim"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/vim.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "welcome"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/welcome.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -3,6 +3,8 @@ name = "workspace"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
[lib]
path = "src/workspace.rs"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -342,7 +342,16 @@ impl Pane {
}
pub fn has_focus(&self, cx: &WindowContext) -> bool {
+ // We not only check whether our focus handle contains focus, but also
+ // whether the active_item might have focus, because we might have just activated an item
+ // but that hasn't rendered yet.
+ // So before the next render, we might have transferred focus
+ // to the item and `focus_handle.contains_focus` returns false because the `active_item`
+ // is not hooked up to us in the dispatch tree.
self.focus_handle.contains_focused(cx)
+ || self
+ .active_item()
+ .map_or(false, |item| item.focus_handle(cx).contains_focused(cx))
}
fn focus_in(&mut self, cx: &mut ViewContext<Self>) {
@@ -1470,7 +1479,7 @@ impl Pane {
),
)
})
- .when(self.was_focused || self.has_focus(cx), |tab_bar| {
+ .when(self.has_focus(cx), |tab_bar| {
tab_bar.end_child({
let render_tab_buttons = self.render_tab_bar_buttons.clone();
render_tab_buttons(self, cx)
@@ -233,24 +233,28 @@ impl SerializedPane {
workspace: WeakView<Workspace>,
cx: &mut AsyncWindowContext,
) -> Result<Vec<Option<Box<dyn ItemHandle>>>> {
- let mut items = Vec::new();
+ let mut item_tasks = Vec::new();
let mut active_item_index = None;
for (index, item) in self.children.iter().enumerate() {
let project = project.clone();
- let item_handle = pane
- .update(cx, |_, cx| {
- if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind) {
- deserializer(project, workspace.clone(), workspace_id, item.item_id, cx)
- } else {
- Task::ready(Err(anyhow::anyhow!(
- "Deserializer does not exist for item kind: {}",
- item.kind
- )))
- }
- })?
- .await
- .log_err();
+ item_tasks.push(pane.update(cx, |_, cx| {
+ if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind) {
+ deserializer(project, workspace.clone(), workspace_id, item.item_id, cx)
+ } else {
+ Task::ready(Err(anyhow::anyhow!(
+ "Deserializer does not exist for item kind: {}",
+ item.kind
+ )))
+ }
+ })?);
+ if item.active {
+ active_item_index = Some(index);
+ }
+ }
+ let mut items = Vec::new();
+ for item_handle in futures::future::join_all(item_tasks).await {
+ let item_handle = item_handle.log_err();
items.push(item_handle.clone());
if let Some(item_handle) = item_handle {
@@ -258,10 +262,6 @@ impl SerializedPane {
pane.add_item(item_handle.clone(), true, true, None, cx);
})?;
}
-
- if item.active {
- active_item_index = Some(index);
- }
}
if let Some(active_item_index) = active_item_index {
@@ -4,6 +4,8 @@ edition = "2021"
name = "zed"
version = "0.119.17"
publish = false
+license = "GPL-3.0-only"
+
[lib]
name = "zed"
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
use async_trait::async_trait;
use collections::HashMap;
use feature_flags::FeatureFlagAppExt;
-use futures::{future::BoxFuture, FutureExt, StreamExt};
+use futures::StreamExt;
use gpui::AppContext;
use language::{LanguageRegistry, LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
@@ -13,7 +13,6 @@ use smol::fs;
use std::{
any::Any,
ffi::OsString,
- future,
path::{Path, PathBuf},
sync::Arc,
};
@@ -107,7 +106,7 @@ impl LspAdapter for JsonLspAdapter {
&self,
_workspace_root: &Path,
cx: &mut AppContext,
- ) -> BoxFuture<'static, serde_json::Value> {
+ ) -> serde_json::Value {
let action_names = cx.all_action_names();
let staff_mode = cx.is_staff();
let language_names = &self.languages.language_names();
@@ -119,7 +118,7 @@ impl LspAdapter for JsonLspAdapter {
cx,
);
- future::ready(serde_json::json!({
+ serde_json::json!({
"json": {
"format": {
"enable": true,
@@ -138,8 +137,7 @@ impl LspAdapter for JsonLspAdapter {
}
]
}
- }))
- .boxed()
+ })
}
async fn language_ids(&self) -> HashMap<String, String> {
@@ -1,10 +1,7 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use collections::HashMap;
-use futures::{
- future::{self, BoxFuture},
- FutureExt, StreamExt,
-};
+use futures::StreamExt;
use gpui::AppContext;
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
@@ -107,17 +104,12 @@ impl LspAdapter for TailwindLspAdapter {
}))
}
- fn workspace_configuration(
- &self,
- _workspace_root: &Path,
- _: &mut AppContext,
- ) -> BoxFuture<'static, Value> {
- future::ready(json!({
+ fn workspace_configuration(&self, _workspace_root: &Path, _: &mut AppContext) -> Value {
+ json!({
"tailwindCSS": {
"emmetCompletions": true,
}
- }))
- .boxed()
+ })
}
async fn language_ids(&self) -> HashMap<String, String> {
@@ -3,7 +3,6 @@ use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
use async_trait::async_trait;
use collections::HashMap;
-use futures::{future::BoxFuture, FutureExt};
use gpui::AppContext;
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::{CodeActionKind, LanguageServerBinary};
@@ -13,7 +12,6 @@ use smol::{fs, io::BufReader, stream::StreamExt};
use std::{
any::Any,
ffi::OsString,
- future,
path::{Path, PathBuf},
sync::Arc,
};
@@ -212,12 +210,8 @@ impl EsLintLspAdapter {
#[async_trait]
impl LspAdapter for EsLintLspAdapter {
- fn workspace_configuration(
- &self,
- workspace_root: &Path,
- _: &mut AppContext,
- ) -> BoxFuture<'static, Value> {
- future::ready(json!({
+ fn workspace_configuration(&self, workspace_root: &Path, _: &mut AppContext) -> Value {
+ json!({
"": {
"validate": "on",
"rulesCustomizations": [],
@@ -230,8 +224,7 @@ impl LspAdapter for EsLintLspAdapter {
.unwrap_or_else(|| workspace_root.as_os_str()),
},
}
- }))
- .boxed()
+ })
}
async fn name(&self) -> LanguageServerName {
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
-use futures::{future::BoxFuture, FutureExt, StreamExt};
+use futures::StreamExt;
use gpui::AppContext;
use language::{
language_settings::all_language_settings, LanguageServerName, LspAdapter, LspAdapterDelegate,
@@ -12,7 +12,6 @@ use smol::fs;
use std::{
any::Any,
ffi::OsString,
- future,
path::{Path, PathBuf},
sync::Arc,
};
@@ -93,24 +92,17 @@ impl LspAdapter for YamlLspAdapter {
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &*self.node).await
}
- fn workspace_configuration(
- &self,
- _workspace_root: &Path,
- cx: &mut AppContext,
- ) -> BoxFuture<'static, Value> {
- let tab_size = all_language_settings(None, cx)
- .language(Some("YAML"))
- .tab_size;
-
- future::ready(serde_json::json!({
+ fn workspace_configuration(&self, _workspace_root: &Path, cx: &mut AppContext) -> Value {
+ serde_json::json!({
"yaml": {
"keyOrdering": false
},
"[yaml]": {
- "editor.tabSize": tab_size,
+ "editor.tabSize": all_language_settings(None, cx)
+ .language(Some("YAML"))
+ .tab_size,
}
- }))
- .boxed()
+ })
}
}
@@ -376,7 +376,7 @@ async fn authenticate(client: Arc<Client>, cx: &AsyncAppContext) -> Result<()> {
if client::IMPERSONATE_LOGIN.is_some() {
client.authenticate_and_connect(false, &cx).await?;
}
- } else if client.has_keychain_credentials(&cx) {
+ } else if client.has_keychain_credentials(&cx).await {
client.authenticate_and_connect(true, &cx).await?;
}
Ok::<_, anyhow::Error>(())
@@ -493,7 +493,6 @@ struct Panic {
#[derive(Serialize)]
struct PanicRequest {
panic: Panic,
- token: String,
}
static PANIC_COUNT: AtomicU32 = AtomicU32::new(0);
@@ -657,11 +656,7 @@ async fn upload_previous_panics(
});
if let Some(panic) = panic {
- let body = serde_json::to_string(&PanicRequest {
- panic,
- token: client::ZED_SECRET_CLIENT_TOKEN.into(),
- })
- .unwrap();
+ let body = serde_json::to_string(&PanicRequest { panic }).unwrap();
let request = Request::post(&panic_report_url)
.redirect_policy(isahc::config::RedirectPolicy::Follow)
@@ -727,10 +722,6 @@ async fn upload_previous_crashes(
let request = Request::post(&crash_report_url)
.redirect_policy(isahc::config::RedirectPolicy::Follow)
.header("Content-Type", "text/plain")
- .header(
- "Authorization",
- format!("token {}", client::ZED_SECRET_CLIENT_TOKEN),
- )
.body(body.into())?;
let response = http.send(request).await.context("error sending crash")?;
@@ -20,9 +20,10 @@ use assets::Assets;
use futures::{channel::mpsc, select_biased, StreamExt};
use project_panel::ProjectPanel;
use quick_action_bar::QuickActionBar;
+use rope::Rope;
use search::project_search::ProjectSearchBar;
use settings::{initial_local_settings_content, KeymapFile, Settings, SettingsStore};
-use std::{borrow::Cow, ops::Deref, sync::Arc};
+use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc};
use terminal_view::terminal_panel::{self, TerminalPanel};
use util::{
asset_str,
@@ -256,16 +257,16 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
)
.register_action(
move |_: &mut Workspace, _: &OpenKeymap, cx: &mut ViewContext<Workspace>| {
- create_and_open_local_file(&paths::KEYMAP, cx, Default::default)
- .detach_and_log_err(cx);
+ open_settings_file(&paths::KEYMAP, Rope::default, cx);
},
)
.register_action(
move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
- create_and_open_local_file(&paths::SETTINGS, cx, || {
- settings::initial_user_settings_content().as_ref().into()
- })
- .detach_and_log_err(cx);
+ open_settings_file(
+ &paths::SETTINGS,
+ || settings::initial_user_settings_content().as_ref().into(),
+ cx,
+ );
},
)
.register_action(open_local_settings_file)
@@ -723,6 +724,30 @@ fn open_bundled_file(
.detach_and_log_err(cx);
}
+fn open_settings_file(
+ abs_path: &'static Path,
+ default_content: impl FnOnce() -> Rope + Send + 'static,
+ cx: &mut ViewContext<Workspace>,
+) {
+ cx.spawn(|workspace, mut cx| async move {
+ let (worktree_creation_task, settings_open_task) =
+ workspace.update(&mut cx, |workspace, cx| {
+ let worktree_creation_task = workspace.project().update(cx, |project, cx| {
+ // Set up a dedicated worktree for settings, since otherwise we're dropping and re-starting LSP servers for each file inside on every settings file close/open
+ // TODO: Do note that all other external files (e.g. drag and drop from OS) still have their worktrees released on file close, causing LSP servers' restarts.
+ project.find_or_create_local_worktree(paths::CONFIG_DIR.as_path(), false, cx)
+ });
+ let settings_open_task = create_and_open_local_file(&abs_path, cx, default_content);
+ (worktree_creation_task, settings_open_task)
+ })?;
+
+ let _ = worktree_creation_task.await?;
+ let _ = settings_open_task.await?;
+ anyhow::Ok(())
+ })
+ .detach_and_log_err(cx);
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -2680,11 +2705,6 @@ mod tests {
.unwrap()
.to_vec()
.into(),
- Assets
- .load("fonts/plex/IBMPlexSans-Regular.ttf")
- .unwrap()
- .to_vec()
- .into(),
])
.unwrap();
let themes = ThemeRegistry::default();
@@ -3,6 +3,8 @@ name = "zed_actions"
version = "0.1.0"
edition = "2021"
publish = false
+license = "GPL-3.0-only"
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -0,0 +1 @@
+../../LICENSE-GPL
@@ -2,7 +2,7 @@
## macOS
-Supported versions: Catalina (10.15) - Ventura (13.x).
+Supported versions: Catalina (10.15) - Sonoma (14.x).
{% hint style="info" %}
The implementation of our screen sharing feature makes use of [LiveKit](https://livekit.io). The LiveKit SDK requires macOS Catalina (10.15); consequently, in v0.62.4, we dropped support for earlier macOS versions that we were initially supporting.
@@ -7,6 +7,11 @@ if [[ $# < 1 ]]; then
exit 1
fi
+if ! [[ -d target ]]; then
+ echo "target directory does not exist yet"
+ exit 0
+fi
+
max_size_gb=$1
current_size=$(du -s target | cut -f1)
@@ -41,7 +41,8 @@ def parse_log_file(file_path):
elif 'ยตs' in time_with_unit:
time, unit = time_with_unit[:-2], 'ยตs'
else:
- raise ValueError(f"Invalid time unit in line: {line.strip()}")
+ # Print an error message if we can't parse the line and then continue with rest.
+ print(f'Error: Invalid time unit in line "{line.strip()}". Skipping.', file=sys.stderr)
continue
data['measurement'].append(measurement)
@@ -1,67 +1,70 @@
#!/usr/bin/env node --redirect-warnings=/dev/null
-const fs = require('fs')
-const {randomBytes} = require('crypto')
-const {execFileSync} = require('child_process')
-const {minimizeTestPlan, buildTests, runTests} = require('./randomized-test-minimize');
+const fs = require("fs");
+const { randomBytes } = require("crypto");
+const { execFileSync } = require("child_process");
+const {
+ minimizeTestPlan,
+ buildTests,
+ runTests,
+} = require("./randomized-test-minimize");
-const {ZED_SERVER_URL, ZED_CLIENT_SECRET_TOKEN} = process.env
-if (!ZED_SERVER_URL) throw new Error('Missing env var `ZED_SERVER_URL`')
-if (!ZED_CLIENT_SECRET_TOKEN) throw new Error('Missing env var `ZED_CLIENT_SECRET_TOKEN`')
+const { ZED_SERVER_URL } = process.env;
+if (!ZED_SERVER_URL) throw new Error("Missing env var `ZED_SERVER_URL`");
-main()
+main();
async function main() {
- buildTests()
+ buildTests();
const seed = randomU64();
- const commit = execFileSync(
- 'git',
- ['rev-parse', 'HEAD'],
- {encoding: 'utf8'}
- ).trim()
+ const commit = execFileSync("git", ["rev-parse", "HEAD"], {
+ encoding: "utf8",
+ }).trim();
- console.log("commit:", commit)
- console.log("starting seed:", seed)
+ console.log("commit:", commit);
+ console.log("starting seed:", seed);
- const planPath = 'target/test-plan.json'
- const minPlanPath = 'target/test-plan.min.json'
+ const planPath = "target/test-plan.json";
+ const minPlanPath = "target/test-plan.min.json";
const failingSeed = runTests({
SEED: seed,
SAVE_PLAN: planPath,
ITERATIONS: 50000,
OPERATIONS: 200,
- })
+ });
if (!failingSeed) {
- console.log("tests passed")
- return
+ console.log("tests passed");
+ return;
}
- console.log("found failure at seed", failingSeed)
- const minimizedSeed = minimizeTestPlan(planPath, minPlanPath)
- const minimizedPlan = fs.readFileSync(minPlanPath, 'utf8')
+ console.log("found failure at seed", failingSeed);
+ const minimizedSeed = minimizeTestPlan(planPath, minPlanPath);
+ const minimizedPlan = fs.readFileSync(minPlanPath, "utf8");
- console.log("minimized plan:\n", minimizedPlan)
+ console.log("minimized plan:\n", minimizedPlan);
- const url = `${ZED_SERVER_URL}/api/randomized_test_failure`
+ const url = `${ZED_SERVER_URL}/api/randomized_test_failure`;
const body = {
seed: minimizedSeed,
- token: ZED_CLIENT_SECRET_TOKEN,
plan: JSON.parse(minimizedPlan),
commit: commit,
- }
+ };
await fetch(url, {
- method: 'POST',
- headers: {"Content-Type": "application/json"},
- body: JSON.stringify(body)
- })
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(body),
+ });
- process.exit(1)
+ process.exit(1);
}
function randomU64() {
- const bytes = randomBytes(8)
- const hexString = bytes.reduce(((string, byte) => string + byte.toString(16)), '')
- return BigInt('0x' + hexString).toString(10)
+ const bytes = randomBytes(8);
+ const hexString = bytes.reduce(
+ (string, byte) => string + byte.toString(16),
+ "",
+ );
+ return BigInt("0x" + hexString).toString(10);
}
@@ -10,7 +10,7 @@ extend-exclude = [
# Vim makes heavy use of partial typing tables
"crates/vim/*",
# Editor and file finder rely on partial typing and custom in-string syntax
- "crates/file_finder/src/file_finder.rs",
+ "crates/file_finder/src/file_finder_tests.rs",
"crates/editor/src/editor_tests.rs",
# :/
"crates/collab/migrations/20231009181554_add_release_channel_to_rooms.sql",