diff --git a/crates/tabby/src/serve.rs b/crates/tabby/src/serve.rs index 2471041cbcb8..c208a5ce4946 100644 --- a/crates/tabby/src/serve.rs +++ b/crates/tabby/src/serve.rs @@ -55,6 +55,7 @@ Install following IDE / Editor extensions to get started with [Tabby](https://gi completion::CompletionRequest, completion::CompletionResponse, completion::Segments, + completion::Declaration, completion::Choice, completion::Snippet, completion::DebugOptions, diff --git a/crates/tabby/src/services/completion.rs b/crates/tabby/src/services/completion.rs index d0f9b7398a13..1ff3b4c2e424 100644 --- a/crates/tabby/src/services/completion.rs +++ b/crates/tabby/src/services/completion.rs @@ -109,8 +109,8 @@ pub struct Segments { suffix: Option, /// The relative path of the file that is being edited. - /// When git_url is set, this is the path of the file in the git repository. - /// When git_url is empty, this is the path of the file in the workspace. + /// - When `git_url` is set, this is the path of the file in the git repository. + /// - When `git_url` is empty, this is the path of the file in the workspace. filepath: Option, /// The remote URL of the current git repository. @@ -118,10 +118,28 @@ pub struct Segments { /// or the git repository does not have a remote URL. git_url: Option, + /// The relevant declaration code snippets provided by editor. + /// It'll contains declarations extracted from `prefix` segments using LSP. + declarations: Option>, + /// Clipboard content when requesting code completion. clipboard: Option, } +/// A snippet of declaration code that is relevant to the current completion request. +#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] +pub struct Declaration { + /// Filepath of the file where the snippet is from. + /// - When the file belongs to the same workspace as the current file, + /// this is a relative filepath, that has the same root as the current file. + /// - When the file located outside the workspace, such as in a dependency package, + /// this is a file URI with an absolute filepath. + filepath: String, + + /// Body of the snippet. + body: String, +} + impl From for api::event::Segments { fn from(val: Segments) -> Self { Self { diff --git a/crates/tabby/src/services/completion/completion_prompt.rs b/crates/tabby/src/services/completion/completion_prompt.rs index d76f1d3229d4..8c77ff378e43 100644 --- a/crates/tabby/src/services/completion/completion_prompt.rs +++ b/crates/tabby/src/services/completion/completion_prompt.rs @@ -195,6 +195,7 @@ mod tests { suffix, filepath: None, git_url: None, + declarations: None, clipboard: None, } }