Compare commits
6 Commits
faster_win
...
show-lua-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e1fe66a19 | ||
|
|
ed52e759d7 | ||
|
|
6da099a9d7 | ||
|
|
5f159bc95e | ||
|
|
a4462577bf | ||
|
|
c147b58558 |
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -490,6 +490,7 @@ dependencies = [
|
||||
"prompt_store",
|
||||
"proto",
|
||||
"rand 0.8.5",
|
||||
"rich_text",
|
||||
"rope",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -8,6 +8,7 @@ members = [
|
||||
"crates/assistant",
|
||||
"crates/assistant2",
|
||||
"crates/assistant_context_editor",
|
||||
"crates/assistant_scripting",
|
||||
"crates/assistant_settings",
|
||||
"crates/assistant_slash_command",
|
||||
"crates/assistant_slash_commands",
|
||||
@@ -118,7 +119,6 @@ members = [
|
||||
"crates/rope",
|
||||
"crates/rpc",
|
||||
"crates/schema_generator",
|
||||
"crates/assistant_scripting",
|
||||
"crates/search",
|
||||
"crates/semantic_index",
|
||||
"crates/semantic_version",
|
||||
|
||||
@@ -21,6 +21,7 @@ test-support = [
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
assistant_context_editor.workspace = true
|
||||
assistant_scripting.workspace = true
|
||||
assistant_settings.workspace = true
|
||||
assistant_slash_command.workspace = true
|
||||
assistant_tool.workspace = true
|
||||
@@ -63,7 +64,7 @@ serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
settings.workspace = true
|
||||
smol.workspace = true
|
||||
assistant_scripting.workspace = true
|
||||
rich_text.workspace = true
|
||||
streaming_diff.workspace = true
|
||||
telemetry_events.workspace = true
|
||||
terminal.workspace = true
|
||||
@@ -82,8 +83,8 @@ zed_actions.workspace = true
|
||||
[dev-dependencies]
|
||||
editor = { workspace = true, features = ["test-support"] }
|
||||
gpui = { workspace = true, "features" = ["test-support"] }
|
||||
indoc.workspace = true
|
||||
language = { workspace = true, "features" = ["test-support"] }
|
||||
language_model = { workspace = true, "features" = ["test-support"] }
|
||||
project = { workspace = true, features = ["test-support"] }
|
||||
rand.workspace = true
|
||||
indoc.workspace = true
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use assistant_scripting::{ScriptId, ScriptState};
|
||||
use collections::{HashMap, HashSet};
|
||||
use editor::{Editor, MultiBuffer};
|
||||
use futures::FutureExt;
|
||||
use gpui::{
|
||||
list, AbsoluteLength, AnyElement, App, ClickEvent, DefiniteLength, EdgesRefinement, Empty,
|
||||
Entity, Focusable, Length, ListAlignment, ListOffset, ListState, StyleRefinement, Subscription,
|
||||
@@ -12,6 +11,8 @@ use language::{Buffer, LanguageRegistry};
|
||||
use language_model::{LanguageModelRegistry, LanguageModelToolUseId, Role};
|
||||
use markdown::{Markdown, MarkdownStyle};
|
||||
use settings::Settings as _;
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, Disclosure, KeyBinding};
|
||||
use util::ResultExt as _;
|
||||
@@ -21,6 +22,8 @@ use crate::thread::{MessageId, RequestKind, Thread, ThreadError, ThreadEvent};
|
||||
use crate::thread_store::ThreadStore;
|
||||
use crate::tool_use::{ToolUse, ToolUseStatus};
|
||||
use crate::ui::ContextPill;
|
||||
use gpui::{HighlightStyle, StyledText};
|
||||
use rich_text::{self, Highlight};
|
||||
|
||||
pub struct ActiveThread {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
@@ -809,11 +812,63 @@ impl ActiveThread {
|
||||
let stdout = script.stdout_snapshot();
|
||||
let error = script.error();
|
||||
|
||||
let lua_language =
|
||||
async { self.language_registry.language_for_name("Lua").await.ok() }
|
||||
.now_or_never()
|
||||
.flatten();
|
||||
|
||||
let source_display = if let Some(lua_language) = &lua_language {
|
||||
let mut highlights = Vec::new();
|
||||
let mut buf = String::new();
|
||||
|
||||
rich_text::render_code(
|
||||
&mut buf,
|
||||
&mut highlights,
|
||||
&script.source,
|
||||
lua_language,
|
||||
);
|
||||
|
||||
let theme = cx.theme();
|
||||
let gpui_highlights: Vec<(Range<usize>, HighlightStyle)> = highlights
|
||||
.iter()
|
||||
.map(|(range, highlight)| {
|
||||
let style = match highlight {
|
||||
Highlight::Code => Default::default(),
|
||||
Highlight::Id(id) => {
|
||||
id.style(theme.syntax()).unwrap_or_default()
|
||||
}
|
||||
Highlight::InlineCode(_) => Default::default(),
|
||||
Highlight::Highlight(highlight) => *highlight,
|
||||
_ => HighlightStyle::default(),
|
||||
};
|
||||
(range.clone(), style)
|
||||
})
|
||||
.collect();
|
||||
|
||||
StyledText::new(buf)
|
||||
.with_highlights(gpui_highlights)
|
||||
.into_any_element()
|
||||
} else {
|
||||
Label::new(script.source.clone())
|
||||
.size(LabelSize::Small)
|
||||
.buffer_font(cx)
|
||||
.into_any_element()
|
||||
};
|
||||
|
||||
parent.child(
|
||||
v_flex()
|
||||
.p_2()
|
||||
.bg(colors.editor_background)
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
.p_2()
|
||||
.bg(colors.editor_foreground.opacity(0.025))
|
||||
.rounded_md()
|
||||
.child(source_display),
|
||||
)
|
||||
.child(if stdout.is_empty() && error.is_none() {
|
||||
Label::new("No output yet")
|
||||
.size(LabelSize::Small)
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
-- Create a sandbox environment
|
||||
local sandbox = {}
|
||||
|
||||
-- For now, add all globals to `sandbox` (so there effectively is no sandbox).
|
||||
-- We still need the logic below so that we can do things like overriding print() to write
|
||||
-- to our in-memory log rather than to stdout, we will delete this loop (and re-enable
|
||||
-- the I/O module being sandboxed below) to have things be sandboxed again.
|
||||
for k, v in pairs(_G) do
|
||||
if sandbox[k] == nil then
|
||||
sandbox[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
-- Allow access to standard libraries (safe subset)
|
||||
sandbox.string = string
|
||||
sandbox.table = table
|
||||
@@ -25,8 +35,7 @@ local io = {}
|
||||
io.open = sb_io_open
|
||||
|
||||
-- Add the sandboxed io library to the sandbox environment
|
||||
sandbox.io = io
|
||||
|
||||
-- sandbox.io = io -- Uncomment this line to re-enable sandboxed file I/O.
|
||||
|
||||
-- Load the script with the sandbox environment
|
||||
local user_script_fn, err = load(user_script, nil, "t", sandbox)
|
||||
|
||||
@@ -119,6 +119,14 @@ impl ScriptSession {
|
||||
let lua = Lua::new();
|
||||
lua.set_memory_limit(2 * 1024 * 1024 * 1024)?; // 2 GB
|
||||
let globals = lua.globals();
|
||||
|
||||
// Use the project root dir as the script's current working dir.
|
||||
if let Some(root_dir) = &root_dir {
|
||||
if let Some(root_dir) = root_dir.to_str() {
|
||||
globals.set("cwd", root_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
globals.set(
|
||||
"sb_print",
|
||||
lua.create_function({
|
||||
|
||||
@@ -11639,7 +11639,7 @@ impl Editor {
|
||||
fn go_to_next_hunk(&mut self, _: &GoToHunk, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let snapshot = self.snapshot(window, cx);
|
||||
let selection = self.selections.newest::<Point>(cx);
|
||||
self.go_to_hunk_after_or_before_position(
|
||||
self.go_to_hunk_before_or_after_position(
|
||||
&snapshot,
|
||||
selection.head(),
|
||||
Direction::Next,
|
||||
@@ -11648,7 +11648,7 @@ impl Editor {
|
||||
);
|
||||
}
|
||||
|
||||
fn go_to_hunk_after_or_before_position(
|
||||
fn go_to_hunk_before_or_after_position(
|
||||
&mut self,
|
||||
snapshot: &EditorSnapshot,
|
||||
position: Point,
|
||||
@@ -11699,7 +11699,7 @@ impl Editor {
|
||||
) {
|
||||
let snapshot = self.snapshot(window, cx);
|
||||
let selection = self.selections.newest::<Point>(cx);
|
||||
self.go_to_hunk_after_or_before_position(
|
||||
self.go_to_hunk_before_or_after_position(
|
||||
&snapshot,
|
||||
selection.head(),
|
||||
Direction::Prev,
|
||||
@@ -13861,21 +13861,6 @@ impl Editor {
|
||||
return;
|
||||
}
|
||||
|
||||
let snapshot = self.snapshot(window, cx);
|
||||
let newest_range = self.selections.newest::<Point>(cx).range();
|
||||
|
||||
let run_twice = snapshot
|
||||
.hunks_for_ranges([newest_range])
|
||||
.first()
|
||||
.is_some_and(|hunk| {
|
||||
let next_line = Point::new(hunk.row_range.end.0 + 1, 0);
|
||||
self.hunk_after_position(&snapshot, next_line)
|
||||
.is_some_and(|other| other.row_range == hunk.row_range)
|
||||
});
|
||||
|
||||
if run_twice {
|
||||
self.go_to_next_hunk(&GoToHunk, window, cx);
|
||||
}
|
||||
self.stage_or_unstage_diff_hunks(stage, ranges, cx);
|
||||
self.go_to_next_hunk(&GoToHunk, window, cx);
|
||||
}
|
||||
|
||||
@@ -9014,7 +9014,7 @@ fn diff_hunk_controls(
|
||||
let snapshot = editor.snapshot(window, cx);
|
||||
let position =
|
||||
hunk_range.end.to_point(&snapshot.buffer_snapshot);
|
||||
editor.go_to_hunk_after_or_before_position(
|
||||
editor.go_to_hunk_before_or_after_position(
|
||||
&snapshot,
|
||||
position,
|
||||
Direction::Next,
|
||||
@@ -9050,7 +9050,7 @@ fn diff_hunk_controls(
|
||||
let snapshot = editor.snapshot(window, cx);
|
||||
let point =
|
||||
hunk_range.start.to_point(&snapshot.buffer_snapshot);
|
||||
editor.go_to_hunk_after_or_before_position(
|
||||
editor.go_to_hunk_before_or_after_position(
|
||||
&snapshot,
|
||||
point,
|
||||
Direction::Prev,
|
||||
|
||||
@@ -152,7 +152,10 @@ impl GoToLine {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
match event {
|
||||
editor::EditorEvent::Blurred => cx.emit(DismissEvent),
|
||||
editor::EditorEvent::Blurred => {
|
||||
self.prev_scroll_position.take();
|
||||
cx.emit(DismissEvent)
|
||||
}
|
||||
editor::EditorEvent::BufferEdited { .. } => self.highlight_current_line(cx),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
- [Rust](./languages/rust.md)
|
||||
- [Scala](./languages/scala.md)
|
||||
- [Scheme](./languages/scheme.md)
|
||||
- [Shell Script](./languages/sh.md)
|
||||
- [Svelte](./languages/svelte.md)
|
||||
- [Swift](./languages/swift.md)
|
||||
- [Tailwind CSS](./languages/tailwindcss.md)
|
||||
|
||||
@@ -28,6 +28,7 @@ Zed supports hundreds of programming languages and text formats. Some work out-o
|
||||
- [Go](./languages/go.md)
|
||||
- [Groovy](./languages/groovy.md)
|
||||
- [Haskell](./languages/haskell.md)
|
||||
- [Helm](./languages/helm.md)
|
||||
- [HTML](./languages/html.md)
|
||||
- [Java](./languages/java.md)
|
||||
- [JavaScript](./languages/javascript.md)
|
||||
@@ -58,7 +59,7 @@ Zed supports hundreds of programming languages and text formats. Some work out-o
|
||||
- [Shell Script](./languages/sh.md)
|
||||
- [Svelte](./languages/svelte.md)
|
||||
- [Swift](./languages/swift.md)
|
||||
- [TailwindCSS](./languages/tailwindcss.md)
|
||||
- [Tailwind CSS](./languages/tailwindcss.md)
|
||||
- [Terraform](./languages/terraform.md)
|
||||
- [TOML](./languages/toml.md)
|
||||
- [TypeScript](./languages/typescript.md)
|
||||
|
||||
Reference in New Issue
Block a user