Compare commits

...
Sign in to create a new pull request.

29 commits

Author SHA1 Message Date
Antonio Scandurra
f630614196 zed 0.80.6 2023-04-10 08:51:50 +02:00
Antonio Scandurra
d46764856d Merge pull request #2366 from zed-industries/avoid-unwrapping-on-try-send
Don't panic if worktree was dropped before sending path changes
2023-04-10 08:50:53 +02:00
Joseph Lyons
4d066662b1 v0.80.x stable 2023-04-05 13:00:39 -04:00
Joseph T. Lyons
f6d1e82315 Merge pull request #2357 from zed-industries/update-eula
Update EULA
2023-04-05 12:58:37 -04:00
Antonio Scandurra
cd2963eaf0 Merge pull request #2356 from zed-industries/copilot-on-preview
Disable Copilot entirely for stable releases
2023-04-05 16:26:40 +02:00
Antonio Scandurra
5718fb12ad zed 0.80.5 2023-04-05 14:22:36 +02:00
Antonio Scandurra
940478d007 Merge pull request #2355 from zed-industries/refine-copilot
Iterate some more on Copilot
2023-04-05 14:21:52 +02:00
Max Brunsfeld
c1af9aa532 zed 0.80.4 2023-04-04 14:31:33 -07:00
Nate Butler
3ac88f2cbb Merge pull request #2354 from zed-industries/nate/fix-embedded-highlight-in-ruby
Fix embedded highlight in ruby
2023-04-04 14:31:06 -07:00
Antonio Scandurra
3ee9de3536 Merge pull request #2353 from zed-industries/more-intuitive-autocomplete-with-copilot
Match VS Code's behavior when deciding whether to show Copilot suggestion
2023-04-04 14:31:06 -07:00
Antonio Scandurra
4a3efb39cf Merge pull request #2352 from zed-industries/debounce-copilot
Debounce copilot completions
2023-04-04 14:31:06 -07:00
Antonio Scandurra
4213fd8e8a Merge pull request #2351 from zed-industries/more-copilot-enhancements
Fix additional Copilot issues
2023-04-04 14:31:06 -07:00
Mikayla Maki
c4b98b8cf1 Merge pull request #2350 from zed-industries/copilot-disable
Disable copilot unless the staff mode flag is flipped
2023-04-04 14:31:06 -07:00
Mikayla Maki
423ba0d351 Merge pull request #2348 from zed-industries/copilot-feedback
Fix issues from copilot feedback
2023-04-04 14:25:30 -07:00
Antonio Scandurra
613f8e6438 Merge pull request #2347 from zed-industries/disable-yaml-key-ordering
Disable key ordering diagnostic for YAML
2023-04-04 10:01:26 +02:00
Antonio Scandurra
3f20252e92 zed 0.80.3 2023-04-03 15:26:30 +02:00
Antonio Scandurra
f3c9e5d8bc Merge pull request #2345 from zed-industries/autocomplete-vs-copilot
Make autocompletion and copilot mutually exclusive
2023-04-03 15:25:52 +02:00
Antonio Scandurra
b69627c1ad Merge pull request #2344 from zed-industries/copilot-collaboration
Fix Copilot errors when opening buffers that don't exist locally
2023-04-03 15:25:45 +02:00
Joseph Lyons
1f293576f1 zed 0.80.2 2023-03-31 15:50:47 -04:00
Mikayla Maki
b5a1cdfb56 Merge pull request #2338 from zed-industries/more-copilot-bugs
More copilot bugs
2023-03-31 15:49:57 -04:00
Mikayla Maki
8a83086b40 Merge pull request #2340 from zed-industries/fix-json-lsp-remove
Fix bug where JSON LSP would be deleted on installation.
2023-03-31 15:49:48 -04:00
Mikayla Maki
762efb4766 Merge pull request #2336 from zed-industries/respect-languages-alias-in-settings-file
Add support for writing to the langauge_overrides alias in settings
2023-03-31 15:49:38 -04:00
Mikayla Maki
8afaf03852 Merge pull request #2334 from zed-industries/quiet-copilot-loggin
Add handlers for LogMessage and statusNotification to copilot LSP
2023-03-31 15:49:27 -04:00
Joseph Lyons
1fe6356b89 zed 0.80.1 2023-03-31 12:42:59 -04:00
Antonio Scandurra
ef62a097ae Merge pull request #2333 from zed-industries/copilot-improvements
Fix several Copilot bugs
2023-03-31 12:36:11 -04:00
Mikayla Maki
b8397a36c1 Merge pull request #2316 from zed-industries/copilot
🚨 WIP 🚨 Copilot
2023-03-31 12:36:04 -04:00
Max Brunsfeld
017b16dc7b Merge pull request #2325 from zed-industries/tab-map-long-lines
Avoid slowdowns with long lines by skipping tab expansion beyond a certain column
2023-03-31 12:35:55 -04:00
Julia
a6cf8708ff Merge pull request #2332 from zed-industries/per-server-code-action-kinds
Allow each language adapter to provide their own code action kinds array
2023-03-31 12:35:13 -04:00
Joseph Lyons
a4b35821fd v0.80.x preview 2023-03-29 14:12:35 -04:00
129 changed files with 4601 additions and 2501 deletions

82
Cargo.lock generated
View file

@ -1113,7 +1113,6 @@ dependencies = [
"futures 0.3.25", "futures 0.3.25",
"gpui", "gpui",
"image", "image",
"isahc",
"lazy_static", "lazy_static",
"log", "log",
"parking_lot 0.11.2", "parking_lot 0.11.2",
@ -1124,6 +1123,7 @@ dependencies = [
"serde_derive", "serde_derive",
"settings", "settings",
"smol", "smol",
"staff_mode",
"sum_tree", "sum_tree",
"tempfile", "tempfile",
"thiserror", "thiserror",
@ -1332,6 +1332,47 @@ dependencies = [
"theme", "theme",
] ]
[[package]]
name = "copilot"
version = "0.1.0"
dependencies = [
"anyhow",
"async-compression",
"async-tar",
"collections",
"context_menu",
"futures 0.3.25",
"gpui",
"language",
"log",
"lsp",
"node_runtime",
"serde",
"serde_derive",
"settings",
"smol",
"theme",
"util",
"workspace",
]
[[package]]
name = "copilot_button"
version = "0.1.0"
dependencies = [
"anyhow",
"context_menu",
"copilot",
"editor",
"futures 0.3.25",
"gpui",
"settings",
"smol",
"theme",
"util",
"workspace",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.3" version = "0.9.3"
@ -1932,6 +1973,7 @@ dependencies = [
"clock", "clock",
"collections", "collections",
"context_menu", "context_menu",
"copilot",
"ctor", "ctor",
"db", "db",
"drag_and_drop", "drag_and_drop",
@ -3910,6 +3952,23 @@ dependencies = [
"memoffset 0.6.5", "memoffset 0.6.5",
] ]
[[package]]
name = "node_runtime"
version = "0.1.0"
dependencies = [
"anyhow",
"async-compression",
"async-tar",
"futures 0.3.25",
"gpui",
"parking_lot 0.11.2",
"serde",
"serde_derive",
"serde_json",
"smol",
"util",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.1" version = "7.1.1"
@ -5882,12 +5941,14 @@ dependencies = [
"gpui", "gpui",
"json_comments", "json_comments",
"postage", "postage",
"pretty_assertions",
"schemars", "schemars",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"serde_path_to_error", "serde_path_to_error",
"sqlez", "sqlez",
"staff_mode",
"theme", "theme",
"toml", "toml",
"tree-sitter", "tree-sitter",
@ -6298,6 +6359,14 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "staff_mode"
version = "0.1.0"
dependencies = [
"anyhow",
"gpui",
]
[[package]] [[package]]
name = "static_assertions" name = "static_assertions"
version = "1.1.0" version = "1.1.0"
@ -6616,6 +6685,7 @@ dependencies = [
"postage", "postage",
"settings", "settings",
"smol", "smol",
"staff_mode",
"theme", "theme",
"util", "util",
"workspace", "workspace",
@ -7500,11 +7570,15 @@ dependencies = [
"dirs 3.0.2", "dirs 3.0.2",
"futures 0.3.25", "futures 0.3.25",
"git2", "git2",
"isahc",
"lazy_static", "lazy_static",
"log", "log",
"rand 0.8.5", "rand 0.8.5",
"serde",
"serde_json", "serde_json",
"smol",
"tempdir", "tempdir",
"url",
] ]
[[package]] [[package]]
@ -8439,7 +8513,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]] [[package]]
name = "zed" name = "zed"
version = "0.80.0" version = "0.80.6"
dependencies = [ dependencies = [
"activity_indicator", "activity_indicator",
"anyhow", "anyhow",
@ -8460,6 +8534,8 @@ dependencies = [
"collections", "collections",
"command_palette", "command_palette",
"context_menu", "context_menu",
"copilot",
"copilot_button",
"ctor", "ctor",
"db", "db",
"diagnostics", "diagnostics",
@ -8486,6 +8562,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"lsp", "lsp",
"node_runtime",
"num_cpus", "num_cpus",
"outline", "outline",
"parking_lot 0.11.2", "parking_lot 0.11.2",
@ -8509,6 +8586,7 @@ dependencies = [
"simplelog", "simplelog",
"smallvec", "smallvec",
"smol", "smol",
"staff_mode",
"sum_tree", "sum_tree",
"tempdir", "tempdir",
"terminal_view", "terminal_view",

View file

@ -13,6 +13,8 @@ members = [
"crates/collections", "crates/collections",
"crates/command_palette", "crates/command_palette",
"crates/context_menu", "crates/context_menu",
"crates/copilot",
"crates/copilot_button",
"crates/db", "crates/db",
"crates/diagnostics", "crates/diagnostics",
"crates/drag_and_drop", "crates/drag_and_drop",
@ -35,6 +37,7 @@ members = [
"crates/lsp", "crates/lsp",
"crates/media", "crates/media",
"crates/menu", "crates/menu",
"crates/node_runtime",
"crates/outline", "crates/outline",
"crates/picker", "crates/picker",
"crates/plugin", "crates/plugin",
@ -51,6 +54,7 @@ members = [
"crates/snippet", "crates/snippet",
"crates/sqlez", "crates/sqlez",
"crates/sqlez_macros", "crates/sqlez_macros",
"crates/staff_mode",
"crates/sum_tree", "crates/sum_tree",
"crates/terminal", "crates/terminal",
"crates/text", "crates/text",

View file

@ -0,0 +1,12 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.2926 3.48996C3.79162 3.79616 3.44871 4.26316 3.44871 4.93872C3.44871 5.75753 3.65302 6.19648 3.88658 6.43349C4.11948 6.66983 4.47018 6.79529 4.95638 6.79529C5.64158 6.79529 6.23176 6.65786 6.64548 6.37099C7.03216 6.10286 7.32149 5.66636 7.35698 4.91278C7.38386 4.34213 7.36863 3.96084 7.21748 3.68905C7.09721 3.47279 6.81682 3.2089 5.96976 3.11109C5.4731 3.05374 4.81346 3.17162 4.2926 3.48996ZM3.72539 2.5525C4.46348 2.10138 5.36842 1.93724 6.09436 2.02107C7.1336 2.14107 7.8142 2.51324 8.17039 3.15373C8.49569 3.73867 8.47238 4.43479 8.44743 4.96466C8.39736 6.02772 7.95809 6.7938 7.26541 7.27411C6.59976 7.73566 5.75982 7.89249 4.95638 7.89249C4.2936 7.89249 3.61755 7.71967 3.11095 7.20558C2.605 6.69216 2.35705 5.92853 2.35705 4.93872C2.35705 3.80566 2.96744 3.01576 3.72539 2.5525Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.69546 8.97734C7.02432 8.97734 7.29091 9.24528 7.29091 9.57581V10.8725C7.29091 11.203 7.02432 11.471 6.69546 11.471C6.3666 11.471 6.1 11.203 6.1 10.8725V9.57581C6.1 9.24528 6.3666 8.97734 6.69546 8.97734Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.45301 7.32072C2.56382 6.90477 2.81104 6.35118 3.40175 6.17048L3.74851 7.31556C3.74509 7.31822 3.73425 7.32798 3.71842 7.35038C3.68409 7.39897 3.64151 7.48723 3.6034 7.6303C3.52629 7.91973 3.49839 8.31081 3.4984 8.73318V10.8761C3.5122 10.9688 3.52011 11.0083 3.53501 11.0478C3.5474 11.0807 3.57295 11.1339 3.6523 11.2153C3.83266 11.4004 4.24428 11.6866 5.21016 12.1174C5.99398 12.467 6.35125 12.6243 6.68361 12.7078C6.99799 12.7869 7.30564 12.8031 7.99999 12.8031V14C7.31311 14 6.86876 13.9882 6.3946 13.869C5.95125 13.7575 5.49691 13.5549 4.78914 13.2391C4.76868 13.23 4.74801 13.2208 4.72712 13.2115C3.73729 12.77 3.14865 12.4092 2.80139 12.0527C2.61692 11.8634 2.49682 11.6721 2.42136 11.4719C2.35507 11.2961 2.33141 11.1302 2.31663 11.0266C2.31561 11.0194 2.31463 11.0126 2.31369 11.0061L2.30749 10.9632V8.73321C2.30748 8.28334 2.33457 7.76532 2.45301 7.32072Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.83439 7.54965C2.14812 7.21281 2.52306 6.88008 2.81315 6.70729L3.42031 7.737C3.27036 7.82631 2.98468 8.06607 2.7038 8.36764C2.43565 8.65553 2.2592 8.90729 2.19783 9.04784C2.18425 9.16608 2.18871 9.38528 2.22654 9.6452C2.26959 9.94104 2.33715 10.1608 2.37974 10.2387L2.42237 10.3167L2.44057 10.4038C2.46806 10.5353 2.60072 10.7284 2.96139 10.9852C3.24332 11.1859 3.57562 11.3661 3.93098 11.5588C4.00968 11.6015 4.0895 11.6448 4.17017 11.689C4.56251 11.8768 5.17152 12.1512 5.7408 12.3785C6.02948 12.4938 6.30016 12.5938 6.5233 12.664C6.63493 12.6991 6.72826 12.7247 6.802 12.7411C6.87402 12.7571 6.90715 12.7597 6.91166 12.76L6.91213 13.957C6.68654 13.957 6.40667 13.8815 6.16744 13.8062C5.90465 13.7235 5.60351 13.6116 5.30115 13.4909C4.69547 13.2491 4.05361 12.9594 3.64268 12.7623L3.62786 12.7552L3.61345 12.7473C3.54294 12.7085 3.46868 12.6683 3.39187 12.6268C3.03384 12.433 2.62042 12.2092 2.27302 11.9619C1.88328 11.6844 1.44476 11.2894 1.29544 10.735C1.17095 10.4701 1.09192 10.1191 1.04817 9.81844C0.999401 9.48332 0.975841 9.08189 1.03513 8.7778L1.04265 8.73927L1.05511 8.70206C1.18745 8.30673 1.53258 7.87368 1.83439 7.54965Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.59243 10.4347V8.41995H2.78334V10.4347H1.59243Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.7074 3.48996C12.2084 3.79616 12.5513 4.26316 12.5513 4.93872C12.5513 5.75753 12.347 6.19648 12.1134 6.43349C11.8805 6.66983 11.5298 6.79529 11.0436 6.79529C10.3584 6.79529 9.76824 6.65786 9.35452 6.37099C8.96784 6.10286 8.67851 5.66636 8.64302 4.91278C8.61614 4.34213 8.63137 3.96084 8.78252 3.68905C8.90279 3.47279 9.18318 3.2089 10.0302 3.11109C10.5269 3.05374 11.1865 3.17162 11.7074 3.48996ZM12.2746 2.5525C11.5365 2.10138 10.6316 1.93724 9.90564 2.02107C8.8664 2.14107 8.1858 2.51324 7.82961 3.15373C7.50431 3.73867 7.52762 4.43479 7.55258 4.96466C7.60264 6.02772 8.04191 6.7938 8.73459 7.27411C9.40024 7.73566 10.2402 7.89249 11.0436 7.89249C11.7064 7.89249 12.3824 7.71967 12.889 7.20558C13.395 6.69216 13.643 5.92853 13.643 4.93872C13.643 3.80566 13.0326 3.01576 12.2746 2.5525Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.30454 8.97734C8.97568 8.97734 8.70909 9.24528 8.70909 9.57581V10.8725C8.70909 11.203 8.97568 11.471 9.30454 11.471C9.6334 11.471 9.9 11.203 9.9 10.8725V9.57581C9.9 9.24528 9.6334 8.97734 9.30454 8.97734Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.547 7.32072C13.4362 6.90477 13.189 6.35118 12.5982 6.17048L12.2515 7.31556C12.2549 7.31822 12.2658 7.32798 12.2816 7.35038C12.3159 7.39897 12.3585 7.48723 12.3966 7.6303C12.4737 7.91973 12.5016 8.31081 12.5016 8.73318V10.8761C12.4878 10.9688 12.4799 11.0083 12.465 11.0478C12.4526 11.0807 12.427 11.1339 12.3477 11.2153C12.1673 11.4004 11.7557 11.6866 10.7898 12.1174C10.006 12.467 9.64875 12.6243 9.31639 12.7078C9.00201 12.7869 8.69433 12.8031 7.99999 12.8031V14C8.68686 14 9.13124 13.9882 9.6054 13.869C10.0488 13.7575 10.5031 13.5549 11.2109 13.2391C11.2313 13.23 11.252 13.2208 11.2729 13.2115C12.2627 12.77 12.8513 12.4092 13.1986 12.0527C13.3831 11.8634 13.5032 11.6721 13.5786 11.4719C13.6449 11.2961 13.6686 11.1302 13.6834 11.0266C13.6844 11.0194 13.6854 11.0126 13.6863 11.0061L13.6925 10.9632V8.73321C13.6925 8.28334 13.6654 7.76532 13.547 7.32072Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.1656 7.54965C13.8519 7.21281 13.4769 6.88008 13.1868 6.70729L12.5797 7.737C12.7296 7.82631 13.0153 8.06607 13.2962 8.36764C13.5643 8.65553 13.7408 8.90729 13.8022 9.04784C13.8158 9.16608 13.8113 9.38528 13.7735 9.6452C13.7304 9.94104 13.6628 10.1608 13.6203 10.2387L13.5776 10.3167L13.5594 10.4038C13.5319 10.5353 13.3993 10.7284 13.0386 10.9852C12.7567 11.1859 12.4244 11.3661 12.069 11.5588C11.9903 11.6015 11.9105 11.6448 11.8298 11.689C11.4375 11.8768 10.8285 12.1512 10.2592 12.3785C9.97052 12.4938 9.69984 12.5938 9.4767 12.664C9.36507 12.6991 9.27174 12.7247 9.198 12.7411C9.12598 12.7571 9.09285 12.7597 9.08834 12.76L9.08787 13.957C9.31345 13.957 9.59333 13.8815 9.83256 13.8062C10.0953 13.7235 10.3965 13.6116 10.6989 13.4909C11.3045 13.2491 11.9464 12.9594 12.3573 12.7623L12.3721 12.7552L12.3865 12.7473C12.4571 12.7085 12.5313 12.6683 12.6081 12.6268C12.9662 12.433 13.3796 12.2092 13.727 11.9619C14.1167 11.6844 14.5552 11.2894 14.7046 10.735C14.829 10.4701 14.9081 10.1191 14.9518 9.81844C15.0006 9.48332 15.0242 9.08189 14.9649 8.7778L14.9574 8.73927L14.9449 8.70206C14.8126 8.30673 14.4674 7.87368 14.1656 7.54965Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.4076 10.4347V8.41995H13.2167V10.4347H14.4076Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 6.7 KiB

View file

@ -0,0 +1,9 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g opacity="0.5">
<path d="M2.38084 5.44737C2.42754 5.92437 2.54311 6.33779 2.72903 6.68417C2.70043 6.72678 2.67414 6.77043 2.64995 6.81463C2.39071 6.9994 2.09192 7.27314 1.83439 7.54965C1.53258 7.87368 1.18745 8.30673 1.05511 8.70206L1.04265 8.73927L1.03513 8.7778C0.975841 9.08189 0.999401 9.48332 1.04817 9.81844C1.09192 10.1191 1.17095 10.4701 1.29544 10.735C1.44476 11.2894 1.88328 11.6844 2.27302 11.9619C2.6204 12.2092 3.03378 12.4329 3.39179 12.6267C3.4686 12.6683 3.54294 12.7085 3.61345 12.7473L3.62786 12.7552L3.64268 12.7623C4.05361 12.9594 4.69547 13.2491 5.30115 13.4909C5.60351 13.6116 5.90465 13.7235 6.16744 13.8062C6.39236 13.877 6.6532 13.948 6.87108 13.9562C7.19351 13.9948 7.54309 14 7.99999 14C8.45688 14 8.80648 13.9948 9.12892 13.9562C9.34679 13.948 9.60764 13.877 9.83256 13.8062C10.0953 13.7235 10.3965 13.6116 10.6989 13.4909C11.0041 13.369 11.3186 13.235 11.6081 13.1067L10.5467 12.2257C9.92791 12.5006 9.61228 12.6334 9.31639 12.7078C9.00201 12.7869 8.69433 12.8031 7.99999 12.8031C7.30564 12.8031 6.99799 12.7869 6.68361 12.7078C6.35125 12.6243 5.99398 12.467 5.21016 12.1174C4.24428 11.6866 3.83266 11.4004 3.6523 11.2153C3.57295 11.1339 3.5474 11.0807 3.53501 11.0478C3.52011 11.0083 3.5122 10.9688 3.4984 10.8761V8.73318C3.49839 8.31081 3.52629 7.91973 3.6034 7.6303C3.60757 7.61463 3.6118 7.59961 3.61607 7.58523C4.02831 7.80894 4.49555 7.89249 4.95638 7.89249C5.07488 7.89249 5.19417 7.88908 5.31358 7.88178L2.38084 5.44737Z" fill="white"/>
<path d="M6.63684 8.9802C6.3355 9.00979 6.1 9.26516 6.1 9.57581V10.8725C6.1 11.203 6.3666 11.471 6.69546 11.471C7.02432 11.471 7.29091 11.203 7.29091 10.8725V9.57581C7.29091 9.55736 7.29008 9.53911 7.28846 9.52109L6.63684 8.9802Z" fill="white"/>
<path d="M8.70909 10.7003V10.8725C8.70909 11.203 8.97568 11.471 9.30454 11.471C9.39795 11.471 9.48633 11.4493 9.56501 11.4108L8.70909 10.7003Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.09436 2.02107C5.38898 1.93962 4.51459 2.09228 3.78849 2.51486L4.71538 3.28426C5.1409 3.1227 5.6004 3.06844 5.96976 3.11109C6.81682 3.2089 7.09721 3.4728 7.21748 3.68905C7.36863 3.96084 7.38386 4.34213 7.35698 4.91278C7.34816 5.1 7.32368 5.26765 7.28592 5.41801L10.1885 7.82737C10.4719 7.87295 10.76 7.89249 11.0436 7.89249C11.5044 7.89249 11.9717 7.80894 12.3839 7.58523C12.3882 7.59961 12.3924 7.61463 12.3966 7.6303C12.4737 7.91973 12.5016 8.31081 12.5016 8.73318V9.74745L14.4065 11.3287C14.5379 11.1547 14.6446 10.9577 14.7046 10.735C14.829 10.4701 14.9081 10.1191 14.9518 9.81844C15.0006 9.48332 15.0242 9.08189 14.9649 8.7778L14.9574 8.73927L14.9449 8.70206C14.8126 8.30673 14.4674 7.87368 14.1656 7.54965C13.9081 7.27314 13.6093 6.9994 13.35 6.81463C13.3259 6.77043 13.2996 6.72678 13.271 6.68417C13.5201 6.21998 13.643 5.63537 13.643 4.93872C13.643 3.80567 13.0326 3.01576 12.2746 2.5525C11.5365 2.10138 10.6316 1.93724 9.90564 2.02107C9.01315 2.12413 8.38516 2.41316 8 2.89841C7.61484 2.41316 6.98685 2.12413 6.09436 2.02107ZM11.7074 3.48996C12.2084 3.79616 12.5513 4.26316 12.5513 4.93872C12.5513 5.75753 12.347 6.19648 12.1134 6.43349C11.8805 6.66983 11.5298 6.79529 11.0436 6.79529C10.3584 6.79529 9.76824 6.65786 9.35452 6.37099C8.96784 6.10286 8.67851 5.66636 8.64302 4.91278C8.61614 4.34213 8.63137 3.96084 8.78252 3.68905C8.90279 3.4728 9.18318 3.2089 10.0302 3.11109C10.5269 3.05374 11.1865 3.17162 11.7074 3.48996Z" fill="white"/>
</g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.1225 13.809C14.0341 13.9146 13.877 13.9289 13.7711 13.8409L1.1931 3.40021C1.08658 3.31178 1.0722 3.15362 1.16103 3.04743L1.87751 2.19101C1.96587 2.0854 2.12299 2.07112 2.22894 2.15906L14.8069 12.5998C14.9134 12.6882 14.9278 12.8464 14.839 12.9526L14.1225 13.809Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -0,0 +1,7 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g opacity="0.5">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.09436 2.02107C5.36842 1.93724 4.46348 2.10138 3.72539 2.5525C2.96744 3.01576 2.35705 3.80567 2.35705 4.93872C2.35705 5.63537 2.47988 6.21998 2.72903 6.68417C2.70043 6.72678 2.67414 6.77043 2.64995 6.81463C2.39071 6.9994 2.09192 7.27314 1.83439 7.54965C1.53258 7.87368 1.18745 8.30673 1.05511 8.70206L1.04265 8.73927L1.03513 8.7778C0.975841 9.08189 0.999401 9.48332 1.04817 9.81844C1.09192 10.1191 1.17095 10.4701 1.29544 10.735C1.44476 11.2894 1.88328 11.6844 2.27302 11.9619C2.6204 12.2092 3.03378 12.4329 3.39179 12.6267C3.4686 12.6683 3.54294 12.7085 3.61345 12.7473L3.62786 12.7552L3.64268 12.7623C4.05361 12.9594 4.69547 13.2491 5.30115 13.4909C5.60351 13.6116 5.90465 13.7235 6.16744 13.8062C6.39236 13.877 6.6532 13.948 6.87108 13.9562C7.19351 13.9948 7.54309 14 7.99999 14C8.01293 14 8.02579 14 8.03857 14C7.97904 13.903 7.99191 13.7743 8.07655 13.6911L9.0197 12.7639C8.77857 12.7952 8.48273 12.8031 7.99999 12.8031C7.30564 12.8031 6.99799 12.7869 6.68361 12.7078C6.35125 12.6243 5.99398 12.467 5.21016 12.1174C4.24428 11.6866 3.83266 11.4004 3.6523 11.2153C3.57295 11.1339 3.5474 11.0807 3.53501 11.0478C3.52011 11.0083 3.5122 10.9688 3.4984 10.8761V8.73318C3.49839 8.31081 3.52629 7.91973 3.6034 7.6303C3.60757 7.61463 3.6118 7.59961 3.61607 7.58523C4.02831 7.80894 4.49555 7.89249 4.95638 7.89249C5.75982 7.89249 6.59976 7.73566 7.26541 7.27411C7.55937 7.07027 7.8077 6.81497 8 6.50734C8.1923 6.81497 8.44063 7.07027 8.73459 7.27411C9.40024 7.73566 10.2402 7.89249 11.0436 7.89249C11.5044 7.89249 11.9717 7.80894 12.3839 7.58523C12.3882 7.59961 12.3924 7.61463 12.3966 7.6303C12.4737 7.91973 12.5016 8.31081 12.5016 8.73318V9.34082L14.1266 7.7433C14.169 7.70159 14.2225 7.67811 14.2775 7.67276C14.2398 7.63028 14.2024 7.58915 14.1656 7.54965C13.9081 7.27314 13.6093 6.9994 13.35 6.81463C13.3259 6.77043 13.2996 6.72678 13.271 6.68417C13.5201 6.21998 13.643 5.63537 13.643 4.93872C13.643 3.80567 13.0326 3.01576 12.2746 2.5525C11.5365 2.10138 10.6316 1.93724 9.90564 2.02107C9.01315 2.12413 8.38516 2.41316 8 2.89841C7.61484 2.41316 6.98685 2.12413 6.09436 2.02107ZM3.44871 4.93872C3.44871 4.26316 3.79162 3.79616 4.2926 3.48996C4.81346 3.17162 5.4731 3.05374 5.96976 3.11109C6.81682 3.2089 7.09721 3.4728 7.21748 3.68905C7.36863 3.96084 7.38386 4.34213 7.35698 4.91278C7.32149 5.66636 7.03216 6.10286 6.64548 6.37099C6.23176 6.65786 5.64158 6.79529 4.95638 6.79529C4.47018 6.79529 4.11948 6.66983 3.88658 6.43349C3.65302 6.19648 3.44871 5.75753 3.44871 4.93872ZM12.5513 4.93872C12.5513 4.26316 12.2084 3.79616 11.7074 3.48996C11.1865 3.17162 10.5269 3.05374 10.0302 3.11109C9.18318 3.2089 8.90279 3.4728 8.78252 3.68905C8.63137 3.96084 8.61614 4.34213 8.64302 4.91278C8.67851 5.66636 8.96784 6.10286 9.35452 6.37099C9.76824 6.65786 10.3584 6.79529 11.0436 6.79529C11.5298 6.79529 11.8805 6.66983 12.1134 6.43349C12.347 6.19648 12.5513 5.75753 12.5513 4.93872Z" fill="white"/>
<path d="M7.29091 9.57581C7.29091 9.24528 7.02432 8.97734 6.69546 8.97734C6.3666 8.97734 6.1 9.24528 6.1 9.57581V10.8725C6.1 11.203 6.3666 11.471 6.69546 11.471C7.02432 11.471 7.29091 11.203 7.29091 10.8725V9.57581Z" fill="white"/>
</g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.6668 14.9102C13.7644 15.0078 13.9227 15.0078 14.0203 14.9102L14.908 14.0224C15.0056 13.9248 15.0056 13.7665 14.908 13.6688L13.2229 11.9836L14.908 10.2983C15.0057 10.2007 15.0057 10.0424 14.908 9.94474L14.0203 9.05695C13.9227 8.95931 13.7644 8.95931 13.6668 9.05695L11.9817 10.7422L10.2966 9.05693C10.199 8.95929 10.0407 8.95929 9.94306 9.05693L9.05535 9.94473C8.95773 10.0424 8.95773 10.2007 9.05535 10.2983L10.7405 11.9836L9.05537 13.6688C8.95775 13.7665 8.95775 13.9248 9.05537 14.0224L9.94308 14.9102C10.0407 15.0079 10.199 15.0079 10.2966 14.9102L11.9817 13.225L13.6668 14.9102Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB

View file

@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.5" fill-rule="evenodd" clip-rule="evenodd" d="M3.44872 4.93872C3.44872 4.26316 3.79163 3.79616 4.29261 3.48996C4.81346 3.17162 5.47311 3.05374 5.96976 3.11109C6.81683 3.2089 7.09722 3.4728 7.21749 3.68905C7.36864 3.96084 7.38387 4.34213 7.35699 4.91278C7.3215 5.66636 7.03217 6.10286 6.64549 6.37099C6.23177 6.65786 5.64159 6.79529 4.95639 6.79529C4.47019 6.79529 4.11949 6.66983 3.88658 6.43349C3.65303 6.19648 3.44872 5.75753 3.44872 4.93872ZM6.09437 2.02107C5.36843 1.93724 4.46349 2.10138 3.7254 2.5525C2.96745 3.01576 2.35706 3.80567 2.35706 4.93872C2.35706 5.63537 2.47988 6.21998 2.72904 6.68417C2.70044 6.72678 2.67415 6.77043 2.64996 6.81463C2.39072 6.9994 2.09193 7.27314 1.83439 7.54965C1.53259 7.87368 1.18745 8.30673 1.05511 8.70206L1.04266 8.73927L1.03514 8.7778C0.975849 9.08189 0.999409 9.48332 1.04818 9.81844C1.09193 10.1191 1.17096 10.4701 1.29545 10.735C1.44476 11.2894 1.88329 11.6844 2.27303 11.9619C2.6204 12.2092 3.03379 12.4329 3.3918 12.6267L3.39183 12.6267L3.39185 12.6267L3.39188 12.6268C3.46869 12.6683 3.54295 12.7085 3.61346 12.7473L3.62787 12.7552L3.64269 12.7623C4.05362 12.9594 4.69548 13.2491 5.30115 13.4909C5.60352 13.6116 5.90466 13.7235 6.16745 13.8062C6.39237 13.877 6.65321 13.948 6.87108 13.9562C7.19351 13.9948 7.5431 14 8 14C8.45052 14 8.79672 13.9949 9.11543 13.9578C9.04001 13.6509 9.00001 13.3301 9.00001 13C9.00001 12.9213 9.00229 12.8431 9.00677 12.7656C8.76798 12.7955 8.47414 12.8031 8 12.8031C7.30565 12.8031 6.998 12.7869 6.68362 12.7078C6.35125 12.6243 5.99399 12.467 5.21017 12.1174C4.24429 11.6866 3.83267 11.4004 3.6523 11.2153C3.57296 11.1339 3.54741 11.0807 3.53502 11.0478C3.52011 11.0083 3.51221 10.9688 3.4984 10.8761V8.73318C3.49839 8.31081 3.5263 7.91973 3.6034 7.6303C3.60758 7.61463 3.61181 7.59961 3.61608 7.58523C4.02832 7.80894 4.49556 7.89249 4.95639 7.89249C5.75982 7.89249 6.59977 7.73566 7.26541 7.27411C7.55938 7.07027 7.8077 6.81497 8.00001 6.50734C8.19231 6.81497 8.44064 7.07027 8.7346 7.27411C9.40025 7.73566 10.2402 7.89249 11.0436 7.89249C11.5045 7.89249 11.9717 7.80894 12.3839 7.58523C12.3882 7.59961 12.3924 7.61463 12.3966 7.6303C12.4737 7.91973 12.5016 8.31081 12.5016 8.73318V9.03072C12.6649 9.01043 12.8312 8.99997 13 8.99997C13.7226 8.99997 14.4004 9.19157 14.9855 9.52673C15.0073 9.26739 15.0077 8.99725 14.9649 8.7778L14.9574 8.73927L14.9449 8.70206C14.8126 8.30673 14.4674 7.87368 14.1656 7.54965C13.9081 7.27314 13.6093 6.9994 13.3501 6.81463C13.3259 6.77043 13.2996 6.72678 13.271 6.68417C13.5201 6.21998 13.643 5.63537 13.643 4.93872C13.643 3.80567 13.0326 3.01576 12.2746 2.5525C11.5365 2.10138 10.6316 1.93724 9.90565 2.02107C9.01315 2.12413 8.38517 2.41316 8.00001 2.89841C7.61485 2.41316 6.98686 2.12413 6.09437 2.02107ZM9.9 10.4719V9.57581C9.9 9.24528 9.63341 8.97734 9.30455 8.97734C8.97569 8.97734 8.7091 9.24528 8.7091 9.57581V10.8725C8.7091 11.2024 8.97466 11.4699 9.30265 11.471C9.45294 11.1079 9.65515 10.7718 9.9 10.4719ZM7.29092 9.57581C7.29092 9.24528 7.02433 8.97734 6.69547 8.97734C6.36661 8.97734 6.10001 9.24528 6.10001 9.57581V10.8725C6.10001 11.203 6.36661 11.471 6.69547 11.471C7.02433 11.471 7.29092 11.203 7.29092 10.8725V9.57581ZM12.5513 4.93872C12.5513 4.26316 12.2084 3.79616 11.7074 3.48996C11.1866 3.17162 10.5269 3.05374 10.0303 3.11109C9.18318 3.2089 8.90279 3.4728 8.78253 3.68905C8.63138 3.96084 8.61615 4.34213 8.64303 4.91278C8.67852 5.66636 8.96785 6.10286 9.35453 6.37099C9.76825 6.65786 10.3584 6.79529 11.0436 6.79529C11.5298 6.79529 11.8805 6.66983 12.1134 6.43349C12.347 6.19648 12.5513 5.75753 12.5513 4.93872Z" fill="white"/>
<circle cx="13" cy="13" r="3" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1.24em" height="1em" viewBox="0 0 256 208"><path d="M205.28 31.36c14.096 14.88 20.016 35.2 22.512 63.68c6.626 0 12.805 1.47 16.976 7.152l7.792 10.56A17.548 17.548 0 0 1 256 123.2v28.688c-.008 3.704-1.843 7.315-4.832 9.504C215.885 187.222 172.35 208 128 208c-49.066 0-98.19-28.273-123.168-46.608c-2.989-2.189-4.825-5.8-4.832-9.504V123.2c0-3.776 1.2-7.424 3.424-10.464l7.792-10.544c4.173-5.657 10.38-7.152 16.992-7.152c2.496-28.48 8.4-48.8 22.512-63.68C77.331 3.165 112.567.06 127.552 0H128c14.72 0 50.4 2.88 77.28 31.36Zm-77.264 47.376c-3.04 0-6.544.176-10.272.544c-1.312 4.896-3.248 9.312-6.08 12.128c-11.2 11.2-24.704 12.928-31.936 12.928c-6.802 0-13.927-1.42-19.744-5.088c-5.502 1.808-10.786 4.415-11.136 10.912c-.586 12.28-.637 24.55-.688 36.824c-.026 6.16-.05 12.322-.144 18.488c.024 3.579 2.182 6.903 5.44 8.384C79.936 185.92 104.976 192 128.016 192c23.008 0 48.048-6.08 74.512-18.144c3.258-1.48 5.415-4.805 5.44-8.384c.317-18.418.062-36.912-.816-55.312h.016c-.342-6.534-5.648-9.098-11.168-10.912c-5.82 3.652-12.927 5.088-19.728 5.088c-7.232 0-20.72-1.728-31.936-12.928c-2.832-2.816-4.768-7.232-6.08-12.128a106.26 106.26 0 0 0-10.24-.544Zm-26.941 43.93c5.748 0 10.408 4.66 10.408 10.409v19.183c0 5.749-4.66 10.409-10.408 10.409c-5.748 0-10.408-4.66-10.408-10.409v-19.183c0-5.748 4.66-10.408 10.408-10.408Zm53.333 0c5.749 0 10.409 4.66 10.409 10.409v19.183c0 5.749-4.66 10.409-10.409 10.409c-5.748 0-10.408-4.66-10.408-10.409v-19.183c0-5.748 4.66-10.408 10.408-10.408ZM81.44 28.32c-11.2 1.12-20.64 4.8-25.44 9.92c-10.4 11.36-8.16 40.16-2.24 46.24c4.32 4.32 12.48 7.2 21.28 7.2c6.72 0 19.52-1.44 30.08-12.16c4.64-4.48 7.52-15.68 7.2-27.04c-.32-9.12-2.88-16.64-6.72-19.84c-4.16-3.68-13.6-5.28-24.16-4.32Zm68.96 4.32c-3.84 3.2-6.4 10.72-6.72 19.84c-.32 11.36 2.56 22.56 7.2 27.04c10.56 10.72 23.36 12.16 30.08 12.16c8.8 0 16.96-2.88 21.28-7.2c5.92-6.08 8.16-34.88-2.24-46.24c-4.8-5.12-14.24-8.8-25.44-9.92c-10.56-.96-20 .64-24.16 4.32ZM128 56c-2.56 0-5.6.16-8.96.48c.32 1.76.48 3.68.64 5.76c0 1.44 0 2.88-.16 4.48c3.2-.32 5.92-.32 8.48-.32c2.56 0 5.28 0 8.48.32c-.16-1.6-.16-3.04-.16-4.48c.16-2.08.32-4 .64-5.76c-3.36-.32-6.4-.48-8.96-.48Z"/></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -0,0 +1,5 @@
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.5 1H7.5H8.75C8.88807 1 9 1.11193 9 1.25V4.5" stroke="#838994" stroke-linecap="round"/>
<path d="M3.64645 5.64645C3.45118 5.84171 3.45118 6.15829 3.64645 6.35355C3.84171 6.54882 4.15829 6.54882 4.35355 6.35355L3.64645 5.64645ZM8.64645 0.646447L3.64645 5.64645L4.35355 6.35355L9.35355 1.35355L8.64645 0.646447Z" fill="#838994"/>
<path d="M7.5 6.5V9C7.5 9.27614 7.27614 9.5 7 9.5H1C0.723858 9.5 0.5 9.27614 0.5 9V3C0.5 2.72386 0.723858 2.5 1 2.5H3.5" stroke="#838994" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 605 B

View file

@ -0,0 +1,14 @@
<svg width="93" height="32" viewBox="0 0 93 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.03996 7.04962C8.00936 7.67635 7.30396 8.63219 7.30396 10.0149C7.30396 11.6908 7.72425 12.5893 8.2047 13.0744C8.68381 13.5581 9.40526 13.8149 10.4054 13.8149C11.815 13.8149 13.0291 13.5336 13.8802 12.9464C14.6756 12.3977 15.2708 11.5042 15.3438 9.96182C15.3991 8.79382 15.3678 8.01341 15.0568 7.45711C14.8094 7.01449 14.2326 6.47436 12.4901 6.27416C11.4684 6.15678 10.1114 6.39804 9.03996 7.04962ZM7.87312 5.13084C9.39147 4.2075 11.2531 3.87155 12.7464 4.04312C14.8843 4.28874 16.2844 5.05049 17.0171 6.36142C17.6863 7.55867 17.6384 8.98348 17.587 10.068C17.484 12.2439 16.5804 13.8118 15.1554 14.7949C13.7861 15.7396 12.0582 16.0606 10.4054 16.0606C9.04201 16.0606 7.65128 15.7069 6.60913 14.6547C5.56832 13.6038 5.05825 12.0408 5.05825 10.0149C5.05825 7.6958 6.3139 6.07903 7.87312 5.13084Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.983 18.2811C14.6595 18.2811 15.2079 18.8295 15.2079 19.506V22.16C15.2079 22.8365 14.6595 23.385 13.983 23.385C13.3065 23.385 12.758 22.8365 12.758 22.16V19.506C12.758 18.8295 13.3065 18.2811 13.983 18.2811Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.25566 14.8903C5.48361 14.039 5.99218 12.9059 7.20734 12.5361L7.92068 14.8798C7.92068 14.8798 7.91996 14.8801 7.92068 14.8798L7.92375 14.8785C7.92411 14.8783 7.92375 14.8785 7.92375 14.8785C7.92374 14.8785 7.92322 14.8778 7.92068 14.8798C7.91364 14.8852 7.89133 14.9052 7.85878 14.951C7.78816 15.0505 7.70057 15.2311 7.62216 15.524C7.46354 16.1164 7.40614 16.9168 7.40616 17.7813V22.1675C7.43456 22.3571 7.45082 22.438 7.48148 22.5189C7.50697 22.5862 7.55954 22.695 7.72276 22.8617C8.09379 23.2406 8.94055 23.8264 10.9275 24.7081C12.5399 25.4236 13.2749 25.7456 13.9586 25.9166C14.6053 26.0784 15.2382 26.1115 16.6666 26.1115V28.5613C15.2536 28.5613 14.3395 28.5372 13.3641 28.2932C12.452 28.0651 11.5174 27.6502 10.0614 27.004C10.0193 26.9853 9.97679 26.9664 9.93382 26.9474C7.8976 26.0438 6.68669 25.3053 5.97232 24.5757C5.59284 24.1882 5.34578 23.7967 5.19055 23.387C5.05418 23.0271 5.0055 22.6875 4.97509 22.4754C4.973 22.4608 4.97099 22.4468 4.96905 22.4335L4.95629 22.3458V17.7814C4.95629 17.7814 4.95629 17.7814 4.95629 17.7814C4.95627 16.8606 5.012 15.8003 5.25566 14.8903Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.98306 15.3589C4.62844 14.6695 5.39976 13.9884 5.99652 13.6348L7.24552 15.7424C6.93706 15.9252 6.34938 16.4159 5.77155 17.0332C5.21994 17.6224 4.85695 18.1377 4.73071 18.4254C4.70277 18.6674 4.71195 19.116 4.78977 19.648C4.87834 20.2536 5.01731 20.7033 5.10492 20.8628L5.19261 21.0224L5.23006 21.2007C5.28661 21.4698 5.55952 21.8651 6.30146 22.3907C6.88143 22.8015 7.56502 23.1703 8.29605 23.5648C8.45794 23.6521 8.62215 23.7407 8.78809 23.8313C9.5952 24.2156 10.848 24.7773 12.0191 25.2425C12.613 25.4784 13.1698 25.6831 13.6288 25.8268C13.8584 25.8987 14.0505 25.9512 14.2021 25.9847C14.3503 26.0175 14.4185 26.0227 14.4277 26.0234C14.4288 26.0234 14.4281 26.0234 14.4277 26.0234L14.4287 28.4733C13.9646 28.4733 13.3889 28.3188 12.8968 28.1648C12.3562 27.9955 11.7367 27.7664 11.1147 27.5193C9.86871 27.0244 8.54832 26.4314 7.70298 26.028L7.67249 26.0135L7.64284 25.9973C7.49779 25.918 7.34502 25.8357 7.18702 25.7506C6.4505 25.354 5.60004 24.896 4.88539 24.3898C4.08363 23.8219 3.18153 23.0135 2.87437 21.8785C2.61828 21.3365 2.4557 20.618 2.3657 20.0026C2.26537 19.3167 2.2169 18.4951 2.33888 17.8727L2.35434 17.7938L2.37996 17.7176C2.6522 16.9085 3.36219 16.0221 3.98306 15.3589Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.48531 21.264V17.1402H5.93518V21.264H3.48531Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M24.2932 7.04962C25.3238 7.67635 26.0292 8.63219 26.0292 10.0149C26.0292 11.6908 25.609 12.5893 25.1285 13.0744C24.6494 13.5581 23.9279 13.8149 22.9278 13.8149C21.5182 13.8149 20.3041 13.5336 19.453 12.9464C18.6576 12.3977 18.0624 11.5042 17.9894 9.96182C17.9341 8.79382 17.9654 8.01341 18.2764 7.45711C18.5238 7.01449 19.1006 6.47436 20.8431 6.27416C21.8648 6.15678 23.2218 6.39804 24.2932 7.04962ZM25.4601 5.13084C23.9417 4.2075 22.0801 3.87155 20.5868 4.04312C18.4489 4.28874 17.0488 5.05049 16.3161 6.36142C15.6469 7.55867 15.6948 8.98348 15.7462 10.068C15.8492 12.2439 16.7528 13.8118 18.1778 14.7949C19.5471 15.7396 21.275 16.0606 22.9278 16.0606C24.2912 16.0606 25.6819 15.7069 26.7241 14.6547C27.7649 13.6038 28.275 12.0408 28.275 10.0149C28.275 7.6958 27.0193 6.07903 25.4601 5.13084Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.3502 18.2811C18.6737 18.2811 18.1253 18.8295 18.1253 19.506V22.16C18.1253 22.8365 18.6737 23.385 19.3502 23.385C20.0267 23.385 20.5752 22.8365 20.5752 22.16V19.506C20.5752 18.8295 20.0267 18.2811 19.3502 18.2811Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M28.0775 14.8903C27.8496 14.039 27.341 12.9059 26.1259 12.5361L25.4125 14.8798C25.4125 14.8798 25.4132 14.8801 25.4125 14.8798L25.4095 14.8785C25.4091 14.8783 25.4095 14.8785 25.4095 14.8785C25.4095 14.8785 25.41 14.8778 25.4125 14.8798C25.4196 14.8852 25.4419 14.9052 25.4744 14.951C25.545 15.0505 25.6326 15.2311 25.711 15.524C25.8697 16.1164 25.9271 16.9168 25.927 17.7813V22.1675C25.8986 22.3571 25.8824 22.438 25.8517 22.5189C25.8262 22.5862 25.7737 22.695 25.6104 22.8617C25.2394 23.2406 24.3927 23.8264 22.4057 24.7081C20.7933 25.4236 20.0583 25.7456 19.3746 25.9166C18.7279 26.0784 18.0949 26.1115 16.6666 26.1115V28.5613C18.0796 28.5613 18.9937 28.5372 19.9691 28.2932C20.8812 28.0651 21.8158 27.6502 23.2718 27.004C23.3139 26.9853 23.3564 26.9664 23.3994 26.9474C25.4356 26.0438 26.6465 25.3053 27.3609 24.5757C27.7404 24.1882 27.9874 23.7967 28.1427 23.387C28.279 23.0271 28.3277 22.6875 28.3581 22.4754C28.3602 22.4608 28.3622 22.4468 28.3642 22.4335L28.3769 22.3458V17.7814C28.3769 17.7814 28.3769 17.7814 28.3769 17.7814C28.3769 16.8606 28.3212 15.8003 28.0775 14.8903Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M29.3501 15.3589C28.7048 14.6695 27.9334 13.9884 27.3367 13.6348L26.0877 15.7424C26.3961 15.9252 26.9838 16.4159 27.5616 17.0332C28.1133 17.6224 28.4763 18.1377 28.6025 18.4254C28.6304 18.6674 28.6213 19.116 28.5434 19.648C28.4549 20.2536 28.3159 20.7033 28.2283 20.8628L28.1406 21.0224L28.1031 21.2007C28.0466 21.4698 27.7737 21.8651 27.0317 22.3907C26.4518 22.8015 25.7682 23.1703 25.0372 23.5648C24.8753 23.6521 24.711 23.7407 24.5451 23.8313C23.738 24.2156 22.4852 24.7773 21.3141 25.2425C20.7202 25.4784 20.1634 25.6831 19.7044 25.8268C19.4748 25.8987 19.2827 25.9512 19.1311 25.9847C18.9829 26.0175 18.9147 26.0227 18.9055 26.0234C18.9044 26.0234 18.9051 26.0234 18.9055 26.0234L18.9045 28.4733C19.3686 28.4733 19.9443 28.3188 20.4364 28.1648C20.977 27.9955 21.5965 27.7664 22.2185 27.5193C23.4645 27.0244 24.7849 26.4314 25.6302 26.028L25.6607 26.0135L25.6904 25.9973C25.8354 25.918 25.9882 25.8357 26.1462 25.7506C26.8827 25.354 27.7332 24.896 28.4478 24.3898C29.2496 23.8219 30.1517 23.0135 30.4588 21.8785C30.7149 21.3365 30.8775 20.618 30.9675 20.0026C31.0678 19.3167 31.1163 18.4951 30.9943 17.8727L30.9789 17.7938L30.9532 17.7176C30.681 16.9085 29.971 16.0221 29.3501 15.3589Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M29.8479 21.264V17.1402H27.398V21.264H29.8479Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M48.6666 11C49.2189 11 49.6666 11.4477 49.6666 12V15H52.6666C53.2189 15 53.6666 15.4477 53.6666 16C53.6666 16.5523 53.2189 17 52.6666 17H49.6666V20C49.6666 20.5523 49.2189 21 48.6666 21C48.1143 21 47.6666 20.5523 47.6666 20V17H44.6666C44.1143 17 43.6666 16.5523 43.6666 16C43.6666 15.4477 44.1143 15 44.6666 15H47.6666V12C47.6666 11.4477 48.1143 11 48.6666 11Z" fill="white" fill-opacity="0.5"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M67.1666 4.33329C66.7064 4.33329 66.3333 4.70639 66.3333 5.16663V23.5H64.6666V5.16663C64.6666 3.78591 65.7859 2.66663 67.1666 2.66663H89.494C90.6077 2.66663 91.1654 4.01306 90.3779 4.80051L76.6264 18.552H80.5V16.8333H82.1666V18.9687C82.1666 19.6591 81.607 20.2187 80.9166 20.2187H74.9597L72.0951 23.0833H85.0833V12.6666H86.75V23.0833C86.75 24.0038 86.0038 24.75 85.0833 24.75H70.4285L67.5118 27.6666H88.8333C89.2935 27.6666 89.6666 27.2935 89.6666 26.8333V8.49996H91.3333V26.8333C91.3333 28.214 90.214 29.3333 88.8333 29.3333H66.5059C65.3922 29.3333 64.8345 27.9869 65.622 27.1994L79.3214 13.5H75.5V15.1666H73.8333V13.0833C73.8333 12.3929 74.3929 11.8333 75.0833 11.8333H80.9881L83.9048 8.91663H70.9166V19.3333H69.25V8.91663C69.25 7.99615 69.9962 7.24996 70.9166 7.24996H85.5714L88.4881 4.33329H67.1666Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 8.5 KiB

View file

@ -176,7 +176,10 @@
{ {
"focus": false "focus": false
} }
] ],
"alt-\\": "copilot::NextSuggestion",
"alt-]": "copilot::NextSuggestion",
"alt-[": "copilot::PreviousSuggestion"
} }
}, },
{ {

View file

@ -13,6 +13,11 @@
// The factor to grow the active pane by. Defaults to 1.0 // The factor to grow the active pane by. Defaults to 1.0
// which gives the same size as all other panes. // which gives the same size as all other panes.
"active_pane_magnification": 1.0, "active_pane_magnification": 1.0,
// Enable / disable copilot integration.
"enable_copilot_integration": true,
// Controls whether copilot provides suggestion immediately
// or waits for a `copilot::Toggle`
"copilot": "on",
// Whether to enable vim modes and key bindings // Whether to enable vim modes and key bindings
"vim_mode": false, "vim_mode": false,
// Whether to show the informational hover box when moving the mouse // Whether to show the informational hover box when moving the mouse
@ -120,7 +125,7 @@
// Settings specific to the terminal // Settings specific to the terminal
"terminal": { "terminal": {
// What shell to use when opening a terminal. May take 3 values: // What shell to use when opening a terminal. May take 3 values:
// 1. Use the system's default terminal configuration (e.g. $TERM). // 1. Use the system's default terminal configuration in /etc/passwd
// "shell": "system" // "shell": "system"
// 2. A program: // 2. A program:
// "shell": { // "shell": {

View file

@ -22,8 +22,8 @@ anyhow = "1.0.38"
isahc = "1.7" isahc = "1.7"
lazy_static = "1.4" lazy_static = "1.4"
log = "0.4" log = "0.4"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
smol = "1.2.5" smol = "1.2.5"
tempdir = "0.3.7" tempdir = "0.3.7"

View file

@ -1,8 +1,7 @@
mod update_notification; mod update_notification;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN}; use client::{ZED_APP_PATH, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN};
use client::{ZED_APP_PATH, ZED_APP_VERSION};
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use gpui::{ use gpui::{
actions, platform::AppVersion, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, actions, platform::AppVersion, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
@ -14,6 +13,7 @@ use smol::{fs::File, io::AsyncReadExt, process::Command};
use std::{ffi::OsString, sync::Arc, time::Duration}; use std::{ffi::OsString, sync::Arc, time::Duration};
use update_notification::UpdateNotification; use update_notification::UpdateNotification;
use util::channel::ReleaseChannel; use util::channel::ReleaseChannel;
use util::http::HttpClient;
use workspace::Workspace; use workspace::Workspace;
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification"; const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification";

View file

@ -17,8 +17,8 @@ anyhow = "1.0"
clap = { version = "3.1", features = ["derive"] } clap = { version = "3.1", features = ["derive"] }
dirs = "3.0" dirs = "3.0"
ipc-channel = "0.16" ipc-channel = "0.16"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.9" core-foundation = "0.9"

View file

@ -17,13 +17,13 @@ db = { path = "../db" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
util = { path = "../util" } util = { path = "../util" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
staff_mode = { path = "../staff_mode" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
anyhow = "1.0.38" anyhow = "1.0.38"
async-recursion = "0.3" async-recursion = "0.3"
async-tungstenite = { version = "0.16", features = ["async-tls"] } async-tungstenite = { version = "0.16", features = ["async-tls"] }
futures = "0.3" futures = "0.3"
image = "0.23" image = "0.23"
isahc = "1.7"
lazy_static = "1.4.0" lazy_static = "1.4.0"
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
parking_lot = "0.11.1" parking_lot = "0.11.1"
@ -35,8 +35,8 @@ time = { version = "0.3", features = ["serde", "serde-well-known"] }
tiny_http = "0.8" tiny_http = "0.8"
uuid = { version = "1.1.2", features = ["v4"] } uuid = { version = "1.1.2", features = ["v4"] }
url = "2.2" url = "2.2"
serde = { version = "*", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
settings = { path = "../settings" } settings = { path = "../settings" }
tempfile = "3" tempfile = "3"

View file

@ -1,7 +1,6 @@
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub mod test; pub mod test;
pub mod http;
pub mod telemetry; pub mod telemetry;
pub mod user; pub mod user;
@ -18,7 +17,6 @@ use gpui::{
AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext, AppVersion, AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext, AppVersion,
AsyncAppContext, Entity, ModelHandle, MutableAppContext, Task, View, ViewContext, ViewHandle, AsyncAppContext, Entity, ModelHandle, MutableAppContext, Task, View, ViewContext, ViewHandle,
}; };
use http::HttpClient;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use parking_lot::RwLock; use parking_lot::RwLock;
use postage::watch; use postage::watch;
@ -41,6 +39,7 @@ use telemetry::Telemetry;
use thiserror::Error; use thiserror::Error;
use url::Url; use url::Url;
use util::channel::ReleaseChannel; use util::channel::ReleaseChannel;
use util::http::HttpClient;
use util::{ResultExt, TryFutureExt}; use util::{ResultExt, TryFutureExt};
pub use rpc::*; pub use rpc::*;
@ -130,7 +129,7 @@ pub enum EstablishConnectionError {
#[error("{0}")] #[error("{0}")]
Other(#[from] anyhow::Error), Other(#[from] anyhow::Error),
#[error("{0}")] #[error("{0}")]
Http(#[from] http::Error), Http(#[from] util::http::Error),
#[error("{0}")] #[error("{0}")]
Io(#[from] std::io::Error), Io(#[from] std::io::Error),
#[error("{0}")] #[error("{0}")]
@ -1396,10 +1395,11 @@ pub fn decode_worktree_url(url: &str) -> Option<(u64, String)> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::test::{FakeHttpClient, FakeServer}; use crate::test::FakeServer;
use gpui::{executor::Deterministic, TestAppContext}; use gpui::{executor::Deterministic, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::future; use std::future;
use util::http::FakeHttpClient;
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
async fn test_reconnection(cx: &mut TestAppContext) { async fn test_reconnection(cx: &mut TestAppContext) {

View file

@ -1,57 +0,0 @@
pub use anyhow::{anyhow, Result};
use futures::future::BoxFuture;
use isahc::{
config::{Configurable, RedirectPolicy},
AsyncBody,
};
pub use isahc::{
http::{Method, Uri},
Error,
};
use smol::future::FutureExt;
use std::{sync::Arc, time::Duration};
pub use url::Url;
pub type Request = isahc::Request<AsyncBody>;
pub type Response = isahc::Response<AsyncBody>;
pub trait HttpClient: Send + Sync {
fn send(&self, req: Request) -> BoxFuture<Result<Response, Error>>;
fn get<'a>(
&'a self,
uri: &str,
body: AsyncBody,
follow_redirects: bool,
) -> BoxFuture<'a, Result<Response, Error>> {
let request = isahc::Request::builder()
.redirect_policy(if follow_redirects {
RedirectPolicy::Follow
} else {
RedirectPolicy::None
})
.method(Method::GET)
.uri(uri)
.body(body);
match request {
Ok(request) => self.send(request),
Err(error) => async move { Err(error.into()) }.boxed(),
}
}
}
pub fn client() -> Arc<dyn HttpClient> {
Arc::new(
isahc::HttpClient::builder()
.connect_timeout(Duration::from_secs(5))
.low_speed_timeout(100, Duration::from_secs(5))
.build()
.unwrap(),
)
}
impl HttpClient for isahc::HttpClient {
fn send(&self, req: Request) -> BoxFuture<Result<Response, Error>> {
Box::pin(async move { self.send_async(req).await })
}
}

View file

@ -1,11 +1,9 @@
use crate::http::HttpClient;
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use gpui::{ use gpui::{
executor::Background, executor::Background,
serde_json::{self, value::Map, Value}, serde_json::{self, value::Map, Value},
AppContext, Task, AppContext, Task,
}; };
use isahc::Request;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use parking_lot::Mutex; use parking_lot::Mutex;
use serde::Serialize; use serde::Serialize;
@ -19,6 +17,7 @@ use std::{
time::{Duration, SystemTime, UNIX_EPOCH}, time::{Duration, SystemTime, UNIX_EPOCH},
}; };
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use util::http::HttpClient;
use util::{channel::ReleaseChannel, post_inc, ResultExt, TryFutureExt}; use util::{channel::ReleaseChannel, post_inc, ResultExt, TryFutureExt};
use uuid::Uuid; use uuid::Uuid;
@ -220,10 +219,10 @@ impl Telemetry {
"App": true "App": true
}), }),
}])?; }])?;
let request = Request::post(MIXPANEL_ENGAGE_URL)
.header("Content-Type", "application/json") this.http_client
.body(json_bytes.into())?; .post_json(MIXPANEL_ENGAGE_URL, json_bytes.into())
this.http_client.send(request).await?; .await?;
anyhow::Ok(()) anyhow::Ok(())
} }
.log_err(), .log_err(),
@ -316,10 +315,9 @@ impl Telemetry {
json_bytes.clear(); json_bytes.clear();
serde_json::to_writer(&mut json_bytes, &events)?; serde_json::to_writer(&mut json_bytes, &events)?;
let request = Request::post(MIXPANEL_EVENTS_URL) this.http_client
.header("Content-Type", "application/json") .post_json(MIXPANEL_EVENTS_URL, json_bytes.into())
.body(json_bytes.into())?; .await?;
this.http_client.send(request).await?;
anyhow::Ok(()) anyhow::Ok(())
} }
.log_err(), .log_err(),

View file

@ -1,16 +1,14 @@
use crate::{ use crate::{Client, Connection, Credentials, EstablishConnectionError, UserStore};
http::{self, HttpClient, Request, Response},
Client, Connection, Credentials, EstablishConnectionError, UserStore,
};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use futures::{future::BoxFuture, stream::BoxStream, Future, StreamExt}; use futures::{stream::BoxStream, StreamExt};
use gpui::{executor, ModelHandle, TestAppContext}; use gpui::{executor, ModelHandle, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use rpc::{ use rpc::{
proto::{self, GetPrivateUserInfo, GetPrivateUserInfoResponse}, proto::{self, GetPrivateUserInfo, GetPrivateUserInfoResponse},
ConnectionId, Peer, Receipt, TypedEnvelope, ConnectionId, Peer, Receipt, TypedEnvelope,
}; };
use std::{fmt, rc::Rc, sync::Arc}; use std::{rc::Rc, sync::Arc};
use util::http::FakeHttpClient;
pub struct FakeServer { pub struct FakeServer {
peer: Arc<Peer>, peer: Arc<Peer>,
@ -219,46 +217,3 @@ impl Drop for FakeServer {
self.disconnect(); self.disconnect();
} }
} }
pub struct FakeHttpClient {
handler: Box<
dyn 'static
+ Send
+ Sync
+ Fn(Request) -> BoxFuture<'static, Result<Response, http::Error>>,
>,
}
impl FakeHttpClient {
pub fn create<Fut, F>(handler: F) -> Arc<dyn HttpClient>
where
Fut: 'static + Send + Future<Output = Result<Response, http::Error>>,
F: 'static + Send + Sync + Fn(Request) -> Fut,
{
Arc::new(Self {
handler: Box::new(move |req| Box::pin(handler(req))),
})
}
pub fn with_404_response() -> Arc<dyn HttpClient> {
Self::create(|_| async move {
Ok(isahc::Response::builder()
.status(404)
.body(Default::default())
.unwrap())
})
}
}
impl fmt::Debug for FakeHttpClient {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FakeHttpClient").finish()
}
}
impl HttpClient for FakeHttpClient {
fn send(&self, req: Request) -> BoxFuture<Result<Response, crate::http::Error>> {
let future = (self.handler)(req);
Box::pin(async move { future.await.map(Into::into) })
}
}

View file

@ -1,4 +1,4 @@
use super::{http::HttpClient, proto, Client, Status, TypedEnvelope}; use super::{proto, Client, Status, TypedEnvelope};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use collections::{hash_map::Entry, HashMap, HashSet}; use collections::{hash_map::Entry, HashMap, HashSet};
use futures::{channel::mpsc, future, AsyncReadExt, Future, StreamExt}; use futures::{channel::mpsc, future, AsyncReadExt, Future, StreamExt};
@ -6,8 +6,10 @@ use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
use postage::{sink::Sink, watch}; use postage::{sink::Sink, watch};
use rpc::proto::{RequestMessage, UsersResponse}; use rpc::proto::{RequestMessage, UsersResponse};
use settings::Settings; use settings::Settings;
use staff_mode::StaffMode;
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use util::{StaffMode, TryFutureExt as _}; use util::http::HttpClient;
use util::TryFutureExt as _;
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct User { pub struct User {

View file

@ -41,9 +41,9 @@ scrypt = "0.7"
# Remove fork dependency when a version with https://github.com/SeaQL/sea-orm/pull/1283 is released. # Remove fork dependency when a version with https://github.com/SeaQL/sea-orm/pull/1283 is released.
sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-postgres", "postgres-array", "runtime-tokio-rustls"] } sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-postgres", "postgres-array", "runtime-tokio-rustls"] }
sea-query = "0.27" sea-query = "0.27"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = "1.0" serde_json = { workspace = true }
sha-1 = "0.9" sha-1 = "0.9"
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "postgres", "json", "time", "uuid", "any"] } sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "postgres", "json", "time", "uuid", "any"] }
time = { version = "0.3", features = ["serde", "serde-well-known"] } time = { version = "0.3", features = ["serde", "serde-well-known"] }
@ -79,7 +79,7 @@ env_logger = "0.9"
util = { path = "../util" } util = { path = "../util" }
lazy_static = "1.4" lazy_static = "1.4"
sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-sqlite"] } sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-sqlite"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
sqlx = { version = "0.6", features = ["sqlite"] } sqlx = { version = "0.6", features = ["sqlite"] }
unindent = "0.1" unindent = "0.1"

View file

@ -7,8 +7,7 @@ use crate::{
use anyhow::anyhow; use anyhow::anyhow;
use call::ActiveCall; use call::ActiveCall;
use client::{ use client::{
self, proto::PeerId, test::FakeHttpClient, Client, Connection, Credentials, self, proto::PeerId, Client, Connection, Credentials, EstablishConnectionError, UserStore,
EstablishConnectionError, UserStore,
}; };
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use fs::FakeFs; use fs::FakeFs;
@ -28,6 +27,7 @@ use std::{
}, },
}; };
use theme::ThemeRegistry; use theme::ThemeRegistry;
use util::http::FakeHttpClient;
use workspace::Workspace; use workspace::Workspace;
mod integration_tests; mod integration_tests;

View file

@ -43,8 +43,8 @@ anyhow = "1.0"
futures = "0.3" futures = "0.3"
log = "0.4" log = "0.4"
postage = { workspace = true } postage = { workspace = true }
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
[dev-dependencies] [dev-dependencies]
call = { path = "../call", features = ["test-support"] } call = { path = "../call", features = ["test-support"] }

View file

@ -301,25 +301,13 @@ impl CollabTitlebarItem {
.with_style(item_style.container) .with_style(item_style.container)
.boxed() .boxed()
})), })),
ContextMenuItem::Item { ContextMenuItem::item("Sign out", SignOut),
label: "Sign out".into(), ContextMenuItem::item("Send Feedback", feedback::feedback_editor::GiveFeedback),
action: Box::new(SignOut),
},
ContextMenuItem::Item {
label: "Send Feedback".into(),
action: Box::new(feedback::feedback_editor::GiveFeedback),
},
] ]
} else { } else {
vec![ vec![
ContextMenuItem::Item { ContextMenuItem::item("Sign in", SignIn),
label: "Sign in".into(), ContextMenuItem::item("Send Feedback", feedback::feedback_editor::GiveFeedback),
action: Box::new(SignIn),
},
ContextMenuItem::Item {
label: "Send Feedback".into(),
action: Box::new(feedback::feedback_editor::GiveFeedback),
},
] ]
}; };

View file

@ -24,3 +24,10 @@ pub type HashMap<K, V> = std::collections::HashMap<K, V>;
pub type HashSet<T> = std::collections::HashSet<T>; pub type HashSet<T> = std::collections::HashSet<T>;
pub use std::collections::*; pub use std::collections::*;
// NEW TYPES
#[derive(Default)]
pub struct CommandPaletteFilter {
pub filtered_namespaces: HashSet<&'static str>,
}

View file

@ -24,7 +24,7 @@ workspace = { path = "../workspace" }
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
editor = { path = "../editor", features = ["test-support"] } editor = { path = "../editor", features = ["test-support"] }
project = { path = "../project", features = ["test-support"] } project = { path = "../project", features = ["test-support"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
ctor = "0.1" ctor = "0.1"
env_logger = "0.9" env_logger = "0.9"

View file

@ -1,4 +1,4 @@
use collections::HashSet; use collections::CommandPaletteFilter;
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, actions,
@ -12,11 +12,6 @@ use settings::Settings;
use std::cmp; use std::cmp;
use workspace::Workspace; use workspace::Workspace;
#[derive(Default)]
pub struct CommandPaletteFilter {
pub filtered_namespaces: HashSet<&'static str>,
}
pub fn init(cx: &mut MutableAppContext) { pub fn init(cx: &mut MutableAppContext) {
cx.add_action(CommandPalette::toggle); cx.add_action(CommandPalette::toggle);
Picker::<CommandPalette>::init(cx); Picker::<CommandPalette>::init(cx);

View file

@ -1,7 +1,7 @@
use gpui::{ use gpui::{
elements::*, geometry::vector::Vector2F, impl_internal_actions, keymap_matcher::KeymapContext, elements::*, geometry::vector::Vector2F, impl_internal_actions, keymap_matcher::KeymapContext,
platform::CursorStyle, Action, AnyViewHandle, AppContext, Axis, Entity, MouseButton, platform::CursorStyle, Action, AnyViewHandle, AppContext, Axis, Entity, MouseButton,
MutableAppContext, RenderContext, SizeConstraint, Subscription, View, ViewContext, MouseState, MutableAppContext, RenderContext, SizeConstraint, Subscription, View, ViewContext,
}; };
use menu::*; use menu::*;
use settings::Settings; use settings::Settings;
@ -24,20 +24,71 @@ pub fn init(cx: &mut MutableAppContext) {
cx.add_action(ContextMenu::cancel); cx.add_action(ContextMenu::cancel);
} }
type ContextMenuItemBuilder = Box<dyn Fn(&mut MouseState, &theme::ContextMenuItem) -> ElementBox>;
pub enum ContextMenuItemLabel {
String(Cow<'static, str>),
Element(ContextMenuItemBuilder),
}
pub enum ContextMenuAction {
ParentAction {
action: Box<dyn Action>,
},
ViewAction {
action: Box<dyn Action>,
for_view: usize,
},
}
impl ContextMenuAction {
fn id(&self) -> TypeId {
match self {
ContextMenuAction::ParentAction { action } => action.id(),
ContextMenuAction::ViewAction { action, .. } => action.id(),
}
}
}
pub enum ContextMenuItem { pub enum ContextMenuItem {
Item { Item {
label: Cow<'static, str>, label: ContextMenuItemLabel,
action: Box<dyn Action>, action: ContextMenuAction,
}, },
Static(StaticItem), Static(StaticItem),
Separator, Separator,
} }
impl ContextMenuItem { impl ContextMenuItem {
pub fn element_item(label: ContextMenuItemBuilder, action: impl 'static + Action) -> Self {
Self::Item {
label: ContextMenuItemLabel::Element(label),
action: ContextMenuAction::ParentAction {
action: Box::new(action),
},
}
}
pub fn item(label: impl Into<Cow<'static, str>>, action: impl 'static + Action) -> Self { pub fn item(label: impl Into<Cow<'static, str>>, action: impl 'static + Action) -> Self {
Self::Item { Self::Item {
label: label.into(), label: ContextMenuItemLabel::String(label.into()),
action: Box::new(action), action: ContextMenuAction::ParentAction {
action: Box::new(action),
},
}
}
pub fn item_for_view(
label: impl Into<Cow<'static, str>>,
view_id: usize,
action: impl 'static + Action,
) -> Self {
Self::Item {
label: ContextMenuItemLabel::String(label.into()),
action: ContextMenuAction::ViewAction {
action: Box::new(action),
for_view: view_id,
},
} }
} }
@ -168,7 +219,15 @@ impl ContextMenu {
fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) { fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
if let Some(ix) = self.selected_index { if let Some(ix) = self.selected_index {
if let Some(ContextMenuItem::Item { action, .. }) = self.items.get(ix) { if let Some(ContextMenuItem::Item { action, .. }) = self.items.get(ix) {
cx.dispatch_any_action(action.boxed_clone()); match action {
ContextMenuAction::ParentAction { action } => {
cx.dispatch_any_action(action.boxed_clone())
}
ContextMenuAction::ViewAction { action, for_view } => {
let window_id = cx.window_id();
cx.dispatch_any_action_at(window_id, *for_view, action.boxed_clone())
}
};
self.reset(cx); self.reset(cx);
} }
} }
@ -278,10 +337,17 @@ impl ContextMenu {
Some(ix) == self.selected_index, Some(ix) == self.selected_index,
); );
Label::new(label.to_string(), style.label.clone()) match label {
.contained() ContextMenuItemLabel::String(label) => {
.with_style(style.container) Label::new(label.to_string(), style.label.clone())
.boxed() .contained()
.with_style(style.container)
.boxed()
}
ContextMenuItemLabel::Element(element) => {
element(&mut Default::default(), style)
}
}
} }
ContextMenuItem::Static(f) => f(cx), ContextMenuItem::Static(f) => f(cx),
@ -306,9 +372,18 @@ impl ContextMenu {
&mut Default::default(), &mut Default::default(),
Some(ix) == self.selected_index, Some(ix) == self.selected_index,
); );
let (action, view_id) = match action {
ContextMenuAction::ParentAction { action } => {
(action.boxed_clone(), self.parent_view_id)
}
ContextMenuAction::ViewAction { action, for_view } => {
(action.boxed_clone(), *for_view)
}
};
KeystrokeLabel::new( KeystrokeLabel::new(
window_id, window_id,
self.parent_view_id, view_id,
action.boxed_clone(), action.boxed_clone(),
style.keystroke.container, style.keystroke.container,
style.keystroke.text.clone(), style.keystroke.text.clone(),
@ -347,22 +422,34 @@ impl ContextMenu {
.with_children(self.items.iter().enumerate().map(|(ix, item)| { .with_children(self.items.iter().enumerate().map(|(ix, item)| {
match item { match item {
ContextMenuItem::Item { label, action } => { ContextMenuItem::Item { label, action } => {
let action = action.boxed_clone(); let (action, view_id) = match action {
ContextMenuAction::ParentAction { action } => {
(action.boxed_clone(), self.parent_view_id)
}
ContextMenuAction::ViewAction { action, for_view } => {
(action.boxed_clone(), *for_view)
}
};
MouseEventHandler::<MenuItem>::new(ix, cx, |state, _| { MouseEventHandler::<MenuItem>::new(ix, cx, |state, _| {
let style = let style =
style.item.style_for(state, Some(ix) == self.selected_index); style.item.style_for(state, Some(ix) == self.selected_index);
Flex::row() Flex::row()
.with_child( .with_child(match label {
Label::new(label.clone(), style.label.clone()) ContextMenuItemLabel::String(label) => {
.contained() Label::new(label.clone(), style.label.clone())
.boxed(), .contained()
) .boxed()
}
ContextMenuItemLabel::Element(element) => {
element(state, style)
}
})
.with_child({ .with_child({
KeystrokeLabel::new( KeystrokeLabel::new(
window_id, window_id,
self.parent_view_id, view_id,
action.boxed_clone(), action.boxed_clone(),
style.keystroke.container, style.keystroke.container,
style.keystroke.text.clone(), style.keystroke.text.clone(),
@ -375,9 +462,12 @@ impl ContextMenu {
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_up(MouseButton::Left, |_, _| {}) // Capture these events
.on_down(MouseButton::Left, |_, _| {}) // Capture these events
.on_click(MouseButton::Left, move |_, cx| { .on_click(MouseButton::Left, move |_, cx| {
cx.dispatch_action(Clicked); cx.dispatch_action(Clicked);
cx.dispatch_any_action(action.boxed_clone()); let window_id = cx.window_id();
cx.dispatch_any_action_at(window_id, view_id, action.boxed_clone());
}) })
.on_drag(MouseButton::Left, |_, _| {}) .on_drag(MouseButton::Left, |_, _| {})
.boxed() .boxed()

47
crates/copilot/Cargo.toml Normal file
View file

@ -0,0 +1,47 @@
[package]
name = "copilot"
version = "0.1.0"
edition = "2021"
publish = false
[lib]
path = "src/copilot.rs"
doctest = false
[features]
test-support = [
"collections/test-support",
"gpui/test-support",
"language/test-support",
"lsp/test-support",
"settings/test-support",
"util/test-support",
]
[dependencies]
collections = { path = "../collections" }
context_menu = { path = "../context_menu" }
gpui = { path = "../gpui" }
language = { path = "../language" }
settings = { path = "../settings" }
theme = { path = "../theme" }
lsp = { path = "../lsp" }
node_runtime = { path = "../node_runtime"}
util = { path = "../util" }
async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] }
async-tar = "0.4.2"
anyhow = "1.0"
log = "0.4"
serde = { workspace = true }
serde_derive = { workspace = true }
smol = "1.2.5"
futures = "0.3"
[dev-dependencies]
collections = { path = "../collections", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] }
language = { path = "../language", features = ["test-support"] }
settings = { path = "../settings", features = ["test-support"] }
lsp = { path = "../lsp", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] }
workspace = { path = "../workspace", features = ["test-support"] }

View file

@ -0,0 +1,688 @@
pub mod request;
mod sign_in;
use anyhow::{anyhow, Context, Result};
use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
use collections::HashMap;
use futures::{future::Shared, Future, FutureExt, TryFutureExt};
use gpui::{
actions, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext,
Task,
};
use language::{point_from_lsp, point_to_lsp, Anchor, Bias, Buffer, Language, ToPointUtf16};
use log::{debug, error};
use lsp::LanguageServer;
use node_runtime::NodeRuntime;
use request::{LogMessage, StatusNotification};
use settings::Settings;
use smol::{fs, io::BufReader, stream::StreamExt};
use std::{
ffi::OsString,
ops::Range,
path::{Path, PathBuf},
sync::Arc,
};
use util::{
channel::ReleaseChannel, fs::remove_matching, github::latest_github_release, http::HttpClient,
paths, ResultExt,
};
const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth";
actions!(copilot_auth, [SignIn, SignOut]);
const COPILOT_NAMESPACE: &'static str = "copilot";
actions!(copilot, [NextSuggestion, PreviousSuggestion, Reinstall]);
pub fn init(http: Arc<dyn HttpClient>, node_runtime: Arc<NodeRuntime>, cx: &mut MutableAppContext) {
// Disable Copilot for stable releases.
if *cx.global::<ReleaseChannel>() == ReleaseChannel::Stable {
cx.update_global::<collections::CommandPaletteFilter, _, _>(|filter, _cx| {
filter.filtered_namespaces.insert(COPILOT_NAMESPACE);
filter.filtered_namespaces.insert(COPILOT_AUTH_NAMESPACE);
});
return;
}
let copilot = cx.add_model({
let node_runtime = node_runtime.clone();
move |cx| Copilot::start(http, node_runtime, cx)
});
cx.set_global(copilot.clone());
sign_in::init(cx);
cx.add_global_action(|_: &SignIn, cx| {
if let Some(copilot) = Copilot::global(cx) {
copilot
.update(cx, |copilot, cx| copilot.sign_in(cx))
.detach_and_log_err(cx);
}
});
cx.add_global_action(|_: &SignOut, cx| {
if let Some(copilot) = Copilot::global(cx) {
copilot
.update(cx, |copilot, cx| copilot.sign_out(cx))
.detach_and_log_err(cx);
}
});
cx.add_global_action(|_: &Reinstall, cx| {
if let Some(copilot) = Copilot::global(cx) {
copilot
.update(cx, |copilot, cx| copilot.reinstall(cx))
.detach();
}
});
}
enum CopilotServer {
Disabled,
Starting {
task: Shared<Task<()>>,
},
Error(Arc<str>),
Started {
server: Arc<LanguageServer>,
status: SignInStatus,
subscriptions_by_buffer_id: HashMap<usize, gpui::Subscription>,
},
}
#[derive(Clone, Debug)]
enum SignInStatus {
Authorized,
Unauthorized,
SigningIn {
prompt: Option<request::PromptUserDeviceFlow>,
task: Shared<Task<Result<(), Arc<anyhow::Error>>>>,
},
SignedOut,
}
#[derive(Debug, Clone)]
pub enum Status {
Starting {
task: Shared<Task<()>>,
},
Error(Arc<str>),
Disabled,
SignedOut,
SigningIn {
prompt: Option<request::PromptUserDeviceFlow>,
},
Unauthorized,
Authorized,
}
impl Status {
pub fn is_authorized(&self) -> bool {
matches!(self, Status::Authorized)
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct Completion {
pub range: Range<Anchor>,
pub text: String,
}
pub struct Copilot {
http: Arc<dyn HttpClient>,
node_runtime: Arc<NodeRuntime>,
server: CopilotServer,
}
impl Entity for Copilot {
type Event = ();
}
impl Copilot {
pub fn global(cx: &AppContext) -> Option<ModelHandle<Self>> {
if cx.has_global::<ModelHandle<Self>>() {
Some(cx.global::<ModelHandle<Self>>().clone())
} else {
None
}
}
fn start(
http: Arc<dyn HttpClient>,
node_runtime: Arc<NodeRuntime>,
cx: &mut ModelContext<Self>,
) -> Self {
cx.observe_global::<Settings, _>({
let http = http.clone();
let node_runtime = node_runtime.clone();
move |this, cx| {
if cx.global::<Settings>().enable_copilot_integration {
if matches!(this.server, CopilotServer::Disabled) {
let start_task = cx
.spawn({
let http = http.clone();
let node_runtime = node_runtime.clone();
move |this, cx| {
Self::start_language_server(http, node_runtime, this, cx)
}
})
.shared();
this.server = CopilotServer::Starting { task: start_task };
cx.notify();
}
} else {
this.server = CopilotServer::Disabled;
cx.notify();
}
}
})
.detach();
if cx.global::<Settings>().enable_copilot_integration {
let start_task = cx
.spawn({
let http = http.clone();
let node_runtime = node_runtime.clone();
move |this, cx| Self::start_language_server(http, node_runtime, this, cx)
})
.shared();
Self {
http,
node_runtime,
server: CopilotServer::Starting { task: start_task },
}
} else {
Self {
http,
node_runtime,
server: CopilotServer::Disabled,
}
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn fake(cx: &mut gpui::TestAppContext) -> (ModelHandle<Self>, lsp::FakeLanguageServer) {
let (server, fake_server) =
LanguageServer::fake("copilot".into(), Default::default(), cx.to_async());
let http = util::http::FakeHttpClient::create(|_| async { unreachable!() });
let this = cx.add_model(|cx| Self {
http: http.clone(),
node_runtime: NodeRuntime::new(http, cx.background().clone()),
server: CopilotServer::Started {
server: Arc::new(server),
status: SignInStatus::Authorized,
subscriptions_by_buffer_id: Default::default(),
},
});
(this, fake_server)
}
fn start_language_server(
http: Arc<dyn HttpClient>,
node_runtime: Arc<NodeRuntime>,
this: ModelHandle<Self>,
mut cx: AsyncAppContext,
) -> impl Future<Output = ()> {
async move {
let start_language_server = async {
let server_path = get_copilot_lsp(http).await?;
let node_path = node_runtime.binary_path().await?;
let arguments: &[OsString] = &[server_path.into(), "--stdio".into()];
let server = LanguageServer::new(
0,
&node_path,
arguments,
Path::new("/"),
None,
cx.clone(),
)?;
let server = server.initialize(Default::default()).await?;
let status = server
.request::<request::CheckStatus>(request::CheckStatusParams {
local_checks_only: false,
})
.await?;
server
.on_notification::<LogMessage, _>(|params, _cx| {
match params.level {
// Copilot is pretty agressive about logging
0 => debug!("copilot: {}", params.message),
1 => debug!("copilot: {}", params.message),
_ => error!("copilot: {}", params.message),
}
debug!("copilot metadata: {}", params.metadata_str);
debug!("copilot extra: {:?}", params.extra);
})
.detach();
server
.on_notification::<StatusNotification, _>(
|_, _| { /* Silence the notification */ },
)
.detach();
anyhow::Ok((server, status))
};
let server = start_language_server.await;
this.update(&mut cx, |this, cx| {
cx.notify();
match server {
Ok((server, status)) => {
this.server = CopilotServer::Started {
server,
status: SignInStatus::SignedOut,
subscriptions_by_buffer_id: Default::default(),
};
this.update_sign_in_status(status, cx);
}
Err(error) => {
this.server = CopilotServer::Error(error.to_string().into());
cx.notify()
}
}
})
}
}
fn sign_in(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
if let CopilotServer::Started { server, status, .. } = &mut self.server {
let task = match status {
SignInStatus::Authorized { .. } | SignInStatus::Unauthorized { .. } => {
Task::ready(Ok(())).shared()
}
SignInStatus::SigningIn { task, .. } => {
cx.notify();
task.clone()
}
SignInStatus::SignedOut => {
let server = server.clone();
let task = cx
.spawn(|this, mut cx| async move {
let sign_in = async {
let sign_in = server
.request::<request::SignInInitiate>(
request::SignInInitiateParams {},
)
.await?;
match sign_in {
request::SignInInitiateResult::AlreadySignedIn { user } => {
Ok(request::SignInStatus::Ok { user })
}
request::SignInInitiateResult::PromptUserDeviceFlow(flow) => {
this.update(&mut cx, |this, cx| {
if let CopilotServer::Started { status, .. } =
&mut this.server
{
if let SignInStatus::SigningIn {
prompt: prompt_flow,
..
} = status
{
*prompt_flow = Some(flow.clone());
cx.notify();
}
}
});
let response = server
.request::<request::SignInConfirm>(
request::SignInConfirmParams {
user_code: flow.user_code,
},
)
.await?;
Ok(response)
}
}
};
let sign_in = sign_in.await;
this.update(&mut cx, |this, cx| match sign_in {
Ok(status) => {
this.update_sign_in_status(status, cx);
Ok(())
}
Err(error) => {
this.update_sign_in_status(
request::SignInStatus::NotSignedIn,
cx,
);
Err(Arc::new(error))
}
})
})
.shared();
*status = SignInStatus::SigningIn {
prompt: None,
task: task.clone(),
};
cx.notify();
task
}
};
cx.foreground()
.spawn(task.map_err(|err| anyhow!("{:?}", err)))
} else {
// If we're downloading, wait until download is finished
// If we're in a stuck state, display to the user
Task::ready(Err(anyhow!("copilot hasn't started yet")))
}
}
fn sign_out(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
if let CopilotServer::Started { server, status, .. } = &mut self.server {
*status = SignInStatus::SignedOut;
cx.notify();
let server = server.clone();
cx.background().spawn(async move {
server
.request::<request::SignOut>(request::SignOutParams {})
.await?;
anyhow::Ok(())
})
} else {
Task::ready(Err(anyhow!("copilot hasn't started yet")))
}
}
fn reinstall(&mut self, cx: &mut ModelContext<Self>) -> Task<()> {
let start_task = cx
.spawn({
let http = self.http.clone();
let node_runtime = self.node_runtime.clone();
move |this, cx| async move {
clear_copilot_dir().await;
Self::start_language_server(http, node_runtime, this, cx).await
}
})
.shared();
self.server = CopilotServer::Starting {
task: start_task.clone(),
};
cx.notify();
cx.foreground().spawn(start_task)
}
pub fn completions<T>(
&mut self,
buffer: &ModelHandle<Buffer>,
position: T,
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<Completion>>>
where
T: ToPointUtf16,
{
self.request_completions::<request::GetCompletions, _>(buffer, position, cx)
}
pub fn completions_cycling<T>(
&mut self,
buffer: &ModelHandle<Buffer>,
position: T,
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<Completion>>>
where
T: ToPointUtf16,
{
self.request_completions::<request::GetCompletionsCycling, _>(buffer, position, cx)
}
fn request_completions<R, T>(
&mut self,
buffer: &ModelHandle<Buffer>,
position: T,
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<Completion>>>
where
R: lsp::request::Request<
Params = request::GetCompletionsParams,
Result = request::GetCompletionsResult,
>,
T: ToPointUtf16,
{
let buffer_id = buffer.id();
let uri: lsp::Url = format!("buffer://{}", buffer_id).parse().unwrap();
let snapshot = buffer.read(cx).snapshot();
let server = match &mut self.server {
CopilotServer::Starting { .. } => {
return Task::ready(Err(anyhow!("copilot is still starting")))
}
CopilotServer::Disabled => return Task::ready(Err(anyhow!("copilot is disabled"))),
CopilotServer::Error(error) => {
return Task::ready(Err(anyhow!(
"copilot was not started because of an error: {}",
error
)))
}
CopilotServer::Started {
server,
status,
subscriptions_by_buffer_id,
} => {
if matches!(status, SignInStatus::Authorized { .. }) {
subscriptions_by_buffer_id
.entry(buffer_id)
.or_insert_with(|| {
server
.notify::<lsp::notification::DidOpenTextDocument>(
lsp::DidOpenTextDocumentParams {
text_document: lsp::TextDocumentItem {
uri: uri.clone(),
language_id: id_for_language(
buffer.read(cx).language(),
),
version: 0,
text: snapshot.text(),
},
},
)
.log_err();
let uri = uri.clone();
cx.observe_release(buffer, move |this, _, _| {
if let CopilotServer::Started {
server,
subscriptions_by_buffer_id,
..
} = &mut this.server
{
server
.notify::<lsp::notification::DidCloseTextDocument>(
lsp::DidCloseTextDocumentParams {
text_document: lsp::TextDocumentIdentifier::new(
uri.clone(),
),
},
)
.log_err();
subscriptions_by_buffer_id.remove(&buffer_id);
}
})
});
server.clone()
} else {
return Task::ready(Err(anyhow!("must sign in before using copilot")));
}
}
};
let settings = cx.global::<Settings>();
let position = position.to_point_utf16(&snapshot);
let language = snapshot.language_at(position);
let language_name = language.map(|language| language.name());
let language_name = language_name.as_deref();
let tab_size = settings.tab_size(language_name);
let hard_tabs = settings.hard_tabs(language_name);
let language_id = id_for_language(language);
let path;
let relative_path;
if let Some(file) = snapshot.file() {
if let Some(file) = file.as_local() {
path = file.abs_path(cx);
} else {
path = file.full_path(cx);
}
relative_path = file.path().to_path_buf();
} else {
path = PathBuf::new();
relative_path = PathBuf::new();
}
cx.background().spawn(async move {
let result = server
.request::<R>(request::GetCompletionsParams {
doc: request::GetCompletionsDocument {
source: snapshot.text(),
tab_size: tab_size.into(),
indent_size: 1,
insert_spaces: !hard_tabs,
uri,
path: path.to_string_lossy().into(),
relative_path: relative_path.to_string_lossy().into(),
language_id,
position: point_to_lsp(position),
version: 0,
},
})
.await?;
let completions = result
.completions
.into_iter()
.map(|completion| {
let start = snapshot
.clip_point_utf16(point_from_lsp(completion.range.start), Bias::Left);
let end =
snapshot.clip_point_utf16(point_from_lsp(completion.range.end), Bias::Left);
Completion {
range: snapshot.anchor_before(start)..snapshot.anchor_after(end),
text: completion.text,
}
})
.collect();
anyhow::Ok(completions)
})
}
pub fn status(&self) -> Status {
match &self.server {
CopilotServer::Starting { task } => Status::Starting { task: task.clone() },
CopilotServer::Disabled => Status::Disabled,
CopilotServer::Error(error) => Status::Error(error.clone()),
CopilotServer::Started { status, .. } => match status {
SignInStatus::Authorized { .. } => Status::Authorized,
SignInStatus::Unauthorized { .. } => Status::Unauthorized,
SignInStatus::SigningIn { prompt, .. } => Status::SigningIn {
prompt: prompt.clone(),
},
SignInStatus::SignedOut => Status::SignedOut,
},
}
}
fn update_sign_in_status(
&mut self,
lsp_status: request::SignInStatus,
cx: &mut ModelContext<Self>,
) {
if let CopilotServer::Started { status, .. } = &mut self.server {
*status = match lsp_status {
request::SignInStatus::Ok { .. }
| request::SignInStatus::MaybeOk { .. }
| request::SignInStatus::AlreadySignedIn { .. } => SignInStatus::Authorized,
request::SignInStatus::NotAuthorized { .. } => SignInStatus::Unauthorized,
request::SignInStatus::NotSignedIn => SignInStatus::SignedOut,
};
cx.notify();
}
}
}
fn id_for_language(language: Option<&Arc<Language>>) -> String {
let language_name = language.map(|language| language.name());
match language_name.as_deref() {
Some("Plain Text") => "plaintext".to_string(),
Some(language_name) => language_name.to_lowercase(),
None => "plaintext".to_string(),
}
}
async fn clear_copilot_dir() {
remove_matching(&paths::COPILOT_DIR, |_| true).await
}
async fn get_copilot_lsp(http: Arc<dyn HttpClient>) -> anyhow::Result<PathBuf> {
const SERVER_PATH: &'static str = "dist/agent.js";
///Check for the latest copilot language server and download it if we haven't already
async fn fetch_latest(http: Arc<dyn HttpClient>) -> anyhow::Result<PathBuf> {
let release = latest_github_release("zed-industries/copilot", http.clone()).await?;
let version_dir = &*paths::COPILOT_DIR.join(format!("copilot-{}", release.name));
fs::create_dir_all(version_dir).await?;
let server_path = version_dir.join(SERVER_PATH);
if fs::metadata(&server_path).await.is_err() {
// Copilot LSP looks for this dist dir specifcially, so lets add it in.
let dist_dir = version_dir.join("dist");
fs::create_dir_all(dist_dir.as_path()).await?;
let url = &release
.assets
.get(0)
.context("Github release for copilot contained no assets")?
.browser_download_url;
let mut response = http
.get(&url, Default::default(), true)
.await
.map_err(|err| anyhow!("error downloading copilot release: {}", err))?;
let decompressed_bytes = GzipDecoder::new(BufReader::new(response.body_mut()));
let archive = Archive::new(decompressed_bytes);
archive.unpack(dist_dir).await?;
remove_matching(&paths::COPILOT_DIR, |entry| entry != version_dir).await;
}
Ok(server_path)
}
match fetch_latest(http).await {
ok @ Result::Ok(..) => ok,
e @ Err(..) => {
e.log_err();
// Fetch a cached binary, if it exists
(|| async move {
let mut last_version_dir = None;
let mut entries = fs::read_dir(paths::COPILOT_DIR.as_path()).await?;
while let Some(entry) = entries.next().await {
let entry = entry?;
if entry.file_type().await?.is_dir() {
last_version_dir = Some(entry.path());
}
}
let last_version_dir =
last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?;
let server_path = last_version_dir.join(SERVER_PATH);
if server_path.exists() {
Ok(server_path)
} else {
Err(anyhow!(
"missing executable in directory {:?}",
last_version_dir
))
}
})()
.await
}
}
}

View file

@ -0,0 +1,171 @@
use serde::{Deserialize, Serialize};
pub enum CheckStatus {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CheckStatusParams {
pub local_checks_only: bool,
}
impl lsp::request::Request for CheckStatus {
type Params = CheckStatusParams;
type Result = SignInStatus;
const METHOD: &'static str = "checkStatus";
}
pub enum SignInInitiate {}
#[derive(Debug, Serialize, Deserialize)]
pub struct SignInInitiateParams {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "status")]
pub enum SignInInitiateResult {
AlreadySignedIn { user: String },
PromptUserDeviceFlow(PromptUserDeviceFlow),
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PromptUserDeviceFlow {
pub user_code: String,
pub verification_uri: String,
}
impl lsp::request::Request for SignInInitiate {
type Params = SignInInitiateParams;
type Result = SignInInitiateResult;
const METHOD: &'static str = "signInInitiate";
}
pub enum SignInConfirm {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SignInConfirmParams {
pub user_code: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "status")]
pub enum SignInStatus {
#[serde(rename = "OK")]
Ok {
user: String,
},
MaybeOk {
user: String,
},
AlreadySignedIn {
user: String,
},
NotAuthorized {
user: String,
},
NotSignedIn,
}
impl lsp::request::Request for SignInConfirm {
type Params = SignInConfirmParams;
type Result = SignInStatus;
const METHOD: &'static str = "signInConfirm";
}
pub enum SignOut {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SignOutParams {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SignOutResult {}
impl lsp::request::Request for SignOut {
type Params = SignOutParams;
type Result = SignOutResult;
const METHOD: &'static str = "signOut";
}
pub enum GetCompletions {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetCompletionsParams {
pub doc: GetCompletionsDocument,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetCompletionsDocument {
pub source: String,
pub tab_size: u32,
pub indent_size: u32,
pub insert_spaces: bool,
pub uri: lsp::Url,
pub path: String,
pub relative_path: String,
pub language_id: String,
pub position: lsp::Position,
pub version: usize,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetCompletionsResult {
pub completions: Vec<Completion>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Completion {
pub text: String,
pub position: lsp::Position,
pub uuid: String,
pub range: lsp::Range,
pub display_text: String,
}
impl lsp::request::Request for GetCompletions {
type Params = GetCompletionsParams;
type Result = GetCompletionsResult;
const METHOD: &'static str = "getCompletions";
}
pub enum GetCompletionsCycling {}
impl lsp::request::Request for GetCompletionsCycling {
type Params = GetCompletionsParams;
type Result = GetCompletionsResult;
const METHOD: &'static str = "getCompletionsCycling";
}
pub enum LogMessage {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LogMessageParams {
pub message: String,
pub level: u8,
pub metadata_str: String,
pub extra: Vec<String>,
}
impl lsp::notification::Notification for LogMessage {
type Params = LogMessageParams;
const METHOD: &'static str = "LogMessage";
}
pub enum StatusNotification {}
#[derive(Debug, Serialize, Deserialize)]
pub struct StatusNotificationParams {
pub message: String,
pub status: String, // One of Normal/InProgress
}
impl lsp::notification::Notification for StatusNotification {
type Params = StatusNotificationParams;
const METHOD: &'static str = "statusNotification";
}

View file

@ -0,0 +1,354 @@
use crate::{request::PromptUserDeviceFlow, Copilot, Status};
use gpui::{
elements::*, geometry::rect::RectF, ClipboardItem, Element, Entity, MutableAppContext, View,
ViewContext, ViewHandle, WindowKind, WindowOptions,
};
use settings::Settings;
use theme::ui::modal;
#[derive(PartialEq, Eq, Debug, Clone)]
struct CopyUserCode;
#[derive(PartialEq, Eq, Debug, Clone)]
struct OpenGithub;
const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot";
pub fn init(cx: &mut MutableAppContext) {
let copilot = Copilot::global(cx).unwrap();
let mut code_verification: Option<ViewHandle<CopilotCodeVerification>> = None;
cx.observe(&copilot, move |copilot, cx| {
let status = copilot.read(cx).status();
match &status {
crate::Status::SigningIn { prompt } => {
if let Some(code_verification_handle) = code_verification.as_mut() {
if cx.has_window(code_verification_handle.window_id()) {
code_verification_handle.update(cx, |code_verification_view, cx| {
code_verification_view.set_status(status, cx)
});
cx.activate_window(code_verification_handle.window_id());
} else {
create_copilot_auth_window(cx, &status, &mut code_verification);
}
} else if let Some(_prompt) = prompt {
create_copilot_auth_window(cx, &status, &mut code_verification);
}
}
Status::Authorized | Status::Unauthorized => {
if let Some(code_verification) = code_verification.as_ref() {
code_verification.update(cx, |code_verification, cx| {
code_verification.set_status(status, cx)
});
cx.platform().activate(true);
cx.activate_window(code_verification.window_id());
}
}
_ => {
if let Some(code_verification) = code_verification.take() {
cx.remove_window(code_verification.window_id());
}
}
}
})
.detach();
}
fn create_copilot_auth_window(
cx: &mut MutableAppContext,
status: &Status,
code_verification: &mut Option<ViewHandle<CopilotCodeVerification>>,
) {
let window_size = cx.global::<Settings>().theme.copilot.modal.dimensions();
let window_options = WindowOptions {
bounds: gpui::WindowBounds::Fixed(RectF::new(Default::default(), window_size)),
titlebar: None,
center: true,
focus: true,
kind: WindowKind::Normal,
is_movable: true,
screen: None,
};
let (_, view) = cx.add_window(window_options, |_cx| {
CopilotCodeVerification::new(status.clone())
});
*code_verification = Some(view);
}
pub struct CopilotCodeVerification {
status: Status,
}
impl CopilotCodeVerification {
pub fn new(status: Status) -> Self {
Self { status }
}
pub fn set_status(&mut self, status: Status, cx: &mut ViewContext<Self>) {
self.status = status;
cx.notify();
}
fn render_device_code(
data: &PromptUserDeviceFlow,
style: &theme::Copilot,
cx: &mut gpui::RenderContext<Self>,
) -> ElementBox {
let copied = cx
.read_from_clipboard()
.map(|item| item.text() == &data.user_code)
.unwrap_or(false);
let device_code_style = &style.auth.prompting.device_code;
MouseEventHandler::<Self>::new(0, cx, |state, _cx| {
Flex::row()
.with_children([
Label::new(data.user_code.clone(), device_code_style.text.clone())
.aligned()
.contained()
.with_style(device_code_style.left_container)
.constrained()
.with_width(device_code_style.left)
.boxed(),
Label::new(
if copied { "Copied!" } else { "Copy" },
device_code_style.cta.style_for(state, false).text.clone(),
)
.aligned()
.contained()
.with_style(*device_code_style.right_container.style_for(state, false))
.constrained()
.with_width(device_code_style.right)
.boxed(),
])
.contained()
.with_style(device_code_style.cta.style_for(state, false).container)
.boxed()
})
.on_click(gpui::MouseButton::Left, {
let user_code = data.user_code.clone();
move |_, cx| {
cx.platform()
.write_to_clipboard(ClipboardItem::new(user_code.clone()));
cx.notify();
}
})
.with_cursor_style(gpui::CursorStyle::PointingHand)
.boxed()
}
fn render_prompting_modal(
data: &PromptUserDeviceFlow,
style: &theme::Copilot,
cx: &mut gpui::RenderContext<Self>,
) -> ElementBox {
Flex::column()
.with_children([
Flex::column()
.with_children([
Label::new(
"Enable Copilot by connecting",
style.auth.prompting.subheading.text.clone(),
)
.aligned()
.boxed(),
Label::new(
"your existing license.",
style.auth.prompting.subheading.text.clone(),
)
.aligned()
.boxed(),
])
.align_children_center()
.contained()
.with_style(style.auth.prompting.subheading.container)
.boxed(),
Self::render_device_code(data, &style, cx),
Flex::column()
.with_children([
Label::new(
"Paste this code into GitHub after",
style.auth.prompting.hint.text.clone(),
)
.aligned()
.boxed(),
Label::new(
"clicking the button below.",
style.auth.prompting.hint.text.clone(),
)
.aligned()
.boxed(),
])
.align_children_center()
.contained()
.with_style(style.auth.prompting.hint.container.clone())
.boxed(),
theme::ui::cta_button_with_click(
"Connect to GitHub",
style.auth.content_width,
&style.auth.cta_button,
cx,
{
let verification_uri = data.verification_uri.clone();
move |_, cx| cx.platform().open_url(&verification_uri)
},
)
.boxed(),
])
.align_children_center()
.boxed()
}
fn render_enabled_modal(
style: &theme::Copilot,
cx: &mut gpui::RenderContext<Self>,
) -> ElementBox {
let enabled_style = &style.auth.authorized;
Flex::column()
.with_children([
Label::new("Copilot Enabled!", enabled_style.subheading.text.clone())
.contained()
.with_style(enabled_style.subheading.container)
.aligned()
.boxed(),
Flex::column()
.with_children([
Label::new(
"You can update your settings or",
enabled_style.hint.text.clone(),
)
.aligned()
.boxed(),
Label::new(
"sign out from the Copilot menu in",
enabled_style.hint.text.clone(),
)
.aligned()
.boxed(),
Label::new("the status bar.", enabled_style.hint.text.clone())
.aligned()
.boxed(),
])
.align_children_center()
.contained()
.with_style(enabled_style.hint.container)
.boxed(),
theme::ui::cta_button_with_click(
"Done",
style.auth.content_width,
&style.auth.cta_button,
cx,
|_, cx| {
let window_id = cx.window_id();
cx.remove_window(window_id)
},
)
.boxed(),
])
.align_children_center()
.boxed()
}
fn render_unauthorized_modal(
style: &theme::Copilot,
cx: &mut gpui::RenderContext<Self>,
) -> ElementBox {
let unauthorized_style = &style.auth.not_authorized;
Flex::column()
.with_children([
Flex::column()
.with_children([
Label::new(
"Enable Copilot by connecting",
unauthorized_style.subheading.text.clone(),
)
.aligned()
.boxed(),
Label::new(
"your existing license.",
unauthorized_style.subheading.text.clone(),
)
.aligned()
.boxed(),
])
.align_children_center()
.contained()
.with_style(unauthorized_style.subheading.container)
.boxed(),
Flex::column()
.with_children([
Label::new(
"You must have an active copilot",
unauthorized_style.warning.text.clone(),
)
.aligned()
.boxed(),
Label::new(
"license to use it in Zed.",
unauthorized_style.warning.text.clone(),
)
.aligned()
.boxed(),
])
.align_children_center()
.contained()
.with_style(unauthorized_style.warning.container)
.boxed(),
theme::ui::cta_button_with_click(
"Subscribe on GitHub",
style.auth.content_width,
&style.auth.cta_button,
cx,
|_, cx| {
let window_id = cx.window_id();
cx.remove_window(window_id);
cx.platform().open_url(COPILOT_SIGN_UP_URL)
},
)
.boxed(),
])
.align_children_center()
.boxed()
}
}
impl Entity for CopilotCodeVerification {
type Event = ();
}
impl View for CopilotCodeVerification {
fn ui_name() -> &'static str {
"CopilotCodeVerification"
}
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut gpui::ViewContext<Self>) {
cx.notify()
}
fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut gpui::ViewContext<Self>) {
cx.notify()
}
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
let style = cx.global::<Settings>().theme.clone();
modal("Connect Copilot to Zed", &style.copilot.modal, cx, |cx| {
Flex::column()
.with_children([
theme::ui::icon(&style.copilot.auth.header).boxed(),
match &self.status {
Status::SigningIn {
prompt: Some(prompt),
} => Self::render_prompting_modal(&prompt, &style.copilot, cx),
Status::Unauthorized => Self::render_unauthorized_modal(&style.copilot, cx),
Status::Authorized => Self::render_enabled_modal(&style.copilot, cx),
_ => Empty::new().boxed(),
},
])
.align_children_center()
.boxed()
})
}
}

View file

@ -0,0 +1,22 @@
[package]
name = "copilot_button"
version = "0.1.0"
edition = "2021"
publish = false
[lib]
path = "src/copilot_button.rs"
doctest = false
[dependencies]
copilot = { path = "../copilot" }
editor = { path = "../editor" }
context_menu = { path = "../context_menu" }
gpui = { path = "../gpui" }
settings = { path = "../settings" }
theme = { path = "../theme" }
util = { path = "../util" }
workspace = { path = "../workspace" }
anyhow = "1.0"
smol = "1.2.5"
futures = "0.3"

View file

@ -0,0 +1,338 @@
use std::sync::Arc;
use context_menu::{ContextMenu, ContextMenuItem};
use editor::Editor;
use gpui::{
elements::*, impl_internal_actions, CursorStyle, Element, ElementBox, Entity, MouseButton,
MouseState, MutableAppContext, RenderContext, Subscription, View, ViewContext, ViewHandle,
};
use settings::{settings_file::SettingsFile, Settings};
use workspace::{
item::ItemHandle, notifications::simple_message_notification::OsOpen, DismissToast,
StatusItemView,
};
use copilot::{Copilot, Reinstall, SignIn, SignOut, Status};
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
const COPILOT_STARTING_TOAST_ID: usize = 1337;
const COPILOT_ERROR_TOAST_ID: usize = 1338;
#[derive(Clone, PartialEq)]
pub struct DeployCopilotMenu;
#[derive(Clone, PartialEq)]
pub struct ToggleCopilotForLanguage {
language: Arc<str>,
}
#[derive(Clone, PartialEq)]
pub struct ToggleCopilotGlobally;
// TODO: Make the other code path use `get_or_insert` logic for this modal
#[derive(Clone, PartialEq)]
pub struct DeployCopilotModal;
impl_internal_actions!(
copilot,
[
DeployCopilotMenu,
DeployCopilotModal,
ToggleCopilotForLanguage,
ToggleCopilotGlobally,
]
);
pub fn init(cx: &mut MutableAppContext) {
cx.add_action(CopilotButton::deploy_copilot_menu);
cx.add_action(
|_: &mut CopilotButton, action: &ToggleCopilotForLanguage, cx| {
let language = action.language.to_owned();
let current_langauge = cx.global::<Settings>().copilot_on(Some(&language));
SettingsFile::update(cx, move |file_contents| {
file_contents.languages.insert(
language.to_owned(),
settings::EditorSettings {
copilot: Some((!current_langauge).into()),
..Default::default()
},
);
})
},
);
cx.add_action(|_: &mut CopilotButton, _: &ToggleCopilotGlobally, cx| {
let copilot_on = cx.global::<Settings>().copilot_on(None);
SettingsFile::update(cx, move |file_contents| {
file_contents.editor.copilot = Some((!copilot_on).into())
})
});
}
pub struct CopilotButton {
popup_menu: ViewHandle<ContextMenu>,
editor_subscription: Option<(Subscription, usize)>,
editor_enabled: Option<bool>,
language: Option<Arc<str>>,
}
impl Entity for CopilotButton {
type Event = ();
}
impl View for CopilotButton {
fn ui_name() -> &'static str {
"CopilotButton"
}
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
let settings = cx.global::<Settings>();
if !settings.enable_copilot_integration {
return Empty::new().boxed();
}
let theme = settings.theme.clone();
let active = self.popup_menu.read(cx).visible();
let Some(copilot) = Copilot::global(cx) else {
return Empty::new().boxed();
};
let status = copilot.read(cx).status();
let enabled = self.editor_enabled.unwrap_or(settings.copilot_on(None));
let view_id = cx.view_id();
Stack::new()
.with_child(
MouseEventHandler::<Self>::new(0, cx, {
let theme = theme.clone();
let status = status.clone();
move |state, _cx| {
let style = theme
.workspace
.status_bar
.sidebar_buttons
.item
.style_for(state, active);
Flex::row()
.with_child(
Svg::new({
match status {
Status::Error(_) => "icons/copilot_error_16.svg",
Status::Authorized => {
if enabled {
"icons/copilot_16.svg"
} else {
"icons/copilot_disabled_16.svg"
}
}
_ => "icons/copilot_init_16.svg",
}
})
.with_color(style.icon_color)
.constrained()
.with_width(style.icon_size)
.aligned()
.named("copilot-icon"),
)
.constrained()
.with_height(style.icon_size)
.contained()
.with_style(style.container)
.boxed()
}
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, {
let status = status.clone();
move |_, cx| match status {
Status::Authorized => cx.dispatch_action(DeployCopilotMenu),
Status::Starting { ref task } => {
cx.dispatch_action(workspace::Toast::new(
COPILOT_STARTING_TOAST_ID,
"Copilot is starting...",
));
let window_id = cx.window_id();
let task = task.to_owned();
cx.spawn(|mut cx| async move {
task.await;
cx.update(|cx| {
if let Some(copilot) = Copilot::global(cx) {
let status = copilot.read(cx).status();
match status {
Status::Authorized => cx.dispatch_action_at(
window_id,
view_id,
workspace::Toast::new(
COPILOT_STARTING_TOAST_ID,
"Copilot has started!",
),
),
_ => {
cx.dispatch_action_at(
window_id,
view_id,
DismissToast::new(COPILOT_STARTING_TOAST_ID),
);
cx.dispatch_global_action(SignIn)
}
}
}
})
})
.detach();
}
Status::Error(ref e) => cx.dispatch_action(workspace::Toast::new_action(
COPILOT_ERROR_TOAST_ID,
format!("Copilot can't be started: {}", e),
"Reinstall Copilot",
Reinstall,
)),
_ => cx.dispatch_action(SignIn),
}
})
.with_tooltip::<Self, _>(
0,
"GitHub Copilot".into(),
None,
theme.tooltip.clone(),
cx,
)
.boxed(),
)
.with_child(
ChildView::new(&self.popup_menu, cx)
.aligned()
.top()
.right()
.boxed(),
)
.boxed()
}
}
impl CopilotButton {
pub fn new(cx: &mut ViewContext<Self>) -> Self {
let menu = cx.add_view(|cx| {
let mut menu = ContextMenu::new(cx);
menu.set_position_mode(OverlayPositionMode::Local);
menu
});
cx.observe(&menu, |_, _, cx| cx.notify()).detach();
Copilot::global(cx).map(|copilot| cx.observe(&copilot, |_, _, cx| cx.notify()).detach());
cx.observe_global::<Settings, _>(move |_, cx| cx.notify())
.detach();
Self {
popup_menu: menu,
editor_subscription: None,
editor_enabled: None,
language: None,
}
}
pub fn deploy_copilot_menu(&mut self, _: &DeployCopilotMenu, cx: &mut ViewContext<Self>) {
let settings = cx.global::<Settings>();
let mut menu_options = Vec::with_capacity(6);
if let Some(language) = &self.language {
let language_enabled = settings.copilot_on(Some(language.as_ref()));
menu_options.push(ContextMenuItem::item(
format!(
"{} Copilot for {}",
if language_enabled {
"Disable"
} else {
"Enable"
},
language
),
ToggleCopilotForLanguage {
language: language.to_owned(),
},
));
}
let globally_enabled = cx.global::<Settings>().copilot_on(None);
menu_options.push(ContextMenuItem::item(
if globally_enabled {
"Disable Copilot Globally"
} else {
"Enable Copilot Globally"
},
ToggleCopilotGlobally,
));
menu_options.push(ContextMenuItem::Separator);
let icon_style = settings.theme.copilot.out_link_icon.clone();
menu_options.push(ContextMenuItem::element_item(
Box::new(
move |state: &mut MouseState, style: &theme::ContextMenuItem| {
Flex::row()
.with_children([
Label::new("Copilot Settings", style.label.clone()).boxed(),
theme::ui::icon(icon_style.style_for(state, false)).boxed(),
])
.align_children_center()
.boxed()
},
),
OsOpen::new(COPILOT_SETTINGS_URL),
));
menu_options.push(ContextMenuItem::item("Sign Out", SignOut));
self.popup_menu.update(cx, |menu, cx| {
menu.show(
Default::default(),
AnchorCorner::BottomRight,
menu_options,
cx,
);
});
}
pub fn update_enabled(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
let editor = editor.read(cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);
let settings = cx.global::<Settings>();
let suggestion_anchor = editor.selections.newest_anchor().start;
let language_name = snapshot
.language_at(suggestion_anchor)
.map(|language| language.name());
self.language = language_name.clone();
self.editor_enabled = Some(settings.copilot_on(language_name.as_deref()));
cx.notify()
}
}
impl StatusItemView for CopilotButton {
fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
if let Some(editor) = item.map(|item| item.act_as::<Editor>(cx)).flatten() {
self.editor_subscription =
Some((cx.observe(&editor, Self::update_enabled), editor.id()));
self.update_enabled(editor, cx);
} else {
self.language = None;
self.editor_subscription = None;
self.editor_enabled = None;
}
cx.notify();
}
}

View file

@ -23,8 +23,8 @@ async-trait = "0.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
parking_lot = "0.11.1" parking_lot = "0.11.1"
serde = { version = "1.0", features = ["derive"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
smol = "1.2" smol = "1.2"
[dev-dependencies] [dev-dependencies]

View file

@ -29,4 +29,4 @@ editor = { path = "../editor", features = ["test-support"] }
language = { path = "../language", features = ["test-support"] } language = { path = "../language", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
serde_json = { version = "1", features = ["preserve_order"] } serde_json = { workspace = true }

View file

@ -11,6 +11,7 @@ doctest = false
[features] [features]
test-support = [ test-support = [
"rand", "rand",
"copilot/test-support",
"text/test-support", "text/test-support",
"language/test-support", "language/test-support",
"gpui/test-support", "gpui/test-support",
@ -22,10 +23,10 @@ test-support = [
] ]
[dependencies] [dependencies]
drag_and_drop = { path = "../drag_and_drop" }
text = { path = "../text" }
clock = { path = "../clock" } clock = { path = "../clock" }
copilot = { path = "../copilot" }
db = { path = "../db" } db = { path = "../db" }
drag_and_drop = { path = "../drag_and_drop" }
collections = { path = "../collections" } collections = { path = "../collections" }
context_menu = { path = "../context_menu" } context_menu = { path = "../context_menu" }
fuzzy = { path = "../fuzzy" } fuzzy = { path = "../fuzzy" }
@ -38,10 +39,12 @@ rpc = { path = "../rpc" }
settings = { path = "../settings" } settings = { path = "../settings" }
snippet = { path = "../snippet" } snippet = { path = "../snippet" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
text = { path = "../text" }
theme = { path = "../theme" } theme = { path = "../theme" }
util = { path = "../util" } util = { path = "../util" }
sqlez = { path = "../sqlez" } sqlez = { path = "../sqlez" }
workspace = { path = "../workspace" } workspace = { path = "../workspace" }
aho-corasick = "0.7" aho-corasick = "0.7"
anyhow = "1.0" anyhow = "1.0"
futures = "0.3" futures = "0.3"
@ -54,7 +57,7 @@ parking_lot = "0.11"
postage = { workspace = true } postage = { workspace = true }
rand = { version = "0.8.3", optional = true } rand = { version = "0.8.3", optional = true }
serde = { workspace = true } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
smallvec = { version = "1.6", features = ["union"] } smallvec = { version = "1.6", features = ["union"] }
smol = "1.2" smol = "1.2"
tree-sitter-rust = { version = "*", optional = true } tree-sitter-rust = { version = "*", optional = true }
@ -63,6 +66,7 @@ tree-sitter-javascript = { version = "*", optional = true }
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259", optional = true } tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259", optional = true }
[dev-dependencies] [dev-dependencies]
copilot = { path = "../copilot", features = ["test-support"] }
text = { path = "../text", features = ["test-support"] } text = { path = "../text", features = ["test-support"] }
language = { path = "../language", features = ["test-support"] } language = { path = "../language", features = ["test-support"] }
lsp = { path = "../lsp", features = ["test-support"] } lsp = { path = "../lsp", features = ["test-support"] }

View file

@ -7,7 +7,7 @@ mod wrap_map;
use crate::{Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint}; use crate::{Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
pub use block_map::{BlockMap, BlockPoint}; pub use block_map::{BlockMap, BlockPoint};
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use fold_map::FoldMap; use fold_map::{FoldMap, FoldOffset};
use gpui::{ use gpui::{
color::Color, color::Color,
fonts::{FontId, HighlightStyle}, fonts::{FontId, HighlightStyle},
@ -19,7 +19,7 @@ use std::{any::TypeId, fmt::Debug, num::NonZeroU32, ops::Range, sync::Arc};
pub use suggestion_map::Suggestion; pub use suggestion_map::Suggestion;
use suggestion_map::SuggestionMap; use suggestion_map::SuggestionMap;
use sum_tree::{Bias, TreeMap}; use sum_tree::{Bias, TreeMap};
use tab_map::{TabMap, TabSnapshot}; use tab_map::TabMap;
use wrap_map::WrapMap; use wrap_map::WrapMap;
pub use block_map::{ pub use block_map::{
@ -230,23 +230,30 @@ impl DisplayMap {
self.text_highlights.remove(&Some(type_id)) self.text_highlights.remove(&Some(type_id))
} }
pub fn has_suggestion(&self) -> bool {
self.suggestion_map.has_suggestion()
}
pub fn replace_suggestion<T>( pub fn replace_suggestion<T>(
&self, &self,
new_suggestion: Option<Suggestion<T>>, new_suggestion: Option<Suggestion<T>>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) where ) -> Option<Suggestion<FoldOffset>>
where
T: ToPoint, T: ToPoint,
{ {
let snapshot = self.buffer.read(cx).snapshot(cx); let snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner(); let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx); let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.fold_map.read(snapshot, edits); let (snapshot, edits) = self.fold_map.read(snapshot, edits);
let (snapshot, edits) = self.suggestion_map.replace(new_suggestion, snapshot, edits); let (snapshot, edits, old_suggestion) =
self.suggestion_map.replace(new_suggestion, snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size); let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self let (snapshot, edits) = self
.wrap_map .wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx)); .update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits); self.block_map.read(snapshot, edits);
old_suggestion
} }
pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) -> bool { pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) -> bool {
@ -382,7 +389,7 @@ impl DisplaySnapshot {
/// Returns text chunks starting at the given display row until the end of the file /// Returns text chunks starting at the given display row until the end of the file
pub fn text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> { pub fn text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
self.block_snapshot self.block_snapshot
.chunks(display_row..self.max_point().row() + 1, false, None) .chunks(display_row..self.max_point().row() + 1, false, None, None)
.map(|h| h.text) .map(|h| h.text)
} }
@ -390,7 +397,7 @@ impl DisplaySnapshot {
pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> { pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
(0..=display_row).into_iter().rev().flat_map(|row| { (0..=display_row).into_iter().rev().flat_map(|row| {
self.block_snapshot self.block_snapshot
.chunks(row..row + 1, false, None) .chunks(row..row + 1, false, None, None)
.map(|h| h.text) .map(|h| h.text)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter() .into_iter()
@ -398,9 +405,18 @@ impl DisplaySnapshot {
}) })
} }
pub fn chunks(&self, display_rows: Range<u32>, language_aware: bool) -> DisplayChunks<'_> { pub fn chunks(
self.block_snapshot &self,
.chunks(display_rows, language_aware, Some(&self.text_highlights)) display_rows: Range<u32>,
language_aware: bool,
suggestion_highlight: Option<HighlightStyle>,
) -> DisplayChunks<'_> {
self.block_snapshot.chunks(
display_rows,
language_aware,
Some(&self.text_highlights),
suggestion_highlight,
)
} }
pub fn chars_at( pub fn chars_at(
@ -634,25 +650,21 @@ impl DisplaySnapshot {
.buffer_snapshot .buffer_snapshot
.buffer_line_for_row(buffer_row) .buffer_line_for_row(buffer_row)
.unwrap(); .unwrap();
let chars = buffer.chars_at(Point::new(range.start.row, 0));
let mut indent_size = 0;
let mut is_blank = false; let mut is_blank = false;
let indent_size = TabSnapshot::expand_tabs( for c in buffer.chars_at(Point::new(range.start.row, 0)) {
chars.take_while(|c| { if c == ' ' || c == '\t' {
if *c == ' ' || *c == '\t' { indent_size += 1;
true } else {
} else { if c == '\n' {
if *c == '\n' { is_blank = true;
is_blank = true;
}
false
} }
}), break;
buffer.line_len(buffer_row) as usize, // Never collapse }
self.tab_snapshot.tab_size, }
);
(indent_size as u32, is_blank) (indent_size, is_blank)
} }
pub fn line_len(&self, row: u32) -> u32 { pub fn line_len(&self, row: u32) -> u32 {
@ -1691,7 +1703,7 @@ pub mod tests {
) -> Vec<(String, Option<Color>, Option<Color>)> { ) -> Vec<(String, Option<Color>, Option<Color>)> {
let snapshot = map.update(cx, |map, cx| map.snapshot(cx)); let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
let mut chunks: Vec<(String, Option<Color>, Option<Color>)> = Vec::new(); let mut chunks: Vec<(String, Option<Color>, Option<Color>)> = Vec::new();
for chunk in snapshot.chunks(rows, true) { for chunk in snapshot.chunks(rows, true, None) {
let syntax_color = chunk let syntax_color = chunk
.syntax_highlight_id .syntax_highlight_id
.and_then(|id| id.style(theme)?.color); .and_then(|id| id.style(theme)?.color);

View file

@ -4,7 +4,7 @@ use super::{
}; };
use crate::{Anchor, ExcerptId, ExcerptRange, ToPoint as _}; use crate::{Anchor, ExcerptId, ExcerptRange, ToPoint as _};
use collections::{Bound, HashMap, HashSet}; use collections::{Bound, HashMap, HashSet};
use gpui::{ElementBox, RenderContext}; use gpui::{fonts::HighlightStyle, ElementBox, RenderContext};
use language::{BufferSnapshot, Chunk, Patch, Point}; use language::{BufferSnapshot, Chunk, Patch, Point};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{ use std::{
@ -572,7 +572,7 @@ impl<'a> BlockMapWriter<'a> {
impl BlockSnapshot { impl BlockSnapshot {
#[cfg(test)] #[cfg(test)]
pub fn text(&self) -> String { pub fn text(&self) -> String {
self.chunks(0..self.transforms.summary().output_rows, false, None) self.chunks(0..self.transforms.summary().output_rows, false, None, None)
.map(|chunk| chunk.text) .map(|chunk| chunk.text)
.collect() .collect()
} }
@ -582,6 +582,7 @@ impl BlockSnapshot {
rows: Range<u32>, rows: Range<u32>,
language_aware: bool, language_aware: bool,
text_highlights: Option<&'a TextHighlights>, text_highlights: Option<&'a TextHighlights>,
suggestion_highlight: Option<HighlightStyle>,
) -> BlockChunks<'a> { ) -> BlockChunks<'a> {
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows); let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(); let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
@ -614,6 +615,7 @@ impl BlockSnapshot {
input_start..input_end, input_start..input_end,
language_aware, language_aware,
text_highlights, text_highlights,
suggestion_highlight,
), ),
input_chunk: Default::default(), input_chunk: Default::default(),
transforms: cursor, transforms: cursor,
@ -1498,6 +1500,7 @@ mod tests {
start_row as u32..blocks_snapshot.max_point().row + 1, start_row as u32..blocks_snapshot.max_point().row + 1,
false, false,
None, None,
None,
) )
.map(|chunk| chunk.text) .map(|chunk| chunk.text)
.collect::<String>(); .collect::<String>();

View file

@ -60,7 +60,6 @@ impl SuggestionPoint {
pub struct Suggestion<T> { pub struct Suggestion<T> {
pub position: T, pub position: T,
pub text: Rope, pub text: Rope,
pub highlight_style: HighlightStyle,
} }
pub struct SuggestionMap(Mutex<SuggestionSnapshot>); pub struct SuggestionMap(Mutex<SuggestionSnapshot>);
@ -80,7 +79,11 @@ impl SuggestionMap {
new_suggestion: Option<Suggestion<T>>, new_suggestion: Option<Suggestion<T>>,
fold_snapshot: FoldSnapshot, fold_snapshot: FoldSnapshot,
fold_edits: Vec<FoldEdit>, fold_edits: Vec<FoldEdit>,
) -> (SuggestionSnapshot, Vec<SuggestionEdit>) ) -> (
SuggestionSnapshot,
Vec<SuggestionEdit>,
Option<Suggestion<FoldOffset>>,
)
where where
T: ToPoint, T: ToPoint,
{ {
@ -93,7 +96,6 @@ impl SuggestionMap {
Suggestion { Suggestion {
position: fold_offset, position: fold_offset,
text: new_suggestion.text, text: new_suggestion.text,
highlight_style: new_suggestion.highlight_style,
} }
}); });
@ -101,7 +103,8 @@ impl SuggestionMap {
let mut snapshot = self.0.lock(); let mut snapshot = self.0.lock();
let mut patch = Patch::new(edits); let mut patch = Patch::new(edits);
if let Some(suggestion) = snapshot.suggestion.take() { let old_suggestion = snapshot.suggestion.take();
if let Some(suggestion) = &old_suggestion {
patch = patch.compose([SuggestionEdit { patch = patch.compose([SuggestionEdit {
old: SuggestionOffset(suggestion.position.0) old: SuggestionOffset(suggestion.position.0)
..SuggestionOffset(suggestion.position.0 + suggestion.text.len()), ..SuggestionOffset(suggestion.position.0 + suggestion.text.len()),
@ -121,7 +124,7 @@ impl SuggestionMap {
snapshot.suggestion = new_suggestion; snapshot.suggestion = new_suggestion;
snapshot.version += 1; snapshot.version += 1;
(snapshot.clone(), patch.into_inner()) (snapshot.clone(), patch.into_inner(), old_suggestion)
} }
pub fn sync( pub fn sync(
@ -173,6 +176,11 @@ impl SuggestionMap {
(snapshot.clone(), suggestion_edits) (snapshot.clone(), suggestion_edits)
} }
pub fn has_suggestion(&self) -> bool {
let snapshot = self.0.lock();
snapshot.suggestion.is_some()
}
} }
#[derive(Clone)] #[derive(Clone)]
@ -210,6 +218,32 @@ impl SuggestionSnapshot {
} }
} }
pub fn line_len(&self, row: u32) -> u32 {
if let Some(suggestion) = &self.suggestion {
let suggestion_start = suggestion.position.to_point(&self.fold_snapshot).0;
let suggestion_end = suggestion_start + suggestion.text.max_point();
if row < suggestion_start.row {
self.fold_snapshot.line_len(row)
} else if row > suggestion_end.row {
self.fold_snapshot
.line_len(suggestion_start.row + (row - suggestion_end.row))
} else {
let mut result = suggestion.text.line_len(row - suggestion_start.row);
if row == suggestion_start.row {
result += suggestion_start.column;
}
if row == suggestion_end.row {
result +=
self.fold_snapshot.line_len(suggestion_start.row) - suggestion_start.column;
}
result
}
} else {
self.fold_snapshot.line_len(row)
}
}
pub fn clip_point(&self, point: SuggestionPoint, bias: Bias) -> SuggestionPoint { pub fn clip_point(&self, point: SuggestionPoint, bias: Bias) -> SuggestionPoint {
if let Some(suggestion) = self.suggestion.as_ref() { if let Some(suggestion) = self.suggestion.as_ref() {
let suggestion_start = suggestion.position.to_point(&self.fold_snapshot).0; let suggestion_start = suggestion.position.to_point(&self.fold_snapshot).0;
@ -369,7 +403,7 @@ impl SuggestionSnapshot {
pub fn chars_at(&self, start: SuggestionPoint) -> impl '_ + Iterator<Item = char> { pub fn chars_at(&self, start: SuggestionPoint) -> impl '_ + Iterator<Item = char> {
let start = self.to_offset(start); let start = self.to_offset(start);
self.chunks(start..self.len(), false, None) self.chunks(start..self.len(), false, None, None)
.flat_map(|chunk| chunk.text.chars()) .flat_map(|chunk| chunk.text.chars())
} }
@ -378,6 +412,7 @@ impl SuggestionSnapshot {
range: Range<SuggestionOffset>, range: Range<SuggestionOffset>,
language_aware: bool, language_aware: bool,
text_highlights: Option<&'a TextHighlights>, text_highlights: Option<&'a TextHighlights>,
suggestion_highlight: Option<HighlightStyle>,
) -> SuggestionChunks<'a> { ) -> SuggestionChunks<'a> {
if let Some(suggestion) = self.suggestion.as_ref() { if let Some(suggestion) = self.suggestion.as_ref() {
let suggestion_range = let suggestion_range =
@ -421,7 +456,7 @@ impl SuggestionSnapshot {
prefix_chunks, prefix_chunks,
suggestion_chunks, suggestion_chunks,
suffix_chunks, suffix_chunks,
highlight_style: suggestion.highlight_style, highlight_style: suggestion_highlight,
} }
} else { } else {
SuggestionChunks { SuggestionChunks {
@ -432,7 +467,7 @@ impl SuggestionSnapshot {
)), )),
suggestion_chunks: None, suggestion_chunks: None,
suffix_chunks: None, suffix_chunks: None,
highlight_style: Default::default(), highlight_style: None,
} }
} }
} }
@ -467,7 +502,7 @@ impl SuggestionSnapshot {
#[cfg(test)] #[cfg(test)]
pub fn text(&self) -> String { pub fn text(&self) -> String {
self.chunks(Default::default()..self.len(), false, None) self.chunks(Default::default()..self.len(), false, None, None)
.map(|chunk| chunk.text) .map(|chunk| chunk.text)
.collect() .collect()
} }
@ -477,7 +512,7 @@ pub struct SuggestionChunks<'a> {
prefix_chunks: Option<FoldChunks<'a>>, prefix_chunks: Option<FoldChunks<'a>>,
suggestion_chunks: Option<text::Chunks<'a>>, suggestion_chunks: Option<text::Chunks<'a>>,
suffix_chunks: Option<FoldChunks<'a>>, suffix_chunks: Option<FoldChunks<'a>>,
highlight_style: HighlightStyle, highlight_style: Option<HighlightStyle>,
} }
impl<'a> Iterator for SuggestionChunks<'a> { impl<'a> Iterator for SuggestionChunks<'a> {
@ -497,7 +532,7 @@ impl<'a> Iterator for SuggestionChunks<'a> {
return Some(Chunk { return Some(Chunk {
text: chunk, text: chunk,
syntax_highlight_id: None, syntax_highlight_id: None,
highlight_style: Some(self.highlight_style), highlight_style: self.highlight_style,
diagnostic_severity: None, diagnostic_severity: None,
is_unnecessary: false, is_unnecessary: false,
}); });
@ -559,11 +594,10 @@ mod tests {
let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot.clone()); let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot.clone());
assert_eq!(suggestion_snapshot.text(), "abcdefghi"); assert_eq!(suggestion_snapshot.text(), "abcdefghi");
let (suggestion_snapshot, _) = suggestion_map.replace( let (suggestion_snapshot, _, _) = suggestion_map.replace(
Some(Suggestion { Some(Suggestion {
position: 3, position: 3,
text: "123\n456".into(), text: "123\n456".into(),
highlight_style: Default::default(),
}), }),
fold_snapshot, fold_snapshot,
Default::default(), Default::default(),
@ -692,7 +726,12 @@ mod tests {
start = expected_text.clip_offset(start, Bias::Right); start = expected_text.clip_offset(start, Bias::Right);
let actual_text = suggestion_snapshot let actual_text = suggestion_snapshot
.chunks(SuggestionOffset(start)..SuggestionOffset(end), false, None) .chunks(
SuggestionOffset(start)..SuggestionOffset(end),
false,
None,
None,
)
.map(|chunk| chunk.text) .map(|chunk| chunk.text)
.collect::<String>(); .collect::<String>();
assert_eq!( assert_eq!(
@ -816,12 +855,13 @@ mod tests {
.collect::<String>() .collect::<String>()
.as_str() .as_str()
.into(), .into(),
highlight_style: Default::default(),
}) })
}; };
log::info!("replacing suggestion with {:?}", new_suggestion); log::info!("replacing suggestion with {:?}", new_suggestion);
self.replace(new_suggestion, fold_snapshot, Default::default()) let (snapshot, edits, _) =
self.replace(new_suggestion, fold_snapshot, Default::default());
(snapshot, edits)
} }
} }
} }

View file

@ -3,11 +3,14 @@ use super::{
TextHighlights, TextHighlights,
}; };
use crate::MultiBufferSnapshot; use crate::MultiBufferSnapshot;
use gpui::fonts::HighlightStyle;
use language::{Chunk, Point}; use language::{Chunk, Point};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{cmp, mem, num::NonZeroU32, ops::Range}; use std::{cmp, mem, num::NonZeroU32, ops::Range};
use sum_tree::Bias; use sum_tree::Bias;
const MAX_EXPANSION_COLUMN: u32 = 256;
pub struct TabMap(Mutex<TabSnapshot>); pub struct TabMap(Mutex<TabSnapshot>);
impl TabMap { impl TabMap {
@ -15,11 +18,18 @@ impl TabMap {
let snapshot = TabSnapshot { let snapshot = TabSnapshot {
suggestion_snapshot: input, suggestion_snapshot: input,
tab_size, tab_size,
max_expansion_column: MAX_EXPANSION_COLUMN,
version: 0, version: 0,
}; };
(Self(Mutex::new(snapshot.clone())), snapshot) (Self(Mutex::new(snapshot.clone())), snapshot)
} }
#[cfg(test)]
pub fn set_max_expansion_column(&self, column: u32) -> TabSnapshot {
self.0.lock().max_expansion_column = column;
self.0.lock().clone()
}
pub fn sync( pub fn sync(
&self, &self,
suggestion_snapshot: SuggestionSnapshot, suggestion_snapshot: SuggestionSnapshot,
@ -30,6 +40,7 @@ impl TabMap {
let mut new_snapshot = TabSnapshot { let mut new_snapshot = TabSnapshot {
suggestion_snapshot, suggestion_snapshot,
tab_size, tab_size,
max_expansion_column: old_snapshot.max_expansion_column,
version: old_snapshot.version, version: old_snapshot.version,
}; };
@ -41,27 +52,66 @@ impl TabMap {
let mut tab_edits = Vec::with_capacity(suggestion_edits.len()); let mut tab_edits = Vec::with_capacity(suggestion_edits.len());
if old_snapshot.tab_size == new_snapshot.tab_size { if old_snapshot.tab_size == new_snapshot.tab_size {
// Expand each edit to include the next tab on the same line as the edit,
// and any subsequent tabs on that line that moved across the tab expansion
// boundary.
for suggestion_edit in &mut suggestion_edits { for suggestion_edit in &mut suggestion_edits {
let mut delta = 0; let old_end_column = old_snapshot
for chunk in old_snapshot.suggestion_snapshot.chunks( .suggestion_snapshot
.to_point(suggestion_edit.old.end)
.column();
let new_end_column = new_snapshot
.suggestion_snapshot
.to_point(suggestion_edit.new.end)
.column();
let mut offset_from_edit = 0;
let mut first_tab_offset = None;
let mut last_tab_with_changed_expansion_offset = None;
'outer: for chunk in old_snapshot.suggestion_snapshot.chunks(
suggestion_edit.old.end..old_max_offset, suggestion_edit.old.end..old_max_offset,
false, false,
None, None,
None,
) { ) {
let patterns: &[_] = &['\t', '\n']; for (ix, mat) in chunk.text.match_indices(&['\t', '\n']) {
if let Some(ix) = chunk.text.find(patterns) { let offset_from_edit = offset_from_edit + (ix as u32);
if &chunk.text[ix..ix + 1] == "\t" { match mat {
suggestion_edit.old.end.0 += delta + ix + 1; "\t" => {
suggestion_edit.new.end.0 += delta + ix + 1; if first_tab_offset.is_none() {
} first_tab_offset = Some(offset_from_edit);
}
break; let old_column = old_end_column + offset_from_edit;
let new_column = new_end_column + offset_from_edit;
let was_expanded = old_column < old_snapshot.max_expansion_column;
let is_expanded = new_column < new_snapshot.max_expansion_column;
if was_expanded != is_expanded {
last_tab_with_changed_expansion_offset = Some(offset_from_edit);
} else if !was_expanded && !is_expanded {
break 'outer;
}
}
"\n" => break 'outer,
_ => unreachable!(),
}
} }
delta += chunk.text.len(); offset_from_edit += chunk.text.len() as u32;
if old_end_column + offset_from_edit >= old_snapshot.max_expansion_column
&& new_end_column | offset_from_edit >= new_snapshot.max_expansion_column
{
break;
}
}
if let Some(offset) = last_tab_with_changed_expansion_offset.or(first_tab_offset) {
suggestion_edit.old.end.0 += offset as usize + 1;
suggestion_edit.new.end.0 += offset as usize + 1;
} }
} }
// Combine any edits that overlap due to the expansion.
let mut ix = 1; let mut ix = 1;
while ix < suggestion_edits.len() { while ix < suggestion_edits.len() {
let (prev_edits, next_edits) = suggestion_edits.split_at_mut(ix); let (prev_edits, next_edits) = suggestion_edits.split_at_mut(ix);
@ -111,6 +161,7 @@ impl TabMap {
pub struct TabSnapshot { pub struct TabSnapshot {
pub suggestion_snapshot: SuggestionSnapshot, pub suggestion_snapshot: SuggestionSnapshot,
pub tab_size: NonZeroU32, pub tab_size: NonZeroU32,
pub max_expansion_column: u32,
pub version: usize, pub version: usize,
} }
@ -122,14 +173,12 @@ impl TabSnapshot {
pub fn line_len(&self, row: u32) -> u32 { pub fn line_len(&self, row: u32) -> u32 {
let max_point = self.max_point(); let max_point = self.max_point();
if row < max_point.row() { if row < max_point.row() {
self.chunks( self.to_tab_point(SuggestionPoint::new(
TabPoint::new(row, 0)..TabPoint::new(row + 1, 0), row,
false, self.suggestion_snapshot.line_len(row),
None, ))
) .0
.map(|chunk| chunk.text.len() as u32) .column
.sum::<u32>()
- 1
} else { } else {
max_point.column() max_point.column()
} }
@ -153,7 +202,7 @@ impl TabSnapshot {
self.max_point() self.max_point()
}; };
for c in self for c in self
.chunks(range.start..line_end, false, None) .chunks(range.start..line_end, false, None, None)
.flat_map(|chunk| chunk.text.chars()) .flat_map(|chunk| chunk.text.chars())
{ {
if c == '\n' { if c == '\n' {
@ -167,7 +216,12 @@ impl TabSnapshot {
last_line_chars = first_line_chars; last_line_chars = first_line_chars;
} else { } else {
for _ in self for _ in self
.chunks(TabPoint::new(range.end.row(), 0)..range.end, false, None) .chunks(
TabPoint::new(range.end.row(), 0)..range.end,
false,
None,
None,
)
.flat_map(|chunk| chunk.text.chars()) .flat_map(|chunk| chunk.text.chars())
{ {
last_line_chars += 1; last_line_chars += 1;
@ -188,15 +242,17 @@ impl TabSnapshot {
range: Range<TabPoint>, range: Range<TabPoint>,
language_aware: bool, language_aware: bool,
text_highlights: Option<&'a TextHighlights>, text_highlights: Option<&'a TextHighlights>,
suggestion_highlight: Option<HighlightStyle>,
) -> TabChunks<'a> { ) -> TabChunks<'a> {
let (input_start, expanded_char_column, to_next_stop) = let (input_start, expanded_char_column, to_next_stop) =
self.to_suggestion_point(range.start, Bias::Left); self.to_suggestion_point(range.start, Bias::Left);
let input_column = input_start.column();
let input_start = self.suggestion_snapshot.to_offset(input_start); let input_start = self.suggestion_snapshot.to_offset(input_start);
let input_end = self let input_end = self
.suggestion_snapshot .suggestion_snapshot
.to_offset(self.to_suggestion_point(range.end, Bias::Right).0); .to_offset(self.to_suggestion_point(range.end, Bias::Right).0);
let to_next_stop = if range.start.0 + Point::new(0, to_next_stop as u32) > range.end.0 { let to_next_stop = if range.start.0 + Point::new(0, to_next_stop) > range.end.0 {
(range.end.column() - range.start.column()) as usize range.end.column() - range.start.column()
} else { } else {
to_next_stop to_next_stop
}; };
@ -206,16 +262,19 @@ impl TabSnapshot {
input_start..input_end, input_start..input_end,
language_aware, language_aware,
text_highlights, text_highlights,
suggestion_highlight,
), ),
input_column,
column: expanded_char_column, column: expanded_char_column,
max_expansion_column: self.max_expansion_column,
output_position: range.start.0, output_position: range.start.0,
max_output_position: range.end.0, max_output_position: range.end.0,
tab_size: self.tab_size, tab_size: self.tab_size,
chunk: Chunk { chunk: Chunk {
text: &SPACES[0..to_next_stop], text: &SPACES[0..(to_next_stop as usize)],
..Default::default() ..Default::default()
}, },
skip_leading_tab: to_next_stop > 0, inside_leading_tab: to_next_stop > 0,
} }
} }
@ -225,7 +284,7 @@ impl TabSnapshot {
#[cfg(test)] #[cfg(test)]
pub fn text(&self) -> String { pub fn text(&self) -> String {
self.chunks(TabPoint::zero()..self.max_point(), false, None) self.chunks(TabPoint::zero()..self.max_point(), false, None, None)
.map(|chunk| chunk.text) .map(|chunk| chunk.text)
.collect() .collect()
} }
@ -245,21 +304,17 @@ impl TabSnapshot {
let chars = self let chars = self
.suggestion_snapshot .suggestion_snapshot
.chars_at(SuggestionPoint::new(input.row(), 0)); .chars_at(SuggestionPoint::new(input.row(), 0));
let expanded = Self::expand_tabs(chars, input.column() as usize, self.tab_size); let expanded = self.expand_tabs(chars, input.column());
TabPoint::new(input.row(), expanded as u32) TabPoint::new(input.row(), expanded)
} }
pub fn to_suggestion_point( pub fn to_suggestion_point(&self, output: TabPoint, bias: Bias) -> (SuggestionPoint, u32, u32) {
&self,
output: TabPoint,
bias: Bias,
) -> (SuggestionPoint, usize, usize) {
let chars = self let chars = self
.suggestion_snapshot .suggestion_snapshot
.chars_at(SuggestionPoint::new(output.row(), 0)); .chars_at(SuggestionPoint::new(output.row(), 0));
let expanded = output.column() as usize; let expanded = output.column();
let (collapsed, expanded_char_column, to_next_stop) = let (collapsed, expanded_char_column, to_next_stop) =
Self::collapse_tabs(chars, expanded, bias, self.tab_size); self.collapse_tabs(chars, expanded, bias);
( (
SuggestionPoint::new(output.row(), collapsed as u32), SuggestionPoint::new(output.row(), collapsed as u32),
expanded_char_column, expanded_char_column,
@ -282,38 +337,38 @@ impl TabSnapshot {
fold_point.to_buffer_point(&self.suggestion_snapshot.fold_snapshot) fold_point.to_buffer_point(&self.suggestion_snapshot.fold_snapshot)
} }
pub fn expand_tabs( fn expand_tabs(&self, chars: impl Iterator<Item = char>, column: u32) -> u32 {
chars: impl Iterator<Item = char>, let tab_size = self.tab_size.get();
column: usize,
tab_size: NonZeroU32,
) -> usize {
let mut expanded_chars = 0; let mut expanded_chars = 0;
let mut expanded_bytes = 0; let mut expanded_bytes = 0;
let mut collapsed_bytes = 0; let mut collapsed_bytes = 0;
let end_column = column.min(self.max_expansion_column);
for c in chars { for c in chars {
if collapsed_bytes == column { if collapsed_bytes >= end_column {
break; break;
} }
if c == '\t' { if c == '\t' {
let tab_size = tab_size.get() as usize;
let tab_len = tab_size - expanded_chars % tab_size; let tab_len = tab_size - expanded_chars % tab_size;
expanded_bytes += tab_len; expanded_bytes += tab_len;
expanded_chars += tab_len; expanded_chars += tab_len;
} else { } else {
expanded_bytes += c.len_utf8(); expanded_bytes += c.len_utf8() as u32;
expanded_chars += 1; expanded_chars += 1;
} }
collapsed_bytes += c.len_utf8(); collapsed_bytes += c.len_utf8() as u32;
} }
expanded_bytes expanded_bytes + column.saturating_sub(collapsed_bytes)
} }
fn collapse_tabs( fn collapse_tabs(
&self,
chars: impl Iterator<Item = char>, chars: impl Iterator<Item = char>,
column: usize, column: u32,
bias: Bias, bias: Bias,
tab_size: NonZeroU32, ) -> (u32, u32, u32) {
) -> (usize, usize, usize) { let tab_size = self.tab_size.get();
let mut expanded_bytes = 0; let mut expanded_bytes = 0;
let mut expanded_chars = 0; let mut expanded_chars = 0;
let mut collapsed_bytes = 0; let mut collapsed_bytes = 0;
@ -321,9 +376,11 @@ impl TabSnapshot {
if expanded_bytes >= column { if expanded_bytes >= column {
break; break;
} }
if collapsed_bytes >= self.max_expansion_column {
break;
}
if c == '\t' { if c == '\t' {
let tab_size = tab_size.get() as usize;
let tab_len = tab_size - (expanded_chars % tab_size); let tab_len = tab_size - (expanded_chars % tab_size);
expanded_chars += tab_len; expanded_chars += tab_len;
expanded_bytes += tab_len; expanded_bytes += tab_len;
@ -336,7 +393,7 @@ impl TabSnapshot {
} }
} else { } else {
expanded_chars += 1; expanded_chars += 1;
expanded_bytes += c.len_utf8(); expanded_bytes += c.len_utf8() as u32;
} }
if expanded_bytes > column && matches!(bias, Bias::Left) { if expanded_bytes > column && matches!(bias, Bias::Left) {
@ -344,9 +401,13 @@ impl TabSnapshot {
break; break;
} }
collapsed_bytes += c.len_utf8(); collapsed_bytes += c.len_utf8() as u32;
} }
(collapsed_bytes, expanded_chars, 0) (
collapsed_bytes + column.saturating_sub(expanded_bytes),
expanded_chars,
0,
)
} }
} }
@ -434,11 +495,13 @@ const SPACES: &str = " ";
pub struct TabChunks<'a> { pub struct TabChunks<'a> {
suggestion_chunks: SuggestionChunks<'a>, suggestion_chunks: SuggestionChunks<'a>,
chunk: Chunk<'a>, chunk: Chunk<'a>,
column: usize, column: u32,
max_expansion_column: u32,
output_position: Point, output_position: Point,
input_column: u32,
max_output_position: Point, max_output_position: Point,
tab_size: NonZeroU32, tab_size: NonZeroU32,
skip_leading_tab: bool, inside_leading_tab: bool,
} }
impl<'a> Iterator for TabChunks<'a> { impl<'a> Iterator for TabChunks<'a> {
@ -448,9 +511,10 @@ impl<'a> Iterator for TabChunks<'a> {
if self.chunk.text.is_empty() { if self.chunk.text.is_empty() {
if let Some(chunk) = self.suggestion_chunks.next() { if let Some(chunk) = self.suggestion_chunks.next() {
self.chunk = chunk; self.chunk = chunk;
if self.skip_leading_tab { if self.inside_leading_tab {
self.chunk.text = &self.chunk.text[1..]; self.chunk.text = &self.chunk.text[1..];
self.skip_leading_tab = false; self.inside_leading_tab = false;
self.input_column += 1;
} }
} else { } else {
return None; return None;
@ -469,27 +533,36 @@ impl<'a> Iterator for TabChunks<'a> {
}); });
} else { } else {
self.chunk.text = &self.chunk.text[1..]; self.chunk.text = &self.chunk.text[1..];
let tab_size = self.tab_size.get() as u32; let tab_size = if self.input_column < self.max_expansion_column {
let mut len = tab_size - self.column as u32 % tab_size; self.tab_size.get() as u32
} else {
1
};
let mut len = tab_size - self.column % tab_size;
let next_output_position = cmp::min( let next_output_position = cmp::min(
self.output_position + Point::new(0, len), self.output_position + Point::new(0, len),
self.max_output_position, self.max_output_position,
); );
len = next_output_position.column - self.output_position.column; len = next_output_position.column - self.output_position.column;
self.column += len as usize; self.column += len;
self.input_column += 1;
self.output_position = next_output_position; self.output_position = next_output_position;
return Some(Chunk { return Some(Chunk {
text: &SPACES[0..len as usize], text: &SPACES[..len as usize],
..self.chunk ..self.chunk
}); });
} }
} }
'\n' => { '\n' => {
self.column = 0; self.column = 0;
self.input_column = 0;
self.output_position += Point::new(1, 0); self.output_position += Point::new(1, 0);
} }
_ => { _ => {
self.column += 1; self.column += 1;
if !self.inside_leading_tab {
self.input_column += c.len_utf8() as u32;
}
self.output_position.column += c.len_utf8() as u32; self.output_position.column += c.len_utf8() as u32;
} }
} }
@ -508,20 +581,83 @@ mod tests {
}; };
use rand::{prelude::StdRng, Rng}; use rand::{prelude::StdRng, Rng};
#[test] #[gpui::test]
fn test_expand_tabs() { fn test_expand_tabs(cx: &mut gpui::MutableAppContext) {
assert_eq!( let buffer = MultiBuffer::build_simple("", cx);
TabSnapshot::expand_tabs("\t".chars(), 0, 4.try_into().unwrap()), let buffer_snapshot = buffer.read(cx).snapshot(cx);
0 let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
); let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
assert_eq!( let (_, tab_snapshot) = TabMap::new(suggestion_snapshot, 4.try_into().unwrap());
TabSnapshot::expand_tabs("\t".chars(), 1, 4.try_into().unwrap()),
4 assert_eq!(tab_snapshot.expand_tabs("\t".chars(), 0), 0);
); assert_eq!(tab_snapshot.expand_tabs("\t".chars(), 1), 4);
assert_eq!( assert_eq!(tab_snapshot.expand_tabs("\ta".chars(), 2), 5);
TabSnapshot::expand_tabs("\ta".chars(), 2, 4.try_into().unwrap()), }
5
); #[gpui::test]
fn test_long_lines(cx: &mut gpui::MutableAppContext) {
let max_expansion_column = 12;
let input = "A\tBC\tDEF\tG\tHI\tJ\tK\tL\tM";
let output = "A BC DEF G HI J K L M";
let buffer = MultiBuffer::build_simple(input, cx);
let buffer_snapshot = buffer.read(cx).snapshot(cx);
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
let (_, mut tab_snapshot) = TabMap::new(suggestion_snapshot, 4.try_into().unwrap());
tab_snapshot.max_expansion_column = max_expansion_column;
assert_eq!(tab_snapshot.text(), output);
for (ix, c) in input.char_indices() {
assert_eq!(
tab_snapshot
.chunks(
TabPoint::new(0, ix as u32)..tab_snapshot.max_point(),
false,
None,
None,
)
.map(|c| c.text)
.collect::<String>(),
&output[ix..],
"text from index {ix}"
);
if c != '\t' {
let input_point = Point::new(0, ix as u32);
let output_point = Point::new(0, output.find(c).unwrap() as u32);
assert_eq!(
tab_snapshot.to_tab_point(SuggestionPoint(input_point)),
TabPoint(output_point),
"to_tab_point({input_point:?})"
);
assert_eq!(
tab_snapshot
.to_suggestion_point(TabPoint(output_point), Bias::Left)
.0,
SuggestionPoint(input_point),
"to_suggestion_point({output_point:?})"
);
}
}
}
#[gpui::test]
fn test_long_lines_with_character_spanning_max_expansion_column(
cx: &mut gpui::MutableAppContext,
) {
let max_expansion_column = 8;
let input = "abcdefg⋯hij";
let buffer = MultiBuffer::build_simple(input, cx);
let buffer_snapshot = buffer.read(cx).snapshot(cx);
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
let (_, mut tab_snapshot) = TabMap::new(suggestion_snapshot, 4.try_into().unwrap());
tab_snapshot.max_expansion_column = max_expansion_column;
assert_eq!(tab_snapshot.text(), input);
} }
#[gpui::test(iterations = 100)] #[gpui::test(iterations = 100)]
@ -547,7 +683,9 @@ mod tests {
let (suggestion_snapshot, _) = suggestion_map.randomly_mutate(&mut rng); let (suggestion_snapshot, _) = suggestion_map.randomly_mutate(&mut rng);
log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text()); log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
let (_, tabs_snapshot) = TabMap::new(suggestion_snapshot.clone(), tab_size); let (tab_map, _) = TabMap::new(suggestion_snapshot.clone(), tab_size);
let tabs_snapshot = tab_map.set_max_expansion_column(32);
let text = text::Rope::from(tabs_snapshot.text().as_str()); let text = text::Rope::from(tabs_snapshot.text().as_str());
log::info!( log::info!(
"TabMap text (tab size: {}): {:?}", "TabMap text (tab size: {}): {:?}",
@ -572,11 +710,11 @@ mod tests {
.collect::<String>(); .collect::<String>();
let expected_summary = TextSummary::from(expected_text.as_str()); let expected_summary = TextSummary::from(expected_text.as_str());
assert_eq!( assert_eq!(
expected_text,
tabs_snapshot tabs_snapshot
.chunks(start..end, false, None) .chunks(start..end, false, None, None)
.map(|c| c.text) .map(|c| c.text)
.collect::<String>(), .collect::<String>(),
expected_text,
"chunks({:?}..{:?})", "chunks({:?}..{:?})",
start, start,
end end
@ -591,7 +729,11 @@ mod tests {
} }
for row in 0..=text.max_point().row { for row in 0..=text.max_point().row {
assert_eq!(tabs_snapshot.line_len(row), text.line_len(row)); assert_eq!(
tabs_snapshot.line_len(row),
text.line_len(row),
"line_len({row})"
);
} }
} }
} }

View file

@ -5,8 +5,9 @@ use super::{
}; };
use crate::MultiBufferSnapshot; use crate::MultiBufferSnapshot;
use gpui::{ use gpui::{
fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, ModelHandle, MutableAppContext, fonts::{FontId, HighlightStyle},
Task, text_layout::LineWrapper,
Entity, ModelContext, ModelHandle, MutableAppContext, Task,
}; };
use language::{Chunk, Point}; use language::{Chunk, Point};
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -444,6 +445,7 @@ impl WrapSnapshot {
TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point(), TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point(),
false, false,
None, None,
None,
); );
let mut edit_transforms = Vec::<Transform>::new(); let mut edit_transforms = Vec::<Transform>::new();
for _ in edit.new_rows.start..edit.new_rows.end { for _ in edit.new_rows.start..edit.new_rows.end {
@ -573,6 +575,7 @@ impl WrapSnapshot {
rows: Range<u32>, rows: Range<u32>,
language_aware: bool, language_aware: bool,
text_highlights: Option<&'a TextHighlights>, text_highlights: Option<&'a TextHighlights>,
suggestion_highlight: Option<HighlightStyle>,
) -> WrapChunks<'a> { ) -> WrapChunks<'a> {
let output_start = WrapPoint::new(rows.start, 0); let output_start = WrapPoint::new(rows.start, 0);
let output_end = WrapPoint::new(rows.end, 0); let output_end = WrapPoint::new(rows.end, 0);
@ -590,6 +593,7 @@ impl WrapSnapshot {
input_start..input_end, input_start..input_end,
language_aware, language_aware,
text_highlights, text_highlights,
suggestion_highlight,
), ),
input_chunk: Default::default(), input_chunk: Default::default(),
output_position: output_start, output_position: output_start,
@ -1089,7 +1093,8 @@ mod tests {
log::info!("FoldMap text: {:?}", fold_snapshot.text()); log::info!("FoldMap text: {:?}", fold_snapshot.text());
let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot.clone()); let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot.clone());
log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text()); log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
let (tab_map, tabs_snapshot) = TabMap::new(suggestion_snapshot.clone(), tab_size); let (tab_map, _) = TabMap::new(suggestion_snapshot.clone(), tab_size);
let tabs_snapshot = tab_map.set_max_expansion_column(32);
log::info!("TabMap text: {:?}", tabs_snapshot.text()); log::info!("TabMap text: {:?}", tabs_snapshot.text());
let mut line_wrapper = LineWrapper::new(font_id, font_size, font_system); let mut line_wrapper = LineWrapper::new(font_id, font_size, font_system);
@ -1315,7 +1320,7 @@ mod tests {
} }
pub fn text_chunks(&self, wrap_row: u32) -> impl Iterator<Item = &str> { pub fn text_chunks(&self, wrap_row: u32) -> impl Iterator<Item = &str> {
self.chunks(wrap_row..self.max_point().row() + 1, false, None) self.chunks(wrap_row..self.max_point().row() + 1, false, None, None)
.map(|h| h.text) .map(|h| h.text)
} }
@ -1339,7 +1344,7 @@ mod tests {
} }
let actual_text = self let actual_text = self
.chunks(start_row..end_row, true, None) .chunks(start_row..end_row, true, None, None)
.map(|c| c.text) .map(|c| c.text)
.collect::<String>(); .collect::<String>();
assert_eq!( assert_eq!(

View file

@ -24,6 +24,7 @@ use anyhow::Result;
use blink_manager::BlinkManager; use blink_manager::BlinkManager;
use clock::ReplicaId; use clock::ReplicaId;
use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque}; use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
use copilot::Copilot;
pub use display_map::DisplayPoint; pub use display_map::DisplayPoint;
use display_map::*; use display_map::*;
pub use element::*; pub use element::*;
@ -52,7 +53,7 @@ pub use language::{char_kind, CharKind};
use language::{ use language::{
AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, CursorShape, AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, CursorShape,
Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16,
Point, Selection, SelectionGoal, TransactionId, Point, Rope, Selection, SelectionGoal, TransactionId,
}; };
use link_go_to_definition::{ use link_go_to_definition::{
hide_link_definition, show_link_definition, LinkDefinitionKind, LinkGoToDefinitionState, hide_link_definition, show_link_definition, LinkDefinitionKind, LinkGoToDefinitionState,
@ -94,6 +95,7 @@ const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
const MAX_LINE_LEN: usize = 1024; const MAX_LINE_LEN: usize = 1024;
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10; const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
const MAX_SELECTION_HISTORY_LEN: usize = 1024; const MAX_SELECTION_HISTORY_LEN: usize = 1024;
const COPILOT_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
pub const FORMAT_TIMEOUT: Duration = Duration::from_secs(2); pub const FORMAT_TIMEOUT: Duration = Duration::from_secs(2);
@ -388,6 +390,8 @@ pub fn init(cx: &mut MutableAppContext) {
cx.add_async_action(Editor::rename); cx.add_async_action(Editor::rename);
cx.add_async_action(Editor::confirm_rename); cx.add_async_action(Editor::confirm_rename);
cx.add_async_action(Editor::find_all_references); cx.add_async_action(Editor::find_all_references);
cx.add_action(Editor::next_copilot_suggestion);
cx.add_action(Editor::previous_copilot_suggestion);
hover_popover::init(cx); hover_popover::init(cx);
link_go_to_definition::init(cx); link_go_to_definition::init(cx);
@ -506,6 +510,7 @@ pub struct Editor {
hover_state: HoverState, hover_state: HoverState,
gutter_hovered: bool, gutter_hovered: bool,
link_go_to_definition_state: LinkGoToDefinitionState, link_go_to_definition_state: LinkGoToDefinitionState,
copilot_state: CopilotState,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@ -1003,6 +1008,74 @@ impl CodeActionsMenu {
} }
} }
pub struct CopilotState {
excerpt_id: Option<ExcerptId>,
pending_refresh: Task<Option<()>>,
completions: Vec<copilot::Completion>,
active_completion_index: usize,
}
impl Default for CopilotState {
fn default() -> Self {
Self {
excerpt_id: None,
pending_refresh: Task::ready(Some(())),
completions: Default::default(),
active_completion_index: 0,
}
}
}
impl CopilotState {
fn text_for_active_completion(
&self,
cursor: Anchor,
buffer: &MultiBufferSnapshot,
) -> Option<&str> {
use language::ToOffset as _;
let completion = self.completions.get(self.active_completion_index)?;
let excerpt_id = self.excerpt_id?;
let completion_buffer = buffer.buffer_for_excerpt(excerpt_id)?;
let mut completion_range = completion.range.to_offset(&completion_buffer);
let prefix_len = Self::common_prefix(
completion_buffer.chars_for_range(completion_range.clone()),
completion.text.chars(),
);
completion_range.start += prefix_len;
let suffix_len = Self::common_prefix(
completion_buffer.reversed_chars_for_range(completion_range.clone()),
completion.text[prefix_len..].chars().rev(),
);
completion_range.end = completion_range.end.saturating_sub(suffix_len);
if completion_range.is_empty()
&& completion_range.start == cursor.text_anchor.to_offset(&completion_buffer)
{
Some(&completion.text[prefix_len..completion.text.len() - suffix_len])
} else {
None
}
}
fn push_completion(&mut self, new_completion: copilot::Completion) {
for completion in &self.completions {
if *completion == new_completion {
return;
}
}
self.completions.push(new_completion);
}
fn common_prefix<T1: Iterator<Item = char>, T2: Iterator<Item = char>>(a: T1, b: T2) -> usize {
a.zip(b)
.take_while(|(a, b)| a == b)
.map(|(a, _)| a.len_utf8())
.sum()
}
}
#[derive(Debug)] #[derive(Debug)]
struct ActiveDiagnosticGroup { struct ActiveDiagnosticGroup {
primary_range: Range<Anchor>, primary_range: Range<Anchor>,
@ -1176,12 +1249,14 @@ impl Editor {
remote_id: None, remote_id: None,
hover_state: Default::default(), hover_state: Default::default(),
link_go_to_definition_state: Default::default(), link_go_to_definition_state: Default::default(),
copilot_state: Default::default(),
gutter_hovered: false, gutter_hovered: false,
_subscriptions: vec![ _subscriptions: vec![
cx.observe(&buffer, Self::on_buffer_changed), cx.observe(&buffer, Self::on_buffer_changed),
cx.subscribe(&buffer, Self::on_buffer_event), cx.subscribe(&buffer, Self::on_buffer_event),
cx.observe(&display_map, Self::on_display_map_changed), cx.observe(&display_map, Self::on_display_map_changed),
cx.observe(&blink_manager, |_, _, cx| cx.notify()), cx.observe(&blink_manager, |_, _, cx| cx.notify()),
cx.observe_global::<Settings, _>(Self::on_settings_changed),
], ],
}; };
this.end_selection(cx); this.end_selection(cx);
@ -1385,6 +1460,7 @@ impl Editor {
self.refresh_code_actions(cx); self.refresh_code_actions(cx);
self.refresh_document_highlights(cx); self.refresh_document_highlights(cx);
refresh_matching_bracket_highlights(self, cx); refresh_matching_bracket_highlights(self, cx);
self.hide_copilot_suggestion(cx);
} }
self.blink_manager.update(cx, BlinkManager::pause_blinking); self.blink_manager.update(cx, BlinkManager::pause_blinking);
@ -1758,6 +1834,10 @@ impl Editor {
return; return;
} }
if self.hide_copilot_suggestion(cx).is_some() {
return;
}
if self.snippet_stack.pop().is_some() { if self.snippet_stack.pop().is_some() {
return; return;
} }
@ -1933,8 +2013,18 @@ impl Editor {
} }
drop(snapshot); drop(snapshot);
let had_active_copilot_suggestion = this.has_active_copilot_suggestion(cx);
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections)); this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections));
this.trigger_completion_on_input(&text, cx);
if had_active_copilot_suggestion {
this.refresh_copilot_suggestions(cx);
if !this.has_active_copilot_suggestion(cx) {
this.trigger_completion_on_input(&text, cx);
}
} else {
this.trigger_completion_on_input(&text, cx);
this.refresh_copilot_suggestions(cx);
}
}); });
} }
@ -2015,6 +2105,7 @@ impl Editor {
.collect(); .collect();
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections)); this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections));
this.refresh_copilot_suggestions(cx);
}); });
} }
@ -2061,6 +2152,21 @@ impl Editor {
} }
pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) { pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
self.insert_with_autoindent_mode(
text,
Some(AutoindentMode::Block {
original_indent_columns: Vec::new(),
}),
cx,
);
}
fn insert_with_autoindent_mode(
&mut self,
text: &str,
autoindent_mode: Option<AutoindentMode>,
cx: &mut ViewContext<Self>,
) {
let text: Arc<str> = text.into(); let text: Arc<str> = text.into();
self.transact(cx, |this, cx| { self.transact(cx, |this, cx| {
let old_selections = this.selections.all_adjusted(cx); let old_selections = this.selections.all_adjusted(cx);
@ -2079,9 +2185,7 @@ impl Editor {
old_selections old_selections
.iter() .iter()
.map(|s| (s.start..s.end, text.clone())), .map(|s| (s.start..s.end, text.clone())),
Some(AutoindentMode::Block { autoindent_mode,
original_indent_columns: Vec::new(),
}),
cx, cx,
); );
anchors anchors
@ -2279,11 +2383,11 @@ impl Editor {
} }
this.completion_tasks.retain(|(id, _)| *id > menu.id); this.completion_tasks.retain(|(id, _)| *id > menu.id);
if this.focused { if this.focused && !menu.matches.is_empty() {
this.show_context_menu(ContextMenu::Completions(menu), cx); this.show_context_menu(ContextMenu::Completions(menu), cx);
} else if this.hide_context_menu(cx).is_none() {
this.update_visible_copilot_suggestion(cx);
} }
cx.notify();
}); });
} }
Ok::<_, anyhow::Error>(()) Ok::<_, anyhow::Error>(())
@ -2385,6 +2489,8 @@ impl Editor {
); );
}); });
} }
this.refresh_copilot_suggestions(cx);
}); });
let project = self.project.clone()?; let project = self.project.clone()?;
@ -2677,6 +2783,139 @@ impl Editor {
None None
} }
fn refresh_copilot_suggestions(&mut self, cx: &mut ViewContext<Self>) -> Option<()> {
let copilot = Copilot::global(cx)?;
if self.mode != EditorMode::Full || !copilot.read(cx).status().is_authorized() {
self.hide_copilot_suggestion(cx);
return None;
}
self.update_visible_copilot_suggestion(cx);
let snapshot = self.buffer.read(cx).snapshot(cx);
let cursor = self.selections.newest_anchor().head();
let language_name = snapshot.language_at(cursor).map(|language| language.name());
if !cx.global::<Settings>().copilot_on(language_name.as_deref()) {
self.hide_copilot_suggestion(cx);
return None;
}
let (buffer, buffer_position) =
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
self.copilot_state.pending_refresh = cx.spawn_weak(|this, mut cx| async move {
cx.background().timer(COPILOT_DEBOUNCE_TIMEOUT).await;
let (completion, completions_cycling) = copilot.update(&mut cx, |copilot, cx| {
(
copilot.completions(&buffer, buffer_position, cx),
copilot.completions_cycling(&buffer, buffer_position, cx),
)
});
let (completion, completions_cycling) = futures::join!(completion, completions_cycling);
let mut completions = Vec::new();
completions.extend(completion.log_err().into_iter().flatten());
completions.extend(completions_cycling.log_err().into_iter().flatten());
this.upgrade(&cx)?.update(&mut cx, |this, cx| {
if !completions.is_empty() {
this.copilot_state.completions.clear();
this.copilot_state.active_completion_index = 0;
this.copilot_state.excerpt_id = Some(cursor.excerpt_id);
for completion in completions {
this.copilot_state.push_completion(completion);
}
this.update_visible_copilot_suggestion(cx);
}
});
Some(())
});
Some(())
}
fn next_copilot_suggestion(&mut self, _: &copilot::NextSuggestion, cx: &mut ViewContext<Self>) {
if !self.has_active_copilot_suggestion(cx) {
self.refresh_copilot_suggestions(cx);
return;
}
self.copilot_state.active_completion_index =
(self.copilot_state.active_completion_index + 1) % self.copilot_state.completions.len();
self.update_visible_copilot_suggestion(cx);
}
fn previous_copilot_suggestion(
&mut self,
_: &copilot::PreviousSuggestion,
cx: &mut ViewContext<Self>,
) {
if !self.has_active_copilot_suggestion(cx) {
self.refresh_copilot_suggestions(cx);
return;
}
self.copilot_state.active_completion_index =
if self.copilot_state.active_completion_index == 0 {
self.copilot_state.completions.len() - 1
} else {
self.copilot_state.active_completion_index - 1
};
self.update_visible_copilot_suggestion(cx);
}
fn accept_copilot_suggestion(&mut self, cx: &mut ViewContext<Self>) -> bool {
if let Some(text) = self.hide_copilot_suggestion(cx) {
self.insert_with_autoindent_mode(&text.to_string(), None, cx);
true
} else {
false
}
}
fn has_active_copilot_suggestion(&self, cx: &AppContext) -> bool {
self.display_map.read(cx).has_suggestion()
}
fn hide_copilot_suggestion(&mut self, cx: &mut ViewContext<Self>) -> Option<Rope> {
if self.has_active_copilot_suggestion(cx) {
let old_suggestion = self
.display_map
.update(cx, |map, cx| map.replace_suggestion::<usize>(None, cx));
cx.notify();
old_suggestion.map(|suggestion| suggestion.text)
} else {
None
}
}
fn update_visible_copilot_suggestion(&mut self, cx: &mut ViewContext<Self>) {
let snapshot = self.buffer.read(cx).snapshot(cx);
let selection = self.selections.newest_anchor();
let cursor = selection.head();
if self.context_menu.is_some()
|| !self.completion_tasks.is_empty()
|| selection.start != selection.end
{
self.hide_copilot_suggestion(cx);
} else if let Some(text) = self
.copilot_state
.text_for_active_completion(cursor, &snapshot)
{
self.display_map.update(cx, |map, cx| {
map.replace_suggestion(
Some(Suggestion {
position: cursor,
text: text.into(),
}),
cx,
)
});
cx.notify();
} else {
self.hide_copilot_suggestion(cx);
}
}
pub fn render_code_actions_indicator( pub fn render_code_actions_indicator(
&self, &self,
style: &EditorStyle, style: &EditorStyle,
@ -2792,13 +3031,18 @@ impl Editor {
self.completion_tasks.clear(); self.completion_tasks.clear();
} }
self.context_menu = Some(menu); self.context_menu = Some(menu);
self.hide_copilot_suggestion(cx);
cx.notify(); cx.notify();
} }
fn hide_context_menu(&mut self, cx: &mut ViewContext<Self>) -> Option<ContextMenu> { fn hide_context_menu(&mut self, cx: &mut ViewContext<Self>) -> Option<ContextMenu> {
cx.notify(); cx.notify();
self.completion_tasks.clear(); self.completion_tasks.clear();
self.context_menu.take() let context_menu = self.context_menu.take();
if context_menu.is_some() {
self.update_visible_copilot_suggestion(cx);
}
context_menu
} }
pub fn insert_snippet( pub fn insert_snippet(
@ -2957,6 +3201,7 @@ impl Editor {
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(selections)); this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(selections));
this.insert("", cx); this.insert("", cx);
this.refresh_copilot_suggestions(cx);
}); });
} }
@ -2972,6 +3217,7 @@ impl Editor {
}) })
}); });
this.insert("", cx); this.insert("", cx);
this.refresh_copilot_suggestions(cx);
}); });
} }
@ -3013,8 +3259,8 @@ impl Editor {
// If the selection is empty and the cursor is in the leading whitespace before the // If the selection is empty and the cursor is in the leading whitespace before the
// suggested indentation, then auto-indent the line. // suggested indentation, then auto-indent the line.
let cursor = selection.head(); let cursor = selection.head();
let current_indent = snapshot.indent_size_for_line(cursor.row);
if let Some(suggested_indent) = suggested_indents.get(&cursor.row).copied() { if let Some(suggested_indent) = suggested_indents.get(&cursor.row).copied() {
let current_indent = snapshot.indent_size_for_line(cursor.row);
if cursor.column < suggested_indent.len if cursor.column < suggested_indent.len
&& cursor.column <= current_indent.len && cursor.column <= current_indent.len
&& current_indent.len <= suggested_indent.len && current_indent.len <= suggested_indent.len
@ -3033,6 +3279,16 @@ impl Editor {
} }
} }
// Accept copilot suggestion if there is only one selection and the cursor is not
// in the leading whitespace.
if self.selections.count() == 1
&& cursor.column >= current_indent.len
&& self.has_active_copilot_suggestion(cx)
{
self.accept_copilot_suggestion(cx);
return;
}
// Otherwise, insert a hard or soft tab. // Otherwise, insert a hard or soft tab.
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let language_name = buffer.language_at(cursor, cx).map(|l| l.name()); let language_name = buffer.language_at(cursor, cx).map(|l| l.name());
@ -3056,7 +3312,8 @@ impl Editor {
self.transact(cx, |this, cx| { self.transact(cx, |this, cx| {
this.buffer.update(cx, |b, cx| b.edit(edits, None, cx)); this.buffer.update(cx, |b, cx| b.edit(edits, None, cx));
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(selections)) this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(selections));
this.refresh_copilot_suggestions(cx);
}); });
} }
@ -3736,6 +3993,7 @@ impl Editor {
} }
self.request_autoscroll(Autoscroll::fit(), cx); self.request_autoscroll(Autoscroll::fit(), cx);
self.unmark_text(cx); self.unmark_text(cx);
self.refresh_copilot_suggestions(cx);
cx.emit(Event::Edited); cx.emit(Event::Edited);
} }
} }
@ -3750,6 +4008,7 @@ impl Editor {
} }
self.request_autoscroll(Autoscroll::fit(), cx); self.request_autoscroll(Autoscroll::fit(), cx);
self.unmark_text(cx); self.unmark_text(cx);
self.refresh_copilot_suggestions(cx);
cx.emit(Event::Edited); cx.emit(Event::Edited);
} }
} }
@ -6157,6 +6416,9 @@ impl Editor {
multi_buffer::Event::Edited => { multi_buffer::Event::Edited => {
self.refresh_active_diagnostics(cx); self.refresh_active_diagnostics(cx);
self.refresh_code_actions(cx); self.refresh_code_actions(cx);
if self.has_active_copilot_suggestion(cx) {
self.update_visible_copilot_suggestion(cx);
}
cx.emit(Event::BufferEdited); cx.emit(Event::BufferEdited);
} }
multi_buffer::Event::ExcerptsAdded { multi_buffer::Event::ExcerptsAdded {
@ -6187,6 +6449,10 @@ impl Editor {
cx.notify(); cx.notify();
} }
fn on_settings_changed(&mut self, cx: &mut ViewContext<Self>) {
self.refresh_copilot_suggestions(cx);
}
pub fn set_searchable(&mut self, searchable: bool) { pub fn set_searchable(&mut self, searchable: bool) {
self.searchable = searchable; self.searchable = searchable;
} }

View file

@ -16,7 +16,7 @@ use language::{BracketPairConfig, FakeLspAdapter, LanguageConfig, LanguageRegist
use parking_lot::Mutex; use parking_lot::Mutex;
use project::FakeFs; use project::FakeFs;
use settings::EditorSettings; use settings::EditorSettings;
use std::{cell::RefCell, rc::Rc, time::Instant}; use std::{cell::RefCell, future::Future, rc::Rc, time::Instant};
use unindent::Unindent; use unindent::Unindent;
use util::{ use util::{
assert_set_eq, assert_set_eq,
@ -630,7 +630,7 @@ fn test_cancel(cx: &mut gpui::MutableAppContext) {
} }
#[gpui::test] #[gpui::test]
fn test_fold(cx: &mut gpui::MutableAppContext) { fn test_fold_action(cx: &mut gpui::MutableAppContext) {
cx.set_global(Settings::test(cx)); cx.set_global(Settings::test(cx));
let buffer = MultiBuffer::build_simple( let buffer = MultiBuffer::build_simple(
&" &"
@ -4585,81 +4585,6 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
cx.assert_editor_state("editor.closeˇ"); cx.assert_editor_state("editor.closeˇ");
handle_resolve_completion_request(&mut cx, None).await; handle_resolve_completion_request(&mut cx, None).await;
apply_additional_edits.await.unwrap(); apply_additional_edits.await.unwrap();
// Handle completion request passing a marked string specifying where the completion
// should be triggered from using '|' character, what range should be replaced, and what completions
// should be returned using '<' and '>' to delimit the range
async fn handle_completion_request<'a>(
cx: &mut EditorLspTestContext<'a>,
marked_string: &str,
completions: Vec<&'static str>,
) {
let complete_from_marker: TextRangeMarker = '|'.into();
let replace_range_marker: TextRangeMarker = ('<', '>').into();
let (_, mut marked_ranges) = marked_text_ranges_by(
marked_string,
vec![complete_from_marker.clone(), replace_range_marker.clone()],
);
let complete_from_position =
cx.to_lsp(marked_ranges.remove(&complete_from_marker).unwrap()[0].start);
let replace_range =
cx.to_lsp_range(marked_ranges.remove(&replace_range_marker).unwrap()[0].clone());
cx.handle_request::<lsp::request::Completion, _, _>(move |url, params, _| {
let completions = completions.clone();
async move {
assert_eq!(params.text_document_position.text_document.uri, url.clone());
assert_eq!(
params.text_document_position.position,
complete_from_position
);
Ok(Some(lsp::CompletionResponse::Array(
completions
.iter()
.map(|completion_text| lsp::CompletionItem {
label: completion_text.to_string(),
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range: replace_range,
new_text: completion_text.to_string(),
})),
..Default::default()
})
.collect(),
)))
}
})
.next()
.await;
}
async fn handle_resolve_completion_request<'a>(
cx: &mut EditorLspTestContext<'a>,
edits: Option<Vec<(&'static str, &'static str)>>,
) {
let edits = edits.map(|edits| {
edits
.iter()
.map(|(marked_string, new_text)| {
let (_, marked_ranges) = marked_text_ranges(marked_string, false);
let replace_range = cx.to_lsp_range(marked_ranges[0].clone());
lsp::TextEdit::new(replace_range, new_text.to_string())
})
.collect::<Vec<_>>()
});
cx.handle_request::<lsp::request::ResolveCompletionItem, _, _>(move |_, _, _| {
let edits = edits.clone();
async move {
Ok(lsp::CompletionItem {
additional_text_edits: edits,
..Default::default()
})
}
})
.next()
.await;
}
} }
#[gpui::test] #[gpui::test]
@ -5956,6 +5881,223 @@ async fn test_move_to_enclosing_bracket(cx: &mut gpui::TestAppContext) {
); );
} }
#[gpui::test(iterations = 10)]
async fn test_copilot(deterministic: Arc<Deterministic>, cx: &mut gpui::TestAppContext) {
let (copilot, copilot_lsp) = Copilot::fake(cx);
cx.update(|cx| cx.set_global(copilot));
let mut cx = EditorLspTestContext::new_rust(
lsp::ServerCapabilities {
completion_provider: Some(lsp::CompletionOptions {
trigger_characters: Some(vec![".".to_string(), ":".to_string()]),
..Default::default()
}),
..Default::default()
},
cx,
)
.await;
cx.set_state(indoc! {"
oneˇ
two
three
"});
// When inserting, ensure autocompletion is favored over Copilot suggestions.
cx.simulate_keystroke(".");
let _ = handle_completion_request(
&mut cx,
indoc! {"
one.|<>
two
three
"},
vec!["completion_a", "completion_b"],
);
handle_copilot_completion_request(
&copilot_lsp,
vec![copilot::request::Completion {
text: "copilot1".into(),
range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 5)),
..Default::default()
}],
vec![],
);
deterministic.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
cx.update_editor(|editor, cx| {
assert!(editor.context_menu_visible());
assert!(!editor.has_active_copilot_suggestion(cx));
// Confirming a completion inserts it and hides the context menu, without showing
// the copilot suggestion afterwards.
editor
.confirm_completion(&Default::default(), cx)
.unwrap()
.detach();
assert!(!editor.context_menu_visible());
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.text(cx), "one.completion_a\ntwo\nthree\n");
assert_eq!(editor.display_text(cx), "one.completion_a\ntwo\nthree\n");
});
cx.set_state(indoc! {"
oneˇ
two
three
"});
// When inserting, ensure autocompletion is favored over Copilot suggestions.
cx.simulate_keystroke(".");
let _ = handle_completion_request(
&mut cx,
indoc! {"
one.|<>
two
three
"},
vec!["completion_a", "completion_b"],
);
handle_copilot_completion_request(
&copilot_lsp,
vec![copilot::request::Completion {
text: "one.copilot1".into(),
range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 4)),
..Default::default()
}],
vec![],
);
deterministic.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
cx.update_editor(|editor, cx| {
assert!(editor.context_menu_visible());
assert!(!editor.has_active_copilot_suggestion(cx));
// When hiding the context menu, the Copilot suggestion becomes visible.
editor.hide_context_menu(cx);
assert!(!editor.context_menu_visible());
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot1\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.\ntwo\nthree\n");
});
// Ensure existing completion is interpolated when inserting again.
cx.simulate_keystroke("c");
deterministic.run_until_parked();
cx.update_editor(|editor, cx| {
assert!(!editor.context_menu_visible());
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot1\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n");
});
// After debouncing, new Copilot completions should be requested.
handle_copilot_completion_request(
&copilot_lsp,
vec![copilot::request::Completion {
text: "one.copilot2".into(),
range: lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 5)),
..Default::default()
}],
vec![],
);
deterministic.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
cx.update_editor(|editor, cx| {
assert!(!editor.context_menu_visible());
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n");
// Canceling should remove the active Copilot suggestion.
editor.cancel(&Default::default(), cx);
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.c\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n");
// After canceling, tabbing shouldn't insert the previously shown suggestion.
editor.tab(&Default::default(), cx);
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.c \ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.c \ntwo\nthree\n");
// When undoing the previously active suggestion is shown again.
editor.undo(&Default::default(), cx);
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n");
});
// If an edit occurs outside of this editor, the suggestion is still correctly interpolated.
cx.update_buffer(|buffer, cx| buffer.edit([(5..5, "o")], None, cx));
cx.update_editor(|editor, cx| {
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");
// Tabbing when there is an active suggestion inserts it.
editor.tab(&Default::default(), cx);
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.copilot2\ntwo\nthree\n");
// When undoing the previously active suggestion is shown again.
editor.undo(&Default::default(), cx);
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");
// Hide suggestion.
editor.cancel(&Default::default(), cx);
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.co\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");
});
// If an edit occurs outside of this editor but no suggestion is being shown,
// we won't make it visible.
cx.update_buffer(|buffer, cx| buffer.edit([(6..6, "p")], None, cx));
cx.update_editor(|editor, cx| {
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "one.cop\ntwo\nthree\n");
assert_eq!(editor.text(cx), "one.cop\ntwo\nthree\n");
});
// Reset the editor to verify how suggestions behave when tabbing on leading indentation.
cx.update_editor(|editor, cx| {
editor.set_text("fn foo() {\n \n}", cx);
editor.change_selections(None, cx, |s| {
s.select_ranges([Point::new(1, 2)..Point::new(1, 2)])
});
});
handle_copilot_completion_request(
&copilot_lsp,
vec![copilot::request::Completion {
text: " let x = 4;".into(),
range: lsp::Range::new(lsp::Position::new(1, 0), lsp::Position::new(1, 2)),
..Default::default()
}],
vec![],
);
cx.update_editor(|editor, cx| editor.next_copilot_suggestion(&Default::default(), cx));
deterministic.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
cx.update_editor(|editor, cx| {
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
assert_eq!(editor.text(cx), "fn foo() {\n \n}");
// Tabbing inside of leading whitespace inserts indentation without accepting the suggestion.
editor.tab(&Default::default(), cx);
assert!(editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.text(cx), "fn foo() {\n \n}");
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
// Tabbing again accepts the suggestion.
editor.tab(&Default::default(), cx);
assert!(!editor.has_active_copilot_suggestion(cx));
assert_eq!(editor.text(cx), "fn foo() {\n let x = 4;\n}");
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
});
}
fn empty_range(row: usize, column: usize) -> Range<DisplayPoint> { fn empty_range(row: usize, column: usize) -> Range<DisplayPoint> {
let point = DisplayPoint::new(row as u32, column as u32); let point = DisplayPoint::new(row as u32, column as u32);
point..point point..point
@ -5971,3 +6113,106 @@ fn assert_selection_ranges(marked_text: &str, view: &mut Editor, cx: &mut ViewCo
marked_text marked_text
); );
} }
/// Handle completion request passing a marked string specifying where the completion
/// should be triggered from using '|' character, what range should be replaced, and what completions
/// should be returned using '<' and '>' to delimit the range
fn handle_completion_request<'a>(
cx: &mut EditorLspTestContext<'a>,
marked_string: &str,
completions: Vec<&'static str>,
) -> impl Future<Output = ()> {
let complete_from_marker: TextRangeMarker = '|'.into();
let replace_range_marker: TextRangeMarker = ('<', '>').into();
let (_, mut marked_ranges) = marked_text_ranges_by(
marked_string,
vec![complete_from_marker.clone(), replace_range_marker.clone()],
);
let complete_from_position =
cx.to_lsp(marked_ranges.remove(&complete_from_marker).unwrap()[0].start);
let replace_range =
cx.to_lsp_range(marked_ranges.remove(&replace_range_marker).unwrap()[0].clone());
let mut request = cx.handle_request::<lsp::request::Completion, _, _>(move |url, params, _| {
let completions = completions.clone();
async move {
assert_eq!(params.text_document_position.text_document.uri, url.clone());
assert_eq!(
params.text_document_position.position,
complete_from_position
);
Ok(Some(lsp::CompletionResponse::Array(
completions
.iter()
.map(|completion_text| lsp::CompletionItem {
label: completion_text.to_string(),
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range: replace_range,
new_text: completion_text.to_string(),
})),
..Default::default()
})
.collect(),
)))
}
});
async move {
request.next().await;
}
}
fn handle_resolve_completion_request<'a>(
cx: &mut EditorLspTestContext<'a>,
edits: Option<Vec<(&'static str, &'static str)>>,
) -> impl Future<Output = ()> {
let edits = edits.map(|edits| {
edits
.iter()
.map(|(marked_string, new_text)| {
let (_, marked_ranges) = marked_text_ranges(marked_string, false);
let replace_range = cx.to_lsp_range(marked_ranges[0].clone());
lsp::TextEdit::new(replace_range, new_text.to_string())
})
.collect::<Vec<_>>()
});
let mut request =
cx.handle_request::<lsp::request::ResolveCompletionItem, _, _>(move |_, _, _| {
let edits = edits.clone();
async move {
Ok(lsp::CompletionItem {
additional_text_edits: edits,
..Default::default()
})
}
});
async move {
request.next().await;
}
}
fn handle_copilot_completion_request(
lsp: &lsp::FakeLanguageServer,
completions: Vec<copilot::request::Completion>,
completions_cycling: Vec<copilot::request::Completion>,
) {
lsp.handle_request::<copilot::request::GetCompletions, _, _>(move |_params, _cx| {
let completions = completions.clone();
async move {
Ok(copilot::request::GetCompletionsResult {
completions: completions.clone(),
})
}
});
lsp.handle_request::<copilot::request::GetCompletionsCycling, _, _>(move |_params, _cx| {
let completions_cycling = completions_cycling.clone();
async move {
Ok(copilot::request::GetCompletionsResult {
completions: completions_cycling.clone(),
})
}
});
}

View file

@ -1318,45 +1318,47 @@ impl EditorElement {
.collect() .collect()
} else { } else {
let style = &self.style; let style = &self.style;
let chunks = snapshot.chunks(rows.clone(), true).map(|chunk| { let chunks = snapshot
let mut highlight_style = chunk .chunks(rows.clone(), true, Some(style.theme.suggestion))
.syntax_highlight_id .map(|chunk| {
.and_then(|id| id.style(&style.syntax)); let mut highlight_style = chunk
.syntax_highlight_id
.and_then(|id| id.style(&style.syntax));
if let Some(chunk_highlight) = chunk.highlight_style {
if let Some(highlight_style) = highlight_style.as_mut() {
highlight_style.highlight(chunk_highlight);
} else {
highlight_style = Some(chunk_highlight);
}
}
let mut diagnostic_highlight = HighlightStyle::default();
if chunk.is_unnecessary {
diagnostic_highlight.fade_out = Some(style.unnecessary_code_fade);
}
if let Some(severity) = chunk.diagnostic_severity {
// Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary {
let diagnostic_style = super::diagnostic_style(severity, true, style);
diagnostic_highlight.underline = Some(Underline {
color: Some(diagnostic_style.message.text.color),
thickness: 1.0.into(),
squiggly: true,
});
}
}
if let Some(chunk_highlight) = chunk.highlight_style {
if let Some(highlight_style) = highlight_style.as_mut() { if let Some(highlight_style) = highlight_style.as_mut() {
highlight_style.highlight(chunk_highlight); highlight_style.highlight(diagnostic_highlight);
} else { } else {
highlight_style = Some(chunk_highlight); highlight_style = Some(diagnostic_highlight);
} }
}
let mut diagnostic_highlight = HighlightStyle::default(); (chunk.text, highlight_style)
});
if chunk.is_unnecessary {
diagnostic_highlight.fade_out = Some(style.unnecessary_code_fade);
}
if let Some(severity) = chunk.diagnostic_severity {
// Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary {
let diagnostic_style = super::diagnostic_style(severity, true, style);
diagnostic_highlight.underline = Some(Underline {
color: Some(diagnostic_style.message.text.color),
thickness: 1.0.into(),
squiggly: true,
});
}
}
if let Some(highlight_style) = highlight_style.as_mut() {
highlight_style.highlight(diagnostic_highlight);
} else {
highlight_style = Some(diagnostic_highlight);
}
(chunk.text, highlight_style)
});
layout_highlighted_chunks( layout_highlighted_chunks(
chunks, chunks,
&style.text, &style.text,

View file

@ -2933,6 +2933,10 @@ impl MultiBufferSnapshot {
Some(self.excerpt(excerpt_id)?.buffer_id) Some(self.excerpt(excerpt_id)?.buffer_id)
} }
pub fn buffer_for_excerpt(&self, excerpt_id: ExcerptId) -> Option<&BufferSnapshot> {
Some(&self.excerpt(excerpt_id)?.buffer)
}
fn excerpt<'a>(&'a self, excerpt_id: ExcerptId) -> Option<&'a Excerpt> { fn excerpt<'a>(&'a self, excerpt_id: ExcerptId) -> Option<&'a Excerpt> {
let mut cursor = self.excerpts.cursor::<Option<&Locator>>(); let mut cursor = self.excerpts.cursor::<Option<&Locator>>();
let locator = self.excerpt_locator_for_id(excerpt_id); let locator = self.excerpt_locator_for_id(excerpt_id);

View file

@ -24,8 +24,8 @@ lazy_static = "1.4.0"
postage = { workspace = true } postage = { workspace = true }
project = { path = "../project" } project = { path = "../project" }
search = { path = "../search" } search = { path = "../search" }
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
settings = { path = "../settings" } settings = { path = "../settings" }
sysinfo = "0.27.1" sysinfo = "0.27.1"
theme = { path = "../theme" } theme = { path = "../theme" }

View file

@ -23,7 +23,7 @@ postage = { workspace = true }
[dev-dependencies] [dev-dependencies]
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
ctor = "0.1" ctor = "0.1"
env_logger = "0.9" env_logger = "0.9"

View file

@ -24,7 +24,7 @@ smol = "1.2.5"
regex = "1.5" regex = "1.5"
git2 = { version = "0.15", default-features = false } git2 = { version = "0.15", default-features = false }
serde = { workspace = true } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
libc = "0.2" libc = "0.2"

View file

@ -41,9 +41,9 @@ rand = "0.8.3"
resvg = "0.14" resvg = "0.14"
schemars = "0.8" schemars = "0.8"
seahash = "4.1" seahash = "4.1"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = "1.0" serde_json = { workspace = true }
smallvec = { version = "1.6", features = ["union"] } smallvec = { version = "1.6", features = ["union"] }
smol = "1.2" smol = "1.2"
time = { version = "0.3", features = ["serde", "serde-well-known"] } time = { version = "0.3", features = ["serde", "serde-well-known"] }

View file

@ -765,6 +765,12 @@ impl MutableAppContext {
}) })
} }
pub fn has_window(&self, window_id: usize) -> bool {
self.window_ids()
.find(|window| window == &window_id)
.is_some()
}
pub fn window_ids(&self) -> impl Iterator<Item = usize> + '_ { pub fn window_ids(&self) -> impl Iterator<Item = usize> + '_ {
self.cx.windows.keys().copied() self.cx.windows.keys().copied()
} }
@ -3945,6 +3951,19 @@ impl<'a, T: View> ViewContext<'a, T> {
}) })
} }
pub fn observe_global<G, F>(&mut self, mut callback: F) -> Subscription
where
G: Any,
F: 'static + FnMut(&mut T, &mut ViewContext<T>),
{
let observer = self.weak_handle();
self.app.observe_global::<G, _>(move |cx| {
if let Some(observer) = observer.upgrade(cx) {
observer.update(cx, |observer, cx| callback(observer, cx));
}
})
}
pub fn observe_focus<F, V>(&mut self, handle: &ViewHandle<V>, mut callback: F) -> Subscription pub fn observe_focus<F, V>(&mut self, handle: &ViewHandle<V>, mut callback: F) -> Subscription
where where
F: 'static + FnMut(&mut T, ViewHandle<V>, bool, &mut ViewContext<T>), F: 'static + FnMut(&mut T, ViewHandle<V>, bool, &mut ViewContext<T>),

View file

@ -389,6 +389,12 @@ impl ElementBox {
} }
} }
impl Clone for ElementBox {
fn clone(&self) -> Self {
ElementBox(self.0.clone())
}
}
impl From<ElementBox> for ElementRc { impl From<ElementBox> for ElementRc {
fn from(val: ElementBox) -> Self { fn from(val: ElementBox) -> Self {
val.0 val.0

View file

@ -1,7 +1,6 @@
use cocoa::{ use cocoa::{
appkit::NSWindow,
base::id, base::id,
foundation::{NSPoint, NSRect, NSSize}, foundation::{NSPoint, NSRect},
}; };
use objc::{msg_send, sel, sel_impl}; use objc::{msg_send, sel, sel_impl};
use pathfinder_geometry::{ use pathfinder_geometry::{
@ -25,61 +24,15 @@ impl Vector2FExt for Vector2F {
} }
} }
pub trait RectFExt {
/// Converts self to an NSRect with y axis pointing up.
/// The resulting NSRect will have an origin at the bottom left of the rectangle.
/// Also takes care of converting from window scaled coordinates to screen coordinates
fn to_screen_ns_rect(&self, native_window: id) -> NSRect;
/// Converts self to an NSRect with y axis point up.
/// The resulting NSRect will have an origin at the bottom left of the rectangle.
/// Unlike to_screen_ns_rect, coordinates are not converted and are assumed to already be in screen scale
fn to_ns_rect(&self) -> NSRect;
}
impl RectFExt for RectF {
fn to_screen_ns_rect(&self, native_window: id) -> NSRect {
unsafe { native_window.convertRectToScreen_(self.to_ns_rect()) }
}
fn to_ns_rect(&self) -> NSRect {
NSRect::new(
NSPoint::new(
self.origin_x() as f64,
-(self.origin_y() + self.height()) as f64,
),
NSSize::new(self.width() as f64, self.height() as f64),
)
}
}
pub trait NSRectExt { pub trait NSRectExt {
/// Converts self to a RectF with y axis pointing down.
/// The resulting RectF will have an origin at the top left of the rectangle.
/// Also takes care of converting from screen scale coordinates to window coordinates
fn to_window_rectf(&self, native_window: id) -> RectF;
/// Converts self to a RectF with y axis pointing down.
/// The resulting RectF will have an origin at the top left of the rectangle.
/// Unlike to_screen_ns_rect, coordinates are not converted and are assumed to already be in screen scale
fn to_rectf(&self) -> RectF; fn to_rectf(&self) -> RectF;
fn intersects(&self, other: Self) -> bool; fn intersects(&self, other: Self) -> bool;
} }
impl NSRectExt for NSRect {
fn to_window_rectf(&self, native_window: id) -> RectF {
unsafe {
self.origin.x;
let rect: NSRect = native_window.convertRectFromScreen_(*self);
rect.to_rectf()
}
}
impl NSRectExt for NSRect {
fn to_rectf(&self) -> RectF { fn to_rectf(&self) -> RectF {
RectF::new( RectF::new(
vec2f( vec2f(self.origin.x as f32, self.origin.y as f32),
self.origin.x as f32,
-(self.origin.y + self.size.height) as f32,
),
vec2f(self.size.width as f32, self.size.height as f32), vec2f(self.size.width as f32, self.size.height as f32),
) )
} }

View file

@ -8,7 +8,7 @@ use crate::{
mac::platform::NSViewLayerContentsRedrawDuringViewResize, mac::platform::NSViewLayerContentsRedrawDuringViewResize,
platform::{ platform::{
self, self,
mac::{geometry::RectFExt, renderer::Renderer, screen::Screen}, mac::{renderer::Renderer, screen::Screen},
Event, WindowBounds, Event, WindowBounds,
}, },
InputHandler, KeyDownEvent, ModifiersChangedEvent, MouseButton, MouseButtonEvent, InputHandler, KeyDownEvent, ModifiersChangedEvent, MouseButton, MouseButtonEvent,
@ -372,7 +372,8 @@ impl WindowState {
} }
let window_frame = self.frame(); let window_frame = self.frame();
if window_frame == self.native_window.screen().visibleFrame().to_rectf() { let screen_frame = self.native_window.screen().visibleFrame().to_rectf();
if window_frame.size() == screen_frame.size() {
WindowBounds::Maximized WindowBounds::Maximized
} else { } else {
WindowBounds::Fixed(window_frame) WindowBounds::Fixed(window_frame)
@ -383,8 +384,19 @@ impl WindowState {
// Returns the window bounds in window coordinates // Returns the window bounds in window coordinates
fn frame(&self) -> RectF { fn frame(&self) -> RectF {
unsafe { unsafe {
let ns_frame = NSWindow::frame(self.native_window); let screen_frame = self.native_window.screen().visibleFrame();
ns_frame.to_rectf() let window_frame = NSWindow::frame(self.native_window);
RectF::new(
vec2f(
window_frame.origin.x as f32,
(screen_frame.size.height - window_frame.origin.y - window_frame.size.height)
as f32,
),
vec2f(
window_frame.size.width as f32,
window_frame.size.height as f32,
),
)
} }
} }
@ -472,7 +484,16 @@ impl Window {
} }
WindowBounds::Fixed(rect) => { WindowBounds::Fixed(rect) => {
let screen_frame = screen.visibleFrame(); let screen_frame = screen.visibleFrame();
let ns_rect = rect.to_ns_rect(); let ns_rect = NSRect::new(
NSPoint::new(
rect.origin_x() as f64,
screen_frame.size.height
- rect.origin_y() as f64
- rect.height() as f64,
),
NSSize::new(rect.width() as f64, rect.height() as f64),
);
if ns_rect.intersects(screen_frame) { if ns_rect.intersects(screen_frame) {
native_window.setFrame_display_(ns_rect, YES); native_window.setFrame_display_(ns_rect, YES);
} else { } else {

View file

@ -46,9 +46,9 @@ parking_lot = "0.11.1"
postage = { workspace = true } postage = { workspace = true }
rand = { version = "0.8.3", optional = true } rand = { version = "0.8.3", optional = true }
regex = "1.5" regex = "1.5"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1", features = ["preserve_order"] } serde_json = { workspace = true }
similar = "1.3" similar = "1.3"
smallvec = { version = "1.6", features = ["union"] } smallvec = { version = "1.6", features = ["union"] }
smol = "1.2" smol = "1.2"

View file

@ -10,7 +10,6 @@ mod buffer_tests;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use async_trait::async_trait; use async_trait::async_trait;
use client::http::HttpClient;
use collections::HashMap; use collections::HashMap;
use futures::{ use futures::{
channel::oneshot, channel::oneshot,
@ -20,6 +19,7 @@ use futures::{
use gpui::{executor::Background, MutableAppContext, Task}; use gpui::{executor::Background, MutableAppContext, Task};
use highlight_map::HighlightMap; use highlight_map::HighlightMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use lsp::CodeActionKind;
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use postage::watch; use postage::watch;
use regex::Regex; use regex::Regex;
@ -45,6 +45,7 @@ use syntax_map::SyntaxSnapshot;
use theme::{SyntaxTheme, Theme}; use theme::{SyntaxTheme, Theme};
use tree_sitter::{self, Query}; use tree_sitter::{self, Query};
use unicase::UniCase; use unicase::UniCase;
use util::http::HttpClient;
use util::{merge_json_value_into, post_inc, ResultExt, TryFutureExt as _, UnwrapFuture}; use util::{merge_json_value_into, post_inc, ResultExt, TryFutureExt as _, UnwrapFuture};
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
@ -140,6 +141,10 @@ impl CachedLspAdapter {
self.adapter.cached_server_binary(container_dir).await self.adapter.cached_server_binary(container_dir).await
} }
pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
self.adapter.code_action_kinds()
}
pub fn workspace_configuration( pub fn workspace_configuration(
&self, &self,
cx: &mut MutableAppContext, cx: &mut MutableAppContext,
@ -225,6 +230,16 @@ pub trait LspAdapter: 'static + Send + Sync {
None None
} }
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
Some(vec![
CodeActionKind::EMPTY,
CodeActionKind::QUICKFIX,
CodeActionKind::REFACTOR,
CodeActionKind::REFACTOR_EXTRACT,
CodeActionKind::SOURCE,
])
}
async fn disk_based_diagnostic_sources(&self) -> Vec<String> { async fn disk_based_diagnostic_sources(&self) -> Vec<String> {
Default::default() Default::default()
} }
@ -825,6 +840,7 @@ impl LanguageRegistry {
&binary.path, &binary.path,
&binary.arguments, &binary.arguments,
&root_path, &root_path,
adapter.code_action_kinds(),
cx, cx,
)?; )?;

View file

@ -62,12 +62,12 @@ jwt = "0.16"
lazy_static = "1.4" lazy_static = "1.4"
objc = "0.2" objc = "0.2"
parking_lot = "0.11.1" parking_lot = "0.11.1"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
sha2 = "0.10" sha2 = "0.10"
simplelog = "0.9" simplelog = "0.9"
[build-dependencies] [build-dependencies]
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }

View file

@ -19,8 +19,8 @@ jwt = "0.16"
prost = "0.8" prost = "0.8"
prost-types = "0.8" prost-types = "0.8"
reqwest = "0.11" reqwest = "0.11"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
sha2 = "0.10" sha2 = "0.10"
[build-dependencies] [build-dependencies]

View file

@ -22,9 +22,9 @@ log = { version = "0.4.16", features = ["kv_unstable_serde"] }
lsp-types = "0.91" lsp-types = "0.91"
parking_lot = "0.11" parking_lot = "0.11"
postage = { workspace = true } postage = { workspace = true }
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["raw_value"] } serde_json = { workspace = true }
smol = "1.2" smol = "1.2"
[dev-dependencies] [dev-dependencies]

View file

@ -40,6 +40,7 @@ pub struct LanguageServer {
outbound_tx: channel::Sender<Vec<u8>>, outbound_tx: channel::Sender<Vec<u8>>,
name: String, name: String,
capabilities: ServerCapabilities, capabilities: ServerCapabilities,
code_action_kinds: Option<Vec<CodeActionKind>>,
notification_handlers: Arc<Mutex<HashMap<&'static str, NotificationHandler>>>, notification_handlers: Arc<Mutex<HashMap<&'static str, NotificationHandler>>>,
response_handlers: Arc<Mutex<Option<HashMap<usize, ResponseHandler>>>>, response_handlers: Arc<Mutex<Option<HashMap<usize, ResponseHandler>>>>,
executor: Arc<executor::Background>, executor: Arc<executor::Background>,
@ -110,6 +111,7 @@ impl LanguageServer {
binary_path: &Path, binary_path: &Path,
arguments: &[T], arguments: &[T],
root_path: &Path, root_path: &Path,
code_action_kinds: Option<Vec<CodeActionKind>>,
cx: AsyncAppContext, cx: AsyncAppContext,
) -> Result<Self> { ) -> Result<Self> {
let working_dir = if root_path.is_dir() { let working_dir = if root_path.is_dir() {
@ -135,6 +137,7 @@ impl LanguageServer {
stout, stout,
Some(server), Some(server),
root_path, root_path,
code_action_kinds,
cx, cx,
|notification| { |notification| {
log::info!( log::info!(
@ -160,6 +163,7 @@ impl LanguageServer {
stdout: Stdout, stdout: Stdout,
server: Option<Child>, server: Option<Child>,
root_path: &Path, root_path: &Path,
code_action_kinds: Option<Vec<CodeActionKind>>,
cx: AsyncAppContext, cx: AsyncAppContext,
on_unhandled_notification: F, on_unhandled_notification: F,
) -> Self ) -> Self
@ -197,6 +201,7 @@ impl LanguageServer {
response_handlers, response_handlers,
name: Default::default(), name: Default::default(),
capabilities: Default::default(), capabilities: Default::default(),
code_action_kinds,
next_id: Default::default(), next_id: Default::default(),
outbound_tx, outbound_tx,
executor: cx.background(), executor: cx.background(),
@ -207,6 +212,10 @@ impl LanguageServer {
} }
} }
pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
self.code_action_kinds.clone()
}
async fn handle_input<Stdout, F>( async fn handle_input<Stdout, F>(
stdout: Stdout, stdout: Stdout,
mut on_unhandled_notification: F, mut on_unhandled_notification: F,
@ -326,6 +335,7 @@ impl LanguageServer {
did_change_configuration: Some(DynamicRegistrationClientCapabilities { did_change_configuration: Some(DynamicRegistrationClientCapabilities {
dynamic_registration: Some(true), dynamic_registration: Some(true),
}), }),
workspace_folders: Some(true),
..Default::default() ..Default::default()
}), }),
text_document: Some(TextDocumentClientCapabilities { text_document: Some(TextDocumentClientCapabilities {
@ -715,6 +725,7 @@ impl LanguageServer {
stdout_reader, stdout_reader,
None, None,
Path::new("/"), Path::new("/"),
None,
cx.clone(), cx.clone(),
|_| {}, |_| {},
); );
@ -725,6 +736,7 @@ impl LanguageServer {
stdin_reader, stdin_reader,
None, None,
Path::new("/"), Path::new("/"),
None,
cx, cx,
move |msg| { move |msg| {
notifications_tx notifications_tx

View file

@ -0,0 +1,22 @@
[package]
name = "node_runtime"
version = "0.1.0"
edition = "2021"
publish = false
[lib]
path = "src/node_runtime.rs"
doctest = false
[dependencies]
gpui = { path = "../gpui" }
util = { path = "../util" }
async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] }
async-tar = "0.4.2"
futures = "0.3"
anyhow = "1.0.38"
parking_lot = "0.11.1"
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
smol = "1.2.5"

View file

@ -1,7 +1,6 @@
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use async_compression::futures::bufread::GzipDecoder; use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive; use async_tar::Archive;
use client::http::HttpClient;
use futures::{future::Shared, FutureExt}; use futures::{future::Shared, FutureExt};
use gpui::{executor::Background, Task}; use gpui::{executor::Background, Task};
use parking_lot::Mutex; use parking_lot::Mutex;
@ -12,6 +11,7 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
}; };
use util::http::HttpClient;
const VERSION: &str = "v18.15.0"; const VERSION: &str = "v18.15.0";

View file

@ -21,7 +21,7 @@ parking_lot = "0.11.1"
[dev-dependencies] [dev-dependencies]
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
ctor = "0.1" ctor = "0.1"
env_logger = "0.9" env_logger = "0.9"

View file

@ -5,7 +5,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
serde = "1.0" serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
bincode = "1.3" bincode = "1.3"
plugin_macros = { path = "../plugin_macros" } plugin_macros = { path = "../plugin_macros" }

View file

@ -11,6 +11,6 @@ proc-macro = true
syn = { version = "1.0", features = ["full", "extra-traits"] } syn = { version = "1.0", features = ["full", "extra-traits"] }
quote = "1.0" quote = "1.0"
proc-macro2 = "1.0" proc-macro2 = "1.0"
serde = "1.0" serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
bincode = "1.3" bincode = "1.3"

View file

@ -9,9 +9,9 @@ wasmtime = "0.38"
wasmtime-wasi = "0.38" wasmtime-wasi = "0.38"
wasi-common = "0.38" wasi-common = "0.38"
anyhow = { version = "1.0", features = ["std"] } anyhow = { version = "1.0", features = ["std"] }
serde = "1.0" serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = "1.0" serde_json = { workspace = true }
bincode = "1.3" bincode = "1.3"
pollster = "0.2.5" pollster = "0.2.5"
smol = "1.2.5" smol = "1.2.5"

View file

@ -49,9 +49,9 @@ postage = { workspace = true }
pulldown-cmark = { version = "0.9.1", default-features = false } pulldown-cmark = { version = "0.9.1", default-features = false }
rand = "0.8.3" rand = "0.8.3"
regex = "1.5" regex = "1.5"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
sha2 = "0.10" sha2 = "0.10"
similar = "1.3" similar = "1.3"
smol = "1.2.5" smol = "1.2.5"

View file

@ -568,7 +568,7 @@ impl Project {
let mut languages = LanguageRegistry::test(); let mut languages = LanguageRegistry::test();
languages.set_executor(cx.background()); languages.set_executor(cx.background());
let http_client = client::test::FakeHttpClient::with_404_response(); let http_client = util::http::FakeHttpClient::with_404_response();
let client = cx.update(|cx| client::Client::new(http_client.clone(), cx)); let client = cx.update(|cx| client::Client::new(http_client.clone(), cx));
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let project = let project =
@ -3773,7 +3773,7 @@ impl Project {
worktree = file.worktree.clone(); worktree = file.worktree.clone();
buffer_abs_path = file.as_local().map(|f| f.abs_path(cx)); buffer_abs_path = file.as_local().map(|f| f.abs_path(cx));
} else { } else {
return Task::ready(Ok(Default::default())); return Task::ready(Ok(Vec::new()));
}; };
let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end); let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end);
@ -3783,13 +3783,13 @@ impl Project {
{ {
server.clone() server.clone()
} else { } else {
return Task::ready(Ok(Default::default())); return Task::ready(Ok(Vec::new()));
}; };
let lsp_range = range_to_lsp(range.to_point_utf16(buffer)); let lsp_range = range_to_lsp(range.to_point_utf16(buffer));
cx.foreground().spawn(async move { cx.foreground().spawn(async move {
if lang_server.capabilities().code_action_provider.is_none() { if lang_server.capabilities().code_action_provider.is_none() {
return Ok(Default::default()); return Ok(Vec::new());
} }
Ok(lang_server Ok(lang_server
@ -3802,13 +3802,7 @@ impl Project {
partial_result_params: Default::default(), partial_result_params: Default::default(),
context: lsp::CodeActionContext { context: lsp::CodeActionContext {
diagnostics: relevant_diagnostics, diagnostics: relevant_diagnostics,
only: Some(vec![ only: lang_server.code_action_kinds(),
lsp::CodeActionKind::EMPTY,
lsp::CodeActionKind::QUICKFIX,
lsp::CodeActionKind::REFACTOR,
lsp::CodeActionKind::REFACTOR_EXTRACT,
lsp::CodeActionKind::SOURCE,
]),
}, },
}) })
.await? .await?

View file

@ -841,8 +841,7 @@ impl LocalWorktree {
.unwrap() .unwrap()
.path_changes_tx .path_changes_tx
.try_send((vec![abs_path], tx)) .try_send((vec![abs_path], tx))
.unwrap(); })?;
});
rx.recv().await; rx.recv().await;
Ok(()) Ok(())
})) }))
@ -933,7 +932,7 @@ impl LocalWorktree {
} }
let (tx, mut rx) = barrier::channel(); let (tx, mut rx) = barrier::channel();
path_changes_tx.try_send((paths, tx)).unwrap(); path_changes_tx.try_send((paths, tx))?;
rx.recv().await; rx.recv().await;
this.upgrade(&cx) this.upgrade(&cx)
.ok_or_else(|| anyhow!("worktree was dropped"))? .ok_or_else(|| anyhow!("worktree was dropped"))?
@ -3114,13 +3113,14 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use client::test::FakeHttpClient;
use fs::repository::FakeGitRepository; use fs::repository::FakeGitRepository;
use fs::{FakeFs, RealFs}; use fs::{FakeFs, RealFs};
use gpui::{executor::Deterministic, TestAppContext}; use gpui::{executor::Deterministic, TestAppContext};
use rand::prelude::*; use rand::prelude::*;
use serde_json::json; use serde_json::json;
use std::{env, fmt::Write}; use std::{env, fmt::Write};
use util::http::FakeHttpClient;
use util::test::temp_tree; use util::test::temp_tree;
#[gpui::test] #[gpui::test]

View file

@ -27,4 +27,4 @@ unicase = "2.6"
editor = { path = "../editor", features = ["test-support"] } editor = { path = "../editor", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }

View file

@ -26,8 +26,8 @@ parking_lot = "0.11.1"
prost = "0.8" prost = "0.8"
rand = "0.8" rand = "0.8"
rsa = "0.4" rsa = "0.4"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
smol-timeout = "0.6" smol-timeout = "0.6"
tracing = { version = "0.1.34", features = ["log"] } tracing = { version = "0.1.34", features = ["log"] }
zstd = "0.11" zstd = "0.11"

View file

@ -23,14 +23,14 @@ anyhow = "1.0"
futures = "0.3" futures = "0.3"
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
postage = { workspace = true } postage = { workspace = true }
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
smallvec = { version = "1.6", features = ["union"] } smallvec = { version = "1.6", features = ["union"] }
smol = "1.2" smol = "1.2"
[dev-dependencies] [dev-dependencies]
editor = { path = "../editor", features = ["test-support"] } editor = { path = "../editor", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
unindent = "0.1" unindent = "0.1"

View file

@ -20,12 +20,13 @@ fs = { path = "../fs" }
anyhow = "1.0.38" anyhow = "1.0.38"
futures = "0.3" futures = "0.3"
theme = { path = "../theme" } theme = { path = "../theme" }
staff_mode = { path = "../staff_mode" }
util = { path = "../util" } util = { path = "../util" }
json_comments = "0.2" json_comments = "0.2"
postage = { workspace = true } postage = { workspace = true }
schemars = "0.8" schemars = "0.8"
serde = { workspace = true } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
serde_path_to_error = "0.1.4" serde_path_to_error = "0.1.4"
toml = "0.5" toml = "0.5"
@ -36,3 +37,4 @@ tree-sitter-json = "*"
unindent = "0.1" unindent = "0.1"
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
fs = { path = "../fs", features = ["test-support"] } fs = { path = "../fs", features = ["test-support"] }
pretty_assertions = "1.3.0"

View file

@ -21,7 +21,7 @@ use sqlez::{
use std::{collections::HashMap, num::NonZeroU32, str, sync::Arc}; use std::{collections::HashMap, num::NonZeroU32, str, sync::Arc};
use theme::{Theme, ThemeRegistry}; use theme::{Theme, ThemeRegistry};
use tree_sitter::Query; use tree_sitter::Query;
use util::ResultExt as _; use util::{RangeExt, ResultExt as _};
pub use keymap_file::{keymap_file_json_schema, KeymapFileContent}; pub use keymap_file::{keymap_file_json_schema, KeymapFileContent};
pub use watched_json::watch_files; pub use watched_json::watch_files;
@ -32,6 +32,7 @@ pub struct Settings {
pub buffer_font_features: fonts::Features, pub buffer_font_features: fonts::Features,
pub buffer_font_family: FamilyId, pub buffer_font_family: FamilyId,
pub default_buffer_font_size: f32, pub default_buffer_font_size: f32,
pub enable_copilot_integration: bool,
pub buffer_font_size: f32, pub buffer_font_size: f32,
pub active_pane_magnification: f32, pub active_pane_magnification: f32,
pub cursor_blink: bool, pub cursor_blink: bool,
@ -60,6 +61,29 @@ pub struct Settings {
pub base_keymap: BaseKeymap, pub base_keymap: BaseKeymap,
} }
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
pub enum CopilotSettings {
#[default]
On,
Off,
}
impl From<CopilotSettings> for bool {
fn from(value: CopilotSettings) -> Self {
match value {
CopilotSettings::On => true,
CopilotSettings::Off => false,
}
}
}
impl CopilotSettings {
pub fn is_on(&self) -> bool {
<CopilotSettings as Into<bool>>::into(*self)
}
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
pub enum BaseKeymap { pub enum BaseKeymap {
#[default] #[default]
@ -153,6 +177,43 @@ pub struct EditorSettings {
pub ensure_final_newline_on_save: Option<bool>, pub ensure_final_newline_on_save: Option<bool>,
pub formatter: Option<Formatter>, pub formatter: Option<Formatter>,
pub enable_language_server: Option<bool>, pub enable_language_server: Option<bool>,
#[schemars(skip)]
pub copilot: Option<OnOff>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum OnOff {
On,
Off,
}
impl OnOff {
pub fn as_bool(&self) -> bool {
match self {
OnOff::On => true,
OnOff::Off => false,
}
}
pub fn from_bool(value: bool) -> OnOff {
match value {
true => OnOff::On,
false => OnOff::Off,
}
}
}
impl From<OnOff> for bool {
fn from(value: OnOff) -> bool {
value.as_bool()
}
}
impl From<bool> for OnOff {
fn from(value: bool) -> OnOff {
OnOff::from_bool(value)
}
} }
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
@ -375,6 +436,9 @@ pub struct SettingsFileContent {
pub auto_update: Option<bool>, pub auto_update: Option<bool>,
#[serde(default)] #[serde(default)]
pub base_keymap: Option<BaseKeymap>, pub base_keymap: Option<BaseKeymap>,
#[serde(default)]
#[schemars(skip)]
pub enable_copilot_integration: Option<bool>,
} }
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
@ -436,6 +500,7 @@ impl Settings {
format_on_save: required(defaults.editor.format_on_save), format_on_save: required(defaults.editor.format_on_save),
formatter: required(defaults.editor.formatter), formatter: required(defaults.editor.formatter),
enable_language_server: required(defaults.editor.enable_language_server), enable_language_server: required(defaults.editor.enable_language_server),
copilot: required(defaults.editor.copilot),
}, },
editor_overrides: Default::default(), editor_overrides: Default::default(),
git: defaults.git.unwrap(), git: defaults.git.unwrap(),
@ -452,6 +517,7 @@ impl Settings {
telemetry_overrides: Default::default(), telemetry_overrides: Default::default(),
auto_update: defaults.auto_update.unwrap(), auto_update: defaults.auto_update.unwrap(),
base_keymap: Default::default(), base_keymap: Default::default(),
enable_copilot_integration: defaults.enable_copilot_integration.unwrap(),
} }
} }
@ -503,6 +569,10 @@ impl Settings {
merge(&mut self.autosave, data.autosave); merge(&mut self.autosave, data.autosave);
merge(&mut self.default_dock_anchor, data.default_dock_anchor); merge(&mut self.default_dock_anchor, data.default_dock_anchor);
merge(&mut self.base_keymap, data.base_keymap); merge(&mut self.base_keymap, data.base_keymap);
merge(
&mut self.enable_copilot_integration,
data.enable_copilot_integration,
);
self.editor_overrides = data.editor; self.editor_overrides = data.editor;
self.git_overrides = data.git.unwrap_or_default(); self.git_overrides = data.git.unwrap_or_default();
@ -526,6 +596,14 @@ impl Settings {
self self
} }
pub fn copilot_on(&self, language: Option<&str>) -> bool {
if self.enable_copilot_integration {
self.language_setting(language, |settings| settings.copilot.map(Into::into))
} else {
false
}
}
pub fn tab_size(&self, language: Option<&str>) -> NonZeroU32 { pub fn tab_size(&self, language: Option<&str>) -> NonZeroU32 {
self.language_setting(language, |settings| settings.tab_size) self.language_setting(language, |settings| settings.tab_size)
} }
@ -662,6 +740,7 @@ impl Settings {
format_on_save: Some(FormatOnSave::On), format_on_save: Some(FormatOnSave::On),
formatter: Some(Formatter::LanguageServer), formatter: Some(Formatter::LanguageServer),
enable_language_server: Some(true), enable_language_server: Some(true),
copilot: Some(OnOff::On),
}, },
editor_overrides: Default::default(), editor_overrides: Default::default(),
journal_defaults: Default::default(), journal_defaults: Default::default(),
@ -681,6 +760,7 @@ impl Settings {
telemetry_overrides: Default::default(), telemetry_overrides: Default::default(),
auto_update: true, auto_update: true,
base_keymap: Default::default(), base_keymap: Default::default(),
enable_copilot_integration: true,
} }
} }
@ -701,6 +781,7 @@ pub fn settings_file_json_schema(
settings.option_add_null_type = false; settings.option_add_null_type = false;
}); });
let generator = SchemaGenerator::new(settings); let generator = SchemaGenerator::new(settings);
let mut root_schema = generator.into_root_schema_for::<SettingsFileContent>(); let mut root_schema = generator.into_root_schema_for::<SettingsFileContent>();
// Create a schema for a theme name. // Create a schema for a theme name.
@ -713,6 +794,7 @@ pub fn settings_file_json_schema(
// Create a schema for a 'languages overrides' object, associating editor // Create a schema for a 'languages overrides' object, associating editor
// settings with specific langauges. // settings with specific langauges.
assert!(root_schema.definitions.contains_key("EditorSettings")); assert!(root_schema.definitions.contains_key("EditorSettings"));
let languages_object_schema = SchemaObject { let languages_object_schema = SchemaObject {
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))), instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
object: Some(Box::new(ObjectValidation { object: Some(Box::new(ObjectValidation {
@ -770,6 +852,9 @@ pub fn parse_json_with_comments<T: DeserializeOwned>(content: &str) -> Result<T>
} }
fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_value: &Value) { fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_value: &Value) {
const LANGUAGE_OVERRIDES: &'static str = "language_overrides";
const LANGAUGES: &'static str = "languages";
let mut parser = tree_sitter::Parser::new(); let mut parser = tree_sitter::Parser::new();
parser.set_language(tree_sitter_json::language()).unwrap(); parser.set_language(tree_sitter_json::language()).unwrap();
let tree = parser.parse(&settings_content, None).unwrap(); let tree = parser.parse(&settings_content, None).unwrap();
@ -786,7 +871,10 @@ fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_valu
) )
.unwrap(); .unwrap();
let has_language_overrides = settings_content.contains(LANGUAGE_OVERRIDES);
let mut depth = 0; let mut depth = 0;
let mut last_value_range = 0..0;
let mut first_key_start = None; let mut first_key_start = None;
let mut existing_value_range = 0..settings_content.len(); let mut existing_value_range = 0..settings_content.len();
let matches = cursor.matches(&query, tree.root_node(), settings_content.as_bytes()); let matches = cursor.matches(&query, tree.root_node(), settings_content.as_bytes());
@ -798,6 +886,14 @@ fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_valu
let key_range = mat.captures[0].node.byte_range(); let key_range = mat.captures[0].node.byte_range();
let value_range = mat.captures[1].node.byte_range(); let value_range = mat.captures[1].node.byte_range();
// Don't enter sub objects until we find an exact
// match for the current keypath
if last_value_range.contains_inclusive(&value_range) {
continue;
}
last_value_range = value_range.clone();
if key_range.start > existing_value_range.end { if key_range.start > existing_value_range.end {
break; break;
} }
@ -806,11 +902,19 @@ fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_valu
let found_key = settings_content let found_key = settings_content
.get(key_range.clone()) .get(key_range.clone())
.map(|key_text| key_text == format!("\"{}\"", key_path[depth])) .map(|key_text| {
if key_path[depth] == LANGAUGES && has_language_overrides {
return key_text == format!("\"{}\"", LANGUAGE_OVERRIDES);
} else {
return key_text == format!("\"{}\"", key_path[depth]);
}
})
.unwrap_or(false); .unwrap_or(false);
if found_key { if found_key {
existing_value_range = value_range; existing_value_range = value_range;
// Reset last value range when increasing in depth
last_value_range = existing_value_range.start..existing_value_range.start;
depth += 1; depth += 1;
if depth == key_path.len() { if depth == key_path.len() {
@ -828,12 +932,20 @@ fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_valu
settings_content.replace_range(existing_value_range, &new_val); settings_content.replace_range(existing_value_range, &new_val);
} else { } else {
// We have key paths, construct the sub objects // We have key paths, construct the sub objects
let new_key = key_path[depth]; let new_key = if has_language_overrides && key_path[depth] == LANGAUGES {
LANGUAGE_OVERRIDES
} else {
key_path[depth]
};
// We don't have the key, construct the nested objects // We don't have the key, construct the nested objects
let mut new_value = serde_json::to_value(new_value).unwrap(); let mut new_value = serde_json::to_value(new_value).unwrap();
for key in key_path[(depth + 1)..].iter().rev() { for key in key_path[(depth + 1)..].iter().rev() {
new_value = serde_json::json!({ key.to_string(): new_value }); if has_language_overrides && key == &LANGAUGES {
new_value = serde_json::json!({ LANGUAGE_OVERRIDES.to_string(): new_value });
} else {
new_value = serde_json::json!({ key.to_string(): new_value });
}
} }
if let Some(first_key_start) = first_key_start { if let Some(first_key_start) = first_key_start {
@ -852,7 +964,8 @@ fn write_settings_key(settings_content: &mut String, key_path: &[&str], new_valu
} }
if row > 0 { if row > 0 {
let new_val = to_pretty_json(&new_value, column, column); // depth is 0 based, but division needs to be 1 based.
let new_val = to_pretty_json(&new_value, column / (depth + 1), column);
let content = format!(r#""{new_key}": {new_val},"#); let content = format!(r#""{new_key}": {new_val},"#);
settings_content.insert_str(first_key_start, &content); settings_content.insert_str(first_key_start, &content);
@ -912,13 +1025,28 @@ fn to_pretty_json(
pub fn update_settings_file( pub fn update_settings_file(
mut text: String, mut text: String,
old_file_content: SettingsFileContent, mut old_file_content: SettingsFileContent,
update: impl FnOnce(&mut SettingsFileContent), update: impl FnOnce(&mut SettingsFileContent),
) -> String { ) -> String {
let mut new_file_content = old_file_content.clone(); let mut new_file_content = old_file_content.clone();
update(&mut new_file_content); update(&mut new_file_content);
if new_file_content.languages.len() != old_file_content.languages.len() {
for language in new_file_content.languages.keys() {
old_file_content
.languages
.entry(language.clone())
.or_default();
}
for language in old_file_content.languages.keys() {
new_file_content
.languages
.entry(language.clone())
.or_default();
}
}
let old_object = to_json_object(old_file_content); let old_object = to_json_object(old_file_content);
let new_object = to_json_object(new_file_content); let new_object = to_json_object(new_file_content);
@ -931,6 +1059,7 @@ pub fn update_settings_file(
for (key, old_value) in old_object.iter() { for (key, old_value) in old_object.iter() {
// We know that these two are from the same shape of object, so we can just unwrap // We know that these two are from the same shape of object, so we can just unwrap
let new_value = new_object.get(key).unwrap(); let new_value = new_object.get(key).unwrap();
if old_value != new_value { if old_value != new_value {
match new_value { match new_value {
Value::Bool(_) | Value::Number(_) | Value::String(_) => { Value::Bool(_) | Value::Number(_) | Value::String(_) => {
@ -986,7 +1115,113 @@ mod tests {
let old_json = old_json.into(); let old_json = old_json.into();
let old_content: SettingsFileContent = serde_json::from_str(&old_json).unwrap_or_default(); let old_content: SettingsFileContent = serde_json::from_str(&old_json).unwrap_or_default();
let new_json = update_settings_file(old_json, old_content, update); let new_json = update_settings_file(old_json, old_content, update);
assert_eq!(new_json, expected_new_json.into()); pretty_assertions::assert_eq!(new_json, expected_new_json.into());
}
#[test]
fn test_update_language_overrides_copilot() {
assert_new_settings(
r#"
{
"language_overrides": {
"JSON": {
"copilot": "off"
}
}
}
"#
.unindent(),
|settings| {
settings.languages.insert(
"Rust".into(),
EditorSettings {
copilot: Some(OnOff::On),
..Default::default()
},
);
},
r#"
{
"language_overrides": {
"Rust": {
"copilot": "on"
},
"JSON": {
"copilot": "off"
}
}
}
"#
.unindent(),
);
}
#[test]
fn test_update_copilot() {
assert_new_settings(
r#"
{
"languages": {
"JSON": {
"copilot": "off"
}
}
}
"#
.unindent(),
|settings| {
settings.editor.copilot = Some(OnOff::On);
},
r#"
{
"copilot": "on",
"languages": {
"JSON": {
"copilot": "off"
}
}
}
"#
.unindent(),
);
}
#[test]
fn test_update_langauge_copilot() {
assert_new_settings(
r#"
{
"languages": {
"JSON": {
"copilot": "off"
}
}
}
"#
.unindent(),
|settings| {
settings.languages.insert(
"Rust".into(),
EditorSettings {
copilot: Some(OnOff::On),
..Default::default()
},
);
},
r#"
{
"languages": {
"Rust": {
"copilot": "on"
},
"JSON": {
"copilot": "off"
}
}
}
"#
.unindent(),
);
} }
#[test] #[test]

View file

@ -0,0 +1,12 @@
[package]
name = "staff_mode"
version = "0.1.0"
edition = "2021"
publish = false
[lib]
path = "src/staff_mode.rs"
[dependencies]
gpui = { path = "../gpui" }
anyhow = "1.0.38"

View file

@ -0,0 +1,42 @@
use gpui::MutableAppContext;
#[derive(Debug, Default)]
pub struct StaffMode(pub bool);
impl std::ops::Deref for StaffMode {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
/// Despite what the type system requires me to tell you, the init function will only be called a once
/// as soon as we know that the staff mode is enabled.
pub fn staff_mode<F: FnMut(&mut MutableAppContext) + 'static>(
cx: &mut MutableAppContext,
mut init: F,
) {
if **cx.default_global::<StaffMode>() {
init(cx)
} else {
let mut once = Some(());
cx.observe_global::<StaffMode, _>(move |cx| {
if **cx.global::<StaffMode>() && once.take().is_some() {
init(cx);
}
})
.detach();
}
}
/// Immediately checks and runs the init function if the staff mode is not enabled.
/// This is only included for symettry with staff_mode() above
pub fn not_staff_mode<F: FnOnce(&mut MutableAppContext) + 'static>(
cx: &mut MutableAppContext,
init: F,
) {
if !**cx.default_global::<StaffMode>() {
init(cx)
}
}

View file

@ -29,8 +29,8 @@ libc = "0.2"
anyhow = "1" anyhow = "1"
thiserror = "1.0" thiserror = "1.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
[dev-dependencies] [dev-dependencies]
rand = "0.8.5" rand = "0.8.5"

View file

@ -33,8 +33,8 @@ libc = "0.2"
anyhow = "1" anyhow = "1"
thiserror = "1.0" thiserror = "1.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }

View file

@ -1579,6 +1579,14 @@ impl BufferSnapshot {
self.text_for_range(range).flat_map(str::chars) self.text_for_range(range).flat_map(str::chars)
} }
pub fn reversed_chars_for_range<T: ToOffset>(
&self,
range: Range<T>,
) -> impl Iterator<Item = char> + '_ {
self.reversed_chunks_in_range(range)
.flat_map(|chunk| chunk.chars().rev())
}
pub fn contains_str_at<T>(&self, position: T, needle: &str) -> bool pub fn contains_str_at<T>(&self, position: T, needle: &str) -> bool
where where
T: ToOffset, T: ToOffset,

View file

@ -13,8 +13,8 @@ gpui = { path = "../gpui" }
anyhow = "1.0.38" anyhow = "1.0.38"
indexmap = "1.6.2" indexmap = "1.6.2"
parking_lot = "0.11.1" parking_lot = "0.11.1"
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
serde_path_to_error = "0.1.4" serde_path_to_error = "0.1.4"
toml = "0.5" toml = "0.5"

View file

@ -9,7 +9,7 @@ use gpui::{
use serde::{de::DeserializeOwned, Deserialize}; use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value; use serde_json::Value;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use ui::{CheckboxStyle, IconStyle}; use ui::{ButtonStyle, CheckboxStyle, IconStyle, ModalStyle, SvgStyle};
pub mod ui; pub mod ui;
@ -23,6 +23,7 @@ pub struct Theme {
pub context_menu: ContextMenu, pub context_menu: ContextMenu,
pub contacts_popover: ContactsPopover, pub contacts_popover: ContactsPopover,
pub contact_list: ContactList, pub contact_list: ContactList,
pub copilot: Copilot,
pub contact_finder: ContactFinder, pub contact_finder: ContactFinder,
pub project_panel: ProjectPanel, pub project_panel: ProjectPanel,
pub command_palette: CommandPalette, pub command_palette: CommandPalette,
@ -75,8 +76,8 @@ pub struct Workspace {
#[derive(Clone, Deserialize, Default)] #[derive(Clone, Deserialize, Default)]
pub struct BlankPaneStyle { pub struct BlankPaneStyle {
pub logo: IconStyle, pub logo: SvgStyle,
pub logo_shadow: IconStyle, pub logo_shadow: SvgStyle,
pub logo_container: ContainerStyle, pub logo_container: ContainerStyle,
pub keyboard_hints: ContainerStyle, pub keyboard_hints: ContainerStyle,
pub keyboard_hint: Interactive<ContainedText>, pub keyboard_hint: Interactive<ContainedText>,
@ -115,6 +116,52 @@ pub struct AvatarStyle {
pub outer_corner_radius: f32, pub outer_corner_radius: f32,
} }
#[derive(Deserialize, Default, Clone)]
pub struct Copilot {
pub out_link_icon: Interactive<IconStyle>,
pub modal: ModalStyle,
pub auth: CopilotAuth,
}
#[derive(Deserialize, Default, Clone)]
pub struct CopilotAuth {
pub content_width: f32,
pub prompting: CopilotAuthPrompting,
pub not_authorized: CopilotAuthNotAuthorized,
pub authorized: CopilotAuthAuthorized,
pub cta_button: ButtonStyle,
pub header: IconStyle,
}
#[derive(Deserialize, Default, Clone)]
pub struct CopilotAuthPrompting {
pub subheading: ContainedText,
pub hint: ContainedText,
pub device_code: DeviceCode,
}
#[derive(Deserialize, Default, Clone)]
pub struct DeviceCode {
pub text: TextStyle,
pub cta: ButtonStyle,
pub left: f32,
pub left_container: ContainerStyle,
pub right: f32,
pub right_container: Interactive<ContainerStyle>,
}
#[derive(Deserialize, Default, Clone)]
pub struct CopilotAuthNotAuthorized {
pub subheading: ContainedText,
pub warning: ContainedText,
}
#[derive(Deserialize, Default, Clone)]
pub struct CopilotAuthAuthorized {
pub subheading: ContainedText,
pub hint: ContainedText,
}
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]
pub struct ContactsPopover { pub struct ContactsPopover {
#[serde(flatten)] #[serde(flatten)]
@ -566,6 +613,7 @@ pub struct Editor {
pub line_number_active: Color, pub line_number_active: Color,
pub guest_selections: Vec<SelectionStyle>, pub guest_selections: Vec<SelectionStyle>,
pub syntax: Arc<SyntaxTheme>, pub syntax: Arc<SyntaxTheme>,
pub suggestion: HighlightStyle,
pub diagnostic_path_header: DiagnosticPathHeader, pub diagnostic_path_header: DiagnosticPathHeader,
pub diagnostic_header: DiagnosticHeader, pub diagnostic_header: DiagnosticHeader,
pub error_diagnostic: DiagnosticStyle, pub error_diagnostic: DiagnosticStyle,
@ -691,7 +739,9 @@ pub struct DiffStyle {
pub struct Interactive<T> { pub struct Interactive<T> {
pub default: T, pub default: T,
pub hover: Option<T>, pub hover: Option<T>,
pub hover_and_active: Option<T>,
pub clicked: Option<T>, pub clicked: Option<T>,
pub click_and_active: Option<T>,
pub active: Option<T>, pub active: Option<T>,
pub disabled: Option<T>, pub disabled: Option<T>,
} }
@ -699,7 +749,17 @@ pub struct Interactive<T> {
impl<T> Interactive<T> { impl<T> Interactive<T> {
pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T { pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
if active { if active {
self.active.as_ref().unwrap_or(&self.default) if state.hovered() {
self.hover_and_active
.as_ref()
.unwrap_or(self.active.as_ref().unwrap_or(&self.default))
} else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
self.click_and_active
.as_ref()
.unwrap_or(self.active.as_ref().unwrap_or(&self.default))
} else {
self.active.as_ref().unwrap_or(&self.default)
}
} else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() { } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
self.clicked.as_ref().unwrap() self.clicked.as_ref().unwrap()
} else if state.hovered() { } else if state.hovered() {
@ -724,7 +784,9 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
#[serde(flatten)] #[serde(flatten)]
default: Value, default: Value,
hover: Option<Value>, hover: Option<Value>,
hover_and_active: Option<Value>,
clicked: Option<Value>, clicked: Option<Value>,
click_and_active: Option<Value>,
active: Option<Value>, active: Option<Value>,
disabled: Option<Value>, disabled: Option<Value>,
} }
@ -751,7 +813,9 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
}; };
let hover = deserialize_state(json.hover)?; let hover = deserialize_state(json.hover)?;
let hover_and_active = deserialize_state(json.hover_and_active)?;
let clicked = deserialize_state(json.clicked)?; let clicked = deserialize_state(json.clicked)?;
let click_and_active = deserialize_state(json.click_and_active)?;
let active = deserialize_state(json.active)?; let active = deserialize_state(json.active)?;
let disabled = deserialize_state(json.disabled)?; let disabled = deserialize_state(json.disabled)?;
let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?; let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
@ -759,7 +823,9 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
Ok(Interactive { Ok(Interactive {
default, default,
hover, hover,
hover_and_active,
clicked, clicked,
click_and_active,
active, active,
disabled, disabled,
}) })
@ -868,7 +934,7 @@ pub struct FeedbackStyle {
#[derive(Clone, Deserialize, Default)] #[derive(Clone, Deserialize, Default)]
pub struct WelcomeStyle { pub struct WelcomeStyle {
pub page_width: f32, pub page_width: f32,
pub logo: IconStyle, pub logo: SvgStyle,
pub logo_subheading: ContainedText, pub logo_subheading: ContainedText,
pub usage_note: ContainedText, pub usage_note: ContainedText,
pub checkbox: CheckboxStyle, pub checkbox: CheckboxStyle,

View file

@ -1,18 +1,23 @@
use std::borrow::Cow;
use gpui::{ use gpui::{
color::Color, color::Color,
elements::{ elements::{
ConstrainedBox, Container, ContainerStyle, Empty, Flex, KeystrokeLabel, Label, ConstrainedBox, Container, ContainerStyle, Empty, Flex, KeystrokeLabel, Label,
MouseEventHandler, ParentElement, Svg, MouseEventHandler, ParentElement, Stack, Svg,
}, },
Action, Element, ElementBox, EventContext, RenderContext, View, fonts::TextStyle,
geometry::vector::{vec2f, Vector2F},
scene::MouseClick,
Action, Element, ElementBox, EventContext, MouseButton, MouseState, RenderContext, View,
}; };
use serde::Deserialize; use serde::Deserialize;
use crate::ContainedText; use crate::{ContainedText, Interactive};
#[derive(Clone, Deserialize, Default)] #[derive(Clone, Deserialize, Default)]
pub struct CheckboxStyle { pub struct CheckboxStyle {
pub icon: IconStyle, pub icon: SvgStyle,
pub label: ContainedText, pub label: ContainedText,
pub default: ContainerStyle, pub default: ContainerStyle,
pub checked: ContainerStyle, pub checked: ContainerStyle,
@ -44,7 +49,7 @@ pub fn checkbox_with_label<T: 'static, V: View>(
) -> MouseEventHandler<T> { ) -> MouseEventHandler<T> {
MouseEventHandler::<T>::new(0, cx, |state, _| { MouseEventHandler::<T>::new(0, cx, |state, _| {
let indicator = if checked { let indicator = if checked {
icon(&style.icon) svg(&style.icon)
} else { } else {
Empty::new() Empty::new()
.constrained() .constrained()
@ -80,9 +85,9 @@ pub fn checkbox_with_label<T: 'static, V: View>(
} }
#[derive(Clone, Deserialize, Default)] #[derive(Clone, Deserialize, Default)]
pub struct IconStyle { pub struct SvgStyle {
pub color: Color, pub color: Color,
pub icon: String, pub asset: String,
pub dimensions: Dimensions, pub dimensions: Dimensions,
} }
@ -92,14 +97,30 @@ pub struct Dimensions {
pub height: f32, pub height: f32,
} }
pub fn icon(style: &IconStyle) -> ConstrainedBox { impl Dimensions {
Svg::new(style.icon.clone()) pub fn to_vec(&self) -> Vector2F {
vec2f(self.width, self.height)
}
}
pub fn svg(style: &SvgStyle) -> ConstrainedBox {
Svg::new(style.asset.clone())
.with_color(style.color) .with_color(style.color)
.constrained() .constrained()
.with_width(style.dimensions.width) .with_width(style.dimensions.width)
.with_height(style.dimensions.height) .with_height(style.dimensions.height)
} }
#[derive(Clone, Deserialize, Default)]
pub struct IconStyle {
icon: SvgStyle,
container: ContainerStyle,
}
pub fn icon(style: &IconStyle) -> Container {
svg(&style.icon).contained().with_style(style.container)
}
pub fn keystroke_label<V: View>( pub fn keystroke_label<V: View>(
label_text: &'static str, label_text: &'static str,
label_style: &ContainedText, label_style: &ContainedText,
@ -147,3 +168,123 @@ pub fn keystroke_label_for(
.contained() .contained()
.with_style(label_style.container) .with_style(label_style.container)
} }
pub type ButtonStyle = Interactive<ContainedText>;
pub fn cta_button<L, A, V>(
label: L,
action: A,
max_width: f32,
style: &ButtonStyle,
cx: &mut RenderContext<V>,
) -> ElementBox
where
L: Into<Cow<'static, str>>,
A: 'static + Action + Clone,
V: View,
{
cta_button_with_click(label, max_width, style, cx, move |_, cx| {
cx.dispatch_action(action.clone())
})
.boxed()
}
pub fn cta_button_with_click<L, V, F>(
label: L,
max_width: f32,
style: &ButtonStyle,
cx: &mut RenderContext<V>,
f: F,
) -> MouseEventHandler<F>
where
L: Into<Cow<'static, str>>,
V: View,
F: Fn(MouseClick, &mut EventContext) + 'static,
{
MouseEventHandler::<F>::new(0, cx, |state, _| {
let style = style.style_for(state, false);
Label::new(label, style.text.to_owned())
.aligned()
.contained()
.with_style(style.container)
.constrained()
.with_max_width(max_width)
.boxed()
})
.on_click(MouseButton::Left, f)
.with_cursor_style(gpui::CursorStyle::PointingHand)
}
#[derive(Clone, Deserialize, Default)]
pub struct ModalStyle {
close_icon: Interactive<IconStyle>,
container: ContainerStyle,
titlebar: ContainerStyle,
title_text: Interactive<TextStyle>,
dimensions: Dimensions,
}
impl ModalStyle {
pub fn dimensions(&self) -> Vector2F {
self.dimensions.to_vec()
}
}
pub fn modal<V, I, F>(
title: I,
style: &ModalStyle,
cx: &mut RenderContext<V>,
build_modal: F,
) -> ElementBox
where
V: View,
I: Into<Cow<'static, str>>,
F: FnOnce(&mut gpui::RenderContext<V>) -> ElementBox,
{
const TITLEBAR_HEIGHT: f32 = 28.;
// let active = cx.window_is_active(cx.window_id());
Flex::column()
.with_child(
Stack::new()
.with_children([
Label::new(
title,
style
.title_text
.style_for(&mut MouseState::default(), false)
.clone(),
)
.boxed(),
// FIXME: Get a better tag type
MouseEventHandler::<V>::new(999999, cx, |state, _cx| {
let style = style.close_icon.style_for(state, false);
icon(style).boxed()
})
.on_click(gpui::MouseButton::Left, move |_, cx| {
let window_id = cx.window_id();
cx.remove_window(window_id);
})
.with_cursor_style(gpui::CursorStyle::PointingHand)
.aligned()
.right()
.boxed(),
])
.contained()
.with_style(style.titlebar)
.constrained()
.with_height(TITLEBAR_HEIGHT)
.boxed(),
)
.with_child(
Container::new(build_modal(cx))
.with_style(style.container)
.constrained()
.with_width(style.dimensions().x())
.with_height(style.dimensions().y() - TITLEBAR_HEIGHT)
.boxed(),
)
.constrained()
.with_height(style.dimensions().y())
.boxed()
}

View file

@ -15,6 +15,7 @@ gpui = { path = "../gpui" }
picker = { path = "../picker" } picker = { path = "../picker" }
theme = { path = "../theme" } theme = { path = "../theme" }
settings = { path = "../settings" } settings = { path = "../settings" }
staff_mode = { path = "../staff_mode" }
workspace = { path = "../workspace" } workspace = { path = "../workspace" }
util = { path = "../util" } util = { path = "../util" }
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }

View file

@ -5,9 +5,9 @@ use gpui::{
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
use staff_mode::StaffMode;
use std::sync::Arc; use std::sync::Arc;
use theme::{Theme, ThemeMeta, ThemeRegistry}; use theme::{Theme, ThemeMeta, ThemeRegistry};
use util::StaffMode;
use workspace::{AppState, Workspace}; use workspace::{AppState, Workspace};
pub struct ThemeSelector { pub struct ThemeSelector {

View file

@ -14,12 +14,16 @@ test-support = ["tempdir", "git2"]
[dependencies] [dependencies]
anyhow = "1.0.38" anyhow = "1.0.38"
backtrace = "0.3" backtrace = "0.3"
futures = "0.3"
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
futures = "0.3"
isahc = "1.7"
smol = "1.2.5"
url = "2.2"
rand = { workspace = true } rand = { workspace = true }
tempdir = { version = "0.3.7", optional = true } tempdir = { version = "0.3.7", optional = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde = { workspace = true }
serde_json = { workspace = true }
git2 = { version = "0.15", default-features = false, optional = true } git2 = { version = "0.15", default-features = false, optional = true }
dirs = "3.0" dirs = "3.0"

View file

@ -3,8 +3,12 @@ use std::env;
use lazy_static::lazy_static; use lazy_static::lazy_static;
lazy_static! { lazy_static! {
pub static ref RELEASE_CHANNEL_NAME: String = env::var("ZED_RELEASE_CHANNEL") pub static ref RELEASE_CHANNEL_NAME: String = if cfg!(debug_assertions) {
.unwrap_or_else(|_| include_str!("../../zed/RELEASE_CHANNEL").to_string()); env::var("ZED_RELEASE_CHANNEL")
.unwrap_or_else(|_| include_str!("../../zed/RELEASE_CHANNEL").to_string())
} else {
include_str!("../../zed/RELEASE_CHANNEL").to_string()
};
pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME.as_str() { pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME.as_str() {
"dev" => ReleaseChannel::Dev, "dev" => ReleaseChannel::Dev,
"preview" => ReleaseChannel::Preview, "preview" => ReleaseChannel::Preview,

28
crates/util/src/fs.rs Normal file
View file

@ -0,0 +1,28 @@
use std::path::Path;
use smol::{fs, stream::StreamExt};
use crate::ResultExt;
// Removes all files and directories matching the given predicate
pub async fn remove_matching<F>(dir: &Path, predicate: F)
where
F: Fn(&Path) -> bool,
{
if let Some(mut entries) = fs::read_dir(dir).await.log_err() {
while let Some(entry) = entries.next().await {
if let Some(entry) = entry.log_err() {
let entry_path = entry.path();
if predicate(entry_path.as_path()) {
if let Ok(metadata) = fs::metadata(&entry_path).await {
if metadata.is_file() {
fs::remove_file(&entry_path).await.log_err();
} else {
fs::remove_dir_all(&entry_path).await.log_err();
}
}
}
}
}
}
}

View file

@ -1,7 +1,7 @@
use crate::http::HttpClient;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use client::http::HttpClient; use futures::AsyncReadExt;
use serde::Deserialize; use serde::Deserialize;
use smol::io::AsyncReadExt;
use std::sync::Arc; use std::sync::Arc;
pub struct GitHubLspBinaryVersion { pub struct GitHubLspBinaryVersion {
@ -10,18 +10,18 @@ pub struct GitHubLspBinaryVersion {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub(crate) struct GithubRelease { pub struct GithubRelease {
pub name: String, pub name: String,
pub assets: Vec<GithubReleaseAsset>, pub assets: Vec<GithubReleaseAsset>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub(crate) struct GithubReleaseAsset { pub struct GithubReleaseAsset {
pub name: String, pub name: String,
pub browser_download_url: String, pub browser_download_url: String,
} }
pub(crate) async fn latest_github_release( pub async fn latest_github_release(
repo_name_with_owner: &str, repo_name_with_owner: &str,
http: Arc<dyn HttpClient>, http: Arc<dyn HttpClient>,
) -> Result<GithubRelease, anyhow::Error> { ) -> Result<GithubRelease, anyhow::Error> {
@ -39,6 +39,7 @@ pub(crate) async fn latest_github_release(
.read_to_end(&mut body) .read_to_end(&mut body)
.await .await
.context("error reading latest release")?; .context("error reading latest release")?;
let release: GithubRelease = let release: GithubRelease =
serde_json::from_slice(body.as_slice()).context("error deserializing latest release")?; serde_json::from_slice(body.as_slice()).context("error deserializing latest release")?;
Ok(release) Ok(release)

117
crates/util/src/http.rs Normal file
View file

@ -0,0 +1,117 @@
pub use anyhow::{anyhow, Result};
use futures::future::BoxFuture;
use isahc::config::{Configurable, RedirectPolicy};
pub use isahc::{
http::{Method, Uri},
Error,
};
pub use isahc::{AsyncBody, Request, Response};
use smol::future::FutureExt;
#[cfg(feature = "test-support")]
use std::fmt;
use std::{sync::Arc, time::Duration};
pub use url::Url;
pub trait HttpClient: Send + Sync {
fn send(&self, req: Request<AsyncBody>) -> BoxFuture<Result<Response<AsyncBody>, Error>>;
fn get<'a>(
&'a self,
uri: &str,
body: AsyncBody,
follow_redirects: bool,
) -> BoxFuture<'a, Result<Response<AsyncBody>, Error>> {
let request = isahc::Request::builder()
.redirect_policy(if follow_redirects {
RedirectPolicy::Follow
} else {
RedirectPolicy::None
})
.method(Method::GET)
.uri(uri)
.body(body);
match request {
Ok(request) => self.send(request),
Err(error) => async move { Err(error.into()) }.boxed(),
}
}
fn post_json<'a>(
&'a self,
uri: &str,
body: AsyncBody,
) -> BoxFuture<'a, Result<Response<AsyncBody>, Error>> {
let request = isahc::Request::builder()
.method(Method::POST)
.uri(uri)
.header("Content-Type", "application/json")
.body(body);
match request {
Ok(request) => self.send(request),
Err(error) => async move { Err(error.into()) }.boxed(),
}
}
}
pub fn client() -> Arc<dyn HttpClient> {
Arc::new(
isahc::HttpClient::builder()
.connect_timeout(Duration::from_secs(5))
.low_speed_timeout(100, Duration::from_secs(5))
.build()
.unwrap(),
)
}
impl HttpClient for isahc::HttpClient {
fn send(&self, req: Request<AsyncBody>) -> BoxFuture<Result<Response<AsyncBody>, Error>> {
Box::pin(async move { self.send_async(req).await })
}
}
#[cfg(feature = "test-support")]
pub struct FakeHttpClient {
handler: Box<
dyn 'static
+ Send
+ Sync
+ Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>,
>,
}
#[cfg(feature = "test-support")]
impl FakeHttpClient {
pub fn create<Fut, F>(handler: F) -> Arc<dyn HttpClient>
where
Fut: 'static + Send + futures::Future<Output = Result<Response<AsyncBody>, Error>>,
F: 'static + Send + Sync + Fn(Request<AsyncBody>) -> Fut,
{
Arc::new(Self {
handler: Box::new(move |req| Box::pin(handler(req))),
})
}
pub fn with_404_response() -> Arc<dyn HttpClient> {
Self::create(|_| async move {
Ok(Response::builder()
.status(404)
.body(Default::default())
.unwrap())
})
}
}
#[cfg(feature = "test-support")]
impl fmt::Debug for FakeHttpClient {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FakeHttpClient").finish()
}
}
#[cfg(feature = "test-support")]
impl HttpClient for FakeHttpClient {
fn send(&self, req: Request<AsyncBody>) -> BoxFuture<Result<Response<AsyncBody>, Error>> {
let future = (self.handler)(req);
Box::pin(async move { future.await.map(Into::into) })
}
}

View file

@ -6,6 +6,7 @@ lazy_static::lazy_static! {
pub static ref LOGS_DIR: PathBuf = HOME.join("Library/Logs/Zed"); pub static ref LOGS_DIR: PathBuf = HOME.join("Library/Logs/Zed");
pub static ref SUPPORT_DIR: PathBuf = HOME.join("Library/Application Support/Zed"); pub static ref SUPPORT_DIR: PathBuf = HOME.join("Library/Application Support/Zed");
pub static ref LANGUAGES_DIR: PathBuf = HOME.join("Library/Application Support/Zed/languages"); pub static ref LANGUAGES_DIR: PathBuf = HOME.join("Library/Application Support/Zed/languages");
pub static ref COPILOT_DIR: PathBuf = HOME.join("Library/Application Support/Zed/copilot");
pub static ref DB_DIR: PathBuf = HOME.join("Library/Application Support/Zed/db"); pub static ref DB_DIR: PathBuf = HOME.join("Library/Application Support/Zed/db");
pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json"); pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json");
pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json"); pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json");

View file

@ -1,4 +1,7 @@
pub mod channel; pub mod channel;
pub mod fs;
pub mod github;
pub mod http;
pub mod paths; pub mod paths;
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub mod test; pub mod test;
@ -14,17 +17,6 @@ pub use backtrace::Backtrace;
use futures::Future; use futures::Future;
use rand::{seq::SliceRandom, Rng}; use rand::{seq::SliceRandom, Rng};
#[derive(Debug, Default)]
pub struct StaffMode(pub bool);
impl std::ops::Deref for StaffMode {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[macro_export] #[macro_export]
macro_rules! debug_panic { macro_rules! debug_panic {
( $($fmt_arg:tt)* ) => { ( $($fmt_arg:tt)* ) => {
@ -298,6 +290,7 @@ pub trait RangeExt<T> {
fn sorted(&self) -> Self; fn sorted(&self) -> Self;
fn to_inclusive(&self) -> RangeInclusive<T>; fn to_inclusive(&self) -> RangeInclusive<T>;
fn overlaps(&self, other: &Range<T>) -> bool; fn overlaps(&self, other: &Range<T>) -> bool;
fn contains_inclusive(&self, other: &Range<T>) -> bool;
} }
impl<T: Ord + Clone> RangeExt<T> for Range<T> { impl<T: Ord + Clone> RangeExt<T> for Range<T> {
@ -312,6 +305,10 @@ impl<T: Ord + Clone> RangeExt<T> for Range<T> {
fn overlaps(&self, other: &Range<T>) -> bool { fn overlaps(&self, other: &Range<T>) -> bool {
self.start < other.end && other.start < self.end self.start < other.end && other.start < self.end
} }
fn contains_inclusive(&self, other: &Range<T>) -> bool {
self.start <= other.start && other.end <= self.end
}
} }
impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> { impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
@ -326,6 +323,10 @@ impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
fn overlaps(&self, other: &Range<T>) -> bool { fn overlaps(&self, other: &Range<T>) -> bool {
self.start() < &other.end && &other.start <= self.end() self.start() < &other.end && &other.start <= self.end()
} }
fn contains_inclusive(&self, other: &Range<T>) -> bool {
self.start() <= &other.start && &other.end <= self.end()
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -12,8 +12,8 @@ doctest = false
neovim = ["nvim-rs", "async-compat", "async-trait", "tokio"] neovim = ["nvim-rs", "async-compat", "async-trait", "tokio"]
[dependencies] [dependencies]
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
itertools = "0.10" itertools = "0.10"
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
@ -21,7 +21,7 @@ async-compat = { version = "0.2.1", "optional" = true }
async-trait = { version = "0.1", "optional" = true } async-trait = { version = "0.1", "optional" = true }
nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "master", features = ["use_tokio"], optional = true } nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "master", features = ["use_tokio"], optional = true }
tokio = { version = "1.15", "optional" = true } tokio = { version = "1.15", "optional" = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
assets = { path = "../assets" } assets = { path = "../assets" }
collections = { path = "../collections" } collections = { path = "../collections" }

View file

@ -12,7 +12,7 @@ mod visual;
use std::sync::Arc; use std::sync::Arc;
use command_palette::CommandPaletteFilter; use collections::CommandPaletteFilter;
use editor::{Bias, Cancel, Editor, EditorMode}; use editor::{Bias, Cancel, Editor, EditorMode};
use gpui::{ use gpui::{
actions, impl_actions, MutableAppContext, Subscription, ViewContext, ViewHandle, WeakViewHandle, actions, impl_actions, MutableAppContext, Subscription, ViewContext, ViewHandle, WeakViewHandle,

View file

@ -1,12 +1,11 @@
mod base_keymap_picker; mod base_keymap_picker;
use std::{borrow::Cow, sync::Arc}; use std::sync::Arc;
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use gpui::{ use gpui::{
elements::{Flex, Label, MouseEventHandler, ParentElement}, elements::{Flex, Label, ParentElement},
Action, Element, ElementBox, Entity, MouseButton, MutableAppContext, RenderContext, Element, ElementBox, Entity, MutableAppContext, Subscription, View, ViewContext,
Subscription, View, ViewContext,
}; };
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
@ -77,7 +76,7 @@ impl View for WelcomePage {
.with_children([ .with_children([
Flex::column() Flex::column()
.with_children([ .with_children([
theme::ui::icon(&theme.welcome.logo) theme::ui::svg(&theme.welcome.logo)
.aligned() .aligned()
.contained() .contained()
.aligned() .aligned()
@ -98,22 +97,25 @@ impl View for WelcomePage {
.boxed(), .boxed(),
Flex::column() Flex::column()
.with_children([ .with_children([
self.render_cta_button( theme::ui::cta_button(
"Choose a theme", "Choose a theme",
theme_selector::Toggle, theme_selector::Toggle,
width, width,
&theme.welcome.button,
cx, cx,
), ),
self.render_cta_button( theme::ui::cta_button(
"Choose a keymap", "Choose a keymap",
ToggleBaseKeymapSelector, ToggleBaseKeymapSelector,
width, width,
&theme.welcome.button,
cx, cx,
), ),
self.render_cta_button( theme::ui::cta_button(
"Install the CLI", "Install the CLI",
install_cli::Install, install_cli::Install,
width, width,
&theme.welcome.button,
cx, cx,
), ),
]) ])
@ -189,101 +191,10 @@ impl View for WelcomePage {
impl WelcomePage { impl WelcomePage {
pub fn new(cx: &mut ViewContext<Self>) -> Self { pub fn new(cx: &mut ViewContext<Self>) -> Self {
let handle = cx.weak_handle();
let settings_subscription = cx.observe_global::<Settings, _>(move |cx| {
if let Some(handle) = handle.upgrade(cx) {
handle.update(cx, |_, cx| cx.notify())
}
});
WelcomePage { WelcomePage {
_settings_subscription: settings_subscription, _settings_subscription: cx.observe_global::<Settings, _>(move |_, cx| cx.notify()),
} }
} }
fn render_cta_button<L, A>(
&self,
label: L,
action: A,
width: f32,
cx: &mut RenderContext<Self>,
) -> ElementBox
where
L: Into<Cow<'static, str>>,
A: 'static + Action + Clone,
{
let theme = cx.global::<Settings>().theme.clone();
MouseEventHandler::<A>::new(0, cx, |state, _| {
let style = theme.welcome.button.style_for(state, false);
Label::new(label, style.text.clone())
.aligned()
.contained()
.with_style(style.container)
.constrained()
.with_max_width(width)
.boxed()
})
.on_click(MouseButton::Left, move |_, cx| {
cx.dispatch_action(action.clone())
})
.with_cursor_style(gpui::CursorStyle::PointingHand)
.boxed()
}
// fn render_settings_checkbox<T: 'static>(
// &self,
// label: &'static str,
// style: &CheckboxStyle,
// checked: bool,
// cx: &mut RenderContext<Self>,
// set_value: fn(&mut SettingsFileContent, checked: bool) -> (),
// ) -> ElementBox {
// MouseEventHandler::<T>::new(0, cx, |state, _| {
// let indicator = if checked {
// Svg::new(style.check_icon.clone())
// .with_color(style.check_icon_color)
// .constrained()
// } else {
// Empty::new().constrained()
// };
// Flex::row()
// .with_children([
// indicator
// .with_width(style.width)
// .with_height(style.height)
// .contained()
// .with_style(if checked {
// if state.hovered() {
// style.hovered_and_checked
// } else {
// style.checked
// }
// } else {
// if state.hovered() {
// style.hovered
// } else {
// style.default
// }
// })
// .boxed(),
// Label::new(label, style.label.text.clone())
// .contained()
// .with_style(style.label.container)
// .boxed(),
// ])
// .align_children_center()
// .boxed()
// })
// .on_click(gpui::MouseButton::Left, move |_, cx| {
// SettingsFile::update(cx, move |content| set_value(content, !checked))
// })
// .with_cursor_style(gpui::CursorStyle::PointingHand)
// .contained()
// .with_style(style.container)
// .boxed()
// }
} }
impl Item for WelcomePage { impl Item for WelcomePage {

View file

@ -44,9 +44,9 @@ env_logger = "0.9.1"
log = { version = "0.4.16", features = ["kv_unstable_serde"] } log = { version = "0.4.16", features = ["kv_unstable_serde"] }
parking_lot = "0.11.1" parking_lot = "0.11.1"
postage = { workspace = true } postage = { workspace = true }
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
smallvec = { version = "1.6", features = ["union"] } smallvec = { version = "1.6", features = ["union"] }
indoc = "1.0.4" indoc = "1.0.4"
uuid = { version = "1.1.2", features = ["v4"] } uuid = { version = "1.1.2", features = ["v4"] }

View file

@ -97,7 +97,7 @@ impl Workspace {
let notification = build_notification(cx); let notification = build_notification(cx);
cx.subscribe(&notification, move |this, handle, event, cx| { cx.subscribe(&notification, move |this, handle, event, cx| {
if handle.read(cx).should_dismiss_notification_on_event(event) { if handle.read(cx).should_dismiss_notification_on_event(event) {
this.dismiss_notification(type_id, id, cx); this.dismiss_notification_internal(type_id, id, cx);
} }
}) })
.detach(); .detach();
@ -107,7 +107,18 @@ impl Workspace {
} }
} }
fn dismiss_notification(&mut self, type_id: TypeId, id: usize, cx: &mut ViewContext<Self>) { pub fn dismiss_notification<V: Notification>(&mut self, id: usize, cx: &mut ViewContext<Self>) {
let type_id = TypeId::of::<V>();
self.dismiss_notification_internal(type_id, id, cx)
}
fn dismiss_notification_internal(
&mut self,
type_id: TypeId,
id: usize,
cx: &mut ViewContext<Self>,
) {
self.notifications self.notifications
.retain(|(existing_type_id, existing_id, _)| { .retain(|(existing_type_id, existing_id, _)| {
if (*existing_type_id, *existing_id) == (type_id, id) { if (*existing_type_id, *existing_id) == (type_id, id) {
@ -141,7 +152,13 @@ pub mod simple_message_notification {
actions!(message_notifications, [CancelMessageNotification]); actions!(message_notifications, [CancelMessageNotification]);
#[derive(Clone, Default, Deserialize, PartialEq)] #[derive(Clone, Default, Deserialize, PartialEq)]
pub struct OsOpen(pub String); pub struct OsOpen(pub Cow<'static, str>);
impl OsOpen {
pub fn new<I: Into<Cow<'static, str>>>(url: I) -> Self {
OsOpen(url.into())
}
}
impl_actions!(message_notifications, [OsOpen]); impl_actions!(message_notifications, [OsOpen]);
@ -149,7 +166,7 @@ pub mod simple_message_notification {
cx.add_action(MessageNotification::dismiss); cx.add_action(MessageNotification::dismiss);
cx.add_action( cx.add_action(
|_workspace: &mut Workspace, open_action: &OsOpen, cx: &mut ViewContext<Workspace>| { |_workspace: &mut Workspace, open_action: &OsOpen, cx: &mut ViewContext<Workspace>| {
cx.platform().open_url(open_action.0.as_str()); cx.platform().open_url(open_action.0.as_ref());
}, },
) )
} }
@ -177,6 +194,18 @@ pub mod simple_message_notification {
} }
} }
pub fn new_boxed_action<S1: Into<Cow<'static, str>>, S2: Into<Cow<'static, str>>>(
message: S1,
click_action: Box<dyn Action>,
click_message: S2,
) -> Self {
Self {
message: message.into(),
click_action: Some(click_action),
click_message: Some(click_message.into()),
}
}
pub fn new<S1: Into<Cow<'static, str>>, A: Action, S2: Into<Cow<'static, str>>>( pub fn new<S1: Into<Cow<'static, str>>, A: Action, S2: Into<Cow<'static, str>>>(
message: S1, message: S1,
click_action: A, click_action: A,
@ -264,9 +293,13 @@ pub mod simple_message_notification {
let style = theme.action_message.style_for(state, false); let style = theme.action_message.style_for(state, false);
if let Some(click_message) = click_message { if let Some(click_message) = click_message {
Some( Some(
Text::new(click_message, style.text.clone()) Flex::row()
.contained() .with_child(
.with_style(style.container) Text::new(click_message, style.text.clone())
.contained()
.with_style(style.container)
.boxed(),
)
.boxed(), .boxed(),
) )
} else { } else {
@ -282,7 +315,8 @@ pub mod simple_message_notification {
.on_up(MouseButton::Left, |_, _| {}) .on_up(MouseButton::Left, |_, _| {})
.on_click(MouseButton::Left, move |_, cx| { .on_click(MouseButton::Left, move |_, cx| {
if let Some(click_action) = click_action.as_ref() { if let Some(click_action) = click_action.as_ref() {
cx.dispatch_any_action(click_action.boxed_clone()) cx.dispatch_any_action(click_action.boxed_clone());
cx.dispatch_action(CancelMessageNotification)
} }
}) })
.with_cursor_style(if has_click_action { .with_cursor_style(if has_click_action {

View file

@ -41,10 +41,10 @@ use gpui::{
impl_actions, impl_internal_actions, impl_actions, impl_internal_actions,
keymap_matcher::KeymapContext, keymap_matcher::KeymapContext,
platform::{CursorStyle, WindowOptions}, platform::{CursorStyle, WindowOptions},
AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, Action, AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext,
MouseButton, MutableAppContext, PathPromptOptions, Platform, PromptLevel, RenderContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, Platform, PromptLevel,
SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, RenderContext, SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle,
WindowBounds, WeakViewHandle, WindowBounds,
}; };
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem}; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
use language::LanguageRegistry; use language::LanguageRegistry;
@ -165,6 +165,67 @@ pub struct OpenProjectEntryInPane {
project_entry: ProjectEntryId, project_entry: ProjectEntryId,
} }
pub struct Toast {
id: usize,
msg: Cow<'static, str>,
click: Option<(Cow<'static, str>, Box<dyn Action>)>,
}
impl Toast {
pub fn new<I: Into<Cow<'static, str>>>(id: usize, msg: I) -> Self {
Toast {
id,
msg: msg.into(),
click: None,
}
}
pub fn new_action<I1: Into<Cow<'static, str>>, I2: Into<Cow<'static, str>>>(
id: usize,
msg: I1,
click_msg: I2,
action: impl Action,
) -> Self {
Toast {
id,
msg: msg.into(),
click: Some((click_msg.into(), Box::new(action))),
}
}
}
impl PartialEq for Toast {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
&& self.msg == other.msg
&& self.click.is_some() == other.click.is_some()
}
}
impl Clone for Toast {
fn clone(&self) -> Self {
Toast {
id: self.id,
msg: self.msg.to_owned(),
click: self
.click
.as_ref()
.map(|(msg, click)| (msg.to_owned(), click.boxed_clone())),
}
}
}
#[derive(Clone, PartialEq)]
pub struct DismissToast {
id: usize,
}
impl DismissToast {
pub fn new(id: usize) -> Self {
DismissToast { id }
}
}
pub type WorkspaceId = i64; pub type WorkspaceId = i64;
impl_internal_actions!( impl_internal_actions!(
@ -178,6 +239,8 @@ impl_internal_actions!(
SplitWithItem, SplitWithItem,
SplitWithProjectEntry, SplitWithProjectEntry,
OpenProjectEntryInPane, OpenProjectEntryInPane,
Toast,
DismissToast
] ]
); );
impl_actions!(workspace, [ActivatePane]); impl_actions!(workspace, [ActivatePane]);
@ -353,6 +416,24 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
.detach(); .detach();
}); });
cx.add_action(|workspace: &mut Workspace, alert: &Toast, cx| {
workspace.dismiss_notification::<MessageNotification>(alert.id, cx);
workspace.show_notification(alert.id, cx, |cx| {
cx.add_view(|_cx| match &alert.click {
Some((click_msg, action)) => MessageNotification::new_boxed_action(
alert.msg.clone(),
action.boxed_clone(),
click_msg.clone(),
),
None => MessageNotification::new_message(alert.msg.clone()),
})
})
});
cx.add_action(|workspace: &mut Workspace, alert: &DismissToast, cx| {
workspace.dismiss_notification::<MessageNotification>(alert.id, cx);
});
let client = &app_state.client; let client = &app_state.client;
client.add_view_request_handler(Workspace::handle_follow); client.add_view_request_handler(Workspace::handle_follow);
client.add_view_message_handler(Workspace::handle_unfollow); client.add_view_message_handler(Workspace::handle_unfollow);
@ -449,7 +530,7 @@ impl AppState {
let fs = fs::FakeFs::new(cx.background().clone()); let fs = fs::FakeFs::new(cx.background().clone());
let languages = Arc::new(LanguageRegistry::test()); let languages = Arc::new(LanguageRegistry::test());
let http_client = client::test::FakeHttpClient::with_404_response(); let http_client = util::http::FakeHttpClient::with_404_response();
let client = Client::new(http_client.clone(), cx); let client = Client::new(http_client.clone(), cx);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let themes = ThemeRegistry::new((), cx.font_cache().clone()); let themes = ThemeRegistry::new((), cx.font_cache().clone());
@ -2690,7 +2771,7 @@ fn notify_if_database_failed(workspace: &ViewHandle<Workspace>, cx: &mut AsyncAp
indoc::indoc! {" indoc::indoc! {"
Failed to load any database file :( Failed to load any database file :(
"}, "},
OsOpen("https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml".to_string()), OsOpen::new("https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml".to_string()),
"Click to let us know about this error" "Click to let us know about this error"
) )
}) })
@ -2712,7 +2793,7 @@ fn notify_if_database_failed(workspace: &ViewHandle<Workspace>, cx: &mut AsyncAp
"}, "},
backup_path backup_path
), ),
OsOpen(backup_path.to_string()), OsOpen::new(backup_path.to_string()),
"Click to show old database in finder", "Click to show old database in finder",
) )
}) })

View file

@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
description = "The fast, collaborative code editor." description = "The fast, collaborative code editor."
edition = "2021" edition = "2021"
name = "zed" name = "zed"
version = "0.80.0" version = "0.80.6"
publish = false publish = false
[lib] [lib]
@ -28,6 +28,8 @@ command_palette = { path = "../command_palette" }
context_menu = { path = "../context_menu" } context_menu = { path = "../context_menu" }
client = { path = "../client" } client = { path = "../client" }
clock = { path = "../clock" } clock = { path = "../clock" }
copilot = { path = "../copilot" }
copilot_button = { path = "../copilot_button" }
diagnostics = { path = "../diagnostics" } diagnostics = { path = "../diagnostics" }
db = { path = "../db" } db = { path = "../db" }
editor = { path = "../editor" } editor = { path = "../editor" }
@ -44,6 +46,7 @@ journal = { path = "../journal" }
language = { path = "../language" } language = { path = "../language" }
language_selector = { path = "../language_selector" } language_selector = { path = "../language_selector" }
lsp = { path = "../lsp" } lsp = { path = "../lsp" }
node_runtime = { path = "../node_runtime" }
outline = { path = "../outline" } outline = { path = "../outline" }
plugin_runtime = { path = "../plugin_runtime" } plugin_runtime = { path = "../plugin_runtime" }
project = { path = "../project" } project = { path = "../project" }
@ -52,6 +55,7 @@ project_symbols = { path = "../project_symbols" }
recent_projects = { path = "../recent_projects" } recent_projects = { path = "../recent_projects" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
settings = { path = "../settings" } settings = { path = "../settings" }
staff_mode = { path = "../staff_mode" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
text = { path = "../text" } text = { path = "../text" }
terminal_view = { path = "../terminal_view" } terminal_view = { path = "../terminal_view" }
@ -87,9 +91,9 @@ rand = "0.8.3"
regex = "1.5" regex = "1.5"
rsa = "0.4" rsa = "0.4"
rust-embed = { version = "6.3", features = ["include-exclude"] } rust-embed = { version = "6.3", features = ["include-exclude"] }
serde = { version = "1.0", features = ["derive", "rc"] } serde = { workspace = true }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] } serde_derive = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
serde_path_to_error = "0.1.4" serde_path_to_error = "0.1.4"
simplelog = "0.9" simplelog = "0.9"
smallvec = { version = "1.6", features = ["union"] } smallvec = { version = "1.6", features = ["union"] }
@ -137,7 +141,7 @@ util = { path = "../util", features = ["test-support"] }
workspace = { path = "../workspace", features = ["test-support"] } workspace = { path = "../workspace", features = ["test-support"] }
env_logger = "0.9" env_logger = "0.9"
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { workspace = true }
unindent = "0.1.7" unindent = "0.1.7"
[package.metadata.bundle-dev] [package.metadata.bundle-dev]

View file

@ -1 +1 @@
dev stable

View file

@ -1,6 +1,4 @@
use anyhow::Context; use anyhow::Context;
use client::http::HttpClient;
use gpui::executor::Background;
pub use language::*; pub use language::*;
use node_runtime::NodeRuntime; use node_runtime::NodeRuntime;
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
@ -9,13 +7,11 @@ use theme::ThemeRegistry;
mod c; mod c;
mod elixir; mod elixir;
mod github;
mod go; mod go;
mod html; mod html;
mod json; mod json;
mod language_plugin; mod language_plugin;
mod lua; mod lua;
mod node_runtime;
mod python; mod python;
mod ruby; mod ruby;
mod rust; mod rust;
@ -37,13 +33,10 @@ mod yaml;
struct LanguageDir; struct LanguageDir;
pub fn init( pub fn init(
http: Arc<dyn HttpClient>,
background: Arc<Background>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
themes: Arc<ThemeRegistry>, themes: Arc<ThemeRegistry>,
node_runtime: Arc<NodeRuntime>,
) { ) {
let node_runtime = NodeRuntime::new(http, background);
for (name, grammar, lsp_adapter) in [ for (name, grammar, lsp_adapter) in [
( (
"c", "c",

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