简体   繁体   English

如何在摩纳哥的自定义函数中自动填充参数?

[英]How to autocomplete arguments in custom functions for Monaco?

I currently want to use a monaco editor with PHP and I want to expand it with autocompletion for the regular PHP functions as well as custom functions. 我目前想要使用带有PHP的monaco编辑器,我想通过自动完成来扩展它,用于常规PHP函数以及自定义函数。

While the autocomplete for functions works fine on my early prototype, autocompleting the parameters does not work. 虽然函数的自动完成功能在我的早期原型上运行良好,但自动完成参数不起作用。 See the fiddle for an example: https://jsfiddle.net/95aq6497/2/ 请参阅小提琴,获取示例: https//jsfiddle.net/95aq6497/2/

Currently, only the function substr is provided as autocomplete and is working. 目前,只有函数substr作为自动完成提供并且正在工作。 However, the helper for parameters defined by registerSignatureHelpProvider does not work: 但是,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.'
        }
      ]
    }]
  };
}

}); });

The function is not even executing, as the console.log does not trigger at all. 该函数甚至没有执行,因为console.log根本没有触发。 What am I missing? 我错过了什么? Expanding javascript similarly by a function worked fine like this, but it's not working for PHP, so what's different here? 类似地通过函数扩展javascript工作正常,但它不适用于PHP,所以这里有什么不同?

Looks like you didn't provide signatureHelpTriggerCharacters option: 看起来你没有提供signatureHelpTriggerCharacters选项:

monaco.languages.registerSignatureHelpProvider('php', {
  signatureHelpTriggerCharacters: ['(', ','],  <==================== this one
  provideSignatureHelp: (model, position, token) => {

https://jsfiddle.net/hec12da1/ https://jsfiddle.net/hec12da1/

To implement provideSignatureHelp function I would suggest you to take a look at typescript version 要实现provideSignatureHelp函数,我建议你看一下打字稿版本

https://github.com/Microsoft/monaco-typescript/blob/7027f0b4ba56fc0df136fb41791aa27e8c25ef54/src/languageFeatures.ts#L262 https://github.com/Microsoft/monaco-typescript/blob/7027f0b4ba56fc0df136fb41791aa27e8c25ef54/src/languageFeatures.ts#L262

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM