feat: add clipboard segment (#898)
* feat: add clipboard segment * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>add-prompt-lookup
parent
a7202318b1
commit
2212171825
|
|
@ -47,10 +47,12 @@ pub enum Event<'a> {
|
||||||
user: Option<&'a str>,
|
user: Option<&'a str>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Segments {
|
pub struct Segments {
|
||||||
pub prefix: String,
|
pub prefix: String,
|
||||||
pub suffix: Option<String>,
|
pub suffix: Option<String>,
|
||||||
|
pub clipboard: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EventLogger: Send + Sync {
|
pub trait EventLogger: Send + Sync {
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,9 @@ pub struct Segments {
|
||||||
|
|
||||||
/// Content that appears after the cursor in the editor window.
|
/// Content that appears after the cursor in the editor window.
|
||||||
suffix: Option<String>,
|
suffix: Option<String>,
|
||||||
|
|
||||||
|
/// Clipboard content when requesting code completion.
|
||||||
|
clipboard: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Segments> for api::event::Segments {
|
impl From<Segments> for api::event::Segments {
|
||||||
|
|
@ -108,6 +111,7 @@ impl From<Segments> for api::event::Segments {
|
||||||
Self {
|
Self {
|
||||||
prefix: val.prefix,
|
prefix: val.prefix,
|
||||||
suffix: val.suffix,
|
suffix: val.suffix,
|
||||||
|
clipboard: val.clipboard,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,14 @@ mod tests {
|
||||||
PromptBuilder::new(prompt_template, None)
|
PromptBuilder::new(prompt_template, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_segment(prefix: String, suffix: Option<String>) -> Segments {
|
||||||
|
Segments {
|
||||||
|
prefix,
|
||||||
|
suffix,
|
||||||
|
clipboard: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prompt_template() {
|
fn test_prompt_template() {
|
||||||
let pb = create_prompt_builder(true);
|
let pb = create_prompt_builder(true);
|
||||||
|
|
@ -202,10 +210,10 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ prefix, w/ suffix.
|
// Test w/ prefix, w/ suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment(
|
||||||
prefix: "this is some prefix".into(),
|
"this is some prefix".into(),
|
||||||
suffix: Some("this is some suffix".into()),
|
Some("this is some suffix".into()),
|
||||||
};
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"<PRE> this is some prefix <SUF>this is some suffix <MID>"
|
"<PRE> this is some prefix <SUF>this is some suffix <MID>"
|
||||||
|
|
@ -214,10 +222,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ prefix, w/o suffix.
|
// Test w/ prefix, w/o suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("this is some prefix".into(), None);
|
||||||
prefix: "this is some prefix".into(),
|
|
||||||
suffix: None,
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"<PRE> this is some prefix <SUF>\n <MID>"
|
"<PRE> this is some prefix <SUF>\n <MID>"
|
||||||
|
|
@ -226,10 +231,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ prefix, w/ empty suffix.
|
// Test w/ prefix, w/ empty suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("this is some prefix".into(), Some("".into()));
|
||||||
prefix: "this is some prefix".into(),
|
|
||||||
suffix: Some("".into()),
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"<PRE> this is some prefix <SUF>\n <MID>"
|
"<PRE> this is some prefix <SUF>\n <MID>"
|
||||||
|
|
@ -238,10 +240,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ empty prefix, w/ suffix.
|
// Test w/ empty prefix, w/ suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("".into(), Some("this is some suffix".into()));
|
||||||
prefix: "".into(),
|
|
||||||
suffix: Some("this is some suffix".into()),
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"<PRE> <SUF>this is some suffix <MID>"
|
"<PRE> <SUF>this is some suffix <MID>"
|
||||||
|
|
@ -250,10 +249,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ empty prefix, w/o suffix.
|
// Test w/ empty prefix, w/o suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("".into(), None);
|
||||||
prefix: "".into(),
|
|
||||||
suffix: None,
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"<PRE> <SUF>\n <MID>"
|
"<PRE> <SUF>\n <MID>"
|
||||||
|
|
@ -262,10 +258,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ emtpy prefix, w/ empty suffix.
|
// Test w/ emtpy prefix, w/ empty suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("".into(), Some("".into()));
|
||||||
prefix: "".into(),
|
|
||||||
suffix: Some("".into()),
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"<PRE> <SUF>\n <MID>"
|
"<PRE> <SUF>\n <MID>"
|
||||||
|
|
@ -283,10 +276,10 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ prefix, w/ suffix.
|
// Test w/ prefix, w/ suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment(
|
||||||
prefix: "this is some prefix".into(),
|
"this is some prefix".into(),
|
||||||
suffix: Some("this is some suffix".into()),
|
Some("this is some suffix".into()),
|
||||||
};
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"this is some prefix"
|
"this is some prefix"
|
||||||
|
|
@ -295,10 +288,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ prefix, w/o suffix.
|
// Test w/ prefix, w/o suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("this is some prefix".into(), None);
|
||||||
prefix: "this is some prefix".into(),
|
|
||||||
suffix: None,
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"this is some prefix"
|
"this is some prefix"
|
||||||
|
|
@ -307,10 +297,7 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ prefix, w/ empty suffix.
|
// Test w/ prefix, w/ empty suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("this is some prefix".into(), Some("".into()));
|
||||||
prefix: "this is some prefix".into(),
|
|
||||||
suffix: Some("".into()),
|
|
||||||
};
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pb.build(language, segments, snippets),
|
pb.build(language, segments, snippets),
|
||||||
"this is some prefix"
|
"this is some prefix"
|
||||||
|
|
@ -319,28 +306,19 @@ mod tests {
|
||||||
|
|
||||||
// Test w/ empty prefix, w/ suffix.
|
// Test w/ empty prefix, w/ suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("".into(), Some("this is some suffix".into()));
|
||||||
prefix: "".into(),
|
|
||||||
suffix: Some("this is some suffix".into()),
|
|
||||||
};
|
|
||||||
assert_eq!(pb.build(language, segments, snippets), "");
|
assert_eq!(pb.build(language, segments, snippets), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test w/ empty prefix, w/o suffix.
|
// Test w/ empty prefix, w/o suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("".into(), None);
|
||||||
prefix: "".into(),
|
|
||||||
suffix: None,
|
|
||||||
};
|
|
||||||
assert_eq!(pb.build(language, segments, snippets), "");
|
assert_eq!(pb.build(language, segments, snippets), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test w/ empty prefix, w/ empty suffix.
|
// Test w/ empty prefix, w/ empty suffix.
|
||||||
{
|
{
|
||||||
let segments = Segments {
|
let segments = make_segment("".into(), Some("".into()));
|
||||||
prefix: "".into(),
|
|
||||||
suffix: Some("".into()),
|
|
||||||
};
|
|
||||||
assert_eq!(pb.build(language, segments, snippets), "");
|
assert_eq!(pb.build(language, segments, snippets), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue