Skip to content

Commit be6b1df

Browse files
committed
Add SignatureInformation.activateParmater
For microsoft#94637 Allows the active paramter to be be specified per signature instead of for all signatures. If provided, this overrides `SignatureHelp.activeParamter`
1 parent 6903204 commit be6b1df

6 files changed

Lines changed: 40 additions & 12 deletions

File tree

src/vs/editor/common/modes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,12 @@ export interface SignatureInformation {
697697
* The parameters of this signature.
698698
*/
699699
parameters: ParameterInformation[];
700+
/**
701+
* Index of the active parameter.
702+
*
703+
* If provided, this is used in place of `SignatureHelp.activeSignature`.
704+
*/
705+
activeParameter?: number;
700706
}
701707
/**
702708
* Signature help represents the signature of something

src/vs/editor/contrib/parameterHints/parameterHintsWidget.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,23 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget {
194194
}
195195

196196
const code = dom.append(this.domNodes.signature, $('.code'));
197-
const hasParameters = signature.parameters.length > 0;
198-
199197
const fontInfo = this.editor.getOption(EditorOption.fontInfo);
200198
code.style.fontSize = `${fontInfo.fontSize}px`;
201199
code.style.fontFamily = fontInfo.fontFamily;
202200

201+
const hasParameters = signature.parameters.length > 0;
202+
const activeParameterIndex = signature.activeParameter ?? hints.activeParameter;
203+
203204
if (!hasParameters) {
204205
const label = dom.append(code, $('span'));
205206
label.textContent = signature.label;
206207
} else {
207-
this.renderParameters(code, signature, hints.activeParameter);
208+
this.renderParameters(code, signature, activeParameterIndex);
208209
}
209210

210-
this.renderDisposeables.clear();
211-
212-
const activeParameter: modes.ParameterInformation | undefined = signature.parameters[hints.activeParameter];
213211

214-
if (activeParameter && activeParameter.documentation) {
212+
const activeParameter: modes.ParameterInformation | undefined = signature.parameters[activeParameterIndex];
213+
if (activeParameter?.documentation) {
215214
const documentation = $('span.documentation');
216215
if (typeof activeParameter.documentation === 'string') {
217216
documentation.textContent = activeParameter.documentation;
@@ -243,7 +242,7 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget {
243242
pad(hints.activeSignature + 1, hints.signatures.length.toString().length) + '/' + hints.signatures.length;
244243

245244
if (activeParameter) {
246-
const labelToAnnounce = this.getParameterLabel(signature, hints.activeParameter);
245+
const labelToAnnounce = this.getParameterLabel(signature, activeParameterIndex);
247246
// Select method gets called on every user type while parameter hints are visible.
248247
// We do not want to spam the user with same announcements, so we only announce if the current parameter changed.
249248

@@ -273,8 +272,8 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget {
273272
return false;
274273
}
275274

276-
private renderParameters(parent: HTMLElement, signature: modes.SignatureInformation, currentParameter: number): void {
277-
const [start, end] = this.getParameterLabelOffsets(signature, currentParameter);
275+
private renderParameters(parent: HTMLElement, signature: modes.SignatureInformation, activeParameterIndex: number): void {
276+
const [start, end] = this.getParameterLabelOffsets(signature, activeParameterIndex);
278277

279278
const beforeSpan = document.createElement('span');
280279
beforeSpan.textContent = signature.label.substring(0, start);

src/vs/monaco.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5640,6 +5640,12 @@ declare namespace monaco.languages {
56405640
* The parameters of this signature.
56415641
*/
56425642
parameters: ParameterInformation[];
5643+
/**
5644+
* Index of the active parameter.
5645+
*
5646+
* If provided, this is used in place of `SignatureHelp.activeSignature`.
5647+
*/
5648+
activeParameter?: number;
56435649
}
56445650

56455651
/**

src/vs/vscode.proposed.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,4 +1991,18 @@ declare module 'vscode' {
19911991

19921992
//#endregion
19931993

1994+
//#region https://github.com/microsoft/vscode/issues/94637
1995+
1996+
export interface SignatureInformation {
1997+
1998+
/**
1999+
* The index of the active parameter.
2000+
*
2001+
* If provided, this is used in place of `SignatureHelp.activeSignature`.
2002+
*/
2003+
activeParameter?: number;
2004+
}
2005+
2006+
//#endregion
2007+
19942008
}

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,15 +939,17 @@ export namespace SignatureInformation {
939939
return {
940940
label: info.label,
941941
documentation: info.documentation ? MarkdownString.fromStrict(info.documentation) : undefined,
942-
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.from) : []
942+
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.from) : [],
943+
activeParameter: info.activeParameter,
943944
};
944945
}
945946

946947
export function to(info: modes.SignatureInformation): types.SignatureInformation {
947948
return {
948949
label: info.label,
949950
documentation: htmlContent.isMarkdownString(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation,
950-
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.to) : []
951+
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.to) : [],
952+
activeParameter: info.activeParameter,
951953
};
952954
}
953955
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ export class SignatureInformation {
12911291
label: string;
12921292
documentation?: string | MarkdownString;
12931293
parameters: ParameterInformation[];
1294+
activeParameter?: number;
12941295

12951296
constructor(label: string, documentation?: string | MarkdownString) {
12961297
this.label = label;

0 commit comments

Comments
 (0)