Render gRPC message body

This commit is contained in:
Gregory Schier
2024-02-18 00:13:56 -08:00
parent 8d29fad261
commit d953a75073
3 changed files with 14 additions and 10 deletions

View File

@@ -219,6 +219,8 @@ async fn cmd_grpc_go(
let cb = { let cb = {
let cancelled_rx = cancelled_rx.clone(); let cancelled_rx = cancelled_rx.clone();
let environment = environment.clone();
let workspace = workspace.clone();
let w = w.clone(); let w = w.clone();
let base_msg = base_msg.clone(); let base_msg = base_msg.clone();
@@ -240,10 +242,12 @@ async fn cmd_grpc_go(
}; };
match serde_json::from_str::<IncomingMsg>(ev.payload().unwrap()) { match serde_json::from_str::<IncomingMsg>(ev.payload().unwrap()) {
Ok(IncomingMsg::Message(msg)) => { Ok(IncomingMsg::Message(raw_msg)) => {
in_msg_tx.try_send(msg.clone()).unwrap(); in_msg_tx.try_send(raw_msg.clone()).unwrap();
let w = w.clone(); let w = w.clone();
let base_msg = base_msg.clone(); let base_msg = base_msg.clone();
let environment_ref = environment.as_ref();
let msg = render::render(raw_msg.as_str(), &workspace, environment_ref);
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
upsert_grpc_message( upsert_grpc_message(
&w, &w,
@@ -306,6 +310,9 @@ async fn cmd_grpc_go(
let w = w.clone(); let w = w.clone();
let base_msg = base_msg.clone(); let base_msg = base_msg.clone();
let req = req.clone(); let req = req.clone();
let workspace = workspace.clone();
let environment = environment.clone();
let msg = render::render(&req.message, &workspace, environment.as_ref());
async move { async move {
let (maybe_stream, maybe_msg) = match ( let (maybe_stream, maybe_msg) = match (
method_desc.is_client_streaming(), method_desc.is_client_streaming(),
@@ -330,18 +337,14 @@ async fn cmd_grpc_go(
(false, true) => ( (false, true) => (
Some( Some(
connection connection
.server_streaming(&service, &method, &req.message, metadata) .server_streaming(&service, &method, &msg, metadata)
.await, .await,
), ),
None, None,
), ),
(false, false) => ( (false, false) => (
None, None,
Some( Some(connection.unary(&service, &method, &msg, metadata).await),
connection
.unary(&service, &method, &req.message, metadata)
.await,
),
), ),
}; };

View File

@@ -106,6 +106,8 @@ export function GrpcEditor({
<div className="h-full w-full grid grid-cols-1 grid-rows-[minmax(0,100%)_auto_auto_minmax(0,auto)]"> <div className="h-full w-full grid grid-cols-1 grid-rows-[minmax(0,100%)_auto_auto_minmax(0,auto)]">
<Editor <Editor
contentType="application/grpc" contentType="application/grpc"
autocompleteVariables
useTemplating
forceUpdateKey={request.id} forceUpdateKey={request.id}
defaultValue={request.message} defaultValue={request.message}
format={tryFormatJson} format={tryFormatJson}

View File

@@ -32,7 +32,6 @@ import {
import { tags as t } from '@lezer/highlight'; import { tags as t } from '@lezer/highlight';
import { graphql, graphqlLanguageSupport } from 'cm6-graphql'; import { graphql, graphqlLanguageSupport } from 'cm6-graphql';
import { EditorView } from 'codemirror'; import { EditorView } from 'codemirror';
import { jsonSchema } from 'codemirror-json-schema';
import type { Environment, Workspace } from '../../../lib/models'; import type { Environment, Workspace } from '../../../lib/models';
import type { EditorProps } from './index'; import type { EditorProps } from './index';
import { text } from './text/extension'; import { text } from './text/extension';
@@ -86,7 +85,7 @@ const myTheme = EditorView.theme({}, { dark: true });
// ]); // ]);
const syntaxExtensions: Record<string, LanguageSupport> = { const syntaxExtensions: Record<string, LanguageSupport> = {
'application/grpc': jsonSchema() as unknown as LanguageSupport, // TODO: Fix this 'application/grpc': json(), // TODO: Make JSONSchema work
'application/graphql': graphqlLanguageSupport(), 'application/graphql': graphqlLanguageSupport(),
'application/json': json(), 'application/json': json(),
'application/javascript': javascript(), 'application/javascript': javascript(),