Skip to content

Commit

Permalink
disable quick suggestions when in snippet mode, #50776
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jul 6, 2018
1 parent 66d811f commit bc067a8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ export interface InternalEditorHoverOptions {
export interface InternalSuggestOptions {
readonly filterGraceful: boolean;
readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
readonly snippetsPreventQuickSuggestions: boolean;
}

export interface EditorWrappingInfo {
Expand Down Expand Up @@ -1751,6 +1752,7 @@ export class EditorOptionsValidator {
return {
filterGraceful: _boolean(opts.suggest.filterGraceful, defaults.filterGraceful),
snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']),
snippetsPreventQuickSuggestions: true,
};
}

Expand Down Expand Up @@ -2470,7 +2472,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
suggestLineHeight: 0,
suggest: {
filterGraceful: true,
snippets: 'inline'
snippets: 'inline',
snippetsPreventQuickSuggestions: true

This comment has been minimized.

Copy link
@ab404

ab404 Dec 31, 2021

阿里路亚

},
selectionHighlight: true,
occurrencesHighlight: true,
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/snippet/snippetController2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export class SnippetController2 implements IEditorContribution {
this._updateState();
}

isInSnippet(): boolean {
return this._inSnippet.get();
}

getSessionEnclosingRange(): Range {
if (this._session) {
return this._session.getEnclosingRange();
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/suggest/completionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/comm
import { isDisposable } from 'vs/base/common/lifecycle';
import { ISuggestResult, ISuggestSupport } from 'vs/editor/common/modes';
import { ISuggestionItem } from './suggest';
import { InternalSuggestOptions } from 'vs/editor/common/config/editorOptions';
import { InternalSuggestOptions, EDITOR_DEFAULTS } from 'vs/editor/common/config/editorOptions';

export interface ICompletionItem extends ISuggestionItem {
matches?: number[];
Expand Down Expand Up @@ -58,7 +58,7 @@ export class CompletionModel {
private _isIncomplete: Set<ISuggestSupport>;
private _stats: ICompletionStats;

constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, options: InternalSuggestOptions = { filterGraceful: true, snippets: 'inline' }) {
constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, options: InternalSuggestOptions = EDITOR_DEFAULTS.contribInfo.suggest) {
this._items = items;
this._column = column;
this._options = options;
Expand Down
6 changes: 6 additions & 0 deletions src/vs/editor/contrib/suggest/suggestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ITextModel, IWordAtPosition } from 'vs/editor/common/model';
import { ISuggestSupport, StandardTokenType, SuggestContext, SuggestRegistry, SuggestTriggerKind } from 'vs/editor/common/modes';
import { CompletionModel } from './completionModel';
import { ISuggestionItem, getSuggestionComparator, provideSuggestionItems, getSnippetSuggestSupport } from './suggest';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';

export interface ICancelEvent {
readonly retrigger: boolean;
Expand Down Expand Up @@ -273,6 +274,11 @@ export class SuggestModel implements IDisposable {
return;
}

if (this._editor.getConfiguration().contribInfo.suggest.snippetsPreventQuickSuggestions && SnippetController2.get(this._editor).isInSnippet()) {
// no quick suggestion when in snippet mode
return;
}

this.cancel();

this._triggerQuickSuggest.cancelAndSet(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/contrib/suggest/test/completionModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ suite('CompletionModel', function () {
], 1, {
leadingLineContent: 's',
characterCountDelta: 0
}, { snippets: 'top', filterGraceful: true });
}, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true });

assert.equal(model.items.length, 2);
const [a, b] = model.items;
Expand All @@ -186,7 +186,7 @@ suite('CompletionModel', function () {
], 1, {
leadingLineContent: 's',
characterCountDelta: 0
}, { snippets: 'bottom', filterGraceful: true });
}, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true });

assert.equal(model.items.length, 2);
const [a, b] = model.items;
Expand All @@ -204,7 +204,7 @@ suite('CompletionModel', function () {
], 1, {
leadingLineContent: 's',
characterCountDelta: 0
}, { snippets: 'inline', filterGraceful: true });
}, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true });

assert.equal(model.items.length, 2);
const [a, b] = model.items;
Expand Down
6 changes: 4 additions & 2 deletions src/vs/editor/contrib/suggest/test/suggestModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';

function createMockEditor(model: TextModel): TestCodeEditor {
return createTestCodeEditor({
let editor = createTestCodeEditor({
model: model,
serviceCollection: new ServiceCollection(
[ITelemetryService, NullTelemetryService],
[IStorageService, NullStorageService]
)
),
});
editor.registerAndInstantiateContribution(SnippetController2);
return editor;
}

suite('SuggestModel - Context', function () {
Expand Down
1 change: 1 addition & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3123,6 +3123,7 @@ declare namespace monaco.editor {
export interface InternalSuggestOptions {
readonly filterGraceful: boolean;
readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
readonly snippetsPreventQuickSuggestions: boolean;
}

export interface EditorWrappingInfo {
Expand Down

0 comments on commit bc067a8

Please sign in to comment.