Skip to content

Commit

Permalink
fix(codeCompletion): refactor processedRange calculation for improved…
Browse files Browse the repository at this point in the history
… accuracy
  • Loading branch information
Sma1lboy committed Dec 7, 2024
1 parent ba2b0ac commit 6e2a252
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 + this.processedText.length,
};
} 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 6e2a252

Please sign in to comment.