Skip to content

Commit dfe2ab8

Browse files
icycodeswsxiaoys
andauthored
feat(core): add relevant snippets in completion request. (TabbyML#1742)
* 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 <meng@tabbyml.com> --------- Co-authored-by: Meng Zhang <meng@tabbyml.com>
1 parent df3fbcb commit dfe2ab8

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

crates/tabby/src/serve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Install following IDE / Editor extensions to get started with [Tabby](https://gi
5555
completion::CompletionRequest,
5656
completion::CompletionResponse,
5757
completion::Segments,
58+
completion::Declaration,
5859
completion::Choice,
5960
completion::Snippet,
6061
completion::DebugOptions,

crates/tabby/src/services/completion.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,37 @@ pub struct Segments {
109109
suffix: Option<String>,
110110

111111
/// The relative path of the file that is being edited.
112-
/// When git_url is set, this is the path of the file in the git repository.
113-
/// When git_url is empty, this is the path of the file in the workspace.
112+
/// - When `git_url` is set, this is the path of the file in the git repository.
113+
/// - When `git_url` is empty, this is the path of the file in the workspace.
114114
filepath: Option<String>,
115115

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

121+
/// The relevant declaration code snippets provided by editor.
122+
/// It'll contains declarations extracted from `prefix` segments using LSP.
123+
declarations: Option<Vec<Declaration>>,
124+
121125
/// Clipboard content when requesting code completion.
122126
clipboard: Option<String>,
123127
}
124128

129+
/// A snippet of declaration code that is relevant to the current completion request.
130+
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
131+
pub struct Declaration {
132+
/// Filepath of the file where the snippet is from.
133+
/// - When the file belongs to the same workspace as the current file,
134+
/// this is a relative filepath, that has the same root as the current file.
135+
/// - When the file located outside the workspace, such as in a dependency package,
136+
/// this is a file URI with an absolute filepath.
137+
filepath: String,
138+
139+
/// Body of the snippet.
140+
body: String,
141+
}
142+
125143
impl From<Segments> for api::event::Segments {
126144
fn from(val: Segments) -> Self {
127145
Self {

crates/tabby/src/services/completion/completion_prompt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ mod tests {
195195
suffix,
196196
filepath: None,
197197
git_url: None,
198+
declarations: None,
198199
clipboard: None,
199200
}
200201
}

0 commit comments

Comments
 (0)