提交 be6b1dfa 编写于 作者: M Matt Bierner

Add SignatureInformation.activateParmater

For #94637

Allows the active paramter to be be specified per signature instead of for all signatures. If provided, this overrides `SignatureHelp.activeParamter`
上级 69032048
......@@ -697,6 +697,12 @@ export interface SignatureInformation {
* The parameters of this signature.
*/
parameters: ParameterInformation[];
/**
* Index of the active parameter.
*
* If provided, this is used in place of `SignatureHelp.activeSignature`.
*/
activeParameter?: number;
}
/**
* Signature help represents the signature of something
......
......@@ -194,24 +194,23 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget {
}
const code = dom.append(this.domNodes.signature, $('.code'));
const hasParameters = signature.parameters.length > 0;
const fontInfo = this.editor.getOption(EditorOption.fontInfo);
code.style.fontSize = `${fontInfo.fontSize}px`;
code.style.fontFamily = fontInfo.fontFamily;
const hasParameters = signature.parameters.length > 0;
const activeParameterIndex = signature.activeParameter ?? hints.activeParameter;
if (!hasParameters) {
const label = dom.append(code, $('span'));
label.textContent = signature.label;
} else {
this.renderParameters(code, signature, hints.activeParameter);
this.renderParameters(code, signature, activeParameterIndex);
}
this.renderDisposeables.clear();
const activeParameter: modes.ParameterInformation | undefined = signature.parameters[hints.activeParameter];
if (activeParameter && activeParameter.documentation) {
const activeParameter: modes.ParameterInformation | undefined = signature.parameters[activeParameterIndex];
if (activeParameter?.documentation) {
const documentation = $('span.documentation');
if (typeof activeParameter.documentation === 'string') {
documentation.textContent = activeParameter.documentation;
......@@ -243,7 +242,7 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget {
pad(hints.activeSignature + 1, hints.signatures.length.toString().length) + '/' + hints.signatures.length;
if (activeParameter) {
const labelToAnnounce = this.getParameterLabel(signature, hints.activeParameter);
const labelToAnnounce = this.getParameterLabel(signature, activeParameterIndex);
// Select method gets called on every user type while parameter hints are visible.
// We do not want to spam the user with same announcements, so we only announce if the current parameter changed.
......@@ -273,8 +272,8 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget {
return false;
}
private renderParameters(parent: HTMLElement, signature: modes.SignatureInformation, currentParameter: number): void {
const [start, end] = this.getParameterLabelOffsets(signature, currentParameter);
private renderParameters(parent: HTMLElement, signature: modes.SignatureInformation, activeParameterIndex: number): void {
const [start, end] = this.getParameterLabelOffsets(signature, activeParameterIndex);
const beforeSpan = document.createElement('span');
beforeSpan.textContent = signature.label.substring(0, start);
......
......@@ -5640,6 +5640,12 @@ declare namespace monaco.languages {
* The parameters of this signature.
*/
parameters: ParameterInformation[];
/**
* Index of the active parameter.
*
* If provided, this is used in place of `SignatureHelp.activeSignature`.
*/
activeParameter?: number;
}
/**
......
......@@ -1991,4 +1991,18 @@ declare module 'vscode' {
//#endregion
//#region https://github.com/microsoft/vscode/issues/94637
export interface SignatureInformation {
/**
* The index of the active parameter.
*
* If provided, this is used in place of `SignatureHelp.activeSignature`.
*/
activeParameter?: number;
}
//#endregion
}
......@@ -939,7 +939,8 @@ export namespace SignatureInformation {
return {
label: info.label,
documentation: info.documentation ? MarkdownString.fromStrict(info.documentation) : undefined,
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.from) : []
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.from) : [],
activeParameter: info.activeParameter,
};
}
......@@ -947,7 +948,8 @@ export namespace SignatureInformation {
return {
label: info.label,
documentation: htmlContent.isMarkdownString(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation,
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.to) : []
parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.to) : [],
activeParameter: info.activeParameter,
};
}
}
......
......@@ -1291,6 +1291,7 @@ export class SignatureInformation {
label: string;
documentation?: string | MarkdownString;
parameters: ParameterInformation[];
activeParameter?: number;
constructor(label: string, documentation?: string | MarkdownString) {
this.label = label;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册