Allow copy-pasting dev-server-token (#11992)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-05-17 16:41:46 -06:00 committed by GitHub
parent 84affa96ff
commit 1f611a9c90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 184 additions and 44 deletions

View file

@ -18,15 +18,14 @@ editor.workspace = true
feature_flags.workspace = true
fuzzy.workspace = true
gpui.workspace = true
markdown.workspace = true
menu.workspace = true
ordered-float.workspace = true
picker.workspace = true
dev_server_projects.workspace = true
rpc.workspace = true
serde.workspace = true
settings.workspace = true
smol.workspace = true
theme.workspace = true
ui.workspace = true
ui_text_field.workspace = true
util.workspace = true

View file

@ -10,12 +10,12 @@ use gpui::{
DismissEvent, EventEmitter, FocusHandle, FocusableView, Model, ScrollHandle, Transformation,
View, ViewContext,
};
use markdown::Markdown;
use markdown::MarkdownStyle;
use rpc::{
proto::{CreateDevServerResponse, DevServerStatus, RegenerateDevServerTokenResponse},
ErrorCode, ErrorExt,
};
use settings::Settings;
use theme::ThemeSettings;
use ui::CheckboxWithLabel;
use ui::{prelude::*, Indicator, List, ListHeader, ListItem, ModalContent, ModalHeader, Tooltip};
use ui_text_field::{FieldLabelLayout, TextField};
@ -33,6 +33,7 @@ pub struct DevServerProjects {
dev_server_name_input: View<TextField>,
use_server_name_in_ssh: Selection,
rename_dev_server_input: View<TextField>,
markdown: View<Markdown>,
_dev_server_subscription: Subscription,
}
@ -113,6 +114,23 @@ impl DevServerProjects {
cx.notify();
});
let markdown_style = MarkdownStyle {
code_block: gpui::TextStyleRefinement {
font_family: Some("Zed Mono".into()),
color: Some(cx.theme().colors().editor_foreground),
background_color: Some(cx.theme().colors().editor_background),
..Default::default()
},
inline_code: Default::default(),
block_quote: Default::default(),
link: Default::default(),
rule_color: Default::default(),
block_quote_border_color: Default::default(),
syntax: cx.theme().syntax().clone(),
selection_background_color: cx.theme().players().local().selection,
};
let markdown = cx.new_view(|cx| Markdown::new("".to_string(), markdown_style, None, cx));
Self {
mode: Mode::Default(None),
focus_handle,
@ -121,6 +139,7 @@ impl DevServerProjects {
project_path_input,
dev_server_name_input,
rename_dev_server_input,
markdown,
use_server_name_in_ssh: Selection::Unselected,
_dev_server_subscription: subscription,
}
@ -726,7 +745,7 @@ impl DevServerProjects {
.child(
CheckboxWithLabel::new(
"use-server-name-in-ssh",
Label::new("Use name as ssh connection string"),
Label::new("Use SSH for terminals"),
self.use_server_name_in_ssh,
|&_, _| {}
)
@ -748,7 +767,7 @@ impl DevServerProjects {
};
div.px_2().child(Label::new(format!(
"Once you have created a dev server, you will be given a command to run on the server to register it.\n\n\
Ssh connection string enables remote terminals, which runs `ssh {ssh_host_name}` when creating terminal tabs."
If you enable SSH, then the terminal will automatically `ssh {ssh_host_name}` on open."
)))
})
.when_some(dev_server.clone(), |div, dev_server| {
@ -758,7 +777,7 @@ impl DevServerProjects {
.dev_server_status(DevServerId(dev_server.dev_server_id));
div.child(
Self::render_dev_server_token_instructions(&dev_server.access_token, &dev_server.name, status, cx)
self.render_dev_server_token_instructions(&dev_server.access_token, &dev_server.name, status, cx)
)
}),
)
@ -766,12 +785,18 @@ impl DevServerProjects {
}
fn render_dev_server_token_instructions(
&self,
access_token: &str,
dev_server_name: &str,
status: DevServerStatus,
cx: &mut ViewContext<Self>,
) -> Div {
let instructions = SharedString::from(format!("zed --dev-server-token {}", access_token));
self.markdown.update(cx, |markdown, cx| {
if !markdown.source().contains(access_token) {
markdown.reset(format!("```\n{}\n```", instructions), cx);
}
});
v_flex()
.pl_2()
@ -799,19 +824,7 @@ impl DevServerProjects {
}),
),
)
.child(
v_flex()
.w_full()
.bg(cx.theme().colors().title_bar_background) // todo: this should be distinct
.border_1()
.border_color(cx.theme().colors().border_variant)
.rounded_md()
.my_1()
.py_0p5()
.px_3()
.font_family(ThemeSettings::get_global(cx).buffer_font.family.clone())
.child(Label::new(instructions)),
)
.child(v_flex().w_full().child(self.markdown.clone()))
.when(status == DevServerStatus::Offline, |this| {
this.child(Self::render_loading_spinner("Waiting for connection…"))
})
@ -926,14 +939,13 @@ impl DevServerProjects {
EditDevServerState::RegeneratingToken => {
Self::render_loading_spinner("Generating token...")
}
EditDevServerState::RegeneratedToken(response) => {
Self::render_dev_server_token_instructions(
EditDevServerState::RegeneratedToken(response) => self
.render_dev_server_token_instructions(
&response.access_token,
&dev_server_name,
dev_server_status,
cx,
)
}
),
_ => h_flex().items_end().w_full().child(
Button::new("regenerate-dev-server-token", "Generate new access token")
.icon(IconName::Update)