Monaco 中 SignatureHelpProvider 是方法提示说明,当敲入方法名时,系统会提示方法名称和对应的参数信息。效果如下:
通过 registerSignatureHelpProvider 实现 SignatureHelpProvider 处理函数。
实现 signatureHelpTriggerCharacters 和 provideSignatureHelp
- signatureHelpTriggerCharacters: 返回触发方法说明的字符列表
- provideSignatureHelp:返回方法信息
返回 SignatureHelpResult
SignatureHelpResult 包含 activeParameter、activeSignature、SignatureInformation[] 三个参数。
SignatureInformation 函数接口信息
ParameterInformation 参数信息
代码实现如下
export function signatureHelpProvider(
editor: monacoEditor.editor.IStandaloneCodeEditor,
monaco: typeof monacoEditor
) {
return monaco.languages.registerSignatureHelpProvider("mySpecialLanguage", {
signatureHelpTriggerCharacters: ['(', ','],
provideSignatureHelp: function (model, positions, token, context) {
const signature = {
label: 'add(a: number, b: number): number',
parameters: [
{
label: 'a',
documentation: 'The first number'
},
{
label: 'b',
documentation: 'The second number'
}
]
};
const result = {
signatures: [signature],
activeSignature: 0,
activeParameter: 0
};
return {
value: result,
dispose: () => { }
};
}
});
}