diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b0293cfddddd98be98c3957298c527b3a71ad1e2..600956c379144d1fcf8d101bfc8b9f85b5e6d4e1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -29,6 +29,7 @@ jobs:
outputs:
run_tests: ${{ steps.filter.outputs.run_tests }}
run_license: ${{ steps.filter.outputs.run_license }}
+ run_docs: ${{ steps.filter.outputs.run_docs }}
runs-on:
- ubuntu-latest
steps:
@@ -58,6 +59,11 @@ jobs:
else
echo "run_tests=false" >> $GITHUB_OUTPUT
fi
+ if [[ $(git diff --name-only $COMPARE_REV ${{ github.sha }} | grep '^docs/') ]]; then
+ echo "run_docs=true" >> $GITHUB_OUTPUT
+ else
+ echo "run_docs=false" >> $GITHUB_OUTPUT
+ fi
if [[ $(git diff --name-only $COMPARE_REV ${{ github.sha }} | grep '^Cargo.lock') ]]; then
echo "run_license=true" >> $GITHUB_OUTPUT
else
@@ -198,7 +204,9 @@ jobs:
timeout-minutes: 60
name: Check docs
needs: [job_spec]
- if: github.repository_owner == 'zed-industries'
+ if: |
+ github.repository_owner == 'zed-industries' &&
+ (needs.job_spec.outputs.run_tests == 'true' || needs.job_spec.outputs.run_docs == 'true')
runs-on:
- buildjet-8vcpu-ubuntu-2204
steps:
diff --git a/.github/workflows/community_delete_comments.yml b/.github/workflows/community_delete_comments.yml
deleted file mode 100644
index 0ebe1ac3acea5fcc2aa572946ac8ae90ac6f94ed..0000000000000000000000000000000000000000
--- a/.github/workflows/community_delete_comments.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-name: Delete Mediafire Comments
-
-on:
- issue_comment:
- types: [created]
-
-permissions:
- issues: write
-
-jobs:
- delete_comment:
- if: github.repository_owner == 'zed-industries'
- runs-on: ubuntu-latest
- steps:
- - name: Check for specific strings in comment
- id: check_comment
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
- with:
- script: |
- const comment = context.payload.comment.body;
- const triggerStrings = ['www.mediafire.com'];
- return triggerStrings.some(triggerString => comment.includes(triggerString));
-
- - name: Delete comment if it contains any of the specific strings
- if: steps.check_comment.outputs.result == 'true'
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
- with:
- script: |
- const commentId = context.payload.comment.id;
- await github.rest.issues.deleteComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- comment_id: commentId
- });
diff --git a/.zed/settings.json b/.zed/settings.json
index b20d741659af99f5c5df83d8b4444f991596de1c..1ef6bc28f7dffb3fd7b25489f3f6ff0c1b0f74c9 100644
--- a/.zed/settings.json
+++ b/.zed/settings.json
@@ -40,6 +40,7 @@
},
"file_types": {
"Dockerfile": ["Dockerfile*[!dockerignore]"],
+ "JSONC": ["assets/**/*.json", "renovate.json"],
"Git Ignore": ["dockerignore"]
},
"hard_tabs": false,
diff --git a/Cargo.lock b/Cargo.lock
index 5caf3a3c2c0450ad30f6a6b0b62d55a332d4fc60..d7840659235de3df350102696365b2ee99958107 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14,6 +14,7 @@ dependencies = [
"gpui",
"language",
"project",
+ "proto",
"release_channel",
"smallvec",
"ui",
@@ -133,18 +134,11 @@ dependencies = [
name = "agent_settings"
version = "0.1.0"
dependencies = [
- "anthropic",
"anyhow",
"collections",
- "deepseek",
"fs",
"gpui",
"language_model",
- "lmstudio",
- "log",
- "mistral",
- "ollama",
- "open_ai",
"paths",
"schemars 0.8.22",
"serde",
@@ -4387,6 +4381,7 @@ dependencies = [
"terminal_view",
"theme",
"tree-sitter",
+ "tree-sitter-go",
"tree-sitter-json",
"ui",
"unindent",
@@ -9024,6 +9019,7 @@ dependencies = [
"ui",
"ui_input",
"util",
+ "vercel",
"workspace-hack",
"zed_llm_client",
]
@@ -9062,6 +9058,7 @@ dependencies = [
"itertools 0.14.0",
"language",
"lsp",
+ "picker",
"project",
"release_channel",
"serde_json",
@@ -13205,6 +13202,7 @@ dependencies = [
"thiserror 2.0.12",
"urlencoding",
"util",
+ "which 6.0.3",
"workspace-hack",
]
@@ -17489,6 +17487,17 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
+[[package]]
+name = "vercel"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "schemars 0.8.22",
+ "serde",
+ "strum 0.27.1",
+ "workspace-hack",
+]
+
[[package]]
name = "version-compare"
version = "0.2.0"
@@ -19971,7 +19980,7 @@ dependencies = [
[[package]]
name = "zed"
-version = "0.193.0"
+version = "0.194.0"
dependencies = [
"activity_indicator",
"agent",
diff --git a/Cargo.toml b/Cargo.toml
index 9ef922b1d995a1541a49c273c5b9994677dba419..ccc70fcb94cf23b45f876802b7dd9211ec0b189c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -166,6 +166,7 @@ members = [
"crates/ui_prompt",
"crates/util",
"crates/util_macros",
+ "crates/vercel",
"crates/vim",
"crates/vim_mode_setting",
"crates/watch",
@@ -377,6 +378,7 @@ ui_macros = { path = "crates/ui_macros" }
ui_prompt = { path = "crates/ui_prompt" }
util = { path = "crates/util" }
util_macros = { path = "crates/util_macros" }
+vercel = { path = "crates/vercel" }
vim = { path = "crates/vim" }
vim_mode_setting = { path = "crates/vim_mode_setting" }
diff --git a/assets/icons/ai_v_zero.svg b/assets/icons/ai_v_zero.svg
new file mode 100644
index 0000000000000000000000000000000000000000..26d09ea26ac12ea4095d5fae0026f54fd332a161
--- /dev/null
+++ b/assets/icons/ai_v_zero.svg
@@ -0,0 +1,16 @@
+
diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json
index 1a9108f1084a929bec2261f8f94f9ea9ab6b5b04..0c4de0e0532f09f01aaf420a4e2803067c9e25b1 100644
--- a/assets/keymaps/default-linux.json
+++ b/assets/keymaps/default-linux.json
@@ -41,7 +41,8 @@
"shift-f11": "debugger::StepOut",
"f11": "zed::ToggleFullScreen",
"ctrl-alt-z": "edit_prediction::RateCompletions",
- "ctrl-shift-i": "edit_prediction::ToggleMenu"
+ "ctrl-shift-i": "edit_prediction::ToggleMenu",
+ "ctrl-alt-l": "lsp_tool::ToggleMenu"
}
},
{
@@ -243,8 +244,7 @@
"ctrl-alt-e": "agent::RemoveAllContext",
"ctrl-shift-e": "project_panel::ToggleFocus",
"ctrl-shift-enter": "agent::ContinueThread",
- "alt-enter": "agent::ContinueWithBurnMode",
- "ctrl-alt-b": "agent::ToggleBurnMode"
+ "alt-enter": "agent::ContinueWithBurnMode"
}
},
{
diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json
index 42bba24d6d84da8bb98cbe5b7f80ac711b624ad4..5bd99963bdb7f22ea1a63d0daa60a55b8d8baccd 100644
--- a/assets/keymaps/default-macos.json
+++ b/assets/keymaps/default-macos.json
@@ -47,7 +47,8 @@
"fn-f": "zed::ToggleFullScreen",
"ctrl-cmd-f": "zed::ToggleFullScreen",
"ctrl-cmd-z": "edit_prediction::RateCompletions",
- "ctrl-cmd-i": "edit_prediction::ToggleMenu"
+ "ctrl-cmd-i": "edit_prediction::ToggleMenu",
+ "ctrl-cmd-l": "lsp_tool::ToggleMenu"
}
},
{
@@ -283,8 +284,7 @@
"cmd-alt-e": "agent::RemoveAllContext",
"cmd-shift-e": "project_panel::ToggleFocus",
"cmd-shift-enter": "agent::ContinueThread",
- "alt-enter": "agent::ContinueWithBurnMode",
- "cmd-alt-b": "agent::ToggleBurnMode"
+ "alt-enter": "agent::ContinueWithBurnMode"
}
},
{
@@ -587,7 +587,6 @@
"alt-cmd-o": ["projects::OpenRecent", { "create_new_window": false }],
"ctrl-cmd-o": ["projects::OpenRemote", { "from_existing_connection": false, "create_new_window": false }],
"ctrl-cmd-shift-o": ["projects::OpenRemote", { "from_existing_connection": true, "create_new_window": false }],
- "alt-cmd-b": "branches::OpenRecent",
"ctrl-~": "workspace::NewTerminal",
"cmd-s": "workspace::Save",
"cmd-k s": "workspace::SaveWithoutFormat",
diff --git a/assets/keymaps/linux/atom.json b/assets/keymaps/linux/atom.json
index d471a54ea59b31ff713e7220d090b40c94d150ba..86ee068b06ef38ccec8215e4296c718dd873c824 100644
--- a/assets/keymaps/linux/atom.json
+++ b/assets/keymaps/linux/atom.json
@@ -9,6 +9,13 @@
},
{
"context": "Editor",
+ "bindings": {
+ "ctrl-k ctrl-u": "editor::ConvertToUpperCase", // editor:upper-case
+ "ctrl-k ctrl-l": "editor::ConvertToLowerCase" // editor:lower-case
+ }
+ },
+ {
+ "context": "Editor && mode == full",
"bindings": {
"ctrl-shift-l": "language_selector::Toggle", // grammar-selector:show
"ctrl-|": "pane::RevealInProjectPanel", // tree-view:reveal-active-file
@@ -19,25 +26,20 @@
"shift-f3": ["editor::SelectPrevious", { "replace_newest": true }], //find-and-replace:find-previous
"alt-shift-down": "editor::AddSelectionBelow", // editor:add-selection-below
"alt-shift-up": "editor::AddSelectionAbove", // editor:add-selection-above
- "ctrl-k ctrl-u": "editor::ConvertToUpperCase", // editor:upper-case
- "ctrl-k ctrl-l": "editor::ConvertToLowerCase", // editor:lower-case
"ctrl-j": "editor::JoinLines", // editor:join-lines
"ctrl-shift-d": "editor::DuplicateLineDown", // editor:duplicate-lines
"ctrl-up": "editor::MoveLineUp", // editor:move-line-up
"ctrl-down": "editor::MoveLineDown", // editor:move-line-down
"ctrl-\\": "workspace::ToggleLeftDock", // tree-view:toggle
- "ctrl-shift-m": "markdown::OpenPreviewToTheSide" // markdown-preview:toggle
- }
- },
- {
- "context": "Editor && mode == full",
- "bindings": {
+ "ctrl-shift-m": "markdown::OpenPreviewToTheSide", // markdown-preview:toggle
"ctrl-r": "outline::Toggle" // symbols-view:toggle-project-symbols
}
},
{
"context": "BufferSearchBar",
"bindings": {
+ "f3": ["editor::SelectNext", { "replace_newest": true }], // find-and-replace:find-next
+ "shift-f3": ["editor::SelectPrevious", { "replace_newest": true }], //find-and-replace:find-previous
"ctrl-f3": "search::SelectNextMatch", // find-and-replace:find-next-selected
"ctrl-shift-f3": "search::SelectPreviousMatch" // find-and-replace:find-previous-selected
}
diff --git a/assets/keymaps/linux/cursor.json b/assets/keymaps/linux/cursor.json
index 14cfcc43eca76239202dc386df23e67d0ca75bd0..347b7885fcc6b013f62e0c6f2ca1504ecc24fb51 100644
--- a/assets/keymaps/linux/cursor.json
+++ b/assets/keymaps/linux/cursor.json
@@ -8,7 +8,6 @@
"ctrl-shift-i": "agent::ToggleFocus",
"ctrl-l": "agent::ToggleFocus",
"ctrl-shift-l": "agent::ToggleFocus",
- "ctrl-alt-b": "agent::ToggleFocus",
"ctrl-shift-j": "agent::OpenConfiguration"
}
},
@@ -42,7 +41,6 @@
"ctrl-shift-i": "workspace::ToggleRightDock",
"ctrl-l": "workspace::ToggleRightDock",
"ctrl-shift-l": "workspace::ToggleRightDock",
- "ctrl-alt-b": "workspace::ToggleRightDock",
"ctrl-w": "workspace::ToggleRightDock", // technically should close chat
"ctrl-.": "agent::ToggleProfileSelector",
"ctrl-/": "agent::ToggleModelSelector",
diff --git a/assets/keymaps/macos/atom.json b/assets/keymaps/macos/atom.json
index 9ddf3538103136d62a51621bfebe99b1c4271267..df48e51767e54524c6645630d1fcb6b1cdeba599 100644
--- a/assets/keymaps/macos/atom.json
+++ b/assets/keymaps/macos/atom.json
@@ -9,6 +9,14 @@
},
{
"context": "Editor",
+ "bindings": {
+ "cmd-shift-backspace": "editor::DeleteToBeginningOfLine",
+ "cmd-k cmd-u": "editor::ConvertToUpperCase",
+ "cmd-k cmd-l": "editor::ConvertToLowerCase"
+ }
+ },
+ {
+ "context": "Editor && mode == full",
"bindings": {
"ctrl-shift-l": "language_selector::Toggle",
"cmd-|": "pane::RevealInProjectPanel",
@@ -19,26 +27,20 @@
"cmd-shift-g": ["editor::SelectPrevious", { "replace_newest": true }],
"ctrl-shift-down": "editor::AddSelectionBelow",
"ctrl-shift-up": "editor::AddSelectionAbove",
- "cmd-shift-backspace": "editor::DeleteToBeginningOfLine",
- "cmd-k cmd-u": "editor::ConvertToUpperCase",
- "cmd-k cmd-l": "editor::ConvertToLowerCase",
"alt-enter": "editor::Newline",
"cmd-shift-d": "editor::DuplicateLineDown",
"ctrl-cmd-up": "editor::MoveLineUp",
"ctrl-cmd-down": "editor::MoveLineDown",
"cmd-\\": "workspace::ToggleLeftDock",
- "ctrl-shift-m": "markdown::OpenPreviewToTheSide"
- }
- },
- {
- "context": "Editor && mode == full",
- "bindings": {
+ "ctrl-shift-m": "markdown::OpenPreviewToTheSide",
"cmd-r": "outline::Toggle"
}
},
{
"context": "BufferSearchBar",
"bindings": {
+ "cmd-g": ["editor::SelectNext", { "replace_newest": true }],
+ "cmd-shift-g": ["editor::SelectPrevious", { "replace_newest": true }],
"cmd-f3": "search::SelectNextMatch",
"cmd-shift-f3": "search::SelectPreviousMatch"
}
diff --git a/assets/keymaps/macos/cursor.json b/assets/keymaps/macos/cursor.json
index 5d26974f056a2d3f918319342fb82d1f8828e767..b1d39bef9eb1397ceaeb0fb82956f14a0391b068 100644
--- a/assets/keymaps/macos/cursor.json
+++ b/assets/keymaps/macos/cursor.json
@@ -8,7 +8,6 @@
"cmd-shift-i": "agent::ToggleFocus",
"cmd-l": "agent::ToggleFocus",
"cmd-shift-l": "agent::ToggleFocus",
- "cmd-alt-b": "agent::ToggleFocus",
"cmd-shift-j": "agent::OpenConfiguration"
}
},
@@ -43,7 +42,6 @@
"cmd-shift-i": "workspace::ToggleRightDock",
"cmd-l": "workspace::ToggleRightDock",
"cmd-shift-l": "workspace::ToggleRightDock",
- "cmd-alt-b": "workspace::ToggleRightDock",
"cmd-w": "workspace::ToggleRightDock", // technically should close chat
"cmd-.": "agent::ToggleProfileSelector",
"cmd-/": "agent::ToggleModelSelector",
diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json
index dde07708488ceb6df5c64fa26311949b58967129..6b95839e2aecf404b0fcbc7d5267e863b2a2bc29 100644
--- a/assets/keymaps/vim.json
+++ b/assets/keymaps/vim.json
@@ -85,10 +85,10 @@
"[ {": ["vim::UnmatchedBackward", { "char": "{" }],
"] )": ["vim::UnmatchedForward", { "char": ")" }],
"[ (": ["vim::UnmatchedBackward", { "char": "(" }],
- "f": ["vim::PushFindForward", { "before": false }],
- "t": ["vim::PushFindForward", { "before": true }],
- "shift-f": ["vim::PushFindBackward", { "after": false }],
- "shift-t": ["vim::PushFindBackward", { "after": true }],
+ "f": ["vim::PushFindForward", { "before": false, "multiline": false }],
+ "t": ["vim::PushFindForward", { "before": true, "multiline": false }],
+ "shift-f": ["vim::PushFindBackward", { "after": false, "multiline": false }],
+ "shift-t": ["vim::PushFindBackward", { "after": true, "multiline": false }],
"m": "vim::PushMark",
"'": ["vim::PushJump", { "line": true }],
"`": ["vim::PushJump", { "line": false }],
@@ -368,6 +368,10 @@
"escape": "editor::Cancel",
"ctrl-[": "editor::Cancel",
":": "command_palette::Toggle",
+ "left": "vim::WrappingLeft",
+ "right": "vim::WrappingRight",
+ "h": "vim::WrappingLeft",
+ "l": "vim::WrappingRight",
"shift-d": "vim::DeleteToEndOfLine",
"shift-j": "vim::JoinLines",
"y": "editor::Copy",
@@ -385,6 +389,10 @@
"shift-p": ["vim::Paste", { "before": true }],
"u": "vim::Undo",
"ctrl-r": "vim::Redo",
+ "f": ["vim::PushFindForward", { "before": false, "multiline": true }],
+ "t": ["vim::PushFindForward", { "before": true, "multiline": true }],
+ "shift-f": ["vim::PushFindBackward", { "after": false, "multiline": true }],
+ "shift-t": ["vim::PushFindBackward", { "after": true, "multiline": true }],
"r": "vim::PushReplace",
"s": "vim::Substitute",
"shift-s": "vim::SubstituteLine",
diff --git a/assets/settings/default.json b/assets/settings/default.json
index 3dd85198d937b8cdb91fece58ca5fe26bc233c16..1b9a19615d4d705de2f8662863f9222cfdd51cf3 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -1720,6 +1720,11 @@
// }
// }
},
+ // Common language server settings.
+ "global_lsp_settings": {
+ // Whether to show the LSP servers button in the status bar.
+ "button": true
+ },
// Jupyter settings
"jupyter": {
"enabled": true
@@ -1734,7 +1739,6 @@
"default_mode": "normal",
"toggle_relative_line_numbers": false,
"use_system_clipboard": "always",
- "use_multiline_find": false,
"use_smartcase_find": false,
"highlight_on_yank_duration": 200,
"custom_digraphs": {},
diff --git a/crates/activity_indicator/Cargo.toml b/crates/activity_indicator/Cargo.toml
index 778cf472df3f7c4234065232ee4c4a023e3ab31f..3a80f012f9fb0e5b056a7b2f8763a2019dfcdf2b 100644
--- a/crates/activity_indicator/Cargo.toml
+++ b/crates/activity_indicator/Cargo.toml
@@ -21,6 +21,7 @@ futures.workspace = true
gpui.workspace = true
language.workspace = true
project.workspace = true
+proto.workspace = true
smallvec.workspace = true
ui.workspace = true
util.workspace = true
diff --git a/crates/activity_indicator/src/activity_indicator.rs b/crates/activity_indicator/src/activity_indicator.rs
index 24762cb7270de14bf4b2e5f42e6209fdd52bc5e2..b3287e8222ccdd1f4f4ca92ff4fd4559b9fcc3f6 100644
--- a/crates/activity_indicator/src/activity_indicator.rs
+++ b/crates/activity_indicator/src/activity_indicator.rs
@@ -80,10 +80,13 @@ impl ActivityIndicator {
let this = cx.new(|cx| {
let mut status_events = languages.language_server_binary_statuses();
cx.spawn(async move |this, cx| {
- while let Some((name, status)) = status_events.next().await {
+ while let Some((name, binary_status)) = status_events.next().await {
this.update(cx, |this: &mut ActivityIndicator, cx| {
this.statuses.retain(|s| s.name != name);
- this.statuses.push(ServerStatus { name, status });
+ this.statuses.push(ServerStatus {
+ name,
+ status: LanguageServerStatusUpdate::Binary(binary_status),
+ });
cx.notify();
})?;
}
@@ -112,8 +115,76 @@ impl ActivityIndicator {
cx.subscribe(
&project.read(cx).lsp_store(),
- |_, _, event, cx| match event {
- LspStoreEvent::LanguageServerUpdate { .. } => cx.notify(),
+ |activity_indicator, _, event, cx| match event {
+ LspStoreEvent::LanguageServerUpdate { name, message, .. } => {
+ if let proto::update_language_server::Variant::StatusUpdate(status_update) =
+ message
+ {
+ let Some(name) = name.clone() else {
+ return;
+ };
+ let status = match &status_update.status {
+ Some(proto::status_update::Status::Binary(binary_status)) => {
+ if let Some(binary_status) =
+ proto::ServerBinaryStatus::from_i32(*binary_status)
+ {
+ let binary_status = match binary_status {
+ proto::ServerBinaryStatus::None => BinaryStatus::None,
+ proto::ServerBinaryStatus::CheckingForUpdate => {
+ BinaryStatus::CheckingForUpdate
+ }
+ proto::ServerBinaryStatus::Downloading => {
+ BinaryStatus::Downloading
+ }
+ proto::ServerBinaryStatus::Starting => {
+ BinaryStatus::Starting
+ }
+ proto::ServerBinaryStatus::Stopping => {
+ BinaryStatus::Stopping
+ }
+ proto::ServerBinaryStatus::Stopped => {
+ BinaryStatus::Stopped
+ }
+ proto::ServerBinaryStatus::Failed => {
+ let Some(error) = status_update.message.clone()
+ else {
+ return;
+ };
+ BinaryStatus::Failed { error }
+ }
+ };
+ LanguageServerStatusUpdate::Binary(binary_status)
+ } else {
+ return;
+ }
+ }
+ Some(proto::status_update::Status::Health(health_status)) => {
+ if let Some(health) =
+ proto::ServerHealth::from_i32(*health_status)
+ {
+ let health = match health {
+ proto::ServerHealth::Ok => ServerHealth::Ok,
+ proto::ServerHealth::Warning => ServerHealth::Warning,
+ proto::ServerHealth::Error => ServerHealth::Error,
+ };
+ LanguageServerStatusUpdate::Health(
+ health,
+ status_update.message.clone().map(SharedString::from),
+ )
+ } else {
+ return;
+ }
+ }
+ None => return,
+ };
+
+ activity_indicator.statuses.retain(|s| s.name != name);
+ activity_indicator
+ .statuses
+ .push(ServerStatus { name, status });
+ }
+ cx.notify()
+ }
_ => {}
},
)
@@ -228,9 +299,23 @@ impl ActivityIndicator {
_: &mut Window,
cx: &mut Context,
) {
- if let Some(updater) = &self.auto_updater {
- updater.update(cx, |updater, cx| updater.dismiss_error(cx));
+ let error_dismissed = if let Some(updater) = &self.auto_updater {
+ updater.update(cx, |updater, cx| updater.dismiss_error(cx))
+ } else {
+ false
+ };
+ if error_dismissed {
+ return;
}
+
+ self.project.update(cx, |project, cx| {
+ if project.last_formatting_failure(cx).is_some() {
+ project.reset_last_formatting_failure(cx);
+ true
+ } else {
+ false
+ }
+ });
}
fn pending_language_server_work<'a>(
@@ -399,6 +484,12 @@ impl ActivityIndicator {
let mut servers_to_clear_statuses = HashSet::::default();
for status in &self.statuses {
match &status.status {
+ LanguageServerStatusUpdate::Binary(
+ BinaryStatus::Starting | BinaryStatus::Stopping,
+ ) => {}
+ LanguageServerStatusUpdate::Binary(BinaryStatus::Stopped) => {
+ servers_to_clear_statuses.insert(status.name.clone());
+ }
LanguageServerStatusUpdate::Binary(BinaryStatus::CheckingForUpdate) => {
checking_for_update.push(status.name.clone());
}
diff --git a/crates/agent/src/agent_profile.rs b/crates/agent/src/agent_profile.rs
index c27a534a56e65dac7da9ae9a69304276205f97a4..07030c744fc085914ed5d085afd3699482fc6739 100644
--- a/crates/agent/src/agent_profile.rs
+++ b/crates/agent/src/agent_profile.rs
@@ -85,6 +85,14 @@ impl AgentProfile {
.collect()
}
+ pub fn is_tool_enabled(&self, source: ToolSource, tool_name: String, cx: &App) -> bool {
+ let Some(settings) = AgentSettings::get_global(cx).profiles.get(&self.id) else {
+ return false;
+ };
+
+ return Self::is_enabled(settings, source, tool_name);
+ }
+
fn is_enabled(settings: &AgentProfileSettings, source: ToolSource, name: String) -> bool {
match source {
ToolSource::Native => *settings.tools.get(name.as_str()).unwrap_or(&false),
diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs
index 7a08de7a0b54dccf792ce42b20666d1e19ca840a..33b9209f0ccd199d28d7aad4f19b81286eb7dfac 100644
--- a/crates/agent/src/thread.rs
+++ b/crates/agent/src/thread.rs
@@ -145,6 +145,10 @@ impl Message {
}
}
+ pub fn push_redacted_thinking(&mut self, data: String) {
+ self.segments.push(MessageSegment::RedactedThinking(data));
+ }
+
pub fn push_text(&mut self, text: &str) {
if let Some(MessageSegment::Text(segment)) = self.segments.last_mut() {
segment.push_str(text);
@@ -183,7 +187,7 @@ pub enum MessageSegment {
text: String,
signature: Option,
},
- RedactedThinking(Vec),
+ RedactedThinking(String),
}
impl MessageSegment {
@@ -194,6 +198,13 @@ impl MessageSegment {
Self::RedactedThinking(_) => false,
}
}
+
+ pub fn text(&self) -> Option<&str> {
+ match self {
+ MessageSegment::Text(text) => Some(text),
+ _ => None,
+ }
+ }
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@@ -1643,6 +1654,25 @@ impl Thread {
};
}
}
+ LanguageModelCompletionEvent::RedactedThinking {
+ data
+ } => {
+ thread.received_chunk();
+
+ if let Some(last_message) = thread.messages.last_mut() {
+ if last_message.role == Role::Assistant
+ && !thread.tool_use.has_tool_results(last_message.id)
+ {
+ last_message.push_redacted_thinking(data);
+ } else {
+ request_assistant_message_id =
+ Some(thread.insert_assistant_message(
+ vec![MessageSegment::RedactedThinking(data)],
+ cx,
+ ));
+ };
+ }
+ }
LanguageModelCompletionEvent::ToolUse(tool_use) => {
let last_assistant_message_id = request_assistant_message_id
.unwrap_or_else(|| {
@@ -1747,7 +1777,7 @@ impl Thread {
match result.as_ref() {
Ok(stop_reason) => match stop_reason {
StopReason::ToolUse => {
- let tool_uses = thread.use_pending_tools(window, cx, model.clone());
+ let tool_uses = thread.use_pending_tools(window, model.clone(), cx);
cx.emit(ThreadEvent::UsePendingTools { tool_uses });
}
StopReason::EndTurn | StopReason::MaxTokens => {
@@ -2097,8 +2127,8 @@ impl Thread {
pub fn use_pending_tools(
&mut self,
window: Option,
- cx: &mut Context,
model: Arc,
+ cx: &mut Context,
) -> Vec {
self.auto_capture_telemetry(cx);
let request =
@@ -2112,43 +2142,53 @@ impl Thread {
.collect::>();
for tool_use in pending_tool_uses.iter() {
- if let Some(tool) = self.tools.read(cx).tool(&tool_use.name, cx) {
- if tool.needs_confirmation(&tool_use.input, cx)
- && !AgentSettings::get_global(cx).always_allow_tool_actions
- {
- self.tool_use.confirm_tool_use(
- tool_use.id.clone(),
- tool_use.ui_text.clone(),
- tool_use.input.clone(),
- request.clone(),
- tool,
- );
- cx.emit(ThreadEvent::ToolConfirmationNeeded);
- } else {
- self.run_tool(
- tool_use.id.clone(),
- tool_use.ui_text.clone(),
- tool_use.input.clone(),
- request.clone(),
- tool,
- model.clone(),
- window,
- cx,
- );
- }
- } else {
- self.handle_hallucinated_tool_use(
- tool_use.id.clone(),
- tool_use.name.clone(),
- window,
- cx,
- );
- }
+ self.use_pending_tool(tool_use.clone(), request.clone(), model.clone(), window, cx);
}
pending_tool_uses
}
+ fn use_pending_tool(
+ &mut self,
+ tool_use: PendingToolUse,
+ request: Arc,
+ model: Arc,
+ window: Option,
+ cx: &mut Context,
+ ) {
+ let Some(tool) = self.tools.read(cx).tool(&tool_use.name, cx) else {
+ return self.handle_hallucinated_tool_use(tool_use.id, tool_use.name, window, cx);
+ };
+
+ if !self.profile.is_tool_enabled(tool.source(), tool.name(), cx) {
+ return self.handle_hallucinated_tool_use(tool_use.id, tool_use.name, window, cx);
+ }
+
+ if tool.needs_confirmation(&tool_use.input, cx)
+ && !AgentSettings::get_global(cx).always_allow_tool_actions
+ {
+ self.tool_use.confirm_tool_use(
+ tool_use.id,
+ tool_use.ui_text,
+ tool_use.input,
+ request,
+ tool,
+ );
+ cx.emit(ThreadEvent::ToolConfirmationNeeded);
+ } else {
+ self.run_tool(
+ tool_use.id,
+ tool_use.ui_text,
+ tool_use.input,
+ request,
+ tool,
+ model,
+ window,
+ cx,
+ );
+ }
+ }
+
pub fn handle_hallucinated_tool_use(
&mut self,
tool_use_id: LanguageModelToolUseId,
diff --git a/crates/agent/src/thread_store.rs b/crates/agent/src/thread_store.rs
index 0582e67a5c4bb13c91a63877b9f17dccd3b18031..516151e9ff90dd6dc4a3e4b3dd5eff37522db7f2 100644
--- a/crates/agent/src/thread_store.rs
+++ b/crates/agent/src/thread_store.rs
@@ -71,7 +71,7 @@ impl Column for DataType {
}
}
-const RULES_FILE_NAMES: [&'static str; 8] = [
+const RULES_FILE_NAMES: [&'static str; 9] = [
".rules",
".cursorrules",
".windsurfrules",
@@ -80,6 +80,7 @@ const RULES_FILE_NAMES: [&'static str; 8] = [
"CLAUDE.md",
"AGENT.md",
"AGENTS.md",
+ "GEMINI.md",
];
pub fn init(cx: &mut App) {
@@ -731,7 +732,7 @@ pub enum SerializedMessageSegment {
signature: Option,
},
RedactedThinking {
- data: Vec,
+ data: String,
},
}
diff --git a/crates/agent_settings/Cargo.toml b/crates/agent_settings/Cargo.toml
index c6a4bedbb5e848d48a03b1d7cbb4329322d1c99b..3afe5ae54757953a43a6bdd465c095dc70c27288 100644
--- a/crates/agent_settings/Cargo.toml
+++ b/crates/agent_settings/Cargo.toml
@@ -12,17 +12,10 @@ workspace = true
path = "src/agent_settings.rs"
[dependencies]
-anthropic = { workspace = true, features = ["schemars"] }
anyhow.workspace = true
collections.workspace = true
gpui.workspace = true
language_model.workspace = true
-lmstudio = { workspace = true, features = ["schemars"] }
-log.workspace = true
-ollama = { workspace = true, features = ["schemars"] }
-open_ai = { workspace = true, features = ["schemars"] }
-deepseek = { workspace = true, features = ["schemars"] }
-mistral = { workspace = true, features = ["schemars"] }
schemars.workspace = true
serde.workspace = true
settings.workspace = true
diff --git a/crates/agent_settings/src/agent_settings.rs b/crates/agent_settings/src/agent_settings.rs
index 1386555582ecf0d47a6e6fcdb2474a655edc3a5e..294d793e79ec534e2318f03db5fbc9a75821ecc0 100644
--- a/crates/agent_settings/src/agent_settings.rs
+++ b/crates/agent_settings/src/agent_settings.rs
@@ -2,16 +2,10 @@ mod agent_profile;
use std::sync::Arc;
-use ::open_ai::Model as OpenAiModel;
-use anthropic::Model as AnthropicModel;
use anyhow::{Result, bail};
use collections::IndexMap;
-use deepseek::Model as DeepseekModel;
use gpui::{App, Pixels, SharedString};
use language_model::LanguageModel;
-use lmstudio::Model as LmStudioModel;
-use mistral::Model as MistralModel;
-use ollama::Model as OllamaModel;
use schemars::{JsonSchema, schema::Schema};
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};
@@ -48,45 +42,6 @@ pub enum NotifyWhenAgentWaiting {
Never,
}
-#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
-#[serde(tag = "name", rename_all = "snake_case")]
-#[schemars(deny_unknown_fields)]
-pub enum AgentProviderContentV1 {
- #[serde(rename = "zed.dev")]
- ZedDotDev { default_model: Option },
- #[serde(rename = "openai")]
- OpenAi {
- default_model: Option,
- api_url: Option,
- available_models: Option>,
- },
- #[serde(rename = "anthropic")]
- Anthropic {
- default_model: Option,
- api_url: Option,
- },
- #[serde(rename = "ollama")]
- Ollama {
- default_model: Option,
- api_url: Option,
- },
- #[serde(rename = "lmstudio")]
- LmStudio {
- default_model: Option,
- api_url: Option,
- },
- #[serde(rename = "deepseek")]
- DeepSeek {
- default_model: Option,
- api_url: Option,
- },
- #[serde(rename = "mistral")]
- Mistral {
- default_model: Option,
- api_url: Option,
- },
-}
-
#[derive(Default, Clone, Debug)]
pub struct AgentSettings {
pub enabled: bool,
@@ -168,366 +123,56 @@ impl LanguageModelParameters {
}
}
-/// Agent panel settings
-#[derive(Clone, Serialize, Deserialize, Debug, Default)]
-pub struct AgentSettingsContent {
- #[serde(flatten)]
- pub inner: Option,
-}
-
-#[derive(Clone, Serialize, Deserialize, Debug)]
-#[serde(untagged)]
-pub enum AgentSettingsContentInner {
- Versioned(Box),
- Legacy(LegacyAgentSettingsContent),
-}
-
-impl AgentSettingsContentInner {
- fn for_v2(content: AgentSettingsContentV2) -> Self {
- AgentSettingsContentInner::Versioned(Box::new(VersionedAgentSettingsContent::V2(content)))
- }
-}
-
-impl JsonSchema for AgentSettingsContent {
- fn schema_name() -> String {
- VersionedAgentSettingsContent::schema_name()
- }
-
- fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> Schema {
- VersionedAgentSettingsContent::json_schema(r#gen)
- }
-
- fn is_referenceable() -> bool {
- VersionedAgentSettingsContent::is_referenceable()
- }
-}
-
impl AgentSettingsContent {
- pub fn is_version_outdated(&self) -> bool {
- match &self.inner {
- Some(AgentSettingsContentInner::Versioned(settings)) => match **settings {
- VersionedAgentSettingsContent::V1(_) => true,
- VersionedAgentSettingsContent::V2(_) => false,
- },
- Some(AgentSettingsContentInner::Legacy(_)) => true,
- None => false,
- }
- }
-
- fn upgrade(&self) -> AgentSettingsContentV2 {
- match &self.inner {
- Some(AgentSettingsContentInner::Versioned(settings)) => match **settings {
- VersionedAgentSettingsContent::V1(ref settings) => AgentSettingsContentV2 {
- enabled: settings.enabled,
- button: settings.button,
- dock: settings.dock,
- default_width: settings.default_width,
- default_height: settings.default_width,
- default_model: settings
- .provider
- .clone()
- .and_then(|provider| match provider {
- AgentProviderContentV1::ZedDotDev { default_model } => default_model
- .map(|model| LanguageModelSelection {
- provider: "zed.dev".into(),
- model,
- }),
- AgentProviderContentV1::OpenAi { default_model, .. } => default_model
- .map(|model| LanguageModelSelection {
- provider: "openai".into(),
- model: model.id().to_string(),
- }),
- AgentProviderContentV1::Anthropic { default_model, .. } => {
- default_model.map(|model| LanguageModelSelection {
- provider: "anthropic".into(),
- model: model.id().to_string(),
- })
- }
- AgentProviderContentV1::Ollama { default_model, .. } => default_model
- .map(|model| LanguageModelSelection {
- provider: "ollama".into(),
- model: model.id().to_string(),
- }),
- AgentProviderContentV1::LmStudio { default_model, .. } => default_model
- .map(|model| LanguageModelSelection {
- provider: "lmstudio".into(),
- model: model.id().to_string(),
- }),
- AgentProviderContentV1::DeepSeek { default_model, .. } => default_model
- .map(|model| LanguageModelSelection {
- provider: "deepseek".into(),
- model: model.id().to_string(),
- }),
- AgentProviderContentV1::Mistral { default_model, .. } => default_model
- .map(|model| LanguageModelSelection {
- provider: "mistral".into(),
- model: model.id().to_string(),
- }),
- }),
- inline_assistant_model: None,
- commit_message_model: None,
- thread_summary_model: None,
- inline_alternatives: None,
- default_profile: None,
- default_view: None,
- profiles: None,
- always_allow_tool_actions: None,
- notify_when_agent_waiting: None,
- stream_edits: None,
- single_file_review: None,
- model_parameters: Vec::new(),
- preferred_completion_mode: None,
- enable_feedback: None,
- play_sound_when_agent_done: None,
- },
- VersionedAgentSettingsContent::V2(ref settings) => settings.clone(),
- },
- Some(AgentSettingsContentInner::Legacy(settings)) => AgentSettingsContentV2 {
- enabled: None,
- button: settings.button,
- dock: settings.dock,
- default_width: settings.default_width,
- default_height: settings.default_height,
- default_model: Some(LanguageModelSelection {
- provider: "openai".into(),
- model: settings
- .default_open_ai_model
- .clone()
- .unwrap_or_default()
- .id()
- .to_string(),
- }),
- inline_assistant_model: None,
- commit_message_model: None,
- thread_summary_model: None,
- inline_alternatives: None,
- default_profile: None,
- default_view: None,
- profiles: None,
- always_allow_tool_actions: None,
- notify_when_agent_waiting: None,
- stream_edits: None,
- single_file_review: None,
- model_parameters: Vec::new(),
- preferred_completion_mode: None,
- enable_feedback: None,
- play_sound_when_agent_done: None,
- },
- None => AgentSettingsContentV2::default(),
- }
- }
-
pub fn set_dock(&mut self, dock: AgentDockPosition) {
- match &mut self.inner {
- Some(AgentSettingsContentInner::Versioned(settings)) => match **settings {
- VersionedAgentSettingsContent::V1(ref mut settings) => {
- settings.dock = Some(dock);
- }
- VersionedAgentSettingsContent::V2(ref mut settings) => {
- settings.dock = Some(dock);
- }
- },
- Some(AgentSettingsContentInner::Legacy(settings)) => {
- settings.dock = Some(dock);
- }
- None => {
- self.inner = Some(AgentSettingsContentInner::for_v2(AgentSettingsContentV2 {
- dock: Some(dock),
- ..Default::default()
- }))
- }
- }
+ self.dock = Some(dock);
}
pub fn set_model(&mut self, language_model: Arc) {
let model = language_model.id().0.to_string();
let provider = language_model.provider_id().0.to_string();
- match &mut self.inner {
- Some(AgentSettingsContentInner::Versioned(settings)) => match **settings {
- VersionedAgentSettingsContent::V1(ref mut settings) => match provider.as_ref() {
- "zed.dev" => {
- log::warn!("attempted to set zed.dev model on outdated settings");
- }
- "anthropic" => {
- let api_url = match &settings.provider {
- Some(AgentProviderContentV1::Anthropic { api_url, .. }) => {
- api_url.clone()
- }
- _ => None,
- };
- settings.provider = Some(AgentProviderContentV1::Anthropic {
- default_model: AnthropicModel::from_id(&model).ok(),
- api_url,
- });
- }
- "ollama" => {
- let api_url = match &settings.provider {
- Some(AgentProviderContentV1::Ollama { api_url, .. }) => api_url.clone(),
- _ => None,
- };
- settings.provider = Some(AgentProviderContentV1::Ollama {
- default_model: Some(ollama::Model::new(
- &model,
- None,
- None,
- Some(language_model.supports_tools()),
- Some(language_model.supports_images()),
- None,
- )),
- api_url,
- });
- }
- "lmstudio" => {
- let api_url = match &settings.provider {
- Some(AgentProviderContentV1::LmStudio { api_url, .. }) => {
- api_url.clone()
- }
- _ => None,
- };
- settings.provider = Some(AgentProviderContentV1::LmStudio {
- default_model: Some(lmstudio::Model::new(
- &model, None, None, false, false,
- )),
- api_url,
- });
- }
- "openai" => {
- let (api_url, available_models) = match &settings.provider {
- Some(AgentProviderContentV1::OpenAi {
- api_url,
- available_models,
- ..
- }) => (api_url.clone(), available_models.clone()),
- _ => (None, None),
- };
- settings.provider = Some(AgentProviderContentV1::OpenAi {
- default_model: OpenAiModel::from_id(&model).ok(),
- api_url,
- available_models,
- });
- }
- "deepseek" => {
- let api_url = match &settings.provider {
- Some(AgentProviderContentV1::DeepSeek { api_url, .. }) => {
- api_url.clone()
- }
- _ => None,
- };
- settings.provider = Some(AgentProviderContentV1::DeepSeek {
- default_model: DeepseekModel::from_id(&model).ok(),
- api_url,
- });
- }
- _ => {}
- },
- VersionedAgentSettingsContent::V2(ref mut settings) => {
- settings.default_model = Some(LanguageModelSelection {
- provider: provider.into(),
- model,
- });
- }
- },
- Some(AgentSettingsContentInner::Legacy(settings)) => {
- if let Ok(model) = OpenAiModel::from_id(&language_model.id().0) {
- settings.default_open_ai_model = Some(model);
- }
- }
- None => {
- self.inner = Some(AgentSettingsContentInner::for_v2(AgentSettingsContentV2 {
- default_model: Some(LanguageModelSelection {
- provider: provider.into(),
- model,
- }),
- ..Default::default()
- }));
- }
- }
+ self.default_model = Some(LanguageModelSelection {
+ provider: provider.into(),
+ model,
+ });
}
pub fn set_inline_assistant_model(&mut self, provider: String, model: String) {
- self.v2_setting(|setting| {
- setting.inline_assistant_model = Some(LanguageModelSelection {
- provider: provider.into(),
- model,
- });
- Ok(())
- })
- .ok();
+ self.inline_assistant_model = Some(LanguageModelSelection {
+ provider: provider.into(),
+ model,
+ });
}
pub fn set_commit_message_model(&mut self, provider: String, model: String) {
- self.v2_setting(|setting| {
- setting.commit_message_model = Some(LanguageModelSelection {
- provider: provider.into(),
- model,
- });
- Ok(())
- })
- .ok();
- }
-
- pub fn v2_setting(
- &mut self,
- f: impl FnOnce(&mut AgentSettingsContentV2) -> anyhow::Result<()>,
- ) -> anyhow::Result<()> {
- match self.inner.get_or_insert_with(|| {
- AgentSettingsContentInner::for_v2(AgentSettingsContentV2 {
- ..Default::default()
- })
- }) {
- AgentSettingsContentInner::Versioned(boxed) => {
- if let VersionedAgentSettingsContent::V2(ref mut settings) = **boxed {
- f(settings)
- } else {
- Ok(())
- }
- }
- _ => Ok(()),
- }
+ self.commit_message_model = Some(LanguageModelSelection {
+ provider: provider.into(),
+ model,
+ });
}
pub fn set_thread_summary_model(&mut self, provider: String, model: String) {
- self.v2_setting(|setting| {
- setting.thread_summary_model = Some(LanguageModelSelection {
- provider: provider.into(),
- model,
- });
- Ok(())
- })
- .ok();
+ self.thread_summary_model = Some(LanguageModelSelection {
+ provider: provider.into(),
+ model,
+ });
}
pub fn set_always_allow_tool_actions(&mut self, allow: bool) {
- self.v2_setting(|setting| {
- setting.always_allow_tool_actions = Some(allow);
- Ok(())
- })
- .ok();
+ self.always_allow_tool_actions = Some(allow);
}
pub fn set_play_sound_when_agent_done(&mut self, allow: bool) {
- self.v2_setting(|setting| {
- setting.play_sound_when_agent_done = Some(allow);
- Ok(())
- })
- .ok();
+ self.play_sound_when_agent_done = Some(allow);
}
pub fn set_single_file_review(&mut self, allow: bool) {
- self.v2_setting(|setting| {
- setting.single_file_review = Some(allow);
- Ok(())
- })
- .ok();
+ self.single_file_review = Some(allow);
}
pub fn set_profile(&mut self, profile_id: AgentProfileId) {
- self.v2_setting(|setting| {
- setting.default_profile = Some(profile_id);
- Ok(())
- })
- .ok();
+ self.default_profile = Some(profile_id);
}
pub fn create_profile(
@@ -535,79 +180,39 @@ impl AgentSettingsContent {
profile_id: AgentProfileId,
profile_settings: AgentProfileSettings,
) -> Result<()> {
- self.v2_setting(|settings| {
- let profiles = settings.profiles.get_or_insert_default();
- if profiles.contains_key(&profile_id) {
- bail!("profile with ID '{profile_id}' already exists");
- }
-
- profiles.insert(
- profile_id,
- AgentProfileContent {
- name: profile_settings.name.into(),
- tools: profile_settings.tools,
- enable_all_context_servers: Some(profile_settings.enable_all_context_servers),
- context_servers: profile_settings
- .context_servers
- .into_iter()
- .map(|(server_id, preset)| {
- (
- server_id,
- ContextServerPresetContent {
- tools: preset.tools,
- },
- )
- })
- .collect(),
- },
- );
-
- Ok(())
- })
- }
-}
+ let profiles = self.profiles.get_or_insert_default();
+ if profiles.contains_key(&profile_id) {
+ bail!("profile with ID '{profile_id}' already exists");
+ }
-#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
-#[serde(tag = "version")]
-#[schemars(deny_unknown_fields)]
-pub enum VersionedAgentSettingsContent {
- #[serde(rename = "1")]
- V1(AgentSettingsContentV1),
- #[serde(rename = "2")]
- V2(AgentSettingsContentV2),
-}
+ profiles.insert(
+ profile_id,
+ AgentProfileContent {
+ name: profile_settings.name.into(),
+ tools: profile_settings.tools,
+ enable_all_context_servers: Some(profile_settings.enable_all_context_servers),
+ context_servers: profile_settings
+ .context_servers
+ .into_iter()
+ .map(|(server_id, preset)| {
+ (
+ server_id,
+ ContextServerPresetContent {
+ tools: preset.tools,
+ },
+ )
+ })
+ .collect(),
+ },
+ );
-impl Default for VersionedAgentSettingsContent {
- fn default() -> Self {
- Self::V2(AgentSettingsContentV2 {
- enabled: None,
- button: None,
- dock: None,
- default_width: None,
- default_height: None,
- default_model: None,
- inline_assistant_model: None,
- commit_message_model: None,
- thread_summary_model: None,
- inline_alternatives: None,
- default_profile: None,
- default_view: None,
- profiles: None,
- always_allow_tool_actions: None,
- notify_when_agent_waiting: None,
- stream_edits: None,
- single_file_review: None,
- model_parameters: Vec::new(),
- preferred_completion_mode: None,
- enable_feedback: None,
- play_sound_when_agent_done: None,
- })
+ Ok(())
}
}
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug, Default)]
#[schemars(deny_unknown_fields)]
-pub struct AgentSettingsContentV2 {
+pub struct AgentSettingsContent {
/// Whether the Agent is enabled.
///
/// Default: true
@@ -734,6 +339,7 @@ impl JsonSchema for LanguageModelProviderSetting {
"deepseek".into(),
"openrouter".into(),
"mistral".into(),
+ "vercel".into(),
]),
..Default::default()
}
@@ -778,65 +384,6 @@ pub struct ContextServerPresetContent {
pub tools: IndexMap, bool>,
}
-#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
-#[schemars(deny_unknown_fields)]
-pub struct AgentSettingsContentV1 {
- /// Whether the Agent is enabled.
- ///
- /// Default: true
- enabled: Option,
- /// Whether to show the Agent panel button in the status bar.
- ///
- /// Default: true
- button: Option,
- /// Where to dock the Agent.
- ///
- /// Default: right
- dock: Option,
- /// Default width in pixels when the Agent is docked to the left or right.
- ///
- /// Default: 640
- default_width: Option,
- /// Default height in pixels when the Agent is docked to the bottom.
- ///
- /// Default: 320
- default_height: Option,
- /// The provider of the Agent service.
- ///
- /// This can be "openai", "anthropic", "ollama", "lmstudio", "deepseek", "zed.dev"
- /// each with their respective default models and configurations.
- provider: Option,
-}
-
-#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
-#[schemars(deny_unknown_fields)]
-pub struct LegacyAgentSettingsContent {
- /// Whether to show the Agent panel button in the status bar.
- ///
- /// Default: true
- pub button: Option,
- /// Where to dock the Agent.
- ///
- /// Default: right
- pub dock: Option,
- /// Default width in pixels when the Agent is docked to the left or right.
- ///
- /// Default: 640
- pub default_width: Option,
- /// Default height in pixels when the Agent is docked to the bottom.
- ///
- /// Default: 320
- pub default_height: Option,
- /// The default OpenAI model to use when creating new chats.
- ///
- /// Default: gpt-4-1106-preview
- pub default_open_ai_model: Option,
- /// OpenAI API base URL to use when creating new chats.
- ///
- /// Default:
- pub openai_api_url: Option,
-}
-
impl Settings for AgentSettings {
const KEY: Option<&'static str> = Some("agent");
@@ -853,11 +400,6 @@ impl Settings for AgentSettings {
let mut settings = AgentSettings::default();
for value in sources.defaults_and_customizations() {
- if value.is_version_outdated() {
- settings.using_outdated_settings_version = true;
- }
-
- let value = value.upgrade();
merge(&mut settings.enabled, value.enabled);
merge(&mut settings.button, value.button);
merge(&mut settings.dock, value.dock);
@@ -869,17 +411,23 @@ impl Settings for AgentSettings {
&mut settings.default_height,
value.default_height.map(Into::into),
);
- merge(&mut settings.default_model, value.default_model);
+ merge(&mut settings.default_model, value.default_model.clone());
settings.inline_assistant_model = value
.inline_assistant_model
+ .clone()
.or(settings.inline_assistant_model.take());
settings.commit_message_model = value
+ .clone()
.commit_message_model
.or(settings.commit_message_model.take());
settings.thread_summary_model = value
+ .clone()
.thread_summary_model
.or(settings.thread_summary_model.take());
- merge(&mut settings.inline_alternatives, value.inline_alternatives);
+ merge(
+ &mut settings.inline_alternatives,
+ value.inline_alternatives.clone(),
+ );
merge(
&mut settings.always_allow_tool_actions,
value.always_allow_tool_actions,
@@ -894,7 +442,7 @@ impl Settings for AgentSettings {
);
merge(&mut settings.stream_edits, value.stream_edits);
merge(&mut settings.single_file_review, value.single_file_review);
- merge(&mut settings.default_profile, value.default_profile);
+ merge(&mut settings.default_profile, value.default_profile.clone());
merge(&mut settings.default_view, value.default_view);
merge(
&mut settings.preferred_completion_mode,
@@ -906,24 +454,24 @@ impl Settings for AgentSettings {
.model_parameters
.extend_from_slice(&value.model_parameters);
- if let Some(profiles) = value.profiles {
+ if let Some(profiles) = value.profiles.as_ref() {
settings
.profiles
.extend(profiles.into_iter().map(|(id, profile)| {
(
- id,
+ id.clone(),
AgentProfileSettings {
- name: profile.name.into(),
- tools: profile.tools,
+ name: profile.name.clone().into(),
+ tools: profile.tools.clone(),
enable_all_context_servers: profile
.enable_all_context_servers
.unwrap_or_default(),
context_servers: profile
.context_servers
- .into_iter()
+ .iter()
.map(|(context_server_id, preset)| {
(
- context_server_id,
+ context_server_id.clone(),
ContextServerPreset {
tools: preset.tools.clone(),
},
@@ -944,28 +492,8 @@ impl Settings for AgentSettings {
.read_value("chat.agent.enabled")
.and_then(|b| b.as_bool())
{
- match &mut current.inner {
- Some(AgentSettingsContentInner::Versioned(versioned)) => match versioned.as_mut() {
- VersionedAgentSettingsContent::V1(setting) => {
- setting.enabled = Some(b);
- setting.button = Some(b);
- }
-
- VersionedAgentSettingsContent::V2(setting) => {
- setting.enabled = Some(b);
- setting.button = Some(b);
- }
- },
- Some(AgentSettingsContentInner::Legacy(setting)) => setting.button = Some(b),
- None => {
- current.inner =
- Some(AgentSettingsContentInner::for_v2(AgentSettingsContentV2 {
- enabled: Some(b),
- button: Some(b),
- ..Default::default()
- }));
- }
- }
+ current.enabled = Some(b);
+ current.button = Some(b);
}
}
}
@@ -975,149 +503,3 @@ fn merge(target: &mut T, value: Option) {
*target = value;
}
}
-
-#[cfg(test)]
-mod tests {
- use fs::Fs;
- use gpui::{ReadGlobal, TestAppContext};
- use settings::SettingsStore;
-
- use super::*;
-
- #[gpui::test]
- async fn test_deserialize_agent_settings_with_version(cx: &mut TestAppContext) {
- let fs = fs::FakeFs::new(cx.executor().clone());
- fs.create_dir(paths::settings_file().parent().unwrap())
- .await
- .unwrap();
-
- cx.update(|cx| {
- let test_settings = settings::SettingsStore::test(cx);
- cx.set_global(test_settings);
- AgentSettings::register(cx);
- });
-
- cx.update(|cx| {
- assert!(!AgentSettings::get_global(cx).using_outdated_settings_version);
- assert_eq!(
- AgentSettings::get_global(cx).default_model,
- LanguageModelSelection {
- provider: "zed.dev".into(),
- model: "claude-sonnet-4".into(),
- }
- );
- });
-
- cx.update(|cx| {
- settings::SettingsStore::global(cx).update_settings_file::(
- fs.clone(),
- |settings, _| {
- *settings = AgentSettingsContent {
- inner: Some(AgentSettingsContentInner::for_v2(AgentSettingsContentV2 {
- default_model: Some(LanguageModelSelection {
- provider: "test-provider".into(),
- model: "gpt-99".into(),
- }),
- inline_assistant_model: None,
- commit_message_model: None,
- thread_summary_model: None,
- inline_alternatives: None,
- enabled: None,
- button: None,
- dock: None,
- default_width: None,
- default_height: None,
- default_profile: None,
- default_view: None,
- profiles: None,
- always_allow_tool_actions: None,
- play_sound_when_agent_done: None,
- notify_when_agent_waiting: None,
- stream_edits: None,
- single_file_review: None,
- enable_feedback: None,
- model_parameters: Vec::new(),
- preferred_completion_mode: None,
- })),
- }
- },
- );
- });
-
- cx.run_until_parked();
-
- let raw_settings_value = fs.load(paths::settings_file()).await.unwrap();
- assert!(raw_settings_value.contains(r#""version": "2""#));
-
- #[derive(Debug, Deserialize)]
- struct AgentSettingsTest {
- agent: AgentSettingsContent,
- }
-
- let agent_settings: AgentSettingsTest =
- serde_json_lenient::from_str(&raw_settings_value).unwrap();
-
- assert!(!agent_settings.agent.is_version_outdated());
- }
-
- #[gpui::test]
- async fn test_load_settings_from_old_key(cx: &mut TestAppContext) {
- let fs = fs::FakeFs::new(cx.executor().clone());
- fs.create_dir(paths::settings_file().parent().unwrap())
- .await
- .unwrap();
-
- cx.update(|cx| {
- let mut test_settings = settings::SettingsStore::test(cx);
- let user_settings_content = r#"{
- "assistant": {
- "enabled": true,
- "version": "2",
- "default_model": {
- "provider": "zed.dev",
- "model": "gpt-99"
- },
- }}"#;
- test_settings
- .set_user_settings(user_settings_content, cx)
- .unwrap();
- cx.set_global(test_settings);
- AgentSettings::register(cx);
- });
-
- cx.run_until_parked();
-
- let agent_settings = cx.update(|cx| AgentSettings::get_global(cx).clone());
- assert!(agent_settings.enabled);
- assert!(!agent_settings.using_outdated_settings_version);
- assert_eq!(agent_settings.default_model.model, "gpt-99");
-
- cx.update_global::(|settings_store, cx| {
- settings_store.update_user_settings::(cx, |settings| {
- *settings = AgentSettingsContent {
- inner: Some(AgentSettingsContentInner::for_v2(AgentSettingsContentV2 {
- enabled: Some(false),
- default_model: Some(LanguageModelSelection {
- provider: "xai".to_owned().into(),
- model: "grok".to_owned(),
- }),
- ..Default::default()
- })),
- };
- });
- });
-
- cx.run_until_parked();
-
- let settings = cx.update(|cx| SettingsStore::global(cx).raw_user_settings().clone());
-
- #[derive(Debug, Deserialize)]
- struct AgentSettingsTest {
- assistant: AgentSettingsContent,
- agent: Option,
- }
-
- let agent_settings: AgentSettingsTest = serde_json::from_value(settings).unwrap();
- assert!(agent_settings.agent.is_none());
- }
-}
diff --git a/crates/agent_ui/src/active_thread.rs b/crates/agent_ui/src/active_thread.rs
index 8df1c88e8a57615d11f43b8098538130a8fafc24..0e7ca9aa897d1962742e660d2d29e43f8dfe6593 100644
--- a/crates/agent_ui/src/active_thread.rs
+++ b/crates/agent_ui/src/active_thread.rs
@@ -809,7 +809,12 @@ impl ActiveThread {
};
for message in thread.read(cx).messages().cloned().collect::>() {
- this.push_message(&message.id, &message.segments, window, cx);
+ let rendered_message = RenderedMessage::from_segments(
+ &message.segments,
+ this.language_registry.clone(),
+ cx,
+ );
+ this.push_rendered_message(message.id, rendered_message);
for tool_use in thread.read(cx).tool_uses_for_message(message.id, cx) {
this.render_tool_use_markdown(
@@ -875,36 +880,11 @@ impl ActiveThread {
&self.text_thread_store
}
- fn push_message(
- &mut self,
- id: &MessageId,
- segments: &[MessageSegment],
- _window: &mut Window,
- cx: &mut Context,
- ) {
+ fn push_rendered_message(&mut self, id: MessageId, rendered_message: RenderedMessage) {
let old_len = self.messages.len();
- self.messages.push(*id);
+ self.messages.push(id);
self.list_state.splice(old_len..old_len, 1);
-
- let rendered_message =
- RenderedMessage::from_segments(segments, self.language_registry.clone(), cx);
- self.rendered_messages_by_id.insert(*id, rendered_message);
- }
-
- fn edited_message(
- &mut self,
- id: &MessageId,
- segments: &[MessageSegment],
- _window: &mut Window,
- cx: &mut Context,
- ) {
- let Some(index) = self.messages.iter().position(|message_id| message_id == id) else {
- return;
- };
- self.list_state.splice(index..index + 1, 1);
- let rendered_message =
- RenderedMessage::from_segments(segments, self.language_registry.clone(), cx);
- self.rendered_messages_by_id.insert(*id, rendered_message);
+ self.rendered_messages_by_id.insert(id, rendered_message);
}
fn deleted_message(&mut self, id: &MessageId) {
@@ -1037,31 +1017,43 @@ impl ActiveThread {
}
}
ThreadEvent::MessageAdded(message_id) => {
- if let Some(message_segments) = self
- .thread
- .read(cx)
- .message(*message_id)
- .map(|message| message.segments.clone())
- {
- self.push_message(message_id, &message_segments, window, cx);
+ if let Some(rendered_message) = self.thread.update(cx, |thread, cx| {
+ thread.message(*message_id).map(|message| {
+ RenderedMessage::from_segments(
+ &message.segments,
+ self.language_registry.clone(),
+ cx,
+ )
+ })
+ }) {
+ self.push_rendered_message(*message_id, rendered_message);
}
self.save_thread(cx);
cx.notify();
}
ThreadEvent::MessageEdited(message_id) => {
- if let Some(message_segments) = self
- .thread
- .read(cx)
- .message(*message_id)
- .map(|message| message.segments.clone())
- {
- self.edited_message(message_id, &message_segments, window, cx);
+ if let Some(index) = self.messages.iter().position(|id| id == message_id) {
+ if let Some(rendered_message) = self.thread.update(cx, |thread, cx| {
+ thread.message(*message_id).map(|message| {
+ let mut rendered_message = RenderedMessage {
+ language_registry: self.language_registry.clone(),
+ segments: Vec::with_capacity(message.segments.len()),
+ };
+ for segment in &message.segments {
+ rendered_message.push_segment(segment, cx);
+ }
+ rendered_message
+ })
+ }) {
+ self.list_state.splice(index..index + 1, 1);
+ self.rendered_messages_by_id
+ .insert(*message_id, rendered_message);
+ self.scroll_to_bottom(cx);
+ self.save_thread(cx);
+ cx.notify();
+ }
}
-
- self.scroll_to_bottom(cx);
- self.save_thread(cx);
- cx.notify();
}
ThreadEvent::MessageDeleted(message_id) => {
self.deleted_message(message_id);
@@ -1311,17 +1303,11 @@ impl ActiveThread {
fn start_editing_message(
&mut self,
message_id: MessageId,
- message_segments: &[MessageSegment],
+ message_text: impl Into>,
message_creases: &[MessageCrease],
window: &mut Window,
cx: &mut Context,
) {
- // User message should always consist of a single text segment,
- // therefore we can skip returning early if it's not a text segment.
- let Some(MessageSegment::Text(message_text)) = message_segments.first() else {
- return;
- };
-
let editor = crate::message_editor::create_editor(
self.workspace.clone(),
self.context_store.downgrade(),
@@ -1333,7 +1319,7 @@ impl ActiveThread {
cx,
);
editor.update(cx, |editor, cx| {
- editor.set_text(message_text.clone(), window, cx);
+ editor.set_text(message_text, window, cx);
insert_message_creases(editor, message_creases, &self.context_store, window, cx);
editor.focus_handle(cx).focus(window);
editor.move_to_end(&editor::actions::MoveToEnd, window, cx);
@@ -1828,8 +1814,6 @@ impl ActiveThread {
return div().children(loading_dots).into_any();
}
- let message_creases = message.creases.clone();
-
let Some(rendered_message) = self.rendered_messages_by_id.get(&message_id) else {
return Empty.into_any();
};
@@ -2144,15 +2128,30 @@ impl ActiveThread {
}),
)
.on_click(cx.listener({
- let message_segments = message.segments.clone();
+ let message_creases = message.creases.clone();
move |this, _, window, cx| {
- this.start_editing_message(
- message_id,
- &message_segments,
- &message_creases,
- window,
- cx,
- );
+ if let Some(message_text) =
+ this.thread.read(cx).message(message_id).and_then(|message| {
+ message.segments.first().and_then(|segment| {
+ match segment {
+ MessageSegment::Text(message_text) => {
+ Some(Into::>::into(message_text.as_str()))
+ }
+ _ => {
+ None
+ }
+ }
+ })
+ })
+ {
+ this.start_editing_message(
+ message_id,
+ message_text,
+ &message_creases,
+ window,
+ cx,
+ );
+ }
}
})),
),
@@ -3826,13 +3825,15 @@ mod tests {
});
active_thread.update_in(cx, |active_thread, window, cx| {
- active_thread.start_editing_message(
- message.id,
- message.segments.as_slice(),
- message.creases.as_slice(),
- window,
- cx,
- );
+ if let Some(message_text) = message.segments.first().and_then(MessageSegment::text) {
+ active_thread.start_editing_message(
+ message.id,
+ message_text,
+ message.creases.as_slice(),
+ window,
+ cx,
+ );
+ }
let editor = active_thread
.editing_message
.as_ref()
@@ -3847,13 +3848,15 @@ mod tests {
let message = thread.update(cx, |thread, _| thread.message(message.id).cloned().unwrap());
active_thread.update_in(cx, |active_thread, window, cx| {
- active_thread.start_editing_message(
- message.id,
- message.segments.as_slice(),
- message.creases.as_slice(),
- window,
- cx,
- );
+ if let Some(message_text) = message.segments.first().and_then(MessageSegment::text) {
+ active_thread.start_editing_message(
+ message.id,
+ message_text,
+ message.creases.as_slice(),
+ window,
+ cx,
+ );
+ }
let editor = active_thread
.editing_message
.as_ref()
@@ -3935,13 +3938,15 @@ mod tests {
// Edit the message while the completion is still running
active_thread.update_in(cx, |active_thread, window, cx| {
- active_thread.start_editing_message(
- message.id,
- message.segments.as_slice(),
- message.creases.as_slice(),
- window,
- cx,
- );
+ if let Some(message_text) = message.segments.first().and_then(MessageSegment::text) {
+ active_thread.start_editing_message(
+ message.id,
+ message_text,
+ message.creases.as_slice(),
+ window,
+ cx,
+ );
+ }
let editor = active_thread
.editing_message
.as_ref()
diff --git a/crates/agent_ui/src/agent_configuration.rs b/crates/agent_ui/src/agent_configuration.rs
index 1c12e51e2ddf4068f4f341089e3a084c5cf7a51f..e91a0f7ebe590d1f0480741f6eec3ebda220ccea 100644
--- a/crates/agent_ui/src/agent_configuration.rs
+++ b/crates/agent_ui/src/agent_configuration.rs
@@ -940,15 +940,56 @@ fn show_unable_to_uninstall_extension_with_context_server(
id: ContextServerId,
cx: &mut App,
) {
+ let workspace_handle = workspace.weak_handle();
+ let context_server_id = id.clone();
+
let status_toast = StatusToast::new(
format!(
- "Unable to uninstall the {} extension, as it provides more than just the MCP server.",
+ "The {} extension provides more than just the MCP server. Proceed to uninstall anyway?",
id.0
),
cx,
- |this, _cx| {
+ move |this, _cx| {
+ let workspace_handle = workspace_handle.clone();
+ let context_server_id = context_server_id.clone();
+
this.icon(ToastIcon::new(IconName::Warning).color(Color::Warning))
- .action("Dismiss", |_, _| {})
+ .dismiss_button(true)
+ .action("Uninstall", move |_, _cx| {
+ if let Some((extension_id, _)) =
+ resolve_extension_for_context_server(&context_server_id, _cx)
+ {
+ ExtensionStore::global(_cx).update(_cx, |store, cx| {
+ store
+ .uninstall_extension(extension_id, cx)
+ .detach_and_log_err(cx);
+ });
+
+ workspace_handle
+ .update(_cx, |workspace, cx| {
+ let fs = workspace.app_state().fs.clone();
+ cx.spawn({
+ let context_server_id = context_server_id.clone();
+ async move |_workspace_handle, cx| {
+ cx.update(|cx| {
+ update_settings_file::(
+ fs,
+ cx,
+ move |settings, _| {
+ settings
+ .context_servers
+ .remove(&context_server_id.0);
+ },
+ );
+ })?;
+ anyhow::Ok(())
+ }
+ })
+ .detach_and_log_err(cx);
+ })
+ .log_err();
+ }
+ })
},
);
diff --git a/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs b/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs
index 6a0bd765c7969b910b321826c0ca44dc92fd82a9..30fad51cfcbc100bdf469278c0210a220c7e2833 100644
--- a/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs
+++ b/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs
@@ -295,10 +295,7 @@ impl ConfigureContextServerModal {
ContextServerDescriptorRegistry::default_global(cx)
.read(cx)
.context_server_descriptor(&server_id.0)
- .map(|_| ContextServerSettings::Extension {
- enabled: true,
- settings: serde_json::json!({}),
- })
+ .map(|_| ContextServerSettings::default_extension())
})
else {
return Task::ready(Err(anyhow::anyhow!("Context server not found")));
diff --git a/crates/agent_ui/src/agent_configuration/tool_picker.rs b/crates/agent_ui/src/agent_configuration/tool_picker.rs
index 7c3d20457e2b9138e49f3c61e867b2f15b54bb84..8f1e0d71c0bd8ef56a71c1a88db1bf67929b060c 100644
--- a/crates/agent_ui/src/agent_configuration/tool_picker.rs
+++ b/crates/agent_ui/src/agent_configuration/tool_picker.rs
@@ -272,42 +272,35 @@ impl PickerDelegate for ToolPickerDelegate {
let server_id = server_id.clone();
let tool_name = tool_name.clone();
move |settings: &mut AgentSettingsContent, _cx| {
- settings
- .v2_setting(|v2_settings| {
- let profiles = v2_settings.profiles.get_or_insert_default();
- let profile =
- profiles
- .entry(profile_id)
- .or_insert_with(|| AgentProfileContent {
- name: default_profile.name.into(),
- tools: default_profile.tools,
- enable_all_context_servers: Some(
- default_profile.enable_all_context_servers,
- ),
- context_servers: default_profile
- .context_servers
- .into_iter()
- .map(|(server_id, preset)| {
- (
- server_id,
- ContextServerPresetContent {
- tools: preset.tools,
- },
- )
- })
- .collect(),
- });
-
- if let Some(server_id) = server_id {
- let preset = profile.context_servers.entry(server_id).or_default();
- *preset.tools.entry(tool_name).or_default() = !is_currently_enabled;
- } else {
- *profile.tools.entry(tool_name).or_default() = !is_currently_enabled;
- }
-
- Ok(())
- })
- .ok();
+ let profiles = settings.profiles.get_or_insert_default();
+ let profile = profiles
+ .entry(profile_id)
+ .or_insert_with(|| AgentProfileContent {
+ name: default_profile.name.into(),
+ tools: default_profile.tools,
+ enable_all_context_servers: Some(
+ default_profile.enable_all_context_servers,
+ ),
+ context_servers: default_profile
+ .context_servers
+ .into_iter()
+ .map(|(server_id, preset)| {
+ (
+ server_id,
+ ContextServerPresetContent {
+ tools: preset.tools,
+ },
+ )
+ })
+ .collect(),
+ });
+
+ if let Some(server_id) = server_id {
+ let preset = profile.context_servers.entry(server_id).or_default();
+ *preset.tools.entry(tool_name).or_default() = !is_currently_enabled;
+ } else {
+ *profile.tools.entry(tool_name).or_default() = !is_currently_enabled;
+ }
}
});
}
diff --git a/crates/agent_ui/src/agent_ui.rs b/crates/agent_ui/src/agent_ui.rs
index a1439620b62208b5778671836655acba141c40dd..4babe4f676054740ea88645235ccbcb834d3fc18 100644
--- a/crates/agent_ui/src/agent_ui.rs
+++ b/crates/agent_ui/src/agent_ui.rs
@@ -48,7 +48,7 @@ pub use crate::agent_panel::{AgentPanel, ConcreteAssistantPanelDelegate};
pub use crate::inline_assistant::InlineAssistant;
use crate::slash_command_settings::SlashCommandSettings;
pub use agent_diff::{AgentDiffPane, AgentDiffToolbar};
-pub use text_thread_editor::AgentPanelDelegate;
+pub use text_thread_editor::{AgentPanelDelegate, TextThreadEditor};
pub use ui::preview::{all_agent_previews, get_agent_preview};
actions!(
@@ -157,6 +157,7 @@ pub fn init(
agent::init(cx);
agent_panel::init(cx);
context_server_configuration::init(language_registry.clone(), fs.clone(), cx);
+ TextThreadEditor::init(cx);
register_slash_commands(cx);
inline_assistant::init(
diff --git a/crates/assistant_context/src/assistant_context.rs b/crates/assistant_context/src/assistant_context.rs
index 1444701aac98e048e67468f420d0fa6512013824..cef9d2f0fd60c842883fcff80766416ca3db66de 100644
--- a/crates/assistant_context/src/assistant_context.rs
+++ b/crates/assistant_context/src/assistant_context.rs
@@ -2117,6 +2117,7 @@ impl AssistantContext {
);
}
}
+ LanguageModelCompletionEvent::RedactedThinking { .. } => {},
LanguageModelCompletionEvent::Text(mut chunk) => {
if let Some(start) = thought_process_stack.pop() {
let end = buffer.anchor_before(message_old_end_offset);
@@ -2522,6 +2523,12 @@ impl AssistantContext {
}
let message = start_message;
+ let at_end = range.end >= message.offset_range.end.saturating_sub(1);
+ let role_after = if range.start == range.end || at_end {
+ Role::User
+ } else {
+ message.role
+ };
let role = message.role;
let mut edited_buffer = false;
@@ -2556,7 +2563,7 @@ impl AssistantContext {
};
let suffix_metadata = MessageMetadata {
- role,
+ role: role_after,
status: MessageStatus::Done,
timestamp: suffix.id.0,
cache: None,
diff --git a/crates/assistant_tools/src/edit_agent/evals.rs b/crates/assistant_tools/src/edit_agent/evals.rs
index 116654e38276ce677d54380155ee0e6d93a15fa9..7beb2ec9190c4e6e65ed7d48211328dc51073ea4 100644
--- a/crates/assistant_tools/src/edit_agent/evals.rs
+++ b/crates/assistant_tools/src/edit_agent/evals.rs
@@ -1470,7 +1470,7 @@ impl EditAgentTest {
Project::init_settings(cx);
language::init(cx);
language_model::init(client.clone(), cx);
- language_models::init(user_store.clone(), client.clone(), fs.clone(), cx);
+ language_models::init(user_store.clone(), client.clone(), cx);
crate::init(client.http_client(), cx);
});
diff --git a/crates/assistant_tools/src/edit_agent/evals/fixtures/disable_cursor_blinking/before.rs b/crates/assistant_tools/src/edit_agent/evals/fixtures/disable_cursor_blinking/before.rs
index 607daa8ce3a129e0f4bc53a00d1a62f479da3932..a070738b600f041cbd6b3cc8ad1e8a6462b1d85a 100644
--- a/crates/assistant_tools/src/edit_agent/evals/fixtures/disable_cursor_blinking/before.rs
+++ b/crates/assistant_tools/src/edit_agent/evals/fixtures/disable_cursor_blinking/before.rs
@@ -9132,7 +9132,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| lines.sort())
+ self.manipulate_immutable_lines(window, cx, |lines| lines.sort())
}
pub fn sort_lines_case_insensitive(
@@ -9141,7 +9141,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| {
+ self.manipulate_immutable_lines(window, cx, |lines| {
lines.sort_by_key(|line| line.to_lowercase())
})
}
@@ -9152,7 +9152,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| {
+ self.manipulate_immutable_lines(window, cx, |lines| {
let mut seen = HashSet::default();
lines.retain(|line| seen.insert(line.to_lowercase()));
})
@@ -9164,7 +9164,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| {
+ self.manipulate_immutable_lines(window, cx, |lines| {
let mut seen = HashSet::default();
lines.retain(|line| seen.insert(*line));
})
@@ -9606,20 +9606,20 @@ impl Editor {
}
pub fn reverse_lines(&mut self, _: &ReverseLines, window: &mut Window, cx: &mut Context) {
- self.manipulate_lines(window, cx, |lines| lines.reverse())
+ self.manipulate_immutable_lines(window, cx, |lines| lines.reverse())
}
pub fn shuffle_lines(&mut self, _: &ShuffleLines, window: &mut Window, cx: &mut Context) {
- self.manipulate_lines(window, cx, |lines| lines.shuffle(&mut thread_rng()))
+ self.manipulate_immutable_lines(window, cx, |lines| lines.shuffle(&mut thread_rng()))
}
- fn manipulate_lines(
+ fn manipulate_lines(
&mut self,
window: &mut Window,
cx: &mut Context,
- mut callback: Fn,
+ mut manipulate: M,
) where
- Fn: FnMut(&mut Vec<&str>),
+ M: FnMut(&str) -> LineManipulationResult,
{
self.hide_mouse_cursor(&HideMouseCursorOrigin::TypingAction);
@@ -9652,18 +9652,14 @@ impl Editor {
.text_for_range(start_point..end_point)
.collect::();
- let mut lines = text.split('\n').collect_vec();
+ let LineManipulationResult { new_text, line_count_before, line_count_after} = manipulate(&text);
- let lines_before = lines.len();
- callback(&mut lines);
- let lines_after = lines.len();
-
- edits.push((start_point..end_point, lines.join("\n")));
+ edits.push((start_point..end_point, new_text));
// Selections must change based on added and removed line count
let start_row =
MultiBufferRow(start_point.row + added_lines as u32 - removed_lines as u32);
- let end_row = MultiBufferRow(start_row.0 + lines_after.saturating_sub(1) as u32);
+ let end_row = MultiBufferRow(start_row.0 + line_count_after.saturating_sub(1) as u32);
new_selections.push(Selection {
id: selection.id,
start: start_row,
@@ -9672,10 +9668,10 @@ impl Editor {
reversed: selection.reversed,
});
- if lines_after > lines_before {
- added_lines += lines_after - lines_before;
- } else if lines_before > lines_after {
- removed_lines += lines_before - lines_after;
+ if line_count_after > line_count_before {
+ added_lines += line_count_after - line_count_before;
+ } else if line_count_before > line_count_after {
+ removed_lines += line_count_before - line_count_after;
}
}
@@ -9720,6 +9716,171 @@ impl Editor {
})
}
+ fn manipulate_immutable_lines(
+ &mut self,
+ window: &mut Window,
+ cx: &mut Context,
+ mut callback: Fn,
+ ) where
+ Fn: FnMut(&mut Vec<&str>),
+ {
+ self.manipulate_lines(window, cx, |text| {
+ let mut lines: Vec<&str> = text.split('\n').collect();
+ let line_count_before = lines.len();
+
+ callback(&mut lines);
+
+ LineManipulationResult {
+ new_text: lines.join("\n"),
+ line_count_before,
+ line_count_after: lines.len(),
+ }
+ });
+ }
+
+ fn manipulate_mutable_lines(
+ &mut self,
+ window: &mut Window,
+ cx: &mut Context,
+ mut callback: Fn,
+ ) where
+ Fn: FnMut(&mut Vec>),
+ {
+ self.manipulate_lines(window, cx, |text| {
+ let mut lines: Vec> = text.split('\n').map(Cow::from).collect();
+ let line_count_before = lines.len();
+
+ callback(&mut lines);
+
+ LineManipulationResult {
+ new_text: lines.join("\n"),
+ line_count_before,
+ line_count_after: lines.len(),
+ }
+ });
+ }
+
+ pub fn convert_indentation_to_spaces(
+ &mut self,
+ _: &ConvertIndentationToSpaces,
+ window: &mut Window,
+ cx: &mut Context,
+ ) {
+ let settings = self.buffer.read(cx).language_settings(cx);
+ let tab_size = settings.tab_size.get() as usize;
+
+ self.manipulate_mutable_lines(window, cx, |lines| {
+ // Allocates a reasonably sized scratch buffer once for the whole loop
+ let mut reindented_line = String::with_capacity(MAX_LINE_LEN);
+ // Avoids recomputing spaces that could be inserted many times
+ let space_cache: Vec> = (1..=tab_size)
+ .map(|n| IndentSize::spaces(n as u32).chars().collect())
+ .collect();
+
+ for line in lines.iter_mut().filter(|line| !line.is_empty()) {
+ let mut chars = line.as_ref().chars();
+ let mut col = 0;
+ let mut changed = false;
+
+ while let Some(ch) = chars.next() {
+ match ch {
+ ' ' => {
+ reindented_line.push(' ');
+ col += 1;
+ }
+ '\t' => {
+ // \t are converted to spaces depending on the current column
+ let spaces_len = tab_size - (col % tab_size);
+ reindented_line.extend(&space_cache[spaces_len - 1]);
+ col += spaces_len;
+ changed = true;
+ }
+ _ => {
+ // If we dont append before break, the character is consumed
+ reindented_line.push(ch);
+ break;
+ }
+ }
+ }
+
+ if !changed {
+ reindented_line.clear();
+ continue;
+ }
+ // Append the rest of the line and replace old reference with new one
+ reindented_line.extend(chars);
+ *line = Cow::Owned(reindented_line.clone());
+ reindented_line.clear();
+ }
+ });
+ }
+
+ pub fn convert_indentation_to_tabs(
+ &mut self,
+ _: &ConvertIndentationToTabs,
+ window: &mut Window,
+ cx: &mut Context,
+ ) {
+ let settings = self.buffer.read(cx).language_settings(cx);
+ let tab_size = settings.tab_size.get() as usize;
+
+ self.manipulate_mutable_lines(window, cx, |lines| {
+ // Allocates a reasonably sized buffer once for the whole loop
+ let mut reindented_line = String::with_capacity(MAX_LINE_LEN);
+ // Avoids recomputing spaces that could be inserted many times
+ let space_cache: Vec> = (1..=tab_size)
+ .map(|n| IndentSize::spaces(n as u32).chars().collect())
+ .collect();
+
+ for line in lines.iter_mut().filter(|line| !line.is_empty()) {
+ let mut chars = line.chars();
+ let mut spaces_count = 0;
+ let mut first_non_indent_char = None;
+ let mut changed = false;
+
+ while let Some(ch) = chars.next() {
+ match ch {
+ ' ' => {
+ // Keep track of spaces. Append \t when we reach tab_size
+ spaces_count += 1;
+ changed = true;
+ if spaces_count == tab_size {
+ reindented_line.push('\t');
+ spaces_count = 0;
+ }
+ }
+ '\t' => {
+ reindented_line.push('\t');
+ spaces_count = 0;
+ }
+ _ => {
+ // Dont append it yet, we might have remaining spaces
+ first_non_indent_char = Some(ch);
+ break;
+ }
+ }
+ }
+
+ if !changed {
+ reindented_line.clear();
+ continue;
+ }
+ // Remaining spaces that didn't make a full tab stop
+ if spaces_count > 0 {
+ reindented_line.extend(&space_cache[spaces_count - 1]);
+ }
+ // If we consume an extra character that was not indentation, add it back
+ if let Some(extra_char) = first_non_indent_char {
+ reindented_line.push(extra_char);
+ }
+ // Append the rest of the line and replace old reference with new one
+ reindented_line.extend(chars);
+ *line = Cow::Owned(reindented_line.clone());
+ reindented_line.clear();
+ }
+ });
+ }
+
pub fn convert_to_upper_case(
&mut self,
_: &ConvertToUpperCase,
@@ -21157,6 +21318,13 @@ pub struct LineHighlight {
pub type_id: Option,
}
+struct LineManipulationResult {
+ pub new_text: String,
+ pub line_count_before: usize,
+ pub line_count_after: usize,
+}
+
+
fn render_diff_hunk_controls(
row: u32,
status: &DiffHunkStatus,
diff --git a/crates/auto_update_ui/src/auto_update_ui.rs b/crates/auto_update_ui/src/auto_update_ui.rs
index 25d64bc3e8245a446c1f55fa31a506d40f3e9bd9..30c1cddec2935d82f2ecc9fe0cfc569999d80d7b 100644
--- a/crates/auto_update_ui/src/auto_update_ui.rs
+++ b/crates/auto_update_ui/src/auto_update_ui.rs
@@ -132,6 +132,11 @@ pub fn notify_if_app_was_updated(cx: &mut App) {
let Some(updater) = AutoUpdater::get(cx) else {
return;
};
+
+ if let ReleaseChannel::Nightly = ReleaseChannel::global(cx) {
+ return;
+ }
+
let should_show_notification = updater.read(cx).should_show_update_notification(cx);
cx.spawn(async move |cx| {
let should_show_notification = should_show_notification.await?;
diff --git a/crates/bedrock/src/models.rs b/crates/bedrock/src/models.rs
index 272ac0e52c4123fe864a5c12b80111657c9078a3..b6eeafa2d6b273a8cc3f0c6cc7a18ea0589c4ba2 100644
--- a/crates/bedrock/src/models.rs
+++ b/crates/bedrock/src/models.rs
@@ -11,6 +11,13 @@ pub enum BedrockModelMode {
},
}
+#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
+pub struct BedrockModelCacheConfiguration {
+ pub max_cache_anchors: usize,
+ pub min_total_token: u64,
+}
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, EnumIter)]
pub enum Model {
@@ -104,6 +111,7 @@ pub enum Model {
display_name: Option,
max_output_tokens: Option,
default_temperature: Option,
+ cache_configuration: Option,
},
}
@@ -401,6 +409,56 @@ impl Model {
}
}
+ pub fn supports_caching(&self) -> bool {
+ match self {
+ // Only Claude models on Bedrock support caching
+ // Nova models support only text caching
+ // https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models
+ Self::Claude3_5Haiku
+ | Self::Claude3_7Sonnet
+ | Self::Claude3_7SonnetThinking
+ | Self::ClaudeSonnet4
+ | Self::ClaudeSonnet4Thinking
+ | Self::ClaudeOpus4
+ | Self::ClaudeOpus4Thinking => true,
+
+ // Custom models - check if they have cache configuration
+ Self::Custom {
+ cache_configuration,
+ ..
+ } => cache_configuration.is_some(),
+
+ // All other models don't support caching
+ _ => false,
+ }
+ }
+
+ pub fn cache_configuration(&self) -> Option {
+ match self {
+ Self::Claude3_7Sonnet
+ | Self::Claude3_7SonnetThinking
+ | Self::ClaudeSonnet4
+ | Self::ClaudeSonnet4Thinking
+ | Self::ClaudeOpus4
+ | Self::ClaudeOpus4Thinking => Some(BedrockModelCacheConfiguration {
+ max_cache_anchors: 4,
+ min_total_token: 1024,
+ }),
+
+ Self::Claude3_5Haiku => Some(BedrockModelCacheConfiguration {
+ max_cache_anchors: 4,
+ min_total_token: 2048,
+ }),
+
+ Self::Custom {
+ cache_configuration,
+ ..
+ } => cache_configuration.clone(),
+
+ _ => None,
+ }
+ }
+
pub fn mode(&self) -> BedrockModelMode {
match self {
Model::Claude3_7SonnetThinking => BedrockModelMode::Thinking {
@@ -660,6 +718,7 @@ mod tests {
display_name: Some("My Custom Model".to_string()),
max_output_tokens: Some(8192),
default_temperature: Some(0.7),
+ cache_configuration: None,
};
// Custom model should return its name unchanged
diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs
index 6b84ca998ec4b8225a3304b267385e41c88f2def..22daab491c499bf568f155cd6e049868c58192ce 100644
--- a/crates/collab/src/rpc.rs
+++ b/crates/collab/src/rpc.rs
@@ -2008,6 +2008,7 @@ async fn join_project(
session.connection_id,
proto::UpdateLanguageServer {
project_id: project_id.to_proto(),
+ server_name: Some(language_server.name.clone()),
language_server_id: language_server.id,
variant: Some(
proto::update_language_server::Variant::DiskBasedDiagnosticsUpdated(
diff --git a/crates/collab/src/stripe_billing.rs b/crates/collab/src/stripe_billing.rs
index 68f8fa5042e8fb491509ac59d6377868c6b48c10..8bf6c08158b9fa742f0f9e59711c7df80013614d 100644
--- a/crates/collab/src/stripe_billing.rs
+++ b/crates/collab/src/stripe_billing.rs
@@ -11,13 +11,14 @@ use crate::Result;
use crate::db::billing_subscription::SubscriptionKind;
use crate::llm::AGENT_EXTENDED_TRIAL_FEATURE_FLAG;
use crate::stripe_client::{
- RealStripeClient, StripeCheckoutSessionMode, StripeCheckoutSessionPaymentMethodCollection,
- StripeClient, StripeCreateCheckoutSessionLineItems, StripeCreateCheckoutSessionParams,
+ RealStripeClient, StripeBillingAddressCollection, StripeCheckoutSessionMode,
+ StripeCheckoutSessionPaymentMethodCollection, StripeClient,
+ StripeCreateCheckoutSessionLineItems, StripeCreateCheckoutSessionParams,
StripeCreateCheckoutSessionSubscriptionData, StripeCreateMeterEventParams,
StripeCreateMeterEventPayload, StripeCreateSubscriptionItems, StripeCreateSubscriptionParams,
- StripeCustomerId, StripeMeter, StripePrice, StripePriceId, StripeSubscription,
- StripeSubscriptionId, StripeSubscriptionTrialSettings,
- StripeSubscriptionTrialSettingsEndBehavior,
+ StripeCustomerId, StripeCustomerUpdate, StripeCustomerUpdateAddress, StripeCustomerUpdateName,
+ StripeMeter, StripePrice, StripePriceId, StripeSubscription, StripeSubscriptionId,
+ StripeSubscriptionTrialSettings, StripeSubscriptionTrialSettingsEndBehavior,
StripeSubscriptionTrialSettingsEndBehaviorMissingPaymentMethod, UpdateSubscriptionItems,
UpdateSubscriptionParams,
};
@@ -245,6 +246,12 @@ impl StripeBilling {
quantity: Some(1),
}]);
params.success_url = Some(success_url);
+ params.billing_address_collection = Some(StripeBillingAddressCollection::Required);
+ params.customer_update = Some(StripeCustomerUpdate {
+ address: Some(StripeCustomerUpdateAddress::Auto),
+ name: Some(StripeCustomerUpdateName::Auto),
+ shipping: None,
+ });
let session = self.client.create_checkout_session(params).await?;
Ok(session.url.context("no checkout session URL")?)
@@ -298,6 +305,12 @@ impl StripeBilling {
quantity: Some(1),
}]);
params.success_url = Some(success_url);
+ params.billing_address_collection = Some(StripeBillingAddressCollection::Required);
+ params.customer_update = Some(StripeCustomerUpdate {
+ address: Some(StripeCustomerUpdateAddress::Auto),
+ name: Some(StripeCustomerUpdateName::Auto),
+ shipping: None,
+ });
let session = self.client.create_checkout_session(params).await?;
Ok(session.url.context("no checkout session URL")?)
diff --git a/crates/collab/src/stripe_client.rs b/crates/collab/src/stripe_client.rs
index 3511fb447ed730e8a635af27d35a9e6a38b53136..9ffcb2ba6c9fde13ebc84b9e7c509851158e0a1e 100644
--- a/crates/collab/src/stripe_client.rs
+++ b/crates/collab/src/stripe_client.rs
@@ -148,6 +148,37 @@ pub struct StripeCreateMeterEventPayload<'a> {
pub stripe_customer_id: &'a StripeCustomerId,
}
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+pub enum StripeBillingAddressCollection {
+ Auto,
+ Required,
+}
+
+#[derive(Debug, PartialEq, Clone)]
+pub struct StripeCustomerUpdate {
+ pub address: Option,
+ pub name: Option,
+ pub shipping: Option,
+}
+
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+pub enum StripeCustomerUpdateAddress {
+ Auto,
+ Never,
+}
+
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+pub enum StripeCustomerUpdateName {
+ Auto,
+ Never,
+}
+
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+pub enum StripeCustomerUpdateShipping {
+ Auto,
+ Never,
+}
+
#[derive(Debug, Default)]
pub struct StripeCreateCheckoutSessionParams<'a> {
pub customer: Option<&'a StripeCustomerId>,
@@ -157,6 +188,8 @@ pub struct StripeCreateCheckoutSessionParams<'a> {
pub payment_method_collection: Option,
pub subscription_data: Option,
pub success_url: Option<&'a str>,
+ pub billing_address_collection: Option,
+ pub customer_update: Option,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
diff --git a/crates/collab/src/stripe_client/fake_stripe_client.rs b/crates/collab/src/stripe_client/fake_stripe_client.rs
index f679987f8b0173b84eff7008393e7f351c01b7ad..11b210dd0e7aba54148d26de0670f23415ae7cea 100644
--- a/crates/collab/src/stripe_client/fake_stripe_client.rs
+++ b/crates/collab/src/stripe_client/fake_stripe_client.rs
@@ -8,13 +8,14 @@ use parking_lot::Mutex;
use uuid::Uuid;
use crate::stripe_client::{
- CreateCustomerParams, StripeCheckoutSession, StripeCheckoutSessionMode,
- StripeCheckoutSessionPaymentMethodCollection, StripeClient,
+ CreateCustomerParams, StripeBillingAddressCollection, StripeCheckoutSession,
+ StripeCheckoutSessionMode, StripeCheckoutSessionPaymentMethodCollection, StripeClient,
StripeCreateCheckoutSessionLineItems, StripeCreateCheckoutSessionParams,
StripeCreateCheckoutSessionSubscriptionData, StripeCreateMeterEventParams,
- StripeCreateSubscriptionParams, StripeCustomer, StripeCustomerId, StripeMeter, StripeMeterId,
- StripePrice, StripePriceId, StripeSubscription, StripeSubscriptionId, StripeSubscriptionItem,
- StripeSubscriptionItemId, UpdateCustomerParams, UpdateSubscriptionParams,
+ StripeCreateSubscriptionParams, StripeCustomer, StripeCustomerId, StripeCustomerUpdate,
+ StripeMeter, StripeMeterId, StripePrice, StripePriceId, StripeSubscription,
+ StripeSubscriptionId, StripeSubscriptionItem, StripeSubscriptionItemId, UpdateCustomerParams,
+ UpdateSubscriptionParams,
};
#[derive(Debug, Clone)]
@@ -35,6 +36,8 @@ pub struct StripeCreateCheckoutSessionCall {
pub payment_method_collection: Option,
pub subscription_data: Option,
pub success_url: Option,
+ pub billing_address_collection: Option,
+ pub customer_update: Option,
}
pub struct FakeStripeClient {
@@ -231,6 +234,8 @@ impl StripeClient for FakeStripeClient {
payment_method_collection: params.payment_method_collection,
subscription_data: params.subscription_data,
success_url: params.success_url.map(|url| url.to_string()),
+ billing_address_collection: params.billing_address_collection,
+ customer_update: params.customer_update,
});
Ok(StripeCheckoutSession {
diff --git a/crates/collab/src/stripe_client/real_stripe_client.rs b/crates/collab/src/stripe_client/real_stripe_client.rs
index 56ddc8d7ac76387b562af4a8bb6c94ccb062af1a..7108e8d7597a3afd235c2ae48a4b05c5fc5de014 100644
--- a/crates/collab/src/stripe_client/real_stripe_client.rs
+++ b/crates/collab/src/stripe_client/real_stripe_client.rs
@@ -17,14 +17,16 @@ use stripe::{
};
use crate::stripe_client::{
- CreateCustomerParams, StripeCancellationDetails, StripeCancellationDetailsReason,
- StripeCheckoutSession, StripeCheckoutSessionMode, StripeCheckoutSessionPaymentMethodCollection,
- StripeClient, StripeCreateCheckoutSessionLineItems, StripeCreateCheckoutSessionParams,
+ CreateCustomerParams, StripeBillingAddressCollection, StripeCancellationDetails,
+ StripeCancellationDetailsReason, StripeCheckoutSession, StripeCheckoutSessionMode,
+ StripeCheckoutSessionPaymentMethodCollection, StripeClient,
+ StripeCreateCheckoutSessionLineItems, StripeCreateCheckoutSessionParams,
StripeCreateCheckoutSessionSubscriptionData, StripeCreateMeterEventParams,
- StripeCreateSubscriptionParams, StripeCustomer, StripeCustomerId, StripeMeter, StripePrice,
- StripePriceId, StripePriceRecurring, StripeSubscription, StripeSubscriptionId,
- StripeSubscriptionItem, StripeSubscriptionItemId, StripeSubscriptionTrialSettings,
- StripeSubscriptionTrialSettingsEndBehavior,
+ StripeCreateSubscriptionParams, StripeCustomer, StripeCustomerId, StripeCustomerUpdate,
+ StripeCustomerUpdateAddress, StripeCustomerUpdateName, StripeCustomerUpdateShipping,
+ StripeMeter, StripePrice, StripePriceId, StripePriceRecurring, StripeSubscription,
+ StripeSubscriptionId, StripeSubscriptionItem, StripeSubscriptionItemId,
+ StripeSubscriptionTrialSettings, StripeSubscriptionTrialSettingsEndBehavior,
StripeSubscriptionTrialSettingsEndBehaviorMissingPaymentMethod, UpdateCustomerParams,
UpdateSubscriptionParams,
};
@@ -444,6 +446,8 @@ impl<'a> TryFrom> for CreateCheckoutSessio
payment_method_collection: value.payment_method_collection.map(Into::into),
subscription_data: value.subscription_data.map(Into::into),
success_url: value.success_url,
+ billing_address_collection: value.billing_address_collection.map(Into::into),
+ customer_update: value.customer_update.map(Into::into),
..Default::default()
})
}
@@ -526,3 +530,63 @@ impl From for StripeCheckoutSession {
Self { url: value.url }
}
}
+
+impl From for stripe::CheckoutSessionBillingAddressCollection {
+ fn from(value: StripeBillingAddressCollection) -> Self {
+ match value {
+ StripeBillingAddressCollection::Auto => {
+ stripe::CheckoutSessionBillingAddressCollection::Auto
+ }
+ StripeBillingAddressCollection::Required => {
+ stripe::CheckoutSessionBillingAddressCollection::Required
+ }
+ }
+ }
+}
+
+impl From for stripe::CreateCheckoutSessionCustomerUpdateAddress {
+ fn from(value: StripeCustomerUpdateAddress) -> Self {
+ match value {
+ StripeCustomerUpdateAddress::Auto => {
+ stripe::CreateCheckoutSessionCustomerUpdateAddress::Auto
+ }
+ StripeCustomerUpdateAddress::Never => {
+ stripe::CreateCheckoutSessionCustomerUpdateAddress::Never
+ }
+ }
+ }
+}
+
+impl From for stripe::CreateCheckoutSessionCustomerUpdateName {
+ fn from(value: StripeCustomerUpdateName) -> Self {
+ match value {
+ StripeCustomerUpdateName::Auto => stripe::CreateCheckoutSessionCustomerUpdateName::Auto,
+ StripeCustomerUpdateName::Never => {
+ stripe::CreateCheckoutSessionCustomerUpdateName::Never
+ }
+ }
+ }
+}
+
+impl From for stripe::CreateCheckoutSessionCustomerUpdateShipping {
+ fn from(value: StripeCustomerUpdateShipping) -> Self {
+ match value {
+ StripeCustomerUpdateShipping::Auto => {
+ stripe::CreateCheckoutSessionCustomerUpdateShipping::Auto
+ }
+ StripeCustomerUpdateShipping::Never => {
+ stripe::CreateCheckoutSessionCustomerUpdateShipping::Never
+ }
+ }
+ }
+}
+
+impl From for stripe::CreateCheckoutSessionCustomerUpdate {
+ fn from(value: StripeCustomerUpdate) -> Self {
+ stripe::CreateCheckoutSessionCustomerUpdate {
+ address: value.address.map(Into::into),
+ name: value.name.map(Into::into),
+ shipping: value.shipping.map(Into::into),
+ }
+ }
+}
diff --git a/crates/collab/src/tests/stripe_billing_tests.rs b/crates/collab/src/tests/stripe_billing_tests.rs
index 9c0dbad54319e9d72a0c60e3e4bfffa347b2b3fe..c19eb0a23432fb835b99007b0ebca2e4a5a8f2e6 100644
--- a/crates/collab/src/tests/stripe_billing_tests.rs
+++ b/crates/collab/src/tests/stripe_billing_tests.rs
@@ -6,11 +6,13 @@ use pretty_assertions::assert_eq;
use crate::llm::AGENT_EXTENDED_TRIAL_FEATURE_FLAG;
use crate::stripe_billing::StripeBilling;
use crate::stripe_client::{
- FakeStripeClient, StripeCheckoutSessionMode, StripeCheckoutSessionPaymentMethodCollection,
- StripeCreateCheckoutSessionLineItems, StripeCreateCheckoutSessionSubscriptionData,
- StripeCustomerId, StripeMeter, StripeMeterId, StripePrice, StripePriceId, StripePriceRecurring,
- StripeSubscription, StripeSubscriptionId, StripeSubscriptionItem, StripeSubscriptionItemId,
- StripeSubscriptionTrialSettings, StripeSubscriptionTrialSettingsEndBehavior,
+ FakeStripeClient, StripeBillingAddressCollection, StripeCheckoutSessionMode,
+ StripeCheckoutSessionPaymentMethodCollection, StripeCreateCheckoutSessionLineItems,
+ StripeCreateCheckoutSessionSubscriptionData, StripeCustomerId, StripeCustomerUpdate,
+ StripeCustomerUpdateAddress, StripeCustomerUpdateName, StripeMeter, StripeMeterId, StripePrice,
+ StripePriceId, StripePriceRecurring, StripeSubscription, StripeSubscriptionId,
+ StripeSubscriptionItem, StripeSubscriptionItemId, StripeSubscriptionTrialSettings,
+ StripeSubscriptionTrialSettingsEndBehavior,
StripeSubscriptionTrialSettingsEndBehaviorMissingPaymentMethod, UpdateSubscriptionItems,
};
@@ -426,6 +428,18 @@ async fn test_checkout_with_zed_pro() {
assert_eq!(call.payment_method_collection, None);
assert_eq!(call.subscription_data, None);
assert_eq!(call.success_url.as_deref(), Some(success_url));
+ assert_eq!(
+ call.billing_address_collection,
+ Some(StripeBillingAddressCollection::Required)
+ );
+ assert_eq!(
+ call.customer_update,
+ Some(StripeCustomerUpdate {
+ address: Some(StripeCustomerUpdateAddress::Auto),
+ name: Some(StripeCustomerUpdateName::Auto),
+ shipping: None,
+ })
+ );
}
}
@@ -507,6 +521,18 @@ async fn test_checkout_with_zed_pro_trial() {
})
);
assert_eq!(call.success_url.as_deref(), Some(success_url));
+ assert_eq!(
+ call.billing_address_collection,
+ Some(StripeBillingAddressCollection::Required)
+ );
+ assert_eq!(
+ call.customer_update,
+ Some(StripeCustomerUpdate {
+ address: Some(StripeCustomerUpdateAddress::Auto),
+ name: Some(StripeCustomerUpdateName::Auto),
+ shipping: None,
+ })
+ );
}
// Successful checkout with extended trial.
@@ -561,5 +587,17 @@ async fn test_checkout_with_zed_pro_trial() {
})
);
assert_eq!(call.success_url.as_deref(), Some(success_url));
+ assert_eq!(
+ call.billing_address_collection,
+ Some(StripeBillingAddressCollection::Required)
+ );
+ assert_eq!(
+ call.customer_update,
+ Some(StripeCustomerUpdate {
+ address: Some(StripeCustomerUpdateAddress::Auto),
+ name: Some(StripeCustomerUpdateName::Auto),
+ shipping: None,
+ })
+ );
}
}
diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs
index d45ce2f88dc5579fcb410180363b855d4b999fa3..6501d3a56649ec3cb2ef15099829d601fbbfadd4 100644
--- a/crates/collab_ui/src/collab_panel.rs
+++ b/crates/collab_ui/src/collab_panel.rs
@@ -1645,6 +1645,10 @@ impl CollabPanel {
self.channel_name_editor.update(cx, |editor, cx| {
editor.insert(" ", window, cx);
});
+ } else if self.filter_editor.focus_handle(cx).is_focused(window) {
+ self.filter_editor.update(cx, |editor, cx| {
+ editor.insert(" ", window, cx);
+ });
}
}
@@ -2045,7 +2049,9 @@ impl CollabPanel {
dispatch_context.add("CollabPanel");
dispatch_context.add("menu");
- let identifier = if self.channel_name_editor.focus_handle(cx).is_focused(window) {
+ let identifier = if self.channel_name_editor.focus_handle(cx).is_focused(window)
+ || self.filter_editor.focus_handle(cx).is_focused(window)
+ {
"editing"
} else {
"not_editing"
@@ -3031,7 +3037,7 @@ impl Render for CollabPanel {
.on_action(cx.listener(CollabPanel::start_move_selected_channel))
.on_action(cx.listener(CollabPanel::move_channel_up))
.on_action(cx.listener(CollabPanel::move_channel_down))
- .track_focus(&self.focus_handle(cx))
+ .track_focus(&self.focus_handle)
.size_full()
.child(if self.user_store.read(cx).current_user().is_none() {
self.render_signed_out(cx)
diff --git a/crates/dap/src/inline_value.rs b/crates/dap/src/inline_value.rs
index 881797e20fb5e400ebbbfa6c88c9b5691f8928a9..47d783308518d4317ff8c7f100253bef431a1962 100644
--- a/crates/dap/src/inline_value.rs
+++ b/crates/dap/src/inline_value.rs
@@ -1,5 +1,3 @@
-use std::collections::{HashMap, HashSet};
-
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum VariableLookupKind {
Variable,
@@ -20,641 +18,3 @@ pub struct InlineValueLocation {
pub row: usize,
pub column: usize,
}
-
-/// A trait for providing inline values for debugging purposes.
-///
-/// Implementors of this trait are responsible for analyzing a given node in the
-/// source code and extracting variable information, including their names,
-/// scopes, and positions. This information is used to display inline values
-/// during debugging sessions. Implementors must also handle variable scoping
-/// themselves by traversing the syntax tree upwards to determine whether a
-/// variable is local or global.
-pub trait InlineValueProvider: 'static + Send + Sync {
- /// Provides a list of inline value locations based on the given node and source code.
- ///
- /// # Parameters
- /// - `node`: The root node of the active debug line. Implementors should traverse
- /// upwards from this node to gather variable information and determine their scope.
- /// - `source`: The source code as a string slice, used to extract variable names.
- /// - `max_row`: The maximum row to consider when collecting variables. Variables
- /// declared beyond this row should be ignored.
- ///
- /// # Returns
- /// A vector of `InlineValueLocation` instances, each representing a variable's
- /// name, scope, and the position of the inline value should be shown.
- fn provide(
- &self,
- node: language::Node,
- source: &str,
- max_row: usize,
- ) -> Vec;
-}
-
-pub struct RustInlineValueProvider;
-
-impl InlineValueProvider for RustInlineValueProvider {
- fn provide(
- &self,
- mut node: language::Node,
- source: &str,
- max_row: usize,
- ) -> Vec {
- let mut variables = Vec::new();
- let mut variable_names = HashSet::new();
- let mut scope = VariableScope::Local;
-
- loop {
- let mut variable_names_in_scope = HashMap::new();
- for child in node.named_children(&mut node.walk()) {
- if child.start_position().row >= max_row {
- break;
- }
-
- if scope == VariableScope::Local && child.kind() == "let_declaration" {
- if let Some(identifier) = child.child_by_field_name("pattern") {
- let variable_name = source[identifier.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) = variable_names_in_scope.get(&variable_name) {
- variables.remove(*index);
- }
-
- variable_names_in_scope.insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier.end_position().column,
- });
- }
- } else if child.kind() == "static_item" {
- if let Some(name) = child.child_by_field_name("name") {
- let variable_name = source[name.byte_range()].to_string();
- variables.push(InlineValueLocation {
- variable_name,
- scope: scope.clone(),
- lookup: VariableLookupKind::Expression,
- row: name.end_position().row,
- column: name.end_position().column,
- });
- }
- }
- }
-
- variable_names.extend(variable_names_in_scope.keys().cloned());
-
- if matches!(node.kind(), "function_item" | "closure_expression") {
- scope = VariableScope::Global;
- }
-
- if let Some(parent) = node.parent() {
- node = parent;
- } else {
- break;
- }
- }
-
- variables
- }
-}
-
-pub struct PythonInlineValueProvider;
-
-impl InlineValueProvider for PythonInlineValueProvider {
- fn provide(
- &self,
- mut node: language::Node,
- source: &str,
- max_row: usize,
- ) -> Vec {
- let mut variables = Vec::new();
- let mut variable_names = HashSet::new();
- let mut scope = VariableScope::Local;
-
- loop {
- let mut variable_names_in_scope = HashMap::new();
- for child in node.named_children(&mut node.walk()) {
- if child.start_position().row >= max_row {
- break;
- }
-
- if scope == VariableScope::Local {
- match child.kind() {
- "expression_statement" => {
- if let Some(expr) = child.child(0) {
- if expr.kind() == "assignment" {
- if let Some(param) = expr.child(0) {
- let param_identifier = if param.kind() == "identifier" {
- Some(param)
- } else if param.kind() == "typed_parameter" {
- param.child(0)
- } else {
- None
- };
-
- if let Some(identifier) = param_identifier {
- if identifier.kind() == "identifier" {
- let variable_name =
- source[identifier.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier.end_position().column,
- });
- }
- }
- }
- }
- }
- }
- "function_definition" => {
- if let Some(params) = child.child_by_field_name("parameters") {
- for param in params.named_children(&mut params.walk()) {
- let param_identifier = if param.kind() == "identifier" {
- Some(param)
- } else if param.kind() == "typed_parameter" {
- param.child(0)
- } else {
- None
- };
-
- if let Some(identifier) = param_identifier {
- if identifier.kind() == "identifier" {
- let variable_name =
- source[identifier.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier.end_position().column,
- });
- }
- }
- }
- }
- }
- "for_statement" => {
- if let Some(target) = child.child_by_field_name("left") {
- if target.kind() == "identifier" {
- let variable_name = source[target.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) = variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: target.end_position().row,
- column: target.end_position().column,
- });
- }
- }
- }
- _ => {}
- }
- }
- }
-
- variable_names.extend(variable_names_in_scope.keys().cloned());
-
- if matches!(node.kind(), "function_definition" | "module")
- && node.range().end_point.row < max_row
- {
- scope = VariableScope::Global;
- }
-
- if let Some(parent) = node.parent() {
- node = parent;
- } else {
- break;
- }
- }
-
- variables
- }
-}
-
-pub struct GoInlineValueProvider;
-
-impl InlineValueProvider for GoInlineValueProvider {
- fn provide(
- &self,
- mut node: language::Node,
- source: &str,
- max_row: usize,
- ) -> Vec {
- let mut variables = Vec::new();
- let mut variable_names = HashSet::new();
- let mut scope = VariableScope::Local;
-
- loop {
- let mut variable_names_in_scope = HashMap::new();
- for child in node.named_children(&mut node.walk()) {
- if child.start_position().row >= max_row {
- break;
- }
-
- if scope == VariableScope::Local {
- match child.kind() {
- "var_declaration" => {
- for var_spec in child.named_children(&mut child.walk()) {
- if var_spec.kind() == "var_spec" {
- if let Some(name_node) = var_spec.child_by_field_name("name") {
- let variable_name =
- source[name_node.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: name_node.end_position().row,
- column: name_node.end_position().column,
- });
- }
- }
- }
- }
- "short_var_declaration" => {
- if let Some(left_side) = child.child_by_field_name("left") {
- for identifier in left_side.named_children(&mut left_side.walk()) {
- if identifier.kind() == "identifier" {
- let variable_name =
- source[identifier.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier.end_position().column,
- });
- }
- }
- }
- }
- "assignment_statement" => {
- if let Some(left_side) = child.child_by_field_name("left") {
- for identifier in left_side.named_children(&mut left_side.walk()) {
- if identifier.kind() == "identifier" {
- let variable_name =
- source[identifier.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier.end_position().column,
- });
- }
- }
- }
- }
- "function_declaration" | "method_declaration" => {
- if let Some(params) = child.child_by_field_name("parameters") {
- for param in params.named_children(&mut params.walk()) {
- if param.kind() == "parameter_declaration" {
- if let Some(name_node) = param.child_by_field_name("name") {
- let variable_name =
- source[name_node.byte_range()].to_string();
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope
- .insert(variable_name.clone(), variables.len());
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: name_node.end_position().row,
- column: name_node.end_position().column,
- });
- }
- }
- }
- }
- }
- "for_statement" => {
- if let Some(clause) = child.named_child(0) {
- if clause.kind() == "for_clause" {
- if let Some(init) = clause.named_child(0) {
- if init.kind() == "short_var_declaration" {
- if let Some(left_side) =
- init.child_by_field_name("left")
- {
- if left_side.kind() == "expression_list" {
- for identifier in left_side
- .named_children(&mut left_side.walk())
- {
- if identifier.kind() == "identifier" {
- let variable_name = source
- [identifier.byte_range()]
- .to_string();
-
- if variable_names
- .contains(&variable_name)
- {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope
- .get(&variable_name)
- {
- variables.remove(*index);
- }
-
- variable_names_in_scope.insert(
- variable_name.clone(),
- variables.len(),
- );
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup:
- VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier
- .end_position()
- .column,
- });
- }
- }
- }
- }
- }
- }
- } else if clause.kind() == "range_clause" {
- if let Some(left) = clause.child_by_field_name("left") {
- if left.kind() == "expression_list" {
- for identifier in left.named_children(&mut left.walk())
- {
- if identifier.kind() == "identifier" {
- let variable_name =
- source[identifier.byte_range()].to_string();
-
- if variable_name == "_" {
- continue;
- }
-
- if variable_names.contains(&variable_name) {
- continue;
- }
-
- if let Some(index) =
- variable_names_in_scope.get(&variable_name)
- {
- variables.remove(*index);
- }
- variable_names_in_scope.insert(
- variable_name.clone(),
- variables.len(),
- );
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Local,
- lookup: VariableLookupKind::Variable,
- row: identifier.end_position().row,
- column: identifier.end_position().column,
- });
- }
- }
- }
- }
- }
- }
- }
- _ => {}
- }
- } else if child.kind() == "var_declaration" {
- for var_spec in child.named_children(&mut child.walk()) {
- if var_spec.kind() == "var_spec" {
- if let Some(name_node) = var_spec.child_by_field_name("name") {
- let variable_name = source[name_node.byte_range()].to_string();
- variables.push(InlineValueLocation {
- variable_name,
- scope: VariableScope::Global,
- lookup: VariableLookupKind::Expression,
- row: name_node.end_position().row,
- column: name_node.end_position().column,
- });
- }
- }
- }
- }
- }
-
- variable_names.extend(variable_names_in_scope.keys().cloned());
-
- if matches!(node.kind(), "function_declaration" | "method_declaration") {
- scope = VariableScope::Global;
- }
-
- if let Some(parent) = node.parent() {
- node = parent;
- } else {
- break;
- }
- }
-
- variables
- }
-}
-#[cfg(test)]
-mod tests {
- use super::*;
- use tree_sitter::Parser;
-
- #[test]
- fn test_go_inline_value_provider() {
- let provider = GoInlineValueProvider;
- let source = r#"
-package main
-
-func main() {
- items := []int{1, 2, 3, 4, 5}
- for i, v := range items {
- println(i, v)
- }
- for j := 0; j < 10; j++ {
- println(j)
- }
-}
-"#;
-
- let mut parser = Parser::new();
- if parser
- .set_language(&tree_sitter_go::LANGUAGE.into())
- .is_err()
- {
- return;
- }
- let Some(tree) = parser.parse(source, None) else {
- return;
- };
- let root_node = tree.root_node();
-
- let mut main_body = None;
- for child in root_node.named_children(&mut root_node.walk()) {
- if child.kind() == "function_declaration" {
- if let Some(name) = child.child_by_field_name("name") {
- if &source[name.byte_range()] == "main" {
- if let Some(body) = child.child_by_field_name("body") {
- main_body = Some(body);
- break;
- }
- }
- }
- }
- }
-
- let Some(main_body) = main_body else {
- return;
- };
-
- let variables = provider.provide(main_body, source, 100);
- assert!(variables.len() >= 2);
-
- let variable_names: Vec<&str> =
- variables.iter().map(|v| v.variable_name.as_str()).collect();
- assert!(variable_names.contains(&"items"));
- assert!(variable_names.contains(&"j"));
- }
-
- #[test]
- fn test_go_inline_value_provider_counter_pattern() {
- let provider = GoInlineValueProvider;
- let source = r#"
-package main
-
-func main() {
- N := 10
- for i := range N {
- println(i)
- }
-}
-"#;
-
- let mut parser = Parser::new();
- if parser
- .set_language(&tree_sitter_go::LANGUAGE.into())
- .is_err()
- {
- return;
- }
- let Some(tree) = parser.parse(source, None) else {
- return;
- };
- let root_node = tree.root_node();
-
- let mut main_body = None;
- for child in root_node.named_children(&mut root_node.walk()) {
- if child.kind() == "function_declaration" {
- if let Some(name) = child.child_by_field_name("name") {
- if &source[name.byte_range()] == "main" {
- if let Some(body) = child.child_by_field_name("body") {
- main_body = Some(body);
- break;
- }
- }
- }
- }
- }
-
- let Some(main_body) = main_body else {
- return;
- };
- let variables = provider.provide(main_body, source, 100);
-
- let variable_names: Vec<&str> =
- variables.iter().map(|v| v.variable_name.as_str()).collect();
- assert!(variable_names.contains(&"N"));
- assert!(variable_names.contains(&"i"));
- }
-}
diff --git a/crates/dap/src/registry.rs b/crates/dap/src/registry.rs
index 2786de227e95ffa9d0b253f1309224d6f21ed877..9435b16b924e43406d5ed99c864df78c179f27b1 100644
--- a/crates/dap/src/registry.rs
+++ b/crates/dap/src/registry.rs
@@ -8,10 +8,7 @@ use task::{
AdapterSchema, AdapterSchemas, DebugRequest, DebugScenario, SpawnInTerminal, TaskTemplate,
};
-use crate::{
- adapters::{DebugAdapter, DebugAdapterName},
- inline_value::InlineValueProvider,
-};
+use crate::adapters::{DebugAdapter, DebugAdapterName};
use std::{collections::BTreeMap, sync::Arc};
/// Given a user build configuration, locator creates a fill-in debug target ([DebugScenario]) on behalf of the user.
@@ -33,7 +30,6 @@ pub trait DapLocator: Send + Sync {
struct DapRegistryState {
adapters: BTreeMap>,
locators: FxHashMap>,
- inline_value_providers: FxHashMap>,
}
#[derive(Clone, Default)]
@@ -82,22 +78,6 @@ impl DapRegistry {
schemas
}
- pub fn add_inline_value_provider(
- &self,
- language: String,
- provider: Arc,
- ) {
- let _previous_value = self
- .0
- .write()
- .inline_value_providers
- .insert(language, provider);
- debug_assert!(
- _previous_value.is_none(),
- "Attempted to insert a new inline value provider when one is already registered"
- );
- }
-
pub fn locators(&self) -> FxHashMap> {
self.0.read().locators.clone()
}
@@ -106,10 +86,6 @@ impl DapRegistry {
self.0.read().adapters.get(name).cloned()
}
- pub fn inline_value_provider(&self, language: &str) -> Option> {
- self.0.read().inline_value_providers.get(language).cloned()
- }
-
pub fn enumerate_adapters(&self) -> Vec {
self.0.read().adapters.keys().cloned().collect()
}
diff --git a/crates/dap_adapters/src/dap_adapters.rs b/crates/dap_adapters/src/dap_adapters.rs
index 414d0a91a3de0d5a75ea4dc981d277c84962246f..79c56fdf25583e6cbe3a182b3abf464ac449eb27 100644
--- a/crates/dap_adapters/src/dap_adapters.rs
+++ b/crates/dap_adapters/src/dap_adapters.rs
@@ -18,7 +18,6 @@ use dap::{
GithubRepo,
},
configure_tcp_connection,
- inline_value::{GoInlineValueProvider, PythonInlineValueProvider, RustInlineValueProvider},
};
use gdb::GdbDebugAdapter;
use go::GoDebugAdapter;
@@ -44,10 +43,5 @@ pub fn init(cx: &mut App) {
{
registry.add_adapter(Arc::from(dap::FakeAdapter {}));
}
-
- registry.add_inline_value_provider("Rust".to_string(), Arc::from(RustInlineValueProvider));
- registry
- .add_inline_value_provider("Python".to_string(), Arc::from(PythonInlineValueProvider));
- registry.add_inline_value_provider("Go".to_string(), Arc::from(GoInlineValueProvider));
})
}
diff --git a/crates/debugger_ui/Cargo.toml b/crates/debugger_ui/Cargo.toml
index e259b8a4b38fef1d702ff5268c29f64fe45498c8..91f9acad3c73334980036880143df9c7b410b3b6 100644
--- a/crates/debugger_ui/Cargo.toml
+++ b/crates/debugger_ui/Cargo.toml
@@ -81,3 +81,4 @@ unindent.workspace = true
util = { workspace = true, features = ["test-support"] }
workspace = { workspace = true, features = ["test-support"] }
zlog.workspace = true
+tree-sitter-go.workspace = true
diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs
index 2bea91b2dc1b2c928a23ddf101000f2c5a333ffe..b7f3be0426e9c189eb0edf203859c7d2489c75d9 100644
--- a/crates/debugger_ui/src/debugger_panel.rs
+++ b/crates/debugger_ui/src/debugger_panel.rs
@@ -695,30 +695,6 @@ impl DebugPanel {
}
}),
)
- .child(
- IconButton::new("debug-step-out", IconName::ArrowUpRight)
- .icon_size(IconSize::XSmall)
- .shape(ui::IconButtonShape::Square)
- .on_click(window.listener_for(
- &running_state,
- |this, _, _window, cx| {
- this.step_out(cx);
- },
- ))
- .disabled(thread_status != ThreadStatus::Stopped)
- .tooltip({
- let focus_handle = focus_handle.clone();
- move |window, cx| {
- Tooltip::for_action_in(
- "Step out",
- &StepOut,
- &focus_handle,
- window,
- cx,
- )
- }
- }),
- )
.child(
IconButton::new(
"debug-step-into",
@@ -746,6 +722,30 @@ impl DebugPanel {
}
}),
)
+ .child(
+ IconButton::new("debug-step-out", IconName::ArrowUpRight)
+ .icon_size(IconSize::XSmall)
+ .shape(ui::IconButtonShape::Square)
+ .on_click(window.listener_for(
+ &running_state,
+ |this, _, _window, cx| {
+ this.step_out(cx);
+ },
+ ))
+ .disabled(thread_status != ThreadStatus::Stopped)
+ .tooltip({
+ let focus_handle = focus_handle.clone();
+ move |window, cx| {
+ Tooltip::for_action_in(
+ "Step out",
+ &StepOut,
+ &focus_handle,
+ window,
+ cx,
+ )
+ }
+ }),
+ )
.child(Divider::vertical())
.child(
IconButton::new("debug-restart", IconName::DebugRestart)
diff --git a/crates/debugger_ui/src/session.rs b/crates/debugger_ui/src/session.rs
index e0e6126867462e7440657b2dce3f40ead9a23e82..ce6730bee77495fa94ad2f079fdf6bda9d219be0 100644
--- a/crates/debugger_ui/src/session.rs
+++ b/crates/debugger_ui/src/session.rs
@@ -11,7 +11,7 @@ use project::worktree_store::WorktreeStore;
use rpc::proto;
use running::RunningState;
use std::{cell::OnceCell, sync::OnceLock};
-use ui::{Indicator, prelude::*};
+use ui::{Indicator, Tooltip, prelude::*};
use workspace::{
CollaboratorId, FollowableItem, ViewId, Workspace,
item::{self, Item},
@@ -153,6 +153,8 @@ impl DebugSession {
};
h_flex()
+ .id("session-label")
+ .tooltip(Tooltip::text(format!("Session {}", self.session_id(cx).0,)))
.ml(depth * px(16.0))
.gap_2()
.when_some(icon, |this, indicator| this.child(indicator))
diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs
index e84e0d74e6c9302d7edf61f794809168c54c279e..83d2d46547ada9da328cc44443813a87a6f681f1 100644
--- a/crates/debugger_ui/src/session/running/console.rs
+++ b/crates/debugger_ui/src/session/running/console.rs
@@ -582,14 +582,31 @@ impl CompletionProvider for ConsoleQueryBarCompletionProvider {
fn is_completion_trigger(
&self,
- _buffer: &Entity,
- _position: language::Anchor,
- _text: &str,
+ buffer: &Entity,
+ position: language::Anchor,
+ text: &str,
_trigger_in_words: bool,
- _menu_is_open: bool,
- _cx: &mut Context,
+ menu_is_open: bool,
+ cx: &mut Context,
) -> bool {
- true
+ let snapshot = buffer.read(cx).snapshot();
+ if !menu_is_open && !snapshot.settings_at(position, cx).show_completions_on_input {
+ return false;
+ }
+
+ self.0
+ .read_with(cx, |console, cx| {
+ console
+ .session
+ .read(cx)
+ .capabilities()
+ .completion_trigger_characters
+ .as_ref()
+ .map(|triggers| triggers.contains(&text.to_string()))
+ })
+ .ok()
+ .flatten()
+ .unwrap_or(true)
}
}
@@ -629,8 +646,23 @@ impl ConsoleQueryBarCompletionProvider {
(variables, string_matches)
});
- let query = buffer.read(cx).text();
-
+ let snapshot = buffer.read(cx).text_snapshot();
+ let query = snapshot.text();
+ let replace_range = {
+ let buffer_offset = buffer_position.to_offset(&snapshot);
+ let reversed_chars = snapshot.reversed_chars_for_range(0..buffer_offset);
+ let mut word_len = 0;
+ for ch in reversed_chars {
+ if ch.is_alphanumeric() || ch == '_' {
+ word_len += 1;
+ } else {
+ break;
+ }
+ }
+ let word_start_offset = buffer_offset - word_len;
+ let start_anchor = snapshot.anchor_at(word_start_offset, Bias::Left);
+ start_anchor..buffer_position
+ };
cx.spawn(async move |_, cx| {
const LIMIT: usize = 10;
let matches = fuzzy::match_strings(
@@ -650,7 +682,7 @@ impl ConsoleQueryBarCompletionProvider {
let variable_value = variables.get(&string_match.string)?;
Some(project::Completion {
- replace_range: buffer_position..buffer_position,
+ replace_range: replace_range.clone(),
new_text: string_match.string.clone(),
label: CodeLabel {
filter_range: 0..string_match.string.len(),
diff --git a/crates/debugger_ui/src/tests/inline_values.rs b/crates/debugger_ui/src/tests/inline_values.rs
index 6fed57ecacc9ad6062a27f3fa33a95bd52cc1a10..45cab2a3063a8741d01efb54059667026a646879 100644
--- a/crates/debugger_ui/src/tests/inline_values.rs
+++ b/crates/debugger_ui/src/tests/inline_values.rs
@@ -246,10 +246,10 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
- let x = 10;
+ let x: 10 = 10;
let value = 42;
let y = 4;
let tester = {
@@ -303,11 +303,11 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
- let value = 42;
+ let value: 42 = 42;
let y = 4;
let tester = {
let y = 10;
@@ -360,12 +360,12 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
let value: 42 = 42;
- let y = 4;
+ let y: 4 = 4;
let tester = {
let y = 10;
let y = 5;
@@ -417,7 +417,7 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
@@ -474,14 +474,14 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
let value: 42 = 42;
let y: 4 = 4;
let tester = {
- let y = 10;
+ let y: 4 = 10;
let y = 5;
let b = 3;
vec![y, 20, 30]
@@ -581,15 +581,15 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
let value: 42 = 42;
- let y = 4;
+ let y: 10 = 4;
let tester = {
let y: 10 = 10;
- let y = 5;
+ let y: 10 = 5;
let b = 3;
vec![y, 20, 30]
};
@@ -688,14 +688,14 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
let value: 42 = 42;
- let y = 4;
+ let y: 5 = 4;
let tester = {
- let y = 10;
+ let y: 5 = 10;
let y: 5 = 5;
let b = 3;
vec![y, 20, 30]
@@ -807,17 +807,17 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
let value: 42 = 42;
- let y = 4;
+ let y: 5 = 4;
let tester = {
- let y = 10;
+ let y: 5 = 10;
let y: 5 = 5;
let b: 3 = 3;
- vec![y, 20, 30]
+ vec![y: 5, 20, 30]
};
let caller = || {
@@ -926,7 +926,7 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
@@ -1058,7 +1058,7 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
@@ -1115,21 +1115,21 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
- let x = 10;
- let value = 42;
- let y = 4;
- let tester = {
+ let x: 10 = 10;
+ let value: 42 = 42;
+ let y: 4 = 4;
+ let tester: size=3 = {
let y = 10;
let y = 5;
let b = 3;
vec![y, 20, 30]
};
- let caller = || {
- let x = 3;
+ let caller: = || {
+ let x: 10 = 3;
println!("x={}", x);
};
@@ -1193,10 +1193,10 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 1: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
- let x = 10;
+ let x: 3 = 10;
let value = 42;
let y = 4;
let tester = {
@@ -1208,7 +1208,7 @@ fn main() {
let caller = || {
let x: 3 = 3;
- println!("x={}", x);
+ println!("x={}", x: 3);
};
caller();
@@ -1338,7 +1338,7 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 2: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
@@ -1362,7 +1362,7 @@ fn main() {
GLOBAL = 2;
}
- let result = value * 2 * x;
+ let result = value: 42 * 2 * x: 10;
println!("Simple test executed: value={}, result={}", value, result);
assert!(true);
}
@@ -1483,7 +1483,7 @@ fn main() {
editor.update_in(cx, |editor, window, cx| {
pretty_assertions::assert_eq!(
r#"
- static mut GLOBAL: 2: usize = 1;
+ static mut GLOBAL: usize = 1;
fn main() {
let x: 10 = 10;
@@ -1507,8 +1507,8 @@ fn main() {
GLOBAL = 2;
}
- let result: 840 = value * 2 * x;
- println!("Simple test executed: value={}, result={}", value, result);
+ let result: 840 = value: 42 * 2 * x: 10;
+ println!("Simple test executed: value={}, result={}", value: 42, result: 840);
assert!(true);
}
"#
@@ -1519,6 +1519,7 @@ fn main() {
}
fn rust_lang() -> Language {
+ let debug_variables_query = include_str!("../../../languages/src/rust/debugger.scm");
Language::new(
LanguageConfig {
name: "Rust".into(),
@@ -1530,6 +1531,8 @@ fn rust_lang() -> Language {
},
Some(tree_sitter_rust::LANGUAGE.into()),
)
+ .with_debug_variables_query(debug_variables_query)
+ .unwrap()
}
#[gpui::test]
@@ -1818,8 +1821,8 @@ def process_data(untyped_param, typed_param: int, another_typed: str):
def process_data(untyped_param: test_value, typed_param: 42: int, another_typed: world: str):
# Local variables
x: 10 = 10
- result: 84 = typed_param * 2
- text: Hello, world = "Hello, " + another_typed
+ result: 84 = typed_param: 42 * 2
+ text: Hello, world = "Hello, " + another_typed: world
# For loop with range
sum_value: 10 = 0
@@ -1837,6 +1840,7 @@ def process_data(untyped_param, typed_param: int, another_typed: str):
}
fn python_lang() -> Language {
+ let debug_variables_query = include_str!("../../../languages/src/python/debugger.scm");
Language::new(
LanguageConfig {
name: "Python".into(),
@@ -1848,4 +1852,392 @@ fn python_lang() -> Language {
},
Some(tree_sitter_python::LANGUAGE.into()),
)
+ .with_debug_variables_query(debug_variables_query)
+ .unwrap()
+}
+
+fn go_lang() -> Language {
+ let debug_variables_query = include_str!("../../../languages/src/go/debugger.scm");
+ Language::new(
+ LanguageConfig {
+ name: "Go".into(),
+ matcher: LanguageMatcher {
+ path_suffixes: vec!["go".to_string()],
+ ..Default::default()
+ },
+ ..Default::default()
+ },
+ Some(tree_sitter_go::LANGUAGE.into()),
+ )
+ .with_debug_variables_query(debug_variables_query)
+ .unwrap()
+}
+
+/// Test utility function for inline values testing
+///
+/// # Arguments
+/// * `variables` - List of tuples containing (variable_name, variable_value)
+/// * `before` - Source code before inline values are applied
+/// * `after` - Expected source code after inline values are applied
+/// * `language` - Language configuration to use for parsing
+/// * `executor` - Background executor for async operations
+/// * `cx` - Test app context
+async fn test_inline_values_util(
+ local_variables: &[(&str, &str)],
+ global_variables: &[(&str, &str)],
+ before: &str,
+ after: &str,
+ active_debug_line: Option,
+ language: Language,
+ executor: BackgroundExecutor,
+ cx: &mut TestAppContext,
+) {
+ init_test(cx);
+
+ let lines_count = before.lines().count();
+ let stop_line =
+ active_debug_line.unwrap_or_else(|| if lines_count > 6 { 6 } else { lines_count - 1 });
+
+ let fs = FakeFs::new(executor.clone());
+ fs.insert_tree(path!("/project"), json!({ "main.rs": before.to_string() }))
+ .await;
+
+ let project = Project::test(fs.clone(), [path!("/project").as_ref()], cx).await;
+ let workspace = init_test_workspace(&project, cx).await;
+ workspace
+ .update(cx, |workspace, window, cx| {
+ workspace.focus_panel::(window, cx);
+ })
+ .unwrap();
+ let cx = &mut VisualTestContext::from_window(*workspace, cx);
+
+ let session = start_debug_session(&workspace, cx, |_| {}).unwrap();
+ let client = session.update(cx, |session, _| session.adapter_client().unwrap());
+
+ client.on_request::(|_, _| {
+ Ok(dap::ThreadsResponse {
+ threads: vec![dap::Thread {
+ id: 1,
+ name: "main".into(),
+ }],
+ })
+ });
+
+ client.on_request::(move |_, _| {
+ Ok(dap::StackTraceResponse {
+ stack_frames: vec![dap::StackFrame {
+ id: 1,
+ name: "main".into(),
+ source: Some(dap::Source {
+ name: Some("main.rs".into()),
+ path: Some(path!("/project/main.rs").into()),
+ source_reference: None,
+ presentation_hint: None,
+ origin: None,
+ sources: None,
+ adapter_data: None,
+ checksums: None,
+ }),
+ line: stop_line as u64,
+ column: 1,
+ end_line: None,
+ end_column: None,
+ can_restart: None,
+ instruction_pointer_reference: None,
+ module_id: None,
+ presentation_hint: None,
+ }],
+ total_frames: None,
+ })
+ });
+
+ let local_vars: Vec = local_variables
+ .iter()
+ .map(|(name, value)| Variable {
+ name: (*name).into(),
+ value: (*value).into(),
+ type_: None,
+ presentation_hint: None,
+ evaluate_name: None,
+ variables_reference: 0,
+ named_variables: None,
+ indexed_variables: None,
+ memory_reference: None,
+ declaration_location_reference: None,
+ value_location_reference: None,
+ })
+ .collect();
+
+ let global_vars: Vec = global_variables
+ .iter()
+ .map(|(name, value)| Variable {
+ name: (*name).into(),
+ value: (*value).into(),
+ type_: None,
+ presentation_hint: None,
+ evaluate_name: None,
+ variables_reference: 0,
+ named_variables: None,
+ indexed_variables: None,
+ memory_reference: None,
+ declaration_location_reference: None,
+ value_location_reference: None,
+ })
+ .collect();
+
+ client.on_request::({
+ let local_vars = Arc::new(local_vars.clone());
+ let global_vars = Arc::new(global_vars.clone());
+ move |_, args| {
+ let variables = match args.variables_reference {
+ 2 => (*local_vars).clone(),
+ 3 => (*global_vars).clone(),
+ _ => vec![],
+ };
+ Ok(dap::VariablesResponse { variables })
+ }
+ });
+
+ client.on_request::(move |_, _| {
+ Ok(dap::ScopesResponse {
+ scopes: vec![
+ Scope {
+ name: "Local".into(),
+ presentation_hint: None,
+ variables_reference: 2,
+ named_variables: None,
+ indexed_variables: None,
+ expensive: false,
+ source: None,
+ line: None,
+ column: None,
+ end_line: None,
+ end_column: None,
+ },
+ Scope {
+ name: "Global".into(),
+ presentation_hint: None,
+ variables_reference: 3,
+ named_variables: None,
+ indexed_variables: None,
+ expensive: false,
+ source: None,
+ line: None,
+ column: None,
+ end_line: None,
+ end_column: None,
+ },
+ ],
+ })
+ });
+
+ if !global_variables.is_empty() {
+ let global_evaluate_map: std::collections::HashMap = global_variables
+ .iter()
+ .map(|(name, value)| (name.to_string(), value.to_string()))
+ .collect();
+
+ client.on_request::(move |_, args| {
+ let value = global_evaluate_map
+ .get(&args.expression)
+ .unwrap_or(&"undefined".to_string())
+ .clone();
+
+ Ok(dap::EvaluateResponse {
+ result: value,
+ type_: None,
+ presentation_hint: None,
+ variables_reference: 0,
+ named_variables: None,
+ indexed_variables: None,
+ memory_reference: None,
+ value_location_reference: None,
+ })
+ });
+ }
+
+ client
+ .fake_event(dap::messages::Events::Stopped(dap::StoppedEvent {
+ reason: dap::StoppedEventReason::Pause,
+ description: None,
+ thread_id: Some(1),
+ preserve_focus_hint: None,
+ text: None,
+ all_threads_stopped: None,
+ hit_breakpoint_ids: None,
+ }))
+ .await;
+
+ cx.run_until_parked();
+
+ let project_path = Path::new(path!("/project"));
+ let worktree = project
+ .update(cx, |project, cx| project.find_worktree(project_path, cx))
+ .expect("This worktree should exist in project")
+ .0;
+
+ let worktree_id = workspace
+ .update(cx, |_, _, cx| worktree.read(cx).id())
+ .unwrap();
+
+ let buffer = project
+ .update(cx, |project, cx| {
+ project.open_buffer((worktree_id, "main.rs"), cx)
+ })
+ .await
+ .unwrap();
+
+ buffer.update(cx, |buffer, cx| {
+ buffer.set_language(Some(Arc::new(language)), cx);
+ });
+
+ let (editor, cx) = cx.add_window_view(|window, cx| {
+ Editor::new(
+ EditorMode::full(),
+ MultiBuffer::build_from_buffer(buffer, cx),
+ Some(project),
+ window,
+ cx,
+ )
+ });
+
+ active_debug_session_panel(workspace, cx).update_in(cx, |_, window, cx| {
+ cx.focus_self(window);
+ });
+ cx.run_until_parked();
+
+ editor.update(cx, |editor, cx| editor.refresh_inline_values(cx));
+
+ cx.run_until_parked();
+
+ editor.update_in(cx, |editor, window, cx| {
+ pretty_assertions::assert_eq!(after, editor.snapshot(window, cx).text());
+ });
+}
+
+#[gpui::test]
+async fn test_inline_values_example(executor: BackgroundExecutor, cx: &mut TestAppContext) {
+ let variables = [("x", "10"), ("y", "20"), ("result", "30")];
+
+ let before = r#"
+fn main() {
+ let x = 10;
+ let y = 20;
+ let result = x + y;
+ println!("Result: {}", result);
+}
+"#
+ .unindent();
+
+ let after = r#"
+fn main() {
+ let x: 10 = 10;
+ let y: 20 = 20;
+ let result: 30 = x: 10 + y: 20;
+ println!("Result: {}", result: 30);
+}
+"#
+ .unindent();
+
+ test_inline_values_util(
+ &variables,
+ &[],
+ &before,
+ &after,
+ None,
+ rust_lang(),
+ executor,
+ cx,
+ )
+ .await;
+}
+
+#[gpui::test]
+async fn test_inline_values_with_globals(executor: BackgroundExecutor, cx: &mut TestAppContext) {
+ let variables = [("x", "5"), ("y", "10")];
+
+ let before = r#"
+static mut GLOBAL_COUNTER: usize = 42;
+
+fn main() {
+ let x = 5;
+ let y = 10;
+ unsafe {
+ GLOBAL_COUNTER += 1;
+ }
+ println!("x={}, y={}, global={}", x, y, unsafe { GLOBAL_COUNTER });
+}
+"#
+ .unindent();
+
+ let after = r#"
+static mut GLOBAL_COUNTER: 42: usize = 42;
+
+fn main() {
+ let x: 5 = 5;
+ let y: 10 = 10;
+ unsafe {
+ GLOBAL_COUNTER += 1;
+ }
+ println!("x={}, y={}, global={}", x, y, unsafe { GLOBAL_COUNTER });
+}
+"#
+ .unindent();
+
+ test_inline_values_util(
+ &variables,
+ &[("GLOBAL_COUNTER", "42")],
+ &before,
+ &after,
+ None,
+ rust_lang(),
+ executor,
+ cx,
+ )
+ .await;
+}
+
+#[gpui::test]
+async fn test_go_inline_values(executor: BackgroundExecutor, cx: &mut TestAppContext) {
+ let variables = [("x", "42"), ("y", "hello")];
+
+ let before = r#"
+package main
+
+var globalCounter int = 100
+
+func main() {
+ x := 42
+ y := "hello"
+ z := x + 10
+ println(x, y, z)
+}
+"#
+ .unindent();
+
+ let after = r#"
+package main
+
+var globalCounter: 100 int = 100
+
+func main() {
+ x: 42 := 42
+ y := "hello"
+ z := x + 10
+ println(x, y, z)
+}
+"#
+ .unindent();
+
+ test_inline_values_util(
+ &variables,
+ &[("globalCounter", "100")],
+ &before,
+ &after,
+ None,
+ go_lang(),
+ executor,
+ cx,
+ )
+ .await;
}
diff --git a/crates/deepseek/src/deepseek.rs b/crates/deepseek/src/deepseek.rs
index 22bde8e5943f1a82c7441354a916f980405582c2..c49270febe3b2b3702b808e2219f6e45d7252267 100644
--- a/crates/deepseek/src/deepseek.rs
+++ b/crates/deepseek/src/deepseek.rs
@@ -201,13 +201,13 @@ pub struct Response {
#[derive(Serialize, Deserialize, Debug)]
pub struct Usage {
- pub prompt_tokens: u32,
- pub completion_tokens: u32,
- pub total_tokens: u32,
+ pub prompt_tokens: u64,
+ pub completion_tokens: u64,
+ pub total_tokens: u64,
#[serde(default)]
- pub prompt_cache_hit_tokens: u32,
+ pub prompt_cache_hit_tokens: u64,
#[serde(default)]
- pub prompt_cache_miss_tokens: u32,
+ pub prompt_cache_miss_tokens: u64,
}
#[derive(Serialize, Deserialize, Debug)]
@@ -224,6 +224,7 @@ pub struct StreamResponse {
pub created: u64,
pub model: String,
pub choices: Vec,
+ pub usage: Option,
}
#[derive(Serialize, Deserialize, Debug)]
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs
index b8a3e5efa778579b61b969e8c224de1bd237bbd2..ff6263dfa71184ded4e7697dd6132aa12138063d 100644
--- a/crates/editor/src/actions.rs
+++ b/crates/editor/src/actions.rs
@@ -270,6 +270,8 @@ actions!(
ContextMenuLast,
ContextMenuNext,
ContextMenuPrevious,
+ ConvertIndentationToSpaces,
+ ConvertIndentationToTabs,
ConvertToKebabCase,
ConvertToLowerCamelCase,
ConvertToLowerCase,
diff --git a/crates/editor/src/code_context_menus.rs b/crates/editor/src/code_context_menus.rs
index e9642657f8b7cba328bce0413e09d29ebbc9cfd4..291c03422def426054457c04ab8c9e4e710112a7 100644
--- a/crates/editor/src/code_context_menus.rs
+++ b/crates/editor/src/code_context_menus.rs
@@ -1205,7 +1205,7 @@ impl CodeActionContents {
tasks_len + code_actions_len + self.debug_scenarios.len()
}
- fn is_empty(&self) -> bool {
+ pub fn is_empty(&self) -> bool {
self.len() == 0
}
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 568e9062c86bb5b2b584bfeaa4f430c88d251a76..ea30cc6fab94d7a80e8855efd3832b21a945b6c1 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -3388,9 +3388,12 @@ impl Editor {
auto_scroll = true;
}
2 => {
- let range = movement::surrounding_word(&display_map, position);
- start = buffer.anchor_before(range.start.to_point(&display_map));
- end = buffer.anchor_before(range.end.to_point(&display_map));
+ let position = display_map
+ .clip_point(position, Bias::Left)
+ .to_offset(&display_map, Bias::Left);
+ let (range, _) = buffer.surrounding_word(position, false);
+ start = buffer.anchor_before(range.start);
+ end = buffer.anchor_before(range.end);
mode = SelectMode::Word(start..end);
auto_scroll = true;
}
@@ -3523,37 +3526,39 @@ impl Editor {
if self.columnar_selection_state.is_some() {
self.select_columns(position, goal_column, &display_map, window, cx);
} else if let Some(mut pending) = self.selections.pending_anchor() {
- let buffer = self.buffer.read(cx).snapshot(cx);
+ let buffer = &display_map.buffer_snapshot;
let head;
let tail;
let mode = self.selections.pending_mode().unwrap();
match &mode {
SelectMode::Character => {
head = position.to_point(&display_map);
- tail = pending.tail().to_point(&buffer);
+ tail = pending.tail().to_point(buffer);
}
SelectMode::Word(original_range) => {
- let original_display_range = original_range.start.to_display_point(&display_map)
- ..original_range.end.to_display_point(&display_map);
- let original_buffer_range = original_display_range.start.to_point(&display_map)
- ..original_display_range.end.to_point(&display_map);
- if movement::is_inside_word(&display_map, position)
- || original_display_range.contains(&position)
+ let offset = display_map
+ .clip_point(position, Bias::Left)
+ .to_offset(&display_map, Bias::Left);
+ let original_range = original_range.to_offset(buffer);
+
+ let head_offset = if buffer.is_inside_word(offset, false)
+ || original_range.contains(&offset)
{
- let word_range = movement::surrounding_word(&display_map, position);
- if word_range.start < original_display_range.start {
- head = word_range.start.to_point(&display_map);
+ let (word_range, _) = buffer.surrounding_word(offset, false);
+ if word_range.start < original_range.start {
+ word_range.start
} else {
- head = word_range.end.to_point(&display_map);
+ word_range.end
}
} else {
- head = position.to_point(&display_map);
- }
+ offset
+ };
- if head <= original_buffer_range.start {
- tail = original_buffer_range.end;
+ head = head_offset.to_point(buffer);
+ if head_offset <= original_range.start {
+ tail = original_range.end.to_point(buffer);
} else {
- tail = original_buffer_range.start;
+ tail = original_range.start.to_point(buffer);
}
}
SelectMode::Line(original_range) => {
@@ -5971,15 +5976,23 @@ impl Editor {
editor.update_in(cx, |editor, window, cx| {
crate::hover_popover::hide_hover(editor, cx);
+ let actions = CodeActionContents::new(
+ resolved_tasks,
+ code_actions,
+ debug_scenarios,
+ task_context.unwrap_or_default(),
+ );
+
+ // Don't show the menu if there are no actions available
+ if actions.is_empty() {
+ cx.notify();
+ return Task::ready(Ok(()));
+ }
+
*editor.context_menu.borrow_mut() =
Some(CodeContextMenu::CodeActions(CodeActionsMenu {
buffer,
- actions: CodeActionContents::new(
- resolved_tasks,
- code_actions,
- debug_scenarios,
- task_context.unwrap_or_default(),
- ),
+ actions,
selected_item: Default::default(),
scroll_handle: UniformListScrollHandle::default(),
deployed_from,
@@ -10075,7 +10088,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| lines.sort())
+ self.manipulate_immutable_lines(window, cx, |lines| lines.sort())
}
pub fn sort_lines_case_insensitive(
@@ -10084,7 +10097,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| {
+ self.manipulate_immutable_lines(window, cx, |lines| {
lines.sort_by_key(|line| line.to_lowercase())
})
}
@@ -10095,7 +10108,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| {
+ self.manipulate_immutable_lines(window, cx, |lines| {
let mut seen = HashSet::default();
lines.retain(|line| seen.insert(line.to_lowercase()));
})
@@ -10107,7 +10120,7 @@ impl Editor {
window: &mut Window,
cx: &mut Context,
) {
- self.manipulate_lines(window, cx, |lines| {
+ self.manipulate_immutable_lines(window, cx, |lines| {
let mut seen = HashSet::default();
lines.retain(|line| seen.insert(*line));
})
@@ -10550,20 +10563,20 @@ impl Editor {
}
pub fn reverse_lines(&mut self, _: &ReverseLines, window: &mut Window, cx: &mut Context) {
- self.manipulate_lines(window, cx, |lines| lines.reverse())
+ self.manipulate_immutable_lines(window, cx, |lines| lines.reverse())
}
pub fn shuffle_lines(&mut self, _: &ShuffleLines, window: &mut Window, cx: &mut Context) {
- self.manipulate_lines(window, cx, |lines| lines.shuffle(&mut thread_rng()))
+ self.manipulate_immutable_lines(window, cx, |lines| lines.shuffle(&mut thread_rng()))
}
- fn manipulate_lines(
+ fn manipulate_lines(
&mut self,
window: &mut Window,
cx: &mut Context,
- mut callback: Fn,
+ mut manipulate: M,
) where
- Fn: FnMut(&mut Vec<&str>),
+ M: FnMut(&str) -> LineManipulationResult,
{
self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx);
@@ -10596,18 +10609,18 @@ impl Editor {
.text_for_range(start_point..end_point)
.collect::();
- let mut lines = text.split('\n').collect_vec();
+ let LineManipulationResult {
+ new_text,
+ line_count_before,
+ line_count_after,
+ } = manipulate(&text);
- let lines_before = lines.len();
- callback(&mut lines);
- let lines_after = lines.len();
-
- edits.push((start_point..end_point, lines.join("\n")));
+ edits.push((start_point..end_point, new_text));
// Selections must change based on added and removed line count
let start_row =
MultiBufferRow(start_point.row + added_lines as u32 - removed_lines as u32);
- let end_row = MultiBufferRow(start_row.0 + lines_after.saturating_sub(1) as u32);
+ let end_row = MultiBufferRow(start_row.0 + line_count_after.saturating_sub(1) as u32);
new_selections.push(Selection {
id: selection.id,
start: start_row,
@@ -10616,10 +10629,10 @@ impl Editor {
reversed: selection.reversed,
});
- if lines_after > lines_before {
- added_lines += lines_after - lines_before;
- } else if lines_before > lines_after {
- removed_lines += lines_before - lines_after;
+ if line_count_after > line_count_before {
+ added_lines += line_count_after - line_count_before;
+ } else if line_count_before > line_count_after {
+ removed_lines += line_count_before - line_count_after;
}
}
@@ -10664,6 +10677,171 @@ impl Editor {
})
}
+ fn manipulate_immutable_lines(
+ &mut self,
+ window: &mut Window,
+ cx: &mut Context,
+ mut callback: Fn,
+ ) where
+ Fn: FnMut(&mut Vec<&str>),
+ {
+ self.manipulate_lines(window, cx, |text| {
+ let mut lines: Vec<&str> = text.split('\n').collect();
+ let line_count_before = lines.len();
+
+ callback(&mut lines);
+
+ LineManipulationResult {
+ new_text: lines.join("\n"),
+ line_count_before,
+ line_count_after: lines.len(),
+ }
+ });
+ }
+
+ fn manipulate_mutable_lines(
+ &mut self,
+ window: &mut Window,
+ cx: &mut Context,
+ mut callback: Fn,
+ ) where
+ Fn: FnMut(&mut Vec>),
+ {
+ self.manipulate_lines(window, cx, |text| {
+ let mut lines: Vec> = text.split('\n').map(Cow::from).collect();
+ let line_count_before = lines.len();
+
+ callback(&mut lines);
+
+ LineManipulationResult {
+ new_text: lines.join("\n"),
+ line_count_before,
+ line_count_after: lines.len(),
+ }
+ });
+ }
+
+ pub fn convert_indentation_to_spaces(
+ &mut self,
+ _: &ConvertIndentationToSpaces,
+ window: &mut Window,
+ cx: &mut Context,
+ ) {
+ let settings = self.buffer.read(cx).language_settings(cx);
+ let tab_size = settings.tab_size.get() as usize;
+
+ self.manipulate_mutable_lines(window, cx, |lines| {
+ // Allocates a reasonably sized scratch buffer once for the whole loop
+ let mut reindented_line = String::with_capacity(MAX_LINE_LEN);
+ // Avoids recomputing spaces that could be inserted many times
+ let space_cache: Vec> = (1..=tab_size)
+ .map(|n| IndentSize::spaces(n as u32).chars().collect())
+ .collect();
+
+ for line in lines.iter_mut().filter(|line| !line.is_empty()) {
+ let mut chars = line.as_ref().chars();
+ let mut col = 0;
+ let mut changed = false;
+
+ while let Some(ch) = chars.next() {
+ match ch {
+ ' ' => {
+ reindented_line.push(' ');
+ col += 1;
+ }
+ '\t' => {
+ // \t are converted to spaces depending on the current column
+ let spaces_len = tab_size - (col % tab_size);
+ reindented_line.extend(&space_cache[spaces_len - 1]);
+ col += spaces_len;
+ changed = true;
+ }
+ _ => {
+ // If we dont append before break, the character is consumed
+ reindented_line.push(ch);
+ break;
+ }
+ }
+ }
+
+ if !changed {
+ reindented_line.clear();
+ continue;
+ }
+ // Append the rest of the line and replace old reference with new one
+ reindented_line.extend(chars);
+ *line = Cow::Owned(reindented_line.clone());
+ reindented_line.clear();
+ }
+ });
+ }
+
+ pub fn convert_indentation_to_tabs(
+ &mut self,
+ _: &ConvertIndentationToTabs,
+ window: &mut Window,
+ cx: &mut Context,
+ ) {
+ let settings = self.buffer.read(cx).language_settings(cx);
+ let tab_size = settings.tab_size.get() as usize;
+
+ self.manipulate_mutable_lines(window, cx, |lines| {
+ // Allocates a reasonably sized buffer once for the whole loop
+ let mut reindented_line = String::with_capacity(MAX_LINE_LEN);
+ // Avoids recomputing spaces that could be inserted many times
+ let space_cache: Vec> = (1..=tab_size)
+ .map(|n| IndentSize::spaces(n as u32).chars().collect())
+ .collect();
+
+ for line in lines.iter_mut().filter(|line| !line.is_empty()) {
+ let mut chars = line.chars();
+ let mut spaces_count = 0;
+ let mut first_non_indent_char = None;
+ let mut changed = false;
+
+ while let Some(ch) = chars.next() {
+ match ch {
+ ' ' => {
+ // Keep track of spaces. Append \t when we reach tab_size
+ spaces_count += 1;
+ changed = true;
+ if spaces_count == tab_size {
+ reindented_line.push('\t');
+ spaces_count = 0;
+ }
+ }
+ '\t' => {
+ reindented_line.push('\t');
+ spaces_count = 0;
+ }
+ _ => {
+ // Dont append it yet, we might have remaining spaces
+ first_non_indent_char = Some(ch);
+ break;
+ }
+ }
+ }
+
+ if !changed {
+ reindented_line.clear();
+ continue;
+ }
+ // Remaining spaces that didn't make a full tab stop
+ if spaces_count > 0 {
+ reindented_line.extend(&space_cache[spaces_count - 1]);
+ }
+ // If we consume an extra character that was not indentation, add it back
+ if let Some(extra_char) = first_non_indent_char {
+ reindented_line.push(extra_char);
+ }
+ // Append the rest of the line and replace old reference with new one
+ reindented_line.extend(chars);
+ *line = Cow::Owned(reindented_line.clone());
+ reindented_line.clear();
+ }
+ });
+ }
+
pub fn convert_to_upper_case(
&mut self,
_: &ConvertToUpperCase,
@@ -10794,7 +10972,6 @@ impl Editor {
where
Fn: FnMut(&str) -> String,
{
- let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let buffer = self.buffer.read(cx).snapshot(cx);
let mut new_selections = Vec::new();
@@ -10805,13 +10982,8 @@ impl Editor {
let selection_is_empty = selection.is_empty();
let (start, end) = if selection_is_empty {
- let word_range = movement::surrounding_word(
- &display_map,
- selection.start.to_display_point(&display_map),
- );
- let start = word_range.start.to_offset(&display_map, Bias::Left);
- let end = word_range.end.to_offset(&display_map, Bias::Left);
- (start, end)
+ let (word_range, _) = buffer.surrounding_word(selection.start, false);
+ (word_range.start, word_range.end)
} else {
(selection.start, selection.end)
};
@@ -13255,12 +13427,10 @@ impl Editor {
let query_match = query_match.unwrap(); // can only fail due to I/O
let offset_range =
start_offset + query_match.start()..start_offset + query_match.end();
- let display_range = offset_range.start.to_display_point(display_map)
- ..offset_range.end.to_display_point(display_map);
if !select_next_state.wordwise
- || (!movement::is_inside_word(display_map, display_range.start)
- && !movement::is_inside_word(display_map, display_range.end))
+ || (!buffer.is_inside_word(offset_range.start, false)
+ && !buffer.is_inside_word(offset_range.end, false))
{
// TODO: This is n^2, because we might check all the selections
if !selections
@@ -13324,12 +13494,9 @@ impl Editor {
if only_carets {
for selection in &mut selections {
- let word_range = movement::surrounding_word(
- display_map,
- selection.start.to_display_point(display_map),
- );
- selection.start = word_range.start.to_offset(display_map, Bias::Left);
- selection.end = word_range.end.to_offset(display_map, Bias::Left);
+ let (word_range, _) = buffer.surrounding_word(selection.start, false);
+ selection.start = word_range.start;
+ selection.end = word_range.end;
selection.goal = SelectionGoal::None;
selection.reversed = false;
self.select_match_ranges(
@@ -13410,18 +13577,22 @@ impl Editor {
} else {
query_match.start()..query_match.end()
};
- let display_range = offset_range.start.to_display_point(&display_map)
- ..offset_range.end.to_display_point(&display_map);
if !select_next_state.wordwise
- || (!movement::is_inside_word(&display_map, display_range.start)
- && !movement::is_inside_word(&display_map, display_range.end))
+ || (!buffer.is_inside_word(offset_range.start, false)
+ && !buffer.is_inside_word(offset_range.end, false))
{
new_selections.push(offset_range.start..offset_range.end);
}
}
select_next_state.done = true;
+
+ if new_selections.is_empty() {
+ log::error!("bug: new_selections is empty in select_all_matches");
+ return Ok(());
+ }
+
self.unfold_ranges(&new_selections.clone(), false, false, cx);
self.change_selections(None, window, cx, |selections| {
selections.select_ranges(new_selections)
@@ -13481,12 +13652,10 @@ impl Editor {
let query_match = query_match.unwrap(); // can only fail due to I/O
let offset_range =
end_offset - query_match.end()..end_offset - query_match.start();
- let display_range = offset_range.start.to_display_point(&display_map)
- ..offset_range.end.to_display_point(&display_map);
if !select_prev_state.wordwise
- || (!movement::is_inside_word(&display_map, display_range.start)
- && !movement::is_inside_word(&display_map, display_range.end))
+ || (!buffer.is_inside_word(offset_range.start, false)
+ && !buffer.is_inside_word(offset_range.end, false))
{
next_selected_range = Some(offset_range);
break;
@@ -13544,12 +13713,9 @@ impl Editor {
if only_carets {
for selection in &mut selections {
- let word_range = movement::surrounding_word(
- &display_map,
- selection.start.to_display_point(&display_map),
- );
- selection.start = word_range.start.to_offset(&display_map, Bias::Left);
- selection.end = word_range.end.to_offset(&display_map, Bias::Left);
+ let (word_range, _) = buffer.surrounding_word(selection.start, false);
+ selection.start = word_range.start;
+ selection.end = word_range.end;
selection.goal = SelectionGoal::None;
selection.reversed = false;
self.select_match_ranges(
@@ -14024,26 +14190,11 @@ impl Editor {
if let Some((node, _)) = buffer.syntax_ancestor(old_range.clone()) {
// manually select word at selection
if ["string_content", "inline"].contains(&node.kind()) {
- let word_range = {
- let display_point = buffer
- .offset_to_point(old_range.start)
- .to_display_point(&display_map);
- let Range { start, end } =
- movement::surrounding_word(&display_map, display_point);
- start.to_point(&display_map).to_offset(&buffer)
- ..end.to_point(&display_map).to_offset(&buffer)
- };
+ let (word_range, _) = buffer.surrounding_word(old_range.start, false);
// ignore if word is already selected
if !word_range.is_empty() && old_range != word_range {
- let last_word_range = {
- let display_point = buffer
- .offset_to_point(old_range.end)
- .to_display_point(&display_map);
- let Range { start, end } =
- movement::surrounding_word(&display_map, display_point);
- start.to_point(&display_map).to_offset(&buffer)
- ..end.to_point(&display_map).to_offset(&buffer)
- };
+ let (last_word_range, _) =
+ buffer.surrounding_word(old_range.end, false);
// only select word if start and end point belongs to same word
if word_range == last_word_range {
selected_larger_node = true;
@@ -16013,7 +16164,7 @@ impl Editor {
})
}
- fn restart_language_server(
+ pub fn restart_language_server(
&mut self,
_: &RestartLanguageServer,
_: &mut Window,
@@ -16024,6 +16175,7 @@ impl Editor {
project.update(cx, |project, cx| {
project.restart_language_servers_for_buffers(
multi_buffer.all_buffers().into_iter().collect(),
+ HashSet::default(),
cx,
);
});
@@ -16031,7 +16183,7 @@ impl Editor {
}
}
- fn stop_language_server(
+ pub fn stop_language_server(
&mut self,
_: &StopLanguageServer,
_: &mut Window,
@@ -16042,6 +16194,7 @@ impl Editor {
project.update(cx, |project, cx| {
project.stop_language_servers_for_buffers(
multi_buffer.all_buffers().into_iter().collect(),
+ HashSet::default(),
cx,
);
cx.emit(project::Event::RefreshInlayHints);
@@ -19167,7 +19320,7 @@ impl Editor {
let current_execution_position = self
.highlighted_rows
.get(&TypeId::of::())
- .and_then(|lines| lines.last().map(|line| line.range.start));
+ .and_then(|lines| lines.last().map(|line| line.range.end));
self.inline_value_cache.refresh_task = cx.spawn(async move |editor, cx| {
let inline_values = editor
@@ -21553,7 +21706,6 @@ impl SemanticsProvider for Entity {
fn inline_values(
&self,
buffer_handle: Entity,
-
range: Range,
cx: &mut App,
) -> Option>>> {
@@ -22964,6 +23116,12 @@ pub struct LineHighlight {
pub type_id: Option,
}
+struct LineManipulationResult {
+ pub new_text: String,
+ pub line_count_before: usize,
+ pub line_count_after: usize,
+}
+
fn render_diff_hunk_controls(
row: u32,
status: &DiffHunkStatus,
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index a6460a50483a2ff249bee7135d3488146caf6d76..3671653e16b0c6452e4c57b9108768b6376b87bf 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -3976,7 +3976,7 @@ async fn test_custom_newlines_cause_no_false_positive_diffs(
}
#[gpui::test]
-async fn test_manipulate_lines_with_single_selection(cx: &mut TestAppContext) {
+async fn test_manipulate_immutable_lines_with_single_selection(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let mut cx = EditorTestContext::new(cx).await;
@@ -4021,8 +4021,8 @@ async fn test_manipulate_lines_with_single_selection(cx: &mut TestAppContext) {
// Skip testing shuffle_line()
- // From here on out, test more complex cases of manipulate_lines() with a single driver method: sort_lines_case_sensitive()
- // Since all methods calling manipulate_lines() are doing the exact same general thing (reordering lines)
+ // From here on out, test more complex cases of manipulate_immutable_lines() with a single driver method: sort_lines_case_sensitive()
+ // Since all methods calling manipulate_immutable_lines() are doing the exact same general thing (reordering lines)
// Don't manipulate when cursor is on single line, but expand the selection
cx.set_state(indoc! {"
@@ -4089,7 +4089,7 @@ async fn test_manipulate_lines_with_single_selection(cx: &mut TestAppContext) {
bbˇ»b
"});
cx.update_editor(|e, window, cx| {
- e.manipulate_lines(window, cx, |lines| lines.push("added_line"))
+ e.manipulate_immutable_lines(window, cx, |lines| lines.push("added_line"))
});
cx.assert_editor_state(indoc! {"
«aaa
@@ -4103,7 +4103,7 @@ async fn test_manipulate_lines_with_single_selection(cx: &mut TestAppContext) {
bbbˇ»
"});
cx.update_editor(|e, window, cx| {
- e.manipulate_lines(window, cx, |lines| {
+ e.manipulate_immutable_lines(window, cx, |lines| {
lines.pop();
})
});
@@ -4117,7 +4117,7 @@ async fn test_manipulate_lines_with_single_selection(cx: &mut TestAppContext) {
bbbˇ»
"});
cx.update_editor(|e, window, cx| {
- e.manipulate_lines(window, cx, |lines| {
+ e.manipulate_immutable_lines(window, cx, |lines| {
lines.drain(..);
})
});
@@ -4217,7 +4217,7 @@ async fn test_unique_lines_single_selection(cx: &mut TestAppContext) {
}
#[gpui::test]
-async fn test_manipulate_lines_with_multi_selection(cx: &mut TestAppContext) {
+async fn test_manipulate_immutable_lines_with_multi_selection(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let mut cx = EditorTestContext::new(cx).await;
@@ -4277,7 +4277,7 @@ async fn test_manipulate_lines_with_multi_selection(cx: &mut TestAppContext) {
aaaˇ»aa
"});
cx.update_editor(|e, window, cx| {
- e.manipulate_lines(window, cx, |lines| lines.push("added line"))
+ e.manipulate_immutable_lines(window, cx, |lines| lines.push("added line"))
});
cx.assert_editor_state(indoc! {"
«2
@@ -4298,7 +4298,7 @@ async fn test_manipulate_lines_with_multi_selection(cx: &mut TestAppContext) {
aaaˇ»aa
"});
cx.update_editor(|e, window, cx| {
- e.manipulate_lines(window, cx, |lines| {
+ e.manipulate_immutable_lines(window, cx, |lines| {
lines.pop();
})
});
@@ -4309,6 +4309,222 @@ async fn test_manipulate_lines_with_multi_selection(cx: &mut TestAppContext) {
"});
}
+#[gpui::test]
+async fn test_convert_indentation_to_spaces(cx: &mut TestAppContext) {
+ init_test(cx, |settings| {
+ settings.defaults.tab_size = NonZeroU32::new(3)
+ });
+
+ let mut cx = EditorTestContext::new(cx).await;
+
+ // MULTI SELECTION
+ // Ln.1 "«" tests empty lines
+ // Ln.9 tests just leading whitespace
+ cx.set_state(indoc! {"
+ «
+ abc // No indentationˇ»
+ «\tabc // 1 tabˇ»
+ \t\tabc « ˇ» // 2 tabs
+ \t ab«c // Tab followed by space
+ \tabc // Space followed by tab (3 spaces should be the result)
+ \t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
+ abˇ»ˇc ˇ ˇ // Already space indented«
+ \t
+ \tabc\tdef // Only the leading tab is manipulatedˇ»
+ "});
+ cx.update_editor(|e, window, cx| {
+ e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
+ });
+ cx.assert_editor_state(indoc! {"
+ «
+ abc // No indentation
+ abc // 1 tab
+ abc // 2 tabs
+ abc // Tab followed by space
+ abc // Space followed by tab (3 spaces should be the result)
+ abc // Mixed indentation (tab conversion depends on the column)
+ abc // Already space indented
+
+ abc\tdef // Only the leading tab is manipulatedˇ»
+ "});
+
+ // Test on just a few lines, the others should remain unchanged
+ // Only lines (3, 5, 10, 11) should change
+ cx.set_state(indoc! {"
+
+ abc // No indentation
+ \tabcˇ // 1 tab
+ \t\tabc // 2 tabs
+ \t abcˇ // Tab followed by space
+ \tabc // Space followed by tab (3 spaces should be the result)
+ \t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
+ abc // Already space indented
+ «\t
+ \tabc\tdef // Only the leading tab is manipulatedˇ»
+ "});
+ cx.update_editor(|e, window, cx| {
+ e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
+ });
+ cx.assert_editor_state(indoc! {"
+
+ abc // No indentation
+ « abc // 1 tabˇ»
+ \t\tabc // 2 tabs
+ « abc // Tab followed by spaceˇ»
+ \tabc // Space followed by tab (3 spaces should be the result)
+ \t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
+ abc // Already space indented
+ «
+ abc\tdef // Only the leading tab is manipulatedˇ»
+ "});
+
+ // SINGLE SELECTION
+ // Ln.1 "«" tests empty lines
+ // Ln.9 tests just leading whitespace
+ cx.set_state(indoc! {"
+ «
+ abc // No indentation
+ \tabc // 1 tab
+ \t\tabc // 2 tabs
+ \t abc // Tab followed by space
+ \tabc // Space followed by tab (3 spaces should be the result)
+ \t \t \t \tabc // Mixed indentation (tab conversion depends on the column)
+ abc // Already space indented
+ \t
+ \tabc\tdef // Only the leading tab is manipulatedˇ»
+ "});
+ cx.update_editor(|e, window, cx| {
+ e.convert_indentation_to_spaces(&ConvertIndentationToSpaces, window, cx);
+ });
+ cx.assert_editor_state(indoc! {"
+ «
+ abc // No indentation
+ abc // 1 tab
+ abc // 2 tabs
+ abc // Tab followed by space
+ abc // Space followed by tab (3 spaces should be the result)
+ abc // Mixed indentation (tab conversion depends on the column)
+ abc // Already space indented
+
+ abc\tdef // Only the leading tab is manipulatedˇ»
+ "});
+}
+
+#[gpui::test]
+async fn test_convert_indentation_to_tabs(cx: &mut TestAppContext) {
+ init_test(cx, |settings| {
+ settings.defaults.tab_size = NonZeroU32::new(3)
+ });
+
+ let mut cx = EditorTestContext::new(cx).await;
+
+ // MULTI SELECTION
+ // Ln.1 "«" tests empty lines
+ // Ln.11 tests just leading whitespace
+ cx.set_state(indoc! {"
+ «
+ abˇ»ˇc // No indentation
+ abc ˇ ˇ // 1 space (< 3 so dont convert)
+ abc « // 2 spaces (< 3 so dont convert)
+ abc // 3 spaces (convert)
+ abc ˇ» // 5 spaces (1 tab + 2 spaces)
+ «\tˇ»\t«\tˇ»abc // Already tab indented
+ «\t abc // Tab followed by space
+ \tabc // Space followed by tab (should be consumed due to tab)
+ \t \t \t \tabc // Mixed indentation (first 3 spaces are consumed, the others are converted)
+ \tˇ» «\t
+ abcˇ» \t ˇˇˇ // Only the leading spaces should be converted
+ "});
+ cx.update_editor(|e, window, cx| {
+ e.convert_indentation_to_tabs(&ConvertIndentationToTabs, window, cx);
+ });
+ cx.assert_editor_state(indoc! {"
+ «
+ abc // No indentation
+ abc // 1 space (< 3 so dont convert)
+ abc // 2 spaces (< 3 so dont convert)
+ \tabc // 3 spaces (convert)
+ \t abc // 5 spaces (1 tab + 2 spaces)
+ \t\t\tabc // Already tab indented
+ \t abc // Tab followed by space
+ \tabc // Space followed by tab (should be consumed due to tab)
+ \t\t\t\t\tabc // Mixed indentation (first 3 spaces are consumed, the others are converted)
+ \t\t\t
+ \tabc \t // Only the leading spaces should be convertedˇ»
+ "});
+
+ // Test on just a few lines, the other should remain unchanged
+ // Only lines (4, 8, 11, 12) should change
+ cx.set_state(indoc! {"
+
+ abc // No indentation
+ abc // 1 space (< 3 so dont convert)
+ abc // 2 spaces (< 3 so dont convert)
+ « abc // 3 spaces (convert)ˇ»
+ abc // 5 spaces (1 tab + 2 spaces)
+ \t\t\tabc // Already tab indented
+ \t abc // Tab followed by space
+ \tabc ˇ // Space followed by tab (should be consumed due to tab)
+ \t\t \tabc // Mixed indentation
+ \t \t \t \tabc // Mixed indentation
+ \t \tˇ
+ « abc \t // Only the leading spaces should be convertedˇ»
+ "});
+ cx.update_editor(|e, window, cx| {
+ e.convert_indentation_to_tabs(&ConvertIndentationToTabs, window, cx);
+ });
+ cx.assert_editor_state(indoc! {"
+
+ abc // No indentation
+ abc // 1 space (< 3 so dont convert)
+ abc // 2 spaces (< 3 so dont convert)
+ «\tabc // 3 spaces (convert)ˇ»
+ abc // 5 spaces (1 tab + 2 spaces)
+ \t\t\tabc // Already tab indented
+ \t abc // Tab followed by space
+ «\tabc // Space followed by tab (should be consumed due to tab)ˇ»
+ \t\t \tabc // Mixed indentation
+ \t \t \t \tabc // Mixed indentation
+ «\t\t\t
+ \tabc \t // Only the leading spaces should be convertedˇ»
+ "});
+
+ // SINGLE SELECTION
+ // Ln.1 "«" tests empty lines
+ // Ln.11 tests just leading whitespace
+ cx.set_state(indoc! {"
+ «
+ abc // No indentation
+ abc // 1 space (< 3 so dont convert)
+ abc // 2 spaces (< 3 so dont convert)
+ abc // 3 spaces (convert)
+ abc // 5 spaces (1 tab + 2 spaces)
+ \t\t\tabc // Already tab indented
+ \t abc // Tab followed by space
+ \tabc // Space followed by tab (should be consumed due to tab)
+ \t \t \t \tabc // Mixed indentation (first 3 spaces are consumed, the others are converted)
+ \t \t
+ abc \t // Only the leading spaces should be convertedˇ»
+ "});
+ cx.update_editor(|e, window, cx| {
+ e.convert_indentation_to_tabs(&ConvertIndentationToTabs, window, cx);
+ });
+ cx.assert_editor_state(indoc! {"
+ «
+ abc // No indentation
+ abc // 1 space (< 3 so dont convert)
+ abc // 2 spaces (< 3 so dont convert)
+ \tabc // 3 spaces (convert)
+ \t abc // 5 spaces (1 tab + 2 spaces)
+ \t\t\tabc // Already tab indented
+ \t abc // Tab followed by space
+ \tabc // Space followed by tab (should be consumed due to tab)
+ \t\t\t\t\tabc // Mixed indentation (first 3 spaces are consumed, the others are converted)
+ \t\t\t
+ \tabc \t // Only the leading spaces should be convertedˇ»
+ "});
+}
+
#[gpui::test]
async fn test_toggle_case(cx: &mut TestAppContext) {
init_test(cx, |_| {});
@@ -6667,6 +6883,15 @@ async fn test_select_all_matches(cx: &mut TestAppContext) {
cx.update_editor(|e, window, cx| e.select_all_matches(&SelectAllMatches, window, cx))
.unwrap();
cx.assert_editor_state("abc\n« ˇ»abc\nabc");
+
+ // Test with a single word and clip_at_line_ends=true (#29823)
+ cx.set_state("aˇbc");
+ cx.update_editor(|e, window, cx| {
+ e.set_clip_at_line_ends(true, cx);
+ e.select_all_matches(&SelectAllMatches, window, cx).unwrap();
+ e.set_clip_at_line_ends(false, cx);
+ });
+ cx.assert_editor_state("«abcˇ»");
}
#[gpui::test]
@@ -15440,7 +15665,7 @@ async fn test_completions_default_resolve_data_handling(cx: &mut TestAppContext)
// Completions that have already been resolved are skipped.
assert_eq!(
*resolved_items.lock(),
- items[items.len() - 16..items.len() - 4]
+ items[items.len() - 17..items.len() - 4]
.iter()
.cloned()
.map(|mut item| {
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index b002a96de8d0e1f615e865b7908c19a5f4bcbbb4..602a0579b3a23b4449d08a732580ac261bd841c2 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -230,6 +230,8 @@ impl EditorElement {
register_action(editor, window, Editor::reverse_lines);
register_action(editor, window, Editor::shuffle_lines);
register_action(editor, window, Editor::toggle_case);
+ register_action(editor, window, Editor::convert_indentation_to_spaces);
+ register_action(editor, window, Editor::convert_indentation_to_tabs);
register_action(editor, window, Editor::convert_to_upper_case);
register_action(editor, window, Editor::convert_to_lower_case);
register_action(editor, window, Editor::convert_to_title_case);
diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs
index e4167ee68ebf7e069d26609385b4063e21c3f09c..b9b7cb2e58c56cb3b1e14e1c52aa7b8b38f510b6 100644
--- a/crates/editor/src/movement.rs
+++ b/crates/editor/src/movement.rs
@@ -2,7 +2,7 @@
//! in editor given a given motion (e.g. it handles converting a "move left" command into coordinates in editor). It is exposed mostly for use by vim crate.
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
-use crate::{CharKind, DisplayRow, EditorStyle, ToOffset, ToPoint, scroll::ScrollAnchor};
+use crate::{DisplayRow, EditorStyle, ToOffset, ToPoint, scroll::ScrollAnchor};
use gpui::{Pixels, WindowTextSystem};
use language::Point;
use multi_buffer::{MultiBufferRow, MultiBufferSnapshot};
@@ -721,38 +721,6 @@ pub fn chars_before(
})
}
-pub(crate) fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
- let raw_point = point.to_point(map);
- let classifier = map.buffer_snapshot.char_classifier_at(raw_point);
- let ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
- let text = &map.buffer_snapshot;
- let next_char_kind = text.chars_at(ix).next().map(|c| classifier.kind(c));
- let prev_char_kind = text
- .reversed_chars_at(ix)
- .next()
- .map(|c| classifier.kind(c));
- prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
-}
-
-pub(crate) fn surrounding_word(
- map: &DisplaySnapshot,
- position: DisplayPoint,
-) -> Range {
- let position = map
- .clip_point(position, Bias::Left)
- .to_offset(map, Bias::Left);
- let (range, _) = map.buffer_snapshot.surrounding_word(position, false);
- let start = range
- .start
- .to_point(&map.buffer_snapshot)
- .to_display_point(map);
- let end = range
- .end
- .to_point(&map.buffer_snapshot)
- .to_display_point(map);
- start..end
-}
-
/// Returns a list of lines (represented as a [`DisplayPoint`] range) contained
/// within a passed range.
///
@@ -1091,30 +1059,6 @@ mod tests {
});
}
- #[gpui::test]
- fn test_surrounding_word(cx: &mut gpui::App) {
- init_test(cx);
-
- fn assert(marked_text: &str, cx: &mut gpui::App) {
- let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
- assert_eq!(
- surrounding_word(&snapshot, display_points[1]),
- display_points[0]..display_points[2],
- "{}",
- marked_text
- );
- }
-
- assert("ˇˇloremˇ ipsum", cx);
- assert("ˇloˇremˇ ipsum", cx);
- assert("ˇloremˇˇ ipsum", cx);
- assert("loremˇ ˇ ˇipsum", cx);
- assert("lorem\nˇˇˇ\nipsum", cx);
- assert("lorem\nˇˇipsumˇ", cx);
- assert("loremˇ,ˇˇ ipsum", cx);
- assert("ˇloremˇˇ, ipsum", cx);
- }
-
#[gpui::test]
async fn test_move_up_and_down_with_excerpts(cx: &mut gpui::TestAppContext) {
cx.update(|cx| {
diff --git a/crates/eval/src/eval.rs b/crates/eval/src/eval.rs
index e5132b0f33c6494807c65c2ed6df95e3e2d016e8..5e8dd8961c8c3416fa84303eff722c22c31738e6 100644
--- a/crates/eval/src/eval.rs
+++ b/crates/eval/src/eval.rs
@@ -417,7 +417,7 @@ pub fn init(cx: &mut App) -> Arc {
debug_adapter_extension::init(extension_host_proxy.clone(), cx);
language_extension::init(extension_host_proxy.clone(), languages.clone());
language_model::init(client.clone(), cx);
- language_models::init(user_store.clone(), client.clone(), fs.clone(), cx);
+ language_models::init(user_store.clone(), client.clone(), cx);
languages::init(languages.clone(), node_runtime.clone(), cx);
prompt_store::init(cx);
terminal_view::init(cx);
diff --git a/crates/eval/src/instance.rs b/crates/eval/src/instance.rs
index b6802537c65974cd7284159cdb3a7a379a2e2ce0..bb66a04e1f07f1f070d9c4c6536f260a05a11bb6 100644
--- a/crates/eval/src/instance.rs
+++ b/crates/eval/src/instance.rs
@@ -1030,6 +1030,7 @@ pub fn response_events_to_markdown(
Ok(LanguageModelCompletionEvent::Thinking { text, .. }) => {
thinking_buffer.push_str(text);
}
+ Ok(LanguageModelCompletionEvent::RedactedThinking { .. }) => {}
Ok(LanguageModelCompletionEvent::Stop(reason)) => {
flush_buffers(&mut response, &mut text_buffer, &mut thinking_buffer);
response.push_str(&format!("**Stop**: {:?}\n\n", reason));
@@ -1126,6 +1127,7 @@ impl ThreadDialog {
// Skip these
Ok(LanguageModelCompletionEvent::UsageUpdate(_))
+ | Ok(LanguageModelCompletionEvent::RedactedThinking { .. })
| Ok(LanguageModelCompletionEvent::StatusUpdate { .. })
| Ok(LanguageModelCompletionEvent::StartMessage { .. })
| Ok(LanguageModelCompletionEvent::Stop(_)) => {}
diff --git a/crates/extension_host/src/extension_store_test.rs b/crates/extension_host/src/extension_store_test.rs
index cea3f0dbc3262211d2f28941e3daefa69da15d73..cfe97f167553dfb2dba880bfdfd9eb82399b5492 100644
--- a/crates/extension_host/src/extension_store_test.rs
+++ b/crates/extension_host/src/extension_store_test.rs
@@ -4,13 +4,13 @@ use crate::{
GrammarManifestEntry, RELOAD_DEBOUNCE_DURATION, SchemaVersion,
};
use async_compression::futures::bufread::GzipEncoder;
-use collections::BTreeMap;
+use collections::{BTreeMap, HashSet};
use extension::ExtensionHostProxy;
use fs::{FakeFs, Fs, RealFs};
use futures::{AsyncReadExt, StreamExt, io::BufReader};
use gpui::{AppContext as _, SemanticVersion, TestAppContext};
use http_client::{FakeHttpClient, Response};
-use language::{BinaryStatus, LanguageMatcher, LanguageRegistry, LanguageServerStatusUpdate};
+use language::{BinaryStatus, LanguageMatcher, LanguageRegistry};
use lsp::LanguageServerName;
use node_runtime::NodeRuntime;
use parking_lot::Mutex;
@@ -720,20 +720,22 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
status_updates.next().await.unwrap(),
status_updates.next().await.unwrap(),
status_updates.next().await.unwrap(),
+ status_updates.next().await.unwrap(),
],
[
(
LanguageServerName::new_static("gleam"),
- LanguageServerStatusUpdate::Binary(BinaryStatus::CheckingForUpdate)
+ BinaryStatus::Starting
),
(
LanguageServerName::new_static("gleam"),
- LanguageServerStatusUpdate::Binary(BinaryStatus::Downloading)
+ BinaryStatus::CheckingForUpdate
),
(
LanguageServerName::new_static("gleam"),
- LanguageServerStatusUpdate::Binary(BinaryStatus::None)
- )
+ BinaryStatus::Downloading
+ ),
+ (LanguageServerName::new_static("gleam"), BinaryStatus::None)
]
);
@@ -794,7 +796,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
// Start a new instance of the language server.
project.update(cx, |project, cx| {
- project.restart_language_servers_for_buffers(vec![buffer.clone()], cx)
+ project.restart_language_servers_for_buffers(vec![buffer.clone()], HashSet::default(), cx)
});
cx.executor().run_until_parked();
@@ -816,7 +818,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
cx.executor().run_until_parked();
project.update(cx, |project, cx| {
- project.restart_language_servers_for_buffers(vec![buffer.clone()], cx)
+ project.restart_language_servers_for_buffers(vec![buffer.clone()], HashSet::default(), cx)
});
// The extension re-fetches the latest version of the language server.
diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs
index a85e48226b7aacd9c29df89691c4bf620c86e7cf..f8f9ae1977687296790a562711c286e2fce026e4 100644
--- a/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs
+++ b/crates/extension_host/src/wasm_host/wit/since_v0_6_0.rs
@@ -945,7 +945,10 @@ impl ExtensionImports for WasmState {
.get(key.as_str())
})
.cloned()
- .context("Failed to get context server configuration")?;
+ .unwrap_or_else(|| {
+ project::project_settings::ContextServerSettings::default_extension(
+ )
+ });
match settings {
project::project_settings::ContextServerSettings::Custom {
diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs
index bfdb8fc4f482f4d6f7965d4d0940eaedfe8cca7d..5096be673342f2cfa365e8806be330bfc3bd26cf 100644
--- a/crates/file_finder/src/file_finder.rs
+++ b/crates/file_finder/src/file_finder.rs
@@ -939,20 +939,47 @@ impl FileFinderDelegate {
matches.into_iter(),
extend_old_matches,
);
- let worktree = self.project.read(cx).visible_worktrees(cx).next();
- let filename = query.raw_query.to_string();
- let path = Path::new(&filename);
+ let filename = &query.raw_query;
+ let mut query_path = Path::new(filename);
// add option of creating new file only if path is relative
- if let Some(worktree) = worktree {
+ let available_worktree = self
+ .project
+ .read(cx)
+ .visible_worktrees(cx)
+ .filter(|worktree| !worktree.read(cx).is_single_file())
+ .collect::>();
+ let worktree_count = available_worktree.len();
+ let mut expect_worktree = available_worktree.first().cloned();
+ for worktree in available_worktree {
+ let worktree_root = worktree
+ .read(cx)
+ .abs_path()
+ .file_name()
+ .map_or(String::new(), |f| f.to_string_lossy().to_string());
+ if worktree_count > 1 && query_path.starts_with(&worktree_root) {
+ query_path = query_path
+ .strip_prefix(&worktree_root)
+ .unwrap_or(query_path);
+ expect_worktree = Some(worktree);
+ break;
+ }
+ }
+
+ if let Some(FoundPath { ref project, .. }) = self.currently_opened_path {
+ let worktree_id = project.worktree_id;
+ expect_worktree = self.project.read(cx).worktree_for_id(worktree_id, cx);
+ }
+
+ if let Some(worktree) = expect_worktree {
let worktree = worktree.read(cx);
- if path.is_relative()
- && worktree.entry_for_path(&path).is_none()
+ if query_path.is_relative()
+ && worktree.entry_for_path(&query_path).is_none()
&& !filename.ends_with("/")
{
self.matches.matches.push(Match::CreateNew(ProjectPath {
worktree_id: worktree.id(),
- path: Arc::from(path),
+ path: Arc::from(query_path),
}));
}
}
diff --git a/crates/file_finder/src/file_finder_tests.rs b/crates/file_finder/src/file_finder_tests.rs
index dbb6d45f916c7251e181c414d315d197aed7bd0a..db259ccef854b1d3c5c4fae3bc9ebad08e398891 100644
--- a/crates/file_finder/src/file_finder_tests.rs
+++ b/crates/file_finder/src/file_finder_tests.rs
@@ -881,6 +881,148 @@ async fn test_single_file_worktrees(cx: &mut TestAppContext) {
picker.update(cx, |f, _| assert_eq!(f.delegate.matches.len(), 0));
}
+#[gpui::test]
+async fn test_create_file_for_multiple_worktrees(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/roota"),
+ json!({ "the-parent-dira": { "filea": "" } }),
+ )
+ .await;
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/rootb"),
+ json!({ "the-parent-dirb": { "fileb": "" } }),
+ )
+ .await;
+
+ let project = Project::test(
+ app_state.fs.clone(),
+ [path!("/roota").as_ref(), path!("/rootb").as_ref()],
+ cx,
+ )
+ .await;
+
+ let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
+ let (_worktree_id1, worktree_id2) = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::>();
+ (
+ WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize),
+ WorktreeId::from_usize(worktrees[1].entity_id().as_u64() as usize),
+ )
+ });
+
+ let b_path = ProjectPath {
+ worktree_id: worktree_id2,
+ path: Arc::from(Path::new(path!("the-parent-dirb/fileb"))),
+ };
+ workspace
+ .update_in(cx, |workspace, window, cx| {
+ workspace.open_path(b_path, None, true, window, cx)
+ })
+ .await
+ .unwrap();
+
+ let finder = open_file_picker(&workspace, cx);
+
+ finder
+ .update_in(cx, |f, window, cx| {
+ f.delegate.spawn_search(
+ test_path_position(path!("the-parent-dirb/filec")),
+ window,
+ cx,
+ )
+ })
+ .await;
+ cx.run_until_parked();
+ finder.update_in(cx, |picker, window, cx| {
+ assert_eq!(picker.delegate.matches.len(), 1);
+ picker.delegate.confirm(false, window, cx)
+ });
+ cx.run_until_parked();
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::(cx).unwrap();
+ let project_path = active_editor.read(cx).project_path(cx);
+ assert_eq!(
+ project_path,
+ Some(ProjectPath {
+ worktree_id: worktree_id2,
+ path: Arc::from(Path::new(path!("the-parent-dirb/filec")))
+ })
+ );
+ });
+}
+
+#[gpui::test]
+async fn test_create_file_no_focused_with_multiple_worktrees(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/roota"),
+ json!({ "the-parent-dira": { "filea": "" } }),
+ )
+ .await;
+
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/rootb"),
+ json!({ "the-parent-dirb": { "fileb": "" } }),
+ )
+ .await;
+
+ let project = Project::test(
+ app_state.fs.clone(),
+ [path!("/roota").as_ref(), path!("/rootb").as_ref()],
+ cx,
+ )
+ .await;
+
+ let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
+ let (_worktree_id1, worktree_id2) = cx.read(|cx| {
+ let worktrees = workspace.read(cx).worktrees(cx).collect::>();
+ (
+ WorktreeId::from_usize(worktrees[0].entity_id().as_u64() as usize),
+ WorktreeId::from_usize(worktrees[1].entity_id().as_u64() as usize),
+ )
+ });
+
+ let finder = open_file_picker(&workspace, cx);
+
+ finder
+ .update_in(cx, |f, window, cx| {
+ f.delegate
+ .spawn_search(test_path_position(path!("rootb/filec")), window, cx)
+ })
+ .await;
+ cx.run_until_parked();
+ finder.update_in(cx, |picker, window, cx| {
+ assert_eq!(picker.delegate.matches.len(), 1);
+ picker.delegate.confirm(false, window, cx)
+ });
+ cx.run_until_parked();
+ cx.read(|cx| {
+ let active_editor = workspace.read(cx).active_item_as::(cx).unwrap();
+ let project_path = active_editor.read(cx).project_path(cx);
+ assert_eq!(
+ project_path,
+ Some(ProjectPath {
+ worktree_id: worktree_id2,
+ path: Arc::from(Path::new("filec"))
+ })
+ );
+ });
+}
+
#[gpui::test]
async fn test_path_distance_ordering(cx: &mut TestAppContext) {
let app_state = init_test(cx);
diff --git a/crates/git_ui/src/branch_picker.rs b/crates/git_ui/src/branch_picker.rs
index a4b77eff7487e62262d6f4e71c1bb7cc792610eb..635876dace889bde4f461a9feee9c8df4d1c24cc 100644
--- a/crates/git_ui/src/branch_picker.rs
+++ b/crates/git_ui/src/branch_picker.rs
@@ -413,10 +413,6 @@ impl PickerDelegate for BranchListDelegate {
cx.emit(DismissEvent);
}
- fn render_header(&self, _: &mut Window, _cx: &mut Context>) -> Option {
- None
- }
-
fn render_match(
&self,
ix: usize,
diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs
index 3cc94f84d325e89f2f5f6a9322460b5de07f45ca..dce3a52e0a567301f4b3b387ee71f89014ef5083 100644
--- a/crates/git_ui/src/git_panel.rs
+++ b/crates/git_ui/src/git_panel.rs
@@ -83,7 +83,6 @@ actions!(
FocusEditor,
FocusChanges,
ToggleFillCoAuthors,
- GenerateCommitMessage
]
);
diff --git a/crates/git_ui/src/repository_selector.rs b/crates/git_ui/src/repository_selector.rs
index 322e623e60ecbce91c86eab95fb740e7621eb1b0..b5865e9a8578e24dffb129eb373b718219344e1c 100644
--- a/crates/git_ui/src/repository_selector.rs
+++ b/crates/git_ui/src/repository_selector.rs
@@ -1,6 +1,4 @@
-use gpui::{
- AnyElement, App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Task, WeakEntity,
-};
+use gpui::{App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Task, WeakEntity};
use itertools::Itertools;
use picker::{Picker, PickerDelegate};
use project::{Project, git_store::Repository};
@@ -207,15 +205,6 @@ impl PickerDelegate for RepositorySelectorDelegate {
.ok();
}
- fn render_header(
- &self,
- _window: &mut Window,
- _cx: &mut Context>,
- ) -> Option {
- // TODO: Implement header rendering if needed
- None
- }
-
fn render_match(
&self,
ix: usize,
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs
index 109d5e7454c4a2b0bcb276243f7f5a6cc072efce..1853e6e93488e0cba9db2380594eb3f28b4a0132 100644
--- a/crates/gpui/src/app.rs
+++ b/crates/gpui/src/app.rs
@@ -909,7 +909,7 @@ impl App {
})
.collect::>()
{
- self.update_window(window, |_, window, cx| window.draw(cx))
+ self.update_window(window, |_, window, cx| window.draw(cx).clear())
.unwrap();
}
diff --git a/crates/gpui/src/arena.rs b/crates/gpui/src/arena.rs
index f30f4b6480cc7487ed8a384306c632cd188531d8..2448746a8867b88cc7e6b22b27a6ef5eae6c40aa 100644
--- a/crates/gpui/src/arena.rs
+++ b/crates/gpui/src/arena.rs
@@ -1,5 +1,5 @@
use std::{
- alloc,
+ alloc::{self, handle_alloc_error},
cell::Cell,
ops::{Deref, DerefMut},
ptr,
@@ -20,43 +20,98 @@ impl Drop for ArenaElement {
}
}
-pub struct Arena {
+struct Chunk {
start: *mut u8,
end: *mut u8,
offset: *mut u8,
- elements: Vec,
- valid: Rc>,
}
-impl Arena {
- pub fn new(size_in_bytes: usize) -> Self {
+impl Drop for Chunk {
+ fn drop(&mut self) {
unsafe {
- let layout = alloc::Layout::from_size_align(size_in_bytes, 1).unwrap();
+ let chunk_size = self.end.offset_from_unsigned(self.start);
+ // this never fails as it succeeded during allocation
+ let layout = alloc::Layout::from_size_align(chunk_size, 1).unwrap();
+ alloc::dealloc(self.start, layout);
+ }
+ }
+}
+
+impl Chunk {
+ fn new(chunk_size: usize) -> Self {
+ unsafe {
+ // this only fails if chunk_size is unreasonably huge
+ let layout = alloc::Layout::from_size_align(chunk_size, 1).unwrap();
let start = alloc::alloc(layout);
- let end = start.add(size_in_bytes);
+ if start.is_null() {
+ handle_alloc_error(layout);
+ }
+ let end = start.add(chunk_size);
Self {
start,
end,
offset: start,
- elements: Vec::new(),
- valid: Rc::new(Cell::new(true)),
}
}
}
- pub fn len(&self) -> usize {
- self.offset as usize - self.start as usize
+ fn allocate(&mut self, layout: alloc::Layout) -> Option<*mut u8> {
+ unsafe {
+ let aligned = self.offset.add(self.offset.align_offset(layout.align()));
+ let next = aligned.add(layout.size());
+
+ if next <= self.end {
+ self.offset = next;
+ Some(aligned)
+ } else {
+ None
+ }
+ }
+ }
+
+ fn reset(&mut self) {
+ self.offset = self.start;
+ }
+}
+
+pub struct Arena {
+ chunks: Vec,
+ elements: Vec,
+ valid: Rc>,
+ current_chunk_index: usize,
+ chunk_size: usize,
+}
+
+impl Drop for Arena {
+ fn drop(&mut self) {
+ self.clear();
+ }
+}
+
+impl Arena {
+ pub fn new(chunk_size: usize) -> Self {
+ assert!(chunk_size > 0);
+ Self {
+ chunks: vec![Chunk::new(chunk_size)],
+ elements: Vec::new(),
+ valid: Rc::new(Cell::new(true)),
+ current_chunk_index: 0,
+ chunk_size,
+ }
}
pub fn capacity(&self) -> usize {
- self.end as usize - self.start as usize
+ self.chunks.len() * self.chunk_size
}
pub fn clear(&mut self) {
self.valid.set(false);
self.valid = Rc::new(Cell::new(true));
self.elements.clear();
- self.offset = self.start;
+ for chunk_index in 0..=self.current_chunk_index {
+ self.chunks[chunk_index].reset();
+ }
+ self.current_chunk_index = 0;
}
#[inline(always)]
@@ -79,33 +134,45 @@ impl Arena {
unsafe {
let layout = alloc::Layout::new::();
- let offset = self.offset.add(self.offset.align_offset(layout.align()));
- let next_offset = offset.add(layout.size());
- assert!(next_offset <= self.end, "not enough space in Arena");
-
- let result = ArenaBox {
- ptr: offset.cast(),
- valid: self.valid.clone(),
+ let mut current_chunk = &mut self.chunks[self.current_chunk_index];
+ let ptr = if let Some(ptr) = current_chunk.allocate(layout) {
+ ptr
+ } else {
+ self.current_chunk_index += 1;
+ if self.current_chunk_index >= self.chunks.len() {
+ self.chunks.push(Chunk::new(self.chunk_size));
+ assert_eq!(self.current_chunk_index, self.chunks.len() - 1);
+ log::info!(
+ "increased element arena capacity to {}kb",
+ self.capacity() / 1024,
+ );
+ }
+ current_chunk = &mut self.chunks[self.current_chunk_index];
+ if let Some(ptr) = current_chunk.allocate(layout) {
+ ptr
+ } else {
+ panic!(
+ "Arena chunk_size of {} is too small to allocate {} bytes",
+ self.chunk_size,
+ layout.size()
+ );
+ }
};
- inner_writer(result.ptr, f);
+ inner_writer(ptr.cast(), f);
self.elements.push(ArenaElement {
- value: offset,
+ value: ptr,
drop: drop::,
});
- self.offset = next_offset;
- result
+ ArenaBox {
+ ptr: ptr.cast(),
+ valid: self.valid.clone(),
+ }
}
}
}
-impl Drop for Arena {
- fn drop(&mut self) {
- self.clear();
- }
-}
-
pub struct ArenaBox {
ptr: *mut T,
valid: Rc>,
@@ -215,13 +282,17 @@ mod tests {
}
#[test]
- #[should_panic(expected = "not enough space in Arena")]
- fn test_arena_overflow() {
- let mut arena = Arena::new(16);
+ fn test_arena_grow() {
+ let mut arena = Arena::new(8);
arena.alloc(|| 1u64);
arena.alloc(|| 2u64);
- // This should panic.
- arena.alloc(|| 3u64);
+
+ assert_eq!(arena.capacity(), 16);
+
+ arena.alloc(|| 3u32);
+ arena.alloc(|| 4u32);
+
+ assert_eq!(arena.capacity(), 24);
}
#[test]
diff --git a/crates/gpui/src/keymap/binding.rs b/crates/gpui/src/keymap/binding.rs
index cbe934212ffaf312a7679cc814669cc4baa78ed1..ffc4656ff7d30e43c553d7f208e0ee1bb668684d 100644
--- a/crates/gpui/src/keymap/binding.rs
+++ b/crates/gpui/src/keymap/binding.rs
@@ -10,6 +10,7 @@ pub struct KeyBinding {
pub(crate) action: Box,
pub(crate) keystrokes: SmallVec<[Keystroke; 2]>,
pub(crate) context_predicate: Option>,
+ pub(crate) meta: Option,
}
impl Clone for KeyBinding {
@@ -18,6 +19,7 @@ impl Clone for KeyBinding {
action: self.action.boxed_clone(),
keystrokes: self.keystrokes.clone(),
context_predicate: self.context_predicate.clone(),
+ meta: self.meta,
}
}
}
@@ -59,9 +61,21 @@ impl KeyBinding {
keystrokes,
action,
context_predicate,
+ meta: None,
})
}
+ /// Set the metadata for this binding.
+ pub fn with_meta(mut self, meta: KeyBindingMetaIndex) -> Self {
+ self.meta = Some(meta);
+ self
+ }
+
+ /// Set the metadata for this binding.
+ pub fn set_meta(&mut self, meta: KeyBindingMetaIndex) {
+ self.meta = Some(meta);
+ }
+
/// Check if the given keystrokes match this binding.
pub fn match_keystrokes(&self, typed: &[Keystroke]) -> Option {
if self.keystrokes.len() < typed.len() {
@@ -91,6 +105,11 @@ impl KeyBinding {
pub fn predicate(&self) -> Option> {
self.context_predicate.as_ref().map(|rc| rc.clone())
}
+
+ /// Get the metadata for this binding
+ pub fn meta(&self) -> Option {
+ self.meta
+ }
}
impl std::fmt::Debug for KeyBinding {
@@ -102,3 +121,9 @@ impl std::fmt::Debug for KeyBinding {
.finish()
}
}
+
+/// A unique identifier for retrieval of metadata associated with a key binding.
+/// Intended to be used as an index or key into a user-defined store of metadata
+/// associated with the binding, such as the source of the binding.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct KeyBindingMetaIndex(pub u32);
diff --git a/crates/gpui/src/platform/linux/x11/client.rs b/crates/gpui/src/platform/linux/x11/client.rs
index dddff8566102be44b63680999be7bed30439e7a5..f0ad8b8cf416498f3a1719180f3d6cc7327dceef 100644
--- a/crates/gpui/src/platform/linux/x11/client.rs
+++ b/crates/gpui/src/platform/linux/x11/client.rs
@@ -1,4 +1,4 @@
-use crate::Capslock;
+use crate::{Capslock, xcb_flush};
use core::str;
use std::{
cell::RefCell,
@@ -378,6 +378,7 @@ impl X11Client {
xcb_connection
.xkb_use_extension(XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION),
)?;
+ assert!(xkb.supported);
let events = xkb::EventType::STATE_NOTIFY
| xkb::EventType::MAP_NOTIFY
@@ -401,7 +402,6 @@ impl X11Client {
&xkb::SelectEventsAux::new(),
),
)?;
- assert!(xkb.supported);
let xkb_context = xkbc::Context::new(xkbc::CONTEXT_NO_FLAGS);
let xkb_device_id = xkbc::x11::get_core_keyboard_device_id(&xcb_connection);
@@ -484,6 +484,8 @@ impl X11Client {
})
.map_err(|err| anyhow!("Failed to initialize XDP event source: {err:?}"))?;
+ xcb_flush(&xcb_connection);
+
Ok(X11Client(Rc::new(RefCell::new(X11ClientState {
modifiers: Modifiers::default(),
capslock: Capslock::default(),
@@ -1523,6 +1525,7 @@ impl LinuxClient for X11Client {
),
)
.log_err();
+ xcb_flush(&state.xcb_connection);
let window_ref = WindowRef {
window: window.0.clone(),
@@ -1554,19 +1557,18 @@ impl LinuxClient for X11Client {
};
state.cursor_styles.insert(focused_window, style);
- state
- .xcb_connection
- .change_window_attributes(
+ check_reply(
+ || "Failed to set cursor style",
+ state.xcb_connection.change_window_attributes(
focused_window,
&ChangeWindowAttributesAux {
cursor: Some(cursor),
..Default::default()
},
- )
- .anyhow()
- .and_then(|cookie| cookie.check().anyhow())
- .context("X11: Failed to set cursor style")
- .log_err();
+ ),
+ )
+ .log_err();
+ state.xcb_connection.flush().log_err();
}
fn open_uri(&self, uri: &str) {
@@ -2087,6 +2089,7 @@ fn xdnd_send_finished(
xcb_connection.send_event(false, target, EventMask::default(), message),
)
.log_err();
+ xcb_connection.flush().log_err();
}
fn xdnd_send_status(
@@ -2109,6 +2112,7 @@ fn xdnd_send_status(
xcb_connection.send_event(false, target, EventMask::default(), message),
)
.log_err();
+ xcb_connection.flush().log_err();
}
/// Recomputes `pointer_device_states` by querying all pointer devices.
@@ -2262,6 +2266,6 @@ fn create_invisible_cursor(
connection.free_pixmap(empty_pixmap)?;
- connection.flush()?;
+ xcb_flush(connection);
Ok(cursor)
}
diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rs
index 2b6028f1ccc2e258f80e33f533fcf5bbf69f881a..673c04a3e5edfcdbb4efd508bffd50b0c50891c5 100644
--- a/crates/gpui/src/platform/linux/x11/window.rs
+++ b/crates/gpui/src/platform/linux/x11/window.rs
@@ -320,6 +320,13 @@ impl rwh::HasDisplayHandle for X11Window {
}
}
+pub(crate) fn xcb_flush(xcb: &XCBConnection) {
+ xcb.flush()
+ .map_err(handle_connection_error)
+ .context("X11 flush failed")
+ .log_err();
+}
+
pub(crate) fn check_reply(
failure_context: F,
result: Result, ConnectionError>,
@@ -597,7 +604,7 @@ impl X11WindowState {
),
)?;
- xcb.flush()?;
+ xcb_flush(&xcb);
let renderer = {
let raw_window = RawWindow {
@@ -657,7 +664,7 @@ impl X11WindowState {
|| "X11 DestroyWindow failed while cleaning it up after setup failure.",
xcb.destroy_window(x_window),
)?;
- xcb.flush()?;
+ xcb_flush(&xcb);
}
setup_result
@@ -685,7 +692,7 @@ impl Drop for X11WindowHandle {
|| "X11 DestroyWindow failed while dropping X11WindowHandle.",
self.xcb.destroy_window(self.id),
)?;
- self.xcb.flush()?;
+ xcb_flush(&self.xcb);
anyhow::Ok(())
})
.log_err();
@@ -704,7 +711,7 @@ impl Drop for X11Window {
|| "X11 DestroyWindow failure.",
self.0.xcb.destroy_window(self.0.x_window),
)?;
- self.0.xcb.flush()?;
+ xcb_flush(&self.0.xcb);
anyhow::Ok(())
})
@@ -799,7 +806,9 @@ impl X11Window {
xproto::EventMask::SUBSTRUCTURE_REDIRECT | xproto::EventMask::SUBSTRUCTURE_NOTIFY,
message,
),
- )
+ )?;
+ xcb_flush(&self.0.xcb);
+ Ok(())
}
fn get_root_position(
@@ -852,15 +861,8 @@ impl X11Window {
),
)?;
- self.flush()
- }
-
- fn flush(&self) -> anyhow::Result<()> {
- self.0
- .xcb
- .flush()
- .map_err(handle_connection_error)
- .context("X11 flush failed")
+ xcb_flush(&self.0.xcb);
+ Ok(())
}
}
@@ -1198,7 +1200,7 @@ impl PlatformWindow for X11Window {
),
)
.log_err();
- self.flush().log_err();
+ xcb_flush(&self.0.xcb);
}
fn scale_factor(&self) -> f32 {
@@ -1289,7 +1291,7 @@ impl PlatformWindow for X11Window {
xproto::Time::CURRENT_TIME,
)
.log_err();
- self.flush().log_err();
+ xcb_flush(&self.0.xcb);
}
fn is_active(&self) -> bool {
@@ -1324,7 +1326,7 @@ impl PlatformWindow for X11Window {
),
)
.log_err();
- self.flush().log_err();
+ xcb_flush(&self.0.xcb);
}
fn set_app_id(&mut self, app_id: &str) {
diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs
index 597bff13e2acf875f264356e606237c71eb604c4..f12c62d504395a2afbf698685a4eb3cc5f0e4e1f 100644
--- a/crates/gpui/src/taffy.rs
+++ b/crates/gpui/src/taffy.rs
@@ -28,8 +28,10 @@ const EXPECT_MESSAGE: &str = "we should avoid taffy layout errors by constructio
impl TaffyLayoutEngine {
pub fn new() -> Self {
+ let mut taffy = TaffyTree::new();
+ taffy.disable_rounding();
TaffyLayoutEngine {
- taffy: TaffyTree::new(),
+ taffy,
absolute_layout_bounds: FxHashMap::default(),
computed_layouts: FxHashSet::default(),
}
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index f0f4579b2909a805a3297595997965d32ca37ebb..be3b753d6ad487eec203a7ea321ea52818a8cad2 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -206,8 +206,20 @@ slotmap::new_key_type! {
}
thread_local! {
- /// 8MB wasn't quite enough...
- pub(crate) static ELEMENT_ARENA: RefCell = RefCell::new(Arena::new(32 * 1024 * 1024));
+ pub(crate) static ELEMENT_ARENA: RefCell = RefCell::new(Arena::new(1024 * 1024));
+}
+
+/// Returned when the element arena has been used and so must be cleared before the next draw.
+#[must_use]
+pub struct ArenaClearNeeded;
+
+impl ArenaClearNeeded {
+ /// Clear the element arena.
+ pub fn clear(self) {
+ ELEMENT_ARENA.with_borrow_mut(|element_arena| {
+ element_arena.clear();
+ });
+ }
}
pub(crate) type FocusMap = RwLock>;
@@ -968,8 +980,10 @@ impl Window {
measure("frame duration", || {
handle
.update(&mut cx, |_, window, cx| {
- window.draw(cx);
+ let arena_clear_needed = window.draw(cx);
window.present();
+ // drop the arena elements after present to reduce latency
+ arena_clear_needed.clear();
})
.log_err();
})
@@ -1730,7 +1744,7 @@ impl Window {
/// Produces a new frame and assigns it to `rendered_frame`. To actually show
/// the contents of the new [Scene], use [present].
#[profiling::function]
- pub fn draw(&mut self, cx: &mut App) {
+ pub fn draw(&mut self, cx: &mut App) -> ArenaClearNeeded {
self.invalidate_entities();
cx.entities.clear_accessed();
debug_assert!(self.rendered_entity_stack.is_empty());
@@ -1754,13 +1768,6 @@ impl Window {
self.layout_engine.as_mut().unwrap().clear();
self.text_system().finish_frame();
self.next_frame.finish(&mut self.rendered_frame);
- ELEMENT_ARENA.with_borrow_mut(|element_arena| {
- let percentage = (element_arena.len() as f32 / element_arena.capacity() as f32) * 100.;
- if percentage >= 80. {
- log::warn!("elevated element arena occupation: {}.", percentage);
- }
- element_arena.clear();
- });
self.invalidator.set_phase(DrawPhase::Focus);
let previous_focus_path = self.rendered_frame.focus_path();
@@ -1802,6 +1809,8 @@ impl Window {
self.refreshing = false;
self.invalidator.set_phase(DrawPhase::None);
self.needs_present.set(true);
+
+ ArenaClearNeeded
}
fn record_entities_accessed(&mut self, cx: &mut App) {
@@ -3467,7 +3476,7 @@ impl Window {
fn dispatch_key_event(&mut self, event: &dyn Any, cx: &mut App) {
if self.invalidator.is_dirty() {
- self.draw(cx);
+ self.draw(cx).clear();
}
let node_id = self.focus_node_id_in_rendered_frame(self.focus);
diff --git a/crates/icons/src/icons.rs b/crates/icons/src/icons.rs
index 182696919063a68fa33d8686527bff74c3b8ee6e..7e1d7db5753ff1517902880bda4c6c9e24cfe582 100644
--- a/crates/icons/src/icons.rs
+++ b/crates/icons/src/icons.rs
@@ -19,6 +19,7 @@ pub enum IconName {
AiOllama,
AiOpenAi,
AiOpenRouter,
+ AiVZero,
AiZed,
ArrowCircle,
ArrowDown,
diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.toml
index 278976d3cdfaf304b6d28bd3c88e9a81cbfdb69f..b0e06c3d65a7bc05df0cb41104a1139353372539 100644
--- a/crates/language/Cargo.toml
+++ b/crates/language/Cargo.toml
@@ -20,6 +20,7 @@ test-support = [
"text/test-support",
"tree-sitter-rust",
"tree-sitter-python",
+ "tree-sitter-rust",
"tree-sitter-typescript",
"settings/test-support",
"util/test-support",
diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs
index 523efa49dc71694084529a13d45b67fdd7c09afd..90a899f79d42f33f91044f025bc22383c2f3881d 100644
--- a/crates/language/src/buffer.rs
+++ b/crates/language/src/buffer.rs
@@ -1,12 +1,6 @@
-pub use crate::{
- Grammar, Language, LanguageRegistry,
- diagnostic_set::DiagnosticSet,
- highlight_map::{HighlightId, HighlightMap},
- proto,
-};
use crate::{
- LanguageScope, Outline, OutlineConfig, RunnableCapture, RunnableTag, TextObject,
- TreeSitterOptions,
+ DebuggerTextObject, LanguageScope, Outline, OutlineConfig, RunnableCapture, RunnableTag,
+ TextObject, TreeSitterOptions,
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
language_settings::{LanguageSettings, language_settings},
outline::OutlineItem,
@@ -17,6 +11,12 @@ use crate::{
task_context::RunnableRange,
text_diff::text_diff,
};
+pub use crate::{
+ Grammar, Language, LanguageRegistry,
+ diagnostic_set::DiagnosticSet,
+ highlight_map::{HighlightId, HighlightMap},
+ proto,
+};
use anyhow::{Context as _, Result};
pub use clock::ReplicaId;
use clock::{AGENT_REPLICA_ID, Lamport};
@@ -3848,6 +3848,74 @@ impl BufferSnapshot {
.filter(|pair| !pair.newline_only)
}
+ pub fn debug_variables_query(
+ &self,
+ range: Range,
+ ) -> impl Iterator- , DebuggerTextObject)> + '_ {
+ let range = range.start.to_offset(self).saturating_sub(1)
+ ..self.len().min(range.end.to_offset(self) + 1);
+
+ let mut matches = self.syntax.matches_with_options(
+ range.clone(),
+ &self.text,
+ TreeSitterOptions::default(),
+ |grammar| grammar.debug_variables_config.as_ref().map(|c| &c.query),
+ );
+
+ let configs = matches
+ .grammars()
+ .iter()
+ .map(|grammar| grammar.debug_variables_config.as_ref())
+ .collect::>();
+
+ let mut captures = Vec::<(Range, DebuggerTextObject)>::new();
+
+ iter::from_fn(move || {
+ loop {
+ while let Some(capture) = captures.pop() {
+ if capture.0.overlaps(&range) {
+ return Some(capture);
+ }
+ }
+
+ let mat = matches.peek()?;
+
+ let Some(config) = configs[mat.grammar_index].as_ref() else {
+ matches.advance();
+ continue;
+ };
+
+ for capture in mat.captures {
+ let Some(ix) = config
+ .objects_by_capture_ix
+ .binary_search_by_key(&capture.index, |e| e.0)
+ .ok()
+ else {
+ continue;
+ };
+ let text_object = config.objects_by_capture_ix[ix].1;
+ let byte_range = capture.node.byte_range();
+
+ let mut found = false;
+ for (range, existing) in captures.iter_mut() {
+ if existing == &text_object {
+ range.start = range.start.min(byte_range.start);
+ range.end = range.end.max(byte_range.end);
+ found = true;
+ break;
+ }
+ }
+
+ if !found {
+ captures.push((byte_range, text_object));
+ }
+ }
+
+ matches.advance();
+ }
+ })
+ }
+
pub fn text_object_ranges(
&self,
range: Range,
diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs
index 8b8c411366f02793bdeb86bf5154fc77aa6d338b..f564b54ed52e028a8a19f13616bc42364ff4d4a4 100644
--- a/crates/language/src/language.rs
+++ b/crates/language/src/language.rs
@@ -1082,6 +1082,7 @@ pub struct Grammar {
pub embedding_config: Option,
pub(crate) injection_config: Option,
pub(crate) override_config: Option,
+ pub(crate) debug_variables_config: Option,
pub(crate) highlight_map: Mutex,
}
@@ -1104,6 +1105,22 @@ pub struct OutlineConfig {
pub annotation_capture_ix: Option,
}
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum DebuggerTextObject {
+ Variable,
+ Scope,
+}
+
+impl DebuggerTextObject {
+ pub fn from_capture_name(name: &str) -> Option {
+ match name {
+ "debug-variable" => Some(DebuggerTextObject::Variable),
+ "debug-scope" => Some(DebuggerTextObject::Scope),
+ _ => None,
+ }
+ }
+}
+
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TextObject {
InsideFunction,
@@ -1206,6 +1223,11 @@ struct BracketsPatternConfig {
newline_only: bool,
}
+pub struct DebugVariablesConfig {
+ pub query: Query,
+ pub objects_by_capture_ix: Vec<(u32, DebuggerTextObject)>,
+}
+
impl Language {
pub fn new(config: LanguageConfig, ts_language: Option) -> Self {
Self::new_with_id(LanguageId::new(), config, ts_language)
@@ -1237,6 +1259,7 @@ impl Language {
redactions_config: None,
runnable_config: None,
error_query: Query::new(&ts_language, "(ERROR) @error").ok(),
+ debug_variables_config: None,
ts_language,
highlight_map: Default::default(),
})
@@ -1307,6 +1330,11 @@ impl Language {
.with_text_object_query(query.as_ref())
.context("Error loading textobject query")?;
}
+ if let Some(query) = queries.debugger {
+ self = self
+ .with_debug_variables_query(query.as_ref())
+ .context("Error loading debug variables query")?;
+ }
Ok(self)
}
@@ -1425,6 +1453,24 @@ impl Language {
Ok(self)
}
+ pub fn with_debug_variables_query(mut self, source: &str) -> Result {
+ let grammar = self.grammar_mut().context("cannot mutate grammar")?;
+ let query = Query::new(&grammar.ts_language, source)?;
+
+ let mut objects_by_capture_ix = Vec::new();
+ for (ix, name) in query.capture_names().iter().enumerate() {
+ if let Some(text_object) = DebuggerTextObject::from_capture_name(name) {
+ objects_by_capture_ix.push((ix as u32, text_object));
+ }
+ }
+
+ grammar.debug_variables_config = Some(DebugVariablesConfig {
+ query,
+ objects_by_capture_ix,
+ });
+ Ok(self)
+ }
+
pub fn with_brackets_query(mut self, source: &str) -> Result {
let grammar = self.grammar_mut().context("cannot mutate grammar")?;
let query = Query::new(&grammar.ts_language, source)?;
@@ -1930,6 +1976,10 @@ impl Grammar {
.capture_index_for_name(name)?;
Some(self.highlight_map.lock().get(capture_id))
}
+
+ pub fn debug_variables_config(&self) -> Option<&DebugVariablesConfig> {
+ self.debug_variables_config.as_ref()
+ }
}
impl CodeLabel {
diff --git a/crates/language/src/language_registry.rs b/crates/language/src/language_registry.rs
index 4d0837d8e30fc1fd9be961e2cc05487d276e3792..b2bb684e1bb10d6edc72a41d3006d114a4b5f371 100644
--- a/crates/language/src/language_registry.rs
+++ b/crates/language/src/language_registry.rs
@@ -157,6 +157,9 @@ pub enum BinaryStatus {
None,
CheckingForUpdate,
Downloading,
+ Starting,
+ Stopping,
+ Stopped,
Failed { error: String },
}
@@ -226,7 +229,7 @@ pub const QUERY_FILENAME_PREFIXES: &[(
("overrides", |q| &mut q.overrides),
("redactions", |q| &mut q.redactions),
("runnables", |q| &mut q.runnables),
- ("debug_variables", |q| &mut q.debug_variables),
+ ("debugger", |q| &mut q.debugger),
("textobjects", |q| &mut q.text_objects),
];
@@ -243,12 +246,12 @@ pub struct LanguageQueries {
pub redactions: Option>,
pub runnables: Option>,
pub text_objects: Option>,
- pub debug_variables: Option>,
+ pub debugger: Option>,
}
#[derive(Clone, Default)]
struct ServerStatusSender {
- txs: Arc>>>,
+ txs: Arc>>>,
}
pub struct LoadedLanguage {
@@ -1085,11 +1088,7 @@ impl LanguageRegistry {
self.state.read().all_lsp_adapters.get(name).cloned()
}
- pub fn update_lsp_status(
- &self,
- server_name: LanguageServerName,
- status: LanguageServerStatusUpdate,
- ) {
+ pub fn update_lsp_binary_status(&self, server_name: LanguageServerName, status: BinaryStatus) {
self.lsp_binary_status_tx.send(server_name, status);
}
@@ -1145,7 +1144,7 @@ impl LanguageRegistry {
pub fn language_server_binary_statuses(
&self,
- ) -> mpsc::UnboundedReceiver<(LanguageServerName, LanguageServerStatusUpdate)> {
+ ) -> mpsc::UnboundedReceiver<(LanguageServerName, BinaryStatus)> {
self.lsp_binary_status_tx.subscribe()
}
@@ -1260,15 +1259,13 @@ impl LanguageRegistryState {
}
impl ServerStatusSender {
- fn subscribe(
- &self,
- ) -> mpsc::UnboundedReceiver<(LanguageServerName, LanguageServerStatusUpdate)> {
+ fn subscribe(&self) -> mpsc::UnboundedReceiver<(LanguageServerName, BinaryStatus)> {
let (tx, rx) = mpsc::unbounded();
self.txs.lock().push(tx);
rx
}
- fn send(&self, name: LanguageServerName, status: LanguageServerStatusUpdate) {
+ fn send(&self, name: LanguageServerName, status: BinaryStatus) {
let mut txs = self.txs.lock();
txs.retain(|tx| tx.unbounded_send((name.clone(), status.clone())).is_ok());
}
diff --git a/crates/language_extension/src/extension_lsp_adapter.rs b/crates/language_extension/src/extension_lsp_adapter.rs
index a32292daa3feac352754ee1507bda403c438aba8..d2eabf0a3e36669f1dfb34af0c5da8077c6be87e 100644
--- a/crates/language_extension/src/extension_lsp_adapter.rs
+++ b/crates/language_extension/src/extension_lsp_adapter.rs
@@ -12,8 +12,8 @@ use fs::Fs;
use futures::{Future, FutureExt};
use gpui::AsyncApp;
use language::{
- BinaryStatus, CodeLabel, HighlightId, Language, LanguageName, LanguageServerStatusUpdate,
- LanguageToolchainStore, LspAdapter, LspAdapterDelegate,
+ BinaryStatus, CodeLabel, HighlightId, Language, LanguageName, LanguageToolchainStore,
+ LspAdapter, LspAdapterDelegate,
};
use lsp::{CodeActionKind, LanguageServerBinary, LanguageServerBinaryOptions, LanguageServerName};
use serde::Serialize;
@@ -82,10 +82,8 @@ impl ExtensionLanguageServerProxy for LanguageServerRegistryProxy {
language_server_id: LanguageServerName,
status: BinaryStatus,
) {
- self.language_registry.update_lsp_status(
- language_server_id,
- LanguageServerStatusUpdate::Binary(status),
- );
+ self.language_registry
+ .update_lsp_binary_status(language_server_id, status);
}
}
diff --git a/crates/language_model/src/language_model.rs b/crates/language_model/src/language_model.rs
index 9f165df301d2a378c678da2e3b8c6a5c3ffdb03e..f84357bd98936e478a826df9a4d0563f2c857e10 100644
--- a/crates/language_model/src/language_model.rs
+++ b/crates/language_model/src/language_model.rs
@@ -67,6 +67,9 @@ pub enum LanguageModelCompletionEvent {
text: String,
signature: Option,
},
+ RedactedThinking {
+ data: String,
+ },
ToolUse(LanguageModelToolUse),
StartMessage {
message_id: String,
@@ -359,6 +362,7 @@ pub trait LanguageModel: Send + Sync {
Ok(LanguageModelCompletionEvent::StartMessage { .. }) => None,
Ok(LanguageModelCompletionEvent::Text(text)) => Some(Ok(text)),
Ok(LanguageModelCompletionEvent::Thinking { .. }) => None,
+ Ok(LanguageModelCompletionEvent::RedactedThinking { .. }) => None,
Ok(LanguageModelCompletionEvent::Stop(_)) => None,
Ok(LanguageModelCompletionEvent::ToolUse(_)) => None,
Ok(LanguageModelCompletionEvent::UsageUpdate(token_usage)) => {
diff --git a/crates/language_model/src/request.rs b/crates/language_model/src/request.rs
index 559d8e9111405cef4c1b039a7c8ffa945de1d950..451a62775e6331b139ef5c4da57e4d7d930af6f8 100644
--- a/crates/language_model/src/request.rs
+++ b/crates/language_model/src/request.rs
@@ -303,7 +303,7 @@ pub enum MessageContent {
text: String,
signature: Option,
},
- RedactedThinking(Vec),
+ RedactedThinking(String),
Image(LanguageModelImage),
ToolUse(LanguageModelToolUse),
ToolResult(LanguageModelToolResult),
diff --git a/crates/language_models/Cargo.toml b/crates/language_models/Cargo.toml
index c8b5e57b1a07c1abebec0e07e61d8b111771dce5..d6aff380aab1696b0f71f0b83ed876cc1e756ecb 100644
--- a/crates/language_models/Cargo.toml
+++ b/crates/language_models/Cargo.toml
@@ -40,8 +40,8 @@ mistral = { workspace = true, features = ["schemars"] }
ollama = { workspace = true, features = ["schemars"] }
open_ai = { workspace = true, features = ["schemars"] }
open_router = { workspace = true, features = ["schemars"] }
+vercel = { workspace = true, features = ["schemars"] }
partial-json-fixer.workspace = true
-project.workspace = true
proto.workspace = true
release_channel.workspace = true
schemars.workspace = true
diff --git a/crates/language_models/src/language_models.rs b/crates/language_models/src/language_models.rs
index 0224da4e6b530224e3ed81ff27143b91e58a104c..c7324732c9bbf88698a1a7280ff80cea077a1d2f 100644
--- a/crates/language_models/src/language_models.rs
+++ b/crates/language_models/src/language_models.rs
@@ -1,7 +1,6 @@
use std::sync::Arc;
use client::{Client, UserStore};
-use fs::Fs;
use gpui::{App, Context, Entity};
use language_model::LanguageModelRegistry;
use provider::deepseek::DeepSeekLanguageModelProvider;
@@ -20,10 +19,11 @@ use crate::provider::mistral::MistralLanguageModelProvider;
use crate::provider::ollama::OllamaLanguageModelProvider;
use crate::provider::open_ai::OpenAiLanguageModelProvider;
use crate::provider::open_router::OpenRouterLanguageModelProvider;
+use crate::provider::vercel::VercelLanguageModelProvider;
pub use crate::settings::*;
-pub fn init(user_store: Entity, client: Arc, fs: Arc, cx: &mut App) {
- crate::settings::init(fs, cx);
+pub fn init(user_store: Entity, client: Arc, cx: &mut App) {
+ crate::settings::init(cx);
let registry = LanguageModelRegistry::global(cx);
registry.update(cx, |registry, cx| {
register_language_model_providers(registry, user_store, client, cx);
@@ -77,5 +77,9 @@ fn register_language_model_providers(
OpenRouterLanguageModelProvider::new(client.http_client(), cx),
cx,
);
+ registry.register_provider(
+ VercelLanguageModelProvider::new(client.http_client(), cx),
+ cx,
+ );
registry.register_provider(CopilotChatLanguageModelProvider::new(cx), cx);
}
diff --git a/crates/language_models/src/provider.rs b/crates/language_models/src/provider.rs
index 4f2ea9cc09f6266b2bcd1f3d3e3d9c9aeff7ba1f..6bc93bd3661e86fc2c8f9bacafaf2d4121e0f7a6 100644
--- a/crates/language_models/src/provider.rs
+++ b/crates/language_models/src/provider.rs
@@ -9,3 +9,4 @@ pub mod mistral;
pub mod ollama;
pub mod open_ai;
pub mod open_router;
+pub mod vercel;
diff --git a/crates/language_models/src/provider/anthropic.rs b/crates/language_models/src/provider/anthropic.rs
index 719975c1d5ef51976a8d592c89d0a887892b9849..48bea47fec02a0cb5b51b59883492caf00d1c982 100644
--- a/crates/language_models/src/provider/anthropic.rs
+++ b/crates/language_models/src/provider/anthropic.rs
@@ -41,7 +41,6 @@ pub struct AnthropicSettings {
pub api_url: String,
/// Extend Zed's list of Anthropic models.
pub available_models: Vec,
- pub needs_setting_migration: bool,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
@@ -554,9 +553,7 @@ pub fn into_anthropic(
}
MessageContent::RedactedThinking(data) => {
if !data.is_empty() {
- Some(anthropic::RequestContent::RedactedThinking {
- data: String::from_utf8(data).ok()?,
- })
+ Some(anthropic::RequestContent::RedactedThinking { data })
} else {
None
}
@@ -730,10 +727,8 @@ impl AnthropicEventMapper {
signature: None,
})]
}
- ResponseContent::RedactedThinking { .. } => {
- // Redacted thinking is encrypted and not accessible to the user, see:
- // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#suggestions-for-handling-redacted-thinking-in-production
- Vec::new()
+ ResponseContent::RedactedThinking { data } => {
+ vec![Ok(LanguageModelCompletionEvent::RedactedThinking { data })]
}
ResponseContent::ToolUse { id, name, .. } => {
self.tool_uses_by_index.insert(
diff --git a/crates/language_models/src/provider/bedrock.rs b/crates/language_models/src/provider/bedrock.rs
index ed5e3726165ff9b67c7da1e8deb25a7f6fde2cc6..a55fc5bc1142dcacf1d6cf5193345f6904c76b37 100644
--- a/crates/language_models/src/provider/bedrock.rs
+++ b/crates/language_models/src/provider/bedrock.rs
@@ -11,8 +11,8 @@ use aws_http_client::AwsHttpClient;
use bedrock::bedrock_client::Client as BedrockClient;
use bedrock::bedrock_client::config::timeout::TimeoutConfig;
use bedrock::bedrock_client::types::{
- ContentBlockDelta, ContentBlockStart, ConverseStreamOutput, ReasoningContentBlockDelta,
- StopReason,
+ CachePointBlock, CachePointType, ContentBlockDelta, ContentBlockStart, ConverseStreamOutput,
+ ReasoningContentBlockDelta, StopReason,
};
use bedrock::{
BedrockAnyToolChoice, BedrockAutoToolChoice, BedrockBlob, BedrockError, BedrockInnerContent,
@@ -48,7 +48,7 @@ use strum::{EnumIter, IntoEnumIterator, IntoStaticStr};
use theme::ThemeSettings;
use tokio::runtime::Handle;
use ui::{Icon, IconName, List, Tooltip, prelude::*};
-use util::{ResultExt, default};
+use util::ResultExt;
use crate::AllLanguageModelSettings;
@@ -329,6 +329,12 @@ impl LanguageModelProvider for BedrockLanguageModelProvider {
max_tokens: model.max_tokens,
max_output_tokens: model.max_output_tokens,
default_temperature: model.default_temperature,
+ cache_configuration: model.cache_configuration.as_ref().map(|config| {
+ bedrock::BedrockModelCacheConfiguration {
+ max_cache_anchors: config.max_cache_anchors,
+ min_total_token: config.min_total_token,
+ }
+ }),
},
);
}
@@ -503,7 +509,8 @@ impl LanguageModel for BedrockModel {
LanguageModelToolChoice::Auto | LanguageModelToolChoice::Any => {
self.model.supports_tool_use()
}
- LanguageModelToolChoice::None => false,
+ // Add support for None - we'll filter tool calls at response
+ LanguageModelToolChoice::None => self.model.supports_tool_use(),
}
}
@@ -549,12 +556,15 @@ impl LanguageModel for BedrockModel {
}
};
+ let deny_tool_calls = request.tool_choice == Some(LanguageModelToolChoice::None);
+
let request = match into_bedrock(
request,
model_id,
self.model.default_temperature(),
self.model.max_output_tokens(),
self.model.mode(),
+ self.model.supports_caching(),
) {
Ok(request) => request,
Err(err) => return futures::future::ready(Err(err.into())).boxed(),
@@ -565,25 +575,53 @@ impl LanguageModel for BedrockModel {
let request = self.stream_completion(request, cx);
let future = self.request_limiter.stream(async move {
let response = request.map_err(|err| anyhow!(err))?.await;
- Ok(map_to_language_model_completion_events(
- response,
- owned_handle,
- ))
+ let events = map_to_language_model_completion_events(response, owned_handle);
+
+ if deny_tool_calls {
+ Ok(deny_tool_use_events(events).boxed())
+ } else {
+ Ok(events.boxed())
+ }
});
+
async move { Ok(future.await?.boxed()) }.boxed()
}
fn cache_configuration(&self) -> Option {
- None
+ self.model
+ .cache_configuration()
+ .map(|config| LanguageModelCacheConfiguration {
+ max_cache_anchors: config.max_cache_anchors,
+ should_speculate: false,
+ min_total_token: config.min_total_token,
+ })
}
}
+fn deny_tool_use_events(
+ events: impl Stream
- >,
+) -> impl Stream
- > {
+ events.map(|event| {
+ match event {
+ Ok(LanguageModelCompletionEvent::ToolUse(tool_use)) => {
+ // Convert tool use to an error message if model decided to call it
+ Ok(LanguageModelCompletionEvent::Text(format!(
+ "\n\n[Error: Tool calls are disabled in this context. Attempted to call '{}']",
+ tool_use.name
+ )))
+ }
+ other => other,
+ }
+ })
+}
+
pub fn into_bedrock(
request: LanguageModelRequest,
model: String,
default_temperature: f32,
max_output_tokens: u64,
mode: BedrockModelMode,
+ supports_caching: bool,
) -> Result {
let mut new_messages: Vec = Vec::new();
let mut system_message = String::new();
@@ -595,7 +633,7 @@ pub fn into_bedrock(
match message.role {
Role::User | Role::Assistant => {
- let bedrock_message_content: Vec = message
+ let mut bedrock_message_content: Vec = message
.content
.into_iter()
.filter_map(|content| match content {
@@ -607,6 +645,11 @@ pub fn into_bedrock(
}
}
MessageContent::Thinking { text, signature } => {
+ if model.contains(Model::DeepSeekR1.request_id()) {
+ // DeepSeekR1 doesn't support thinking blocks
+ // And the AWS API demands that you strip them
+ return None;
+ }
let thinking = BedrockThinkingTextBlock::builder()
.text(text)
.set_signature(signature)
@@ -619,19 +662,32 @@ pub fn into_bedrock(
))
}
MessageContent::RedactedThinking(blob) => {
+ if model.contains(Model::DeepSeekR1.request_id()) {
+ // DeepSeekR1 doesn't support thinking blocks
+ // And the AWS API demands that you strip them
+ return None;
+ }
let redacted =
BedrockThinkingBlock::RedactedContent(BedrockBlob::new(blob));
Some(BedrockInnerContent::ReasoningContent(redacted))
}
- MessageContent::ToolUse(tool_use) => BedrockToolUseBlock::builder()
- .name(tool_use.name.to_string())
- .tool_use_id(tool_use.id.to_string())
- .input(value_to_aws_document(&tool_use.input))
- .build()
- .context("failed to build Bedrock tool use block")
- .log_err()
- .map(BedrockInnerContent::ToolUse),
+ MessageContent::ToolUse(tool_use) => {
+ let input = if tool_use.input.is_null() {
+ // Bedrock API requires valid JsonValue, not null, for tool use input
+ value_to_aws_document(&serde_json::json!({}))
+ } else {
+ value_to_aws_document(&tool_use.input)
+ };
+ BedrockToolUseBlock::builder()
+ .name(tool_use.name.to_string())
+ .tool_use_id(tool_use.id.to_string())
+ .input(input)
+ .build()
+ .context("failed to build Bedrock tool use block")
+ .log_err()
+ .map(BedrockInnerContent::ToolUse)
+ },
MessageContent::ToolResult(tool_result) => {
BedrockToolResultBlock::builder()
.tool_use_id(tool_result.tool_use_id.to_string())
@@ -661,6 +717,14 @@ pub fn into_bedrock(
_ => None,
})
.collect();
+ if message.cache && supports_caching {
+ bedrock_message_content.push(BedrockInnerContent::CachePoint(
+ CachePointBlock::builder()
+ .r#type(CachePointType::Default)
+ .build()
+ .context("failed to build cache point block")?,
+ ));
+ }
let bedrock_role = match message.role {
Role::User => bedrock::BedrockRole::User,
Role::Assistant => bedrock::BedrockRole::Assistant,
@@ -689,7 +753,7 @@ pub fn into_bedrock(
}
}
- let tool_spec: Vec = request
+ let mut tool_spec: Vec = request
.tools
.iter()
.filter_map(|tool| {
@@ -706,6 +770,15 @@ pub fn into_bedrock(
})
.collect();
+ if !tool_spec.is_empty() && supports_caching {
+ tool_spec.push(BedrockTool::CachePoint(
+ CachePointBlock::builder()
+ .r#type(CachePointType::Default)
+ .build()
+ .context("failed to build cache point block")?,
+ ));
+ }
+
let tool_choice = match request.tool_choice {
Some(LanguageModelToolChoice::Auto) | None => {
BedrockToolChoice::Auto(BedrockAutoToolChoice::builder().build())
@@ -714,7 +787,8 @@ pub fn into_bedrock(
BedrockToolChoice::Any(BedrockAnyToolChoice::builder().build())
}
Some(LanguageModelToolChoice::None) => {
- anyhow::bail!("LanguageModelToolChoice::None is not supported");
+ // For None, we still use Auto but will filter out tool calls in the response
+ BedrockToolChoice::Auto(BedrockAutoToolChoice::builder().build())
}
};
let tool_config: BedrockToolConfig = BedrockToolConfig::builder()
@@ -947,10 +1021,11 @@ pub fn map_to_language_model_completion_events(
LanguageModelCompletionEvent::UsageUpdate(
TokenUsage {
input_tokens: metadata.input_tokens as u64,
- output_tokens: metadata.output_tokens
- as u64,
- cache_creation_input_tokens: default(),
- cache_read_input_tokens: default(),
+ output_tokens: metadata.output_tokens as u64,
+ cache_creation_input_tokens:
+ metadata.cache_write_input_tokens.unwrap_or_default() as u64,
+ cache_read_input_tokens:
+ metadata.cache_read_input_tokens.unwrap_or_default() as u64,
},
);
return Some((Some(Ok(completion_event)), state));
diff --git a/crates/language_models/src/provider/cloud.rs b/crates/language_models/src/provider/cloud.rs
index 1062d732a42d0d7fdd15e99d15a50b72826ed03c..58902850ea1d66d843306e9612a0ed2538a29ac9 100644
--- a/crates/language_models/src/provider/cloud.rs
+++ b/crates/language_models/src/provider/cloud.rs
@@ -888,7 +888,12 @@ impl LanguageModel for CloudLanguageModel {
Ok(model) => model,
Err(err) => return async move { Err(anyhow!(err).into()) }.boxed(),
};
- let request = into_open_ai(request, &model, None);
+ let request = into_open_ai(
+ request,
+ model.id(),
+ model.supports_parallel_tool_calls(),
+ None,
+ );
let llm_api_token = self.llm_api_token.clone();
let future = self.request_limiter.stream(async move {
let PerformLlmCompletionResponse {
diff --git a/crates/language_models/src/provider/deepseek.rs b/crates/language_models/src/provider/deepseek.rs
index 10030c909109e03c3aeac4e2472c5879740290a4..99a1ca70c6e9ced064c76d4ede427e3b2f5ace0f 100644
--- a/crates/language_models/src/provider/deepseek.rs
+++ b/crates/language_models/src/provider/deepseek.rs
@@ -14,7 +14,7 @@ use language_model::{
LanguageModelId, LanguageModelName, LanguageModelProvider, LanguageModelProviderId,
LanguageModelProviderName, LanguageModelProviderState, LanguageModelRequest,
LanguageModelToolChoice, LanguageModelToolResultContent, LanguageModelToolUse, MessageContent,
- RateLimiter, Role, StopReason,
+ RateLimiter, Role, StopReason, TokenUsage,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -513,6 +513,15 @@ impl DeepSeekEventMapper {
}
}
+ if let Some(usage) = event.usage {
+ events.push(Ok(LanguageModelCompletionEvent::UsageUpdate(TokenUsage {
+ input_tokens: usage.prompt_tokens,
+ output_tokens: usage.completion_tokens,
+ cache_creation_input_tokens: 0,
+ cache_read_input_tokens: 0,
+ })));
+ }
+
match choice.finish_reason.as_deref() {
Some("stop") => {
events.push(Ok(LanguageModelCompletionEvent::Stop(StopReason::EndTurn)));
diff --git a/crates/language_models/src/provider/mistral.rs b/crates/language_models/src/provider/mistral.rs
index 5e46c41746d1404d1061da47fce32bb5ad74d048..171ce058968afe2f8bc16326fc841e3ea6b804de 100644
--- a/crates/language_models/src/provider/mistral.rs
+++ b/crates/language_models/src/provider/mistral.rs
@@ -36,7 +36,6 @@ const PROVIDER_NAME: &str = "Mistral";
pub struct MistralSettings {
pub api_url: String,
pub available_models: Vec,
- pub needs_setting_migration: bool,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
diff --git a/crates/language_models/src/provider/open_ai.rs b/crates/language_models/src/provider/open_ai.rs
index f6e1ea559a3efc73de0b104dbc874e0452393b14..ad4203ff81c5ec28e98bbf6eab0e4f3e23b7f604 100644
--- a/crates/language_models/src/provider/open_ai.rs
+++ b/crates/language_models/src/provider/open_ai.rs
@@ -12,7 +12,7 @@ use language_model::{
LanguageModelId, LanguageModelName, LanguageModelProvider, LanguageModelProviderId,
LanguageModelProviderName, LanguageModelProviderState, LanguageModelRequest,
LanguageModelToolChoice, LanguageModelToolResultContent, LanguageModelToolUse, MessageContent,
- RateLimiter, Role, StopReason,
+ RateLimiter, Role, StopReason, TokenUsage,
};
use menu;
use open_ai::{ImageUrl, Model, ResponseStreamEvent, stream_completion};
@@ -28,6 +28,7 @@ use ui::{ElevationIndex, List, Tooltip, prelude::*};
use ui_input::SingleLineInput;
use util::ResultExt;
+use crate::OpenAiSettingsContent;
use crate::{AllLanguageModelSettings, ui::InstructionListItem};
const PROVIDER_ID: &str = "openai";
@@ -37,7 +38,6 @@ const PROVIDER_NAME: &str = "OpenAI";
pub struct OpenAiSettings {
pub api_url: String,
pub available_models: Vec,
- pub needs_setting_migration: bool,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
@@ -344,7 +344,12 @@ impl LanguageModel for OpenAiLanguageModel {
LanguageModelCompletionError,
>,
> {
- let request = into_open_ai(request, &self.model, self.max_output_tokens());
+ let request = into_open_ai(
+ request,
+ self.model.id(),
+ self.model.supports_parallel_tool_calls(),
+ self.max_output_tokens(),
+ );
let completions = self.stream_completion(request, cx);
async move {
let mapper = OpenAiEventMapper::new();
@@ -356,10 +361,11 @@ impl LanguageModel for OpenAiLanguageModel {
pub fn into_open_ai(
request: LanguageModelRequest,
- model: &Model,
+ model_id: &str,
+ supports_parallel_tool_calls: bool,
max_output_tokens: Option,
) -> open_ai::Request {
- let stream = !model.id().starts_with("o1-");
+ let stream = !model_id.starts_with("o1-");
let mut messages = Vec::new();
for message in request.messages {
@@ -435,13 +441,13 @@ pub fn into_open_ai(
}
open_ai::Request {
- model: model.id().into(),
+ model: model_id.into(),
messages,
stream,
stop: request.stop,
temperature: request.temperature.unwrap_or(1.0),
max_completion_tokens: max_output_tokens,
- parallel_tool_calls: if model.supports_parallel_tool_calls() && !request.tools.is_empty() {
+ parallel_tool_calls: if supports_parallel_tool_calls && !request.tools.is_empty() {
// Disable parallel tool calls, as the Agent currently expects a maximum of one per turn.
Some(false)
} else {
@@ -528,11 +534,20 @@ impl OpenAiEventMapper {
&mut self,
event: ResponseStreamEvent,
) -> Vec> {
+ let mut events = Vec::new();
+ if let Some(usage) = event.usage {
+ events.push(Ok(LanguageModelCompletionEvent::UsageUpdate(TokenUsage {
+ input_tokens: usage.prompt_tokens,
+ output_tokens: usage.completion_tokens,
+ cache_creation_input_tokens: 0,
+ cache_read_input_tokens: 0,
+ })));
+ }
+
let Some(choice) = event.choices.first() else {
- return Vec::new();
+ return events;
};
- let mut events = Vec::new();
if let Some(content) = choice.delta.content.clone() {
events.push(Ok(LanguageModelCompletionEvent::Text(content)));
}
@@ -788,30 +803,13 @@ impl ConfigurationView {
if !api_url.is_empty() && api_url != effective_current_url {
let fs = ::global(cx);
update_settings_file::(fs, cx, move |settings, _| {
- use crate::settings::{OpenAiSettingsContent, VersionedOpenAiSettingsContent};
-
- if settings.openai.is_none() {
- settings.openai = Some(OpenAiSettingsContent::Versioned(
- VersionedOpenAiSettingsContent::V1(
- crate::settings::OpenAiSettingsContentV1 {
- api_url: Some(api_url.clone()),
- available_models: None,
- },
- ),
- ));
+ if let Some(settings) = settings.openai.as_mut() {
+ settings.api_url = Some(api_url.clone());
} else {
- if let Some(openai) = settings.openai.as_mut() {
- match openai {
- OpenAiSettingsContent::Versioned(versioned) => match versioned {
- VersionedOpenAiSettingsContent::V1(v1) => {
- v1.api_url = Some(api_url.clone());
- }
- },
- OpenAiSettingsContent::Legacy(legacy) => {
- legacy.api_url = Some(api_url.clone());
- }
- }
- }
+ settings.openai = Some(OpenAiSettingsContent {
+ api_url: Some(api_url.clone()),
+ available_models: None,
+ });
}
});
}
@@ -825,19 +823,8 @@ impl ConfigurationView {
});
let fs = ::global(cx);
update_settings_file::(fs, cx, |settings, _cx| {
- use crate::settings::{OpenAiSettingsContent, VersionedOpenAiSettingsContent};
-
- if let Some(openai) = settings.openai.as_mut() {
- match openai {
- OpenAiSettingsContent::Versioned(versioned) => match versioned {
- VersionedOpenAiSettingsContent::V1(v1) => {
- v1.api_url = None;
- }
- },
- OpenAiSettingsContent::Legacy(legacy) => {
- legacy.api_url = None;
- }
- }
+ if let Some(settings) = settings.openai.as_mut() {
+ settings.api_url = None;
}
});
cx.notify();
diff --git a/crates/language_models/src/provider/vercel.rs b/crates/language_models/src/provider/vercel.rs
new file mode 100644
index 0000000000000000000000000000000000000000..2f64115d2096c4bd4214d43d0a010995fb2edd15
--- /dev/null
+++ b/crates/language_models/src/provider/vercel.rs
@@ -0,0 +1,577 @@
+use anyhow::{Context as _, Result, anyhow};
+use collections::BTreeMap;
+use credentials_provider::CredentialsProvider;
+use futures::{FutureExt, StreamExt, future::BoxFuture};
+use gpui::{AnyView, App, AsyncApp, Context, Entity, Subscription, Task, Window};
+use http_client::HttpClient;
+use language_model::{
+ AuthenticateError, LanguageModel, LanguageModelCompletionError, LanguageModelCompletionEvent,
+ LanguageModelId, LanguageModelName, LanguageModelProvider, LanguageModelProviderId,
+ LanguageModelProviderName, LanguageModelProviderState, LanguageModelRequest,
+ LanguageModelToolChoice, RateLimiter, Role,
+};
+use menu;
+use open_ai::ResponseStreamEvent;
+use schemars::JsonSchema;
+use serde::{Deserialize, Serialize};
+use settings::{Settings, SettingsStore};
+use std::sync::Arc;
+use strum::IntoEnumIterator;
+use vercel::Model;
+
+use ui::{ElevationIndex, List, Tooltip, prelude::*};
+use ui_input::SingleLineInput;
+use util::ResultExt;
+
+use crate::{AllLanguageModelSettings, ui::InstructionListItem};
+
+const PROVIDER_ID: &str = "vercel";
+const PROVIDER_NAME: &str = "Vercel";
+
+#[derive(Default, Clone, Debug, PartialEq)]
+pub struct VercelSettings {
+ pub api_url: String,
+ pub available_models: Vec,
+}
+
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
+pub struct AvailableModel {
+ pub name: String,
+ pub display_name: Option,
+ pub max_tokens: u64,
+ pub max_output_tokens: Option,
+ pub max_completion_tokens: Option,
+}
+
+pub struct VercelLanguageModelProvider {
+ http_client: Arc,
+ state: gpui::Entity,
+}
+
+pub struct State {
+ api_key: Option,
+ api_key_from_env: bool,
+ _subscription: Subscription,
+}
+
+const VERCEL_API_KEY_VAR: &str = "VERCEL_API_KEY";
+
+impl State {
+ fn is_authenticated(&self) -> bool {
+ self.api_key.is_some()
+ }
+
+ fn reset_api_key(&self, cx: &mut Context) -> Task> {
+ let credentials_provider = ::global(cx);
+ let settings = &AllLanguageModelSettings::get_global(cx).vercel;
+ let api_url = if settings.api_url.is_empty() {
+ vercel::VERCEL_API_URL.to_string()
+ } else {
+ settings.api_url.clone()
+ };
+ cx.spawn(async move |this, cx| {
+ credentials_provider
+ .delete_credentials(&api_url, &cx)
+ .await
+ .log_err();
+ this.update(cx, |this, cx| {
+ this.api_key = None;
+ this.api_key_from_env = false;
+ cx.notify();
+ })
+ })
+ }
+
+ fn set_api_key(&mut self, api_key: String, cx: &mut Context) -> Task> {
+ let credentials_provider = ::global(cx);
+ let settings = &AllLanguageModelSettings::get_global(cx).vercel;
+ let api_url = if settings.api_url.is_empty() {
+ vercel::VERCEL_API_URL.to_string()
+ } else {
+ settings.api_url.clone()
+ };
+ cx.spawn(async move |this, cx| {
+ credentials_provider
+ .write_credentials(&api_url, "Bearer", api_key.as_bytes(), &cx)
+ .await
+ .log_err();
+ this.update(cx, |this, cx| {
+ this.api_key = Some(api_key);
+ cx.notify();
+ })
+ })
+ }
+
+ fn authenticate(&self, cx: &mut Context
| | |