Skip to content

Commit 501a019

Browse files
authored
1 parent ab8498a commit 501a019

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionContextKeys.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ export class InlineCompletionContextKeys extends Disposable {
3030

3131
this._register(autorun('update context key: inlineCompletionVisible, suppressSuggestions', (reader) => {
3232
const model = this.model.read(reader);
33-
const suggestion = model?.selectedInlineCompletion.read(reader);
34-
const ghostText = model?.ghostText.read(reader);
35-
this.inlineCompletionVisible.set(ghostText !== undefined && !ghostText.isEmpty());
33+
const state = model?.state.read(reader);
34+
35+
const isInlineCompletionVisible = !!state?.inlineCompletion && state?.ghostText !== undefined && !state?.ghostText.isEmpty();
36+
this.inlineCompletionVisible.set(isInlineCompletionVisible);
3637

37-
if (ghostText && suggestion) {
38-
this.suppressSuggestions.set(suggestion.inlineCompletion.source.inlineCompletions.suppressSuggestions);
38+
if (state?.ghostText && state?.inlineCompletion) {
39+
this.suppressSuggestions.set(state.inlineCompletion.inlineCompletion.source.inlineCompletions.suppressSuggestions);
3940
}
4041
}));
4142

src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ export class InlineCompletionsController extends Disposable {
172172
this._register(autorun('play audio cue & read suggestion', reader => {
173173
const model = this.model.read(reader);
174174
const state = model?.state.read(reader);
175-
if (!model || !state || !state.completion) {
175+
if (!model || !state || !state.inlineCompletion) {
176176
lastInlineCompletionId = undefined;
177177
return;
178178
}
179179

180-
if (state.completion.semanticId !== lastInlineCompletionId) {
181-
lastInlineCompletionId = state.completion.semanticId;
180+
if (state.inlineCompletion.semanticId !== lastInlineCompletionId) {
181+
lastInlineCompletionId = state.inlineCompletion.semanticId;
182182
const lineText = model.textModel.getLineContent(state.ghostText.lineNumber);
183183
this.audioCueService.playAudioCue(AudioCue.inlineSuggestion).then(() => {
184184
if (this.editor.getOption(EditorOption.screenReaderAnnounceInlineSuggestion)) {

src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class InlineCompletionsModel extends Disposable {
6565
let lastItem: InlineCompletionWithUpdatedRange | undefined = undefined;
6666
this._register(autorun('call handleItemDidShow', reader => {
6767
const item = this.state.read(reader);
68-
const completion = item?.completion;
68+
const completion = item?.inlineCompletion;
6969
if (completion?.semanticId !== lastItem?.semanticId) {
7070
lastItem = completion;
7171
if (completion) {
@@ -191,7 +191,7 @@ export class InlineCompletionsModel extends Disposable {
191191

192192
public readonly state = derived<{
193193
suggestItem: SuggestItemInfo | undefined;
194-
completion: InlineCompletionWithUpdatedRange | undefined;
194+
inlineCompletion: InlineCompletionWithUpdatedRange | undefined;
195195
ghostText: GhostTextOrReplacement;
196196
} | undefined>('ghostTextAndCompletion', (reader) => {
197197
const model = this.textModel;
@@ -225,7 +225,7 @@ export class InlineCompletionsModel extends Disposable {
225225

226226
// Show an invisible ghost text to reserve space
227227
const ghostText = newGhostText ?? new GhostText(edit.range.endLineNumber, []);
228-
return { ghostText, completion: augmentedCompletion?.completion, suggestItem };
228+
return { ghostText, inlineCompletion: augmentedCompletion?.completion, suggestItem };
229229
} else {
230230
if (!this._isActive.read(reader)) { return undefined; }
231231
const item = this.selectedInlineCompletion.read(reader);
@@ -235,7 +235,7 @@ export class InlineCompletionsModel extends Disposable {
235235
const mode = this._inlineSuggestMode.read(reader);
236236
const cursor = this.cursorPosition.read(reader);
237237
const ghostText = replacement.computeGhostText(model, mode, cursor);
238-
return ghostText ? { ghostText, completion: item, suggestItem: undefined } : undefined;
238+
return ghostText ? { ghostText, inlineCompletion: item, suggestItem: undefined } : undefined;
239239
}
240240
});
241241

@@ -271,10 +271,10 @@ export class InlineCompletionsModel extends Disposable {
271271
}
272272

273273
const state = this.state.get();
274-
if (!state || state.ghostText.isEmpty() || !state.completion) {
274+
if (!state || state.ghostText.isEmpty() || !state.inlineCompletion) {
275275
return;
276276
}
277-
const completion = state.completion.toInlineCompletion(undefined);
277+
const completion = state.inlineCompletion.toInlineCompletion(undefined);
278278

279279
editor.pushUndoStop();
280280
if (completion.snippetInfo) {
@@ -363,11 +363,11 @@ export class InlineCompletionsModel extends Disposable {
363363
}
364364

365365
const state = this.state.get();
366-
if (!state || state.ghostText.isEmpty() || !state.completion) {
366+
if (!state || state.ghostText.isEmpty() || !state.inlineCompletion) {
367367
return;
368368
}
369369
const ghostText = state.ghostText;
370-
const completion = state.completion.toInlineCompletion(undefined);
370+
const completion = state.inlineCompletion.toInlineCompletion(undefined);
371371

372372
if (completion.snippetInfo || completion.filterText !== completion.insertText) {
373373
// not in WYSIWYG mode, partial commit might change completion, thus it is not supported

0 commit comments

Comments
 (0)