mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
This reverts commit 3bdd297575.
This commit is contained in:
@@ -83,14 +83,6 @@ export class GhostTextPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GhostTextReplacement {
|
export class GhostTextReplacement {
|
||||||
public readonly parts: ReadonlyArray<GhostTextPart> = [
|
|
||||||
new GhostTextPart(
|
|
||||||
this.columnStart + this.length,
|
|
||||||
this.newLines,
|
|
||||||
false
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly lineNumber: number,
|
readonly lineNumber: number,
|
||||||
readonly columnStart: number,
|
readonly columnStart: number,
|
||||||
@@ -98,6 +90,13 @@ export class GhostTextReplacement {
|
|||||||
readonly newLines: readonly string[],
|
readonly newLines: readonly string[],
|
||||||
public readonly additionalReservedLineCount: number = 0,
|
public readonly additionalReservedLineCount: number = 0,
|
||||||
) { }
|
) { }
|
||||||
|
public readonly parts: ReadonlyArray<GhostTextPart> = [
|
||||||
|
new GhostTextPart(
|
||||||
|
this.columnStart + this.length,
|
||||||
|
this.newLines,
|
||||||
|
false
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
renderForScreenReader(_lineText: string): string {
|
renderForScreenReader(_lineText: string): string {
|
||||||
return this.newLines.join('\n');
|
return this.newLines.join('\n');
|
||||||
|
|||||||
@@ -78,17 +78,26 @@ export class InlineCompletionsModel extends Disposable implements GhostTextWidge
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._register(this.editor.onDidType((e) => { this.handleUserInput(); }));
|
this._register(
|
||||||
|
this.editor.onDidType((e) => {
|
||||||
|
this.handleUserInput();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
this._register(
|
this._register(
|
||||||
this.editor.onDidChangeCursorPosition((e) => {
|
this.editor.onDidChangeCursorPosition((e) => {
|
||||||
if (e.reason === CursorChangeReason.Explicit || this.session && !this.session.isValid) {
|
if (e.reason === CursorChangeReason.Explicit ||
|
||||||
|
this.session && !this.session.isValid) {
|
||||||
this.hide();
|
this.hide();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._register(toDisposable(() => { this.disposed = true; }));
|
this._register(
|
||||||
|
toDisposable(() => {
|
||||||
|
this.disposed = true;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
this._register(
|
this._register(
|
||||||
this.editor.onDidBlurEditorWidget(() => {
|
this.editor.onDidBlurEditorWidget(() => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import { compareBy, findMaxBy, numberComparator } from 'vs/base/common/arrays';
|
import { compareBy, findMaxBy, numberComparator } from 'vs/base/common/arrays';
|
||||||
import { Event } from 'vs/base/common/event';
|
import { Emitter, Event } from 'vs/base/common/event';
|
||||||
import { Disposable } from 'vs/base/common/lifecycle';
|
import { Disposable } from 'vs/base/common/lifecycle';
|
||||||
import { IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
|
import { IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||||
import { Position } from 'vs/editor/common/core/position';
|
import { Position } from 'vs/editor/common/core/position';
|
||||||
@@ -15,7 +15,6 @@ import { SnippetSession } from 'vs/editor/contrib/snippet/browser/snippetSession
|
|||||||
import { CompletionItem } from 'vs/editor/contrib/suggest/browser/suggest';
|
import { CompletionItem } from 'vs/editor/contrib/suggest/browser/suggest';
|
||||||
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
|
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
|
||||||
import { minimizeInlineCompletion, NormalizedInlineCompletion, normalizedInlineCompletionsEquals } from './inlineCompletionToGhostText';
|
import { minimizeInlineCompletion, NormalizedInlineCompletion, normalizedInlineCompletionsEquals } from './inlineCompletionToGhostText';
|
||||||
import { IObservable, observableValue, transaction } from 'vs/base/common/observable';
|
|
||||||
|
|
||||||
export interface SuggestWidgetState {
|
export interface SuggestWidgetState {
|
||||||
/**
|
/**
|
||||||
@@ -35,11 +34,18 @@ export class SuggestWidgetInlineCompletionProvider extends Disposable {
|
|||||||
private isShiftKeyPressed = false;
|
private isShiftKeyPressed = false;
|
||||||
private _isActive = false;
|
private _isActive = false;
|
||||||
private _currentSuggestItemInfo: SuggestItemInfo | undefined = undefined;
|
private _currentSuggestItemInfo: SuggestItemInfo | undefined = undefined;
|
||||||
|
private readonly onDidChangeEmitter = new Emitter<void>();
|
||||||
|
|
||||||
private readonly _state = observableValue('suggestWidgetInlineCompletionProvider.state', undefined as SuggestWidgetState | undefined);
|
public readonly onDidChange = this.onDidChangeEmitter.event;
|
||||||
|
|
||||||
public get state(): IObservable<SuggestWidgetState | undefined> {
|
/**
|
||||||
return this._state;
|
* Returns undefined if the suggest widget is not active.
|
||||||
|
*/
|
||||||
|
get state(): SuggestWidgetState | undefined {
|
||||||
|
if (!this._isActive) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return { selectedItem: this._currentSuggestItemInfo };
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -81,7 +87,8 @@ export class SuggestWidgetInlineCompletionProvider extends Disposable {
|
|||||||
if (!normalizedSuggestItem) {
|
if (!normalizedSuggestItem) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const valid = rangeStartsWith(normalizedItemToPreselect.range, normalizedSuggestItem.range) &&
|
const valid =
|
||||||
|
rangeStartsWith(normalizedItemToPreselect.range, normalizedSuggestItem.range) &&
|
||||||
normalizedItemToPreselect.insertText.startsWith(normalizedSuggestItem.insertText);
|
normalizedItemToPreselect.insertText.startsWith(normalizedSuggestItem.insertText);
|
||||||
return { index, valid, prefixLength: normalizedSuggestItem.insertText.length, suggestItem };
|
return { index, valid, prefixLength: normalizedSuggestItem.insertText.length, suggestItem };
|
||||||
})
|
})
|
||||||
@@ -135,9 +142,7 @@ export class SuggestWidgetInlineCompletionProvider extends Disposable {
|
|||||||
shouldFire = true;
|
shouldFire = true;
|
||||||
}
|
}
|
||||||
if (shouldFire) {
|
if (shouldFire) {
|
||||||
transaction(tx => {
|
this.onDidChangeEmitter.fire();
|
||||||
this._state.set(this._isActive ? { selectedItem: this._currentSuggestItemInfo } : undefined, tx);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { BaseGhostTextWidgetModel, GhostText } from './ghostText';
|
|||||||
import { provideInlineCompletions, TrackedInlineCompletions, UpdateOperation } from './inlineCompletionsModel';
|
import { provideInlineCompletions, TrackedInlineCompletions, UpdateOperation } from './inlineCompletionsModel';
|
||||||
import { inlineCompletionToGhostText, minimizeInlineCompletion, NormalizedInlineCompletion } from './inlineCompletionToGhostText';
|
import { inlineCompletionToGhostText, minimizeInlineCompletion, NormalizedInlineCompletion } from './inlineCompletionToGhostText';
|
||||||
import { SuggestWidgetInlineCompletionProvider } from './suggestWidgetInlineCompletionProvider';
|
import { SuggestWidgetInlineCompletionProvider } from './suggestWidgetInlineCompletionProvider';
|
||||||
import { autorun } from 'vs/base/common/observable';
|
|
||||||
|
|
||||||
export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
||||||
private readonly suggestionInlineCompletionSource = this._register(
|
private readonly suggestionInlineCompletionSource = this._register(
|
||||||
@@ -46,7 +45,7 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
|||||||
) {
|
) {
|
||||||
super(editor);
|
super(editor);
|
||||||
|
|
||||||
this._register(autorun('update', reader => {
|
this._register(this.suggestionInlineCompletionSource.onDidChange(() => {
|
||||||
if (!this.editor.hasModel()) {
|
if (!this.editor.hasModel()) {
|
||||||
// onDidChange might be called when calling setModel on the editor, before we are disposed.
|
// onDidChange might be called when calling setModel on the editor, before we are disposed.
|
||||||
return;
|
return;
|
||||||
@@ -54,7 +53,7 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
|||||||
|
|
||||||
this.updateCacheSoon.schedule();
|
this.updateCacheSoon.schedule();
|
||||||
|
|
||||||
const suggestWidgetState = this.suggestionInlineCompletionSource.state.read(reader);
|
const suggestWidgetState = this.suggestionInlineCompletionSource.state;
|
||||||
if (!suggestWidgetState) {
|
if (!suggestWidgetState) {
|
||||||
this.minReservedLineCount = 0;
|
this.minReservedLineCount = 0;
|
||||||
}
|
}
|
||||||
@@ -91,7 +90,7 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async updateCache() {
|
private async updateCache() {
|
||||||
const state = this.suggestionInlineCompletionSource.state.get();
|
const state = this.suggestionInlineCompletionSource.state;
|
||||||
if (!state || !state.selectedItem) {
|
if (!state || !state.selectedItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -153,7 +152,7 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
|||||||
const augmentedCompletion = minimizeInlineCompletion(model, this.cache.value?.completions[0]?.toLiveInlineCompletion());
|
const augmentedCompletion = minimizeInlineCompletion(model, this.cache.value?.completions[0]?.toLiveInlineCompletion());
|
||||||
|
|
||||||
const suggestWidgetState = this.suggestionInlineCompletionSource.state;
|
const suggestWidgetState = this.suggestionInlineCompletionSource.state;
|
||||||
const suggestInlineCompletion = minimizeInlineCompletion(model, suggestWidgetState?.get()?.selectedItem?.normalizedInlineCompletion);
|
const suggestInlineCompletion = minimizeInlineCompletion(model, suggestWidgetState?.selectedItem?.normalizedInlineCompletion);
|
||||||
|
|
||||||
const isAugmentedCompletionValid = augmentedCompletion
|
const isAugmentedCompletionValid = augmentedCompletion
|
||||||
&& suggestInlineCompletion
|
&& suggestInlineCompletion
|
||||||
|
|||||||
Reference in New Issue
Block a user