如何自动完成摩纳哥自定义函数中的参数?
How to autocomplete arguments in custom functions for Monaco?
我目前想将 monaco 编辑器与 PHP 一起使用,我想通过常规 PHP 函数和自定义函数的自动完成来扩展它。
虽然函数的自动完成功能在我的早期原型上运行良好,但自动完成参数不起作用。有关示例,请参见 fiddle:
https://jsfiddle.net/95aq6497/2/
目前,只有函数 substr 被提供为自动完成并且正在运行。但是,由 registerSignatureHelpProvider 定义的参数助手不起作用:
monaco.languages.registerSignatureHelpProvider('php', {
provideSignatureHelp: (model, position, token) => {
console.log('Signature Help');
return {
activeParameter: 0,
activeSignature: 0,
signatures: [{
label: 'string substr(string $string, int $start [, int $length])',
parameters: [
{
label: 'string $string',
documentation: 'The input string. Must be one character or longer.'
},
{
label: 'int $start',
documentation: "If $start is non-negative, the returned string will start at the $start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.\r\nIf $start is negative, the returned string will start at the $start'th character from the end of string. If $string is less than $start characters long, FALSE will be returned."
},
{
label: 'int $length',
documentation: 'If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depending on the length of $string) If $length is given and is negative, then that many characters will be omitted from the end of $string (after the start position has been calculated when a start is negative). If $start denotes the position of this truncation or beyond, FALSE will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If $length is omitted, the substring starting from $start until the end of the string will be returned.'
}
]
}]
};
}
});
函数甚至没有执行,因为 console.log 根本没有触发。我错过了什么?通过函数类似地扩展 javascript 工作得很好,但它不适用于 PHP,所以这里有什么不同?
您似乎没有提供 signatureHelpTriggerCharacters
选项:
monaco.languages.registerSignatureHelpProvider('php', {
signatureHelpTriggerCharacters: ['(', ','], <==================== this one
provideSignatureHelp: (model, position, token) => {
https://jsfiddle.net/hec12da1/
要实现provideSignatureHelp
功能我建议你看一下typescript版本
我目前想将 monaco 编辑器与 PHP 一起使用,我想通过常规 PHP 函数和自定义函数的自动完成来扩展它。
虽然函数的自动完成功能在我的早期原型上运行良好,但自动完成参数不起作用。有关示例,请参见 fiddle: https://jsfiddle.net/95aq6497/2/
目前,只有函数 substr 被提供为自动完成并且正在运行。但是,由 registerSignatureHelpProvider 定义的参数助手不起作用:
monaco.languages.registerSignatureHelpProvider('php', {
provideSignatureHelp: (model, position, token) => {
console.log('Signature Help');
return {
activeParameter: 0,
activeSignature: 0,
signatures: [{
label: 'string substr(string $string, int $start [, int $length])',
parameters: [
{
label: 'string $string',
documentation: 'The input string. Must be one character or longer.'
},
{
label: 'int $start',
documentation: "If $start is non-negative, the returned string will start at the $start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.\r\nIf $start is negative, the returned string will start at the $start'th character from the end of string. If $string is less than $start characters long, FALSE will be returned."
},
{
label: 'int $length',
documentation: 'If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depending on the length of $string) If $length is given and is negative, then that many characters will be omitted from the end of $string (after the start position has been calculated when a start is negative). If $start denotes the position of this truncation or beyond, FALSE will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If $length is omitted, the substring starting from $start until the end of the string will be returned.'
}
]
}]
};
}
});
函数甚至没有执行,因为 console.log 根本没有触发。我错过了什么?通过函数类似地扩展 javascript 工作得很好,但它不适用于 PHP,所以这里有什么不同?
您似乎没有提供 signatureHelpTriggerCharacters
选项:
monaco.languages.registerSignatureHelpProvider('php', {
signatureHelpTriggerCharacters: ['(', ','], <==================== this one
provideSignatureHelp: (model, position, token) => {
https://jsfiddle.net/hec12da1/
要实现provideSignatureHelp
功能我建议你看一下typescript版本