Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3659,6 +3659,11 @@ export interface IEditorParameterHintOptions {
* Defaults to false.
*/
cycle?: boolean;
/**
* Automatically show parameter hints when the cursor enters an unmatched open parenthesis.
* Defaults to false.
*/
autoTriggerOnCursorInArgs?: boolean;
}

/**
Expand All @@ -3671,7 +3676,8 @@ class EditorParameterHints extends BaseEditorOption<EditorOption.parameterHints,
constructor() {
const defaults: InternalParameterHintOptions = {
enabled: true,
cycle: true
cycle: true,
autoTriggerOnCursorInArgs: false
};
super(
EditorOption.parameterHints, 'parameterHints', defaults,
Expand All @@ -3686,6 +3692,11 @@ class EditorParameterHints extends BaseEditorOption<EditorOption.parameterHints,
default: defaults.cycle,
description: nls.localize('parameterHints.cycle', "Controls whether the parameter hints menu cycles or closes when reaching the end of the list.")
},
'editor.parameterHints.autoTriggerOnCursorInArgs': {
type: 'boolean',
default: defaults.autoTriggerOnCursorInArgs,
description: nls.localize('parameterHints.autoTriggerOnCursorInArgs', "Controls whether parameter hints are automatically shown when the cursor moves into an existing, unmatched opening parenthesis.")
},
}
);
}
Expand All @@ -3697,7 +3708,8 @@ class EditorParameterHints extends BaseEditorOption<EditorOption.parameterHints,
const input = _input as Unknown<IEditorParameterHintOptions>;
return {
enabled: boolean(input.enabled, this.defaultValue.enabled),
cycle: boolean(input.cycle, this.defaultValue.cycle)
cycle: boolean(input.cycle, this.defaultValue.cycle),
autoTriggerOnCursorInArgs: boolean(input.autoTriggerOnCursorInArgs, this.defaultValue.autoTriggerOnCursorInArgs)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class ParameterHintsModel extends Disposable {
private readonly providers: LanguageFeatureRegistry<languages.SignatureHelpProvider>;

private triggerOnType = false;
private autoTriggerOnCursorInArgs = false;
private _state: ParameterHintState.State = ParameterHintState.Default;
private _pendingTriggers: TriggerContext[] = [];

Expand Down Expand Up @@ -294,11 +295,51 @@ export class ParameterHintsModel extends Disposable {
}

private onCursorChange(e: ICursorSelectionChangedEvent): void {
if (e.source === 'mouse') {
this.cancel();
} else if (this.isTriggered) {
if (this.isTriggered) {
this.trigger({ triggerKind: languages.SignatureHelpTriggerKind.ContentChange });
} else if (e.source === 'mouse') {
if (this.autoTriggerOnCursorInArgs && this.triggerOnType && this.isCursorInsideArgumentList()) {
this.trigger({ triggerKind: languages.SignatureHelpTriggerKind.Invoke });
} else {
this.cancel();
}
} else if (this.autoTriggerOnCursorInArgs && this.triggerOnType && this.isCursorInsideArgumentList()) {
this.trigger({ triggerKind: languages.SignatureHelpTriggerKind.Invoke });
}
}

private isCursorInsideArgumentList(): boolean {
const model = this.editor.getModel();
const position = this.editor.getPosition();
if (!model || !position) {
return false;
}
const text = model.getLineContent(position.lineNumber).substring(0, position.column - 1);
let depth = 0;
let inSingle = false;
let inDouble = false;
let inBacktick = false;
for (let i = 0; i < text.length; i++) {
const ch = text.charAt(i);
if (ch === '\\' && i + 1 < text.length) {
i++;
continue;
}
if (!inDouble && !inBacktick && ch === '\'') {
inSingle = !inSingle;
} else if (!inSingle && !inBacktick && ch === '"') {
inDouble = !inDouble;
} else if (!inSingle && !inDouble && ch === '`') {
inBacktick = !inBacktick;
} else if (!inSingle && !inDouble && !inBacktick) {
if (ch === '(') {
depth++;
} else if (ch === ')' && depth > 0) {
depth--;
}
}
}
return depth > 0;
}

private onModelContentChange(): void {
Expand All @@ -308,7 +349,9 @@ export class ParameterHintsModel extends Disposable {
}

private onEditorConfigurationChange(): void {
this.triggerOnType = this.editor.getOption(EditorOption.parameterHints).enabled;
const options = this.editor.getOption(EditorOption.parameterHints);
this.triggerOnType = options.enabled;
this.autoTriggerOnCursorInArgs = options.autoTriggerOnCursorInArgs;

if (!this.triggerOnType) {
this.cancel();
Expand Down