feat: agent enable per request prefix/suffix max lines configuration (#255)
parent
7ed5dd584d
commit
450e6bbb56
|
|
@ -0,0 +1,7 @@
|
|||
.PHONY: openapi-codegen
|
||||
openapi-codegen:
|
||||
yarn run openapi-codegen
|
||||
|
||||
.PHONY: build
|
||||
build: openapi-codegen
|
||||
yarn run build
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -57,6 +57,8 @@ type CompletionRequest = {
|
|||
language: string;
|
||||
text: string;
|
||||
position: number;
|
||||
maxPrefixLines: number;
|
||||
maxSuffixLines: number;
|
||||
};
|
||||
type CompletionResponse = CompletionResponse$1;
|
||||
type LogEventRequest = LogEventRequest$1;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1046,14 +1046,15 @@ var _TabbyAgent = class extends import_events2.EventEmitter {
|
|||
});
|
||||
}
|
||||
createSegments(request2) {
|
||||
const maxLines = 20;
|
||||
const maxPrefixLines = request2.maxPrefixLines;
|
||||
const maxSuffixLines = request2.maxSuffixLines;
|
||||
const prefix = request2.text.slice(0, request2.position);
|
||||
const prefixLines = splitLines(prefix);
|
||||
const suffix = request2.text.slice(request2.position);
|
||||
const suffixLines = splitLines(suffix);
|
||||
return {
|
||||
prefix: prefixLines.slice(Math.max(prefixLines.length - maxLines, 0)).join(""),
|
||||
suffix: suffixLines.slice(0, maxLines).join("")
|
||||
prefix: prefixLines.slice(Math.max(prefixLines.length - maxPrefixLines, 0)).join(""),
|
||||
suffix: suffixLines.slice(0, maxSuffixLines).join("")
|
||||
};
|
||||
}
|
||||
async initialize(options) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -15097,14 +15097,15 @@ var _TabbyAgent = class extends EventEmitter {
|
|||
});
|
||||
}
|
||||
createSegments(request2) {
|
||||
const maxLines = 20;
|
||||
const maxPrefixLines = request2.maxPrefixLines;
|
||||
const maxSuffixLines = request2.maxSuffixLines;
|
||||
const prefix = request2.text.slice(0, request2.position);
|
||||
const prefixLines = splitLines(prefix);
|
||||
const suffix = request2.text.slice(request2.position);
|
||||
const suffixLines = splitLines(suffix);
|
||||
return {
|
||||
prefix: prefixLines.slice(Math.max(prefixLines.length - maxLines, 0)).join(""),
|
||||
suffix: suffixLines.slice(0, maxLines).join("")
|
||||
prefix: prefixLines.slice(Math.max(prefixLines.length - maxPrefixLines, 0)).join(""),
|
||||
suffix: suffixLines.slice(0, maxSuffixLines).join("")
|
||||
};
|
||||
}
|
||||
async initialize(options) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -16,6 +16,8 @@ export type CompletionRequest = {
|
|||
language: string;
|
||||
text: string;
|
||||
position: number;
|
||||
maxPrefixLines: number;
|
||||
maxSuffixLines: number;
|
||||
};
|
||||
|
||||
export type CompletionResponse = ApiCompletionResponse;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ export class StdIO {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error({ error }, `Failed to handle request: ${JSON.stringify(request)}`);
|
||||
this.logger.error({ error, request }, `Failed to handle request`);
|
||||
} finally {
|
||||
return response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,15 +123,16 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
|||
}
|
||||
|
||||
private createSegments(request: CompletionRequest): { prefix: string; suffix: string } {
|
||||
// max to 20 lines in prefix and max to 20 lines in suffix
|
||||
const maxLines = 20;
|
||||
// max lines in prefix and suffix configurable
|
||||
const maxPrefixLines = request.maxPrefixLines;
|
||||
const maxSuffixLines = request.maxSuffixLines;
|
||||
const prefix = request.text.slice(0, request.position);
|
||||
const prefixLines = splitLines(prefix);
|
||||
const suffix = request.text.slice(request.position);
|
||||
const suffixLines = splitLines(suffix);
|
||||
return {
|
||||
prefix: prefixLines.slice(Math.max(prefixLines.length - maxLines, 0)).join(""),
|
||||
suffix: suffixLines.slice(0, maxLines).join(""),
|
||||
prefix: prefixLines.slice(Math.max(prefixLines.length - maxPrefixLines, 0)).join(""),
|
||||
suffix: suffixLines.slice(0, maxSuffixLines).join(""),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ import { StdIO } from "./StdIO";
|
|||
const stdio = new StdIO();
|
||||
TabbyAgent.create().then((agent) => {
|
||||
stdio.bind(agent);
|
||||
stdio.listen();
|
||||
});
|
||||
|
||||
stdio.listen();
|
||||
|
|
|
|||
|
|
@ -105,6 +105,8 @@ endfunction
|
|||
" - g:tabby_suggestion_delay
|
||||
" - g:tabby_filetype_to_languages
|
||||
" - g:tabby_server_url
|
||||
" - g:tabby_max_prefix_lines
|
||||
" - g:tabby_max_suffix_lines
|
||||
"
|
||||
|
||||
if !exists('g:tabby_enabled')
|
||||
|
|
@ -115,6 +117,13 @@ if !exists('g:tabby_suggestion_delay')
|
|||
let g:tabby_suggestion_delay = 150
|
||||
endif
|
||||
|
||||
if !exists('g:tabby_max_prefix_lines')
|
||||
let g:tabby_max_prefix_lines = 20
|
||||
endif
|
||||
if !exists('g:tabby_max_suffix_lines')
|
||||
let g:tabby_max_suffix_lines = 20
|
||||
endif
|
||||
|
||||
if !exists('g:tabby_filetype_to_languages')
|
||||
" From: vim filetype https://github.com/vim/vim/blob/master/runtime/filetype.vim
|
||||
" To: vscode language identifier https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
|
||||
|
|
@ -530,6 +539,8 @@ function! s:CreateCompletionRequest()
|
|||
\ language: s:GetLanguage(),
|
||||
\ text: join(getbufline('%', 1, '$'), "\n"),
|
||||
\ position: line2byte(line('.')) + col('.') - 2,
|
||||
\ maxPrefixLines: g:tabby_max_prefix_lines,
|
||||
\ maxSuffixLines: g:tabby_max_suffix_lines,
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -181,11 +181,6 @@ braces@^3.0.2:
|
|||
dependencies:
|
||||
fill-range "^7.0.1"
|
||||
|
||||
browser-or-node@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/browser-or-node/-/browser-or-node-2.1.1.tgz#738790b3a86a8fc020193fa581273fbe65eaea0f"
|
||||
integrity sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==
|
||||
|
||||
buffer@^6.0.3:
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6"
|
||||
|
|
@ -496,6 +491,15 @@ form-data@^4.0.0:
|
|||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
fs-extra@^11.1.1:
|
||||
version "11.1.1"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
|
||||
integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==
|
||||
dependencies:
|
||||
graceful-fs "^4.2.0"
|
||||
jsonfile "^6.0.1"
|
||||
universalify "^2.0.0"
|
||||
|
||||
function-bind@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
|
||||
|
|
@ -552,7 +556,7 @@ gopd@^1.0.1:
|
|||
dependencies:
|
||||
get-intrinsic "^1.1.3"
|
||||
|
||||
graceful-fs@^4.1.2:
|
||||
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
|
||||
version "4.2.11"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
|
||||
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
|
||||
|
|
@ -816,11 +820,25 @@ json-parse-even-better-errors@^2.3.0:
|
|||
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
|
||||
integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==
|
||||
|
||||
jsonfile@^6.0.1:
|
||||
version "6.1.0"
|
||||
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
|
||||
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
|
||||
dependencies:
|
||||
universalify "^2.0.0"
|
||||
optionalDependencies:
|
||||
graceful-fs "^4.1.6"
|
||||
|
||||
junk@^4.0.0:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/junk/-/junk-4.0.1.tgz#7ee31f876388c05177fe36529ee714b07b50fbed"
|
||||
integrity sha512-Qush0uP+G8ZScpGMZvHUiRfI0YBWuB3gVBYlI0v0vvOJt5FLicco+IkP0a50LqTTQhmts/m6tP5SWE+USyIvcQ==
|
||||
|
||||
jwt-decode@^3.1.2:
|
||||
version "3.1.2"
|
||||
resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59"
|
||||
integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==
|
||||
|
||||
kind-of@^6.0.3:
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
|
||||
|
|
@ -1361,10 +1379,11 @@ supports-color@^5.3.0:
|
|||
version "0.0.1"
|
||||
dependencies:
|
||||
axios "^1.4.0"
|
||||
browser-or-node "^2.1.1"
|
||||
deep-equal "^2.2.1"
|
||||
deepmerge "^4.3.1"
|
||||
form-data "^4.0.0"
|
||||
fs-extra "^11.1.1"
|
||||
jwt-decode "^3.1.2"
|
||||
lru-cache "^9.1.1"
|
||||
object-hash "^3.0.0"
|
||||
object-sizeof "^2.6.1"
|
||||
|
|
@ -1396,6 +1415,11 @@ type-fest@^1.0.1, type-fest@^1.2.1, type-fest@^1.2.2:
|
|||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1"
|
||||
integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==
|
||||
|
||||
universalify@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
|
||||
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
|
||||
|
||||
uuid@^9.0.0:
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
|
||||
|
|
|
|||
|
|
@ -58,6 +58,16 @@
|
|||
"type": "object",
|
||||
"description": "Developer options for Tabby.",
|
||||
"properties": {
|
||||
"maxPrefixLines": {
|
||||
"type": "number",
|
||||
"default": 20,
|
||||
"description": "Number of lines to include in the Prefix for completion requests"
|
||||
},
|
||||
"maxSuffixLines": {
|
||||
"type": "number",
|
||||
"default": 20,
|
||||
"description": "Number of lines to include in the Suffix for completion requests"
|
||||
},
|
||||
"suggestionDelay": {
|
||||
"type": "number",
|
||||
"default": 150,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
|||
// User Settings
|
||||
private enabled: boolean = true;
|
||||
private suggestionDelay: number = 150;
|
||||
private maxPrefixLines: number = 20;
|
||||
private maxSuffixLines: number = 20;
|
||||
|
||||
constructor() {
|
||||
this.updateConfiguration();
|
||||
|
|
@ -60,6 +62,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
|||
language: document.languageId, // https://code.visualstudio.com/docs/languages/identifiers
|
||||
text: document.getText(),
|
||||
position: document.offsetAt(position),
|
||||
maxPrefixLines: this.maxPrefixLines,
|
||||
maxSuffixLines: this.maxSuffixLines,
|
||||
};
|
||||
this.pendingCompletion = agent().getCompletions(request);
|
||||
|
||||
|
|
@ -76,6 +80,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
|||
const configuration = workspace.getConfiguration("tabby");
|
||||
this.enabled = configuration.get("codeCompletion", true);
|
||||
this.suggestionDelay = configuration.get("developerOptions.suggestionDelay", 150);
|
||||
this.maxPrefixLines = configuration.get("developerOptions.maxPrefixLines", 20);
|
||||
this.maxSuffixLines = configuration.get("developerOptions.maxSuffixLines", 20);
|
||||
}
|
||||
|
||||
private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] {
|
||||
|
|
|
|||
Loading…
Reference in New Issue