feat: add select kind param. Supported editors could log line select … (#299)
* feat: add select kind param. Supported editors could log line select or block select * fix lintsweep/improve-logging-information
parent
3457599db5
commit
95bd53ac9c
|
|
@ -33,6 +33,12 @@ pub struct Choice<'a> {
|
|||
pub text: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SelectKind {
|
||||
Line,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Event<'a> {
|
||||
|
|
@ -43,6 +49,8 @@ pub enum Event<'a> {
|
|||
Select {
|
||||
completion_id: &'a str,
|
||||
choice_index: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
kind: Option<SelectKind>,
|
||||
},
|
||||
Completion {
|
||||
completion_id: &'a str,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use axum::Json;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use axum::{extract::Query, Json};
|
||||
use hyper::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tabby_common::events;
|
||||
use tabby_common::events::{self, SelectKind};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
|
||||
|
|
@ -27,7 +29,10 @@ pub struct LogEventRequest {
|
|||
(status = 400, description = "Bad Request")
|
||||
)
|
||||
)]
|
||||
pub async fn log_event(Json(request): Json<LogEventRequest>) -> StatusCode {
|
||||
pub async fn log_event(
|
||||
Query(params): Query<HashMap<String, String>>,
|
||||
Json(request): Json<LogEventRequest>,
|
||||
) -> StatusCode {
|
||||
if request.event_type == "view" {
|
||||
events::Event::View {
|
||||
completion_id: &request.completion_id,
|
||||
|
|
@ -36,9 +41,18 @@ pub async fn log_event(Json(request): Json<LogEventRequest>) -> StatusCode {
|
|||
.log();
|
||||
StatusCode::OK
|
||||
} else if request.event_type == "select" {
|
||||
let is_line = params
|
||||
.get("select_kind")
|
||||
.map(|x| x == "line")
|
||||
.unwrap_or(false);
|
||||
events::Event::Select {
|
||||
completion_id: &request.completion_id,
|
||||
choice_index: request.choice_index,
|
||||
kind: if is_line {
|
||||
Some(SelectKind::Line)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
.log();
|
||||
StatusCode::OK
|
||||
|
|
|
|||
Loading…
Reference in New Issue