Checkpoint

This commit is contained in:
SilasMarvin
2024-03-23 12:22:14 -07:00
parent 217933c0c7
commit a096f2d738
12 changed files with 459 additions and 211 deletions

View File

@@ -26,19 +26,29 @@ pub enum PromptForType {
Generate,
}
#[async_trait::async_trait]
pub trait MemoryBackend {
fn init(&self) -> anyhow::Result<()> {
async fn init(&self) -> anyhow::Result<()> {
Ok(())
}
fn opened_text_document(&mut self, params: DidOpenTextDocumentParams) -> anyhow::Result<()>;
fn changed_text_document(&mut self, params: DidChangeTextDocumentParams) -> anyhow::Result<()>;
fn renamed_file(&mut self, params: RenameFilesParams) -> anyhow::Result<()>;
fn build_prompt(
async fn opened_text_document(
&mut self,
params: DidOpenTextDocumentParams,
) -> anyhow::Result<()>;
async fn changed_text_document(
&mut self,
params: DidChangeTextDocumentParams,
) -> anyhow::Result<()>;
async fn renamed_file(&mut self, params: RenameFilesParams) -> anyhow::Result<()>;
async fn build_prompt(
&mut self,
position: &TextDocumentPositionParams,
prompt_for_type: PromptForType,
) -> anyhow::Result<Prompt>;
fn get_filter_text(&self, position: &TextDocumentPositionParams) -> anyhow::Result<String>;
async fn get_filter_text(
&self,
position: &TextDocumentPositionParams,
) -> anyhow::Result<String>;
}
impl TryFrom<Configuration> for Box<dyn MemoryBackend + Send> {
@@ -55,3 +65,15 @@ impl TryFrom<Configuration> for Box<dyn MemoryBackend + Send> {
}
}
}
// This makes testing much easier. Every transformer backend takes in a prompt. When verifying they work, its
// easier to just pass in a default prompt.
#[cfg(test)]
impl Prompt {
pub fn default_with_cursor() -> Self {
Self {
context: r#"def test_context():\n pass"#.to_string(),
code: r#"def test_code():\n <CURSOR>"#.to_string(),
}
}
}