Skip to content

Commit

Permalink
Fixes #3928 (#180404)
Browse files Browse the repository at this point in the history
* Fixes #3928

* Fixes CI
  • Loading branch information
hediet authored Apr 21, 2023
1 parent 93a5a6e commit 8d00125
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { BugIndicatingError } from 'vs/base/common/errors';
import { matchesSubString } from 'vs/base/common/filters';
import { Disposable, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { ITransaction, derived } from 'vs/base/common/observable';
Expand Down Expand Up @@ -246,6 +245,7 @@ export class UpToDateInlineCompletions implements IDisposable {
export class InlineCompletionWithUpdatedRange {
public readonly semanticId = JSON.stringify([this.inlineCompletion.filterText, this.inlineCompletion.insertText, this.inlineCompletion.range.getStartPosition().toString()]);
private _updatedRange: Range;
private _isValid = true;

constructor(
public readonly inlineCompletion: InlineCompletionItem,
Expand All @@ -264,7 +264,9 @@ export class InlineCompletionWithUpdatedRange {
public _updateRange(textModel: ITextModel): boolean {
const range = textModel.getDecorationRange(this.decorationId);
if (!range) {
throw new BugIndicatingError();
// A setValue call might flush all decorations.
this._isValid = false;
return true;
}
if (!this._updatedRange.equalsRange(range)) {
this._updatedRange = range;
Expand All @@ -284,11 +286,11 @@ export class InlineCompletionWithUpdatedRange {
public isVisible(model: ITextModel, cursorPosition: Position, reader: IReader | undefined): boolean {
const minimizedReplacement = this.toFilterTextReplacement(reader).removeCommonPrefix(model);

if (!this.inlineCompletion.range.getStartPosition().equals(this.getUpdatedRange(reader).getStartPosition())) {
return false;
}

if (cursorPosition.lineNumber !== minimizedReplacement.range.startLineNumber) {
if (
!this._isValid
|| !this.inlineCompletion.range.getStartPosition().equals(this.getUpdatedRange(reader).getStartPosition())
|| cursorPosition.lineNumber !== minimizedReplacement.range.startLineNumber
) {
return false;
}

Expand Down Expand Up @@ -325,7 +327,8 @@ export class InlineCompletionWithUpdatedRange {
}

public canBeReused(model: ITextModel, position: Position): boolean {
return this.getUpdatedRange(undefined).containsPosition(position)
return this._isValid
&& this.getUpdatedRange(undefined).containsPosition(position)
&& this.isVisible(model, position, undefined)
&& !this.isSmallerThanOriginal(undefined);
}
Expand Down

0 comments on commit 8d00125

Please sign in to comment.