-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #179134. Adds flag suppressSuggestions to inline completion res…
…ult. (#180129) * Fixes #179134. Adds flag suppressSuggestions to inline completion result. * Fixes memory leak. * Implements hidden keepOnBlur editor flag for inline suggestions to make debugging easier. * Fixes inline suggestion visibility bug * Implements experimental forward stability flag (defaults to false).
- Loading branch information
Showing
13 changed files
with
150 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionContextKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { IObservable, autorun } from 'vs/base/common/observable'; | ||
import { firstNonWhitespaceIndex } from 'vs/base/common/strings'; | ||
import { CursorColumns } from 'vs/editor/common/core/cursorColumns'; | ||
import { InlineCompletionsModel } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel'; | ||
import { RawContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; | ||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { localize } from 'vs/nls'; | ||
|
||
export class InlineCompletionContextKeys extends Disposable { | ||
public static readonly inlineSuggestionVisible = new RawContextKey<boolean>('inlineSuggestionVisible', false, localize('inlineSuggestionVisible', "Whether an inline suggestion is visible")); | ||
public static readonly inlineSuggestionHasIndentation = new RawContextKey<boolean>('inlineSuggestionHasIndentation', false, localize('inlineSuggestionHasIndentation', "Whether the inline suggestion starts with whitespace")); | ||
public static readonly inlineSuggestionHasIndentationLessThanTabSize = new RawContextKey<boolean>('inlineSuggestionHasIndentationLessThanTabSize', true, localize('inlineSuggestionHasIndentationLessThanTabSize', "Whether the inline suggestion starts with whitespace that is less than what would be inserted by tab")); | ||
public static readonly alwaysShowInlineSuggestionToolbar = new RawContextKey<boolean>('alwaysShowInlineSuggestionToolbar', false, localize('alwaysShowInlineSuggestionToolbar', "Whether the inline suggestion toolbar should always be visible")); | ||
public static readonly suppressSuggestions = new RawContextKey<boolean | undefined>('inlineSuggestionSuppressSuggestions', undefined, localize('suppressSuggestions', "Whether suggestions should be suppressed for the current suggestion")); | ||
|
||
public readonly inlineCompletionVisible = InlineCompletionContextKeys.inlineSuggestionVisible.bindTo(this.contextKeyService); | ||
public readonly inlineCompletionSuggestsIndentation = InlineCompletionContextKeys.inlineSuggestionHasIndentation.bindTo(this.contextKeyService); | ||
public readonly inlineCompletionSuggestsIndentationLessThanTabSize = InlineCompletionContextKeys.inlineSuggestionHasIndentationLessThanTabSize.bindTo(this.contextKeyService); | ||
public readonly suppressSuggestions = InlineCompletionContextKeys.suppressSuggestions.bindTo(this.contextKeyService); | ||
|
||
constructor( | ||
private readonly contextKeyService: IContextKeyService, | ||
private readonly model: IObservable<InlineCompletionsModel | undefined>, | ||
) { | ||
super(); | ||
|
||
this._register(autorun('update context key: inlineCompletionVisible, suppressSuggestions', (reader) => { | ||
const model = this.model.read(reader); | ||
const suggestion = model?.currentInlineCompletion.read(reader); | ||
const ghostText = model?.ghostText.read(reader); | ||
const selectedSuggestItem = model?.selectedSuggestItem.read(reader); | ||
this.inlineCompletionVisible.set(selectedSuggestItem === undefined && ghostText !== undefined); | ||
|
||
if (ghostText && suggestion) { | ||
this.suppressSuggestions.set(suggestion.inlineCompletion.source.inlineCompletions.suppressSuggestions); | ||
} | ||
})); | ||
|
||
this._register(autorun('update context key: inlineCompletionSuggestsIndentation, inlineCompletionSuggestsIndentationLessThanTabSize', (reader) => { | ||
const model = this.model.read(reader); | ||
|
||
let startsWithIndentation = false; | ||
let startsWithIndentationLessThanTabSize = true; | ||
|
||
const ghostText = model?.ghostText.read(reader); | ||
if (!!model?.selectedSuggestItem && ghostText && ghostText.parts.length > 0) { | ||
const { column, lines } = ghostText.parts[0]; | ||
|
||
const firstLine = lines[0]; | ||
|
||
const indentationEndColumn = model.textModel.getLineIndentColumn(ghostText.lineNumber); | ||
const inIndentation = column <= indentationEndColumn; | ||
|
||
if (inIndentation) { | ||
let firstNonWsIdx = firstNonWhitespaceIndex(firstLine); | ||
if (firstNonWsIdx === -1) { | ||
firstNonWsIdx = firstLine.length - 1; | ||
} | ||
startsWithIndentation = firstNonWsIdx > 0; | ||
|
||
const tabSize = model.textModel.getOptions().tabSize; | ||
const visibleColumnIndentation = CursorColumns.visibleColumnFromColumn(firstLine, firstNonWsIdx + 1, tabSize); | ||
startsWithIndentationLessThanTabSize = visibleColumnIndentation < tabSize; | ||
} | ||
} | ||
|
||
this.inlineCompletionSuggestsIndentation.set(startsWithIndentation); | ||
this.inlineCompletionSuggestsIndentationLessThanTabSize.set(startsWithIndentationLessThanTabSize); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.