Skip to content

Commit

Permalink
fix(tabby-agent): Fix when auto completion shown wrong processed range (
Browse files Browse the repository at this point in the history
#3524)

* fix(codeCompletion): correct processedRange end calculation in CompletionItem

* fix(codeCompletion): update processedRange end calculation to use processedText length

* fix(codeCompletion): refactor processedRange calculation for improved accuracy
  • Loading branch information
Sma1lboy authored Dec 9, 2024
1 parent c61a9ee commit 1f7e7e1
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions clients/tabby-agent/src/codeCompletion/solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,22 @@ export class CompletionItem {
this.isBlank = isBlank(this.text);

// if with auto complete item, insert the completion item with the predicted text
let position = this.context.position;
this.processedText = this.fullText;

if (this.context.isWithCorrectAutoComplete()) {
this.processedText = this.context.insertSeg + this.fullText;
this.processedRange = {
start: this.context.insertPosition,
end: this.context.insertPosition,
};
} else {
this.processedText = this.fullText;
this.processedRange = {
start: this.context.currentLinePrefix.endsWith(this.replacePrefix)
? this.context.position - this.replacePrefix.length
: this.context.position,
end: this.context.currentLineSuffix.startsWith(this.replaceSuffix)
? this.context.position + this.replaceSuffix.length
: this.context.position,
};
position = this.context.insertPosition;
this.processedText = this.context.insertSeg + this.processedText;
}

this.processedRange = {
start: this.context.currentLinePrefix.endsWith(this.replacePrefix)
? position - this.replacePrefix.length
: position,
end: this.context.currentLineSuffix.startsWith(this.replaceSuffix)
? position + this.replaceSuffix.length
: position,
};
}

static createBlankItem(context: CompletionContext): CompletionItem {
Expand Down

0 comments on commit 1f7e7e1

Please sign in to comment.