Skip to content

Commit

Permalink
feat(core): add relevant snippets in completion request. (#1742)
Browse files Browse the repository at this point in the history
* feat(api): add relevant snippets in completion request.

* fix: define Declaration instead of using Snippets.

* Apply suggestions from code review

Co-authored-by: Meng Zhang <[email protected]>

---------

Co-authored-by: Meng Zhang <[email protected]>
  • Loading branch information
icycodes and wsxiaoys authored Mar 29, 2024
1 parent df3fbcb commit dfe2ab8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/tabby/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 20 additions & 2 deletions crates/tabby/src/services/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,37 @@ pub struct Segments {
suffix: Option<String>,

/// 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<String>,

/// The remote URL of the current git repository.
/// Leave this empty if the file is not in a git repository,
/// or the git repository does not have a remote URL.
git_url: Option<String>,

/// The relevant declaration code snippets provided by editor.
/// It'll contains declarations extracted from `prefix` segments using LSP.
declarations: Option<Vec<Declaration>>,

/// Clipboard content when requesting code completion.
clipboard: Option<String>,
}

/// 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<Segments> for api::event::Segments {
fn from(val: Segments) -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions crates/tabby/src/services/completion/completion_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ mod tests {
suffix,
filepath: None,
git_url: None,
declarations: None,
clipboard: None,
}
}
Expand Down

0 comments on commit dfe2ab8

Please sign in to comment.