From 4a6e0356e8a4d4e07170e1ccc20523aa2cb7e0ea Mon Sep 17 00:00:00 2001 From: Laurynas Keturakis Date: Mon, 2 Sep 2024 23:52:52 +0200 Subject: [PATCH] remove the actual extension as that needs to be in a separate repo --- Cargo.toml | 1 - zed-extension/.gitignore | 1 - zed-extension/Cargo.lock | 7 -- zed-extension/Cargo.toml | 18 ----- zed-extension/extension.toml | 11 --- zed-extension/src/extension.rs | 144 --------------------------------- 6 files changed, 182 deletions(-) delete mode 100644 zed-extension/.gitignore delete mode 100644 zed-extension/Cargo.lock delete mode 100644 zed-extension/Cargo.toml delete mode 100644 zed-extension/extension.toml delete mode 100644 zed-extension/src/extension.rs diff --git a/Cargo.toml b/Cargo.toml index 5c026504e..a62803a7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ members = [ "fpx-workers", "fpx-macros", "xtask", - "zed-extension", ] default-members = ["fpx"] diff --git a/zed-extension/.gitignore b/zed-extension/.gitignore deleted file mode 100644 index ea8c4bf7f..000000000 --- a/zed-extension/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/zed-extension/Cargo.lock b/zed-extension/Cargo.lock deleted file mode 100644 index b68e89ccf..000000000 --- a/zed-extension/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "fiberplane-studio-zed" -version = "0.1.0" diff --git a/zed-extension/Cargo.toml b/zed-extension/Cargo.toml deleted file mode 100644 index 33d8b0c42..000000000 --- a/zed-extension/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "fiberplane-studio-zed" -version = "0.1.0" -edition = "2021" -publish = false -license = "Apache-2.0" - -[dependencies] -zed_extension_api = "0.1.0" -serde = { workspace = true } -serde_json = { workspace = true } -# isahc = { version = "1.7.2", features = ["json"] } -fpx-lib = { version = "0.1.0", path = "../fpx-lib" } - - -[lib] -path = "src/extension.rs" -crate-type = ["cdylib"] diff --git a/zed-extension/extension.toml b/zed-extension/extension.toml deleted file mode 100644 index 944a44d27..000000000 --- a/zed-extension/extension.toml +++ /dev/null @@ -1,11 +0,0 @@ -id = "fiberplane-studio-zed" -name = "Fiberplane Studio" -description = "A way to interface with traces captured by the Fiberplane Studio" -version = "0.1.0" -schema_version = 1 -authors = ["Fiberplane "] -repository = "https://github.com/fiberplane/fpx" - -[slash_commands.trace] -description = "Add a trace from the Fiberplane Studio" -requires_argument = true diff --git a/zed-extension/src/extension.rs b/zed-extension/src/extension.rs deleted file mode 100644 index c3e69cdef..000000000 --- a/zed-extension/src/extension.rs +++ /dev/null @@ -1,144 +0,0 @@ -use fpx_lib::api::models::Span as SpanPayload; -use serde::{Deserialize, Serialize}; -use zed_extension_api::{ - self as zed, http_client, SlashCommand, SlashCommandArgumentCompletion, SlashCommandOutput, - SlashCommandOutputSection, Worktree, -}; - -#[derive(Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -struct Trace { - trace_id: String, - spans: Vec, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Span { - span_id: String, - trace_id: String, - parsed_payload: SpanPayload, -} - -fn get_traces() -> Result, String> { - let url = format!("http://localhost:8788/v1/traces"); - - let request = http_client::HttpRequest { - method: http_client::HttpMethod::Get, - url, - body: None, - headers: vec![("Content-Type".to_string(), "application/json".to_string())], - redirect_policy: http_client::RedirectPolicy::NoFollow, - }; - - let response = http_client::fetch(&request)?; - - serde_json::from_slice(&response.body).map_err(|e| format!("Failed to parse JSON: {}", e)) -} - -fn get_spans(trace_id: &str) -> Result, String> { - let url = format!("http://localhost:8788/v1/traces/{}/spans", trace_id); - - let request = http_client::HttpRequest { - method: http_client::HttpMethod::Get, - url, - body: None, - headers: vec![("Content-Type".to_string(), "application/json".to_string())], - redirect_policy: http_client::RedirectPolicy::NoFollow, - }; - - let response = http_client::fetch(&request)?; - - serde_json::from_slice(&response.body).map_err(|e| format!("Failed to parse JSON: {}", e)) -} - -struct SlashCommandsExampleExtension; - -impl zed::Extension for SlashCommandsExampleExtension { - fn new() -> Self { - SlashCommandsExampleExtension - } - - fn complete_slash_command_argument( - &self, - command: SlashCommand, - _args: Vec, - ) -> Result, String> { - let traces = get_traces()?; - - match command.name.as_str() { - "trace" => Ok(traces - .iter() - .flat_map(|trace| { - trace.spans.iter().map(|span| { - let name = &span.parsed_payload.name; - let method = span - .parsed_payload - .attributes - .0 - .get("http.request.method") - .and_then(|v| v.as_ref()) - .and_then(|v| v.as_str()) - .unwrap_or("UNKNOWN"); - let path = span - .parsed_payload - .attributes - .0 - .get("fpx.http.request.pathname") - .and_then(|v| v.as_ref()) - .and_then(|v| v.as_str()) - .unwrap_or("/"); - let status_code = span - .parsed_payload - .attributes - .0 - .get("http.response.status_code") - .and_then(|v| v.as_ref()) - .and_then(|v| v.as_str()) - .unwrap_or("???"); - - let label = format!("{}: {} {} ({})", name, method, path, status_code); - - SlashCommandArgumentCompletion { - new_text: trace.trace_id.clone(), - label, - run_command: true, - } - }) - }) - .collect::>()), - command => Err(format!("unknown slash command: \"{command}\"")), - } - } - - fn run_slash_command( - &self, - command: SlashCommand, - args: Vec, - _worktree: Option<&Worktree>, - ) -> Result { - match command.name.as_str() { - "trace" => { - let trace_id = args.first().ok_or("no trace id provided")?; - let spans = get_spans(trace_id)?; - let trace = Trace { - trace_id: trace_id.to_string(), - spans, - }; - let formatted_json = serde_json::to_string_pretty(&trace) - .map_err(|e| format!("Failed to format JSON: {}", e))?; - let spans_text = format!("```json\n{}\n```", formatted_json); - Ok(SlashCommandOutput { - sections: vec![SlashCommandOutputSection { - range: (0..spans_text.len()).into(), - label: format!("Trace: {}", trace_id), - }], - text: spans_text, - }) - } - command => Err(format!("unknown slash command: \"{command}\"")), - } - } -} - -zed::register_extension!(SlashCommandsExampleExtension);